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

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: use SetController(nullptr) 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 ~AshKeyboardControllerObserver() override {}
79
80 // KeyboardControllerObserver overrides:
81 void OnKeyboardBoundsChanging(const gfx::Rect& bounds) override {
82 extensions::EventRouter* router = extensions::EventRouter::Get(context_);
83
84 if (!router->HasEventListener(
85 virtual_keyboard_private::OnBoundsChanged::kEventName)) {
86 return;
87 }
88
89 scoped_ptr<base::ListValue> event_args(new base::ListValue());
90 scoped_ptr<base::DictionaryValue> new_bounds(new base::DictionaryValue());
91 new_bounds->SetInteger("left", bounds.x());
92 new_bounds->SetInteger("top", bounds.y());
93 new_bounds->SetInteger("width", bounds.width());
94 new_bounds->SetInteger("height", bounds.height());
95 event_args->Append(new_bounds.release());
96
97 scoped_ptr<extensions::Event> event(new extensions::Event(
98 virtual_keyboard_private::OnBoundsChanged::kEventName,
99 event_args.Pass()));
100 event->restrict_to_browser_context = context_;
101 router->BroadcastEvent(event.Pass());
102 }
103
104 private:
105 content::BrowserContext* context_;
106
107 DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerObserver);
108 };
109
72 } // namespace 110 } // namespace
73 111
74 AshKeyboardControllerProxy::AshKeyboardControllerProxy( 112 AshKeyboardControllerProxy::AshKeyboardControllerProxy(
75 content::BrowserContext* context) 113 content::BrowserContext* context)
76 : keyboard::KeyboardControllerProxy(context) { 114 : keyboard::KeyboardControllerProxy(context) {
77 } 115 }
78 116
79 AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {} 117 AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {}
oshima 2015/05/15 17:29:16 can you add DCHECK(!keyboard_controller_) ?
bshe 2015/05/15 17:33:50 Done.
80 118
81 void AshKeyboardControllerProxy::OnRequest( 119 void AshKeyboardControllerProxy::OnRequest(
82 const ExtensionHostMsg_Request_Params& params) { 120 const ExtensionHostMsg_Request_Params& params) {
83 extension_function_dispatcher_->Dispatch( 121 extension_function_dispatcher_->Dispatch(
84 params, web_contents()->GetRenderViewHost()); 122 params, web_contents()->GetRenderViewHost());
85 } 123 }
86 124
87 ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() { 125 ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() {
88 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); 126 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
89 DCHECK(root_window); 127 DCHECK(root_window);
(...skipping 26 matching lines...) Expand all
116 contents); 154 contents);
117 Observe(contents); 155 Observe(contents);
118 } 156 }
119 157
120 extensions::WindowController* 158 extensions::WindowController*
121 AshKeyboardControllerProxy::GetExtensionWindowController() const { 159 AshKeyboardControllerProxy::GetExtensionWindowController() const {
122 // The keyboard doesn't have a window controller. 160 // The keyboard doesn't have a window controller.
123 return NULL; 161 return NULL;
124 } 162 }
125 163
164 void AshKeyboardControllerProxy::SetController(
165 keyboard::KeyboardController* controller) {
166 // During KeyboardController destruction, controller can be set to null.
167 if (!controller) {
168 DCHECK(keyboard_controller_);
169 keyboard_controller_->RemoveObserver(observer_.get());
oshima 2015/05/15 17:29:16 keyboard_controller_ = nullptr;
bshe 2015/05/15 17:33:50 Done.
170 return;
171 }
172 keyboard_controller_ = controller;
173 observer_.reset(new AshKeyboardControllerObserver(browser_context()));
174 keyboard_controller_->AddObserver(observer_.get());
175 }
176
126 content::WebContents* 177 content::WebContents*
127 AshKeyboardControllerProxy::GetAssociatedWebContents() const { 178 AshKeyboardControllerProxy::GetAssociatedWebContents() const {
128 return web_contents(); 179 return web_contents();
129 } 180 }
130 181
131 bool AshKeyboardControllerProxy::OnMessageReceived( 182 bool AshKeyboardControllerProxy::OnMessageReceived(
132 const IPC::Message& message) { 183 const IPC::Message& message) {
133 bool handled = true; 184 bool handled = true;
134 IPC_BEGIN_MESSAGE_MAP(AshKeyboardControllerProxy, message) 185 IPC_BEGIN_MESSAGE_MAP(AshKeyboardControllerProxy, message)
135 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) 186 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 virtual_keyboard_private::ToString( 226 virtual_keyboard_private::ToString(
176 TextInputTypeToGeneratedInputTypeEnum(type))); 227 TextInputTypeToGeneratedInputTypeEnum(type)));
177 event_args->Append(input_context.release()); 228 event_args->Append(input_context.release());
178 229
179 scoped_ptr<extensions::Event> event(new extensions::Event( 230 scoped_ptr<extensions::Event> event(new extensions::Event(
180 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, 231 virtual_keyboard_private::OnTextInputBoxFocused::kEventName,
181 event_args.Pass())); 232 event_args.Pass()));
182 event->restrict_to_browser_context = browser_context(); 233 event->restrict_to_browser_context = browser_context();
183 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); 234 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass());
184 } 235 }
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