nsListItemFrame.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsListItemFrame.h"
  6. #include <algorithm>
  7. #include "nsCOMPtr.h"
  8. #include "nsNameSpaceManager.h"
  9. #include "nsGkAtoms.h"
  10. #include "nsDisplayList.h"
  11. #include "nsBoxLayout.h"
  12. #include "nsIContent.h"
  13. nsListItemFrame::nsListItemFrame(nsStyleContext* aContext,
  14. bool aIsRoot,
  15. nsBoxLayout* aLayoutManager)
  16. : nsGridRowLeafFrame(aContext, aIsRoot, aLayoutManager)
  17. {
  18. }
  19. nsListItemFrame::~nsListItemFrame()
  20. {
  21. }
  22. nsSize
  23. nsListItemFrame::GetXULPrefSize(nsBoxLayoutState& aState)
  24. {
  25. nsSize size = nsBoxFrame::GetXULPrefSize(aState);
  26. DISPLAY_PREF_SIZE(this, size);
  27. // guarantee that our preferred height doesn't exceed the standard
  28. // listbox row height
  29. size.height = std::max(mRect.height, size.height);
  30. return size;
  31. }
  32. void
  33. nsListItemFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
  34. const nsDisplayListSet& aLists)
  35. {
  36. if (aBuilder->IsForEventDelivery()) {
  37. if (!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::allowevents,
  38. nsGkAtoms::_true, eCaseMatters))
  39. return;
  40. }
  41. nsGridRowLeafFrame::BuildDisplayListForChildren(aBuilder, aLists);
  42. }
  43. // Creation Routine ///////////////////////////////////////////////////////////////////////
  44. already_AddRefed<nsBoxLayout> NS_NewGridRowLeafLayout();
  45. nsIFrame*
  46. NS_NewListItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
  47. {
  48. nsCOMPtr<nsBoxLayout> layout = NS_NewGridRowLeafLayout();
  49. if (!layout) {
  50. return nullptr;
  51. }
  52. return new (aPresShell) nsListItemFrame(aContext, false, layout);
  53. }
  54. NS_IMPL_FRAMEARENA_HELPERS(nsListItemFrame)