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