michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsLegendFrame.h" michael@0: #include "nsIContent.h" michael@0: #include "nsGenericHTMLElement.h" michael@0: #include "nsAttrValueInlines.h" michael@0: #include "nsHTMLParts.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsStyleConsts.h" michael@0: #include "nsFormControlFrame.h" michael@0: michael@0: nsIFrame* michael@0: NS_NewLegendFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: #ifdef DEBUG michael@0: const nsStyleDisplay* disp = aContext->StyleDisplay(); michael@0: NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle() && !disp->IsFloatingStyle(), michael@0: "Legends should not be positioned and should not float"); michael@0: #endif michael@0: michael@0: nsIFrame* f = new (aPresShell) nsLegendFrame(aContext); michael@0: if (f) { michael@0: f->AddStateBits(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT); michael@0: } michael@0: return f; michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsLegendFrame) michael@0: michael@0: nsIAtom* michael@0: nsLegendFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::legendFrame; michael@0: } michael@0: michael@0: void michael@0: nsLegendFrame::DestroyFrom(nsIFrame* aDestructRoot) michael@0: { michael@0: nsFormControlFrame::RegUnRegAccessKey(static_cast(this), false); michael@0: nsBlockFrame::DestroyFrom(aDestructRoot); michael@0: } michael@0: michael@0: NS_QUERYFRAME_HEAD(nsLegendFrame) michael@0: NS_QUERYFRAME_ENTRY(nsLegendFrame) michael@0: NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame) michael@0: michael@0: nsresult michael@0: nsLegendFrame::Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aDesiredSize, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: DO_GLOBAL_REFLOW_COUNT("nsLegendFrame"); michael@0: DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); michael@0: if (mState & NS_FRAME_FIRST_REFLOW) { michael@0: nsFormControlFrame::RegUnRegAccessKey(static_cast(this), true); michael@0: } michael@0: return nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); michael@0: } michael@0: michael@0: // REVIEW: We don't need to override BuildDisplayList, nsBlockFrame will honour michael@0: // our visibility setting michael@0: int32_t nsLegendFrame::GetAlign() michael@0: { michael@0: int32_t intValue = NS_STYLE_TEXT_ALIGN_LEFT; michael@0: if (mParent && NS_STYLE_DIRECTION_RTL == mParent->StyleVisibility()->mDirection) { michael@0: intValue = NS_STYLE_TEXT_ALIGN_RIGHT; michael@0: } michael@0: michael@0: nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent); michael@0: michael@0: if (content) { michael@0: const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::align); michael@0: if (attr && attr->Type() == nsAttrValue::eEnum) { michael@0: intValue = attr->GetEnumValue(); michael@0: } michael@0: } michael@0: return intValue; michael@0: } michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: nsresult michael@0: nsLegendFrame::GetFrameName(nsAString& aResult) const michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("Legend"), aResult); michael@0: } michael@0: #endif