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

This commit is contained in:
Charly Molter ext:(%20and%20Alexandre%20Dumont%20%3CAlexandre%20Dumont%20%3E) 2012-06-23 13:11:00 +02:00
parent d9ec3587ea
commit ac1373cebd
4 changed files with 121 additions and 96 deletions

View File

@ -43,7 +43,7 @@ load 538062-1.xhtml
load 570624-1.html
load 498698-1.html
asserts(1) load 578604-1.html # bug 584564
asserts(3-5) load 590302-1.xhtml # bug 584564
asserts(4-7) load 590302-1.xhtml # bug 584564
load 626014.xhtml
load 639733.xhtml
asserts(0-1) load 669767.html

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();

View File

@ -6,7 +6,7 @@
#ifndef nsTextControlFrame_h___
#define nsTextControlFrame_h___
#include "nsStackFrame.h"
#include "nsContainerFrame.h"
#include "nsBlockFrame.h"
#include "nsIFormControlFrame.h"
#include "nsIAnonymousContentCreator.h"
@ -32,7 +32,7 @@ class Element;
}
}
class nsTextControlFrame : public nsStackFrame,
class nsTextControlFrame : public nsContainerFrame,
public nsIAnonymousContentCreator,
public nsITextControlFrame,
public nsIStatefulFrame
@ -54,6 +54,8 @@ public:
}
virtual nscoord GetMinWidth(nsRenderingContext* aRenderingContext);
virtual nscoord GetPrefWidth(nsRenderingContext* aRenderingContext);
virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext,
nsSize aCBSize, nscoord aAvailableWidth,
nsSize aMargin, nsSize aBorder,
@ -64,13 +66,10 @@ public:
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState);
virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState);
virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState);
virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState);
virtual bool IsCollapsed();
DECL_DO_GLOBAL_REFLOW_COUNT_DSP(nsTextControlFrame, nsStackFrame)
DECL_DO_GLOBAL_REFLOW_COUNT_DSP(nsTextControlFrame, nsContainerFrame)
virtual bool IsLeaf() const;
@ -90,7 +89,7 @@ public:
{
// nsStackFrame is already both of these, but that's somewhat bogus,
// and we really mean it.
return nsStackFrame::IsFrameOfType(aFlags &
return nsContainerFrame::IsFrameOfType(aFlags &
~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
}
@ -163,6 +162,15 @@ public:
// We could make these auto-Revoking via the "delete" entry for safety
NS_DECLARE_FRAME_PROPERTY(TextControlInitializer, nsnull)
protected:
/**
* Launch the reflow on the child frames - see nsTextControlFrame::Reflow()
*/
void ReflowTextControlChild(nsIFrame* aFrame,
nsPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus,
nsHTMLReflowMetrics& aParentDesiredSize);
public: //for methods who access nsTextControlFrame directly
void SetValueChanged(bool aValueChanged);

View File

@ -14,7 +14,7 @@ load 310556-1.xhtml
load 322780-1.xul
load 323381-1.html
load 323381-2.html
asserts(2) asserts-if(gtk2Widget,17) load 323386-1.html # Bug 575011
asserts-if(gtk2Widget,13) load 323386-1.html # Bug 575011
load 323389-1.html
load 323389-2.html
load 323493-1.html