浏览代码

LibWeb: Implement Element::scroll_by(HTML::ScrollToOptions)

Shannon Booth 1 年之前
父节点
当前提交
e640a68733
共有 2 个文件被更改,包括 16 次插入4 次删除
  1. 15 3
      Userland/Libraries/LibWeb/DOM/Element.cpp
  2. 1 1
      Userland/Libraries/LibWeb/DOM/Element.h

+ 15 - 3
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -2159,10 +2159,22 @@ void Element::scroll_by(double x, double y)
     dbgln("FIXME: Implement Element::scroll_by({}, {})", x, y);
     dbgln("FIXME: Implement Element::scroll_by({}, {})", x, y);
 }
 }
 
 
-// https://drafts.csswg.org/cssom-view/#dom-window-scrollby
-void Element::scroll_by(HTML::ScrollToOptions const&)
+// https://drafts.csswg.org/cssom-view/#dom-element-scrollby
+void Element::scroll_by(HTML::ScrollToOptions options)
 {
 {
-    dbgln("FIXME: Implement Element::scroll_by(ScrollToOptions)");
+    // 1. Let options be the argument.
+    // 2. Normalize non-finite values for left and top dictionary members of options, if present.
+    auto left = HTML::normalize_non_finite_values(options.left);
+    auto top = HTML::normalize_non_finite_values(options.top);
+
+    // 3. Add the value of scrollLeft to the left dictionary member.
+    options.left = scroll_left() + left;
+
+    // 4. Add the value of scrollTop to the top dictionary member.
+    options.top = scroll_top() + top;
+
+    // 5. Act as if the scroll() method was invoked with options as the only argument.
+    scroll(options);
 }
 }
 
 
 bool Element::id_reference_exists(String const& id_reference) const
 bool Element::id_reference_exists(String const& id_reference) const

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Element.h

@@ -337,7 +337,7 @@ public:
 
 
     void scroll(HTML::ScrollToOptions const&);
     void scroll(HTML::ScrollToOptions const&);
     void scroll(double x, double y);
     void scroll(double x, double y);
-    void scroll_by(HTML::ScrollToOptions const&);
+    void scroll_by(HTML::ScrollToOptions);
     void scroll_by(double x, double y);
     void scroll_by(double x, double y);
 
 
     void register_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, IntersectionObserver::IntersectionObserverRegistration);
     void register_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, IntersectionObserver::IntersectionObserverRegistration);