Eliminate nsStyleBorderPadding and add margin/padding/content rect APIs to nsIFrame. b=332922 r+sr=roc

This commit is contained in:
dbaron%dbaron.org 2006-12-20 01:23:45 +00:00
Родитель 15d1307833
Коммит 2084e073f8
15 изменённых файлов: 99 добавлений и 120 удалений

Просмотреть файл

@ -1149,12 +1149,7 @@ nsGenericHTMLElement::GetScrollWidth(PRInt32* aScrollWidth)
const nsSize
nsGenericHTMLElement::GetClientAreaSize(nsIFrame *aFrame)
{
nsRect rect = aFrame->GetRect();
nsMargin border_size = aFrame->GetUsedBorder();
rect.Deflate(border_size);
return nsSize(rect.width, rect.height);
return aFrame->GetPaddingRect().Size();
}
nsresult

Просмотреть файл

@ -346,12 +346,7 @@ nsHTMLImageElement::GetWidthHeight()
if (frame) {
// XXX we could put an accessor on nsIImageFrame to return its
// mComputedSize.....
size = frame->GetSize();
nsMargin margin = frame->GetUsedBorderAndPadding();
size.height -= margin.top + margin.bottom;
size.width -= margin.left + margin.right;
size = frame->GetContentRect().Size();
nsPresContext *context = GetPresContext();
if (context) {

Просмотреть файл

@ -616,15 +616,13 @@ nsImageDocument::CheckOverflowing(PRBool changeState)
nsRefPtr<nsStyleContext> styleContext =
context->StyleSet()->ResolveStyleFor(content, nsnull);
const nsStyleMargin* marginData = styleContext->GetStyleMargin();
nsMargin margin;
marginData->GetMargin(margin);
visibleArea.Deflate(margin);
nsStyleBorderPadding bPad;
styleContext->GetBorderPaddingFor(bPad);
bPad.GetBorderPadding(margin);
visibleArea.Deflate(margin);
nsMargin m;
if (styleContext->GetStyleMargin()->GetMargin(m))
visibleArea.Deflate(m);
m = styleContext->GetStyleBorder()->GetBorder();
visibleArea.Deflate(m);
if (styleContext->GetStylePadding()->GetPadding(m))
visibleArea.Deflate(m);
float t2p;
t2p = context->TwipsToPixels();

Просмотреть файл

@ -269,31 +269,22 @@ nsButtonFrameRenderer::GetButtonContentRect(const nsRect& aRect, nsRect& r)
nsMargin
nsButtonFrameRenderer::GetButtonOuterFocusBorderAndPadding()
{
nsMargin focusBorderAndPadding(0,0,0,0);
nsMargin result(0,0,0,0);
if (mOuterFocusStyle) {
nsStyleBorderPadding bPad;
mOuterFocusStyle->GetBorderPaddingFor(bPad);
if (!bPad.GetBorderPadding(focusBorderAndPadding)) {
NS_NOTYETIMPLEMENTED("percentage border");
if (!mOuterFocusStyle->GetStylePadding()->GetPadding(result)) {
NS_NOTYETIMPLEMENTED("percentage padding");
}
result += mOuterFocusStyle->GetStyleBorder()->GetBorder();
}
return focusBorderAndPadding;
return result;
}
nsMargin
nsButtonFrameRenderer::GetButtonBorderAndPadding()
{
nsStyleContext* context = mFrame->GetStyleContext();
nsMargin innerFocusBorderAndPadding(0,0,0,0);
nsStyleBorderPadding bPad;
context->GetBorderPaddingFor(bPad);
if (!bPad.GetBorderPadding(innerFocusBorderAndPadding)) {
NS_NOTYETIMPLEMENTED("percentage border");
}
return innerFocusBorderAndPadding;
return mFrame->GetUsedBorderAndPadding();
}
/**
@ -305,9 +296,10 @@ nsButtonFrameRenderer::GetButtonInnerFocusMargin()
nsMargin innerFocusMargin(0,0,0,0);
if (mInnerFocusStyle) {
// get the outer focus border and padding
const nsStyleMargin* margin = mInnerFocusStyle->GetStyleMargin();
margin->GetMargin(innerFocusMargin);
if (!margin->GetMargin(innerFocusMargin)) {
NS_NOTYETIMPLEMENTED("percentage margin");
}
}
return innerFocusMargin;
@ -316,18 +308,16 @@ nsButtonFrameRenderer::GetButtonInnerFocusMargin()
nsMargin
nsButtonFrameRenderer::GetButtonInnerFocusBorderAndPadding()
{
nsMargin innerFocusBorderAndPadding(0,0,0,0);
nsMargin result(0,0,0,0);
if (mInnerFocusStyle) {
// get the outer focus border and padding
nsStyleBorderPadding bPad;
mInnerFocusStyle->GetBorderPaddingFor(bPad);
if (!bPad.GetBorderPadding(innerFocusBorderAndPadding)) {
NS_NOTYETIMPLEMENTED("percentage border");
if (!mInnerFocusStyle->GetStylePadding()->GetPadding(result)) {
NS_NOTYETIMPLEMENTED("percentage padding");
}
result += mInnerFocusStyle->GetStyleBorder()->GetBorder();
}
return innerFocusBorderAndPadding;
return result;
}
nsMargin

Просмотреть файл

@ -216,10 +216,8 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIRenderingContext& aRenderingContext,
{
// REVIEW: moved the mAppearance test out so we avoid constructing
// a display item if it's not needed
nsMargin borderPadding = GetUsedBorderAndPadding();
nsRect checkRect(aPt, mRect.Size());
checkRect.Deflate(borderPadding);
checkRect.Deflate(GetUsedBorderAndPadding());
const nsStyleColor* color = GetStyleColor();
aRenderingContext.SetColor(color->mColor);

Просмотреть файл

@ -736,6 +736,50 @@ nsIFrame::GetUsedPadding() const
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*
nsFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
{

Просмотреть файл

@ -698,6 +698,20 @@ public:
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
* name for the additional child list at the specified 0-based index, or a

Просмотреть файл

@ -2066,10 +2066,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
if (!frame)
return NS_OK;
nsMargin borderPadding = frame->GetUsedBorderAndPadding();
nsRect rect(frame->GetRect());
rect.Deflate(borderPadding);
adjSize = rect.Size();
adjSize = frame->GetContentRect().Size();
documentIsTopLevel = PR_FALSE;
// presshell exists because parent is printable
} else {

Просмотреть файл

@ -2650,10 +2650,7 @@ nsComputedDOMStyle::GetHeight(nsIFrame *aFrame,
}
if (calcHeight) {
nsMargin bp = aFrame->GetUsedBorderAndPadding();
nsSize size = aFrame->GetSize();
val->SetTwips(size.height - bp.TopBottom());
val->SetTwips(aFrame->GetContentRect().height);
} else {
// Just return the value in the style context
const nsStylePosition* positionData = GetStylePosition(aFrame);
@ -2701,9 +2698,7 @@ nsComputedDOMStyle::GetWidth(nsIFrame *aFrame,
}
if (calcWidth) {
nsSize size = aFrame->GetSize();
nsMargin bp = aFrame->GetUsedBorderAndPadding();
val->SetTwips(size.width - bp.LeftRight());
val->SetTwips(aFrame->GetContentRect().width);
} else {
// Just return the value in the style context
const nsStylePosition *positionData = GetStylePosition(aFrame);
@ -3082,14 +3077,11 @@ nsComputedDOMStyle::GetRelativeOffset(PRUint8 aSide, nsIFrame* aFrame,
case eStyleUnit_Percent:
container = GetContainingBlockFor(aFrame);
if (container) {
nsMargin bp = container->GetUsedBorderAndPadding();
nsSize size = container->GetSize();
nsSize size = container->GetContentRect().Size();
if (aSide == NS_SIDE_LEFT || aSide == NS_SIDE_RIGHT) {
val->SetTwips(sign * coord.GetPercentValue() *
(size.width - bp.LeftRight()));
val->SetTwips(sign * coord.GetPercentValue() * size.width);
} else {
val->SetTwips(sign * coord.GetPercentValue() *
(size.height - bp.TopBottom()));
val->SetTwips(sign * coord.GetPercentValue() * size.height);
}
} else {
// 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.
}
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
// style data! Do not use this function unless you absolutely have to! You should avoid
// this at all costs! -dwh

Просмотреть файл

@ -109,8 +109,6 @@ public:
NS_HIDDEN_(PRBool) Equals(const nsStyleContext* aOther) const;
PRBool HasTextDecorations() { return mBits & NS_STYLE_HAS_TEXT_DECORATIONS; };
NS_HIDDEN_(void) GetBorderPaddingFor(nsStyleBorderPadding& aBorderPadding);
NS_HIDDEN_(void) SetStyle(nsStyleStructID aSID, nsStyleStruct* aStruct);
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 {
nsStyleOutline(nsPresContext* aPresContext);
nsStyleOutline(const nsStyleOutline& aOutline);

Просмотреть файл

@ -781,14 +781,11 @@ nsListBoxBodyFrame::ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState)
nscoord width = 0;
nsMargin margin(0,0,0,0);
nsStyleBorderPadding bPad;
styleContext->GetBorderPaddingFor(bPad);
bPad.GetBorderPadding(margin);
width += (margin.left + margin.right);
styleContext->GetStyleMargin()->GetMargin(margin);
width += (margin.left + margin.right);
if (styleContext->GetStylePadding()->GetPadding(margin))
width += margin.LeftRight();
width += styleContext->GetStyleBorder()->GetBorder().LeftRight();
if (styleContext->GetStyleMargin()->GetMargin(margin))
width += margin.LeftRight();
nsIContent* listbox = mContent->GetBindingParent();
NS_ENSURE_TRUE(listbox, largestWidth);

Просмотреть файл

@ -322,13 +322,8 @@ nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext,
if (mTitle.IsEmpty())
return;
nsStyleBorderPadding bPad;
mStyleContext->GetBorderPaddingFor(bPad);
nsMargin border(0,0,0,0);
bPad.GetBorderPadding(border);
nsRect textRect(aPt, GetSize());
textRect.Deflate(border);
textRect.Deflate(GetUsedBorderAndPadding());
// determine (cropped) title and underline position
nsPresContext* presContext = GetPresContext();

Просмотреть файл

@ -187,9 +187,11 @@ nsTreeBodyFrame::Release(void)
static void
GetBorderPadding(nsStyleContext* aContext, nsMargin& aMargin)
{
nsStyleBorderPadding borderPaddingStyle;
aContext->GetBorderPaddingFor(borderPaddingStyle);
borderPaddingStyle.GetBorderPadding(aMargin);
aMargin.SizeTo(0, 0, 0, 0);
if (!aContext->GetStylePadding()->GetPadding(aMargin)) {
NS_NOTYETIMPLEMENTED("percentage padding");
}
aMargin += aContext->GetStyleBorder()->GetBorder();
}
static void