OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "ui/aura/client/activation_client.h" | |
10 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/client/drag_drop_client.h" | 10 #include "ui/aura/client/drag_drop_client.h" |
12 #include "ui/aura/client/shadow_types.h" | 11 #include "ui/aura/client/shadow_types.h" |
13 #include "ui/aura/event.h" | 12 #include "ui/aura/event.h" |
14 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/root_window_observer.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/aura/window_observer.h" | |
17 #include "ui/aura/window_types.h" | 16 #include "ui/aura/window_types.h" |
18 #include "ui/base/dragdrop/os_exchange_data.h" | 17 #include "ui/base/dragdrop/os_exchange_data.h" |
19 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
20 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/compositor/layer.h" | 20 #include "ui/gfx/compositor/layer.h" |
22 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
23 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
24 #include "ui/views/widget/drop_helper.h" | 23 #include "ui/views/widget/drop_helper.h" |
25 #include "ui/views/widget/native_widget_delegate.h" | 24 #include "ui/views/widget/native_widget_delegate.h" |
26 #include "ui/views/widget/tooltip_manager_aura.h" | 25 #include "ui/views/widget/tooltip_manager_aura.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 for (aura::Window::Windows::const_iterator it = children.begin(); | 69 for (aura::Window::Windows::const_iterator it = children.begin(); |
71 it != children.end(); ++it) { | 70 it != children.end(); ++it) { |
72 NotifyLocaleChangedInternal(*it); | 71 NotifyLocaleChangedInternal(*it); |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 } // namespace | 75 } // namespace |
77 | 76 |
78 // Used when SetInactiveRenderingDisabled() is invoked to track when active | 77 // Used when SetInactiveRenderingDisabled() is invoked to track when active |
79 // status changes in such a way that we should enable inactive rendering. | 78 // status changes in such a way that we should enable inactive rendering. |
80 class NativeWidgetAura::ActiveWindowObserver : public aura::WindowObserver { | 79 class NativeWidgetAura::RootWindowObserverImpl |
| 80 : public aura::RootWindowObserver { |
81 public: | 81 public: |
82 explicit ActiveWindowObserver(NativeWidgetAura* host) : host_(host) { | 82 explicit RootWindowObserverImpl(NativeWidgetAura* host) |
| 83 : host_(host) { |
83 aura::RootWindow::GetInstance()->AddObserver(this); | 84 aura::RootWindow::GetInstance()->AddObserver(this); |
84 } | 85 } |
85 virtual ~ActiveWindowObserver() { | 86 |
| 87 virtual ~RootWindowObserverImpl() { |
86 aura::RootWindow::GetInstance()->RemoveObserver(this); | 88 aura::RootWindow::GetInstance()->RemoveObserver(this); |
87 } | 89 } |
88 | 90 |
89 // Overridden from aura::WindowObserver: | 91 // RootWindowObserver overrides: |
90 virtual void OnWindowPropertyChanged(aura::Window* window, | 92 virtual void OnActiveWindowChanged(aura::Window* active) OVERRIDE { |
91 const char* key, | |
92 void* old) OVERRIDE { | |
93 if (key != aura::kRootWindowActiveWindow) | |
94 return; | |
95 aura::Window* active = | |
96 aura::ActivationClient::GetActivationClient()->GetActiveWindow(); | |
97 if (!active || (active != host_->window_ && | 93 if (!active || (active != host_->window_ && |
98 active->transient_parent() != host_->window_)) { | 94 active->transient_parent() != host_->window_)) { |
99 host_->delegate_->EnableInactiveRendering(); | 95 host_->delegate_->EnableInactiveRendering(); |
100 } | 96 } |
101 } | 97 } |
102 | 98 |
103 private: | 99 private: |
104 NativeWidgetAura* host_; | 100 NativeWidgetAura* host_; |
105 | 101 |
106 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); | 102 DISALLOW_COPY_AND_ASSIGN(RootWindowObserverImpl); |
107 }; | 103 }; |
108 | 104 |
109 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
110 // NativeWidgetAura, public: | 106 // NativeWidgetAura, public: |
111 | 107 |
112 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | 108 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) |
113 : delegate_(delegate), | 109 : delegate_(delegate), |
114 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 110 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
115 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 111 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
116 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 112 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 tooltip_manager_.reset(new views::TooltipManagerAura(this)); | 174 tooltip_manager_.reset(new views::TooltipManagerAura(this)); |
179 } | 175 } |
180 | 176 |
181 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | 177 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); |
182 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | 178 if (params.type != Widget::InitParams::TYPE_TOOLTIP && |
183 params.type != Widget::InitParams::TYPE_POPUP) { | 179 params.type != Widget::InitParams::TYPE_POPUP) { |
184 window_->SetProperty(aura::kDragDropDelegateKey, | 180 window_->SetProperty(aura::kDragDropDelegateKey, |
185 static_cast<aura::WindowDragDropDelegate*>(this)); | 181 static_cast<aura::WindowDragDropDelegate*>(this)); |
186 } | 182 } |
187 | 183 |
188 aura::ActivationDelegate::SetActivationDelegate(window_, this); | |
189 | |
190 if (window_type == Widget::InitParams::TYPE_MENU || | 184 if (window_type == Widget::InitParams::TYPE_MENU || |
191 window_type == Widget::InitParams::TYPE_TOOLTIP) | 185 window_type == Widget::InitParams::TYPE_TOOLTIP) |
192 window_->SetIntProperty(aura::kShadowTypeKey, | 186 window_->SetIntProperty(aura::kShadowTypeKey, |
193 aura::SHADOW_TYPE_RECTANGULAR); | 187 aura::SHADOW_TYPE_RECTANGULAR); |
194 } | 188 } |
195 | 189 |
196 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { | 190 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { |
197 return NULL; | 191 return NULL; |
198 } | 192 } |
199 | 193 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } | 418 } |
425 | 419 |
426 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { | 420 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { |
427 if (state == ui::SHOW_STATE_MAXIMIZED || | 421 if (state == ui::SHOW_STATE_MAXIMIZED || |
428 state == ui::SHOW_STATE_FULLSCREEN) { | 422 state == ui::SHOW_STATE_FULLSCREEN) { |
429 window_->SetIntProperty(aura::kShowStateKey, state); | 423 window_->SetIntProperty(aura::kShowStateKey, state); |
430 } | 424 } |
431 window_->Show(); | 425 window_->Show(); |
432 if (can_activate_ && (state != ui::SHOW_STATE_INACTIVE || | 426 if (can_activate_ && (state != ui::SHOW_STATE_INACTIVE || |
433 !GetWidget()->SetInitialFocus())) { | 427 !GetWidget()->SetInitialFocus())) { |
434 Activate(); | 428 window_->Activate(); |
435 } | 429 } |
436 } | 430 } |
437 | 431 |
438 bool NativeWidgetAura::IsVisible() const { | 432 bool NativeWidgetAura::IsVisible() const { |
439 return window_->IsVisible(); | 433 return window_->IsVisible(); |
440 } | 434 } |
441 | 435 |
442 void NativeWidgetAura::Activate() { | 436 void NativeWidgetAura::Activate() { |
443 aura::ActivationClient::GetActivationClient()->ActivateWindow(window_); | 437 window_->Activate(); |
444 } | 438 } |
445 | 439 |
446 void NativeWidgetAura::Deactivate() { | 440 void NativeWidgetAura::Deactivate() { |
447 aura::ActivationClient::GetActivationClient()->DeactivateWindow(window_); | 441 window_->Deactivate(); |
448 } | 442 } |
449 | 443 |
450 bool NativeWidgetAura::IsActive() const { | 444 bool NativeWidgetAura::IsActive() const { |
451 return aura::ActivationClient::GetActivationClient()->GetActiveWindow() == | 445 return aura::RootWindow::GetInstance()->active_window() == window_; |
452 window_; | |
453 } | 446 } |
454 | 447 |
455 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { | 448 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { |
456 window_->SetIntProperty(aura::kAlwaysOnTopKey, on_top); | 449 window_->SetIntProperty(aura::kAlwaysOnTopKey, on_top); |
457 } | 450 } |
458 | 451 |
459 void NativeWidgetAura::Maximize() { | 452 void NativeWidgetAura::Maximize() { |
460 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 453 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
461 } | 454 } |
462 | 455 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { | 525 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { |
533 window_->GetFocusManager()->SetFocusedWindow(native_view); | 526 window_->GetFocusManager()->SetFocusedWindow(native_view); |
534 } | 527 } |
535 | 528 |
536 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { | 529 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { |
537 return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); | 530 return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); |
538 } | 531 } |
539 | 532 |
540 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { | 533 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { |
541 if (!value) | 534 if (!value) |
542 active_window_observer_.reset(); | 535 root_window_observer_.reset(); |
543 else | 536 else |
544 active_window_observer_.reset(new ActiveWindowObserver(this)); | 537 root_window_observer_.reset(new RootWindowObserverImpl(this)); |
545 } | 538 } |
546 | 539 |
547 //////////////////////////////////////////////////////////////////////////////// | 540 //////////////////////////////////////////////////////////////////////////////// |
548 // NativeWidgetAura, views::InputMethodDelegate implementation: | 541 // NativeWidgetAura, views::InputMethodDelegate implementation: |
549 | 542 |
550 void NativeWidgetAura::DispatchKeyEventPostIME(const KeyEvent& key) { | 543 void NativeWidgetAura::DispatchKeyEventPostIME(const KeyEvent& key) { |
551 if (delegate_->OnKeyEvent(key)) | 544 if (delegate_->OnKeyEvent(key)) |
552 return; | 545 return; |
553 if (key.type() == ui::ET_KEY_PRESSED && GetWidget()->GetFocusManager()) | 546 if (key.type() == ui::ET_KEY_PRESSED && GetWidget()->GetFocusManager()) |
554 GetWidget()->GetFocusManager()->OnKeyEvent(key); | 547 GetWidget()->GetFocusManager()->OnKeyEvent(key); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) { | 622 ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) { |
630 DCHECK(window_->IsVisible()); | 623 DCHECK(window_->IsVisible()); |
631 TouchEvent touch_event(event); | 624 TouchEvent touch_event(event); |
632 return delegate_->OnTouchEvent(touch_event); | 625 return delegate_->OnTouchEvent(touch_event); |
633 } | 626 } |
634 | 627 |
635 bool NativeWidgetAura::CanFocus() { | 628 bool NativeWidgetAura::CanFocus() { |
636 return true; | 629 return true; |
637 } | 630 } |
638 | 631 |
| 632 bool NativeWidgetAura::ShouldActivate(aura::Event* event) { |
| 633 return can_activate_; |
| 634 } |
| 635 |
| 636 void NativeWidgetAura::OnActivated() { |
| 637 delegate_->OnNativeWidgetActivationChanged(true); |
| 638 if (IsVisible() && GetWidget()->non_client_view()) |
| 639 GetWidget()->non_client_view()->SchedulePaint(); |
| 640 } |
| 641 |
| 642 void NativeWidgetAura::OnLostActive() { |
| 643 delegate_->OnNativeWidgetActivationChanged(false); |
| 644 if (IsVisible() && GetWidget()->non_client_view()) |
| 645 GetWidget()->non_client_view()->SchedulePaint(); |
| 646 } |
| 647 |
639 void NativeWidgetAura::OnCaptureLost() { | 648 void NativeWidgetAura::OnCaptureLost() { |
640 delegate_->OnMouseCaptureLost(); | 649 delegate_->OnMouseCaptureLost(); |
641 } | 650 } |
642 | 651 |
643 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | 652 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { |
644 delegate_->OnNativeWidgetPaint(canvas); | 653 delegate_->OnNativeWidgetPaint(canvas); |
645 } | 654 } |
646 | 655 |
647 void NativeWidgetAura::OnWindowDestroying() { | 656 void NativeWidgetAura::OnWindowDestroying() { |
648 window_->SetProperty(aura::kDragDropDelegateKey, NULL); | 657 window_->SetProperty(aura::kDragDropDelegateKey, NULL); |
649 delegate_->OnNativeWidgetDestroying(); | 658 delegate_->OnNativeWidgetDestroying(); |
650 | 659 |
651 // If the aura::Window is destroyed, we can no longer show tooltips. | 660 // If the aura::Window is destroyed, we can no longer show tooltips. |
652 tooltip_manager_.reset(); | 661 tooltip_manager_.reset(); |
653 } | 662 } |
654 | 663 |
655 void NativeWidgetAura::OnWindowDestroyed() { | 664 void NativeWidgetAura::OnWindowDestroyed() { |
656 window_ = NULL; | 665 window_ = NULL; |
657 tooltip_manager_.reset(); | 666 tooltip_manager_.reset(); |
658 delegate_->OnNativeWidgetDestroyed(); | 667 delegate_->OnNativeWidgetDestroyed(); |
659 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 668 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
660 delete this; | 669 delete this; |
661 } | 670 } |
662 | 671 |
663 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { | 672 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { |
664 delegate_->OnNativeWidgetVisibilityChanged(visible); | 673 delegate_->OnNativeWidgetVisibilityChanged(visible); |
665 } | 674 } |
666 | 675 |
667 //////////////////////////////////////////////////////////////////////////////// | |
668 // NativeWidgetAura, aura::ActivationDelegate implementation: | |
669 | |
670 bool NativeWidgetAura::ShouldActivate(aura::Event* event) { | |
671 return can_activate_; | |
672 } | |
673 | |
674 void NativeWidgetAura::OnActivated() { | |
675 delegate_->OnNativeWidgetActivationChanged(true); | |
676 if (IsVisible() && GetWidget()->non_client_view()) | |
677 GetWidget()->non_client_view()->SchedulePaint(); | |
678 } | |
679 | |
680 void NativeWidgetAura::OnLostActive() { | |
681 delegate_->OnNativeWidgetActivationChanged(false); | |
682 if (IsVisible() && GetWidget()->non_client_view()) | |
683 GetWidget()->non_client_view()->SchedulePaint(); | |
684 } | |
685 | |
686 //////////////////////////////////////////////////////////////////////////////// | |
687 // NativeWidgetAura, aura::WindowDragDropDelegate implementation: | |
688 | |
689 void NativeWidgetAura::OnDragEntered(const aura::DropTargetEvent& event) { | 676 void NativeWidgetAura::OnDragEntered(const aura::DropTargetEvent& event) { |
690 DCHECK(drop_helper_.get() != NULL); | 677 DCHECK(drop_helper_.get() != NULL); |
691 drop_helper_->OnDragOver(event.data(), event.location(), | 678 drop_helper_->OnDragOver(event.data(), event.location(), |
692 event.source_operations()); | 679 event.source_operations()); |
693 } | 680 } |
694 | 681 |
695 int NativeWidgetAura::OnDragUpdated(const aura::DropTargetEvent& event) { | 682 int NativeWidgetAura::OnDragUpdated(const aura::DropTargetEvent& event) { |
696 DCHECK(drop_helper_.get() != NULL); | 683 DCHECK(drop_helper_.get() != NULL); |
697 return drop_helper_->OnDragOver(event.data(), event.location(), | 684 return drop_helper_->OnDragOver(event.data(), event.location(), |
698 event.source_operations()); | 685 event.source_operations()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 } | 802 } |
816 } | 803 } |
817 | 804 |
818 // static | 805 // static |
819 bool NativeWidgetPrivate::IsMouseButtonDown() { | 806 bool NativeWidgetPrivate::IsMouseButtonDown() { |
820 return aura::RootWindow::GetInstance()->IsMouseButtonDown(); | 807 return aura::RootWindow::GetInstance()->IsMouseButtonDown(); |
821 } | 808 } |
822 | 809 |
823 } // namespace internal | 810 } // namespace internal |
824 } // namespace views | 811 } // namespace views |
OLD | NEW |