Chromium Code Reviews| 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/root_window_observer.h" | 
| 
 
sky
2011/12/09 23:11:23
Can this be removed now?
 
 | |
| 15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.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" | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 53 case Widget::InitParams::TYPE_MENU: | 54 case Widget::InitParams::TYPE_MENU: | 
| 54 return aura::WINDOW_TYPE_MENU; | 55 return aura::WINDOW_TYPE_MENU; | 
| 55 case Widget::InitParams::TYPE_TOOLTIP: | 56 case Widget::InitParams::TYPE_TOOLTIP: | 
| 56 return aura::WINDOW_TYPE_TOOLTIP; | 57 return aura::WINDOW_TYPE_TOOLTIP; | 
| 57 default: | 58 default: | 
| 58 NOTREACHED() << "Unhandled widget type " << type; | 59 NOTREACHED() << "Unhandled widget type " << type; | 
| 59 return aura::WINDOW_TYPE_UNKNOWN; | 60 return aura::WINDOW_TYPE_UNKNOWN; | 
| 60 } | 61 } | 
| 61 } | 62 } | 
| 62 | 63 | 
| 64 aura::ActivationClient* GetActivationClient() { | |
| 65 return reinterpret_cast<aura::ActivationClient*>( | |
| 66 aura::RootWindow::GetInstance()->GetProperty( | |
| 67 aura::kRootWindowActivationClient)); | |
| 68 } | |
| 63 } // namespace | 69 } // namespace | 
| 64 | 70 | 
| 65 // Used when SetInactiveRenderingDisabled() is invoked to track when active | 71 // Used when SetInactiveRenderingDisabled() is invoked to track when active | 
| 66 // status changes in such a way that we should enable inactive rendering. | 72 // status changes in such a way that we should enable inactive rendering. | 
| 67 class NativeWidgetAura::RootWindowObserverImpl | 73 class NativeWidgetAura::RootWindowObserverImpl : public aura::WindowObserver { | 
| 68 : public aura::RootWindowObserver { | |
| 69 public: | 74 public: | 
| 70 explicit RootWindowObserverImpl(NativeWidgetAura* host) | 75 explicit RootWindowObserverImpl(NativeWidgetAura* host) : host_(host) { | 
| 71 : host_(host) { | |
| 72 aura::RootWindow::GetInstance()->AddObserver(this); | 76 aura::RootWindow::GetInstance()->AddObserver(this); | 
| 73 } | 77 } | 
| 74 | |
| 75 virtual ~RootWindowObserverImpl() { | 78 virtual ~RootWindowObserverImpl() { | 
| 76 aura::RootWindow::GetInstance()->RemoveObserver(this); | 79 aura::RootWindow::GetInstance()->RemoveObserver(this); | 
| 77 } | 80 } | 
| 78 | 81 | 
| 79 // RootWindowObserver overrides: | 82 // Overridden from aura::WindowObserver: | 
| 80 virtual void OnActiveWindowChanged(aura::Window* active) OVERRIDE { | 83 virtual void OnWindowPropertyChanged(aura::Window* window, | 
| 84 const char* key, | |
| 85 void* old) OVERRIDE { | |
| 86 if (key != aura::kRootWindowActiveWindow) | |
| 87 return; | |
| 88 aura::Window* active = GetActivationClient()->GetActiveWindow(); | |
| 81 if (!active || (active != host_->window_ && | 89 if (!active || (active != host_->window_ && | 
| 82 active->transient_parent() != host_->window_)) { | 90 active->transient_parent() != host_->window_)) { | 
| 83 host_->delegate_->EnableInactiveRendering(); | 91 host_->delegate_->EnableInactiveRendering(); | 
| 84 } | 92 } | 
| 85 } | 93 } | 
| 86 | 94 | 
| 87 private: | 95 private: | 
| 88 NativeWidgetAura* host_; | 96 NativeWidgetAura* host_; | 
| 89 | 97 | 
| 90 DISALLOW_COPY_AND_ASSIGN(RootWindowObserverImpl); | 98 DISALLOW_COPY_AND_ASSIGN(RootWindowObserverImpl); | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 tooltip_manager_.reset(new views::TooltipManagerAura(this)); | 170 tooltip_manager_.reset(new views::TooltipManagerAura(this)); | 
| 163 } | 171 } | 
| 164 | 172 | 
| 165 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | 173 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | 
| 166 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | 174 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | 
| 167 params.type != Widget::InitParams::TYPE_POPUP) { | 175 params.type != Widget::InitParams::TYPE_POPUP) { | 
| 168 window_->SetProperty(aura::kDragDropDelegateKey, | 176 window_->SetProperty(aura::kDragDropDelegateKey, | 
| 169 static_cast<aura::WindowDragDropDelegate*>(this)); | 177 static_cast<aura::WindowDragDropDelegate*>(this)); | 
| 170 } | 178 } | 
| 171 | 179 | 
| 180 window_->SetProperty(aura::kActivationDelegateKey, | |
| 181 static_cast<aura::ActivationDelegate*>(this)); | |
| 182 | |
| 172 if (window_type == Widget::InitParams::TYPE_MENU || | 183 if (window_type == Widget::InitParams::TYPE_MENU || | 
| 173 window_type == Widget::InitParams::TYPE_TOOLTIP) | 184 window_type == Widget::InitParams::TYPE_TOOLTIP) | 
| 174 window_->SetIntProperty(aura::kShadowTypeKey, | 185 window_->SetIntProperty(aura::kShadowTypeKey, | 
| 175 aura::SHADOW_TYPE_RECTANGULAR); | 186 aura::SHADOW_TYPE_RECTANGULAR); | 
| 176 } | 187 } | 
| 177 | 188 | 
| 178 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { | 189 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { | 
| 179 return NULL; | 190 return NULL; | 
| 180 } | 191 } | 
| 181 | 192 | 
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 } | 417 } | 
| 407 | 418 | 
| 408 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { | 419 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { | 
| 409 if (state == ui::SHOW_STATE_MAXIMIZED || | 420 if (state == ui::SHOW_STATE_MAXIMIZED || | 
| 410 state == ui::SHOW_STATE_FULLSCREEN) { | 421 state == ui::SHOW_STATE_FULLSCREEN) { | 
| 411 window_->SetIntProperty(aura::kShowStateKey, state); | 422 window_->SetIntProperty(aura::kShowStateKey, state); | 
| 412 } | 423 } | 
| 413 window_->Show(); | 424 window_->Show(); | 
| 414 if (can_activate_ && (state != ui::SHOW_STATE_INACTIVE || | 425 if (can_activate_ && (state != ui::SHOW_STATE_INACTIVE || | 
| 415 !GetWidget()->SetInitialFocus())) { | 426 !GetWidget()->SetInitialFocus())) { | 
| 416 window_->Activate(); | 427 Activate(); | 
| 417 } | 428 } | 
| 418 } | 429 } | 
| 419 | 430 | 
| 420 bool NativeWidgetAura::IsVisible() const { | 431 bool NativeWidgetAura::IsVisible() const { | 
| 421 return window_->IsVisible(); | 432 return window_->IsVisible(); | 
| 422 } | 433 } | 
| 423 | 434 | 
| 424 void NativeWidgetAura::Activate() { | 435 void NativeWidgetAura::Activate() { | 
| 425 window_->Activate(); | 436 GetActivationClient()->ActivateWindow(window_); | 
| 426 } | 437 } | 
| 427 | 438 | 
| 428 void NativeWidgetAura::Deactivate() { | 439 void NativeWidgetAura::Deactivate() { | 
| 429 window_->Deactivate(); | 440 GetActivationClient()->DeactivateWindow(window_); | 
| 430 } | 441 } | 
| 431 | 442 | 
| 432 bool NativeWidgetAura::IsActive() const { | 443 bool NativeWidgetAura::IsActive() const { | 
| 433 return aura::RootWindow::GetInstance()->active_window() == window_; | 444 return GetActivationClient()->GetActiveWindow() == window_; | 
| 434 } | 445 } | 
| 435 | 446 | 
| 436 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { | 447 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { | 
| 437 window_->SetIntProperty(aura::kAlwaysOnTopKey, on_top); | 448 window_->SetIntProperty(aura::kAlwaysOnTopKey, on_top); | 
| 438 } | 449 } | 
| 439 | 450 | 
| 440 void NativeWidgetAura::Maximize() { | 451 void NativeWidgetAura::Maximize() { | 
| 441 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 452 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 
| 442 } | 453 } | 
| 443 | 454 | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) { | 621 ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) { | 
| 611 DCHECK(window_->IsVisible()); | 622 DCHECK(window_->IsVisible()); | 
| 612 TouchEvent touch_event(event); | 623 TouchEvent touch_event(event); | 
| 613 return delegate_->OnTouchEvent(touch_event); | 624 return delegate_->OnTouchEvent(touch_event); | 
| 614 } | 625 } | 
| 615 | 626 | 
| 616 bool NativeWidgetAura::CanFocus() { | 627 bool NativeWidgetAura::CanFocus() { | 
| 617 return true; | 628 return true; | 
| 618 } | 629 } | 
| 619 | 630 | 
| 620 bool NativeWidgetAura::ShouldActivate(aura::Event* event) { | |
| 621 return can_activate_; | |
| 622 } | |
| 623 | |
| 624 void NativeWidgetAura::OnActivated() { | |
| 625 delegate_->OnNativeWidgetActivationChanged(true); | |
| 626 if (IsVisible() && GetWidget()->non_client_view()) | |
| 627 GetWidget()->non_client_view()->SchedulePaint(); | |
| 628 } | |
| 629 | |
| 630 void NativeWidgetAura::OnLostActive() { | |
| 631 delegate_->OnNativeWidgetActivationChanged(false); | |
| 632 if (IsVisible() && GetWidget()->non_client_view()) | |
| 633 GetWidget()->non_client_view()->SchedulePaint(); | |
| 634 } | |
| 635 | |
| 636 void NativeWidgetAura::OnCaptureLost() { | 631 void NativeWidgetAura::OnCaptureLost() { | 
| 637 delegate_->OnMouseCaptureLost(); | 632 delegate_->OnMouseCaptureLost(); | 
| 638 } | 633 } | 
| 639 | 634 | 
| 640 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | 635 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | 
| 641 delegate_->OnNativeWidgetPaint(canvas); | 636 delegate_->OnNativeWidgetPaint(canvas); | 
| 642 } | 637 } | 
| 643 | 638 | 
| 644 void NativeWidgetAura::OnWindowDestroying() { | 639 void NativeWidgetAura::OnWindowDestroying() { | 
| 645 window_->SetProperty(aura::kDragDropDelegateKey, NULL); | 640 window_->SetProperty(aura::kDragDropDelegateKey, NULL); | 
| 646 delegate_->OnNativeWidgetDestroying(); | 641 delegate_->OnNativeWidgetDestroying(); | 
| 647 | 642 | 
| 648 // If the aura::Window is destroyed, we can no longer show tooltips. | 643 // If the aura::Window is destroyed, we can no longer show tooltips. | 
| 649 tooltip_manager_.reset(); | 644 tooltip_manager_.reset(); | 
| 650 } | 645 } | 
| 651 | 646 | 
| 652 void NativeWidgetAura::OnWindowDestroyed() { | 647 void NativeWidgetAura::OnWindowDestroyed() { | 
| 653 window_ = NULL; | 648 window_ = NULL; | 
| 654 tooltip_manager_.reset(); | 649 tooltip_manager_.reset(); | 
| 655 delegate_->OnNativeWidgetDestroyed(); | 650 delegate_->OnNativeWidgetDestroyed(); | 
| 656 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 651 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 
| 657 delete this; | 652 delete this; | 
| 658 } | 653 } | 
| 659 | 654 | 
| 660 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { | 655 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { | 
| 661 delegate_->OnNativeWidgetVisibilityChanged(visible); | 656 delegate_->OnNativeWidgetVisibilityChanged(visible); | 
| 662 } | 657 } | 
| 663 | 658 | 
| 659 //////////////////////////////////////////////////////////////////////////////// | |
| 660 // NativeWidgetAura, aura::ActivationDelegate implementation: | |
| 661 | |
| 662 bool NativeWidgetAura::ShouldActivate(aura::Event* event) { | |
| 663 return can_activate_; | |
| 664 } | |
| 665 | |
| 666 void NativeWidgetAura::OnActivated() { | |
| 667 delegate_->OnNativeWidgetActivationChanged(true); | |
| 668 if (IsVisible() && GetWidget()->non_client_view()) | |
| 669 GetWidget()->non_client_view()->SchedulePaint(); | |
| 670 } | |
| 671 | |
| 672 void NativeWidgetAura::OnLostActive() { | |
| 673 delegate_->OnNativeWidgetActivationChanged(false); | |
| 674 if (IsVisible() && GetWidget()->non_client_view()) | |
| 675 GetWidget()->non_client_view()->SchedulePaint(); | |
| 676 } | |
| 677 | |
| 678 //////////////////////////////////////////////////////////////////////////////// | |
| 679 // NativeWidgetAura, aura::WindowDragDropDelegate implementation: | |
| 680 | |
| 664 void NativeWidgetAura::OnDragEntered(const aura::DropTargetEvent& event) { | 681 void NativeWidgetAura::OnDragEntered(const aura::DropTargetEvent& event) { | 
| 665 DCHECK(drop_helper_.get() != NULL); | 682 DCHECK(drop_helper_.get() != NULL); | 
| 666 drop_helper_->OnDragOver(event.data(), event.location(), | 683 drop_helper_->OnDragOver(event.data(), event.location(), | 
| 667 event.source_operations()); | 684 event.source_operations()); | 
| 668 } | 685 } | 
| 669 | 686 | 
| 670 int NativeWidgetAura::OnDragUpdated(const aura::DropTargetEvent& event) { | 687 int NativeWidgetAura::OnDragUpdated(const aura::DropTargetEvent& event) { | 
| 671 DCHECK(drop_helper_.get() != NULL); | 688 DCHECK(drop_helper_.get() != NULL); | 
| 672 return drop_helper_->OnDragOver(event.data(), event.location(), | 689 return drop_helper_->OnDragOver(event.data(), event.location(), | 
| 673 event.source_operations()); | 690 event.source_operations()); | 
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 } | 808 } | 
| 792 } | 809 } | 
| 793 | 810 | 
| 794 // static | 811 // static | 
| 795 bool NativeWidgetPrivate::IsMouseButtonDown() { | 812 bool NativeWidgetPrivate::IsMouseButtonDown() { | 
| 796 return aura::RootWindow::GetInstance()->IsMouseButtonDown(); | 813 return aura::RootWindow::GetInstance()->IsMouseButtonDown(); | 
| 797 } | 814 } | 
| 798 | 815 | 
| 799 } // namespace internal | 816 } // namespace internal | 
| 800 } // namespace views | 817 } // namespace views | 
| OLD | NEW |