Commit 4d54eaa9 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Commit Bot

Introduce ArcInputMethodBoundsTracker interface in ash/public.

The interface allows classes outside of ash/ to observe any bounds
changes of ARC IME window.
This CL should not cause any behavior change.

Bug: 1060272
Change-Id: I3b5b0652c89fd87ffe93de4903dae11523b30dae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217827
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772651}
parent b37d5bfd
......@@ -28,24 +28,14 @@ void ArcInputMethodSurfaceManager::RemoveSurface(
if (input_method_surface_ == surface)
input_method_surface_ = nullptr;
for (Observer& observer : observers_)
observer.OnArcInputMethodSurfaceBoundsChanged(gfx::Rect());
NotifyArcInputMethodBoundsChanged(gfx::Rect());
}
void ArcInputMethodSurfaceManager::OnTouchableBoundsChanged(
exo::InputMethodSurface* surface) {
DLOG_IF(ERROR, input_method_surface_ != surface)
<< "OnSurfaceTouchableBoundsChanged is called for not registered surface";
for (Observer& observer : observers_)
observer.OnArcInputMethodSurfaceBoundsChanged(surface->GetBounds());
}
void ArcInputMethodSurfaceManager::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void ArcInputMethodSurfaceManager::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
<< "OnTouchableBoundsChanged is called for not registered surface";
NotifyArcInputMethodBoundsChanged(surface->GetBounds());
}
} // namespace ash
......@@ -5,6 +5,7 @@
#ifndef ASH_KEYBOARD_ARC_ARC_INPUT_METHOD_SURFACE_MANAGER_H_
#define ASH_KEYBOARD_ARC_ARC_INPUT_METHOD_SURFACE_MANAGER_H_
#include "ash/public/cpp/keyboard/arc/arc_input_method_bounds_tracker.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "components/exo/input_method_surface_manager.h"
......@@ -12,15 +13,9 @@
namespace ash {
class ArcInputMethodSurfaceManager : public exo::InputMethodSurfaceManager {
class ArcInputMethodSurfaceManager : public exo::InputMethodSurfaceManager,
public ArcInputMethodBoundsTracker {
public:
class Observer : public base::CheckedObserver {
public:
~Observer() override = default;
virtual void OnArcInputMethodSurfaceBoundsChanged(
const gfx::Rect& bounds) = 0;
};
ArcInputMethodSurfaceManager();
~ArcInputMethodSurfaceManager() override;
......@@ -30,15 +25,9 @@ class ArcInputMethodSurfaceManager : public exo::InputMethodSurfaceManager {
void RemoveSurface(exo::InputMethodSurface* surface) override;
void OnTouchableBoundsChanged(exo::InputMethodSurface* surface) override;
// Management of the observer list.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
exo::InputMethodSurface* input_method_surface_ = nullptr; // Not owned
base::ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(ArcInputMethodSurfaceManager);
};
......
......@@ -20,7 +20,7 @@ class TestArcInputMethodSurfaceManagerObserver
TestArcInputMethodSurfaceManagerObserver() = default;
~TestArcInputMethodSurfaceManagerObserver() override = default;
void OnArcInputMethodSurfaceBoundsChanged(const gfx::Rect& bounds) override {
void OnArcInputMethodBoundsChanged(const gfx::Rect& bounds) override {
++bounds_changed_calls_;
last_bounds_ = bounds;
}
......
......@@ -138,6 +138,8 @@ component("cpp") {
"immersive/immersive_fullscreen_controller_delegate.h",
"immersive/immersive_revealed_lock.cc",
"immersive/immersive_revealed_lock.h",
"keyboard/arc/arc_input_method_bounds_tracker.cc",
"keyboard/arc/arc_input_method_bounds_tracker.h",
"keyboard/keyboard_config.h",
"keyboard/keyboard_controller.cc",
"keyboard/keyboard_controller.h",
......
// Copyright 2020 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.
#include "ash/public/cpp/keyboard/arc/arc_input_method_bounds_tracker.h"
namespace ash {
namespace {
ArcInputMethodBoundsTracker* g_instance = nullptr;
} // namespace
// static
ArcInputMethodBoundsTracker* ArcInputMethodBoundsTracker::Get() {
return g_instance;
}
ArcInputMethodBoundsTracker::ArcInputMethodBoundsTracker() {
DCHECK(!g_instance);
g_instance = this;
}
ArcInputMethodBoundsTracker::~ArcInputMethodBoundsTracker() {
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
}
void ArcInputMethodBoundsTracker::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void ArcInputMethodBoundsTracker::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void ArcInputMethodBoundsTracker::NotifyArcInputMethodBoundsChanged(
const gfx::Rect& bounds) {
for (Observer& observer : observers_)
observer.OnArcInputMethodBoundsChanged(bounds);
}
} // namespace ash
// Copyright 2020 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_KEYBOARD_ARC_ARC_INPUT_METHOD_BOUNDS_TRACKER_H_
#define ASH_PUBLIC_CPP_KEYBOARD_ARC_ARC_INPUT_METHOD_BOUNDS_TRACKER_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/observer_list.h"
#include "ui/gfx/geometry/rect.h"
namespace ash {
// This interface keeps tracking the bounds change events of ARC IMEs
// and notifies registered observers of bounds changes.
class ASH_PUBLIC_EXPORT ArcInputMethodBoundsTracker {
public:
class Observer : public base::CheckedObserver {
public:
~Observer() override = default;
virtual void OnArcInputMethodBoundsChanged(const gfx::Rect& bounds) = 0;
};
// Gets the global ArcInputMethodBoundsTracker instance.
static ArcInputMethodBoundsTracker* Get();
ArcInputMethodBoundsTracker();
virtual ~ArcInputMethodBoundsTracker();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void NotifyArcInputMethodBoundsChanged(const gfx::Rect& bounds);
private:
base::ObserverList<Observer> observers_;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_KEYBOARD_ARC_ARC_INPUT_METHOD_BOUNDS_TRACKER_H_
......@@ -57,6 +57,7 @@
#include "ash/host/ash_window_tree_host_init_params.h"
#include "ash/hud_display/hud_display.h"
#include "ash/ime/ime_controller_impl.h"
#include "ash/keyboard/arc/arc_input_method_surface_manager.h"
#include "ash/keyboard/keyboard_controller_impl.h"
#include "ash/keyboard/ui/keyboard_ui_factory.h"
#include "ash/login/login_screen_controller.h"
......@@ -377,7 +378,7 @@ void Shell::InitWaylandServer(std::unique_ptr<exo::FileHelper> file_helper) {
if (wayland_server_controller_) {
system_tray_model()
->virtual_keyboard()
->SetInputMethodSurfaceManagerObserver(
->SetInputMethodBoundsTrackerObserver(
wayland_server_controller_->arc_input_method_surface_manager());
}
}
......@@ -386,7 +387,7 @@ void Shell::DestroyWaylandServer() {
if (wayland_server_controller_) {
system_tray_model()
->virtual_keyboard()
->RemoveInputMethodSurfaceManagerObserver(
->RemoveInputMethodBoundsTrackerObserver(
wayland_server_controller_->arc_input_method_surface_manager());
}
wayland_server_controller_.reset();
......
......@@ -19,19 +19,19 @@ void VirtualKeyboardModel::RemoveObserver(
observers_.RemoveObserver(observer);
}
void VirtualKeyboardModel::SetInputMethodSurfaceManagerObserver(
ArcInputMethodSurfaceManager* input_method_surface_manager) {
DCHECK(input_method_surface_manager);
input_method_surface_manager->AddObserver(this);
void VirtualKeyboardModel::SetInputMethodBoundsTrackerObserver(
ArcInputMethodBoundsTracker* input_method_bounds_tracker) {
DCHECK(input_method_bounds_tracker);
input_method_bounds_tracker->AddObserver(this);
}
void VirtualKeyboardModel::RemoveInputMethodSurfaceManagerObserver(
ArcInputMethodSurfaceManager* input_method_surface_manager) {
DCHECK(input_method_surface_manager);
input_method_surface_manager->RemoveObserver(this);
void VirtualKeyboardModel::RemoveInputMethodBoundsTrackerObserver(
ArcInputMethodBoundsTracker* input_method_bounds_tracker) {
DCHECK(input_method_bounds_tracker);
input_method_bounds_tracker->RemoveObserver(this);
}
void VirtualKeyboardModel::OnArcInputMethodSurfaceBoundsChanged(
void VirtualKeyboardModel::OnArcInputMethodBoundsChanged(
const gfx::Rect& bounds) {
const bool new_visible = !bounds.IsEmpty();
if (visible_ == new_visible)
......
......@@ -8,17 +8,15 @@
#include <memory>
#include "ash/ash_export.h"
#include "ash/keyboard/arc/arc_input_method_surface_manager.h"
#include "ash/public/cpp/keyboard/arc/arc_input_method_bounds_tracker.h"
#include "base/macros.h"
#include "base/observer_list.h"
namespace ash {
class ArcInputMethodSurfaceManager;
// Model to store virtual keyboard visibility state.
class ASH_EXPORT VirtualKeyboardModel
: public ArcInputMethodSurfaceManager::Observer {
: public ArcInputMethodBoundsTracker::Observer {
public:
class Observer {
public:
......@@ -33,14 +31,14 @@ class ASH_EXPORT VirtualKeyboardModel
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// Start/stop observing ArcInputMethodSurfaceManager.
void SetInputMethodSurfaceManagerObserver(
ArcInputMethodSurfaceManager* input_method_surface_manager);
void RemoveInputMethodSurfaceManagerObserver(
ArcInputMethodSurfaceManager* input_method_surface_manager);
// Start/stop observing ArcInputMethodBoundsTracker.
void SetInputMethodBoundsTrackerObserver(
ArcInputMethodBoundsTracker* input_method_bounds_tracker);
void RemoveInputMethodBoundsTrackerObserver(
ArcInputMethodBoundsTracker* input_method_bounds_tracker);
// ArcInputMethodSurfaceManager::Observer:
void OnArcInputMethodSurfaceBoundsChanged(const gfx::Rect& bounds) override;
// ArcInputMethodBoundsTracker::Observer:
void OnArcInputMethodBoundsChanged(const gfx::Rect& bounds) override;
bool visible() const { return visible_; }
......
......@@ -438,7 +438,7 @@ TEST_F(StatusAreaWidgetCollapseStateTest, ImeMenuShownWithVirtualKeyboard) {
Shell::Get()
->system_tray_model()
->virtual_keyboard()
->OnArcInputMethodSurfaceBoundsChanged(gfx::Rect(0, 0, 100, 100));
->OnArcInputMethodBoundsChanged(gfx::Rect(0, 0, 100, 100));
EXPECT_TRUE(ime_menu_->GetVisible());
EXPECT_FALSE(palette_->GetVisible());
EXPECT_FALSE(virtual_keyboard_->GetVisible());
......
......@@ -598,7 +598,7 @@ TEST_F(BackGestureEventHandlerTest, BackGestureWithAndroidKeyboardTest) {
Shell::Get()->system_tray_model()->virtual_keyboard();
ASSERT_TRUE(keyboard);
// Fakes showing the keyboard.
keyboard->OnArcInputMethodSurfaceBoundsChanged(gfx::Rect(400, 400));
keyboard->OnArcInputMethodBoundsChanged(gfx::Rect(400, 400));
EXPECT_TRUE(keyboard->visible());
// Unfortunately we cannot hook this all the wall up to see if the Android IME
......
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