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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_native_widget_aura.cc

Issue 31043006: Moves creation of various clients to DesktopNativeWidgetAura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve merge Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "ui/aura/client/activation_client.h" 8 #include "ui/aura/client/activation_client.h"
9 #include "ui/aura/client/aura_constants.h" 9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/cursor_client.h" 10 #include "ui/aura/client/cursor_client.h"
11 #include "ui/aura/client/drag_drop_client.h"
11 #include "ui/aura/client/focus_client.h" 12 #include "ui/aura/client/focus_client.h"
12 #include "ui/aura/client/window_tree_client.h" 13 #include "ui/aura/client/window_tree_client.h"
13 #include "ui/aura/root_window.h" 14 #include "ui/aura/root_window.h"
14 #include "ui/aura/root_window_host.h" 15 #include "ui/aura/root_window_host.h"
15 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
16 #include "ui/aura/window_observer.h" 17 #include "ui/aura/window_observer.h"
17 #include "ui/aura/window_property.h" 18 #include "ui/aura/window_property.h"
18 #include "ui/base/hit_test.h" 19 #include "ui/base/hit_test.h"
19 #include "ui/compositor/layer.h" 20 #include "ui/compositor/layer.h"
20 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
22 #include "ui/gfx/point_conversions.h" 23 #include "ui/gfx/point_conversions.h"
23 #include "ui/gfx/screen.h" 24 #include "ui/gfx/screen.h"
24 #include "ui/gfx/size_conversions.h" 25 #include "ui/gfx/size_conversions.h"
25 #include "ui/native_theme/native_theme.h" 26 #include "ui/native_theme/native_theme.h"
26 #include "ui/views/corewm/compound_event_filter.h" 27 #include "ui/views/corewm/compound_event_filter.h"
27 #include "ui/views/corewm/corewm_switches.h" 28 #include "ui/views/corewm/corewm_switches.h"
29 #include "ui/views/corewm/cursor_manager.h"
30 #include "ui/views/corewm/focus_controller.h"
28 #include "ui/views/corewm/input_method_event_filter.h" 31 #include "ui/views/corewm/input_method_event_filter.h"
32 #include "ui/views/corewm/native_cursor_manager.h"
29 #include "ui/views/corewm/shadow_controller.h" 33 #include "ui/views/corewm/shadow_controller.h"
30 #include "ui/views/corewm/shadow_types.h" 34 #include "ui/views/corewm/shadow_types.h"
31 #include "ui/views/corewm/tooltip.h" 35 #include "ui/views/corewm/tooltip.h"
32 #include "ui/views/corewm/tooltip_controller.h" 36 #include "ui/views/corewm/tooltip_controller.h"
33 #include "ui/views/corewm/visibility_controller.h" 37 #include "ui/views/corewm/visibility_controller.h"
34 #include "ui/views/corewm/window_modality_controller.h" 38 #include "ui/views/corewm/window_modality_controller.h"
35 #include "ui/views/drag_utils.h" 39 #include "ui/views/drag_utils.h"
36 #include "ui/views/ime/input_method.h" 40 #include "ui/views/ime/input_method.h"
37 #include "ui/views/ime/input_method_bridge.h" 41 #include "ui/views/ime/input_method_bridge.h"
38 #include "ui/views/widget/desktop_aura/desktop_capture_client.h" 42 #include "ui/views/widget/desktop_aura/desktop_capture_client.h"
43 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
44 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h"
45 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h"
46 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
39 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h" 47 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h"
48 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h"
40 #include "ui/views/widget/drop_helper.h" 49 #include "ui/views/widget/drop_helper.h"
41 #include "ui/views/widget/native_widget_aura.h" 50 #include "ui/views/widget/native_widget_aura.h"
42 #include "ui/views/widget/root_view.h" 51 #include "ui/views/widget/root_view.h"
43 #include "ui/views/widget/tooltip_manager_aura.h" 52 #include "ui/views/widget/tooltip_manager_aura.h"
44 #include "ui/views/widget/widget.h" 53 #include "ui/views/widget/widget.h"
45 #include "ui/views/widget/widget_aura_utils.h" 54 #include "ui/views/widget/widget_aura_utils.h"
46 #include "ui/views/widget/widget_delegate.h" 55 #include "ui/views/widget/widget_delegate.h"
47 #include "ui/views/widget/window_reorderer.h" 56 #include "ui/views/widget/window_reorderer.h"
48 57
49 #if defined(OS_WIN) 58 #if defined(OS_WIN)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 217
209 void DesktopNativeWidgetAura::OnHostClosed() { 218 void DesktopNativeWidgetAura::OnHostClosed() {
210 // Don't invoke Widget::OnNativeWidgetDestroying(), its done by 219 // Don't invoke Widget::OnNativeWidgetDestroying(), its done by
211 // DesktopRootWindowHost. 220 // DesktopRootWindowHost.
212 221
213 // The WindowModalityController is at the front of the event pretarget 222 // The WindowModalityController is at the front of the event pretarget
214 // handler list. We destroy it first to preserve order symantics. 223 // handler list. We destroy it first to preserve order symantics.
215 if (window_modality_controller_) 224 if (window_modality_controller_)
216 window_modality_controller_.reset(); 225 window_modality_controller_.reset();
217 226
218 // Make sure we don't still have capture. Otherwise CaptureController and 227 // Make sure we don't have capture. Otherwise CaptureController and RootWindow
219 // RootWindow are left referencing a deleted Window. 228 // are left referencing a deleted Window.
220 { 229 {
221 aura::Window* capture_window = capture_client_->GetCaptureWindow(); 230 aura::Window* capture_window = capture_client_->GetCaptureWindow();
222 if (capture_window && root_window_->Contains(capture_window)) 231 if (capture_window && root_window_->Contains(capture_window))
223 capture_window->ReleaseCapture(); 232 capture_window->ReleaseCapture();
224 } 233 }
225 234
226 // DesktopRootWindowHost owns the ActivationController which ShadowController 235 // DesktopRootWindowHost owns the ActivationController which ShadowController
227 // references. Make sure we destroy ShadowController early on. 236 // references. Make sure we destroy ShadowController early on.
228 shadow_controller_.reset(); 237 shadow_controller_.reset();
229 tooltip_manager_.reset(); 238 tooltip_manager_.reset();
(...skipping 11 matching lines...) Expand all
241 root_window_.reset(); // Uses input_method_event_filter_ at destruction. 250 root_window_.reset(); // Uses input_method_event_filter_ at destruction.
242 // RootWindow owns |desktop_root_window_host_|. 251 // RootWindow owns |desktop_root_window_host_|.
243 desktop_root_window_host_ = NULL; 252 desktop_root_window_host_ = NULL;
244 content_window_ = NULL; 253 content_window_ = NULL;
245 254
246 native_widget_delegate_->OnNativeWidgetDestroyed(); 255 native_widget_delegate_->OnNativeWidgetDestroyed();
247 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 256 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
248 delete this; 257 delete this;
249 } 258 }
250 259
251 void DesktopNativeWidgetAura::InstallInputMethodEventFilter( 260 void DesktopNativeWidgetAura::OnDesktopRootWindowHostDestroyed(
252 aura::RootWindow* root) { 261 aura::RootWindow* root) {
253 DCHECK(!input_method_event_filter_.get()); 262 // |root_window_| is still valid, but DesktopRootWindowHost is nearly
263 // destroyed. Do cleanup here of members DesktopRootWindowHost may also use.
264 aura::client::SetFocusClient(root, NULL);
265 aura::client::SetActivationClient(root, NULL);
266 focus_client_.reset();
254 267
255 // CEF sets focus to the window the user clicks down on. 268 aura::client::SetDispatcherClient(root, NULL);
256 // TODO(beng): see if we can't do this some other way. CEF seems a heavy- 269 dispatcher_client_.reset();
257 // handed way of accomplishing focus.
258 // No event filter for aura::Env. Create CompoundEvnetFilter per RootWindow.
259 root_window_event_filter_ = new corewm::CompoundEventFilter;
260 // Pass ownership of the filter to the root_window.
261 root->SetEventFilter(root_window_event_filter_);
262 270
263 input_method_event_filter_.reset( 271 aura::client::SetCursorClient(root, NULL);
264 new corewm::InputMethodEventFilter(root->GetAcceleratedWidget())); 272 cursor_client_.reset();
265 input_method_event_filter_->SetInputMethodPropertyInRootWindow(root);
266 root_window_event_filter_->AddHandler(input_method_event_filter_.get());
267 }
268 273
269 void DesktopNativeWidgetAura::CreateCaptureClient(aura::RootWindow* root) { 274 aura::client::SetScreenPositionClient(root, NULL);
270 DCHECK(!capture_client_.get()); 275 position_client_.reset();
271 capture_client_.reset(new DesktopCaptureClient(root)); 276
277 aura::client::SetDragDropClient(root, NULL);
278 drag_drop_client_.reset();
272 } 279 }
273 280
274 void DesktopNativeWidgetAura::HandleActivationChanged(bool active) { 281 void DesktopNativeWidgetAura::HandleActivationChanged(bool active) {
275 native_widget_delegate_->OnNativeWidgetActivationChanged(active); 282 native_widget_delegate_->OnNativeWidgetActivationChanged(active);
276 aura::client::ActivationClient* activation_client = 283 aura::client::ActivationClient* activation_client =
277 aura::client::GetActivationClient(root_window_.get()); 284 aura::client::GetActivationClient(root_window_.get());
278 if (!activation_client) 285 if (!activation_client)
279 return; 286 return;
280 if (active) { 287 if (active) {
281 if (GetWidget()->HasFocusManager()) { 288 if (GetWidget()->HasFocusManager()) {
(...skipping 13 matching lines...) Expand all
295 // If we're not active we need to deactivate the corresponding 302 // If we're not active we need to deactivate the corresponding
296 // aura::Window. This way if a child widget is active it gets correctly 303 // aura::Window. This way if a child widget is active it gets correctly
297 // deactivated (child widgets don't get native desktop activation changes, 304 // deactivated (child widgets don't get native desktop activation changes,
298 // only aura activation changes). 305 // only aura activation changes).
299 aura::Window* active_window = activation_client->GetActiveWindow(); 306 aura::Window* active_window = activation_client->GetActiveWindow();
300 if (active_window) 307 if (active_window)
301 activation_client->DeactivateWindow(active_window); 308 activation_client->DeactivateWindow(active_window);
302 } 309 }
303 } 310 }
304 311
305 void DesktopNativeWidgetAura::InstallWindowModalityController(
306 aura::RootWindow* root) {
307 // The WindowsModalityController event filter should be at the head of the
308 // pre target handlers list. This ensures that it handles input events first
309 // when modal windows are at the top of the Zorder.
310 if (widget_type_ == Widget::InitParams::TYPE_WINDOW)
311 window_modality_controller_.reset(
312 new views::corewm::WindowModalityController(root));
313 }
314
315 //////////////////////////////////////////////////////////////////////////////// 312 ////////////////////////////////////////////////////////////////////////////////
316 // DesktopNativeWidgetAura, internal::NativeWidgetPrivate implementation: 313 // DesktopNativeWidgetAura, internal::NativeWidgetPrivate implementation:
317 314
318 void DesktopNativeWidgetAura::InitNativeWidget( 315 void DesktopNativeWidgetAura::InitNativeWidget(
319 const Widget::InitParams& params) { 316 const Widget::InitParams& params) {
320 ownership_ = params.ownership; 317 ownership_ = params.ownership;
321 widget_type_ = params.type; 318 widget_type_ = params.type;
322 319
323 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_window_); 320 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_window_);
324 // Animations on TYPE_WINDOW are handled by the OS. Additionally if we animate 321 // Animations on TYPE_WINDOW are handled by the OS. Additionally if we animate
325 // these windows the size of the window gets augmented, effecting restore 322 // these windows the size of the window gets augmented, effecting restore
326 // bounds and maximized windows in bad ways. 323 // bounds and maximized windows in bad ways.
327 if (params.type == Widget::InitParams::TYPE_WINDOW && 324 if (params.type == Widget::InitParams::TYPE_WINDOW &&
328 !params.remove_standard_frame) { 325 !params.remove_standard_frame) {
329 content_window_->SetProperty(aura::client::kAnimationsDisabledKey, true); 326 content_window_->SetProperty(aura::client::kAnimationsDisabledKey, true);
330 } 327 }
331 content_window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); 328 content_window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
332 content_window_->Init(params.layer_type); 329 content_window_->Init(params.layer_type);
333 corewm::SetShadowType(content_window_, corewm::SHADOW_TYPE_NONE); 330 corewm::SetShadowType(content_window_, corewm::SHADOW_TYPE_NONE);
334 #if defined(OS_LINUX) // TODO(scottmg): http://crbug.com/180071 331 #if defined(OS_LINUX) // TODO(scottmg): http://crbug.com/180071
335 content_window_->Show(); 332 content_window_->Show();
336 #endif 333 #endif
337 334
338 desktop_root_window_host_ = params.desktop_root_window_host ?
339 params.desktop_root_window_host :
340 DesktopRootWindowHost::Create(native_widget_delegate_,
341 this, params.bounds);
342 root_window_.reset(
343 desktop_root_window_host_->Init(content_window_, params));
344
345 UpdateWindowTransparency();
346
347 content_window_container_ = new aura::Window(NULL); 335 content_window_container_ = new aura::Window(NULL);
348 content_window_container_->Init(ui::LAYER_NOT_DRAWN); 336 content_window_container_->Init(ui::LAYER_NOT_DRAWN);
349 content_window_container_->Show(); 337 content_window_container_->Show();
350 content_window_container_->AddChild(content_window_); 338 content_window_container_->AddChild(content_window_);
339
340 desktop_root_window_host_ = params.desktop_root_window_host ?
341 params.desktop_root_window_host :
342 DesktopRootWindowHost::Create(native_widget_delegate_, this);
343 aura::RootWindow::CreateParams rw_params(params.bounds);
344 desktop_root_window_host_->Init(content_window_, params, &rw_params);
345
346 root_window_.reset(new aura::RootWindow(rw_params));
347 root_window_->Init();
351 root_window_->AddChild(content_window_container_); 348 root_window_->AddChild(content_window_container_);
349
350 // The WindowsModalityController event filter should be at the head of the
351 // pre target handlers list. This ensures that it handles input events first
352 // when modal windows are at the top of the Zorder.
353 if (widget_type_ == Widget::InitParams::TYPE_WINDOW)
354 window_modality_controller_.reset(
355 new views::corewm::WindowModalityController(root_window_.get()));
356
357 // |root_window_event_filter_| must be created before
358 // OnRootWindowHostCreated() is invoked.
359
360 // CEF sets focus to the window the user clicks down on.
361 // TODO(beng): see if we can't do this some other way. CEF seems a heavy-
362 // handed way of accomplishing focus.
363 // No event filter for aura::Env. Create CompoundEvnetFilter per RootWindow.
364 root_window_event_filter_ = new corewm::CompoundEventFilter;
365 // Pass ownership of the filter to the root_window.
366 root_window_->SetEventFilter(root_window_event_filter_);
367
368 desktop_root_window_host_->OnRootWindowCreated(root_window_.get(), params);
369
370 native_widget_delegate_->OnNativeWidgetCreated(true);
371
372 UpdateWindowTransparency();
373
374 capture_client_.reset(new DesktopCaptureClient(root_window_.get()));
375
376 corewm::FocusController* focus_controller =
377 new corewm::FocusController(new DesktopFocusRules(content_window_));
378 focus_client_.reset(focus_controller);
379 aura::client::SetFocusClient(root_window_.get(), focus_controller);
380 aura::client::SetActivationClient(root_window_.get(), focus_controller);
381 root_window_->AddPreTargetHandler(focus_controller);
382
383 dispatcher_client_.reset(new DesktopDispatcherClient);
384 aura::client::SetDispatcherClient(root_window_.get(),
385 dispatcher_client_.get());
386
387 DesktopNativeCursorManager* desktop_native_cursor_manager =
388 new views::DesktopNativeCursorManager(
389 root_window_.get(),
390 DesktopCursorLoaderUpdater::Create());
391 cursor_client_.reset(
392 new views::corewm::CursorManager(
393 scoped_ptr<corewm::NativeCursorManager>(
394 desktop_native_cursor_manager)));
395 aura::client::SetCursorClient(root_window_.get(), cursor_client_.get());
396
397 position_client_.reset(new DesktopScreenPositionClient());
398 aura::client::SetScreenPositionClient(root_window_.get(),
399 position_client_.get());
400
401 InstallInputMethodEventFilter();
402
403 drag_drop_client_ = desktop_root_window_host_->CreateDragDropClient(
404 desktop_native_cursor_manager);
405 aura::client::SetDragDropClient(root_window_.get(), drag_drop_client_.get());
406
407 focus_client_->FocusWindow(content_window_);
408
352 OnRootWindowHostResized(root_window_.get()); 409 OnRootWindowHostResized(root_window_.get());
353 410
354 root_window_->AddRootWindowObserver(this); 411 root_window_->AddRootWindowObserver(this);
355 412
356 window_tree_client_.reset( 413 window_tree_client_.reset(
357 new DesktopNativeWidgetAuraWindowTreeClient(root_window_.get())); 414 new DesktopNativeWidgetAuraWindowTreeClient(root_window_.get()));
358 drop_helper_.reset(new DropHelper( 415 drop_helper_.reset(new DropHelper(
359 static_cast<internal::RootView*>(GetWidget()->GetRootView()))); 416 static_cast<internal::RootView*>(GetWidget()->GetRootView())));
360 aura::client::SetDragDropDelegate(content_window_, this); 417 aura::client::SetDragDropDelegate(content_window_, this);
361 418
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 native_widget_delegate_->OnNativeWidgetMove(); 1072 native_widget_delegate_->OnNativeWidgetMove();
1016 } 1073 }
1017 1074
1018 //////////////////////////////////////////////////////////////////////////////// 1075 ////////////////////////////////////////////////////////////////////////////////
1019 // DesktopNativeWidgetAura, NativeWidget implementation: 1076 // DesktopNativeWidgetAura, NativeWidget implementation:
1020 1077
1021 ui::EventHandler* DesktopNativeWidgetAura::GetEventHandler() { 1078 ui::EventHandler* DesktopNativeWidgetAura::GetEventHandler() {
1022 return this; 1079 return this;
1023 } 1080 }
1024 1081
1082 void DesktopNativeWidgetAura::InstallInputMethodEventFilter() {
1083 DCHECK(!input_method_event_filter_.get());
1084
1085 input_method_event_filter_.reset(
1086 new corewm::InputMethodEventFilter(root_window_->GetAcceleratedWidget()));
1087 input_method_event_filter_->SetInputMethodPropertyInRootWindow(
1088 root_window_.get());
1089 root_window_event_filter_->AddHandler(input_method_event_filter_.get());
1090 }
1091
1025 void DesktopNativeWidgetAura::UpdateWindowTransparency() { 1092 void DesktopNativeWidgetAura::UpdateWindowTransparency() {
1026 content_window_->SetTransparent(ShouldUseNativeFrame()); 1093 content_window_->SetTransparent(ShouldUseNativeFrame());
1027 } 1094 }
1028 1095
1029 } // namespace views 1096 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_native_widget_aura.h ('k') | ui/views/widget/desktop_aura/desktop_root_window_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698