Skip to content

Commit

Permalink
Update the pop-up implementation to match hint/auto resolutions
Browse files Browse the repository at this point in the history
See the set of behaviors described here:

  openui/open-ui#525 (comment)

which were resolved here:

  openui/open-ui#525 (comment)

This CL implements those changes in behavior, which mostly deal with
how popup=auto and popup=hint interact, and some small changes to how
`defaultopen` works.

Bug: 1307772
Change-Id: I4d280b60e7c341b4d0f97fe82e60134ff4a6e1fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3742105
Auto-Submit: Mason Freed <masonf@chromium.org>
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1021327}
NOKEYCHECK=True
GitOrigin-RevId: 033ae102a356d906af6f62d3a31588f0b2fc4b18
  • Loading branch information
Mason Freed authored and copybara-github committed Jul 6, 2022
1 parent 42e100c commit 9e8f08f
Show file tree
Hide file tree
Showing 14 changed files with 563 additions and 280 deletions.
15 changes: 8 additions & 7 deletions blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7260,12 +7260,12 @@ HTMLDialogElement* Document::ActiveModalDialog() const {
return nullptr;
}

bool Document::PopupOrHintShowing() const {
return !popup_and_hint_stack_.IsEmpty();
}
bool Document::HintShowing() const {
return !popup_and_hint_stack_.IsEmpty() &&
(popup_and_hint_stack_.back()->PopupType() == PopupValueType::kHint);
Element* Document::TopmostPopupAutoOrHint() const {
if (PopupHintShowing())
return PopupHintShowing();
if (PopupStack().IsEmpty())
return nullptr;
return PopupStack().back();
}

void Document::exitPointerLock() {
Expand Down Expand Up @@ -8019,7 +8019,8 @@ void Document::Trace(Visitor* visitor) const {
visitor->Trace(lists_invalidated_at_document_);
visitor->Trace(node_lists_);
visitor->Trace(top_layer_elements_);
visitor->Trace(popup_and_hint_stack_);
visitor->Trace(popup_hint_showing_);
visitor->Trace(popup_stack_);
visitor->Trace(popups_waiting_to_hide_);
visitor->Trace(load_event_delay_timer_);
visitor->Trace(plugin_loading_timer_);
Expand Down
23 changes: 12 additions & 11 deletions blink/renderer/core/dom/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_map.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_linked_hash_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap_observer_set.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cancellable_task.h"
Expand Down Expand Up @@ -1515,14 +1516,15 @@ class CORE_EXPORT Document : public ContainerNode,

HTMLDialogElement* ActiveModalDialog() const;

HeapVector<Member<Element>>& PopupAndHintStack() {
return popup_and_hint_stack_;
}
Element* PopupHintShowing() const { return popup_hint_showing_; }
void SetPopupHintShowing(Element* element) { popup_hint_showing_ = element; }
HeapVector<Member<Element>>& PopupStack() { return popup_stack_; }
const HeapVector<Member<Element>>& PopupStack() const { return popup_stack_; }
bool PopupAutoShowing() const { return !popup_stack_.IsEmpty(); }
Element* TopmostPopupAutoOrHint() const;
HeapHashSet<Member<Element>>& PopupsWaitingToHide() {
return popups_waiting_to_hide_;
}
bool PopupOrHintShowing() const;
bool HintShowing() const;

// A non-null template_document_host_ implies that |this| was created by
// EnsureTemplateDocument().
Expand Down Expand Up @@ -2318,12 +2320,11 @@ class CORE_EXPORT Document : public ContainerNode,
// stack and is thus the one that will be visually on top.
HeapVector<Member<Element>> top_layer_elements_;

// The stack of currently-displayed Popup (and Hint) elements, which are
// elements that have either `popup=popup` or `popup=hint`. Elements in the
// stack go from earliest (bottom-most) to latest (top-most). If there is a
// hint in the stack, it is at the top.
HeapVector<Member<Element>> popup_and_hint_stack_;

// The stack of currently-displayed `popup=auto` elements. Elements in the
// stack go from earliest (bottom-most) to latest (top-most).
HeapVector<Member<Element>> popup_stack_;
// The `popup=hint` that is currently showing, if any.
Member<Element> popup_hint_showing_;
// A set of popups for which hidePopUp() has been called, but animations are
// still running.
HeapHashSet<Member<Element>> popups_waiting_to_hide_;
Expand Down
Loading

0 comments on commit 9e8f08f

Please sign in to comment.