Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
| 6 | 6 |
| 7 #include "ui/aura/layout_manager.h" | 7 #include "ui/aura/layout_manager.h" |
| 8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_delegate.h" | 9 #include "ui/aura/window_delegate.h" |
| 10 #include "ui/base/hit_test.h" | 10 #include "ui/base/hit_test.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 if (!container_) { | 134 if (!container_) { |
| 135 container_ = new aura::Window(new KeyboardWindowDelegate()); | 135 container_ = new aura::Window(new KeyboardWindowDelegate()); |
| 136 container_->SetName("KeyboardContainer"); | 136 container_->SetName("KeyboardContainer"); |
| 137 container_->Init(ui::LAYER_NOT_DRAWN); | 137 container_->Init(ui::LAYER_NOT_DRAWN); |
| 138 container_->AddObserver(this); | 138 container_->AddObserver(this); |
| 139 container_->SetLayoutManager(new KeyboardLayoutManager(container_)); | 139 container_->SetLayoutManager(new KeyboardLayoutManager(container_)); |
| 140 } | 140 } |
| 141 return container_; | 141 return container_; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void KeyboardController::AddObserver(Observer* observer) { | |
| 145 observer_list_.AddObserver(observer); | |
| 146 } | |
| 147 | |
| 148 void KeyboardController::RemoveObserver(Observer* observer) { | |
| 149 observer_list_.RemoveObserver(observer); | |
| 150 } | |
| 151 | |
| 144 void KeyboardController::OnWindowParentChanged(aura::Window* window, | 152 void KeyboardController::OnWindowParentChanged(aura::Window* window, |
| 145 aura::Window* parent) { | 153 aura::Window* parent) { |
| 146 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); | 154 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); |
| 147 } | 155 } |
| 148 | 156 |
| 149 void KeyboardController::OnWindowDestroying(aura::Window* window) { | 157 void KeyboardController::OnWindowDestroying(aura::Window* window) { |
| 150 DCHECK_EQ(container_, window); | 158 DCHECK_EQ(container_, window); |
| 151 container_ = NULL; | 159 container_ = NULL; |
| 152 } | 160 } |
| 153 | 161 |
| 154 void KeyboardController::OnTextInputStateChanged( | 162 void KeyboardController::OnTextInputStateChanged( |
| 155 const ui::TextInputClient* client) { | 163 const ui::TextInputClient* client) { |
| 156 if (!container_) | 164 if (!container_) |
| 157 return; | 165 return; |
| 158 | 166 |
| 167 bool was_showing = container_->IsVisible(); | |
| 159 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | 168 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
| 160 container_->Hide(); | 169 container_->Hide(); |
| 161 } else { | 170 } else { |
| 162 if (container_->children().empty()) { | 171 if (container_->children().empty()) { |
| 163 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | 172 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
| 164 keyboard->Show(); | 173 keyboard->Show(); |
| 165 container_->AddChild(keyboard); | 174 container_->AddChild(keyboard); |
| 166 container_->layout_manager()->OnWindowResized(); | 175 container_->layout_manager()->OnWindowResized(); |
| 167 } | 176 } |
| 168 container_->parent()->StackChildAtTop(container_); | 177 container_->parent()->StackChildAtTop(container_); |
| 169 container_->Show(); | 178 container_->Show(); |
| 170 } | 179 } |
| 180 bool is_showing = container_->IsVisible(); | |
| 181 | |
| 182 if (was_showing != is_showing) { | |
| 183 FOR_EACH_OBSERVER( | |
| 184 Observer, | |
| 185 observer_list_, | |
| 186 OnKeyboardBoundsChanged( | |
| 187 is_showing ? container_->children()[0]->bounds() : | |
| 188 gfx::Rect(0, 0, 0, 0))); | |
|
sadrul
2013/04/26 02:54:16
just gfx::Rect()
bryeung
2013/04/26 13:44:50
Oh, that's nicer. Thanks!
| |
| 189 } | |
| 190 | |
| 171 // TODO(bryeung): whenever the TextInputClient changes we need to notify the | 191 // TODO(bryeung): whenever the TextInputClient changes we need to notify the |
| 172 // keyboard (with the TextInputType) so that it can reset it's state (e.g. | 192 // keyboard (with the TextInputType) so that it can reset it's state (e.g. |
| 173 // abandon compositions in progress) | 193 // abandon compositions in progress) |
| 174 } | 194 } |
| 175 | 195 |
| 176 void KeyboardController::OnInputMethodDestroyed( | 196 void KeyboardController::OnInputMethodDestroyed( |
| 177 const ui::InputMethod* input_method) { | 197 const ui::InputMethod* input_method) { |
| 178 DCHECK_EQ(input_method_, input_method); | 198 DCHECK_EQ(input_method_, input_method); |
| 179 input_method_ = NULL; | 199 input_method_ = NULL; |
| 180 } | 200 } |
| 181 | 201 |
| 182 } // namespace keyboard | 202 } // namespace keyboard |
| OLD | NEW |