1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 // Netscape Communications
42 // See documentation in associated header file
45 #include "nsDeckFrame.h"
46 #include "nsStyleContext.h"
47 #include "nsPresContext.h"
48 #include "nsIContent.h"
50 #include "nsINameSpaceManager.h"
51 #include "nsGkAtoms.h"
52 #include "nsHTMLParts.h"
53 #include "nsIPresShell.h"
54 #include "nsCSSRendering.h"
55 #include "nsIViewManager.h"
56 #include "nsBoxLayoutState.h"
57 #include "nsStackLayout.h"
58 #include "nsDisplayList.h"
61 NS_NewDeckFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
63 return new (aPresShell
) nsDeckFrame(aPresShell
, aContext
);
67 nsDeckFrame::nsDeckFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
68 : nsBoxFrame(aPresShell
, aContext
), mIndex(0)
70 nsCOMPtr
<nsIBoxLayout
> layout
;
71 NS_NewStackLayout(aPresShell
, layout
);
72 SetLayoutManager(layout
);
76 nsDeckFrame::GetType() const
78 return nsGkAtoms::deckFrame
;
82 nsDeckFrame::AttributeChanged(PRInt32 aNameSpaceID
,
86 nsresult rv
= nsBoxFrame::AttributeChanged(aNameSpaceID
, aAttribute
,
90 // if the index changed hide the old element and make the new element visible
91 if (aAttribute
== nsGkAtoms::selectedIndex
) {
92 IndexChanged(PresContext());
99 nsDeckFrame::Init(nsIContent
* aContent
,
101 nsIFrame
* aPrevInFlow
)
103 nsresult rv
= nsBoxFrame::Init(aContent
, aParent
, aPrevInFlow
);
105 mIndex
= GetSelectedIndex();
111 nsDeckFrame::HideBox(nsPresContext
* aPresContext
, nsIBox
* aBox
)
113 nsIView
* view
= aBox
->GetView();
116 nsIViewManager
* viewManager
= view
->GetViewManager();
117 viewManager
->SetViewVisibility(view
, nsViewVisibility_kHide
);
118 viewManager
->ResizeView(view
, nsRect(0, 0, 0, 0));
123 nsDeckFrame::ShowBox(nsPresContext
* aPresContext
, nsIBox
* aBox
)
125 nsRect rect
= aBox
->GetRect();
126 nsIView
* view
= aBox
->GetView();
128 nsIViewManager
* viewManager
= view
->GetViewManager();
130 viewManager
->ResizeView(view
, rect
);
131 viewManager
->SetViewVisibility(view
, nsViewVisibility_kShow
);
136 nsDeckFrame::IndexChanged(nsPresContext
* aPresContext
)
138 //did the index change?
139 PRInt32 index
= GetSelectedIndex();
144 nsBoxLayoutState
state(aPresContext
);
147 // hide the currently showing box
148 nsIBox
* currentBox
= GetSelectedBox();
149 if (currentBox
) // only hide if it exists
150 HideBox(aPresContext
, currentBox
);
155 nsIBox
* newBox
= GetSelectedBox();
156 if (newBox
) // only show if it exists
157 ShowBox(aPresContext
, newBox
);
161 nsDeckFrame::GetSelectedIndex()
163 // default index is 0
166 // get the index attribute
168 if (mContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::selectedIndex
, value
))
172 // convert it to an integer
173 index
= value
.ToInteger(&error
);
180 nsDeckFrame::GetSelectedBox()
182 return (mIndex
>= 0) ? mFrames
.FrameAt(mIndex
) : nsnull
;
186 nsDeckFrame::BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
187 const nsRect
& aDirtyRect
,
188 const nsDisplayListSet
& aLists
)
190 // if a tab is hidden all its children are too.
191 if (!GetStyleVisibility()->mVisible
)
194 // REVIEW: The old code skipped painting of background/borders/outline for this
195 // frame and painting of debug boxes ... I've put it back.
196 return nsBoxFrame::BuildDisplayList(aBuilder
, aDirtyRect
, aLists
);
200 nsDeckFrame::BuildDisplayListForChildren(nsDisplayListBuilder
* aBuilder
,
201 const nsRect
& aDirtyRect
,
202 const nsDisplayListSet
& aLists
)
204 // only paint the selected box
205 nsIBox
* box
= GetSelectedBox();
209 // Putting the child in the background list. This is a little weird but
210 // it matches what we were doing before.
211 nsDisplayListSet
set(aLists
, aLists
.BlockBorderBackgrounds());
212 return BuildDisplayListForChild(aBuilder
, box
, aDirtyRect
, set
);
216 nsDeckFrame::DoLayout(nsBoxLayoutState
& aState
)
218 // Make sure we tweak the state so it does not resize our children.
220 PRUint32 oldFlags
= aState
.LayoutFlags();
221 aState
.SetLayoutFlags(NS_FRAME_NO_SIZE_VIEW
| NS_FRAME_NO_VISIBILITY
);
223 // do a normal layout
224 nsresult rv
= nsBoxFrame::DoLayout(aState
);
226 // run though each child. Hide all but the selected one
227 nsIBox
* box
= GetChildBox();
232 // make collapsed children not show up
234 ShowBox(aState
.PresContext(), box
);
236 HideBox(aState
.PresContext(), box
);
238 box
= box
->GetNextBox();
242 aState
.SetLayoutFlags(oldFlags
);