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.org 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 ***** */
38 #include "nsLegendFrame.h"
39 #include "nsIContent.h"
41 #include "nsGenericHTMLElement.h"
42 #include "nsHTMLParts.h"
43 #include "nsGkAtoms.h"
44 #include "nsStyleConsts.h"
45 #include "nsFormControlFrame.h"
48 NS_NewLegendFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
51 const nsStyleDisplay
* disp
= aContext
->GetStyleDisplay();
52 NS_ASSERTION(!disp
->IsAbsolutelyPositioned() && !disp
->IsFloating(),
53 "Legends should not be positioned and should not float");
56 nsIFrame
* f
= new (aPresShell
) nsLegendFrame(aContext
);
58 f
->AddStateBits(NS_BLOCK_FLOAT_MGR
| NS_BLOCK_MARGIN_ROOT
);
63 NS_IMPL_FRAMEARENA_HELPERS(nsLegendFrame
)
66 nsLegendFrame::GetType() const
68 return nsGkAtoms::legendFrame
;
72 nsLegendFrame::DestroyFrom(nsIFrame
* aDestructRoot
)
74 nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame
*>(this), PR_FALSE
);
75 nsBlockFrame::DestroyFrom(aDestructRoot
);
78 NS_QUERYFRAME_HEAD(nsLegendFrame
)
79 NS_QUERYFRAME_ENTRY(nsLegendFrame
)
80 NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame
)
83 nsLegendFrame::Reflow(nsPresContext
* aPresContext
,
84 nsHTMLReflowMetrics
& aDesiredSize
,
85 const nsHTMLReflowState
& aReflowState
,
86 nsReflowStatus
& aStatus
)
88 DO_GLOBAL_REFLOW_COUNT("nsLegendFrame");
89 DISPLAY_REFLOW(aPresContext
, this, aReflowState
, aDesiredSize
, aStatus
);
90 if (mState
& NS_FRAME_FIRST_REFLOW
) {
91 nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame
*>(this), PR_TRUE
);
93 return nsBlockFrame::Reflow(aPresContext
, aDesiredSize
, aReflowState
, aStatus
);
96 // REVIEW: We don't need to override BuildDisplayList, nsBlockFrame will honour
97 // our visibility setting
98 PRInt32
nsLegendFrame::GetAlign()
100 PRInt32 intValue
= NS_STYLE_TEXT_ALIGN_LEFT
;
102 if (mParent
&& NS_STYLE_DIRECTION_RTL
== mParent
->GetStyleVisibility()->mDirection
) {
103 intValue
= NS_STYLE_TEXT_ALIGN_RIGHT
;
107 nsGenericHTMLElement
*content
= nsGenericHTMLElement::FromContent(mContent
);
110 const nsAttrValue
* attr
= content
->GetParsedAttr(nsGkAtoms::align
);
111 if (attr
&& attr
->Type() == nsAttrValue::eEnum
) {
112 intValue
= attr
->GetEnumValue();
120 nsLegendFrame::GetFrameName(nsAString
& aResult
) const
122 return MakeFrameName(NS_LITERAL_STRING("Legend"), aResult
);