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

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

Issue 2179903002: ARC: Avoid duplicate observers in IME service (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
« no previous file with comments | « components/arc/ime/arc_ime_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 24 matching lines...) Expand all
35 } // namespace 35 } // namespace
36 36
37 //////////////////////////////////////////////////////////////////////////////// 37 ////////////////////////////////////////////////////////////////////////////////
38 // ArcImeService main implementation: 38 // ArcImeService main implementation:
39 39
40 ArcImeService::ArcImeService(ArcBridgeService* bridge_service) 40 ArcImeService::ArcImeService(ArcBridgeService* bridge_service)
41 : ArcService(bridge_service), 41 : ArcService(bridge_service),
42 ime_bridge_(new ArcImeBridgeImpl(this, bridge_service)), 42 ime_bridge_(new ArcImeBridgeImpl(this, bridge_service)),
43 ime_type_(ui::TEXT_INPUT_TYPE_NONE), 43 ime_type_(ui::TEXT_INPUT_TYPE_NONE),
44 has_composition_text_(false), 44 has_composition_text_(false),
45 focus_client_(nullptr),
45 keyboard_controller_(nullptr), 46 keyboard_controller_(nullptr),
46 test_input_method_(nullptr) { 47 test_input_method_(nullptr) {
47 aura::Env* env = aura::Env::GetInstanceDontCreate(); 48 aura::Env* env = aura::Env::GetInstanceDontCreate();
48 if (env) 49 if (env)
49 env->AddObserver(this); 50 env->AddObserver(this);
50 } 51 }
51 52
52 ArcImeService::~ArcImeService() { 53 ArcImeService::~ArcImeService() {
53 ui::InputMethod* const input_method = GetInputMethod(); 54 ui::InputMethod* const input_method = GetInputMethod();
54 if (input_method) 55 if (input_method)
55 input_method->DetachTextInputClient(this); 56 input_method->DetachTextInputClient(this);
56 57
57 for (aura::Window* window : arc_windows_.windows()) 58 for (aura::Window* window : arc_windows_.windows())
58 window->RemoveObserver(this); 59 window->RemoveObserver(this);
59 for (aura::Window* root : observing_root_windows_.windows()) 60 if (focus_client_)
60 aura::client::GetFocusClient(root)->RemoveObserver(this); 61 focus_client_->RemoveObserver(this);
61 aura::Env* env = aura::Env::GetInstanceDontCreate(); 62 aura::Env* env = aura::Env::GetInstanceDontCreate();
62 if (env) 63 if (env)
63 env->RemoveObserver(this); 64 env->RemoveObserver(this);
64 // Removing |this| from KeyboardController. 65 // Removing |this| from KeyboardController.
65 keyboard::KeyboardController* keyboard_controller = 66 keyboard::KeyboardController* keyboard_controller =
66 keyboard::KeyboardController::GetInstance(); 67 keyboard::KeyboardController::GetInstance();
67 if (keyboard_controller && keyboard_controller_ == keyboard_controller) { 68 if (keyboard_controller && keyboard_controller_ == keyboard_controller) {
68 keyboard_controller_->RemoveObserver(this); 69 keyboard_controller_->RemoveObserver(this);
69 } 70 }
70 } 71 }
(...skipping 19 matching lines...) Expand all
90 //////////////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////////
91 // Overridden from aura::EnvObserver: 92 // Overridden from aura::EnvObserver:
92 93
93 void ArcImeService::OnWindowInitialized(aura::Window* new_window) { 94 void ArcImeService::OnWindowInitialized(aura::Window* new_window) {
94 if (IsArcWindow(new_window)) { 95 if (IsArcWindow(new_window)) {
95 arc_windows_.Add(new_window); 96 arc_windows_.Add(new_window);
96 new_window->AddObserver(this); 97 new_window->AddObserver(this);
97 } 98 }
98 keyboard::KeyboardController* keyboard_controller = 99 keyboard::KeyboardController* keyboard_controller =
99 keyboard::KeyboardController::GetInstance(); 100 keyboard::KeyboardController::GetInstance();
100 if (keyboard_controller && keyboard_controller_ != keyboard_controller) { 101 if (keyboard_controller && keyboard_controller_ != keyboard_controller) {
oshima 2016/07/25 19:13:00 does this mean that the keyboard_controller_ point
Dominik Laskowski 2016/07/25 19:54:18 Yes, it can be stale after a call to KeyboardContr
101 // Registering |this| as an observer only once per KeyboardController. 102 // Registering |this| as an observer only once per KeyboardController.
102 keyboard_controller_ = keyboard_controller; 103 keyboard_controller_ = keyboard_controller;
103 keyboard_controller_->AddObserver(this); 104 keyboard_controller_->AddObserver(this);
104 } 105 }
105 } 106 }
106 107
107 void ArcImeService::OnWindowAddedToRootWindow(aura::Window* window) { 108 void ArcImeService::OnWindowAddedToRootWindow(aura::Window* window) {
108 aura::Window* root = window->GetRootWindow(); 109 aura::Window* root = window->GetRootWindow();
109 aura::client::FocusClient* focus_client = aura::client::GetFocusClient(root); 110 aura::client::FocusClient* focus_client = aura::client::GetFocusClient(root);
110 if (focus_client && !observing_root_windows_.Contains(root)) { 111 if (!focus_client)
111 focus_client->AddObserver(this); 112 return;
112 observing_root_windows_.Add(root); 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);
113 } 120 }
114 } 121 }
115 122
116 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
117 // Overridden from aura::client::FocusChangeObserver: 124 // Overridden from aura::client::FocusChangeObserver:
118 125
119 void ArcImeService::OnWindowFocused(aura::Window* gained_focus, 126 void ArcImeService::OnWindowFocused(aura::Window* gained_focus,
120 aura::Window* lost_focus) { 127 aura::Window* lost_focus) {
121 // The Aura focus may or may not be on sub-window of the toplevel ARC++ frame. 128 // The Aura focus may or may not be on sub-window of the toplevel ARC++ frame.
122 // To handle all cases, judge the state by always climbing up to the toplevel. 129 // To handle all cases, judge the state by always climbing up to the toplevel.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 base::i18n::TextDirection direction) { 348 base::i18n::TextDirection direction) {
342 return false; 349 return false;
343 } 350 }
344 351
345 bool ArcImeService::IsTextEditCommandEnabled( 352 bool ArcImeService::IsTextEditCommandEnabled(
346 ui::TextEditCommand command) const { 353 ui::TextEditCommand command) const {
347 return false; 354 return false;
348 } 355 }
349 356
350 } // namespace arc 357 } // namespace arc
OLDNEW
« no previous file with comments | « 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