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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 if (!container_) { | 135 if (!container_) { |
136 container_ = new aura::Window(new KeyboardWindowDelegate()); | 136 container_ = new aura::Window(new KeyboardWindowDelegate()); |
137 container_->SetName("KeyboardContainer"); | 137 container_->SetName("KeyboardContainer"); |
138 container_->Init(ui::LAYER_NOT_DRAWN); | 138 container_->Init(ui::LAYER_NOT_DRAWN); |
139 container_->AddObserver(this); | 139 container_->AddObserver(this); |
140 container_->SetLayoutManager(new KeyboardLayoutManager(container_)); | 140 container_->SetLayoutManager(new KeyboardLayoutManager(container_)); |
141 } | 141 } |
142 return container_; | 142 return container_; |
143 } | 143 } |
144 | 144 |
145 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) { | 145 void KeyboardController::SetKeyboardVisibility(bool should_show) { |
146 observer_list_.AddObserver(observer); | |
147 } | |
148 | |
149 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) { | |
150 observer_list_.RemoveObserver(observer); | |
151 } | |
152 | |
153 void KeyboardController::OnWindowParentChanged(aura::Window* window, | |
154 aura::Window* parent) { | |
155 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); | |
156 } | |
157 | |
158 void KeyboardController::OnWindowDestroying(aura::Window* window) { | |
159 DCHECK_EQ(container_, window); | |
160 container_ = NULL; | |
161 } | |
162 | |
163 void KeyboardController::OnTextInputStateChanged( | |
164 const ui::TextInputClient* client) { | |
165 if (!container_) | 146 if (!container_) |
166 return; | 147 return; |
167 | 148 |
168 bool was_showing = container_->IsVisible(); | 149 bool was_showing = container_->IsVisible(); |
169 bool should_show = was_showing; | 150 if (was_showing != should_show) { |
170 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | 151 if (should_show && container_->children().empty()) { |
171 should_show = false; | |
172 } else { | |
173 if (container_->children().empty()) { | |
174 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | 152 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
175 keyboard->Show(); | 153 keyboard->Show(); |
176 container_->AddChild(keyboard); | 154 container_->AddChild(keyboard); |
177 container_->layout_manager()->OnWindowResized(); | 155 container_->layout_manager()->OnWindowResized(); |
178 } | 156 } |
179 container_->parent()->StackChildAtTop(container_); | |
180 should_show = true; | |
181 } | |
182 | 157 |
183 if (was_showing != should_show) { | |
184 gfx::Rect new_bounds( | 158 gfx::Rect new_bounds( |
185 should_show ? container_->children()[0]->bounds() : gfx::Rect()); | 159 should_show ? container_->children()[0]->bounds() : gfx::Rect()); |
186 | 160 |
187 FOR_EACH_OBSERVER( | 161 FOR_EACH_OBSERVER( |
188 KeyboardControllerObserver, | 162 KeyboardControllerObserver, |
189 observer_list_, | 163 observer_list_, |
190 OnKeyboardBoundsChanging(new_bounds)); | 164 OnKeyboardBoundsChanging(new_bounds)); |
191 | 165 |
192 if (should_show) | 166 if (should_show) { |
167 container_->parent()->StackChildAtTop(container_); | |
193 container_->Show(); | 168 container_->Show(); |
194 else | 169 } else { |
195 container_->Hide(); | 170 container_->Hide(); |
bryeung
2013/04/30 20:21:03
directly hiding the keyboard from JS seems to caus
sadrul
2013/05/14 06:23:19
Animation in the page itself should not be causing
| |
171 } | |
196 | 172 |
197 proxy_->OnKeyboardBoundsChanged(new_bounds); | 173 proxy_->OnKeyboardBoundsChanged(new_bounds); |
198 } | 174 } |
175 } | |
176 | |
177 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) { | |
178 observer_list_.AddObserver(observer); | |
179 } | |
180 | |
181 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) { | |
182 observer_list_.RemoveObserver(observer); | |
183 } | |
184 | |
185 void KeyboardController::OnWindowParentChanged(aura::Window* window, | |
186 aura::Window* parent) { | |
187 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); | |
188 } | |
189 | |
190 void KeyboardController::OnWindowDestroying(aura::Window* window) { | |
191 DCHECK_EQ(container_, window); | |
192 container_ = NULL; | |
193 } | |
194 | |
195 void KeyboardController::OnTextInputStateChanged( | |
196 const ui::TextInputClient* client) { | |
197 SetKeyboardVisibility( | |
198 (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)); | |
199 | 199 |
200 // TODO(bryeung): whenever the TextInputClient changes we need to notify the | 200 // TODO(bryeung): whenever the TextInputClient changes we need to notify the |
201 // keyboard (with the TextInputType) so that it can reset it's state (e.g. | 201 // keyboard (with the TextInputType) so that it can reset it's state (e.g. |
202 // abandon compositions in progress) | 202 // abandon compositions in progress) |
203 } | 203 } |
204 | 204 |
205 void KeyboardController::OnInputMethodDestroyed( | 205 void KeyboardController::OnInputMethodDestroyed( |
206 const ui::InputMethod* input_method) { | 206 const ui::InputMethod* input_method) { |
207 DCHECK_EQ(input_method_, input_method); | 207 DCHECK_EQ(input_method_, input_method); |
208 input_method_ = NULL; | 208 input_method_ = NULL; |
209 } | 209 } |
210 | 210 |
211 } // namespace keyboard | 211 } // namespace keyboard |
OLD | NEW |