Skip to content

Commit

Permalink
Move the anchor attribute to its own (dependent) flag
Browse files Browse the repository at this point in the history
Just as a precaution, this gates the `anchor` attribute behavior
on its own `HTMLAnchorAttribute` feature, which is implied by the
`CSSAnchorPositioning` feature. This is just in case we are not
able to ship the `anchor` attribute due to delays at WHATWG:

 - whatwg/html#9144

Bug: 40059176
Change-Id: Ic4be7cc935bc9db03eba2f0477e5dfd69d8e0ba4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5438893
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1285571}
  • Loading branch information
Mason Freed authored and Chromium LUCI CQ committed Apr 11, 2024
1 parent 42fb8d0 commit db6a65f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions third_party/blink/renderer/core/dom/element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1235,13 +1235,17 @@ void Element::InterestGained() {
Element* Element::anchorElement() const {
// TODO(crbug.com/1425215): Fix GetElementAttribute() for out-of-tree-scope
// elements, so that we can remove the hack below.
if (!RuntimeEnabledFeatures::HTMLAnchorAttributeEnabled()) {
return nullptr;
}
if (!IsInTreeScope()) {
return nullptr;
}
return GetElementAttribute(html_names::kAnchorAttr);
}

void Element::setAnchorElement(Element* new_element) {
CHECK(RuntimeEnabledFeatures::HTMLAnchorAttributeEnabled());
SetElementAttribute(html_names::kAnchorAttr, new_element);
EnsureAnchorElementObserver().Notify();
}
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/core/dom/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,8 @@ class CORE_EXPORT Element : public ContainerNode, public Animatable {

// Retrieves the element pointed to by this element's 'anchor' content
// attribute, if that element exists.
// TODO(crbug.com/40059176) If the HTMLAnchorAttribute feature is disabled,
// this will return nullptr;
Element* anchorElement() const;
void setAnchorElement(Element*);

Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/dom/element.idl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ dictionary CheckVisibilityOptions {
readonly attribute long clientHeight;

// Used by both Anchor Positioning and Popover
[CEReactions,RuntimeEnabled=CSSAnchorPositioning] attribute Element? anchorElement;
[CEReactions,RuntimeEnabled=HTMLAnchorAttribute] attribute Element? anchorElement;

// Non-standard API
[MeasureAs=ElementScrollIntoViewIfNeeded] void scrollIntoViewIfNeeded(optional boolean centerIfNeeded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,13 @@
status: "stable",
base_feature: "none",
},
// The `anchor` attribute, supported by both anchor positioning and the
// popover API.
{
name: "HTMLAnchorAttribute",
status: "experimental",
implied_by: ["CSSAnchorPositioning"]
},
// Adds support for the experimental `interesttarget`
// attributes, as specified in the open-ui "Interest Invokers" explainer.
// https://open-ui.org/components/interest-invokers.explainer/
Expand Down

0 comments on commit db6a65f

Please sign in to comment.