| 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_util.h" | 5 #include "ui/keyboard/keyboard_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 22 #include "ui/events/keycodes/dom/dom_code.h" | 22 #include "ui/events/keycodes/dom/dom_code.h" |
| 23 #include "ui/events/keycodes/dom/dom_key.h" | 23 #include "ui/events/keycodes/dom/dom_key.h" |
| 24 #include "ui/events/keycodes/dom/keycode_converter.h" | 24 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 25 #include "ui/events/keycodes/keyboard_code_conversion.h" | 25 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 26 #include "ui/keyboard/keyboard_controller.h" | 26 #include "ui/keyboard/keyboard_controller.h" |
| 27 #include "ui/keyboard/keyboard_switches.h" | 27 #include "ui/keyboard/keyboard_switches.h" |
| 28 #include "ui/keyboard/keyboard_ui.h" | 28 #include "ui/keyboard/keyboard_ui.h" |
| 29 #include "ui/keyboard/scoped_keyboard_disabler.h" | 29 #include "ui/keyboard/scoped_keyboard_disabler.h" |
| 30 | 30 |
| 31 namespace keyboard { |
| 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 const char kKeyDown[] ="keydown"; | 35 const char kKeyDown[] ="keydown"; |
| 34 const char kKeyUp[] = "keyup"; | 36 const char kKeyUp[] = "keyup"; |
| 35 | 37 |
| 36 void SendProcessKeyEvent(ui::EventType type, | 38 void SendProcessKeyEvent(ui::EventType type, |
| 37 aura::WindowTreeHost* host) { | 39 aura::WindowTreeHost* host) { |
| 38 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::DomCode::NONE, | 40 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::DomCode::NONE, |
| 39 ui::EF_IS_SYNTHESIZED, ui::DomKey::PROCESS, | 41 ui::EF_IS_SYNTHESIZED, ui::DomKey::PROCESS, |
| 40 ui::EventTimeForNow()); | 42 ui::EventTimeForNow()); |
| 41 ui::EventDispatchDetails details = | 43 ui::EventDispatchDetails details = |
| 42 host->event_sink()->OnEventFromSource(&event); | 44 host->event_sink()->OnEventFromSource(&event); |
| 43 CHECK(!details.dispatcher_destroyed); | 45 CHECK(!details.dispatcher_destroyed); |
| 44 } | 46 } |
| 45 | 47 |
| 46 base::LazyInstance<base::Time>::DestructorAtExit g_keyboard_load_time_start = | 48 base::LazyInstance<base::Time>::DestructorAtExit g_keyboard_load_time_start = |
| 47 LAZY_INSTANCE_INITIALIZER; | 49 LAZY_INSTANCE_INITIALIZER; |
| 48 | 50 |
| 49 bool g_accessibility_keyboard_enabled = false; | 51 bool g_accessibility_keyboard_enabled = false; |
| 50 | 52 |
| 51 bool g_hotrod_keyboard_enabled = false; | 53 bool g_hotrod_keyboard_enabled = false; |
| 52 | 54 |
| 53 bool g_keyboard_restricted = false; | 55 bool g_keyboard_restricted = false; |
| 54 | 56 |
| 55 bool g_touch_keyboard_enabled = false; | 57 bool g_touch_keyboard_enabled = false; |
| 56 | 58 |
| 57 bool g_overscroll_enabled_with_accessibility_keyboard = false; | 59 bool g_overscroll_enabled_with_accessibility_keyboard = false; |
| 58 | 60 |
| 59 keyboard::KeyboardState g_requested_keyboard_state = | 61 KeyboardState g_requested_keyboard_state = KEYBOARD_STATE_AUTO; |
| 60 keyboard::KEYBOARD_STATE_AUTO; | |
| 61 | 62 |
| 62 keyboard::KeyboardOverscrolOverride g_keyboard_overscroll_override = | 63 KeyboardOverscrolOverride g_keyboard_overscroll_override = |
| 63 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE; | 64 KEYBOARD_OVERSCROLL_OVERRIDE_NONE; |
| 64 | 65 |
| 65 keyboard::KeyboardShowOverride g_keyboard_show_override = | 66 KeyboardShowOverride g_keyboard_show_override = KEYBOARD_SHOW_OVERRIDE_NONE; |
| 66 keyboard::KEYBOARD_SHOW_OVERRIDE_NONE; | |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 namespace keyboard { | |
| 71 | |
| 72 gfx::Rect FullWidthKeyboardBoundsFromRootBounds(const gfx::Rect& root_bounds, | 70 gfx::Rect FullWidthKeyboardBoundsFromRootBounds(const gfx::Rect& root_bounds, |
| 73 int keyboard_height) { | 71 int keyboard_height) { |
| 74 return gfx::Rect( | 72 return gfx::Rect( |
| 75 root_bounds.x(), | 73 root_bounds.x(), |
| 76 root_bounds.bottom() - keyboard_height, | 74 root_bounds.bottom() - keyboard_height, |
| 77 root_bounds.width(), | 75 root_bounds.width(), |
| 78 keyboard_height); | 76 keyboard_height); |
| 79 } | 77 } |
| 80 | 78 |
| 81 void SetAccessibilityKeyboardEnabled(bool enabled) { | 79 void SetAccessibilityKeyboardEnabled(bool enabled) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 115 } |
| 118 | 116 |
| 119 bool IsKeyboardEnabled() { | 117 bool IsKeyboardEnabled() { |
| 120 // Blocks keyboard from showing up regardless of other settings. | 118 // Blocks keyboard from showing up regardless of other settings. |
| 121 if (ScopedKeyboardDisabler::GetForceDisableVirtualKeyboard()) | 119 if (ScopedKeyboardDisabler::GetForceDisableVirtualKeyboard()) |
| 122 return false; | 120 return false; |
| 123 // Accessibility setting prioritized over policy setting. | 121 // Accessibility setting prioritized over policy setting. |
| 124 if (g_accessibility_keyboard_enabled) | 122 if (g_accessibility_keyboard_enabled) |
| 125 return true; | 123 return true; |
| 126 // Policy strictly disables showing a virtual keyboard. | 124 // Policy strictly disables showing a virtual keyboard. |
| 127 if (g_keyboard_show_override == keyboard::KEYBOARD_SHOW_OVERRIDE_DISABLED) | 125 if (g_keyboard_show_override == KEYBOARD_SHOW_OVERRIDE_DISABLED) |
| 128 return false; | 126 return false; |
| 129 // Policy strictly enables the keyboard. | 127 // Policy strictly enables the keyboard. |
| 130 if (g_keyboard_show_override == keyboard::KEYBOARD_SHOW_OVERRIDE_ENABLED) | 128 if (g_keyboard_show_override == KEYBOARD_SHOW_OVERRIDE_ENABLED) |
| 131 return true; | 129 return true; |
| 132 // Run-time flag to enable keyboard has been included. | 130 // Run-time flag to enable keyboard has been included. |
| 133 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 131 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 134 switches::kEnableVirtualKeyboard)) | 132 switches::kEnableVirtualKeyboard)) |
| 135 return true; | 133 return true; |
| 136 // Requested state from the application layer. | 134 // Requested state from the application layer. |
| 137 if (g_requested_keyboard_state == keyboard::KEYBOARD_STATE_DISABLED) | 135 if (g_requested_keyboard_state == KEYBOARD_STATE_DISABLED) |
| 138 return false; | 136 return false; |
| 139 // Check if any of the other flags are enabled. | 137 // Check if any of the other flags are enabled. |
| 140 return g_touch_keyboard_enabled || | 138 return g_touch_keyboard_enabled || |
| 141 g_requested_keyboard_state == keyboard::KEYBOARD_STATE_ENABLED; | 139 g_requested_keyboard_state == KEYBOARD_STATE_ENABLED; |
| 140 } |
| 141 |
| 142 bool IsKeyboardVisible() { |
| 143 auto* keyboard_controller = keyboard::KeyboardController::GetInstance(); |
| 144 return keyboard_controller && keyboard_controller->keyboard_visible(); |
| 142 } | 145 } |
| 143 | 146 |
| 144 bool IsKeyboardOverscrollEnabled() { | 147 bool IsKeyboardOverscrollEnabled() { |
| 145 if (!IsKeyboardEnabled()) | 148 if (!IsKeyboardEnabled()) |
| 146 return false; | 149 return false; |
| 147 | 150 |
| 148 // Users of the accessibility on-screen keyboard are likely to be using mouse | 151 // Users of the accessibility on-screen keyboard are likely to be using mouse |
| 149 // input, which may interfere with overscrolling. | 152 // input, which may interfere with overscrolling. |
| 150 if (g_accessibility_keyboard_enabled && | 153 if (g_accessibility_keyboard_enabled && |
| 151 !g_overscroll_enabled_with_accessibility_keyboard) { | 154 !g_overscroll_enabled_with_accessibility_keyboard) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 switches::kDisableSmartVirtualKeyboard); | 215 switches::kDisableSmartVirtualKeyboard); |
| 213 } | 216 } |
| 214 | 217 |
| 215 bool IsVoiceInputEnabled() { | 218 bool IsVoiceInputEnabled() { |
| 216 return !g_keyboard_restricted && | 219 return !g_keyboard_restricted && |
| 217 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 220 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 218 switches::kDisableVoiceInput); | 221 switches::kDisableVoiceInput); |
| 219 } | 222 } |
| 220 | 223 |
| 221 bool InsertText(const base::string16& text) { | 224 bool InsertText(const base::string16& text) { |
| 222 keyboard::KeyboardController* controller = KeyboardController::GetInstance(); | 225 KeyboardController* controller = KeyboardController::GetInstance(); |
| 223 if (!controller) | 226 if (!controller) |
| 224 return false; | 227 return false; |
| 225 | 228 |
| 226 ui::InputMethod* input_method = controller->ui()->GetInputMethod(); | 229 ui::InputMethod* input_method = controller->ui()->GetInputMethod(); |
| 227 if (!input_method) | 230 if (!input_method) |
| 228 return false; | 231 return false; |
| 229 | 232 |
| 230 ui::TextInputClient* tic = input_method->GetTextInputClient(); | 233 ui::TextInputClient* tic = input_method->GetTextInputClient(); |
| 231 if (!tic || tic->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 234 if (!tic || tic->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
| 232 return false; | 235 return false; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 if (!logged) { | 387 if (!logged) { |
| 385 // Log the delta only once. | 388 // Log the delta only once. |
| 386 UMA_HISTOGRAM_TIMES( | 389 UMA_HISTOGRAM_TIMES( |
| 387 "VirtualKeyboard.InitLatency.FirstLoad", | 390 "VirtualKeyboard.InitLatency.FirstLoad", |
| 388 base::Time::Now() - g_keyboard_load_time_start.Get()); | 391 base::Time::Now() - g_keyboard_load_time_start.Get()); |
| 389 logged = true; | 392 logged = true; |
| 390 } | 393 } |
| 391 } | 394 } |
| 392 | 395 |
| 393 void LogKeyboardControlEvent(KeyboardControlEvent event) { | 396 void LogKeyboardControlEvent(KeyboardControlEvent event) { |
| 394 UMA_HISTOGRAM_ENUMERATION( | 397 UMA_HISTOGRAM_ENUMERATION("VirtualKeyboard.KeyboardControlEvent", event, |
| 395 "VirtualKeyboard.KeyboardControlEvent", | 398 KEYBOARD_CONTROL_MAX); |
| 396 event, | |
| 397 keyboard::KEYBOARD_CONTROL_MAX); | |
| 398 } | 399 } |
| 399 | 400 |
| 400 void SetOverscrollEnabledWithAccessibilityKeyboard(bool enabled) { | 401 void SetOverscrollEnabledWithAccessibilityKeyboard(bool enabled) { |
| 401 g_overscroll_enabled_with_accessibility_keyboard = enabled; | 402 g_overscroll_enabled_with_accessibility_keyboard = enabled; |
| 402 } | 403 } |
| 403 | 404 |
| 404 } // namespace keyboard | 405 } // namespace keyboard |
| OLD | NEW |