diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-01-08 17:35:24 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-01-08 17:42:01 +0100 |
commit | 814e0bca313611080bd5d26c850023e06af042ab (patch) | |
tree | 7a954cca04c3e52c1a5d96314b96fdc909f9507c | |
parent | 29b9d4496a52e8a98b7ade9c57001126daee5608 (diff) | |
download | UXP-PM28.3.0_Release.tar UXP-PM28.3.0_Release.tar.gz UXP-PM28.3.0_Release.tar.lz UXP-PM28.3.0_Release.tar.xz UXP-PM28.3.0_Release.zip |
Align Element.ScrollIntoView() with the spec. (uplift)PM28.3.0_Release
This also removes the (unused) shadow alias from nsIDOMHTMLElement
which used the different calling convention.
This resolves #927
-rw-r--r-- | dom/base/Element.cpp | 62 | ||||
-rw-r--r-- | dom/base/Element.h | 5 | ||||
-rw-r--r-- | dom/html/nsGenericHTMLElement.h | 7 | ||||
-rw-r--r-- | dom/interfaces/html/nsIDOMHTMLElement.idl | 1 | ||||
-rw-r--r-- | dom/webidl/Element.webidl | 6 |
5 files changed, 56 insertions, 25 deletions
diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 67759fdb2..5c3277e84 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -687,19 +687,23 @@ Element::GetScrollFrame(nsIFrame **aStyledFrame, bool aFlushLayout) } void -Element::ScrollIntoView() +Element::ScrollIntoView(const BooleanOrScrollIntoViewOptions& aObject) { - ScrollIntoView(ScrollIntoViewOptions()); -} + if (aObject.IsScrollIntoViewOptions()) { + return ScrollIntoView(aObject.GetAsScrollIntoViewOptions()); + } + + MOZ_DIAGNOSTIC_ASSERT(aObject.IsBoolean()); -void -Element::ScrollIntoView(bool aTop) -{ ScrollIntoViewOptions options; - if (!aTop) { + if (aObject.GetAsBoolean()) { + options.mBlock = ScrollLogicalPosition::Start; + options.mInline = ScrollLogicalPosition::Nearest; + } else { options.mBlock = ScrollLogicalPosition::End; + options.mInline = ScrollLogicalPosition::Nearest; } - ScrollIntoView(options); + return ScrollIntoView(options); } void @@ -716,9 +720,41 @@ Element::ScrollIntoView(const ScrollIntoViewOptions &aOptions) return; } - int16_t vpercent = (aOptions.mBlock == ScrollLogicalPosition::Start) - ? nsIPresShell::SCROLL_TOP - : nsIPresShell::SCROLL_BOTTOM; + int16_t vpercent = nsIPresShell::SCROLL_CENTER; + switch (aOptions.mBlock) { + case ScrollLogicalPosition::Start: + vpercent = nsIPresShell::SCROLL_TOP; + break; + case ScrollLogicalPosition::Center: + vpercent = nsIPresShell::SCROLL_CENTER; + break; + case ScrollLogicalPosition::End: + vpercent = nsIPresShell::SCROLL_BOTTOM; + break; + case ScrollLogicalPosition::Nearest: + vpercent = nsIPresShell::SCROLL_MINIMUM; + break; + default: + MOZ_ASSERT_UNREACHABLE("Unexpected ScrollLogicalPosition value"); + } + + int16_t hpercent = nsIPresShell::SCROLL_CENTER; + switch (aOptions.mInline) { + case ScrollLogicalPosition::Start: + hpercent = nsIPresShell::SCROLL_LEFT; + break; + case ScrollLogicalPosition::Center: + hpercent = nsIPresShell::SCROLL_CENTER; + break; + case ScrollLogicalPosition::End: + hpercent = nsIPresShell::SCROLL_RIGHT; + break; + case ScrollLogicalPosition::Nearest: + hpercent = nsIPresShell::SCROLL_MINIMUM; + break; + default: + MOZ_ASSERT_UNREACHABLE("Unexpected ScrollLogicalPosition value"); + } uint32_t flags = nsIPresShell::SCROLL_OVERFLOW_HIDDEN; if (aOptions.mBehavior == ScrollBehavior::Smooth) { @@ -731,7 +767,9 @@ Element::ScrollIntoView(const ScrollIntoViewOptions &aOptions) nsIPresShell::ScrollAxis( vpercent, nsIPresShell::SCROLL_ALWAYS), - nsIPresShell::ScrollAxis(), + nsIPresShell::ScrollAxis( + hpercent, + nsIPresShell::SCROLL_ALWAYS), flags); } diff --git a/dom/base/Element.h b/dom/base/Element.h index ef57a6466..ce84b74fb 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -818,9 +818,10 @@ public: return slots ? slots->mShadowRoot.get() : nullptr; } - void ScrollIntoView(); - void ScrollIntoView(bool aTop); +private: void ScrollIntoView(const ScrollIntoViewOptions &aOptions); +public: + void ScrollIntoView(const BooleanOrScrollIntoViewOptions& aObject); void Scroll(double aXScroll, double aYScroll); void Scroll(const ScrollToOptions& aOptions); void ScrollTo(double aXScroll, double aYScroll); diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 0635c27e1..24a7a3652 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -396,13 +396,6 @@ public: } NS_IMETHOD InsertAdjacentHTML(const nsAString& position, const nsAString& text) final override; - NS_IMETHOD ScrollIntoView(bool top, uint8_t _argc) final override { - if (!_argc) { - top = true; - } - mozilla::dom::Element::ScrollIntoView(top); - return NS_OK; - } NS_IMETHOD GetOffsetParent(nsIDOMElement** aOffsetParent) final override { mozilla::dom::Element* offsetParent = GetOffsetParent(); diff --git a/dom/interfaces/html/nsIDOMHTMLElement.idl b/dom/interfaces/html/nsIDOMHTMLElement.idl index 63a1f9572..686475f04 100644 --- a/dom/interfaces/html/nsIDOMHTMLElement.idl +++ b/dom/interfaces/html/nsIDOMHTMLElement.idl @@ -58,7 +58,6 @@ interface nsIDOMHTMLElement : nsIDOMElement // CSSOM View - [optional_argc] void scrollIntoView([optional] in boolean top); readonly attribute nsIDOMElement offsetParent; readonly attribute long offsetTop; readonly attribute long offsetLeft; diff --git a/dom/webidl/Element.webidl b/dom/webidl/Element.webidl index 97eb4ffe0..cf17523a5 100644 --- a/dom/webidl/Element.webidl +++ b/dom/webidl/Element.webidl @@ -164,9 +164,10 @@ interface Element : Node { }; // http://dev.w3.org/csswg/cssom-view/ -enum ScrollLogicalPosition { "start", "end" }; +enum ScrollLogicalPosition { "start", "center", "end", "nearest" }; dictionary ScrollIntoViewOptions : ScrollOptions { ScrollLogicalPosition block = "start"; + ScrollLogicalPosition inline = "nearest"; }; // http://dev.w3.org/csswg/cssom-view/#extensions-to-the-element-interface @@ -175,8 +176,7 @@ partial interface Element { DOMRect getBoundingClientRect(); // scrolling - void scrollIntoView(boolean top); - void scrollIntoView(optional ScrollIntoViewOptions options); + void scrollIntoView(optional (boolean or ScrollIntoViewOptions) arg); // None of the CSSOM attributes are [Pure], because they flush attribute long scrollTop; // scroll on setting attribute long scrollLeft; // scroll on setting |