Commit 6017edbb authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Remove unnecessary observers of OnVirtualKeyboardStateChanged.

Some classes listen to ShellObserver::OnVirtualKeyboardStateChanged in
order to add/remove KeyboardController observer when the keyboard is
enabled/disabled. However, with the simplified KeyboardController
lifetimes, we can add/remove observers whenever.

So we just add an observer in the constructor and remove it in the
destructor.

After this change, there will be no more observers of
OnVirtualKeyboardStateChanged.

Bug: 731537
Change-Id: I7274484229ff5f64ac973806e565f178a271094f
Reviewed-on: https://chromium-review.googlesource.com/1101598Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567918}
parent e4973655
...@@ -41,7 +41,6 @@ namespace ash { ...@@ -41,7 +41,6 @@ namespace ash {
AppListControllerImpl::AppListControllerImpl() AppListControllerImpl::AppListControllerImpl()
: presenter_(std::make_unique<AppListPresenterDelegateImpl>(this)), : presenter_(std::make_unique<AppListPresenterDelegateImpl>(this)),
keyboard_observer_(this),
is_home_launcher_enabled_(app_list::features::IsHomeLauncherEnabled()) { is_home_launcher_enabled_(app_list::features::IsHomeLauncherEnabled()) {
model_.AddObserver(this); model_.AddObserver(this);
...@@ -63,9 +62,11 @@ AppListControllerImpl::AppListControllerImpl() ...@@ -63,9 +62,11 @@ AppListControllerImpl::AppListControllerImpl()
Shell::Get()->tablet_mode_controller()->AddObserver(this); Shell::Get()->tablet_mode_controller()->AddObserver(this);
Shell::Get()->wallpaper_controller()->AddObserver(this); Shell::Get()->wallpaper_controller()->AddObserver(this);
Shell::Get()->AddShellObserver(this); Shell::Get()->AddShellObserver(this);
keyboard::KeyboardController::Get()->AddObserver(this);
} }
AppListControllerImpl::~AppListControllerImpl() { AppListControllerImpl::~AppListControllerImpl() {
keyboard::KeyboardController::Get()->RemoveObserver(this);
Shell::Get()->RemoveShellObserver(this); Shell::Get()->RemoveShellObserver(this);
Shell::Get()->wallpaper_controller()->RemoveObserver(this); Shell::Get()->wallpaper_controller()->RemoveObserver(this);
Shell::Get()->tablet_mode_controller()->RemoveObserver(this); Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
...@@ -446,18 +447,6 @@ void AppListControllerImpl::FlushForTesting() { ...@@ -446,18 +447,6 @@ void AppListControllerImpl::FlushForTesting() {
bindings_.FlushForTesting(); bindings_.FlushForTesting();
} }
void AppListControllerImpl::OnVirtualKeyboardStateChanged(
bool activated,
aura::Window* root_window) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
if (!keyboard_controller->enabled())
return;
if (activated && !keyboard_observer_.IsObserving(keyboard_controller))
keyboard_observer_.Add(keyboard_controller);
else if (!activated && keyboard_observer_.IsObserving(keyboard_controller))
keyboard_observer_.Remove(keyboard_controller);
}
void AppListControllerImpl::OnOverviewModeStarting() { void AppListControllerImpl::OnOverviewModeStarting() {
in_overview_mode_ = true; in_overview_mode_ = true;
if (!IsHomeLauncherEnabledInTabletMode()) { if (!IsHomeLauncherEnabledInTabletMode()) {
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "ash/shell_observer.h" #include "ash/shell_observer.h"
#include "ash/wallpaper/wallpaper_controller_observer.h" #include "ash/wallpaper/wallpaper_controller_observer.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h" #include "ash/wm/tablet_mode/tablet_mode_observer.h"
#include "base/scoped_observer.h"
#include "components/sync/model/string_ordinal.h" #include "components/sync/model/string_ordinal.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h" #include "mojo/public/cpp/bindings/interface_ptr_set.h"
...@@ -171,8 +170,6 @@ class ASH_EXPORT AppListControllerImpl ...@@ -171,8 +170,6 @@ class ASH_EXPORT AppListControllerImpl
void FlushForTesting(); void FlushForTesting();
// ShellObserver: // ShellObserver:
void OnVirtualKeyboardStateChanged(bool activated,
aura::Window* root_window) override;
void OnOverviewModeStarting() override; void OnOverviewModeStarting() override;
void OnOverviewModeEnding() override; void OnOverviewModeEnding() override;
...@@ -221,10 +218,6 @@ class ASH_EXPORT AppListControllerImpl ...@@ -221,10 +218,6 @@ class ASH_EXPORT AppListControllerImpl
std::unique_ptr<app_list::AnswerCardContentsRegistry> std::unique_ptr<app_list::AnswerCardContentsRegistry>
answer_card_contents_registry_; answer_card_contents_registry_;
ScopedObserver<keyboard::KeyboardController,
keyboard::KeyboardControllerObserver>
keyboard_observer_;
// Whether the on-screen keyboard is shown. // Whether the on-screen keyboard is shown.
bool onscreen_keyboard_shown_ = false; bool onscreen_keyboard_shown_ = false;
......
...@@ -570,7 +570,6 @@ void RootWindowController::ActivateKeyboard( ...@@ -570,7 +570,6 @@ void RootWindowController::ActivateKeyboard(
aura::Window* keyboard_window = keyboard_controller->GetContainerWindow(); aura::Window* keyboard_window = keyboard_controller->GetContainerWindow();
DCHECK(!keyboard_window->parent()); DCHECK(!keyboard_window->parent());
Shell::Get()->NotifyVirtualKeyboardActivated(true, GetRootWindow());
aura::Window* vk_container = aura::Window* vk_container =
GetContainer(kShellWindowId_VirtualKeyboardContainer); GetContainer(kShellWindowId_VirtualKeyboardContainer);
DCHECK(vk_container); DCHECK(vk_container);
...@@ -597,7 +596,6 @@ void RootWindowController::DeactivateKeyboard( ...@@ -597,7 +596,6 @@ void RootWindowController::DeactivateKeyboard(
DCHECK(vk_container); DCHECK(vk_container);
DCHECK_EQ(vk_container, keyboard_window->parent()); DCHECK_EQ(vk_container, keyboard_window->parent());
vk_container->RemoveChild(keyboard_window); vk_container->RemoveChild(keyboard_window);
Shell::Get()->NotifyVirtualKeyboardActivated(false, GetRootWindow());
} }
} }
......
...@@ -640,12 +640,6 @@ void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) { ...@@ -640,12 +640,6 @@ void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
observer.OnPinnedStateChanged(pinned_window); observer.OnPinnedStateChanged(pinned_window);
} }
void Shell::NotifyVirtualKeyboardActivated(bool activated,
aura::Window* root_window) {
for (auto& observer : shell_observers_)
observer.OnVirtualKeyboardStateChanged(activated, root_window);
}
void Shell::NotifyShelfCreatedForRootWindow(aura::Window* root_window) { void Shell::NotifyShelfCreatedForRootWindow(aura::Window* root_window) {
for (auto& observer : shell_observers_) for (auto& observer : shell_observers_)
observer.OnShelfCreatedForRootWindow(root_window); observer.OnShelfCreatedForRootWindow(root_window);
......
...@@ -643,11 +643,6 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -643,11 +643,6 @@ class ASH_EXPORT Shell : public SessionObserver,
// Notifies observers that |pinned_window| changed its pinned window state. // Notifies observers that |pinned_window| changed its pinned window state.
void NotifyPinnedStateChanged(aura::Window* pinned_window); void NotifyPinnedStateChanged(aura::Window* pinned_window);
// Notifies observers that the virtual keyboard has been
// activated/deactivated for |root_window|.
void NotifyVirtualKeyboardActivated(bool activated,
aura::Window* root_window);
// Notifies observers that the shelf was created for |root_window|. // Notifies observers that the shelf was created for |root_window|.
// TODO(jamescook): Move to Shelf. // TODO(jamescook): Move to Shelf.
void NotifyShelfCreatedForRootWindow(aura::Window* root_window); void NotifyShelfCreatedForRootWindow(aura::Window* root_window);
......
...@@ -71,10 +71,6 @@ class ASH_EXPORT ShellObserver { ...@@ -71,10 +71,6 @@ class ASH_EXPORT ShellObserver {
// Called when dicatation is ended. // Called when dicatation is ended.
virtual void OnDictationEnded() {} virtual void OnDictationEnded() {}
// Called when keyboard is activated/deactivated in |root_window|.
virtual void OnVirtualKeyboardStateChanged(bool activated,
aura::Window* root_window) {}
// Called when a new KeyboardController is created. // Called when a new KeyboardController is created.
virtual void OnKeyboardControllerCreated() {} virtual void OnKeyboardControllerCreated() {}
......
...@@ -127,11 +127,7 @@ WebUILoginView::WebUILoginView(const WebViewSettings& settings) ...@@ -127,11 +127,7 @@ WebUILoginView::WebUILoginView(const WebViewSettings& settings)
// TODO(mash): Support virtual keyboard under MASH. There is no // TODO(mash): Support virtual keyboard under MASH. There is no
// KeyboardController in the browser process under MASH. // KeyboardController in the browser process under MASH.
if (!ash_util::IsRunningInMash()) { if (!ash_util::IsRunningInMash()) {
if (keyboard::KeyboardController::Get()->enabled()) keyboard::KeyboardController::Get()->AddObserver(this);
keyboard::KeyboardController::Get()->AddObserver(this);
// TODO(crbug.com/648733): OnVirtualKeyboardStateChanged not supported in
// mash
ash::Shell::Get()->AddShellObserver(this);
} else { } else {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
...@@ -215,20 +211,12 @@ WebUILoginView::~WebUILoginView() { ...@@ -215,20 +211,12 @@ WebUILoginView::~WebUILoginView() {
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnHostDestroying(); observer.OnHostDestroying();
// TODO(crbug.com/648733): OnVirtualKeyboardStateChanged not supported in mash
if (!ash_util::IsRunningInMash()) {
ash::Shell::Get()->RemoveShellObserver(this);
if (keyboard::KeyboardController::Get()->enabled())
keyboard::KeyboardController::Get()->RemoveObserver(this);
}
if (!ash_util::IsRunningInMash()) { if (!ash_util::IsRunningInMash()) {
ash::Shell::Get()->system_tray_notifier()->RemoveSystemTrayFocusObserver( ash::Shell::Get()->system_tray_notifier()->RemoveSystemTrayFocusObserver(
this); this);
}
if (!ash_util::IsRunningInMash())
ash::Shell::Get()->accelerator_controller()->UnregisterAll(this); ash::Shell::Get()->accelerator_controller()->UnregisterAll(this);
keyboard::KeyboardController::Get()->RemoveObserver(this);
}
// Clear any delegates we have set on the WebView. // Clear any delegates we have set on the WebView.
WebContents* web_contents = web_view()->GetWebContents(); WebContents* web_contents = web_view()->GetWebContents();
...@@ -458,23 +446,6 @@ void WebUILoginView::ClearLockScreenAppFocusCyclerDelegate() { ...@@ -458,23 +446,6 @@ void WebUILoginView::ClearLockScreenAppFocusCyclerDelegate() {
delegates_lock_screen_app_focus_cycle_ = false; delegates_lock_screen_app_focus_cycle_ = false;
} }
////////////////////////////////////////////////////////////////////////////////
// ash::ShellObserver:
void WebUILoginView::OnVirtualKeyboardStateChanged(bool activated,
aura::Window* root_window) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
DCHECK(keyboard_controller);
if (keyboard_controller->enabled()) {
if (activated) {
if (!keyboard_controller->HasObserver(this))
keyboard_controller->AddObserver(this);
} else {
keyboard_controller->RemoveObserver(this);
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// keyboard::KeyboardControllerObserver: // keyboard::KeyboardControllerObserver:
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include "ash/shell_observer.h"
#include "ash/system/system_tray_focus_observer.h" #include "ash/system/system_tray_focus_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
...@@ -42,7 +41,6 @@ class OobeUI; ...@@ -42,7 +41,6 @@ class OobeUI;
// View used to render a WebUI supporting Widget. This widget is used for the // View used to render a WebUI supporting Widget. This widget is used for the
// WebUI based start up and lock screens. It contains a WebView. // WebUI based start up and lock screens. It contains a WebView.
class WebUILoginView : public views::View, class WebUILoginView : public views::View,
public ash::ShellObserver,
public keyboard::KeyboardControllerObserver, public keyboard::KeyboardControllerObserver,
public content::WebContentsDelegate, public content::WebContentsDelegate,
public content::NotificationObserver, public content::NotificationObserver,
...@@ -147,10 +145,6 @@ class WebUILoginView : public views::View, ...@@ -147,10 +145,6 @@ class WebUILoginView : public views::View,
// Map type for the accelerator-to-identifier map. // Map type for the accelerator-to-identifier map.
typedef std::map<ui::Accelerator, std::string> AccelMap; typedef std::map<ui::Accelerator, std::string> AccelMap;
// ash::ShellObserver:
void OnVirtualKeyboardStateChanged(bool activated,
aura::Window* root_window) override;
// keyboard::KeyboardControllerObserver: // keyboard::KeyboardControllerObserver:
void OnKeyboardAvailabilityChanged(bool is_available) override; void OnKeyboardAvailabilityChanged(bool is_available) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment