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

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

Issue 12342028: make menus, bubbles, etc. top level windows on aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixes Created 7 years, 9 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/stacking_client.h" 10 #include "ui/aura/client/stacking_client.h"
11 #include "ui/aura/focus_manager.h" 11 #include "ui/aura/focus_manager.h"
12 #include "ui/aura/root_window.h" 12 #include "ui/aura/root_window.h"
13 #include "ui/aura/root_window_host.h" 13 #include "ui/aura/root_window_host.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/aura/window_observer.h" 15 #include "ui/aura/window_observer.h"
16 #include "ui/aura/window_property.h" 16 #include "ui/aura/window_property.h"
17 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
18 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
19 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/native_theme/native_theme.h" 20 #include "ui/native_theme/native_theme.h"
21 #include "ui/views/corewm/compound_event_filter.h" 21 #include "ui/views/corewm/compound_event_filter.h"
22 #include "ui/views/corewm/corewm_switches.h" 22 #include "ui/views/corewm/corewm_switches.h"
23 #include "ui/views/corewm/input_method_event_filter.h" 23 #include "ui/views/corewm/input_method_event_filter.h"
24 #include "ui/views/corewm/shadow_controller.h" 24 #include "ui/views/corewm/shadow_controller.h"
25 #include "ui/views/corewm/shadow_types.h" 25 #include "ui/views/corewm/shadow_types.h"
26 #include "ui/views/corewm/tooltip_controller.h" 26 #include "ui/views/corewm/tooltip_controller.h"
27 #include "ui/views/corewm/visibility_controller.h"
28 #include "ui/views/corewm/window_animations.h"
27 #include "ui/views/drag_utils.h" 29 #include "ui/views/drag_utils.h"
28 #include "ui/views/ime/input_method.h" 30 #include "ui/views/ime/input_method.h"
29 #include "ui/views/ime/input_method_bridge.h" 31 #include "ui/views/ime/input_method_bridge.h"
30 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h" 32 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h"
31 #include "ui/views/widget/drop_helper.h" 33 #include "ui/views/widget/drop_helper.h"
32 #include "ui/views/widget/native_widget_aura_window_observer.h" 34 #include "ui/views/widget/native_widget_aura_window_observer.h"
33 #include "ui/views/widget/root_view.h" 35 #include "ui/views/widget/root_view.h"
34 #include "ui/views/widget/tooltip_manager_aura.h" 36 #include "ui/views/widget/tooltip_manager_aura.h"
35 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
36 #include "ui/views/widget/widget_aura_utils.h" 38 #include "ui/views/widget/widget_aura_utils.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 154
153 DesktopNativeWidgetAura::DesktopNativeWidgetAura( 155 DesktopNativeWidgetAura::DesktopNativeWidgetAura(
154 internal::NativeWidgetDelegate* delegate) 156 internal::NativeWidgetDelegate* delegate)
155 : ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 157 : ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
156 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), 158 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
157 can_activate_(true), 159 can_activate_(true),
158 desktop_root_window_host_(NULL), 160 desktop_root_window_host_(NULL),
159 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 161 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
160 native_widget_delegate_(delegate), 162 native_widget_delegate_(delegate),
161 last_drop_operation_(ui::DragDropTypes::DRAG_NONE), 163 last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
162 restore_focus_on_activate_(false) { 164 restore_focus_on_activate_(false),
165 pending_close_(false) {
163 window_->SetProperty(kDesktopNativeWidgetAuraKey, this); 166 window_->SetProperty(kDesktopNativeWidgetAuraKey, this);
164 aura::client::SetFocusChangeObserver(window_, this); 167 aura::client::SetFocusChangeObserver(window_, this);
165 aura::client::SetActivationChangeObserver(window_, this); 168 aura::client::SetActivationChangeObserver(window_, this);
166 } 169 }
167 170
168 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() { 171 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() {
169 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 172 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
170 delete native_widget_delegate_; 173 delete native_widget_delegate_;
171 else 174 else
172 CloseNow(); 175 CloseNow();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 215
213 void DesktopNativeWidgetAura::InitNativeWidget( 216 void DesktopNativeWidgetAura::InitNativeWidget(
214 const Widget::InitParams& params) { 217 const Widget::InitParams& params) {
215 ownership_ = params.ownership; 218 ownership_ = params.ownership;
216 219
217 window_->set_user_data(this); 220 window_->set_user_data(this);
218 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); 221 window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
219 window_->SetTransparent(true); 222 window_->SetTransparent(true);
220 window_->Init(params.layer_type); 223 window_->Init(params.layer_type);
221 corewm::SetShadowType(window_, corewm::SHADOW_TYPE_NONE); 224 corewm::SetShadowType(window_, corewm::SHADOW_TYPE_NONE);
222 window_->Show();
223 225
224 desktop_root_window_host_ = params.desktop_root_window_host ? 226 desktop_root_window_host_ = params.desktop_root_window_host ?
225 params.desktop_root_window_host : 227 params.desktop_root_window_host :
226 DesktopRootWindowHost::Create(native_widget_delegate_, 228 DesktopRootWindowHost::Create(native_widget_delegate_,
227 this, params.bounds); 229 this, params.bounds);
228 root_window_.reset( 230 root_window_.reset(
229 desktop_root_window_host_->Init(window_, params)); 231 desktop_root_window_host_->Init(window_, params));
230 stacking_client_.reset( 232 stacking_client_.reset(
231 new DesktopNativeWidgetAuraStackingClient(root_window_.get())); 233 new DesktopNativeWidgetAuraStackingClient(root_window_.get()));
232 drop_helper_.reset(new DropHelper( 234 drop_helper_.reset(new DropHelper(
233 static_cast<internal::RootView*>(GetWidget()->GetRootView()))); 235 static_cast<internal::RootView*>(GetWidget()->GetRootView())));
234 aura::client::SetDragDropDelegate(window_, this); 236 aura::client::SetDragDropDelegate(window_, this);
235 237
236 tooltip_manager_.reset(new views::TooltipManagerAura(window_, GetWidget())); 238 tooltip_manager_.reset(new views::TooltipManagerAura(window_, GetWidget()));
237 tooltip_controller_.reset( 239 tooltip_controller_.reset(
238 new corewm::TooltipController(gfx::SCREEN_TYPE_NATIVE)); 240 new corewm::TooltipController(gfx::SCREEN_TYPE_NATIVE));
239 aura::client::SetTooltipClient(root_window_.get(), 241 aura::client::SetTooltipClient(root_window_.get(),
240 tooltip_controller_.get()); 242 tooltip_controller_.get());
241 root_window_->AddPreTargetHandler(tooltip_controller_.get()); 243 root_window_->AddPreTargetHandler(tooltip_controller_.get());
242 244
245 if (params.type != Widget::InitParams::TYPE_WINDOW) {
246 visibility_controller_.reset(new views::corewm::VisibilityController);
247 aura::client::SetVisibilityClient(GetNativeView()->GetRootWindow(),
248 visibility_controller_.get());
249 views::corewm::SetChildWindowVisibilityChangesAnimated(
250 GetNativeView()->GetRootWindow());
251 }
252 window_->Show();
253 desktop_root_window_host_->InitFocus(window_);
sky 2013/03/15 03:15:05 What is the focus needed for?
scottmg 2013/03/15 22:23:46 The window_->Show has to be deferred until after t
254
243 aura::client::SetActivationDelegate(window_, this); 255 aura::client::SetActivationDelegate(window_, this);
244 256
245 shadow_controller_.reset( 257 shadow_controller_.reset(
246 new corewm::ShadowController( 258 new corewm::ShadowController(
247 aura::client::GetActivationClient(root_window_.get()))); 259 aura::client::GetActivationClient(root_window_.get())));
248 } 260 }
249 261
250 NonClientFrameView* DesktopNativeWidgetAura::CreateNonClientFrameView() { 262 NonClientFrameView* DesktopNativeWidgetAura::CreateNonClientFrameView() {
251 return desktop_root_window_host_->CreateNonClientFrameView(); 263 return desktop_root_window_host_->CreateNonClientFrameView();
252 } 264 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 } 406 }
395 407
396 void DesktopNativeWidgetAura::StackBelow(gfx::NativeView native_view) { 408 void DesktopNativeWidgetAura::StackBelow(gfx::NativeView native_view) {
397 } 409 }
398 410
399 void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) { 411 void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) {
400 desktop_root_window_host_->SetShape(shape); 412 desktop_root_window_host_->SetShape(shape);
401 } 413 }
402 414
403 void DesktopNativeWidgetAura::Close() { 415 void DesktopNativeWidgetAura::Close() {
404 desktop_root_window_host_->Close(); 416 if (window_) {
405 if (window_)
406 window_->SuppressPaint(); 417 window_->SuppressPaint();
418 if (window_->type() == aura::client::WINDOW_TYPE_NORMAL ||
419 views::corewm::WindowAnimationsDisabled(window_)) {
420 desktop_root_window_host_->Close();
421 } else {
422 pending_close_ = true;
423 Hide(); // OnWindowHidingAnimationCompleted does the actual Close.
424 }
425 }
407 } 426 }
408 427
409 void DesktopNativeWidgetAura::CloseNow() { 428 void DesktopNativeWidgetAura::CloseNow() {
410 desktop_root_window_host_->CloseNow(); 429 desktop_root_window_host_->CloseNow();
411 } 430 }
412 431
413 void DesktopNativeWidgetAura::Show() { 432 void DesktopNativeWidgetAura::Show() {
414 desktop_root_window_host_->AsRootWindowHost()->Show(); 433 desktop_root_window_host_->AsRootWindowHost()->Show();
415 window_->Show(); 434 window_->Show();
416 } 435 }
417 436
418 void DesktopNativeWidgetAura::Hide() { 437 void DesktopNativeWidgetAura::Hide() {
419 desktop_root_window_host_->AsRootWindowHost()->Hide(); 438 if (!pending_close_)
sky 2013/03/15 03:15:05 Ugh, this also means if you Hide() a window then a
scottmg 2013/03/15 22:23:46 I believe Hide() still works as before (or that's
439 desktop_root_window_host_->AsRootWindowHost()->Hide();
420 if (window_) 440 if (window_)
421 window_->Hide(); 441 window_->Hide();
422 } 442 }
423 443
424 void DesktopNativeWidgetAura::ShowMaximizedWithBounds( 444 void DesktopNativeWidgetAura::ShowMaximizedWithBounds(
425 const gfx::Rect& restored_bounds) { 445 const gfx::Rect& restored_bounds) {
426 desktop_root_window_host_->ShowMaximizedWithBounds(restored_bounds); 446 desktop_root_window_host_->ShowMaximizedWithBounds(restored_bounds);
427 } 447 }
428 448
429 void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { 449 void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 // DesktopNativeWidgetAura, aura::WindowDelegate implementation: 568 // DesktopNativeWidgetAura, aura::WindowDelegate implementation:
549 569
550 gfx::Size DesktopNativeWidgetAura::GetMinimumSize() const { 570 gfx::Size DesktopNativeWidgetAura::GetMinimumSize() const {
551 return native_widget_delegate_->GetMinimumSize(); 571 return native_widget_delegate_->GetMinimumSize();
552 } 572 }
553 573
554 gfx::Size DesktopNativeWidgetAura::GetMaximumSize() const { 574 gfx::Size DesktopNativeWidgetAura::GetMaximumSize() const {
555 return native_widget_delegate_->GetMaximumSize(); 575 return native_widget_delegate_->GetMaximumSize();
556 } 576 }
557 577
578 void DesktopNativeWidgetAura::SetHostTransitionBounds(const gfx::Rect& bounds) {
579 desktop_root_window_host_->AsRootWindowHost()->SetHostWindowExpansion(bounds);
580 }
581
558 void DesktopNativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, 582 void DesktopNativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds,
559 const gfx::Rect& new_bounds) { 583 const gfx::Rect& new_bounds) {
560 if (old_bounds.origin() != new_bounds.origin()) 584 if (old_bounds.origin() != new_bounds.origin())
561 native_widget_delegate_->OnNativeWidgetMove(); 585 native_widget_delegate_->OnNativeWidgetMove();
562 if (old_bounds.size() != new_bounds.size()) 586 if (old_bounds.size() != new_bounds.size())
563 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); 587 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
564 } 588 }
565 589
566 gfx::NativeCursor DesktopNativeWidgetAura::GetCursor(const gfx::Point& point) { 590 gfx::NativeCursor DesktopNativeWidgetAura::GetCursor(const gfx::Point& point) {
567 return gfx::kNullCursor; 591 return gfx::kNullCursor;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 633 }
610 } 634 }
611 635
612 void DesktopNativeWidgetAura::OnWindowDestroyed() { 636 void DesktopNativeWidgetAura::OnWindowDestroyed() {
613 window_ = NULL; 637 window_ = NULL;
614 native_widget_delegate_->OnNativeWidgetDestroyed(); 638 native_widget_delegate_->OnNativeWidgetDestroyed();
615 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 639 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
616 delete this; 640 delete this;
617 } 641 }
618 642
643 void DesktopNativeWidgetAura::OnWindowHidingAnimationCompleted() {
644 if (pending_close_)
645 desktop_root_window_host_->Close();
646 }
647
619 void DesktopNativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) { 648 void DesktopNativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) {
620 } 649 }
621 650
622 bool DesktopNativeWidgetAura::HasHitTestMask() const { 651 bool DesktopNativeWidgetAura::HasHitTestMask() const {
623 return native_widget_delegate_->HasHitTestMask(); 652 return native_widget_delegate_->HasHitTestMask();
624 } 653 }
625 654
626 void DesktopNativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { 655 void DesktopNativeWidgetAura::GetHitTestMask(gfx::Path* mask) const {
627 native_widget_delegate_->GetHitTestMask(mask); 656 native_widget_delegate_->GetHitTestMask(mask);
628 } 657 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 drop_helper_->OnDragExit(); 822 drop_helper_->OnDragExit();
794 } 823 }
795 824
796 int DesktopNativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { 825 int DesktopNativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) {
797 DCHECK(drop_helper_.get() != NULL); 826 DCHECK(drop_helper_.get() != NULL);
798 return drop_helper_->OnDrop(event.data(), event.location(), 827 return drop_helper_->OnDrop(event.data(), event.location(),
799 last_drop_operation_); 828 last_drop_operation_);
800 } 829 }
801 830
802 } // namespace views 831 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698