From 7850f5f46239a16a3e6722c6c68b88e618dd0056 Mon Sep 17 00:00:00 2001 From: Corey Ford Date: Thu, 15 Aug 2013 17:31:32 -0700 Subject: [PATCH] Bug 886646 - Part 3: Compute sticky positioning offsets for getComputedStyle(). r=heycam --- layout/style/nsComputedDOMStyle.cpp | 76 ++++++++++++++++++ layout/style/nsComputedDOMStyle.h | 4 + layout/style/test/Makefile.in | 2 + layout/style/test/file_position_sticky.html | 88 +++++++++++++++++++++ layout/style/test/test_position_sticky.html | 42 ++++++++++ 5 files changed, 212 insertions(+) create mode 100644 layout/style/test/file_position_sticky.html create mode 100644 layout/style/test/test_position_sticky.html diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 7f22a4cc671b..751e6abe9b67 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -3708,6 +3708,8 @@ nsComputedDOMStyle::GetOffsetWidthFor(mozilla::css::Side aSide) return GetStaticOffset(aSide); case NS_STYLE_POSITION_RELATIVE: return GetRelativeOffset(aSide); + case NS_STYLE_POSITION_STICKY: + return GetStickyOffset(aSide); case NS_STYLE_POSITION_ABSOLUTE: case NS_STYLE_POSITION_FIXED: return GetAbsoluteOffset(aSide); @@ -3808,6 +3810,36 @@ nsComputedDOMStyle::GetRelativeOffset(mozilla::css::Side aSide) return val; } +CSSValue* +nsComputedDOMStyle::GetStickyOffset(mozilla::css::Side aSide) +{ + nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue; + + const nsStylePosition* positionData = StylePosition(); + nsStyleCoord coord = positionData->mOffset.Get(aSide); + + NS_ASSERTION(coord.GetUnit() == eStyleUnit_Coord || + coord.GetUnit() == eStyleUnit_Percent || + coord.GetUnit() == eStyleUnit_Auto || + coord.IsCalcUnit(), + "Unexpected unit"); + + if (coord.GetUnit() == eStyleUnit_Auto) { + val->SetIdent(eCSSKeyword_auto); + return val; + } + PercentageBaseGetter baseGetter; + if (aSide == NS_SIDE_LEFT || aSide == NS_SIDE_RIGHT) { + baseGetter = &nsComputedDOMStyle::GetScrollFrameContentWidth; + } else { + baseGetter = &nsComputedDOMStyle::GetScrollFrameContentHeight; + } + + val->SetAppUnits(StyleCoordToNSCoord(coord, baseGetter, 0, false)); + return val; +} + + CSSValue* nsComputedDOMStyle::GetStaticOffset(mozilla::css::Side aSide) @@ -4126,6 +4158,50 @@ nsComputedDOMStyle::GetCBContentHeight(nscoord& aHeight) return true; } +bool +nsComputedDOMStyle::GetScrollFrameContentWidth(nscoord& aWidth) +{ + if (!mOuterFrame) { + return false; + } + + AssertFlushedPendingReflows(); + + nsIScrollableFrame* scrollableFrame = + nsLayoutUtils::GetNearestScrollableFrame(mOuterFrame->GetParent(), + nsLayoutUtils::SCROLLABLE_SAME_DOC | + nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN); + + if (!scrollableFrame) { + return false; + } + aWidth = + scrollableFrame->GetScrolledFrame()->GetContentRectRelativeToSelf().width; + return true; +} + +bool +nsComputedDOMStyle::GetScrollFrameContentHeight(nscoord& aHeight) +{ + if (!mOuterFrame) { + return false; + } + + AssertFlushedPendingReflows(); + + nsIScrollableFrame* scrollableFrame = + nsLayoutUtils::GetNearestScrollableFrame(mOuterFrame->GetParent(), + nsLayoutUtils::SCROLLABLE_SAME_DOC | + nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN); + + if (!scrollableFrame) { + return false; + } + aHeight = + scrollableFrame->GetScrolledFrame()->GetContentRectRelativeToSelf().height; + return true; +} + bool nsComputedDOMStyle::GetFrameBorderRectWidth(nscoord& aWidth) { diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index ae3040561eab..dfd6e41253db 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -125,6 +125,8 @@ private: mozilla::dom::CSSValue* GetRelativeOffset(mozilla::css::Side aSide); + mozilla::dom::CSSValue* GetStickyOffset(mozilla::css::Side aSide); + mozilla::dom::CSSValue* GetStaticOffset(mozilla::css::Side aSide); mozilla::dom::CSSValue* GetPaddingWidthFor(mozilla::css::Side aSide); @@ -491,6 +493,8 @@ private: bool GetCBContentWidth(nscoord& aWidth); bool GetCBContentHeight(nscoord& aWidth); + bool GetScrollFrameContentWidth(nscoord& aWidth); + bool GetScrollFrameContentHeight(nscoord& aHeight); bool GetFrameBoundsWidthForTransform(nscoord &aWidth); bool GetFrameBoundsHeightForTransform(nscoord &aHeight); bool GetFrameBorderRectWidth(nscoord& aWidth); diff --git a/layout/style/test/Makefile.in b/layout/style/test/Makefile.in index 2e898bcaeb06..ebc9aab2cd56 100644 --- a/layout/style/test/Makefile.in +++ b/layout/style/test/Makefile.in @@ -137,6 +137,8 @@ MOCHITEST_FILES = test_acid3_test46.html \ test_parser_diagnostics_unprintables.html \ test_pixel_lengths.html \ test_pointer-events.html \ + file_position_sticky.html \ + test_position_sticky.html \ test_property_database.html \ test_priority_preservation.html \ test_property_syntax_errors.html \ diff --git a/layout/style/test/file_position_sticky.html b/layout/style/test/file_position_sticky.html new file mode 100644 index 000000000000..20e1550cb71b --- /dev/null +++ b/layout/style/test/file_position_sticky.html @@ -0,0 +1,88 @@ + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+ + diff --git a/layout/style/test/test_position_sticky.html b/layout/style/test/test_position_sticky.html new file mode 100644 index 000000000000..0164f2219a0b --- /dev/null +++ b/layout/style/test/test_position_sticky.html @@ -0,0 +1,42 @@ + + + + + + Test for Bug 886646 + + + + +Mozilla Bug 886646 +
+ +
+
+
+
+ +