OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "chrome/browser/extensions/api/input/input.h" | 5 #include "chrome/browser/extensions/api/input/input.h" |
6 | 6 |
| 7 #include "ash/root_window_controller.h" |
7 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
8 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
9 #include "chrome/browser/extensions/extension_function_registry.h" | 10 #include "chrome/browser/extensions/extension_function_registry.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "ui/base/events/event.h" | 12 #include "ui/base/events/event.h" |
| 13 #include "ui/keyboard/keyboard_controller.h" |
12 | 14 |
13 #if defined(USE_ASH) | 15 #if defined(USE_ASH) |
14 #include "ash/shell.h" | 16 #include "ash/shell.h" |
15 #include "ui/keyboard/keyboard_util.h" | 17 #include "ui/keyboard/keyboard_util.h" |
16 #endif | 18 #endif |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 const char kNotYetImplementedError[] = | 22 const char kNotYetImplementedError[] = |
21 "API is not implemented on this platform."; | 23 "API is not implemented on this platform."; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXTENSION_FUNCTION_VALIDATE(params->GetString("type", &type)); | 71 EXTENSION_FUNCTION_VALIDATE(params->GetString("type", &type)); |
70 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("charValue", &char_value)); | 72 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("charValue", &char_value)); |
71 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("keyCode", &key_code)); | 73 EXTENSION_FUNCTION_VALIDATE(params->GetInteger("keyCode", &key_code)); |
72 EXTENSION_FUNCTION_VALIDATE(params->GetBoolean("shiftKey", &shift_modifier)); | 74 EXTENSION_FUNCTION_VALIDATE(params->GetBoolean("shiftKey", &shift_modifier)); |
73 | 75 |
74 return keyboard::SendKeyEvent(type, | 76 return keyboard::SendKeyEvent(type, |
75 char_value, | 77 char_value, |
76 key_code, | 78 key_code, |
77 shift_modifier, | 79 shift_modifier, |
78 ash::Shell::GetPrimaryRootWindow()); | 80 ash::Shell::GetPrimaryRootWindow()); |
79 | |
80 #endif | 81 #endif |
81 error_ = kNotYetImplementedError; | 82 error_ = kNotYetImplementedError; |
82 return false; | 83 return false; |
| 84 } |
| 85 |
| 86 bool HideKeyboardFunction::RunImpl() { |
| 87 #if defined(USE_ASH) |
| 88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 89 |
| 90 ash::Shell::GetPrimaryRootWindowController()->keyboard_controller()-> |
| 91 HideKeyboard(); |
| 92 |
| 93 return true; |
| 94 #endif |
| 95 error_ = kNotYetImplementedError; |
| 96 return false; |
83 } | 97 } |
84 | 98 |
85 InputAPI::InputAPI(Profile* profile) { | 99 InputAPI::InputAPI(Profile* profile) { |
86 ExtensionFunctionRegistry* registry = | 100 ExtensionFunctionRegistry* registry = |
87 ExtensionFunctionRegistry::GetInstance(); | 101 ExtensionFunctionRegistry::GetInstance(); |
88 registry->RegisterFunction<InsertTextFunction>(); | 102 registry->RegisterFunction<InsertTextFunction>(); |
89 registry->RegisterFunction<MoveCursorFunction>(); | 103 registry->RegisterFunction<MoveCursorFunction>(); |
90 registry->RegisterFunction<SendKeyEventFunction>(); | 104 registry->RegisterFunction<SendKeyEventFunction>(); |
| 105 registry->RegisterFunction<HideKeyboardFunction>(); |
91 } | 106 } |
92 | 107 |
93 InputAPI::~InputAPI() { | 108 InputAPI::~InputAPI() { |
94 } | 109 } |
95 | 110 |
96 static base::LazyInstance<ProfileKeyedAPIFactory<InputAPI> > | 111 static base::LazyInstance<ProfileKeyedAPIFactory<InputAPI> > |
97 g_factory = LAZY_INSTANCE_INITIALIZER; | 112 g_factory = LAZY_INSTANCE_INITIALIZER; |
98 | 113 |
99 // static | 114 // static |
100 ProfileKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { | 115 ProfileKeyedAPIFactory<InputAPI>* InputAPI::GetFactoryInstance() { |
101 return &g_factory.Get(); | 116 return &g_factory.Get(); |
102 } | 117 } |
103 | 118 |
104 } // namespace extensions | 119 } // namespace extensions |
OLD | NEW |