From 8e79f76734b09b88a44aebb0a5bd9e57850086ef Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 28 Jul 2011 18:11:51 -0700 Subject: [PATCH] Make hypothetical box calculation consider types that are inline-outside rather than just inline. (Bug 505706) r=bzbarsky Change the "hypothetical box" calculations that we do for 'auto'-offset absolutely positioned elements take its inline codepath (using horizontal position of placeholder, and placing even with the top of the placeholder's line) rather than its block codepath (using the horizontal edge of the containing block, and placing below the placeholder's line) when display types are display-outside:inline types other than display:inline. --- layout/generic/nsHTMLReflowState.cpp | 6 +++--- .../auto-offset-inline-block-1-ref.html | 6 ++++++ .../abs-pos/auto-offset-inline-block-1.html | 10 ++++++++++ layout/reftests/abs-pos/reftest.list | 1 + layout/style/nsStyleStruct.h | 20 +++++++++++++------ 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 layout/reftests/abs-pos/auto-offset-inline-block-1-ref.html create mode 100644 layout/reftests/abs-pos/auto-offset-inline-block-1.html diff --git a/layout/generic/nsHTMLReflowState.cpp b/layout/generic/nsHTMLReflowState.cpp index 325322576dcc..3d7c7fb9a1f3 100644 --- a/layout/generic/nsHTMLReflowState.cpp +++ b/layout/generic/nsHTMLReflowState.cpp @@ -977,7 +977,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsPresContext* aPresContext, // How we determine the hypothetical box depends on whether the element // would have been inline-level or block-level - if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) { + if (mStyleDisplay->IsOriginalDisplayInlineOutside()) { // Use the top of the inline box which the placeholder lives in // as the hypothetical box's top. aHypotheticalBox.mTop = lineBox->mBounds.y + blockYOffset; @@ -1029,7 +1029,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsPresContext* aPresContext, if (NS_STYLE_DIRECTION_LTR == blockVis->mDirection) { // How we determine the hypothetical box depends on whether the element // would have been inline-level or block-level - if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) { + if (mStyleDisplay->IsOriginalDisplayInlineOutside()) { // The placeholder represents the left edge of the hypothetical box aHypotheticalBox.mLeft = placeholderOffset.x; } else { @@ -1056,7 +1056,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsPresContext* aPresContext, } else { // The placeholder represents the right edge of the hypothetical box - if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) { + if (mStyleDisplay->IsOriginalDisplayInlineOutside()) { aHypotheticalBox.mRight = placeholderOffset.x; } else { aHypotheticalBox.mRight = aBlockLeftContentEdge + aBlockContentWidth; diff --git a/layout/reftests/abs-pos/auto-offset-inline-block-1-ref.html b/layout/reftests/abs-pos/auto-offset-inline-block-1-ref.html new file mode 100644 index 000000000000..d8ae9807cca9 --- /dev/null +++ b/layout/reftests/abs-pos/auto-offset-inline-block-1-ref.html @@ -0,0 +1,6 @@ + +'auto' offset properties on display:inline-block (reference) + +

HelloWorld

diff --git a/layout/reftests/abs-pos/auto-offset-inline-block-1.html b/layout/reftests/abs-pos/auto-offset-inline-block-1.html new file mode 100644 index 000000000000..08a691ade313 --- /dev/null +++ b/layout/reftests/abs-pos/auto-offset-inline-block-1.html @@ -0,0 +1,10 @@ + +'auto' offset properties on display:inline-block + +

HelloWorld

diff --git a/layout/reftests/abs-pos/reftest.list b/layout/reftests/abs-pos/reftest.list index 4a28bb9c8fbd..9dee65e95fe0 100644 --- a/layout/reftests/abs-pos/reftest.list +++ b/layout/reftests/abs-pos/reftest.list @@ -1,2 +1,3 @@ == font-size-wrap.html font-size-wrap-ref.html == abs-pos-auto-margin-1.html abs-pos-auto-margin-1-ref.html +== auto-offset-inline-block-1.html auto-offset-inline-block-1-ref.html diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 0911310feb7a..6faa4960e3a5 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -1551,13 +1551,21 @@ struct nsStyleDisplay { NS_STYLE_DISPLAY_TABLE == mDisplay; } + static PRBool IsDisplayTypeInlineOutside(PRUint8 aDisplay) { + return NS_STYLE_DISPLAY_INLINE == aDisplay || + NS_STYLE_DISPLAY_INLINE_BLOCK == aDisplay || + NS_STYLE_DISPLAY_INLINE_TABLE == aDisplay || + NS_STYLE_DISPLAY_INLINE_BOX == aDisplay || + NS_STYLE_DISPLAY_INLINE_GRID == aDisplay || + NS_STYLE_DISPLAY_INLINE_STACK == aDisplay; + } + PRBool IsInlineOutside() const { - return NS_STYLE_DISPLAY_INLINE == mDisplay || - NS_STYLE_DISPLAY_INLINE_BLOCK == mDisplay || - NS_STYLE_DISPLAY_INLINE_TABLE == mDisplay || - NS_STYLE_DISPLAY_INLINE_BOX == mDisplay || - NS_STYLE_DISPLAY_INLINE_GRID == mDisplay || - NS_STYLE_DISPLAY_INLINE_STACK == mDisplay; + return IsDisplayTypeInlineOutside(mDisplay); + } + + PRBool IsOriginalDisplayInlineOutside() const { + return IsDisplayTypeInlineOutside(mOriginalDisplay); } PRBool IsFloating() const {