| 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 "base/command_line.h" |
| 9 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/aura/window_delegate.h" | 11 #include "ui/aura/window_delegate.h" |
| 12 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
| 13 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 14 #include "ui/base/ime/input_method.h" | 14 #include "ui/base/ime/input_method.h" |
| 15 #include "ui/base/ime/text_input_client.h" | 15 #include "ui/base/ime/text_input_client.h" |
| 16 #include "ui/base/ime/text_input_type.h" | 16 #include "ui/base/ime/text_input_type.h" |
| 17 #include "ui/gfx/path.h" | 17 #include "ui/gfx/path.h" |
| 18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 20 #include "ui/keyboard/keyboard_controller_observer.h" | 20 #include "ui/keyboard/keyboard_controller_observer.h" |
| 21 #include "ui/keyboard/keyboard_controller_proxy.h" | 21 #include "ui/keyboard/keyboard_controller_proxy.h" |
| 22 #include "ui/keyboard/keyboard_switches.h" | 22 #include "ui/keyboard/keyboard_switches.h" |
| 23 #include "ui/keyboard/keyboard_util.h" | 23 #include "ui/keyboard/keyboard_util.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const int kHideKeyboardDelayMs = 100; | 27 const int kHideKeyboardDelayMs = 100; |
| 28 | 28 |
| 29 gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) { | 29 gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) { |
| 30 const float kKeyboardHeightRatio = | 30 const float kKeyboardHeightRatio = 0.3f; |
| 31 keyboard::IsKeyboardUsabilityExperimentEnabled() ? 1.0f : 0.3f; | |
| 32 return gfx::Rect( | 31 return gfx::Rect( |
| 33 window_bounds.x(), | 32 window_bounds.x(), |
| 34 window_bounds.y() + window_bounds.height() * (1 - kKeyboardHeightRatio), | 33 window_bounds.y() + window_bounds.height() * (1 - kKeyboardHeightRatio), |
| 35 window_bounds.width(), | 34 window_bounds.width(), |
| 36 window_bounds.height() * kKeyboardHeightRatio); | 35 window_bounds.height() * kKeyboardHeightRatio); |
| 37 } | 36 } |
| 38 | 37 |
| 39 // The KeyboardWindowDelegate makes sure the keyboard-window does not get focus. | 38 // The KeyboardWindowDelegate makes sure the keyboard-window does not get focus. |
| 40 // This is necessary to make sure that the synthetic key-events reach the target | 39 // This is necessary to make sure that the synthetic key-events reach the target |
| 41 // window. | 40 // window. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void KeyboardController::OnTextInputStateChanged( | 184 void KeyboardController::OnTextInputStateChanged( |
| 186 const ui::TextInputClient* client) { | 185 const ui::TextInputClient* client) { |
| 187 if (!container_.get()) | 186 if (!container_.get()) |
| 188 return; | 187 return; |
| 189 | 188 |
| 190 bool was_showing = keyboard_visible_; | 189 bool was_showing = keyboard_visible_; |
| 191 bool should_show = was_showing; | 190 bool should_show = was_showing; |
| 192 ui::TextInputType type = | 191 ui::TextInputType type = |
| 193 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 192 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
| 194 if (type == ui::TEXT_INPUT_TYPE_NONE && | 193 if (type == ui::TEXT_INPUT_TYPE_NONE && |
| 195 !IsKeyboardUsabilityExperimentEnabled()) { | 194 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 195 switches::kKeyboardUsabilityTest)) { |
| 196 should_show = false; | 196 should_show = false; |
| 197 } else { | 197 } else { |
| 198 if (container_->children().empty()) { | 198 if (container_->children().empty()) { |
| 199 keyboard::MarkKeyboardLoadStarted(); | 199 keyboard::MarkKeyboardLoadStarted(); |
| 200 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | 200 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
| 201 keyboard->Show(); | 201 keyboard->Show(); |
| 202 container_->AddChild(keyboard); | 202 container_->AddChild(keyboard); |
| 203 container_->layout_manager()->OnWindowResized(); | 203 container_->layout_manager()->OnWindowResized(); |
| 204 } | 204 } |
| 205 if (type != ui::TEXT_INPUT_TYPE_NONE) | 205 proxy_->SetUpdateInputType(type); |
| 206 proxy_->SetUpdateInputType(type); | |
| 207 container_->parent()->StackChildAtTop(container_.get()); | 206 container_->parent()->StackChildAtTop(container_.get()); |
| 208 should_show = true; | 207 should_show = true; |
| 209 } | 208 } |
| 210 | 209 |
| 211 if (was_showing != should_show) { | 210 if (was_showing != should_show) { |
| 212 if (should_show) { | 211 if (should_show) { |
| 213 keyboard_visible_ = true; | 212 keyboard_visible_ = true; |
| 214 | 213 |
| 215 // If the controller is in the process of hiding the keyboard, do not log | 214 // If the controller is in the process of hiding the keyboard, do not log |
| 216 // the stat here since the keyboard will not actually be shown. | 215 // the stat here since the keyboard will not actually be shown. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 246 const ui::InputMethod* input_method) { | 245 const ui::InputMethod* input_method) { |
| 247 DCHECK_EQ(input_method_, input_method); | 246 DCHECK_EQ(input_method_, input_method); |
| 248 input_method_ = NULL; | 247 input_method_ = NULL; |
| 249 } | 248 } |
| 250 | 249 |
| 251 bool KeyboardController::WillHideKeyboard() const { | 250 bool KeyboardController::WillHideKeyboard() const { |
| 252 return weak_factory_.HasWeakPtrs(); | 251 return weak_factory_.HasWeakPtrs(); |
| 253 } | 252 } |
| 254 | 253 |
| 255 } // namespace keyboard | 254 } // namespace keyboard |
| OLD | NEW |