From 3729a079f756592ae8922f24e09483375be91104 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Mon, 19 Apr 2021 23:48:24 +0000 Subject: [PATCH] Add initiallyopen attribute to the element This add an attribute called initiallyopen to the element. When this attribute is present on page load, the first such element will be shown by default. See [1] for the conversation and Open-UI resolution. This CL also re-points the explainer links for all popup tests to the new Open-UI repo. [1] https://github.com/WICG/open-ui/issues/311#issuecomment-820655960 Bug: 1168738 Change-Id: Ib95d12234f359d503dc168e6799dd2a17b0dc18e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2832157 Reviewed-by: Ionel Popescu Commit-Queue: Mason Freed Cr-Commit-Position: refs/heads/master@{#874037} GitOrigin-RevId: 9d0421abc7790a8e3447ae6151c87557e9081146 --- .../core/html/html_attribute_names.json5 | 1 + .../renderer/core/html/html_popup_element.cc | 25 +++++++++++++++ blink/renderer/core/html/html_popup_element.h | 5 +++ .../renderer/core/html/html_popup_element.idl | 1 + .../popup-anchor-nesting.tentative.html | 2 +- .../popup-element-basic.tentative.html | 2 +- .../popup-hidden-display.tentative.html | 2 +- ...p-initiallyopen-display-ref.tentative.html | 22 +++++++++++++ ...popup-initiallyopen-display.tentative.html | 26 ++++++++++++++++ .../popup-initiallyopen.tentative.html | 31 +++++++++++++++++++ .../popup-inside-display-none.tentative.html | 2 +- .../popup-invoking-attribute.tentative.html | 2 +- ...pup-light-dismiss-on-scroll.tentative.html | 2 +- .../popup-light-dismiss.tentative.html | 2 +- .../popup-open-display.tentative.html | 2 +- ...popup-open-overflow-display.tentative.html | 2 +- .../popup-shadow-dom.tentative.html | 2 +- .../popup-stacking.tentative.html | 2 +- ...ent-instance-property-listing-expected.txt | 1 + .../global-interface-listing-expected.txt | 2 ++ 20 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display-ref.tentative.html create mode 100644 blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display.tentative.html create mode 100644 blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen.tentative.html diff --git a/blink/renderer/core/html/html_attribute_names.json5 b/blink/renderer/core/html/html_attribute_names.json5 index 719fede3a78a..88958f2f814e 100644 --- a/blink/renderer/core/html/html_attribute_names.json5 +++ b/blink/renderer/core/html/html_attribute_names.json5 @@ -110,6 +110,7 @@ "impressionexpiry", "incremental", "inert", + "initiallyopen", "inputmode", "integrity", "is", diff --git a/blink/renderer/core/html/html_popup_element.cc b/blink/renderer/core/html/html_popup_element.cc index 6e3afa4b4660..dddfecd007bd 100644 --- a/blink/renderer/core/html/html_popup_element.cc +++ b/blink/renderer/core/html/html_popup_element.cc @@ -21,6 +21,7 @@ namespace blink { HTMLPopupElement::HTMLPopupElement(Document& document) : HTMLElement(html_names::kPopupTag, document), open_(false), + had_initiallyopen_when_parsed_(false), invoker_(nullptr), needs_repositioning_for_select_menu_(false), owner_select_menu_element_(nullptr) { @@ -77,6 +78,30 @@ void HTMLPopupElement::show() { MarkStyleDirty(); } +Node::InsertionNotificationRequest HTMLPopupElement::InsertedInto( + ContainerNode& insertion_point) { + HTMLElement::InsertedInto(insertion_point); + + if (had_initiallyopen_when_parsed_) { + DCHECK(isConnected()) << "This should be being inserted by the parser"; + // If a has the initiallyopen attribute upon page + // load, and it is the first such popup, show it. + if (!GetDocument().PopupShowing()) + show(); + had_initiallyopen_when_parsed_ = false; + } + return kInsertionDone; +} + +void HTMLPopupElement::ParserDidSetAttributes() { + HTMLElement::ParserDidSetAttributes(); + + if (FastHasAttribute(html_names::kInitiallyopenAttr)) { + DCHECK(!isConnected()); + had_initiallyopen_when_parsed_ = true; + } +} + void HTMLPopupElement::PushNewPopupElement(HTMLPopupElement* popup) { auto& stack = GetDocument().PopupElementStack(); DCHECK(!stack.Contains(popup)); diff --git a/blink/renderer/core/html/html_popup_element.h b/blink/renderer/core/html/html_popup_element.h index cdde68fbdc4a..3fd22d9e832d 100644 --- a/blink/renderer/core/html/html_popup_element.h +++ b/blink/renderer/core/html/html_popup_element.h @@ -51,6 +51,10 @@ class HTMLPopupElement final : public HTMLElement { void ScheduleHideEvent(); void MarkStyleDirty(); + Node::InsertionNotificationRequest InsertedInto( + ContainerNode& insertion_point) override; + void ParserDidSetAttributes() override; + // TODO(crbug.com/1197720): The popup position should be provided by the new // anchored positioning scheme. void AdjustPopupPositionForSelectMenu(ComputedStyle&); @@ -62,6 +66,7 @@ class HTMLPopupElement final : public HTMLElement { static const HTMLPopupElement* NearestOpenAncestralPopup(Node*); bool open_; + bool had_initiallyopen_when_parsed_; WeakMember invoker_; bool needs_repositioning_for_select_menu_; diff --git a/blink/renderer/core/html/html_popup_element.idl b/blink/renderer/core/html/html_popup_element.idl index 06d07b8a955b..58ebfab2648f 100644 --- a/blink/renderer/core/html/html_popup_element.idl +++ b/blink/renderer/core/html/html_popup_element.idl @@ -6,6 +6,7 @@ [Exposed=Window,HTMLConstructor,RuntimeEnabled=HTMLPopupElement] interface HTMLPopupElement : HTMLElement { [CEReactions] readonly attribute boolean open; + [CEReactions, Reflect] attribute boolean initiallyOpen; [CEReactions, Measure] void show(); [CEReactions, Measure] void hide(); }; diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-anchor-nesting.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-anchor-nesting.tentative.html index f39d301e2264..64b8fc694c73 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-anchor-nesting.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-anchor-nesting.tentative.html @@ -2,7 +2,7 @@ Popup anchor nesting - + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-element-basic.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-element-basic.tentative.html index 9909b2f0bbfa..0b1d99099e58 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-element-basic.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-element-basic.tentative.html @@ -1,7 +1,7 @@ - + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-hidden-display.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-hidden-display.tentative.html index 8a070b9d479a..b313f06f664d 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-hidden-display.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-hidden-display.tentative.html @@ -1,7 +1,7 @@ - + No popup should be displayed here.

diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display-ref.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display-ref.tentative.html new file mode 100644 index 000000000000..db1a3f2b044d --- /dev/null +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display-ref.tentative.html @@ -0,0 +1,22 @@ + + + + +

This is a popup, which should be open upon load
+ + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display.tentative.html new file mode 100644 index 000000000000..64589e5267a1 --- /dev/null +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display.tentative.html @@ -0,0 +1,26 @@ + + + + + + +This is a popup, which should be open upon load +This is a second popup with initiallyopen, which should NOT be open upon load + + + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen.tentative.html new file mode 100644 index 000000000000..ac3e845b7ba8 --- /dev/null +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen.tentative.html @@ -0,0 +1,31 @@ + + + + + + + +This is a popup, which should be open upon load +This is a second popup with initiallyopen, which should NOT be open upon load +Also not visible + + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-inside-display-none.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-inside-display-none.tentative.html index 745403da5ff3..0b9fcc5427ca 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-inside-display-none.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-inside-display-none.tentative.html @@ -1,7 +1,7 @@ - + No popup should be displayed here.

diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-invoking-attribute.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-invoking-attribute.tentative.html index 2b5eaad51dd2..1ff60fd7f9b3 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-invoking-attribute.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-invoking-attribute.tentative.html @@ -2,7 +2,7 @@ Popup invoking attribute - + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss-on-scroll.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss-on-scroll.tentative.html index 28dd4f4d1873..4f14dd7ae774 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss-on-scroll.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss-on-scroll.tentative.html @@ -3,7 +3,7 @@ Popup light dismiss on scroll - + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss.tentative.html index c017893f1386..99781809c8e5 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-light-dismiss.tentative.html @@ -2,7 +2,7 @@ Popup light dismiss behavior - + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-display.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-display.tentative.html index 7c5bf44b7794..792cc09d071a 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-display.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-display.tentative.html @@ -1,7 +1,7 @@ - + This is a popup diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-overflow-display.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-overflow-display.tentative.html index b2780b7af362..ebe95d8544da 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-overflow-display.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-open-overflow-display.tentative.html @@ -1,7 +1,7 @@ - +

diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-shadow-dom.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-shadow-dom.tentative.html index 96289a5e8f50..516b6ead1b9e 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-shadow-dom.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-shadow-dom.tentative.html @@ -1,7 +1,7 @@ - + diff --git a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-stacking.tentative.html b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-stacking.tentative.html index 4fccaa7c69a4..88e935056316 100644 --- a/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-stacking.tentative.html +++ b/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-popup-element/popup-stacking.tentative.html @@ -1,7 +1,7 @@ - + diff --git a/blink/web_tests/webexposed/element-instance-property-listing-expected.txt b/blink/web_tests/webexposed/element-instance-property-listing-expected.txt index e2aecf11ce61..e0567cc0dd0b 100644 --- a/blink/web_tests/webexposed/element-instance-property-listing-expected.txt +++ b/blink/web_tests/webexposed/element-instance-property-listing-expected.txt @@ -905,6 +905,7 @@ html element picture html element plaintext html element popup property hide + property initiallyOpen property open property show html element pre diff --git a/blink/web_tests/webexposed/global-interface-listing-expected.txt b/blink/web_tests/webexposed/global-interface-listing-expected.txt index f74f87f432cf..75ad46d1d97a 100644 --- a/blink/web_tests/webexposed/global-interface-listing-expected.txt +++ b/blink/web_tests/webexposed/global-interface-listing-expected.txt @@ -4034,10 +4034,12 @@ interface HTMLPictureElement : HTMLElement method constructor interface HTMLPopupElement : HTMLElement attribute @@toStringTag + getter initiallyOpen getter open method constructor method hide method show + setter initiallyOpen interface HTMLPreElement : HTMLElement attribute @@toStringTag getter width