Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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/. */
6 #include "nsListItemFrame.h"
8 #include "nsCOMPtr.h"
9 #include "nsNameSpaceManager.h"
10 #include "nsGkAtoms.h"
11 #include "nsDisplayList.h"
12 #include "nsBoxLayout.h"
13 #include <algorithm>
15 nsListItemFrame::nsListItemFrame(nsIPresShell* aPresShell,
16 nsStyleContext* aContext,
17 bool aIsRoot,
18 nsBoxLayout* aLayoutManager)
19 : nsGridRowLeafFrame(aPresShell, aContext, aIsRoot, aLayoutManager)
20 {
21 }
23 nsListItemFrame::~nsListItemFrame()
24 {
25 }
27 nsSize
28 nsListItemFrame::GetPrefSize(nsBoxLayoutState& aState)
29 {
30 nsSize size = nsBoxFrame::GetPrefSize(aState);
31 DISPLAY_PREF_SIZE(this, size);
33 // guarantee that our preferred height doesn't exceed the standard
34 // listbox row height
35 size.height = std::max(mRect.height, size.height);
36 return size;
37 }
39 void
40 nsListItemFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
41 const nsRect& aDirtyRect,
42 const nsDisplayListSet& aLists)
43 {
44 if (aBuilder->IsForEventDelivery()) {
45 if (!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::allowevents,
46 nsGkAtoms::_true, eCaseMatters))
47 return;
48 }
50 nsGridRowLeafFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
51 }
53 // Creation Routine ///////////////////////////////////////////////////////////////////////
55 already_AddRefed<nsBoxLayout> NS_NewGridRowLeafLayout();
57 nsIFrame*
58 NS_NewListItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
59 {
60 nsCOMPtr<nsBoxLayout> layout = NS_NewGridRowLeafLayout();
61 if (!layout) {
62 return nullptr;
63 }
65 return new (aPresShell) nsListItemFrame(aPresShell, aContext, false, layout);
66 }
68 NS_IMPL_FRAMEARENA_HELPERS(nsListItemFrame)