Bug 716875 - Make nsTextControlFrame inherits from nsContainerFrame instead of nsStackFrame. r=roc,bz

This commit is contained in:
Charly Molter
2012-06-23 13:11:00 +02:00
parent 9376a5ee50
commit 8dfebacb7d
4 changed files with 121 additions and 96 deletions

View File

@@ -92,7 +92,7 @@ NS_QUERYFRAME_HEAD(nsTextControlFrame)
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
NS_QUERYFRAME_ENTRY(nsITextControlFrame)
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
#ifdef ACCESSIBILITY
already_AddRefed<Accessible>
@@ -134,7 +134,7 @@ private:
#endif
nsTextControlFrame::nsTextControlFrame(nsIPresShell* aShell, nsStyleContext* aContext)
: nsStackFrame(aShell, aContext)
: nsContainerFrame(aContext)
, mUseEditor(false)
, mIsProcessing(false)
#ifdef DEBUG
@@ -166,7 +166,7 @@ nsTextControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
nsBoxFrame::DestroyFrom(aDestructRoot);
nsContainerFrame::DestroyFrom(aDestructRoot);
}
nsIAtom*
@@ -441,6 +441,20 @@ nsTextControlFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
aElements.MaybeAppendElement(txtCtrl->GetRootEditorNode());
if (!(aFilter & nsIContent::eSkipPlaceholderContent))
aElements.MaybeAppendElement(txtCtrl->GetPlaceholderNode());
}
nscoord
nsTextControlFrame::GetPrefWidth(nsRenderingContext* aRenderingContext)
{
nscoord result = 0;
DISPLAY_PREF_WIDTH(this, result);
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
nsSize autoSize;
CalcIntrinsicSize(aRenderingContext, autoSize, inflation);
return autoSize.width;
}
nscoord
@@ -472,22 +486,19 @@ nsTextControlFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
// Note: Ancestor ComputeAutoSize only computes a width if we're auto-width
else if (GetStylePosition()->mWidth.GetUnit() == eStyleUnit_Auto) {
nsSize ancestorAutoSize =
nsStackFrame::ComputeAutoSize(aRenderingContext,
aCBSize, aAvailableWidth,
aMargin, aBorder,
aPadding, aShrinkWrap);
nsContainerFrame::ComputeAutoSize(aRenderingContext,
aCBSize, aAvailableWidth,
aMargin, aBorder,
aPadding, aShrinkWrap);
// Disabled when there's inflation; see comment in GetPrefSize.
NS_ASSERTION(inflation != 1.0f || ancestorAutoSize.width == autoSize.width,
"Incorrect size computed by ComputeAutoSize?");
}
#endif
return autoSize;
}
// We inherit our GetPrefWidth from nsBoxFrame
NS_IMETHODIMP
nsTextControlFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
@@ -497,55 +508,98 @@ nsTextControlFrame::Reflow(nsPresContext* aPresContext,
DO_GLOBAL_REFLOW_COUNT("nsTextControlFrame");
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
// make sure the the form registers itself on the initial/first reflow
// make sure that the form registers itself on the initial/first reflow
if (mState & NS_FRAME_FIRST_REFLOW) {
nsFormControlFrame::RegUnRegAccessKey(this, true);
}
return nsStackFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
aStatus);
// set values of reflow's out parameters
aDesiredSize.width = aReflowState.ComputedWidth() +
aReflowState.mComputedBorderPadding.LeftRight();
aDesiredSize.height = NS_CSS_MINMAX(aReflowState.ComputedHeight(),
aReflowState.mComputedMinHeight,
aReflowState.mComputedMaxHeight);
nscoord lineHeight = aDesiredSize.height;
aDesiredSize.height += aReflowState.mComputedBorderPadding.TopBottom();
// computation of the ascent wrt the input height
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
if (!IsSingleLineTextControl()) {
lineHeight = nsHTMLReflowState::CalcLineHeight(GetStyleContext(),
NS_AUTOHEIGHT, inflation);
}
nsRefPtr<nsFontMetrics> fontMet;
nsresult rv = nsLayoutUtils::GetFontMetricsForFrame(this,
getter_AddRefs(fontMet),
inflation);
NS_ENSURE_SUCCESS(rv, rv);
// now adjust for our borders and padding
aDesiredSize.ascent =
nsLayoutUtils::GetCenteredFontBaseline(fontMet, lineHeight)
+ aReflowState.mComputedBorderPadding.top;
// overflow handling
aDesiredSize.SetOverflowAreasToDesiredBounds();
// perform reflow on all kids
nsIFrame* kid = mFrames.FirstChild();
while (kid) {
ReflowTextControlChild(kid, aPresContext, aReflowState, aStatus, aDesiredSize);
kid = kid->GetNextSibling();
}
// take into account css properties that affect overflow handling
FinishAndStoreOverflow(&aDesiredSize);
aStatus = NS_FRAME_COMPLETE;
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
return NS_OK;
}
nsSize
nsTextControlFrame::GetPrefSize(nsBoxLayoutState& aState)
void
nsTextControlFrame::ReflowTextControlChild(nsIFrame* aKid,
nsPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus,
nsHTMLReflowMetrics& aParentDesiredSize)
{
if (!DoesNeedRecalc(mPrefSize))
return mPrefSize;
// compute available size and frame offsets for child
nsSize availSize(aReflowState.ComputedWidth(),
aReflowState.ComputedHeight());
availSize.width = NS_MAX(availSize.width, 0);
availSize.height = NS_MAX(availSize.height, 0);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
aKid, availSize);
#ifdef DEBUG_LAYOUT
PropagateDebug(aState);
#endif
// Set computed width and computed height for the child
nscoord width = availSize.width;
width -= kidReflowState.mComputedMargin.LeftRight() +
kidReflowState.mComputedBorderPadding.LeftRight();
width = NS_MAX(width, 0);
kidReflowState.SetComputedWidth(width);
nsSize pref(0,0);
nscoord height = availSize.height;
height -= kidReflowState.mComputedMargin.TopBottom() +
kidReflowState.mComputedBorderPadding.TopBottom();
height = NS_MAX(height, 0);
kidReflowState.SetComputedHeight(height);
// FIXME: This inflation parameter isn't correct; we should fix it if
// we want font size inflation to work well in XUL. If we do, we can
// also re-enable the assertion in ComputeAutoSize when inflation is
// enabled.
nsresult rv = CalcIntrinsicSize(aState.GetRenderingContext(), pref, 1.0f);
NS_ENSURE_SUCCESS(rv, pref);
AddBorderAndPadding(pref);
// compute the offsets
nscoord xOffset = aReflowState.mComputedBorderPadding.left
+ kidReflowState.mComputedMargin.left;
nscoord yOffset = aReflowState.mComputedBorderPadding.top
+ kidReflowState.mComputedMargin.top;
bool widthSet, heightSet;
nsIBox::AddCSSPrefSize(this, pref, widthSet, heightSet);
// reflow the child
nsHTMLReflowMetrics desiredSize;
ReflowChild(aKid, aPresContext, desiredSize, kidReflowState,
xOffset, yOffset, 0, aStatus);
nsSize minSize = GetMinSize(aState);
nsSize maxSize = GetMaxSize(aState);
mPrefSize = BoundsCheck(minSize, pref, maxSize);
// place the child
FinishReflowChild(aKid, aPresContext, &kidReflowState,
desiredSize, xOffset, yOffset, 0);
#ifdef DEBUG_rods
{
nsMargin borderPadding(0,0,0,0);
GetBorderAndPadding(borderPadding);
nsSize size(169, 24);
nsSize actual(pref.width/15,
pref.height/15);
printf("nsGfxText(field) %d,%d %d,%d %d,%d\n",
size.width, size.height, actual.width, actual.height, actual.width-size.width, actual.height-size.height); // text field
}
#endif
return mPrefSize;
// consider the overflow
aParentDesiredSize.mOverflowAreas.UnionWith(desiredSize.mOverflowAreas);
}
nsSize
@@ -555,43 +609,6 @@ nsTextControlFrame::GetMinSize(nsBoxLayoutState& aState)
return nsBox::GetMinSize(aState);
}
nsSize
nsTextControlFrame::GetMaxSize(nsBoxLayoutState& aState)
{
// XXXbz why? Why not the nsBoxFrame sizes?
return nsBox::GetMaxSize(aState);
}
nscoord
nsTextControlFrame::GetBoxAscent(nsBoxLayoutState& aState)
{
// Return the baseline of the first (nominal) row, with centering for
// single-line controls.
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
// First calculate the ascent wrt the client rect
nsRect clientRect;
GetClientRect(clientRect);
nscoord lineHeight =
IsSingleLineTextControl() ? clientRect.height :
nsHTMLReflowState::CalcLineHeight(GetStyleContext(), NS_AUTOHEIGHT,
inflation);
nsRefPtr<nsFontMetrics> fontMet;
nsresult rv =
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet),
inflation);
NS_ENSURE_SUCCESS(rv, 0);
nscoord ascent = nsLayoutUtils::GetCenteredFontBaseline(fontMet, lineHeight);
// Now adjust for our borders and padding
ascent += clientRect.y;
return ascent;
}
bool
nsTextControlFrame::IsCollapsed()
{
@@ -1111,7 +1128,7 @@ nsTextControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
GetEditor(getter_AddRefs(editor));
}
if ((needEditor && !editor) || !selCon)
return nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);;
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
nsresult rv = NS_OK;
@@ -1180,7 +1197,7 @@ nsTextControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
// Allow the base class to handle common attributes supported
// by all form elements...
else {
rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
rv = nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
}
return rv;
@@ -1250,7 +1267,7 @@ NS_IMETHODIMP
nsTextControlFrame::SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList)
{
nsresult rv = nsBoxFrame::SetInitialChildList(aListID, aChildList);
nsresult rv = nsContainerFrame::SetInitialChildList(aListID, aChildList);
nsIFrame* first = GetFirstPrincipalChild();