mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-27 19:59:03 +00:00
LibWeb: Implement Element::scroll(HTML::ScrollToOptions)
This commit is contained in:
parent
37ca32d62c
commit
71819153cb
Notes:
sideshowbarker
2024-07-17 06:35:16 +09:00
Author: https://github.com/shannonbooth
Commit: 71819153cb
Pull-request: https://github.com/SerenityOS/serenity/pull/24200
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/awesomekling
4 changed files with 54 additions and 3 deletions
7
Tests/LibWeb/Text/expected/element-scrollby-event.txt
Normal file
7
Tests/LibWeb/Text/expected/element-scrollby-event.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed
|
||||||
|
cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis
|
||||||
|
ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum
|
||||||
|
lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
|
||||||
|
inceptos himenaeos.
|
||||||
|
scroll event fired y=151 x=25
|
36
Tests/LibWeb/Text/input/element-scrollby-event.html
Normal file
36
Tests/LibWeb/Text/input/element-scrollby-event.html
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<style>
|
||||||
|
#scrollable-div {
|
||||||
|
width: 300px;
|
||||||
|
height: 50px;
|
||||||
|
overflow: auto;
|
||||||
|
white-space: pre;
|
||||||
|
border: 1px solid black;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 50px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="include.js"></script>
|
||||||
|
<div id="scrollable-div">
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed
|
||||||
|
cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis
|
||||||
|
ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum
|
||||||
|
lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
|
||||||
|
inceptos himenaeos.
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
asyncTest(done => {
|
||||||
|
const scrollable = document.getElementById("scrollable-div");
|
||||||
|
|
||||||
|
scrollable.addEventListener("scroll", event => {
|
||||||
|
println(`scroll event fired y=${scrollable.scrollTop} x=${scrollable.scrollLeft}`);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
scrollable.scrollBy({
|
||||||
|
top: 151,
|
||||||
|
left: 25,
|
||||||
|
behaviour: 'smooth'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -2201,9 +2201,17 @@ void Element::scroll(double x, double y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-scroll
|
// https://drafts.csswg.org/cssom-view/#dom-element-scroll
|
||||||
void Element::scroll(HTML::ScrollToOptions const&)
|
void Element::scroll(HTML::ScrollToOptions options)
|
||||||
{
|
{
|
||||||
dbgln("FIXME: Implement Element::scroll(ScrollToOptions)");
|
// 1. If invoked with one argument, follow these substeps:
|
||||||
|
// 1. Let options be the argument.
|
||||||
|
// 2. Normalize non-finite values for left and top dictionary members of options, if present.
|
||||||
|
// 3. Let x be the value of the left dictionary member of options, if present, or the element’s current scroll position on the x axis otherwise.
|
||||||
|
// 4. Let y be the value of the top dictionary member of options, if present, or the element’s current scroll position on the y axis otherwise.
|
||||||
|
// NOTE: remaining steps performed by Element::scroll(double x, double y)
|
||||||
|
auto x = options.left.has_value() ? HTML::normalize_non_finite_values(options.left.value()) : scroll_left();
|
||||||
|
auto y = options.top.has_value() ? HTML::normalize_non_finite_values(options.top.value()) : scroll_top();
|
||||||
|
scroll(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollby
|
// https://drafts.csswg.org/cssom-view/#dom-element-scrollby
|
||||||
|
|
|
@ -335,7 +335,7 @@ public:
|
||||||
void set_custom_element_state(CustomElementState value) { m_custom_element_state = value; }
|
void set_custom_element_state(CustomElementState value) { m_custom_element_state = value; }
|
||||||
void setup_custom_element_from_constructor(HTML::CustomElementDefinition& custom_element_definition, Optional<String> const& is_value);
|
void setup_custom_element_from_constructor(HTML::CustomElementDefinition& custom_element_definition, Optional<String> const& is_value);
|
||||||
|
|
||||||
void scroll(HTML::ScrollToOptions const&);
|
void scroll(HTML::ScrollToOptions);
|
||||||
void scroll(double x, double y);
|
void scroll(double x, double y);
|
||||||
void scroll_by(HTML::ScrollToOptions);
|
void scroll_by(HTML::ScrollToOptions);
|
||||||
void scroll_by(double x, double y);
|
void scroll_by(double x, double y);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue