Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: components/arc/ime/arc_ime_service.cc

Issue 2259243002: arc: Use exo::WMHelper to abserve window focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/arc/ime/arc_ime_service.h" 5 #include "components/arc/ime/arc_ime_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/arc/ime/arc_ime_bridge_impl.h" 11 #include "components/arc/ime/arc_ime_bridge_impl.h"
12 #include "components/exo/shell_surface.h" 12 #include "components/exo/shell_surface.h"
13 #include "components/exo/surface.h" 13 #include "components/exo/surface.h"
14 #include "ui/aura/client/focus_client.h"
15 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
16 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
17 #include "ui/aura/window_tree_host.h" 16 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/ime/input_method.h" 17 #include "ui/base/ime/input_method.h"
19 #include "ui/events/base_event_utils.h" 18 #include "ui/events/base_event_utils.h"
20 #include "ui/events/event.h" 19 #include "ui/events/event.h"
21 #include "ui/events/keycodes/keyboard_codes.h" 20 #include "ui/events/keycodes/keyboard_codes.h"
22 21
23 namespace arc { 22 namespace arc {
24 23
(...skipping 10 matching lines...) Expand all
35 } // namespace 34 } // namespace
36 35
37 //////////////////////////////////////////////////////////////////////////////// 36 ////////////////////////////////////////////////////////////////////////////////
38 // ArcImeService main implementation: 37 // ArcImeService main implementation:
39 38
40 ArcImeService::ArcImeService(ArcBridgeService* bridge_service) 39 ArcImeService::ArcImeService(ArcBridgeService* bridge_service)
41 : ArcService(bridge_service), 40 : ArcService(bridge_service),
42 ime_bridge_(new ArcImeBridgeImpl(this, bridge_service)), 41 ime_bridge_(new ArcImeBridgeImpl(this, bridge_service)),
43 ime_type_(ui::TEXT_INPUT_TYPE_NONE), 42 ime_type_(ui::TEXT_INPUT_TYPE_NONE),
44 has_composition_text_(false), 43 has_composition_text_(false),
45 focus_client_(nullptr),
46 keyboard_controller_(nullptr), 44 keyboard_controller_(nullptr),
47 test_input_method_(nullptr) { 45 test_input_method_(nullptr),
46 is_focus_observer_installed_(false) {
48 aura::Env* env = aura::Env::GetInstanceDontCreate(); 47 aura::Env* env = aura::Env::GetInstanceDontCreate();
49 if (env) 48 if (env)
50 env->AddObserver(this); 49 env->AddObserver(this);
51 } 50 }
52 51
53 ArcImeService::~ArcImeService() { 52 ArcImeService::~ArcImeService() {
54 ui::InputMethod* const input_method = GetInputMethod(); 53 ui::InputMethod* const input_method = GetInputMethod();
55 if (input_method) 54 if (input_method)
56 input_method->DetachTextInputClient(this); 55 input_method->DetachTextInputClient(this);
57 56
58 for (aura::Window* window : arc_windows_.windows()) 57 if (is_focus_observer_installed_ && exo::WMHelper::GetInstance())
Yusuke Sato 2016/08/20 01:25:38 Is the is_focus_observer_installed_ check really n
Peng 2016/08/20 13:09:23 As I explained at line 94. It is difficult to remo
59 window->RemoveObserver(this); 58 exo::WMHelper::GetInstance()->RemoveFocusObserver(this);
60 if (focus_client_)
61 focus_client_->RemoveObserver(this);
62 aura::Env* env = aura::Env::GetInstanceDontCreate(); 59 aura::Env* env = aura::Env::GetInstanceDontCreate();
63 if (env) 60 if (env)
64 env->RemoveObserver(this); 61 env->RemoveObserver(this);
65 // Removing |this| from KeyboardController. 62 // Removing |this| from KeyboardController.
66 keyboard::KeyboardController* keyboard_controller = 63 keyboard::KeyboardController* keyboard_controller =
67 keyboard::KeyboardController::GetInstance(); 64 keyboard::KeyboardController::GetInstance();
68 if (keyboard_controller && keyboard_controller_ == keyboard_controller) { 65 if (keyboard_controller && keyboard_controller_ == keyboard_controller) {
69 keyboard_controller_->RemoveObserver(this); 66 keyboard_controller_->RemoveObserver(this);
70 } 67 }
71 } 68 }
(...skipping 14 matching lines...) Expand all
86 if (focused_arc_window_.windows().empty()) 83 if (focused_arc_window_.windows().empty())
87 return nullptr; 84 return nullptr;
88 return focused_arc_window_.windows().front()->GetHost()->GetInputMethod(); 85 return focused_arc_window_.windows().front()->GetHost()->GetInputMethod();
89 } 86 }
90 87
91 //////////////////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////////////////
92 // Overridden from aura::EnvObserver: 89 // Overridden from aura::EnvObserver:
93 90
94 void ArcImeService::OnWindowInitialized(aura::Window* new_window) { 91 void ArcImeService::OnWindowInitialized(aura::Window* new_window) {
95 if (IsArcWindow(new_window)) { 92 if (IsArcWindow(new_window)) {
96 arc_windows_.Add(new_window); 93 if (!is_focus_observer_installed_) {
97 new_window->AddObserver(this); 94 exo::WMHelper::GetInstance()->AddFocusObserver(this);
Yusuke Sato 2016/08/20 01:25:38 Can't we move this to somewhere else (e.g. the con
Peng 2016/08/20 13:09:23 The constructor doesn't work, because this class i
95 is_focus_observer_installed_ = true;
96 }
98 } 97 }
99 keyboard::KeyboardController* keyboard_controller = 98 keyboard::KeyboardController* keyboard_controller =
100 keyboard::KeyboardController::GetInstance(); 99 keyboard::KeyboardController::GetInstance();
101 if (keyboard_controller && keyboard_controller_ != keyboard_controller) { 100 if (keyboard_controller && keyboard_controller_ != keyboard_controller) {
102 // Registering |this| as an observer only once per KeyboardController. 101 // Registering |this| as an observer only once per KeyboardController.
103 keyboard_controller_ = keyboard_controller; 102 keyboard_controller_ = keyboard_controller;
104 keyboard_controller_->AddObserver(this); 103 keyboard_controller_->AddObserver(this);
105 } 104 }
106 } 105 }
107 106
108 void ArcImeService::OnWindowAddedToRootWindow(aura::Window* window) {
109 aura::Window* root = window->GetRootWindow();
110 aura::client::FocusClient* focus_client = aura::client::GetFocusClient(root);
111 if (!focus_client)
112 return;
113
114 if (focus_client_) {
115 // Root windows share the same FocusClient in Ash.
116 DCHECK_EQ(focus_client_, focus_client);
117 } else {
118 focus_client_ = focus_client;
119 focus_client_->AddObserver(this);
120 }
121 }
122
123 //////////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////////
124 // Overridden from aura::client::FocusChangeObserver: 108 // Overridden from exo::WMHelper::FocusChangeObserver:
125 109
126 void ArcImeService::OnWindowFocused(aura::Window* gained_focus, 110 void ArcImeService::OnWindowFocused(aura::Window* gained_focus,
127 aura::Window* lost_focus) { 111 aura::Window* lost_focus) {
128 // The Aura focus may or may not be on sub-window of the toplevel ARC++ frame. 112 // The Aura focus may or may not be on sub-window of the toplevel ARC++ frame.
129 // To handle all cases, judge the state by always climbing up to the toplevel. 113 // To handle all cases, judge the state by always climbing up to the toplevel.
130 gained_focus = gained_focus ? gained_focus->GetToplevelWindow() : nullptr; 114 gained_focus = gained_focus ? gained_focus->GetToplevelWindow() : nullptr;
131 lost_focus = lost_focus ? lost_focus->GetToplevelWindow() : nullptr; 115 lost_focus = lost_focus ? lost_focus->GetToplevelWindow() : nullptr;
132 if (lost_focus == gained_focus) 116 if (lost_focus == gained_focus)
133 return; 117 return;
134 118
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 base::i18n::TextDirection direction) { 332 base::i18n::TextDirection direction) {
349 return false; 333 return false;
350 } 334 }
351 335
352 bool ArcImeService::IsTextEditCommandEnabled( 336 bool ArcImeService::IsTextEditCommandEnabled(
353 ui::TextEditCommand command) const { 337 ui::TextEditCommand command) const {
354 return false; 338 return false;
355 } 339 }
356 340
357 } // namespace arc 341 } // namespace arc
OLDNEW
« components/arc/ime/arc_ime_service.h ('K') | « components/arc/ime/arc_ime_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698