mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Implement the headingoffset and headingreset attributes
:heading() now matches based on a computed heading level, which is based
on the level of the tag (h1, h2, etc) and then modified by these two new
attributes.
I'm caching this heading level on HTMLHeadingElement, based on the dom
tree version. That's more invalidation than is actually needed, but it
saves us calculating it over and over when the document hasn't changed.
The failing test cases are:
- Implicit headingreset for modal dialogs which is apparently unspecced
and controversial.
- Not walking the flat tree properly. A flat tree ancestor of a
slot-assigned element is its slot, which is something we don't do
anywhere that I could find. I've made a note to look into this later.
We also don't implement the `ReflectRange` IDL attribute yet, which
means we're not clamping the read value of `headingOffset`.
Corresponds to:
e774e8e318
This commit is contained in:
Notes:
github-actions[bot]
2025-12-15 14:09:36 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/f9f4c36f202 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7100
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@@ -8,6 +9,7 @@
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/ComputedProperties.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/HTMLHeadingElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
@@ -53,4 +55,15 @@ void HTMLHeadingElement::apply_presentational_hints(GC::Ref<CSS::CascadedPropert
|
||||
});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/sections.html#heading-level
|
||||
WebIDL::UnsignedLong HTMLHeadingElement::heading_level() const
|
||||
{
|
||||
// h1–h6 elements have a heading level, which is given by getting the element's computed heading level.
|
||||
if (m_dom_tree_version_for_cached_heading_level < document().dom_tree_version()) {
|
||||
m_dom_tree_version_for_cached_heading_level = document().dom_tree_version();
|
||||
m_cached_heading_level = computed_heading_level();
|
||||
}
|
||||
return m_cached_heading_level;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user