ax_active_popup.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/accessibility/ax_active_popup.h"
  5. namespace ui {
  6. namespace {
  7. absl::optional<AXNodeID>& GetActivePopupAXUniqueIdInstance() {
  8. // Keeps track of the unique ID that can be used to retrieve the
  9. // `ViewAccessibility` object that is handling the accessibility for the
  10. // currently active autofill popup. This singleton is used for communicating
  11. // the live status of the autofill popup between web contents and Views. The
  12. // assumption here is that only one autofill popup can exist at a time.
  13. static absl::optional<AXNodeID> active_popup_ax_unique_id;
  14. return active_popup_ax_unique_id;
  15. }
  16. } // namespace
  17. absl::optional<AXNodeID> GetActivePopupAxUniqueId() {
  18. return GetActivePopupAXUniqueIdInstance();
  19. }
  20. void SetActivePopupAxUniqueId(absl::optional<AXNodeID> ax_unique_id) {
  21. // When an instance of autofill popup hides, the caller of popup hide should
  22. // make sure active_popup_ax_unique_id is cleared. The assumption is that
  23. // there can only be one active autofill popup existing at a time. If on
  24. // popup showing, we encounter active_popup_ax_unique_id is already set,
  25. // this would indicate two autofill popups are showing at the same time or
  26. // previous on popup hide call did not clear the variable, so we should fail
  27. // via DCHECK here.
  28. DCHECK(!GetActivePopupAXUniqueIdInstance());
  29. GetActivePopupAXUniqueIdInstance() = ax_unique_id;
  30. }
  31. void ClearActivePopupAxUniqueId() {
  32. GetActivePopupAXUniqueIdInstance() = absl::nullopt;
  33. }
  34. } // namespace ui