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