1
1
/*
2
2
* Copyright (c) 2018-2024, Andreas Kling <[email protected] >
3
+ * Copyright (c) 2025, Jelle Raaijmakers <[email protected] >
3
4
*
4
5
* SPDX-License-Identifier: BSD-2-Clause
5
6
*/
@@ -463,7 +464,7 @@ int HTMLElement::offset_top() const
463
464
if (!paintable_box ())
464
465
return 0 ;
465
466
466
- CSSPixels top_border_edge_of_element = paintable_box ()->absolute_border_box_rect ().y ();
467
+ CSSPixels top_border_edge_of_element = paintable_box ()->absolute_united_border_box_rect ().y ();
467
468
468
469
// 2. If the offsetParent of the element is null
469
470
// return the y-coordinate of the top border edge of the first CSS layout box associated with the element,
@@ -487,7 +488,7 @@ int HTMLElement::offset_top() const
487
488
if (offset_parent->is_html_body_element () && !offset_parent->paintable_box ()->is_positioned ()) {
488
489
top_padding_edge_of_offset_parent = 0 ;
489
490
} else {
490
- top_padding_edge_of_offset_parent = offset_parent->paintable_box ()->absolute_padding_box_rect ().y ();
491
+ top_padding_edge_of_offset_parent = offset_parent->paintable_box ()->absolute_united_padding_box_rect ().y ();
491
492
}
492
493
return (top_border_edge_of_element - top_padding_edge_of_offset_parent).to_int ();
493
494
}
@@ -505,7 +506,7 @@ int HTMLElement::offset_left() const
505
506
if (!paintable_box ())
506
507
return 0 ;
507
508
508
- CSSPixels left_border_edge_of_element = paintable_box ()->absolute_border_box_rect ().x ();
509
+ CSSPixels left_border_edge_of_element = paintable_box ()->absolute_united_border_box_rect ().x ();
509
510
510
511
// 2. If the offsetParent of the element is null
511
512
// return the x-coordinate of the left border edge of the first CSS layout box associated with the element,
@@ -529,7 +530,7 @@ int HTMLElement::offset_left() const
529
530
if (offset_parent->is_html_body_element () && !offset_parent->paintable_box ()->is_positioned ()) {
530
531
left_padding_edge_of_offset_parent = 0 ;
531
532
} else {
532
- left_padding_edge_of_offset_parent = offset_parent->paintable_box ()->absolute_padding_box_rect ().x ();
533
+ left_padding_edge_of_offset_parent = offset_parent->paintable_box ()->absolute_united_padding_box_rect ().x ();
533
534
}
534
535
return (left_border_edge_of_element - left_padding_edge_of_offset_parent).to_int ();
535
536
}
@@ -540,13 +541,17 @@ int HTMLElement::offset_width() const
540
541
// NOTE: Ensure that layout is up-to-date before looking at metrics.
541
542
const_cast <DOM::Document&>(document ()).update_layout ();
542
543
543
- // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
544
- if (!paintable_box ())
544
+ // 1. If the element does not have any associated box return zero and terminate this algorithm.
545
+ auto const * box = paintable_box ();
546
+ if (!box)
545
547
return 0 ;
546
548
547
- // 2. Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
548
- // ignoring any transforms that apply to the element and its ancestors.
549
- return paintable_box ()->border_box_width ().to_int ();
549
+ // 2. Return the unscaled width of the axis-aligned bounding box of the border boxes of all fragments generated by
550
+ // the element’s principal box, ignoring any transforms that apply to the element and its ancestors.
551
+ //
552
+ // If the element’s principal box is an inline-level box which was "split" by a block-level descendant, also
553
+ // include fragments generated by the block-level descendants, unless they are zero width or height.
554
+ return box->absolute_united_border_box_rect ().width ().to_int ();
550
555
}
551
556
552
557
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
@@ -555,13 +560,17 @@ int HTMLElement::offset_height() const
555
560
// NOTE: Ensure that layout is up-to-date before looking at metrics.
556
561
const_cast <DOM::Document&>(document ()).update_layout ();
557
562
558
- // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
559
- if (!paintable_box ())
563
+ // 1. If the element does not have any associated box return zero and terminate this algorithm.
564
+ auto const * box = paintable_box ();
565
+ if (!box)
560
566
return 0 ;
561
567
562
- // 2. Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
563
- // ignoring any transforms that apply to the element and its ancestors.
564
- return paintable_box ()->border_box_height ().to_int ();
568
+ // 2. Return the unscaled height of the axis-aligned bounding box of the border boxes of all fragments generated by
569
+ // the element’s principal box, ignoring any transforms that apply to the element and its ancestors.
570
+ //
571
+ // If the element’s principal box is an inline-level box which was "split" by a block-level descendant, also
572
+ // include fragments generated by the block-level descendants, unless they are zero width or height.
573
+ return box->absolute_united_border_box_rect ().height ().to_int ();
565
574
}
566
575
567
576
// https://html.spec.whatwg.org/multipage/links.html#cannot-navigate
0 commit comments