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(); |
| 168 bool should_show = was_showing; |
159 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | 169 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
160 container_->Hide(); | 170 should_show = false; |
161 } else { | 171 } else { |
162 if (container_->children().empty()) { | 172 if (container_->children().empty()) { |
163 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | 173 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
164 keyboard->Show(); | 174 keyboard->Show(); |
165 container_->AddChild(keyboard); | 175 container_->AddChild(keyboard); |
166 container_->layout_manager()->OnWindowResized(); | 176 container_->layout_manager()->OnWindowResized(); |
167 } | 177 } |
168 container_->parent()->StackChildAtTop(container_); | 178 container_->parent()->StackChildAtTop(container_); |
169 container_->Show(); | 179 should_show = true; |
170 } | 180 } |
| 181 |
| 182 if (was_showing != should_show) { |
| 183 gfx::Rect new_bounds( |
| 184 should_show ? container_->children()[0]->bounds() : gfx::Rect()); |
| 185 |
| 186 FOR_EACH_OBSERVER( |
| 187 Observer, observer_list_, OnKeyboardBoundsChanging(new_bounds)); |
| 188 |
| 189 if (should_show) |
| 190 container_->Show(); |
| 191 else |
| 192 container_->Hide(); |
| 193 } |
| 194 |
171 // TODO(bryeung): whenever the TextInputClient changes we need to notify the | 195 // 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. | 196 // keyboard (with the TextInputType) so that it can reset it's state (e.g. |
173 // abandon compositions in progress) | 197 // abandon compositions in progress) |
174 } | 198 } |
175 | 199 |
176 void KeyboardController::OnInputMethodDestroyed( | 200 void KeyboardController::OnInputMethodDestroyed( |
177 const ui::InputMethod* input_method) { | 201 const ui::InputMethod* input_method) { |
178 DCHECK_EQ(input_method_, input_method); | 202 DCHECK_EQ(input_method_, input_method); |
179 input_method_ = NULL; | 203 input_method_ = NULL; |
180 } | 204 } |
181 | 205 |
182 } // namespace keyboard | 206 } // namespace keyboard |
OLD | NEW |