Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / views / widget / desktop_aura / desktop_native_widget_aura.cc
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
3 // found in the LICENSE file.
4
5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6
7 #include "base/bind.h"
8 #include "base/debug/trace_event.h"
9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/cursor_client.h"
11 #include "ui/aura/client/focus_client.h"
12 #include "ui/aura/client/window_tree_client.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_observer.h"
15 #include "ui/aura/window_property.h"
16 #include "ui/aura/window_tree_host.h"
17 #include "ui/base/hit_test.h"
18 #include "ui/base/ui_base_switches_util.h"
19 #include "ui/compositor/layer.h"
20 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/display.h"
22 #include "ui/gfx/point_conversions.h"
23 #include "ui/gfx/screen.h"
24 #include "ui/gfx/size_conversions.h"
25 #include "ui/native_theme/native_theme.h"
26 #include "ui/views/corewm/tooltip.h"
27 #include "ui/views/corewm/tooltip_controller.h"
28 #include "ui/views/drag_utils.h"
29 #include "ui/views/ime/input_method_bridge.h"
30 #include "ui/views/ime/null_input_method.h"
31 #include "ui/views/view_constants_aura.h"
32 #include "ui/views/widget/desktop_aura/desktop_capture_client.h"
33 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
34 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h"
35 #include "ui/views/widget/desktop_aura/desktop_event_client.h"
36 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h"
37 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
38 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h"
39 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
40 #include "ui/views/widget/drop_helper.h"
41 #include "ui/views/widget/native_widget_aura.h"
42 #include "ui/views/widget/root_view.h"
43 #include "ui/views/widget/tooltip_manager_aura.h"
44 #include "ui/views/widget/widget.h"
45 #include "ui/views/widget/widget_aura_utils.h"
46 #include "ui/views/widget/widget_delegate.h"
47 #include "ui/views/widget/window_reorderer.h"
48 #include "ui/wm/core/compound_event_filter.h"
49 #include "ui/wm/core/cursor_manager.h"
50 #include "ui/wm/core/focus_controller.h"
51 #include "ui/wm/core/input_method_event_filter.h"
52 #include "ui/wm/core/native_cursor_manager.h"
53 #include "ui/wm/core/shadow_controller.h"
54 #include "ui/wm/core/shadow_types.h"
55 #include "ui/wm/core/visibility_controller.h"
56 #include "ui/wm/core/window_modality_controller.h"
57 #include "ui/wm/public/activation_client.h"
58 #include "ui/wm/public/drag_drop_client.h"
59
60 #if defined(OS_WIN)
61 #include "ui/base/win/shell.h"
62 #include "ui/gfx/win/dpi.h"
63 #endif
64
65 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(VIEWS_EXPORT,
66                                       views::DesktopNativeWidgetAura*);
67
68 namespace views {
69
70 DEFINE_WINDOW_PROPERTY_KEY(DesktopNativeWidgetAura*,
71                            kDesktopNativeWidgetAuraKey, NULL);
72
73 namespace {
74
75 // This class provides functionality to create a top level widget to host a
76 // child window.
77 class DesktopNativeWidgetTopLevelHandler : public aura::WindowObserver {
78  public:
79   // This function creates a widget with the bounds passed in which eventually
80   // becomes the parent of the child window passed in.
81   static aura::Window* CreateParentWindow(aura::Window* child_window,
82                                           const gfx::Rect& bounds,
83                                           bool full_screen,
84                                           bool root_is_always_on_top) {
85     // This instance will get deleted when the widget is destroyed.
86     DesktopNativeWidgetTopLevelHandler* top_level_handler =
87         new DesktopNativeWidgetTopLevelHandler;
88
89     child_window->SetBounds(gfx::Rect(bounds.size()));
90
91     Widget::InitParams init_params;
92     init_params.type = full_screen ? Widget::InitParams::TYPE_WINDOW :
93         Widget::InitParams::TYPE_POPUP;
94     init_params.bounds = bounds;
95     init_params.ownership = Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
96     init_params.layer_type = aura::WINDOW_LAYER_NOT_DRAWN;
97     init_params.can_activate = full_screen;
98     init_params.keep_on_top = root_is_always_on_top;
99
100     // This widget instance will get deleted when the window is
101     // destroyed.
102     top_level_handler->top_level_widget_ = new Widget();
103     top_level_handler->top_level_widget_->Init(init_params);
104
105     top_level_handler->top_level_widget_->SetFullscreen(full_screen);
106     top_level_handler->top_level_widget_->Show();
107
108     aura::Window* native_window =
109         top_level_handler->top_level_widget_->GetNativeView();
110     child_window->AddObserver(top_level_handler);
111     native_window->AddObserver(top_level_handler);
112     top_level_handler->child_window_ = child_window;
113     return native_window;
114   }
115
116   // aura::WindowObserver overrides
117   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
118     window->RemoveObserver(this);
119
120     // If the widget is being destroyed by the OS then we should not try and
121     // destroy it again.
122     if (top_level_widget_ &&
123         window == top_level_widget_->GetNativeView()) {
124       top_level_widget_ = NULL;
125       return;
126     }
127
128     if (top_level_widget_) {
129       DCHECK(top_level_widget_->GetNativeView());
130       top_level_widget_->GetNativeView()->RemoveObserver(this);
131       // When we receive a notification that the child of the window created
132       // above is being destroyed we go ahead and initiate the destruction of
133       // the corresponding widget.
134       top_level_widget_->Close();
135       top_level_widget_ = NULL;
136     }
137     delete this;
138   }
139
140   virtual void OnWindowBoundsChanged(aura::Window* window,
141                                      const gfx::Rect& old_bounds,
142                                      const gfx::Rect& new_bounds) OVERRIDE {
143     if (top_level_widget_ && window == child_window_)
144       top_level_widget_->SetSize(new_bounds.size());
145   }
146
147  private:
148   DesktopNativeWidgetTopLevelHandler()
149       : top_level_widget_(NULL),
150         child_window_(NULL) {}
151
152   virtual ~DesktopNativeWidgetTopLevelHandler() {}
153
154   Widget* top_level_widget_;
155   aura::Window* child_window_;
156
157   DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetTopLevelHandler);
158 };
159
160 class DesktopNativeWidgetAuraWindowTreeClient :
161     public aura::client::WindowTreeClient {
162  public:
163   explicit DesktopNativeWidgetAuraWindowTreeClient(
164       aura::Window* root_window)
165       : root_window_(root_window) {
166     aura::client::SetWindowTreeClient(root_window_, this);
167   }
168   virtual ~DesktopNativeWidgetAuraWindowTreeClient() {
169     aura::client::SetWindowTreeClient(root_window_, NULL);
170   }
171
172   // Overridden from client::WindowTreeClient:
173   virtual aura::Window* GetDefaultParent(aura::Window* context,
174                                          aura::Window* window,
175                                          const gfx::Rect& bounds) OVERRIDE {
176     bool is_fullscreen = window->GetProperty(aura::client::kShowStateKey) ==
177         ui::SHOW_STATE_FULLSCREEN;
178     bool is_menu = window->type() == ui::wm::WINDOW_TYPE_MENU;
179
180     if (is_fullscreen || is_menu) {
181       bool root_is_always_on_top = false;
182       internal::NativeWidgetPrivate* native_widget =
183           DesktopNativeWidgetAura::ForWindow(root_window_);
184       if (native_widget)
185         root_is_always_on_top = native_widget->IsAlwaysOnTop();
186
187       return DesktopNativeWidgetTopLevelHandler::CreateParentWindow(
188           window, bounds, is_fullscreen, root_is_always_on_top);
189     }
190     return root_window_;
191   }
192
193  private:
194   aura::Window* root_window_;
195
196   DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAuraWindowTreeClient);
197 };
198
199 }  // namespace
200
201 class FocusManagerEventHandler : public ui::EventHandler {
202  public:
203   FocusManagerEventHandler(DesktopNativeWidgetAura* desktop_native_widget_aura)
204       : desktop_native_widget_aura_(desktop_native_widget_aura) {}
205
206   // Implementation of ui::EventHandler:
207   virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
208     Widget* widget = desktop_native_widget_aura_->GetWidget();
209     if (widget && widget->GetFocusManager()->GetFocusedView() &&
210         !widget->GetFocusManager()->OnKeyEvent(*event)) {
211       event->SetHandled();
212     }
213   }
214
215  private:
216   DesktopNativeWidgetAura* desktop_native_widget_aura_;
217
218   DISALLOW_COPY_AND_ASSIGN(FocusManagerEventHandler);
219 };
220
221 class RootWindowDestructionObserver : public aura::WindowObserver {
222  public:
223   explicit RootWindowDestructionObserver(DesktopNativeWidgetAura* parent)
224     : parent_(parent) {}
225   virtual ~RootWindowDestructionObserver() {}
226
227  private:
228   // Overridden from aura::WindowObserver:
229   virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
230     parent_->RootWindowDestroyed();
231     window->RemoveObserver(this);
232     delete this;
233   }
234
235   DesktopNativeWidgetAura* parent_;
236
237   DISALLOW_COPY_AND_ASSIGN(RootWindowDestructionObserver);
238 };
239
240 ////////////////////////////////////////////////////////////////////////////////
241 // DesktopNativeWidgetAura, public:
242
243 int DesktopNativeWidgetAura::cursor_reference_count_ = 0;
244 DesktopNativeCursorManager* DesktopNativeWidgetAura::native_cursor_manager_ =
245     NULL;
246 wm::CursorManager* DesktopNativeWidgetAura::cursor_manager_ = NULL;
247
248 DesktopNativeWidgetAura::DesktopNativeWidgetAura(
249     internal::NativeWidgetDelegate* delegate)
250     : desktop_window_tree_host_(NULL),
251       ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
252       close_widget_factory_(this),
253       can_activate_(true),
254       content_window_container_(NULL),
255       content_window_(new aura::Window(this)),
256       native_widget_delegate_(delegate),
257       last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
258       restore_focus_on_activate_(false),
259       cursor_(gfx::kNullCursor),
260       widget_type_(Widget::InitParams::TYPE_WINDOW) {
261   aura::client::SetFocusChangeObserver(content_window_, this);
262   aura::client::SetActivationChangeObserver(content_window_, this);
263 }
264
265 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() {
266   if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
267     delete native_widget_delegate_;
268   else
269     CloseNow();
270 }
271
272 // static
273 DesktopNativeWidgetAura* DesktopNativeWidgetAura::ForWindow(
274     aura::Window* window) {
275   return window->GetProperty(kDesktopNativeWidgetAuraKey);
276 }
277
278 void DesktopNativeWidgetAura::OnHostClosed() {
279   // Don't invoke Widget::OnNativeWidgetDestroying(), its done by
280   // DesktopWindowTreeHost.
281
282   // The WindowModalityController is at the front of the event pretarget
283   // handler list. We destroy it first to preserve order symantics.
284   if (window_modality_controller_)
285     window_modality_controller_.reset();
286
287   // Make sure we don't have capture. Otherwise CaptureController and
288   // WindowEventDispatcher are left referencing a deleted Window.
289   {
290     aura::Window* capture_window = capture_client_->GetCaptureWindow();
291     if (capture_window && host_->window()->Contains(capture_window))
292       capture_window->ReleaseCapture();
293   }
294
295   // DesktopWindowTreeHost owns the ActivationController which ShadowController
296   // references. Make sure we destroy ShadowController early on.
297   shadow_controller_.reset();
298   tooltip_manager_.reset();
299   host_->window()->RemovePreTargetHandler(tooltip_controller_.get());
300   aura::client::SetTooltipClient(host_->window(), NULL);
301   tooltip_controller_.reset();
302
303   root_window_event_filter_->RemoveHandler(input_method_event_filter_.get());
304
305   window_tree_client_.reset();  // Uses host_->dispatcher() at destruction.
306
307   capture_client_.reset();  // Uses host_->dispatcher() at destruction.
308
309   // FocusController uses |content_window_|. Destroy it now so that we don't
310   // have to worry about the possibility of FocusController attempting to use
311   // |content_window_| after it's been destroyed but before all child windows
312   // have been destroyed.
313   host_->window()->RemovePreTargetHandler(focus_client_.get());
314   aura::client::SetFocusClient(host_->window(), NULL);
315   aura::client::SetActivationClient(host_->window(), NULL);
316   focus_client_.reset();
317
318   host_->RemoveObserver(this);
319   host_.reset();  // Uses input_method_event_filter_ at destruction.
320   // WindowEventDispatcher owns |desktop_window_tree_host_|.
321   desktop_window_tree_host_ = NULL;
322   content_window_ = NULL;
323
324   native_widget_delegate_->OnNativeWidgetDestroyed();
325   if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
326     delete this;
327 }
328
329 void DesktopNativeWidgetAura::OnDesktopWindowTreeHostDestroyed(
330     aura::WindowTreeHost* host) {
331   // |dispatcher_| is still valid, but DesktopWindowTreeHost is nearly
332   // destroyed. Do cleanup here of members DesktopWindowTreeHost may also use.
333   aura::client::SetDispatcherClient(host->window(), NULL);
334   dispatcher_client_.reset();
335
336   // We explicitly do NOT clear the cursor client property. Since the cursor
337   // manager is a singleton, it can outlive any window hierarchy, and it's
338   // important that objects attached to this destroying window hierarchy have
339   // an opportunity to deregister their observers from the cursor manager.
340   // They may want to do this when they are notified that they're being
341   // removed from the window hierarchy, which happens soon after this
342   // function when DesktopWindowTreeHost* calls DestroyDispatcher().
343   native_cursor_manager_->RemoveHost(host);
344
345   aura::client::SetScreenPositionClient(host->window(), NULL);
346   position_client_.reset();
347
348   aura::client::SetDragDropClient(host->window(), NULL);
349   drag_drop_client_.reset();
350
351   aura::client::SetEventClient(host->window(), NULL);
352   event_client_.reset();
353 }
354
355 void DesktopNativeWidgetAura::HandleActivationChanged(bool active) {
356   native_widget_delegate_->OnNativeWidgetActivationChanged(active);
357   aura::client::ActivationClient* activation_client =
358       aura::client::GetActivationClient(host_->window());
359   if (!activation_client)
360     return;
361   if (active) {
362     if (GetWidget()->HasFocusManager()) {
363       // This function can be called before the focus manager has had a
364       // chance to set the focused view. In which case we should get the
365       // last focused view.
366       View* view_for_activation =
367           GetWidget()->GetFocusManager()->GetFocusedView() ?
368               GetWidget()->GetFocusManager()->GetFocusedView() :
369                   GetWidget()->GetFocusManager()->GetStoredFocusView();
370       if (!view_for_activation)
371         view_for_activation = GetWidget()->GetRootView();
372       activation_client->ActivateWindow(
373           view_for_activation->GetWidget()->GetNativeView());
374     }
375   } else {
376     // If we're not active we need to deactivate the corresponding
377     // aura::Window. This way if a child widget is active it gets correctly
378     // deactivated (child widgets don't get native desktop activation changes,
379     // only aura activation changes).
380     aura::Window* active_window = activation_client->GetActiveWindow();
381     if (active_window)
382       activation_client->DeactivateWindow(active_window);
383   }
384 }
385
386 ////////////////////////////////////////////////////////////////////////////////
387 // DesktopNativeWidgetAura, internal::NativeWidgetPrivate implementation:
388
389 void DesktopNativeWidgetAura::InitNativeWidget(
390     const Widget::InitParams& params) {
391   ownership_ = params.ownership;
392   widget_type_ = params.type;
393
394   NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_window_);
395   // Animations on TYPE_WINDOW are handled by the OS. Additionally if we animate
396   // these windows the size of the window gets augmented, effecting restore
397   // bounds and maximized windows in bad ways.
398   if (params.type == Widget::InitParams::TYPE_WINDOW &&
399       !params.remove_standard_frame) {
400     content_window_->SetProperty(aura::client::kAnimationsDisabledKey, true);
401   }
402   content_window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
403   content_window_->Init(params.layer_type);
404   wm::SetShadowType(content_window_, wm::SHADOW_TYPE_NONE);
405
406   content_window_container_ = new aura::Window(NULL);
407   content_window_container_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
408   content_window_container_->Show();
409   content_window_container_->AddChild(content_window_);
410
411   desktop_window_tree_host_ = params.desktop_window_tree_host ?
412       params.desktop_window_tree_host :
413       DesktopWindowTreeHost::Create(native_widget_delegate_, this);
414   host_.reset(desktop_window_tree_host_->AsWindowTreeHost());
415   desktop_window_tree_host_->Init(content_window_, params);
416
417   // Mark this window as Desktop root window.
418   host_->window()->SetProperty(views::kDesktopRootWindow, true);
419
420   host_->InitHost();
421   host_->window()->AddChild(content_window_container_);
422   host_->window()->SetProperty(kDesktopNativeWidgetAuraKey, this);
423
424   host_->window()->AddObserver(new RootWindowDestructionObserver(this));
425
426   // The WindowsModalityController event filter should be at the head of the
427   // pre target handlers list. This ensures that it handles input events first
428   // when modal windows are at the top of the Zorder.
429   if (widget_type_ == Widget::InitParams::TYPE_WINDOW)
430     window_modality_controller_.reset(
431         new wm::WindowModalityController(host_->window()));
432
433   // |root_window_event_filter_| must be created before
434   // OnWindowTreeHostCreated() is invoked.
435
436   // CEF sets focus to the window the user clicks down on.
437   // TODO(beng): see if we can't do this some other way. CEF seems a heavy-
438   //             handed way of accomplishing focus.
439   // No event filter for aura::Env. Create CompoundEvnetFilter per
440   // WindowEventDispatcher.
441   root_window_event_filter_.reset(new wm::CompoundEventFilter);
442   host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
443
444   // The host's dispatcher must be added to |native_cursor_manager_| before
445   // OnNativeWidgetCreated() is called.
446   cursor_reference_count_++;
447   if (!native_cursor_manager_) {
448     native_cursor_manager_ = new DesktopNativeCursorManager(
449         DesktopCursorLoaderUpdater::Create());
450   }
451   if (!cursor_manager_) {
452     cursor_manager_ = new wm::CursorManager(
453         scoped_ptr<wm::NativeCursorManager>(native_cursor_manager_));
454   }
455   native_cursor_manager_->AddHost(host());
456   aura::client::SetCursorClient(host_->window(), cursor_manager_);
457
458   desktop_window_tree_host_->OnNativeWidgetCreated(params);
459
460   UpdateWindowTransparency();
461
462   capture_client_.reset(new DesktopCaptureClient(host_->window()));
463
464   wm::FocusController* focus_controller =
465       new wm::FocusController(new DesktopFocusRules(content_window_));
466   focus_client_.reset(focus_controller);
467   aura::client::SetFocusClient(host_->window(), focus_controller);
468   aura::client::SetActivationClient(host_->window(), focus_controller);
469   host_->window()->AddPreTargetHandler(focus_controller);
470
471   dispatcher_client_.reset(new DesktopDispatcherClient);
472   aura::client::SetDispatcherClient(host_->window(),
473                                     dispatcher_client_.get());
474
475   position_client_.reset(new DesktopScreenPositionClient(host_->window()));
476
477   InstallInputMethodEventFilter();
478
479   drag_drop_client_ = desktop_window_tree_host_->CreateDragDropClient(
480       native_cursor_manager_);
481   aura::client::SetDragDropClient(host_->window(),
482                                   drag_drop_client_.get());
483
484   static_cast<aura::client::FocusClient*>(focus_client_.get())->
485       FocusWindow(content_window_);
486
487   OnHostResized(host());
488
489   host_->AddObserver(this);
490
491   window_tree_client_.reset(
492       new DesktopNativeWidgetAuraWindowTreeClient(host_->window()));
493   drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
494   aura::client::SetDragDropDelegate(content_window_, this);
495
496   tooltip_manager_.reset(new TooltipManagerAura(GetWidget()));
497
498   tooltip_controller_.reset(
499       new corewm::TooltipController(
500           desktop_window_tree_host_->CreateTooltip()));
501   aura::client::SetTooltipClient(host_->window(),
502                                  tooltip_controller_.get());
503   host_->window()->AddPreTargetHandler(tooltip_controller_.get());
504
505   if (params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW) {
506     visibility_controller_.reset(new wm::VisibilityController);
507     aura::client::SetVisibilityClient(host_->window(),
508                                       visibility_controller_.get());
509     wm::SetChildWindowVisibilityChangesAnimated(host_->window());
510     wm::SetChildWindowVisibilityChangesAnimated(
511         content_window_container_);
512   }
513
514   if (params.type == Widget::InitParams::TYPE_WINDOW) {
515     focus_manager_event_handler_.reset(new FocusManagerEventHandler(this));
516     host_->window()->AddPreTargetHandler(focus_manager_event_handler_.get());
517   }
518
519   event_client_.reset(new DesktopEventClient);
520   aura::client::SetEventClient(host_->window(), event_client_.get());
521
522   aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_);
523
524   aura::client::SetActivationDelegate(content_window_, this);
525
526   shadow_controller_.reset(new wm::ShadowController(
527       aura::client::GetActivationClient(host_->window())));
528
529   content_window_->SetProperty(aura::client::kCanMaximizeKey,
530                                GetWidget()->widget_delegate()->CanMaximize());
531   content_window_->SetProperty(aura::client::kCanResizeKey,
532                                GetWidget()->widget_delegate()->CanResize());
533
534   window_reorderer_.reset(new WindowReorderer(content_window_,
535       GetWidget()->GetRootView()));
536 }
537
538 NonClientFrameView* DesktopNativeWidgetAura::CreateNonClientFrameView() {
539   return desktop_window_tree_host_->CreateNonClientFrameView();
540 }
541
542 bool DesktopNativeWidgetAura::ShouldUseNativeFrame() const {
543   return desktop_window_tree_host_->ShouldUseNativeFrame();
544 }
545
546 bool DesktopNativeWidgetAura::ShouldWindowContentsBeTransparent() const {
547   return desktop_window_tree_host_->ShouldWindowContentsBeTransparent();
548 }
549
550 void DesktopNativeWidgetAura::FrameTypeChanged() {
551   desktop_window_tree_host_->FrameTypeChanged();
552   UpdateWindowTransparency();
553 }
554
555 Widget* DesktopNativeWidgetAura::GetWidget() {
556   return native_widget_delegate_->AsWidget();
557 }
558
559 const Widget* DesktopNativeWidgetAura::GetWidget() const {
560   return native_widget_delegate_->AsWidget();
561 }
562
563 gfx::NativeView DesktopNativeWidgetAura::GetNativeView() const {
564   return content_window_;
565 }
566
567 gfx::NativeWindow DesktopNativeWidgetAura::GetNativeWindow() const {
568   return content_window_;
569 }
570
571 Widget* DesktopNativeWidgetAura::GetTopLevelWidget() {
572   return GetWidget();
573 }
574
575 const ui::Compositor* DesktopNativeWidgetAura::GetCompositor() const {
576   return content_window_ ? content_window_->layer()->GetCompositor() : NULL;
577 }
578
579 ui::Compositor* DesktopNativeWidgetAura::GetCompositor() {
580   return const_cast<ui::Compositor*>(
581       const_cast<const DesktopNativeWidgetAura*>(this)->GetCompositor());
582 }
583
584 ui::Layer* DesktopNativeWidgetAura::GetLayer() {
585   return content_window_ ? content_window_->layer() : NULL;
586 }
587
588 void DesktopNativeWidgetAura::ReorderNativeViews() {
589   window_reorderer_->ReorderChildWindows();
590 }
591
592 void DesktopNativeWidgetAura::ViewRemoved(View* view) {
593   DCHECK(drop_helper_.get() != NULL);
594   drop_helper_->ResetTargetViewIfEquals(view);
595 }
596
597 void DesktopNativeWidgetAura::SetNativeWindowProperty(const char* name,
598                                                       void* value) {
599   if (content_window_)
600     content_window_->SetNativeWindowProperty(name, value);
601 }
602
603 void* DesktopNativeWidgetAura::GetNativeWindowProperty(const char* name) const {
604   return content_window_ ?
605       content_window_->GetNativeWindowProperty(name) : NULL;
606 }
607
608 TooltipManager* DesktopNativeWidgetAura::GetTooltipManager() const {
609   return tooltip_manager_.get();
610 }
611
612 void DesktopNativeWidgetAura::SetCapture() {
613   if (!content_window_)
614     return;
615
616   content_window_->SetCapture();
617 }
618
619 void DesktopNativeWidgetAura::ReleaseCapture() {
620   if (!content_window_)
621     return;
622
623   content_window_->ReleaseCapture();
624 }
625
626 bool DesktopNativeWidgetAura::HasCapture() const {
627   return content_window_ && content_window_->HasCapture() &&
628       desktop_window_tree_host_->HasCapture();
629 }
630
631 InputMethod* DesktopNativeWidgetAura::CreateInputMethod() {
632   if (switches::IsTextInputFocusManagerEnabled())
633     return new NullInputMethod();
634
635   ui::InputMethod* host = input_method_event_filter_->input_method();
636   return new InputMethodBridge(this, host, false);
637 }
638
639 internal::InputMethodDelegate*
640     DesktopNativeWidgetAura::GetInputMethodDelegate() {
641   return this;
642 }
643
644 ui::InputMethod* DesktopNativeWidgetAura::GetHostInputMethod() {
645   return input_method_event_filter_->input_method();
646 }
647
648 void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) {
649   if (content_window_)
650     desktop_window_tree_host_->CenterWindow(size);
651 }
652
653 void DesktopNativeWidgetAura::GetWindowPlacement(
654       gfx::Rect* bounds,
655       ui::WindowShowState* maximized) const {
656   if (content_window_)
657     desktop_window_tree_host_->GetWindowPlacement(bounds, maximized);
658 }
659
660 bool DesktopNativeWidgetAura::SetWindowTitle(const base::string16& title) {
661   if (!content_window_)
662     return false;
663   content_window_->set_title(title);
664   return desktop_window_tree_host_->SetWindowTitle(title);
665 }
666
667 void DesktopNativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon,
668                                              const gfx::ImageSkia& app_icon) {
669   if (content_window_)
670     desktop_window_tree_host_->SetWindowIcons(window_icon, app_icon);
671 }
672
673 void DesktopNativeWidgetAura::InitModalType(ui::ModalType modal_type) {
674   // 99% of the time, we should not be asked to create a
675   // DesktopNativeWidgetAura that is modal. We only support window modal
676   // dialogs on the same lines as non AURA.
677   desktop_window_tree_host_->InitModalType(modal_type);
678 }
679
680 gfx::Rect DesktopNativeWidgetAura::GetWindowBoundsInScreen() const {
681   return content_window_ ?
682       desktop_window_tree_host_->GetWindowBoundsInScreen() : gfx::Rect();
683 }
684
685 gfx::Rect DesktopNativeWidgetAura::GetClientAreaBoundsInScreen() const {
686   return content_window_ ?
687       desktop_window_tree_host_->GetClientAreaBoundsInScreen() : gfx::Rect();
688 }
689
690 gfx::Rect DesktopNativeWidgetAura::GetRestoredBounds() const {
691   return content_window_ ?
692       desktop_window_tree_host_->GetRestoredBounds() : gfx::Rect();
693 }
694
695 void DesktopNativeWidgetAura::SetBounds(const gfx::Rect& bounds) {
696   if (!content_window_)
697     return;
698   // TODO(ananta)
699   // This code by default scales the bounds rectangle by 1.
700   // We could probably get rid of this and similar logic from
701   // the DesktopNativeWidgetAura::OnWindowTreeHostResized function.
702   float scale = 1;
703   aura::Window* root = host_->window();
704   if (root) {
705     scale = gfx::Screen::GetScreenFor(root)->
706         GetDisplayNearestWindow(root).device_scale_factor();
707   }
708   gfx::Rect bounds_in_pixels(
709       gfx::ToCeiledPoint(gfx::ScalePoint(bounds.origin(), scale)),
710       gfx::ToFlooredSize(gfx::ScaleSize(bounds.size(), scale)));
711   desktop_window_tree_host_->AsWindowTreeHost()->SetBounds(bounds_in_pixels);
712 }
713
714 void DesktopNativeWidgetAura::SetSize(const gfx::Size& size) {
715   if (content_window_)
716     desktop_window_tree_host_->SetSize(size);
717 }
718
719 void DesktopNativeWidgetAura::StackAbove(gfx::NativeView native_view) {
720 }
721
722 void DesktopNativeWidgetAura::StackAtTop() {
723   if (content_window_)
724     desktop_window_tree_host_->StackAtTop();
725 }
726
727 void DesktopNativeWidgetAura::StackBelow(gfx::NativeView native_view) {
728 }
729
730 void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) {
731   if (content_window_)
732     desktop_window_tree_host_->SetShape(shape);
733 }
734
735 void DesktopNativeWidgetAura::Close() {
736   if (!content_window_)
737     return;
738
739   content_window_->SuppressPaint();
740   content_window_->Hide();
741
742   desktop_window_tree_host_->Close();
743 }
744
745 void DesktopNativeWidgetAura::CloseNow() {
746   if (content_window_)
747     desktop_window_tree_host_->CloseNow();
748 }
749
750 void DesktopNativeWidgetAura::Show() {
751   if (!content_window_)
752     return;
753   desktop_window_tree_host_->AsWindowTreeHost()->Show();
754   content_window_->Show();
755 }
756
757 void DesktopNativeWidgetAura::Hide() {
758   if (!content_window_)
759     return;
760   desktop_window_tree_host_->AsWindowTreeHost()->Hide();
761   content_window_->Hide();
762 }
763
764 void DesktopNativeWidgetAura::ShowMaximizedWithBounds(
765       const gfx::Rect& restored_bounds) {
766   if (!content_window_)
767     return;
768   desktop_window_tree_host_->ShowMaximizedWithBounds(restored_bounds);
769   content_window_->Show();
770 }
771
772 void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) {
773   if (!content_window_)
774     return;
775   desktop_window_tree_host_->ShowWindowWithState(state);
776   content_window_->Show();
777 }
778
779 bool DesktopNativeWidgetAura::IsVisible() const {
780   return content_window_ && desktop_window_tree_host_->IsVisible();
781 }
782
783 void DesktopNativeWidgetAura::Activate() {
784   if (content_window_)
785     desktop_window_tree_host_->Activate();
786 }
787
788 void DesktopNativeWidgetAura::Deactivate() {
789   if (content_window_)
790     desktop_window_tree_host_->Deactivate();
791 }
792
793 bool DesktopNativeWidgetAura::IsActive() const {
794   return content_window_ && desktop_window_tree_host_->IsActive();
795 }
796
797 void DesktopNativeWidgetAura::SetAlwaysOnTop(bool always_on_top) {
798   if (content_window_)
799     desktop_window_tree_host_->SetAlwaysOnTop(always_on_top);
800 }
801
802 bool DesktopNativeWidgetAura::IsAlwaysOnTop() const {
803   return content_window_ && desktop_window_tree_host_->IsAlwaysOnTop();
804 }
805
806 void DesktopNativeWidgetAura::SetVisibleOnAllWorkspaces(bool always_visible) {
807   if (content_window_)
808     desktop_window_tree_host_->SetVisibleOnAllWorkspaces(always_visible);
809 }
810
811 void DesktopNativeWidgetAura::Maximize() {
812   if (content_window_)
813     desktop_window_tree_host_->Maximize();
814 }
815
816 void DesktopNativeWidgetAura::Minimize() {
817   if (content_window_)
818     desktop_window_tree_host_->Minimize();
819 }
820
821 bool DesktopNativeWidgetAura::IsMaximized() const {
822   return content_window_ && desktop_window_tree_host_->IsMaximized();
823 }
824
825 bool DesktopNativeWidgetAura::IsMinimized() const {
826   return content_window_ && desktop_window_tree_host_->IsMinimized();
827 }
828
829 void DesktopNativeWidgetAura::Restore() {
830   if (content_window_)
831     desktop_window_tree_host_->Restore();
832 }
833
834 void DesktopNativeWidgetAura::SetFullscreen(bool fullscreen) {
835   if (content_window_)
836     desktop_window_tree_host_->SetFullscreen(fullscreen);
837 }
838
839 bool DesktopNativeWidgetAura::IsFullscreen() const {
840   return content_window_ && desktop_window_tree_host_->IsFullscreen();
841 }
842
843 void DesktopNativeWidgetAura::SetOpacity(unsigned char opacity) {
844   if (content_window_)
845     desktop_window_tree_host_->SetOpacity(opacity);
846 }
847
848 void DesktopNativeWidgetAura::SetUseDragFrame(bool use_drag_frame) {
849 }
850
851 void DesktopNativeWidgetAura::FlashFrame(bool flash_frame) {
852   if (content_window_)
853     desktop_window_tree_host_->FlashFrame(flash_frame);
854 }
855
856 void DesktopNativeWidgetAura::RunShellDrag(
857     View* view,
858     const ui::OSExchangeData& data,
859     const gfx::Point& location,
860     int operation,
861     ui::DragDropTypes::DragEventSource source) {
862   views::RunShellDrag(content_window_, data, location, operation, source);
863 }
864
865 void DesktopNativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
866   if (content_window_)
867     content_window_->SchedulePaintInRect(rect);
868 }
869
870 void DesktopNativeWidgetAura::SetCursor(gfx::NativeCursor cursor) {
871   cursor_ = cursor;
872   aura::client::CursorClient* cursor_client =
873       aura::client::GetCursorClient(host_->window());
874   if (cursor_client)
875     cursor_client->SetCursor(cursor);
876 }
877
878 bool DesktopNativeWidgetAura::IsMouseEventsEnabled() const {
879   if (!content_window_)
880     return false;
881   aura::client::CursorClient* cursor_client =
882       aura::client::GetCursorClient(host_->window());
883   return cursor_client ? cursor_client->IsMouseEventsEnabled() : true;
884 }
885
886 void DesktopNativeWidgetAura::ClearNativeFocus() {
887   desktop_window_tree_host_->ClearNativeFocus();
888
889   if (ShouldActivate()) {
890     aura::client::GetFocusClient(content_window_)->
891         ResetFocusWithinActiveWindow(content_window_);
892   }
893 }
894
895 gfx::Rect DesktopNativeWidgetAura::GetWorkAreaBoundsInScreen() const {
896   return desktop_window_tree_host_ ?
897       desktop_window_tree_host_->GetWorkAreaBoundsInScreen() : gfx::Rect();
898 }
899
900 Widget::MoveLoopResult DesktopNativeWidgetAura::RunMoveLoop(
901     const gfx::Vector2d& drag_offset,
902     Widget::MoveLoopSource source,
903     Widget::MoveLoopEscapeBehavior escape_behavior) {
904   if (!content_window_)
905     return Widget::MOVE_LOOP_CANCELED;
906   return desktop_window_tree_host_->RunMoveLoop(drag_offset, source,
907                                                 escape_behavior);
908 }
909
910 void DesktopNativeWidgetAura::EndMoveLoop() {
911   if (content_window_)
912     desktop_window_tree_host_->EndMoveLoop();
913 }
914
915 void DesktopNativeWidgetAura::SetVisibilityChangedAnimationsEnabled(
916     bool value) {
917   if (content_window_)
918     desktop_window_tree_host_->SetVisibilityChangedAnimationsEnabled(value);
919 }
920
921 ui::NativeTheme* DesktopNativeWidgetAura::GetNativeTheme() const {
922   return DesktopWindowTreeHost::GetNativeTheme(content_window_);
923 }
924
925 void DesktopNativeWidgetAura::OnRootViewLayout() const {
926   if (content_window_)
927     desktop_window_tree_host_->OnRootViewLayout();
928 }
929
930 ////////////////////////////////////////////////////////////////////////////////
931 // DesktopNativeWidgetAura, aura::WindowDelegate implementation:
932
933 gfx::Size DesktopNativeWidgetAura::GetMinimumSize() const {
934   return native_widget_delegate_->GetMinimumSize();
935 }
936
937 gfx::Size DesktopNativeWidgetAura::GetMaximumSize() const {
938   return native_widget_delegate_->GetMaximumSize();
939 }
940
941 gfx::NativeCursor DesktopNativeWidgetAura::GetCursor(const gfx::Point& point) {
942   return cursor_;
943 }
944
945 int DesktopNativeWidgetAura::GetNonClientComponent(
946     const gfx::Point& point) const {
947   return native_widget_delegate_->GetNonClientComponent(point);
948 }
949
950 bool DesktopNativeWidgetAura::ShouldDescendIntoChildForEventHandling(
951       aura::Window* child,
952       const gfx::Point& location) {
953   views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate();
954   return !widget_delegate ||
955       widget_delegate->ShouldDescendIntoChildForEventHandling(child, location);
956 }
957
958 bool DesktopNativeWidgetAura::CanFocus() {
959   return true;
960 }
961
962 void DesktopNativeWidgetAura::OnCaptureLost() {
963   native_widget_delegate_->OnMouseCaptureLost();
964 }
965
966 void DesktopNativeWidgetAura::OnPaint(gfx::Canvas* canvas) {
967   native_widget_delegate_->OnNativeWidgetPaint(canvas);
968 }
969
970 void DesktopNativeWidgetAura::OnDeviceScaleFactorChanged(
971     float device_scale_factor) {
972 }
973
974 void DesktopNativeWidgetAura::OnWindowDestroying(aura::Window* window) {
975   // Cleanup happens in OnHostClosed().
976 }
977
978 void DesktopNativeWidgetAura::OnWindowDestroyed(aura::Window* window) {
979   // Cleanup happens in OnHostClosed(). We own |content_window_| (indirectly by
980   // way of |dispatcher_|) so there should be no need to do any processing
981   // here.
982 }
983
984 void DesktopNativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) {
985 }
986
987 bool DesktopNativeWidgetAura::HasHitTestMask() const {
988   return native_widget_delegate_->HasHitTestMask();
989 }
990
991 void DesktopNativeWidgetAura::GetHitTestMask(gfx::Path* mask) const {
992   native_widget_delegate_->GetHitTestMask(mask);
993 }
994
995 ////////////////////////////////////////////////////////////////////////////////
996 // DesktopNativeWidgetAura, ui::EventHandler implementation:
997
998 void DesktopNativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
999   if (event->is_char()) {
1000     // If a ui::InputMethod object is attached to the root window, character
1001     // events are handled inside the object and are not passed to this function.
1002     // If such object is not attached, character events might be sent (e.g. on
1003     // Windows). In this case, we just skip these.
1004     return;
1005   }
1006   // Renderer may send a key event back to us if the key event wasn't handled,
1007   // and the window may be invisible by that time.
1008   if (!content_window_->IsVisible())
1009     return;
1010
1011   native_widget_delegate_->OnKeyEvent(event);
1012   if (event->handled())
1013     return;
1014
1015   if (GetWidget()->HasFocusManager() &&
1016       !GetWidget()->GetFocusManager()->OnKeyEvent(*event))
1017     event->SetHandled();
1018 }
1019
1020 void DesktopNativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) {
1021   DCHECK(content_window_->IsVisible());
1022   if (tooltip_manager_.get())
1023     tooltip_manager_->UpdateTooltip();
1024   TooltipManagerAura::UpdateTooltipManagerForCapture(GetWidget());
1025   native_widget_delegate_->OnMouseEvent(event);
1026   // WARNING: we may have been deleted.
1027 }
1028
1029 void DesktopNativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) {
1030   if (event->type() == ui::ET_SCROLL) {
1031     native_widget_delegate_->OnScrollEvent(event);
1032     if (event->handled())
1033       return;
1034
1035     // Convert unprocessed scroll events into wheel events.
1036     ui::MouseWheelEvent mwe(*static_cast<ui::ScrollEvent*>(event));
1037     native_widget_delegate_->OnMouseEvent(&mwe);
1038     if (mwe.handled())
1039       event->SetHandled();
1040   } else {
1041     native_widget_delegate_->OnScrollEvent(event);
1042   }
1043 }
1044
1045 void DesktopNativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) {
1046   native_widget_delegate_->OnGestureEvent(event);
1047 }
1048
1049 ////////////////////////////////////////////////////////////////////////////////
1050 // DesktopNativeWidgetAura, aura::client::ActivationDelegate implementation:
1051
1052 bool DesktopNativeWidgetAura::ShouldActivate() const {
1053   return can_activate_ && native_widget_delegate_->CanActivate();
1054 }
1055
1056 ////////////////////////////////////////////////////////////////////////////////
1057 // DesktopNativeWidgetAura, aura::client::ActivationChangeObserver
1058 //    implementation:
1059
1060 void DesktopNativeWidgetAura::OnWindowActivated(aura::Window* gained_active,
1061                                                 aura::Window* lost_active) {
1062   DCHECK(content_window_ == gained_active || content_window_ == lost_active);
1063   if (gained_active == content_window_ && restore_focus_on_activate_) {
1064     restore_focus_on_activate_ = false;
1065     GetWidget()->GetFocusManager()->RestoreFocusedView();
1066   } else if (lost_active == content_window_ && GetWidget()->HasFocusManager()) {
1067     DCHECK(!restore_focus_on_activate_);
1068     restore_focus_on_activate_ = true;
1069     // Pass in false so that ClearNativeFocus() isn't invoked.
1070     GetWidget()->GetFocusManager()->StoreFocusedView(false);
1071   }
1072 }
1073
1074 ////////////////////////////////////////////////////////////////////////////////
1075 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation:
1076
1077 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
1078                                               aura::Window* lost_focus) {
1079   if (content_window_ == gained_focus) {
1080     desktop_window_tree_host_->OnNativeWidgetFocus();
1081     native_widget_delegate_->OnNativeFocus(lost_focus);
1082
1083     // If focus is moving from a descendant Window to |content_window_| then
1084     // native activation hasn't changed. We still need to inform the InputMethod
1085     // we've been focused though.
1086     InputMethod* input_method = GetWidget()->GetInputMethod();
1087     if (input_method)
1088       input_method->OnFocus();
1089   } else if (content_window_ == lost_focus) {
1090     desktop_window_tree_host_->OnNativeWidgetBlur();
1091     native_widget_delegate_->OnNativeBlur(
1092         aura::client::GetFocusClient(content_window_)->GetFocusedWindow());
1093   }
1094 }
1095
1096 ////////////////////////////////////////////////////////////////////////////////
1097 // DesktopNativeWidgetAura, views::internal::InputMethodDelegate:
1098
1099 void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
1100   FocusManager* focus_manager =
1101       native_widget_delegate_->AsWidget()->GetFocusManager();
1102   native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
1103   if (key.handled() || !focus_manager)
1104     return;
1105   focus_manager->OnKeyEvent(key);
1106 }
1107
1108 ////////////////////////////////////////////////////////////////////////////////
1109 // DesktopNativeWidgetAura, aura::WindowDragDropDelegate implementation:
1110
1111 void DesktopNativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) {
1112   DCHECK(drop_helper_.get() != NULL);
1113   last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
1114       event.location(), event.source_operations());
1115 }
1116
1117 int DesktopNativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) {
1118   DCHECK(drop_helper_.get() != NULL);
1119   last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
1120       event.location(), event.source_operations());
1121   return last_drop_operation_;
1122 }
1123
1124 void DesktopNativeWidgetAura::OnDragExited() {
1125   DCHECK(drop_helper_.get() != NULL);
1126   drop_helper_->OnDragExit();
1127 }
1128
1129 int DesktopNativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) {
1130   DCHECK(drop_helper_.get() != NULL);
1131   Activate();
1132   return drop_helper_->OnDrop(event.data(), event.location(),
1133       last_drop_operation_);
1134 }
1135
1136 ////////////////////////////////////////////////////////////////////////////////
1137 // DesktopNativeWidgetAura, aura::WindowTreeHostObserver implementation:
1138
1139 void DesktopNativeWidgetAura::OnHostCloseRequested(
1140     const aura::WindowTreeHost* host) {
1141   GetWidget()->Close();
1142 }
1143
1144 void DesktopNativeWidgetAura::OnHostResized(const aura::WindowTreeHost* host) {
1145   // Don't update the bounds of the child layers when animating closed. If we
1146   // did it would force a paint, which we don't want. We don't want the paint
1147   // as we can't assume any of the children are valid.
1148   if (desktop_window_tree_host_->IsAnimatingClosed())
1149     return;
1150
1151   gfx::Rect new_bounds = gfx::Rect(host->window()->bounds().size());
1152   content_window_->SetBounds(new_bounds);
1153   // Can be NULL at start.
1154   if (content_window_container_)
1155     content_window_container_->SetBounds(new_bounds);
1156   native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
1157 }
1158
1159 void DesktopNativeWidgetAura::OnHostMoved(const aura::WindowTreeHost* host,
1160                                           const gfx::Point& new_origin) {
1161   TRACE_EVENT1("views", "DesktopNativeWidgetAura::OnHostMoved",
1162                "new_origin", new_origin.ToString());
1163
1164   native_widget_delegate_->OnNativeWidgetMove();
1165 }
1166
1167 ////////////////////////////////////////////////////////////////////////////////
1168 // DesktopNativeWidgetAura, NativeWidget implementation:
1169
1170 ui::EventHandler* DesktopNativeWidgetAura::GetEventHandler() {
1171   return this;
1172 }
1173
1174 void DesktopNativeWidgetAura::InstallInputMethodEventFilter() {
1175   DCHECK(!input_method_event_filter_.get());
1176
1177   input_method_event_filter_.reset(new wm::InputMethodEventFilter(
1178       host_->GetAcceleratedWidget()));
1179   input_method_event_filter_->SetInputMethodPropertyInRootWindow(
1180       host_->window());
1181   root_window_event_filter_->AddHandler(input_method_event_filter_.get());
1182 }
1183
1184 void DesktopNativeWidgetAura::UpdateWindowTransparency() {
1185   content_window_->SetTransparent(
1186       desktop_window_tree_host_->ShouldWindowContentsBeTransparent());
1187   // Regardless of transparency or not, this root content window will always
1188   // fill its bounds completely, so set this flag to true to avoid an
1189   // unecessary clear before update.
1190   content_window_->SetFillsBoundsCompletely(true);
1191 }
1192
1193 void DesktopNativeWidgetAura::RootWindowDestroyed() {
1194   cursor_reference_count_--;
1195   if (cursor_reference_count_ == 0) {
1196     // We are the last DesktopNativeWidgetAura instance, and we are responsible
1197     // for cleaning up |cursor_manager_|.
1198     delete cursor_manager_;
1199     native_cursor_manager_ = NULL;
1200     cursor_manager_ = NULL;
1201   }
1202 }
1203
1204 }  // namespace views