OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/base/ime/input_method_ibus_aura.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/aura/desktop.h" |
| 9 #include "ui/aura/event.h" |
| 10 #include "ui/base/ime/text_input_client.h" |
| 11 #include "ui/base/ime/input_method_delegate.h" |
| 12 |
| 13 namespace ui { |
| 14 |
| 15 InputMethodIBusAura::InputMethodIBusAura( |
| 16 internal::InputMethodDelegate* delegate) |
| 17 : InputMethodIBus(delegate), |
| 18 active_window_(NULL) { |
| 19 } |
| 20 |
| 21 InputMethodIBusAura::~InputMethodIBusAura() { |
| 22 aura::Desktop* desktop = aura::Desktop::GetInstance(); |
| 23 desktop->RemoveObserver(this); |
| 24 } |
| 25 |
| 26 void InputMethodIBusAura::Init() { |
| 27 aura::Desktop* desktop = aura::Desktop::GetInstance(); |
| 28 aura::Window* active_window = desktop->active_window(); |
| 29 if (active_window) |
| 30 OnActiveWindowChanged(active_window); |
| 31 desktop->AddObserver(this); |
| 32 InputMethodIBus::Init(); |
| 33 } |
| 34 |
| 35 void InputMethodIBusAura::OnActiveWindowChanged( |
| 36 aura::Window* new_active_window) { |
| 37 active_window_ = new_active_window; |
| 38 UpdateContextFocusState(); |
| 39 // We don't have to confirm/cancel a composition text here because the window |
| 40 // which is losing focus will do that. |
| 41 } |
| 42 |
| 43 bool InputMethodIBusAura::IsWindowFocused(aura::Window* window) const { |
| 44 if (!active_window_ || !window) |
| 45 return false; |
| 46 |
| 47 // Return true if |window| is in the |active_window_|'s tree. |
| 48 aura::Window* current = window; |
| 49 while (current) { |
| 50 if (active_window_ == current) |
| 51 return true; |
| 52 current = current->parent(); |
| 53 } |
| 54 |
| 55 return false; |
| 56 } |
| 57 |
| 58 } // namespace ui |
OLD | NEW |