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: /* base class for rendering objects that do not have child lists */ michael@0: michael@0: #include "nsLeafFrame.h" michael@0: #include "nsPresContext.h" michael@0: michael@0: nsLeafFrame::~nsLeafFrame() michael@0: { michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsLeafFrame) michael@0: michael@0: /* virtual */ nscoord michael@0: nsLeafFrame::GetMinWidth(nsRenderingContext *aRenderingContext) michael@0: { michael@0: nscoord result; michael@0: DISPLAY_MIN_WIDTH(this, result); michael@0: michael@0: result = GetIntrinsicWidth(); michael@0: return result; michael@0: } michael@0: michael@0: /* virtual */ nscoord michael@0: nsLeafFrame::GetPrefWidth(nsRenderingContext *aRenderingContext) michael@0: { michael@0: nscoord result; michael@0: DISPLAY_PREF_WIDTH(this, result); michael@0: result = GetIntrinsicWidth(); michael@0: return result; michael@0: } michael@0: michael@0: /* virtual */ nsSize michael@0: nsLeafFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext, michael@0: nsSize aCBSize, nscoord aAvailableWidth, michael@0: nsSize aMargin, nsSize aBorder, michael@0: nsSize aPadding, bool aShrinkWrap) michael@0: { michael@0: return nsSize(GetIntrinsicWidth(), GetIntrinsicHeight()); michael@0: } michael@0: michael@0: nsresult michael@0: nsLeafFrame::Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aMetrics, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: DO_GLOBAL_REFLOW_COUNT("nsLeafFrame"); michael@0: NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, michael@0: ("enter nsLeafFrame::Reflow: aMaxSize=%d,%d", michael@0: aReflowState.AvailableWidth(), aReflowState.AvailableHeight())); michael@0: michael@0: NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow"); michael@0: michael@0: DoReflow(aPresContext, aMetrics, aReflowState, aStatus); michael@0: michael@0: FinishAndStoreOverflow(&aMetrics); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsLeafFrame::DoReflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aMetrics, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: NS_ASSERTION(aReflowState.ComputedWidth() != NS_UNCONSTRAINEDSIZE, michael@0: "Shouldn't have unconstrained stuff here " michael@0: "Thanks to the rules of reflow"); michael@0: NS_ASSERTION(NS_INTRINSICSIZE != aReflowState.ComputedHeight(), michael@0: "Shouldn't have unconstrained stuff here " michael@0: "thanks to ComputeAutoSize"); michael@0: michael@0: aMetrics.Width() = aReflowState.ComputedWidth(); michael@0: aMetrics.Height() = aReflowState.ComputedHeight(); michael@0: michael@0: AddBordersAndPadding(aReflowState, aMetrics); michael@0: aStatus = NS_FRAME_COMPLETE; michael@0: michael@0: NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, michael@0: ("exit nsLeafFrame::DoReflow: size=%d,%d", michael@0: aMetrics.Width(), aMetrics.Height())); michael@0: NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics); michael@0: michael@0: aMetrics.SetOverflowAreasToDesiredBounds(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nscoord michael@0: nsLeafFrame::GetIntrinsicHeight() michael@0: { michael@0: NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize"); michael@0: return 0; michael@0: } michael@0: michael@0: // XXX how should border&padding effect baseline alignment? michael@0: // => descent = borderPadding.bottom for example michael@0: void michael@0: nsLeafFrame::AddBordersAndPadding(const nsHTMLReflowState& aReflowState, michael@0: nsHTMLReflowMetrics& aMetrics) michael@0: { michael@0: aMetrics.Width() += aReflowState.ComputedPhysicalBorderPadding().LeftRight(); michael@0: aMetrics.Height() += aReflowState.ComputedPhysicalBorderPadding().TopBottom(); michael@0: } michael@0: michael@0: void michael@0: nsLeafFrame::SizeToAvailSize(const nsHTMLReflowState& aReflowState, michael@0: nsHTMLReflowMetrics& aDesiredSize) michael@0: { michael@0: aDesiredSize.Width() = aReflowState.AvailableWidth(); // FRAME michael@0: aDesiredSize.Height() = aReflowState.AvailableHeight(); michael@0: aDesiredSize.SetOverflowAreasToDesiredBounds(); michael@0: FinishAndStoreOverflow(&aDesiredSize); michael@0: }