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

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: add animation_host.* 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);
167 aura::client::SetAnimationHost(window_, this);
164 aura::client::SetFocusChangeObserver(window_, this); 168 aura::client::SetFocusChangeObserver(window_, this);
165 aura::client::SetActivationChangeObserver(window_, this); 169 aura::client::SetActivationChangeObserver(window_, this);
166 } 170 }
167 171
168 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() { 172 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() {
169 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 173 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
170 delete native_widget_delegate_; 174 delete native_widget_delegate_;
171 else 175 else
172 CloseNow(); 176 CloseNow();
173 177
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 216
213 void DesktopNativeWidgetAura::InitNativeWidget( 217 void DesktopNativeWidgetAura::InitNativeWidget(
214 const Widget::InitParams& params) { 218 const Widget::InitParams& params) {
215 ownership_ = params.ownership; 219 ownership_ = params.ownership;
216 220
217 window_->set_user_data(this); 221 window_->set_user_data(this);
218 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); 222 window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
219 window_->SetTransparent(true); 223 window_->SetTransparent(true);
220 window_->Init(params.layer_type); 224 window_->Init(params.layer_type);
221 corewm::SetShadowType(window_, corewm::SHADOW_TYPE_NONE); 225 corewm::SetShadowType(window_, corewm::SHADOW_TYPE_NONE);
222 window_->Show();
223 226
224 desktop_root_window_host_ = params.desktop_root_window_host ? 227 desktop_root_window_host_ = params.desktop_root_window_host ?
225 params.desktop_root_window_host : 228 params.desktop_root_window_host :
226 DesktopRootWindowHost::Create(native_widget_delegate_, 229 DesktopRootWindowHost::Create(native_widget_delegate_,
227 this, params.bounds); 230 this, params.bounds);
228 root_window_.reset( 231 root_window_.reset(
229 desktop_root_window_host_->Init(window_, params)); 232 desktop_root_window_host_->Init(window_, params));
230 stacking_client_.reset( 233 stacking_client_.reset(
231 new DesktopNativeWidgetAuraStackingClient(root_window_.get())); 234 new DesktopNativeWidgetAuraStackingClient(root_window_.get()));
232 drop_helper_.reset(new DropHelper( 235 drop_helper_.reset(new DropHelper(
233 static_cast<internal::RootView*>(GetWidget()->GetRootView()))); 236 static_cast<internal::RootView*>(GetWidget()->GetRootView())));
234 aura::client::SetDragDropDelegate(window_, this); 237 aura::client::SetDragDropDelegate(window_, this);
235 238
236 tooltip_manager_.reset(new views::TooltipManagerAura(window_, GetWidget())); 239 tooltip_manager_.reset(new views::TooltipManagerAura(window_, GetWidget()));
237 tooltip_controller_.reset( 240 tooltip_controller_.reset(
238 new corewm::TooltipController(gfx::SCREEN_TYPE_NATIVE)); 241 new corewm::TooltipController(gfx::SCREEN_TYPE_NATIVE));
239 aura::client::SetTooltipClient(root_window_.get(), 242 aura::client::SetTooltipClient(root_window_.get(),
240 tooltip_controller_.get()); 243 tooltip_controller_.get());
241 root_window_->AddPreTargetHandler(tooltip_controller_.get()); 244 root_window_->AddPreTargetHandler(tooltip_controller_.get());
242 245
246 if (params.type != Widget::InitParams::TYPE_WINDOW) {
247 visibility_controller_.reset(new views::corewm::VisibilityController);
248 aura::client::SetVisibilityClient(GetNativeView()->GetRootWindow(),
249 visibility_controller_.get());
250 views::corewm::SetChildWindowVisibilityChangesAnimated(
251 GetNativeView()->GetRootWindow());
252 }
253 window_->Show();
254 desktop_root_window_host_->InitFocus(window_);
255
243 aura::client::SetActivationDelegate(window_, this); 256 aura::client::SetActivationDelegate(window_, this);
244 257
245 shadow_controller_.reset( 258 shadow_controller_.reset(
246 new corewm::ShadowController( 259 new corewm::ShadowController(
247 aura::client::GetActivationClient(root_window_.get()))); 260 aura::client::GetActivationClient(root_window_.get())));
248 } 261 }
249 262
250 NonClientFrameView* DesktopNativeWidgetAura::CreateNonClientFrameView() { 263 NonClientFrameView* DesktopNativeWidgetAura::CreateNonClientFrameView() {
251 return desktop_root_window_host_->CreateNonClientFrameView(); 264 return desktop_root_window_host_->CreateNonClientFrameView();
252 } 265 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 } 407 }
395 408
396 void DesktopNativeWidgetAura::StackBelow(gfx::NativeView native_view) { 409 void DesktopNativeWidgetAura::StackBelow(gfx::NativeView native_view) {
397 } 410 }
398 411
399 void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) { 412 void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) {
400 desktop_root_window_host_->SetShape(shape); 413 desktop_root_window_host_->SetShape(shape);
401 } 414 }
402 415
403 void DesktopNativeWidgetAura::Close() { 416 void DesktopNativeWidgetAura::Close() {
404 desktop_root_window_host_->Close(); 417 if (window_) {
405 if (window_)
406 window_->SuppressPaint(); 418 window_->SuppressPaint();
419 if (window_->type() == aura::client::WINDOW_TYPE_NORMAL ||
420 views::corewm::WindowAnimationsDisabled(window_)) {
421 desktop_root_window_host_->Close();
422 } else {
423 pending_close_ = true;
sky 2013/03/18 15:49:42 Do you end up in this code path on linux?
424 Hide(); // OnWindowHidingAnimationCompleted does the actual Close.
425 }
426 }
407 } 427 }
408 428
409 void DesktopNativeWidgetAura::CloseNow() { 429 void DesktopNativeWidgetAura::CloseNow() {
410 desktop_root_window_host_->CloseNow(); 430 desktop_root_window_host_->CloseNow();
411 } 431 }
412 432
413 void DesktopNativeWidgetAura::Show() { 433 void DesktopNativeWidgetAura::Show() {
414 desktop_root_window_host_->AsRootWindowHost()->Show(); 434 desktop_root_window_host_->AsRootWindowHost()->Show();
415 window_->Show(); 435 window_->Show();
416 } 436 }
417 437
418 void DesktopNativeWidgetAura::Hide() { 438 void DesktopNativeWidgetAura::Hide() {
419 desktop_root_window_host_->AsRootWindowHost()->Hide(); 439 if (!pending_close_)
440 desktop_root_window_host_->AsRootWindowHost()->Hide();
420 if (window_) 441 if (window_)
421 window_->Hide(); 442 window_->Hide();
422 } 443 }
423 444
424 void DesktopNativeWidgetAura::ShowMaximizedWithBounds( 445 void DesktopNativeWidgetAura::ShowMaximizedWithBounds(
425 const gfx::Rect& restored_bounds) { 446 const gfx::Rect& restored_bounds) {
426 desktop_root_window_host_->ShowMaximizedWithBounds(restored_bounds); 447 desktop_root_window_host_->ShowMaximizedWithBounds(restored_bounds);
427 } 448 }
428 449
429 void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { 450 void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 649 }
629 650
630 scoped_refptr<ui::Texture> DesktopNativeWidgetAura::CopyTexture() { 651 scoped_refptr<ui::Texture> DesktopNativeWidgetAura::CopyTexture() {
631 // The layer we create doesn't have an external texture, so this should never 652 // The layer we create doesn't have an external texture, so this should never
632 // get invoked. 653 // get invoked.
633 NOTREACHED(); 654 NOTREACHED();
634 return scoped_refptr<ui::Texture>(); 655 return scoped_refptr<ui::Texture>();
635 } 656 }
636 657
637 //////////////////////////////////////////////////////////////////////////////// 658 ////////////////////////////////////////////////////////////////////////////////
659 // DesktopNativeWidgetAura, aura::WindowAnimationHost implementation:
660
661 void DesktopNativeWidgetAura::SetHostTransitionBounds(const gfx::Rect& bounds) {
sky 2013/03/18 15:49:42 If this is only applicable to windows, should we i
scottmg 2013/03/18 21:47:48 Ah, that seems better, removes all the empty/NOTIM
662 desktop_root_window_host_->AsRootWindowHost()->SetHostWindowExpansion(bounds);
663 }
664
665 void DesktopNativeWidgetAura::OnWindowHidingAnimationCompleted() {
666 if (pending_close_)
667 desktop_root_window_host_->Close();
668 }
669
670 ////////////////////////////////////////////////////////////////////////////////
638 // DesktopNativeWidgetAura, ui::EventHandler implementation: 671 // DesktopNativeWidgetAura, ui::EventHandler implementation:
639 672
640 void DesktopNativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { 673 void DesktopNativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
641 if (event->is_char()) { 674 if (event->is_char()) {
642 // If a ui::InputMethod object is attached to the root window, character 675 // If a ui::InputMethod object is attached to the root window, character
643 // events are handled inside the object and are not passed to this function. 676 // events are handled inside the object and are not passed to this function.
644 // If such object is not attached, character events might be sent (e.g. on 677 // If such object is not attached, character events might be sent (e.g. on
645 // Windows). In this case, we just skip these. 678 // Windows). In this case, we just skip these.
646 return; 679 return;
647 } 680 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 drop_helper_->OnDragExit(); 826 drop_helper_->OnDragExit();
794 } 827 }
795 828
796 int DesktopNativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { 829 int DesktopNativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) {
797 DCHECK(drop_helper_.get() != NULL); 830 DCHECK(drop_helper_.get() != NULL);
798 return drop_helper_->OnDrop(event.data(), event.location(), 831 return drop_helper_->OnDrop(event.data(), event.location(),
799 last_drop_operation_); 832 last_drop_operation_);
800 } 833 }
801 834
802 } // namespace views 835 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698