2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* base class for rendering objects that do not have child lists */
|
|
|
|
|
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
|
|
|
nsLeafFrame::~nsLeafFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsLeafFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLeafFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
|
|
|
result = GetIntrinsicWidth();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLeafFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
result = GetIntrinsicWidth();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-01-27 12:24:06 -08:00
|
|
|
/* virtual */ nsSize
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLeafFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
2008-01-27 12:24:06 -08:00
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSize aPadding, bool aShrinkWrap)
|
2008-01-27 12:24:06 -08:00
|
|
|
{
|
|
|
|
return nsSize(GetIntrinsicWidth(), GetIntrinsicHeight());
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLeafFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsLeafFrame");
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsLeafFrame::Reflow: aMaxSize=%d,%d",
|
2013-12-27 09:59:21 -08:00
|
|
|
aReflowState.AvailableWidth(), aReflowState.AvailableHeight()));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
2008-01-20 18:03:08 -08:00
|
|
|
DoReflow(aPresContext, aMetrics, aReflowState, aStatus);
|
|
|
|
|
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2008-01-20 18:03:08 -08:00
|
|
|
nsLeafFrame::DoReflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2008-01-27 12:24:06 -08:00
|
|
|
NS_ASSERTION(aReflowState.ComputedWidth() != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"Shouldn't have unconstrained stuff here "
|
|
|
|
"Thanks to the rules of reflow");
|
|
|
|
NS_ASSERTION(NS_INTRINSICSIZE != aReflowState.ComputedHeight(),
|
|
|
|
"Shouldn't have unconstrained stuff here "
|
|
|
|
"thanks to ComputeAutoSize");
|
|
|
|
|
2013-12-27 09:59:52 -08:00
|
|
|
aMetrics.Width() = aReflowState.ComputedWidth();
|
|
|
|
aMetrics.Height() = aReflowState.ComputedHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
AddBordersAndPadding(aReflowState, aMetrics);
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2008-01-20 18:03:08 -08:00
|
|
|
("exit nsLeafFrame::DoReflow: size=%d,%d",
|
2013-12-27 09:59:52 -08:00
|
|
|
aMetrics.Width(), aMetrics.Height()));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsLeafFrame::GetIntrinsicHeight()
|
|
|
|
{
|
2008-01-27 12:24:06 -08:00
|
|
|
NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize");
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX how should border&padding effect baseline alignment?
|
|
|
|
// => descent = borderPadding.bottom for example
|
|
|
|
void
|
|
|
|
nsLeafFrame::AddBordersAndPadding(const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aMetrics)
|
|
|
|
{
|
2013-12-27 09:59:52 -08:00
|
|
|
aMetrics.Width() += aReflowState.ComputedPhysicalBorderPadding().LeftRight();
|
|
|
|
aMetrics.Height() += aReflowState.ComputedPhysicalBorderPadding().TopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLeafFrame::SizeToAvailSize(const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Width() = aReflowState.AvailableWidth(); // FRAME
|
|
|
|
aDesiredSize.Height() = aReflowState.AvailableHeight();
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
}
|