mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-10-28 16:45:23 +08:00
Implement feedback
Add missing comment, fix comparison, add test cases.
This commit is contained in:
3 files changed
+8
-4
No files matched your search
@@ -9,19 +9,21 @@
|
||||
<script id="rectIsViewportRelative">
|
||||
{
|
||||
const filler = $('#filler');
|
||||
// Empty paragraphs have no height in a real layout, so give them text.
|
||||
for (let i = 0; i < 300; i++) {
|
||||
filler.appendChild(document.createElement('p'));
|
||||
const p = document.createElement('p');
|
||||
p.textContent = 'x';
|
||||
filler.appendChild(p);
|
||||
}
|
||||
const far = $('#far');
|
||||
const before = far.getBoundingClientRect();
|
||||
testing.expectTrue(before.top > window.innerHeight);
|
||||
testing.expectEqual(far, document.elementFromPoint(before.x, before.y));
|
||||
|
||||
window.scrollTo(0, 100);
|
||||
const after = far.getBoundingClientRect();
|
||||
testing.expectEqual(before.top - 100, after.top);
|
||||
testing.expectEqual(before.x, after.x);
|
||||
testing.expectEqual(far, document.elementFromPoint(after.x, after.y));
|
||||
testing.expectEqual(after.top, far.getClientRects()[0].top);
|
||||
|
||||
// scrollIntoView brings it into the viewport
|
||||
far.scrollIntoView();
|
||||
|
||||
@@ -2132,7 +2132,7 @@ pub fn scrollIntoViewIfNeeded(self: *Element, center_if_needed: ?bool, frame: *F
|
||||
const y = calculateDocumentPosition(self.asNode());
|
||||
const scroll_y: f64 = @floatFromInt(frame.window.getScrollY());
|
||||
const viewport_height: f64 = @floatFromInt(frame.window.getInnerHeight(frame));
|
||||
if (y >= scroll_y and y <= scroll_y + viewport_height) {
|
||||
if (y >= scroll_y and y < scroll_y + viewport_height) {
|
||||
return;
|
||||
}
|
||||
self.scrollIntoView(null, frame);
|
||||
|
||||
@@ -486,6 +486,8 @@ fn scrollIntoViewIfNeeded(cmd: *CDP.Command) !void {
|
||||
.element => {
|
||||
// Drivers (e.g. Playwright's click) scroll the target into view and
|
||||
// then require its content quads to intersect the viewport.
|
||||
// `params.rect` (Playwright's click position) is ignored: the faux
|
||||
// layout scrolls the whole element into view.
|
||||
const frame = bc.mainFrame() orelse return error.FrameNotLoaded;
|
||||
const element = node.dom.is(DOMNode.Element).?;
|
||||
element.scrollIntoViewIfNeeded(null, element.ownerFrame(frame) orelse frame);
|
||||
|
||||
Reference in new issue
Block a user