summaryrefslogtreecommitdiffstats
path: root/chromium/components/arc/ime/arc_ime_service.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-08-30 10:22:43 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-08-30 12:36:28 +0000
commit271a6c3487a14599023a9106329505597638d793 (patch)
treee040d58ffc86c1480b79ca8528020ca9ec919bf8 /chromium/components/arc/ime/arc_ime_service.cc
parent7b2ffa587235a47d4094787d72f38102089f402a (diff)
BASELINE: Update Chromium to 77.0.3865.59
Change-Id: I1e89a5f3b009a9519a6705102ad65c92fe736f21 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/arc/ime/arc_ime_service.cc')
-rw-r--r--chromium/components/arc/ime/arc_ime_service.cc78
1 files changed, 58 insertions, 20 deletions
diff --git a/chromium/components/arc/ime/arc_ime_service.cc b/chromium/components/arc/ime/arc_ime_service.cc
index 037682b9c60..ebe0b002f9d 100644
--- a/chromium/components/arc/ime/arc_ime_service.cc
+++ b/chromium/components/arc/ime/arc_ime_service.cc
@@ -6,7 +6,7 @@
#include <utility>
-#include "ash/keyboard/ui/keyboard_controller.h"
+#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/strings/string_util.h"
@@ -20,7 +20,6 @@
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_flags.h"
-#include "ui/base/ui_base_features.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
@@ -93,6 +92,13 @@ class ArcWindowDelegateImpl : public ArcImeService::ArcWindowDelegate {
return window->GetHost()->GetInputMethod();
}
+ bool IsImeBlocked(aura::Window* window) const override {
+ // WMHelper is not created in tests.
+ if (!exo::WMHelper::HasInstance())
+ return false;
+ return exo::WMHelper::GetInstance()->IsImeBlocked(window);
+ }
+
private:
ArcImeService* const ime_service_;
@@ -156,8 +162,8 @@ ArcImeService::~ArcImeService() {
// KeyboardController is destroyed before ArcImeService (except in tests),
// so check whether there is a KeyboardController first before removing |this|
// from KeyboardController observers.
- if (keyboard::KeyboardController::HasInstance()) {
- auto* keyboard_controller = keyboard::KeyboardController::Get();
+ if (keyboard::KeyboardUIController::HasInstance()) {
+ auto* keyboard_controller = keyboard::KeyboardUIController::Get();
if (keyboard_controller->HasObserver(this))
keyboard_controller->RemoveObserver(this);
}
@@ -196,11 +202,8 @@ void ArcImeService::ReattachInputMethod(aura::Window* old_window,
// Overridden from aura::EnvObserver:
void ArcImeService::OnWindowInitialized(aura::Window* new_window) {
- // TODO(mash): Support virtual keyboard under MASH. There is no
- // KeyboardController in the browser process under MASH.
- if (!features::IsMultiProcessMash() &&
- keyboard::KeyboardController::HasInstance()) {
- auto* keyboard_controller = keyboard::KeyboardController::Get();
+ if (keyboard::KeyboardUIController::HasInstance()) {
+ auto* keyboard_controller = keyboard::KeyboardUIController::Get();
if (keyboard_controller->IsEnabled() &&
!keyboard_controller->HasObserver(this)) {
keyboard_controller->AddObserver(this);
@@ -215,15 +218,39 @@ void ArcImeService::OnWindowDestroying(aura::Window* window) {
// This shouldn't be reached on production, since the window lost the focus
// and called OnWindowFocused() before destroying.
// But we handle this case for testing.
- DCHECK_EQ(window, focused_arc_window_);
- OnWindowFocused(nullptr, focused_arc_window_);
+ if (window == focused_arc_window_)
+ OnWindowFocused(nullptr, focused_arc_window_);
}
void ArcImeService::OnWindowRemovingFromRootWindow(aura::Window* window,
aura::Window* new_root) {
- DCHECK_EQ(window, focused_arc_window_);
// IMEs are associated with root windows, hence we may need to detach/attach.
- ReattachInputMethod(focused_arc_window_, new_root);
+ if (window == focused_arc_window_)
+ ReattachInputMethod(focused_arc_window_, new_root);
+}
+
+void ArcImeService::OnWindowPropertyChanged(aura::Window* window,
+ const void* key,
+ intptr_t old) {
+ if (window == focused_arc_window_)
+ return;
+
+ bool ime_blocked = arc_window_delegate_->IsImeBlocked(focused_arc_window_);
+ if (last_ime_blocked_ == ime_blocked)
+ return;
+ last_ime_blocked_ = ime_blocked;
+
+ // IME blocking has changed.
+ ui::InputMethod* const input_method = GetInputMethod();
+ if (input_method) {
+ if (has_composition_text_) {
+ // If it has composition text, clear both ARC's current composition text
+ // and Chrome IME's one.
+ ClearCompositionText();
+ input_method->CancelComposition(this);
+ }
+ input_method->OnTextInputTypeChanged(this);
+ }
}
////////////////////////////////////////////////////////////////////////////////
@@ -238,6 +265,10 @@ void ArcImeService::OnWindowFocused(aura::Window* gained_focus,
const bool attach = arc_window_delegate_->IsInArcAppWindow(gained_focus);
if (detach) {
+ // The focused window and the toplevel window are different in production,
+ // but in tests they can be the same, so avoid adding the observer twice.
+ if (focused_arc_window_ != focused_arc_window_->GetToplevelWindow())
+ focused_arc_window_->GetToplevelWindow()->RemoveObserver(this);
focused_arc_window_->RemoveObserver(this);
focused_arc_window_ = nullptr;
}
@@ -245,6 +276,10 @@ void ArcImeService::OnWindowFocused(aura::Window* gained_focus,
DCHECK_EQ(nullptr, focused_arc_window_);
focused_arc_window_ = gained_focus;
focused_arc_window_->AddObserver(this);
+ // The focused window and the toplevel window are different in production,
+ // but in tests they can be the same, so avoid adding the observer twice.
+ if (focused_arc_window_ != focused_arc_window_->GetToplevelWindow())
+ focused_arc_window_->GetToplevelWindow()->AddObserver(this);
}
ReattachInputMethod(detach ? lost_focus : nullptr, focused_arc_window_);
@@ -319,20 +354,17 @@ void ArcImeService::RequestHideIme() {
if (!focused_arc_window_)
return;
- // TODO(mash): Support virtual keyboard under MASH. There is no
- // KeyboardController in the browser process under MASH.
- if (!features::IsMultiProcessMash() &&
- keyboard::KeyboardController::HasInstance()) {
- auto* keyboard_controller = keyboard::KeyboardController::Get();
+ if (keyboard::KeyboardUIController::HasInstance()) {
+ auto* keyboard_controller = keyboard::KeyboardUIController::Get();
if (keyboard_controller->IsEnabled())
keyboard_controller->HideKeyboardImplicitlyBySystem();
}
}
////////////////////////////////////////////////////////////////////////////////
-// Overridden from keyboard::KeyboardControllerObserver
+// Overridden from ash::KeyboardControllerObserver
void ArcImeService::OnKeyboardAppearanceChanged(
- const keyboard::KeyboardStateDescriptor& state) {
+ const ash::KeyboardStateDescriptor& state) {
gfx::Rect new_bounds = state.occluded_bounds_in_screen;
// Multiply by the scale factor. To convert from DIP to physical pixels.
// The default scale factor is always used in Android side regardless of
@@ -378,6 +410,10 @@ void ArcImeService::InsertText(const base::string16& text) {
}
void ArcImeService::InsertChar(const ui::KeyEvent& event) {
+ // When IME is blocked for the window, let Exo handle the event.
+ if (arc_window_delegate_->IsImeBlocked(focused_arc_window_))
+ return;
+
// According to the document in text_input_client.h, InsertChar() is called
// even when the text input type is NONE. We ignore such events, since for
// ARC we are only interested in the event as a method of text input.
@@ -419,6 +455,8 @@ void ArcImeService::InsertChar(const ui::KeyEvent& event) {
}
ui::TextInputType ArcImeService::GetTextInputType() const {
+ if (arc_window_delegate_->IsImeBlocked(focused_arc_window_))
+ return ui::TEXT_INPUT_TYPE_NONE;
return ime_type_;
}