[go: nahoru, domu]

Reland "Cancel the ChromeVox hint if the system tray bubble is shown"

This is a reland of https://www.crrev.com/c/2757174

The initial change was reverted to enable a clean revert of the
upstream change: https://www.crrev.com/c/2752922

Original change's description:
> In order to cancel the ChromeVox hint when the system tray bubble is
> shown, this change does the following:
> 1. Renames SystemTrayFocusObserver to SystemTrayObserver for better
> naming.
> 2. Adds a method called OnSystemTrayBubbleShown to SystemTrayObserver.
> 3. Implements the above method in CoreOobeHandler that cancels the
> ChromeVox hint.
>
> clicking the status area and waiting 20s.
> clicked.

> Fixed: 1186501
> Test: Manual. Verify that the ChromeVox hint does not fire after
> AX-Relnotes: Cancel the ChromeVox hint timer if the status area is
> Change-Id: Ib18b07c9fd7411b96276488ae32012bfcbf62358
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2757174
> Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#866363}

Change-Id: I461a9e516322e25069425a3d3daf2fb6790d0734
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2795505
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#870110}
diff --git a/ash/login/login_screen_controller.cc b/ash/login/login_screen_controller.cc
index 32bfd480..54a76ad4 100644
--- a/ash/login/login_screen_controller.cc
+++ b/ash/login/login_screen_controller.cc
@@ -66,11 +66,11 @@
 LoginScreenController::LoginScreenController(
     SystemTrayNotifier* system_tray_notifier)
     : system_tray_notifier_(system_tray_notifier) {
-  system_tray_notifier_->AddSystemTrayFocusObserver(this);
+  system_tray_notifier_->AddSystemTrayObserver(this);
 }
 
 LoginScreenController::~LoginScreenController() {
-  system_tray_notifier_->RemoveSystemTrayFocusObserver(this);
+  system_tray_notifier_->RemoveSystemTrayObserver(this);
 }
 
 // static
@@ -481,6 +481,12 @@
   client_->OnFocusLeavingSystemTray(reverse);
 }
 
