зеркало из https://github.com/mozilla/gecko-dev.git
Eliminate nsStyleBorderPadding and add margin/padding/content rect APIs to nsIFrame. b=332922 r+sr=roc
This commit is contained in:
Родитель
15d1307833
Коммит
2084e073f8
|
@ -1149,12 +1149,7 @@ nsGenericHTMLElement::GetScrollWidth(PRInt32* aScrollWidth)
|
||||||
const nsSize
|
const nsSize
|
||||||
nsGenericHTMLElement::GetClientAreaSize(nsIFrame *aFrame)
|
nsGenericHTMLElement::GetClientAreaSize(nsIFrame *aFrame)
|
||||||
{
|
{
|
||||||
nsRect rect = aFrame->GetRect();
|
return aFrame->GetPaddingRect().Size();
|
||||||
nsMargin border_size = aFrame->GetUsedBorder();
|
|
||||||
|
|
||||||
rect.Deflate(border_size);
|
|
||||||
|
|
||||||
return nsSize(rect.width, rect.height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
|
|
@ -346,12 +346,7 @@ nsHTMLImageElement::GetWidthHeight()
|
||||||
if (frame) {
|
if (frame) {
|
||||||
// XXX we could put an accessor on nsIImageFrame to return its
|
// XXX we could put an accessor on nsIImageFrame to return its
|
||||||
// mComputedSize.....
|
// mComputedSize.....
|
||||||
size = frame->GetSize();
|
size = frame->GetContentRect().Size();
|
||||||
|
|
||||||
nsMargin margin = frame->GetUsedBorderAndPadding();
|
|
||||||
|
|
||||||
size.height -= margin.top + margin.bottom;
|
|
||||||
size.width -= margin.left + margin.right;
|
|
||||||
|
|
||||||
nsPresContext *context = GetPresContext();
|
nsPresContext *context = GetPresContext();
|
||||||
if (context) {
|
if (context) {
|
||||||
|
|
|
@ -616,15 +616,13 @@ nsImageDocument::CheckOverflowing(PRBool changeState)
|
||||||
nsRefPtr<nsStyleContext> styleContext =
|
nsRefPtr<nsStyleContext> styleContext =
|
||||||
context->StyleSet()->ResolveStyleFor(content, nsnull);
|
context->StyleSet()->ResolveStyleFor(content, nsnull);
|
||||||
|
|
||||||
const nsStyleMargin* marginData = styleContext->GetStyleMargin();
|
nsMargin m;
|
||||||
nsMargin margin;
|
if (styleContext->GetStyleMargin()->GetMargin(m))
|
||||||
marginData->GetMargin(margin);
|
visibleArea.Deflate(m);
|
||||||
visibleArea.Deflate(margin);
|
m = styleContext->GetStyleBorder()->GetBorder();
|
||||||
|
visibleArea.Deflate(m);
|
||||||
nsStyleBorderPadding bPad;
|
if (styleContext->GetStylePadding()->GetPadding(m))
|
||||||
styleContext->GetBorderPaddingFor(bPad);
|
visibleArea.Deflate(m);
|
||||||
bPad.GetBorderPadding(margin);
|
|
||||||
visibleArea.Deflate(margin);
|
|
||||||
|
|
||||||
float t2p;
|
float t2p;
|
||||||
t2p = context->TwipsToPixels();
|
t2p = context->TwipsToPixels();
|
||||||
|
|
|
@ -269,31 +269,22 @@ nsButtonFrameRenderer::GetButtonContentRect(const nsRect& aRect, nsRect& r)
|
||||||
nsMargin
|
nsMargin
|
||||||
nsButtonFrameRenderer::GetButtonOuterFocusBorderAndPadding()
|
nsButtonFrameRenderer::GetButtonOuterFocusBorderAndPadding()
|
||||||
{
|
{
|
||||||
nsMargin focusBorderAndPadding(0,0,0,0);
|
nsMargin result(0,0,0,0);
|
||||||
|
|
||||||
if (mOuterFocusStyle) {
|
if (mOuterFocusStyle) {
|
||||||
nsStyleBorderPadding bPad;
|
if (!mOuterFocusStyle->GetStylePadding()->GetPadding(result)) {
|
||||||
mOuterFocusStyle->GetBorderPaddingFor(bPad);
|
NS_NOTYETIMPLEMENTED("percentage padding");
|
||||||
if (!bPad.GetBorderPadding(focusBorderAndPadding)) {
|
|
||||||
NS_NOTYETIMPLEMENTED("percentage border");
|
|
||||||
}
|
}
|
||||||
|
result += mOuterFocusStyle->GetStyleBorder()->GetBorder();
|
||||||
}
|
}
|
||||||
|
|
||||||
return focusBorderAndPadding;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsMargin
|
nsMargin
|
||||||
nsButtonFrameRenderer::GetButtonBorderAndPadding()
|
nsButtonFrameRenderer::GetButtonBorderAndPadding()
|
||||||
{
|
{
|
||||||
nsStyleContext* context = mFrame->GetStyleContext();
|
return mFrame->GetUsedBorderAndPadding();
|
||||||
|
|
||||||
nsMargin innerFocusBorderAndPadding(0,0,0,0);
|
|
||||||
nsStyleBorderPadding bPad;
|
|
||||||
context->GetBorderPaddingFor(bPad);
|
|
||||||
if (!bPad.GetBorderPadding(innerFocusBorderAndPadding)) {
|
|
||||||
NS_NOTYETIMPLEMENTED("percentage border");
|
|
||||||
}
|
|
||||||
return innerFocusBorderAndPadding;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,9 +296,10 @@ nsButtonFrameRenderer::GetButtonInnerFocusMargin()
|
||||||
nsMargin innerFocusMargin(0,0,0,0);
|
nsMargin innerFocusMargin(0,0,0,0);
|
||||||
|
|
||||||
if (mInnerFocusStyle) {
|
if (mInnerFocusStyle) {
|
||||||
// get the outer focus border and padding
|
|
||||||
const nsStyleMargin* margin = mInnerFocusStyle->GetStyleMargin();
|
const nsStyleMargin* margin = mInnerFocusStyle->GetStyleMargin();
|
||||||
margin->GetMargin(innerFocusMargin);
|
if (!margin->GetMargin(innerFocusMargin)) {
|
||||||
|
NS_NOTYETIMPLEMENTED("percentage margin");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return innerFocusMargin;
|
return innerFocusMargin;
|
||||||
|
@ -316,18 +308,16 @@ nsButtonFrameRenderer::GetButtonInnerFocusMargin()
|
||||||
nsMargin
|
nsMargin
|
||||||
nsButtonFrameRenderer::GetButtonInnerFocusBorderAndPadding()
|
nsButtonFrameRenderer::GetButtonInnerFocusBorderAndPadding()
|
||||||
{
|
{
|
||||||
nsMargin innerFocusBorderAndPadding(0,0,0,0);
|
nsMargin result(0,0,0,0);
|
||||||
|
|
||||||
if (mInnerFocusStyle) {
|
if (mInnerFocusStyle) {
|
||||||
// get the outer focus border and padding
|
if (!mInnerFocusStyle->GetStylePadding()->GetPadding(result)) {
|
||||||
nsStyleBorderPadding bPad;
|
NS_NOTYETIMPLEMENTED("percentage padding");
|
||||||
mInnerFocusStyle->GetBorderPaddingFor(bPad);
|
|
||||||
if (!bPad.GetBorderPadding(innerFocusBorderAndPadding)) {
|
|
||||||
NS_NOTYETIMPLEMENTED("percentage border");
|
|
||||||
}
|
}
|
||||||
|
result += mInnerFocusStyle->GetStyleBorder()->GetBorder();
|
||||||
}
|
}
|
||||||
|
|
||||||
return innerFocusBorderAndPadding;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsMargin
|
nsMargin
|
||||||
|
|
|
@ -216,10 +216,8 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIRenderingContext& aRenderingContext,
|
||||||
{
|
{
|
||||||
// REVIEW: moved the mAppearance test out so we avoid constructing
|
// REVIEW: moved the mAppearance test out so we avoid constructing
|
||||||
// a display item if it's not needed
|
// a display item if it's not needed
|
||||||
nsMargin borderPadding = GetUsedBorderAndPadding();
|
|
||||||
|
|
||||||
nsRect checkRect(aPt, mRect.Size());
|
nsRect checkRect(aPt, mRect.Size());
|
||||||
checkRect.Deflate(borderPadding);
|
checkRect.Deflate(GetUsedBorderAndPadding());
|
||||||
|
|
||||||
const nsStyleColor* color = GetStyleColor();
|
const nsStyleColor* color = GetStyleColor();
|
||||||
aRenderingContext.SetColor(color->mColor);
|
aRenderingContext.SetColor(color->mColor);
|
||||||
|
|
|
@ -736,6 +736,50 @@ nsIFrame::GetUsedPadding() const
|
||||||
return padding;
|
return padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsIFrame::ApplySkipSides(nsMargin& aMargin) const
|
||||||
|
{
|
||||||
|
PRIntn skipSides = GetSkipSides();
|
||||||
|
if (skipSides & (1 << NS_SIDE_TOP))
|
||||||
|
aMargin.top = 0;
|
||||||
|
if (skipSides & (1 << NS_SIDE_RIGHT))
|
||||||
|
aMargin.right = 0;
|
||||||
|
if (skipSides & (1 << NS_SIDE_BOTTOM))
|
||||||
|
aMargin.bottom = 0;
|
||||||
|
if (skipSides & (1 << NS_SIDE_LEFT))
|
||||||
|
aMargin.left = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsRect
|
||||||
|
nsIFrame::GetMarginRect() const
|
||||||
|
{
|
||||||
|
nsMargin m(GetUsedMargin());
|
||||||
|
ApplySkipSides(m);
|
||||||
|
nsRect r(mRect);
|
||||||
|
r.Inflate(m);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsRect
|
||||||
|
nsIFrame::GetPaddingRect() const
|
||||||
|
{
|
||||||
|
nsMargin b(GetUsedBorder());
|
||||||
|
ApplySkipSides(b);
|
||||||
|
nsRect r(mRect);
|
||||||
|
r.Deflate(b);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsRect
|
||||||
|
nsIFrame::GetContentRect() const
|
||||||
|
{
|
||||||
|
nsMargin bp(GetUsedBorderAndPadding());
|
||||||
|
ApplySkipSides(bp);
|
||||||
|
nsRect r(mRect);
|
||||||
|
r.Deflate(bp);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
nsStyleContext*
|
nsStyleContext*
|
||||||
nsFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
|
nsFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -698,6 +698,20 @@ public:
|
||||||
return GetUsedBorder() + GetUsedPadding();
|
return GetUsedBorder() + GetUsedPadding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the result of GetSkipSides() on this frame to an nsMargin by
|
||||||
|
* setting to zero any sides that are skipped.
|
||||||
|
*/
|
||||||
|
void ApplySkipSides(nsMargin& aMargin) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like the frame's rect (see |GetRect|), which is the border rect,
|
||||||
|
* other rectangles of the frame, in twips, relative to the parent.
|
||||||
|
*/
|
||||||
|
nsRect GetMarginRect() const;
|
||||||
|
nsRect GetPaddingRect() const;
|
||||||
|
nsRect GetContentRect() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to iterate the list of additional child list names. Returns the atom
|
* Used to iterate the list of additional child list names. Returns the atom
|
||||||
* name for the additional child list at the specified 0-based index, or a
|
* name for the additional child list at the specified 0-based index, or a
|
||||||
|
|
|
@ -2066,10 +2066,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
nsMargin borderPadding = frame->GetUsedBorderAndPadding();
|
adjSize = frame->GetContentRect().Size();
|
||||||
nsRect rect(frame->GetRect());
|
|
||||||
rect.Deflate(borderPadding);
|
|
||||||
adjSize = rect.Size();
|
|
||||||
documentIsTopLevel = PR_FALSE;
|
documentIsTopLevel = PR_FALSE;
|
||||||
// presshell exists because parent is printable
|
// presshell exists because parent is printable
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2650,10 +2650,7 @@ nsComputedDOMStyle::GetHeight(nsIFrame *aFrame,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calcHeight) {
|
if (calcHeight) {
|
||||||
nsMargin bp = aFrame->GetUsedBorderAndPadding();
|
val->SetTwips(aFrame->GetContentRect().height);
|
||||||
nsSize size = aFrame->GetSize();
|
|
||||||
|
|
||||||
val->SetTwips(size.height - bp.TopBottom());
|
|
||||||
} else {
|
} else {
|
||||||
// Just return the value in the style context
|
// Just return the value in the style context
|
||||||
const nsStylePosition* positionData = GetStylePosition(aFrame);
|
const nsStylePosition* positionData = GetStylePosition(aFrame);
|
||||||
|
@ -2701,9 +2698,7 @@ nsComputedDOMStyle::GetWidth(nsIFrame *aFrame,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calcWidth) {
|
if (calcWidth) {
|
||||||
nsSize size = aFrame->GetSize();
|
val->SetTwips(aFrame->GetContentRect().width);
|
||||||
nsMargin bp = aFrame->GetUsedBorderAndPadding();
|
|
||||||
val->SetTwips(size.width - bp.LeftRight());
|
|
||||||
} else {
|
} else {
|
||||||
// Just return the value in the style context
|
// Just return the value in the style context
|
||||||
const nsStylePosition *positionData = GetStylePosition(aFrame);
|
const nsStylePosition *positionData = GetStylePosition(aFrame);
|
||||||
|
@ -3082,14 +3077,11 @@ nsComputedDOMStyle::GetRelativeOffset(PRUint8 aSide, nsIFrame* aFrame,
|
||||||
case eStyleUnit_Percent:
|
case eStyleUnit_Percent:
|
||||||
container = GetContainingBlockFor(aFrame);
|
container = GetContainingBlockFor(aFrame);
|
||||||
if (container) {
|
if (container) {
|
||||||
nsMargin bp = container->GetUsedBorderAndPadding();
|
nsSize size = container->GetContentRect().Size();
|
||||||
nsSize size = container->GetSize();
|
|
||||||
if (aSide == NS_SIDE_LEFT || aSide == NS_SIDE_RIGHT) {
|
if (aSide == NS_SIDE_LEFT || aSide == NS_SIDE_RIGHT) {
|
||||||
val->SetTwips(sign * coord.GetPercentValue() *
|
val->SetTwips(sign * coord.GetPercentValue() * size.width);
|
||||||
(size.width - bp.LeftRight()));
|
|
||||||
} else {
|
} else {
|
||||||
val->SetTwips(sign * coord.GetPercentValue() *
|
val->SetTwips(sign * coord.GetPercentValue() * size.height);
|
||||||
(size.height - bp.TopBottom()));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// XXX no containing block.
|
// XXX no containing block.
|
||||||
|
|
|
@ -245,16 +245,6 @@ inline const nsStyleStruct* nsStyleContext::PeekStyleData(nsStyleStructID aSID)
|
||||||
return mRuleNode->GetStyleData(aSID, this, PR_FALSE); // Our rule node will take care of it for us.
|
return mRuleNode->GetStyleData(aSID, this, PR_FALSE); // Our rule node will take care of it for us.
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
nsStyleContext::GetBorderPaddingFor(nsStyleBorderPadding& aBorderPadding)
|
|
||||||
{
|
|
||||||
nsMargin padding;
|
|
||||||
if (GetStylePadding()->GetPadding(padding)) {
|
|
||||||
padding += GetStyleBorder()->GetBorder();
|
|
||||||
aBorderPadding.SetBorderPadding(padding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is an evil evil function, since it forces you to alloc your own separate copy of
|
// This is an evil evil function, since it forces you to alloc your own separate copy of
|
||||||
// style data! Do not use this function unless you absolutely have to! You should avoid
|
// style data! Do not use this function unless you absolutely have to! You should avoid
|
||||||
// this at all costs! -dwh
|
// this at all costs! -dwh
|
||||||
|
|
|
@ -109,8 +109,6 @@ public:
|
||||||
NS_HIDDEN_(PRBool) Equals(const nsStyleContext* aOther) const;
|
NS_HIDDEN_(PRBool) Equals(const nsStyleContext* aOther) const;
|
||||||
PRBool HasTextDecorations() { return mBits & NS_STYLE_HAS_TEXT_DECORATIONS; };
|
PRBool HasTextDecorations() { return mBits & NS_STYLE_HAS_TEXT_DECORATIONS; };
|
||||||
|
|
||||||
NS_HIDDEN_(void) GetBorderPaddingFor(nsStyleBorderPadding& aBorderPadding);
|
|
||||||
|
|
||||||
NS_HIDDEN_(void) SetStyle(nsStyleStructID aSID, nsStyleStruct* aStruct);
|
NS_HIDDEN_(void) SetStyle(nsStyleStructID aSID, nsStyleStruct* aStruct);
|
||||||
|
|
||||||
nsRuleNode* GetRuleNode() { return mRuleNode; }
|
nsRuleNode* GetRuleNode() { return mRuleNode; }
|
||||||
|
|
|
@ -478,32 +478,6 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct nsStyleBorderPadding: public nsStyleStruct {
|
|
||||||
nsStyleBorderPadding(void) { mHasCachedBorderPadding = PR_FALSE; };
|
|
||||||
~nsStyleBorderPadding(void) {};
|
|
||||||
|
|
||||||
// No accessor for this struct, since it's not a real struct. At
|
|
||||||
// least not for now...
|
|
||||||
|
|
||||||
PRBool GetBorderPadding(nsMargin& aBorderPadding) const {
|
|
||||||
if (mHasCachedBorderPadding) {
|
|
||||||
aBorderPadding = mCachedBorderPadding;
|
|
||||||
return PR_TRUE;
|
|
||||||
}
|
|
||||||
return PR_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetBorderPadding(nsMargin aBorderPadding) {
|
|
||||||
mCachedBorderPadding = aBorderPadding;
|
|
||||||
mHasCachedBorderPadding = PR_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
nsMargin mCachedBorderPadding;
|
|
||||||
PRPackedBool mHasCachedBorderPadding;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct nsStyleOutline: public nsStyleStruct {
|
struct nsStyleOutline: public nsStyleStruct {
|
||||||
nsStyleOutline(nsPresContext* aPresContext);
|
nsStyleOutline(nsPresContext* aPresContext);
|
||||||
nsStyleOutline(const nsStyleOutline& aOutline);
|
nsStyleOutline(const nsStyleOutline& aOutline);
|
||||||
|
|
|
@ -781,14 +781,11 @@ nsListBoxBodyFrame::ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState)
|
||||||
nscoord width = 0;
|
nscoord width = 0;
|
||||||
nsMargin margin(0,0,0,0);
|
nsMargin margin(0,0,0,0);
|
||||||
|
|
||||||
nsStyleBorderPadding bPad;
|
if (styleContext->GetStylePadding()->GetPadding(margin))
|
||||||
styleContext->GetBorderPaddingFor(bPad);
|
width += margin.LeftRight();
|
||||||
bPad.GetBorderPadding(margin);
|
width += styleContext->GetStyleBorder()->GetBorder().LeftRight();
|
||||||
|
if (styleContext->GetStyleMargin()->GetMargin(margin))
|
||||||
width += (margin.left + margin.right);
|
width += margin.LeftRight();
|
||||||
|
|
||||||
styleContext->GetStyleMargin()->GetMargin(margin);
|
|
||||||
width += (margin.left + margin.right);
|
|
||||||
|
|
||||||
nsIContent* listbox = mContent->GetBindingParent();
|
nsIContent* listbox = mContent->GetBindingParent();
|
||||||
NS_ENSURE_TRUE(listbox, largestWidth);
|
NS_ENSURE_TRUE(listbox, largestWidth);
|
||||||
|
|
|
@ -322,13 +322,8 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext,
|
||||||
if (mTitle.IsEmpty())
|
if (mTitle.IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nsStyleBorderPadding bPad;
|
|
||||||
mStyleContext->GetBorderPaddingFor(bPad);
|
|
||||||
nsMargin border(0,0,0,0);
|
|
||||||
bPad.GetBorderPadding(border);
|
|
||||||
|
|
||||||
nsRect textRect(aPt, GetSize());
|
nsRect textRect(aPt, GetSize());
|
||||||
textRect.Deflate(border);
|
textRect.Deflate(GetUsedBorderAndPadding());
|
||||||
|
|
||||||
// determine (cropped) title and underline position
|
// determine (cropped) title and underline position
|
||||||
nsPresContext* presContext = GetPresContext();
|
nsPresContext* presContext = GetPresContext();
|
||||||
|
|
|
@ -187,9 +187,11 @@ nsTreeBodyFrame::Release(void)
|
||||||
static void
|
static void
|
||||||
GetBorderPadding(nsStyleContext* aContext, nsMargin& aMargin)
|
GetBorderPadding(nsStyleContext* aContext, nsMargin& aMargin)
|
||||||
{
|
{
|
||||||
nsStyleBorderPadding borderPaddingStyle;
|
aMargin.SizeTo(0, 0, 0, 0);
|
||||||
aContext->GetBorderPaddingFor(borderPaddingStyle);
|
if (!aContext->GetStylePadding()->GetPadding(aMargin)) {
|
||||||
borderPaddingStyle.GetBorderPadding(aMargin);
|
NS_NOTYETIMPLEMENTED("percentage padding");
|
||||||
|
}
|
||||||
|
aMargin += aContext->GetStyleBorder()->GetBorder();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Загрузка…
Ссылка в новой задаче