| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 8 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
| 9 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_delegate.h" | 11 #include "ui/aura/window_delegate.h" |
| 11 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
| 12 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 13 #include "ui/base/ime/input_method.h" | 14 #include "ui/base/ime/input_method.h" |
| 14 #include "ui/base/ime/text_input_client.h" | 15 #include "ui/base/ime/text_input_client.h" |
| 15 #include "ui/base/ime/text_input_type.h" | 16 #include "ui/base/ime/text_input_type.h" |
| 16 #include "ui/gfx/path.h" | 17 #include "ui/gfx/path.h" |
| 17 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 18 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 19 #include "ui/keyboard/keyboard_controller_observer.h" | 20 #include "ui/keyboard/keyboard_controller_observer.h" |
| 20 #include "ui/keyboard/keyboard_controller_proxy.h" | 21 #include "ui/keyboard/keyboard_controller_proxy.h" |
| 22 #include "ui/keyboard/keyboard_switches.h" |
| 21 #include "ui/keyboard/keyboard_util.h" | 23 #include "ui/keyboard/keyboard_util.h" |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 const int kHideKeyboardDelayMs = 100; | 27 const int kHideKeyboardDelayMs = 100; |
| 26 | 28 |
| 27 gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) { | 29 gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) { |
| 28 const float kKeyboardHeightRatio = 0.3f; | 30 const float kKeyboardHeightRatio = 0.3f; |
| 29 return gfx::Rect( | 31 return gfx::Rect( |
| 30 window_bounds.x(), | 32 window_bounds.x(), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 aura::Window* container_; | 120 aura::Window* container_; |
| 119 aura::Window* keyboard_; | 121 aura::Window* keyboard_; |
| 120 | 122 |
| 121 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); | 123 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); |
| 122 }; | 124 }; |
| 123 | 125 |
| 124 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) | 126 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) |
| 125 : proxy_(proxy), | 127 : proxy_(proxy), |
| 126 input_method_(NULL), | 128 input_method_(NULL), |
| 127 keyboard_visible_(false), | 129 keyboard_visible_(false), |
| 130 command_line_for_testing_(NULL), |
| 128 weak_factory_(this) { | 131 weak_factory_(this) { |
| 129 CHECK(proxy); | 132 CHECK(proxy); |
| 130 input_method_ = proxy_->GetInputMethod(); | 133 input_method_ = proxy_->GetInputMethod(); |
| 131 input_method_->AddObserver(this); | 134 input_method_->AddObserver(this); |
| 132 } | 135 } |
| 133 | 136 |
| 134 KeyboardController::~KeyboardController() { | 137 KeyboardController::~KeyboardController() { |
| 135 if (container_.get()) | 138 if (container_.get()) |
| 136 container_->RemoveObserver(this); | 139 container_->RemoveObserver(this); |
| 137 if (input_method_) | 140 if (input_method_) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 184 |
| 182 void KeyboardController::OnTextInputStateChanged( | 185 void KeyboardController::OnTextInputStateChanged( |
| 183 const ui::TextInputClient* client) { | 186 const ui::TextInputClient* client) { |
| 184 if (!container_.get()) | 187 if (!container_.get()) |
| 185 return; | 188 return; |
| 186 | 189 |
| 187 bool was_showing = keyboard_visible_; | 190 bool was_showing = keyboard_visible_; |
| 188 bool should_show = was_showing; | 191 bool should_show = was_showing; |
| 189 ui::TextInputType type = | 192 ui::TextInputType type = |
| 190 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 193 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
| 191 if (type == ui::TEXT_INPUT_TYPE_NONE) { | 194 CommandLine* command_line = command_line_for_testing_ ? |
| 195 command_line_for_testing_ : CommandLine::ForCurrentProcess(); |
| 196 if (type == ui::TEXT_INPUT_TYPE_NONE && |
| 197 !command_line->HasSwitch(switches::kKeyboardUsabilityTest)) { |
| 192 should_show = false; | 198 should_show = false; |
| 193 } else { | 199 } else { |
| 194 if (container_->children().empty()) { | 200 if (container_->children().empty()) { |
| 195 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | 201 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
| 196 keyboard->Show(); | 202 keyboard->Show(); |
| 197 container_->AddChild(keyboard); | 203 container_->AddChild(keyboard); |
| 198 container_->layout_manager()->OnWindowResized(); | 204 container_->layout_manager()->OnWindowResized(); |
| 199 } | 205 } |
| 200 proxy_->SetUpdateInputType(type); | 206 proxy_->SetUpdateInputType(type); |
| 201 container_->parent()->StackChildAtTop(container_.get()); | 207 container_->parent()->StackChildAtTop(container_.get()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 const ui::InputMethod* input_method) { | 246 const ui::InputMethod* input_method) { |
| 241 DCHECK_EQ(input_method_, input_method); | 247 DCHECK_EQ(input_method_, input_method); |
| 242 input_method_ = NULL; | 248 input_method_ = NULL; |
| 243 } | 249 } |
| 244 | 250 |
| 245 bool KeyboardController::WillHideKeyboard() const { | 251 bool KeyboardController::WillHideKeyboard() const { |
| 246 return weak_factory_.HasWeakPtrs(); | 252 return weak_factory_.HasWeakPtrs(); |
| 247 } | 253 } |
| 248 | 254 |
| 249 } // namespace keyboard | 255 } // namespace keyboard |
| OLD | NEW |