+void LoginScreenController::OnSystemTrayBubbleShown() {
+  if (!client_)
+    return;
+  client_->OnSystemTrayBubbleShown();
+}
+
 void LoginScreenController::OnLockScreenDestroyed() {
   DCHECK_EQ(authentication_stage_, AuthenticationStage::kIdle);
 
diff --git a/ash/login/login_screen_controller.h b/ash/login/login_screen_controller.h
index ec8ea8ca..2d26ed544 100644
--- a/ash/login/login_screen_controller.h
+++ b/ash/login/login_screen_controller.h
@@ -13,7 +13,7 @@
 #include "ash/public/cpp/kiosk_app_menu.h"
 #include "ash/public/cpp/login_accelerators.h"
 #include "ash/public/cpp/login_screen.h"
-#include "ash/public/cpp/system_tray_focus_observer.h"
+#include "ash/public/cpp/system_tray_observer.h"
 #include "base/macros.h"
 #include "base/optional.h"
 #include "base/time/time.h"
@@ -34,7 +34,7 @@
 // LoginScreen interface.
 class ASH_EXPORT LoginScreenController : public LoginScreen,
                                          public KioskAppMenu,
-                                         public SystemTrayFocusObserver {
+                                         public SystemTrayObserver {
  public:
   // The current authentication stage. Used to get more verbose logging.
   enum class AuthenticationStage {
@@ -151,8 +151,9 @@
   // Common code that is called when the login/lock screen is shown.
   void OnShow();
 
-  // SystemTrayFocusObserver:
+  // SystemTrayObserver:
   void OnFocusLeavingSystemTray(bool reverse) override;
+  void OnSystemTrayBubbleShown() override;
 
   LoginDataDispatcher login_data_dispatcher_;
 
diff --git a/ash/login/mock_login_screen_client.h b/ash/login/mock_login_screen_client.h
index d3d1be3..6f6e8c3a 100644
--- a/ash/login/mock_login_screen_client.h
+++ b/ash/login/mock_login_screen_client.h
@@ -110,6 +110,7 @@
   MOCK_METHOD(void, OnFocusLeavingSystemTray, (bool reverse), (override));
   MOCK_METHOD(void, OnUserActivity, (), (override));
   MOCK_METHOD(void, OnLoginScreenShown, (), (override));
+  MOCK_METHOD(void, OnSystemTrayBubbleShown, (), (override));
 
  private:
   bool authenticate_user_callback_result_ = true;
diff --git a/ash/login/ui/lock_contents_view.cc b/ash/login/ui/lock_contents_view.cc
index fc4ae6df..ee8dccd 100644
--- a/ash/login/ui/lock_contents_view.cc
+++ b/ash/login/ui/lock_contents_view.cc
@@ -588,7 +588,7 @@
 
   data_dispatcher_->AddObserver(this);
   display_observation_.Observe(display::Screen::GetScreen());
-  Shell::Get()->system_tray_notifier()->AddSystemTrayFocusObserver(this);
+  Shell::Get()->system_tray_notifier()->AddSystemTrayObserver(this);
   keyboard::KeyboardUIController::Get()->AddObserver(this);
 
   // We reuse the focusable state on this view as a signal that focus should
@@ -684,7 +684,7 @@
   Shell::Get()->accelerator_controller()->UnregisterAll(this);
   data_dispatcher_->RemoveObserver(this);
   keyboard::KeyboardUIController::Get()->RemoveObserver(this);
-  Shell::Get()->system_tray_notifier()->RemoveSystemTrayFocusObserver(this);
+  Shell::Get()->system_tray_notifier()->RemoveSystemTrayObserver(this);
 
   // Times a password was incorrectly entered until view is destroyed.
   Shell::Get()->metrics()->login_metrics_recorder()->RecordNumLoginAttempts(
diff --git a/ash/login/ui/lock_contents_view.h b/ash/login/ui/lock_contents_view.h
index 6035058..8a2262c 100644
--- a/ash/login/ui/lock_contents_view.h
+++ b/ash/login/ui/lock_contents_view.h
@@ -22,7 +22,7 @@
 #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
 #include "ash/public/cpp/login_accelerators.h"
 #include "ash/public/cpp/login_types.h"
-#include "ash/public/cpp/system_tray_focus_observer.h"
+#include "ash/public/cpp/system_tray_observer.h"
 #include "base/callback_forward.h"
 #include "base/macros.h"
 #include "base/memory/weak_ptr.h"
@@ -65,7 +65,7 @@
 class ASH_EXPORT LockContentsView
     : public NonAccessibleView,
       public LoginDataDispatcher::Observer,
-      public SystemTrayFocusObserver,
+      public SystemTrayObserver,
       public display::DisplayObserver,
       public KeyboardControllerObserver,
       public chromeos::PowerManagerClient::Observer {
@@ -208,7 +208,7 @@
   void MaybeUpdateExpandedView(const AccountId& account_id,
                                const LoginUserInfo& user_info);
 
-  // SystemTrayFocusObserver:
+  // SystemTrayObserver:
   void OnFocusLeavingSystemTray(bool reverse) override;
 
   // display::DisplayObserver:
diff --git a/ash/public/cpp/BUILD.gn b/ash/public/cpp/BUILD.gn
index 66369e9..4a49bb2 100644
--- a/ash/public/cpp/BUILD.gn
+++ b/ash/public/cpp/BUILD.gn
@@ -284,7 +284,7 @@
     "system_tray.cc",
     "system_tray.h",
     "system_tray_client.h",
-    "system_tray_focus_observer.h",
+    "system_tray_observer.h",
     "tablet_mode.cc",
     "tablet_mode.h",
     "tablet_mode_observer.h",
diff --git a/ash/public/cpp/login_screen_client.h b/ash/public/cpp/login_screen_client.h
index 79b10ec..88af241 100644
--- a/ash/public/cpp/login_screen_client.h
+++ b/ash/public/cpp/login_screen_client.h
@@ -153,6 +153,9 @@
   // reversed direction.
   virtual void OnFocusLeavingSystemTray(bool reverse) = 0;
 
+  // Called when the system tray bubble is shown.
+  virtual void OnSystemTrayBubbleShown() = 0;
+
   // Called when the lock screen is shown.
   virtual void OnLoginScreenShown() = 0;
 
diff --git a/ash/public/cpp/system_tray_focus_observer.h b/ash/public/cpp/system_tray_focus_observer.h
deleted file mode 100644
index 5a1aeea..0000000
--- a/ash/public/cpp/system_tray_focus_observer.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ASH_PUBLIC_CPP_SYSTEM_TRAY_FOCUS_OBSERVER_H_
-#define ASH_PUBLIC_CPP_SYSTEM_TRAY_FOCUS_OBSERVER_H_
-
-#include "ash/public/cpp/ash_public_export.h"
-#include "base/macros.h"
-
-namespace ash {
-
-// A class that observes system tray related focus events.
-class ASH_PUBLIC_EXPORT SystemTrayFocusObserver {
- public:
-  // Called when focus is about to leave system tray.
-  virtual void OnFocusLeavingSystemTray(bool reverse) = 0;
-
- protected:
-  virtual ~SystemTrayFocusObserver() = default;
-};
-
-}  // namespace ash
-
-#endif  // ASH_PUBLIC_CPP_SYSTEM_TRAY_FOCUS_OBSERVER_H_
diff --git a/ash/public/cpp/system_tray_observer.h b/ash/public/cpp/system_tray_observer.h
new file mode 100644
index 0000000..00fc8021
--- /dev/null
+++ b/ash/public/cpp/system_tray_observer.h
@@ -0,0 +1,28 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_PUBLIC_CPP_SYSTEM_TRAY_OBSERVER_H_
+#define ASH_PUBLIC_CPP_SYSTEM_TRAY_OBSERVER_H_
+
+#include "ash/public/cpp/ash_public_export.h"
+#include "base/macros.h"
+
+namespace ash {
+
+// A class that observes system tray related focus events.
+class ASH_PUBLIC_EXPORT SystemTrayObserver {
+ public:
+  // Called when focus is about to leave system tray.
+  virtual void OnFocusLeavingSystemTray(bool reverse) = 0;
+
+  // Called when the UnifiedSystemTrayBubble is shown.
+  virtual void OnSystemTrayBubbleShown() {}
+
+ protected:
+  virtual ~SystemTrayObserver() = default;
+};
+
+}  // namespace ash
+
+#endif  // ASH_PUBLIC_CPP_SYSTEM_TRAY_OBSERVER_H_
diff --git a/ash/system/status_area_widget_unittest.cc b/ash/system/status_area_widget_unittest.cc
index 453fea4..ab36cdc0 100644
--- a/ash/system/status_area_widget_unittest.cc
+++ b/ash/system/status_area_widget_unittest.cc
@@ -10,7 +10,7 @@
 #include "ash/keyboard/ui/test/keyboard_test_util.h"
 #include "ash/public/cpp/ash_switches.h"
 #include "ash/public/cpp/keyboard/keyboard_switches.h"
-#include "ash/public/cpp/system_tray_focus_observer.h"
+#include "ash/public/cpp/system_tray_observer.h"
 #include "ash/session/session_controller_impl.h"
 #include "ash/session/test_session_controller_client.h"
 #include "ash/shell.h"
@@ -74,7 +74,7 @@
   EXPECT_FALSE(status->virtual_keyboard_tray_for_testing()->GetVisible());
 }
 
-class SystemTrayFocusTestObserver : public SystemTrayFocusObserver {
+class SystemTrayFocusTestObserver : public SystemTrayObserver {
  public:
   SystemTrayFocusTestObserver() = default;
   ~SystemTrayFocusTestObserver() override = default;
@@ -83,7 +83,7 @@
   int reverse_focus_out_count() { return reverse_focus_out_count_; }
 
  protected:
-  // SystemTrayFocusObserver:
+  // SystemTrayObserver:
   void OnFocusLeavingSystemTray(bool reverse) override {
     reverse ? ++reverse_focus_out_count_ : ++focus_out_count_;
   }
@@ -104,13 +104,13 @@
   void SetUp() override {
     AshTestBase::SetUp();
     test_observer_.reset(new SystemTrayFocusTestObserver);
-    Shell::Get()->system_tray_notifier()->AddSystemTrayFocusObserver(
+    Shell::Get()->system_tray_notifier()->AddSystemTrayObserver(
         test_observer_.get());
   }
 
   // AshTestBase:
   void TearDown() override {
-    Shell::Get()->system_tray_notifier()->RemoveSystemTrayFocusObserver(
+    Shell::Get()->system_tray_notifier()->RemoveSystemTrayObserver(
         test_observer_.get());
     test_observer_.reset();
     AshTestBase::TearDown();
diff --git a/ash/system/tray/system_tray_notifier.cc b/ash/system/tray/system_tray_notifier.cc
index 574f1c5..80d21d8 100644
--- a/ash/system/tray/system_tray_notifier.cc
+++ b/ash/system/tray/system_tray_notifier.cc
@@ -4,7 +4,7 @@
 
 #include "ash/system/tray/system_tray_notifier.h"
 
-#include "ash/public/cpp/system_tray_focus_observer.h"
+#include "ash/public/cpp/system_tray_observer.h"
 #include "ash/system/ime/ime_observer.h"
 #include "ash/system/network/network_observer.h"
 #include "ash/system/screen_security/screen_capture_observer.h"
@@ -93,21 +93,25 @@
     observer.OnScreenShareStop();
 }
 
-void SystemTrayNotifier::AddSystemTrayFocusObserver(
-    SystemTrayFocusObserver* observer) {
-  system_tray_focus_observers_.AddObserver(observer);
+void SystemTrayNotifier::AddSystemTrayObserver(SystemTrayObserver* observer) {
+  system_tray_observers_.AddObserver(observer);
 }
 
-void SystemTrayNotifier::RemoveSystemTrayFocusObserver(
-    SystemTrayFocusObserver* observer) {
-  system_tray_focus_observers_.RemoveObserver(observer);
+void SystemTrayNotifier::RemoveSystemTrayObserver(
+    SystemTrayObserver* observer) {
+  system_tray_observers_.RemoveObserver(observer);
 }
 
 void SystemTrayNotifier::NotifyFocusOut(bool reverse) {
-  for (auto& observer : system_tray_focus_observers_)
+  for (auto& observer : system_tray_observers_)
     observer.OnFocusLeavingSystemTray(reverse);
 }
 
+void SystemTrayNotifier::NotifySystemTrayBubbleShown() {
+  for (auto& observer : system_tray_observers_)
+    observer.OnSystemTrayBubbleShown();
+}
+
 void SystemTrayNotifier::AddVirtualKeyboardObserver(
     VirtualKeyboardObserver* observer) {
   virtual_keyboard_observers_.AddObserver(observer);
diff --git a/ash/system/tray/system_tray_notifier.h b/ash/system/tray/system_tray_notifier.h
index 3f57ddb..73fd2a3 100644
--- a/ash/system/tray/system_tray_notifier.h
+++ b/ash/system/tray/system_tray_notifier.h
@@ -19,7 +19,7 @@
 class NetworkObserver;
 class ScreenCaptureObserver;
 class ScreenShareObserver;
-class SystemTrayFocusObserver;
+class SystemTrayObserver;
 class VirtualKeyboardObserver;
 
 namespace mojom {
@@ -59,9 +59,10 @@
   void NotifyScreenShareStop();
 
   // System tray focus.
-  void AddSystemTrayFocusObserver(SystemTrayFocusObserver* observer);
-  void RemoveSystemTrayFocusObserver(SystemTrayFocusObserver* observer);
+  void AddSystemTrayObserver(SystemTrayObserver* observer);
+  void RemoveSystemTrayObserver(SystemTrayObserver* observer);
   void NotifyFocusOut(bool reverse);
+  void NotifySystemTrayBubbleShown();
 
   // Virtual keyboard.
   void AddVirtualKeyboardObserver(VirtualKeyboardObserver* observer);
@@ -74,8 +75,7 @@
   base::ObserverList<ScreenCaptureObserver>::Unchecked
       screen_capture_observers_;
   base::ObserverList<ScreenShareObserver>::Unchecked screen_share_observers_;
-  base::ObserverList<SystemTrayFocusObserver>::Unchecked
-      system_tray_focus_observers_;
+  base::ObserverList<SystemTrayObserver>::Unchecked system_tray_observers_;
   base::ObserverList<VirtualKeyboardObserver>::Unchecked
       virtual_keyboard_observers_;
 
diff --git a/ash/system/unified/unified_system_tray.cc b/ash/system/unified/unified_system_tray.cc
index 666e878..400552a 100644
--- a/ash/system/unified/unified_system_tray.cc
+++ b/ash/system/unified/unified_system_tray.cc
@@ -22,6 +22,7 @@
 #include "ash/system/privacy_screen/privacy_screen_toast_controller.h"
 #include "ash/system/time/time_tray_item_view.h"
 #include "ash/system/time/time_view.h"
+#include "ash/system/tray/system_tray_notifier.h"
 #include "ash/system/tray/tray_constants.h"
 #include "ash/system/tray/tray_container.h"
 #include "ash/system/unified/camera_mic_tray_item_view.h"
@@ -367,8 +368,10 @@
 
 void UnifiedSystemTray::ShowBubble() {
   // ShowBubbleInternal will be called from UiDelegate.
-  if (!bubble_)
+  if (!bubble_) {
     ui_delegate_->ui_controller()->ShowMessageCenterBubble();
+    Shell::Get()->system_tray_notifier()->NotifySystemTrayBubbleShown();
+  }
 }
 
 void UnifiedSystemTray::CloseBubble() {