Line data Source 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/. */
5 :
6 : #include "nsLegendFrame.h"
7 : #include "nsIContent.h"
8 : #include "nsGenericHTMLElement.h"
9 : #include "nsAttrValueInlines.h"
10 : #include "nsHTMLParts.h"
11 : #include "nsGkAtoms.h"
12 : #include "nsStyleConsts.h"
13 : #include "nsFormControlFrame.h"
14 :
15 : nsIFrame*
16 0 : NS_NewLegendFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
17 : {
18 : #ifdef DEBUG
19 0 : const nsStyleDisplay* disp = aContext->StyleDisplay();
20 0 : NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle() && !disp->IsFloatingStyle(),
21 : "Legends should not be positioned and should not float");
22 : #endif
23 :
24 0 : nsIFrame* f = new (aPresShell) nsLegendFrame(aContext);
25 0 : f->AddStateBits(NS_BLOCK_FORMATTING_CONTEXT_STATE_BITS);
26 0 : return f;
27 : }
28 :
29 0 : NS_IMPL_FRAMEARENA_HELPERS(nsLegendFrame)
30 :
31 : void
32 0 : nsLegendFrame::DestroyFrom(nsIFrame* aDestructRoot)
33 : {
34 0 : nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
35 0 : nsBlockFrame::DestroyFrom(aDestructRoot);
36 0 : }
37 :
38 0 : NS_QUERYFRAME_HEAD(nsLegendFrame)
39 0 : NS_QUERYFRAME_ENTRY(nsLegendFrame)
40 0 : NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
41 :
42 : void
43 0 : nsLegendFrame::Reflow(nsPresContext* aPresContext,
44 : ReflowOutput& aDesiredSize,
45 : const ReflowInput& aReflowInput,
46 : nsReflowStatus& aStatus)
47 : {
48 0 : DO_GLOBAL_REFLOW_COUNT("nsLegendFrame");
49 0 : DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
50 0 : if (mState & NS_FRAME_FIRST_REFLOW) {
51 0 : nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
52 : }
53 0 : return nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
54 : }
55 :
56 : int32_t
57 0 : nsLegendFrame::GetLogicalAlign(WritingMode aCBWM)
58 : {
59 0 : int32_t intValue = NS_STYLE_TEXT_ALIGN_START;
60 0 : nsGenericHTMLElement* content = nsGenericHTMLElement::FromContent(mContent);
61 0 : if (content) {
62 0 : const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::align);
63 0 : if (attr && attr->Type() == nsAttrValue::eEnum) {
64 0 : intValue = attr->GetEnumValue();
65 0 : switch (intValue) {
66 : case NS_STYLE_TEXT_ALIGN_LEFT:
67 0 : intValue = aCBWM.IsBidiLTR() ? NS_STYLE_TEXT_ALIGN_START
68 : : NS_STYLE_TEXT_ALIGN_END;
69 0 : break;
70 : case NS_STYLE_TEXT_ALIGN_RIGHT:
71 0 : intValue = aCBWM.IsBidiLTR() ? NS_STYLE_TEXT_ALIGN_END
72 : : NS_STYLE_TEXT_ALIGN_START;
73 0 : break;
74 : }
75 : }
76 : }
77 0 : return intValue;
78 : }
79 :
80 : #ifdef DEBUG_FRAME_DUMP
81 : nsresult
82 0 : nsLegendFrame::GetFrameName(nsAString& aResult) const
83 : {
84 0 : return MakeFrameName(NS_LITERAL_STRING("Legend"), aResult);
85 : }
86 : #endif
|