Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc

Issue 1128173003: Implements onBoundsChanged event in virtualKeyboardPrivate namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" 5 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 10 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
11 #include "content/public/browser/host_zoom_map.h" 11 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/site_instance.h" 14 #include "content/public/browser/site_instance.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "extensions/browser/event_router.h" 16 #include "extensions/browser/event_router.h"
17 #include "extensions/browser/extension_function_dispatcher.h" 17 #include "extensions/browser/extension_function_dispatcher.h"
18 #include "extensions/browser/extension_registry.h" 18 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/view_type_utils.h" 19 #include "extensions/browser/view_type_utils.h"
20 #include "extensions/common/api/virtual_keyboard_private.h" 20 #include "extensions/common/api/virtual_keyboard_private.h"
21 #include "extensions/common/constants.h" 21 #include "extensions/common/constants.h"
22 #include "extensions/common/extension_messages.h" 22 #include "extensions/common/extension_messages.h"
23 #include "ipc/ipc_message_macros.h" 23 #include "ipc/ipc_message_macros.h"
24 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
25 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
26 #include "ui/aura/window_event_dispatcher.h" 26 #include "ui/aura/window_event_dispatcher.h"
27 #include "ui/compositor/scoped_layer_animation_settings.h" 27 #include "ui/compositor/scoped_layer_animation_settings.h"
28 #include "ui/keyboard/keyboard_controller.h" 28 #include "ui/keyboard/keyboard_controller.h"
29 #include "ui/keyboard/keyboard_controller_observer.h"
29 30
30 namespace virtual_keyboard_private = 31 namespace virtual_keyboard_private =
31 extensions::core_api::virtual_keyboard_private; 32 extensions::core_api::virtual_keyboard_private;
32 33
33 typedef virtual_keyboard_private::OnTextInputBoxFocused::Context Context; 34 typedef virtual_keyboard_private::OnTextInputBoxFocused::Context Context;
34 35
35 namespace { 36 namespace {
36 37
37 const char* kVirtualKeyboardExtensionID = "mppnpdlheglhdfmldimlhpnegondlapf"; 38 const char* kVirtualKeyboardExtensionID = "mppnpdlheglhdfmldimlhpnegondlapf";
38 39
(...skipping 23 matching lines...) Expand all
62 case ui::TEXT_INPUT_TYPE_WEEK: 63 case ui::TEXT_INPUT_TYPE_WEEK:
63 case ui::TEXT_INPUT_TYPE_TEXT_AREA: 64 case ui::TEXT_INPUT_TYPE_TEXT_AREA:
64 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE: 65 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE:
65 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: 66 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD:
66 return virtual_keyboard_private::ON_TEXT_INPUT_BOX_FOCUSED_TYPE_TEXT; 67 return virtual_keyboard_private::ON_TEXT_INPUT_BOX_FOCUSED_TYPE_TEXT;
67 } 68 }
68 NOTREACHED(); 69 NOTREACHED();
69 return virtual_keyboard_private::ON_TEXT_INPUT_BOX_FOCUSED_TYPE_NONE; 70 return virtual_keyboard_private::ON_TEXT_INPUT_BOX_FOCUSED_TYPE_NONE;
70 } 71 }
71 72
73 class AshKeyboardControllerObserver
74 : public keyboard::KeyboardControllerObserver {
75 public:
76 explicit AshKeyboardControllerObserver(content::BrowserContext* context)
77 : context_(context) {
78 }
79 ~AshKeyboardControllerObserver() override {}
80
81 // KeyboardControllerObserver overrides:
82 void OnKeyboardBoundsChanging(const gfx::Rect& bounds) override {
83 extensions::EventRouter* router =
84 extensions::EventRouter::Get(context_);
85
86 if (!router->HasEventListener(
87 virtual_keyboard_private::OnBoundsChanged::kEventName)) {
88 return;
89 }
90
91 scoped_ptr<base::ListValue> event_args(new base::ListValue());
92 scoped_ptr<base::DictionaryValue> new_bounds(new base::DictionaryValue());
93 new_bounds->SetInteger("left", bounds.x());
94 new_bounds->SetInteger("top", bounds.y());
95 new_bounds->SetInteger("width", bounds.width());
96 new_bounds->SetInteger("height", bounds.height());
97 event_args->Append(new_bounds.release());
98
99 scoped_ptr<extensions::Event> event(new extensions::Event(
100 virtual_keyboard_private::OnBoundsChanged::kEventName,
101 event_args.Pass()));
102 event->restrict_to_browser_context = context_;
103 router->BroadcastEvent(event.Pass());
104 }
105
106 private:
107 content::BrowserContext* context_;
oshima 2015/05/14 15:37:22 nit: new line before DISALLOW...
bshe 2015/05/15 16:10:41 Done.
108 DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerObserver);
109 };
110
72 } // namespace 111 } // namespace
73 112
74 AshKeyboardControllerProxy::AshKeyboardControllerProxy( 113 AshKeyboardControllerProxy::AshKeyboardControllerProxy(
75 content::BrowserContext* context) 114 content::BrowserContext* context)
76 : keyboard::KeyboardControllerProxy(context) { 115 : keyboard::KeyboardControllerProxy(context) {
77 } 116 }
78 117
79 AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {} 118 AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {
119 keyboard_controller_->RemoveObserver(observer_.get());
oshima 2015/05/14 15:37:22 looks like the proxy is owned by controller, so th
bshe 2015/05/15 15:32:51 What do you think of letting ChromeShellDelegate o
sadrul 2015/05/15 15:37:00 How about calling proxy->SetController(nullptr) fr
bshe 2015/05/15 16:10:41 called proxy_.reset() directly. Otherwise, I need
120 }
80 121
81 void AshKeyboardControllerProxy::OnRequest( 122 void AshKeyboardControllerProxy::OnRequest(
82 const ExtensionHostMsg_Request_Params& params) { 123 const ExtensionHostMsg_Request_Params& params) {
83 extension_function_dispatcher_->Dispatch( 124 extension_function_dispatcher_->Dispatch(
84 params, web_contents()->GetRenderViewHost()); 125 params, web_contents()->GetRenderViewHost());
85 } 126 }
86 127
87 ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() { 128 ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() {
88 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); 129 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
89 DCHECK(root_window); 130 DCHECK(root_window);
(...skipping 26 matching lines...) Expand all
116 contents); 157 contents);
117 Observe(contents); 158 Observe(contents);
118 } 159 }
119 160
120 extensions::WindowController* 161 extensions::WindowController*
121 AshKeyboardControllerProxy::GetExtensionWindowController() const { 162 AshKeyboardControllerProxy::GetExtensionWindowController() const {
122 // The keyboard doesn't have a window controller. 163 // The keyboard doesn't have a window controller.
123 return NULL; 164 return NULL;
124 } 165 }
125 166
167 void AshKeyboardControllerProxy::SetController(
168 keyboard::KeyboardController* controller) {
169 keyboard_controller_ = controller;
170 observer_.reset(new AshKeyboardControllerObserver(browser_context()));
171 keyboard_controller_->AddObserver(observer_.get());
172 }
173
126 content::WebContents* 174 content::WebContents*
127 AshKeyboardControllerProxy::GetAssociatedWebContents() const { 175 AshKeyboardControllerProxy::GetAssociatedWebContents() const {
128 return web_contents(); 176 return web_contents();
129 } 177 }
130 178
131 bool AshKeyboardControllerProxy::OnMessageReceived( 179 bool AshKeyboardControllerProxy::OnMessageReceived(
132 const IPC::Message& message) { 180 const IPC::Message& message) {
133 bool handled = true; 181 bool handled = true;
134 IPC_BEGIN_MESSAGE_MAP(AshKeyboardControllerProxy, message) 182 IPC_BEGIN_MESSAGE_MAP(AshKeyboardControllerProxy, message)
135 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) 183 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 virtual_keyboard_private::ToString( 223 virtual_keyboard_private::ToString(
176 TextInputTypeToGeneratedInputTypeEnum(type))); 224 TextInputTypeToGeneratedInputTypeEnum(type)));
177 event_args->Append(input_context.release()); 225 event_args->Append(input_context.release());
178 226
179 scoped_ptr<extensions::Event> event(new extensions::Event( 227 scoped_ptr<extensions::Event> event(new extensions::Event(
180 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, 228 virtual_keyboard_private::OnTextInputBoxFocused::kEventName,
181 event_args.Pass())); 229 event_args.Pass()));
182 event->restrict_to_browser_context = browser_context(); 230 event->restrict_to_browser_context = browser_context();
183 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); 231 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass());
184 } 232 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/ash_keyboard_controller_proxy.h ('k') | extensions/common/api/virtual_keyboard_private.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698