| OLD | NEW |
| 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_root_window_host_win.h" | 5 #include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h" |
| 6 | 6 |
| 7 #include "base/win/metro.h" | 7 #include "base/win/metro.h" |
| 8 #include "third_party/skia/include/core/SkPath.h" | 8 #include "third_party/skia/include/core/SkPath.h" |
| 9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/client/cursor_client.h" | 11 #include "ui/aura/client/cursor_client.h" |
| 12 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
| 13 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/window_property.h" | 14 #include "ui/aura/window_property.h" |
| 15 #include "ui/base/cursor/cursor_loader_win.h" | 15 #include "ui/base/cursor/cursor_loader_win.h" |
| 16 #include "ui/base/ime/input_method.h" | 16 #include "ui/base/ime/input_method.h" |
| 17 #include "ui/base/ime/win/tsf_bridge.h" | 17 #include "ui/base/ime/win/tsf_bridge.h" |
| 18 #include "ui/base/win/shell.h" | 18 #include "ui/base/win/shell.h" |
| 19 #include "ui/gfx/insets.h" | 19 #include "ui/gfx/insets.h" |
| 20 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
| 21 #include "ui/gfx/path_win.h" | 21 #include "ui/gfx/path_win.h" |
| 22 #include "ui/gfx/vector2d.h" | 22 #include "ui/gfx/vector2d.h" |
| 23 #include "ui/gfx/win/dpi.h" | 23 #include "ui/gfx/win/dpi.h" |
| 24 #include "ui/native_theme/native_theme_aura.h" | 24 #include "ui/native_theme/native_theme_aura.h" |
| 25 #include "ui/native_theme/native_theme_win.h" | 25 #include "ui/native_theme/native_theme_win.h" |
| 26 #include "ui/views/corewm/compound_event_filter.h" | 26 #include "ui/views/corewm/compound_event_filter.h" |
| 27 #include "ui/views/corewm/corewm_switches.h" | 27 #include "ui/views/corewm/corewm_switches.h" |
| 28 #include "ui/views/corewm/cursor_manager.h" | |
| 29 #include "ui/views/corewm/focus_controller.h" | |
| 30 #include "ui/views/corewm/input_method_event_filter.h" | 28 #include "ui/views/corewm/input_method_event_filter.h" |
| 31 #include "ui/views/corewm/tooltip_win.h" | 29 #include "ui/views/corewm/tooltip_win.h" |
| 32 #include "ui/views/corewm/window_animations.h" | 30 #include "ui/views/corewm/window_animations.h" |
| 33 #include "ui/views/ime/input_method_bridge.h" | 31 #include "ui/views/ime/input_method_bridge.h" |
| 34 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" | 32 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" |
| 35 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" | |
| 36 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h" | 33 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h" |
| 37 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h" | |
| 38 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 34 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
| 39 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 40 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" | |
| 41 #include "ui/views/widget/root_view.h" | 36 #include "ui/views/widget/root_view.h" |
| 42 #include "ui/views/widget/widget_delegate.h" | 37 #include "ui/views/widget/widget_delegate.h" |
| 43 #include "ui/views/widget/widget_hwnd_utils.h" | 38 #include "ui/views/widget/widget_hwnd_utils.h" |
| 44 #include "ui/views/win/fullscreen_handler.h" | 39 #include "ui/views/win/fullscreen_handler.h" |
| 45 #include "ui/views/win/hwnd_message_handler.h" | 40 #include "ui/views/win/hwnd_message_handler.h" |
| 46 #include "ui/views/window/native_frame_view.h" | 41 #include "ui/views/window/native_frame_view.h" |
| 47 | 42 |
| 48 namespace views { | 43 namespace views { |
| 49 | 44 |
| 50 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kContentWindowForRootWindow, NULL); | 45 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kContentWindowForRootWindow, NULL); |
| 51 | 46 |
| 52 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 53 // DesktopRootWindowHostWin, public: | 48 // DesktopRootWindowHostWin, public: |
| 54 | 49 |
| 55 DesktopRootWindowHostWin::DesktopRootWindowHostWin( | 50 DesktopRootWindowHostWin::DesktopRootWindowHostWin( |
| 56 internal::NativeWidgetDelegate* native_widget_delegate, | 51 internal::NativeWidgetDelegate* native_widget_delegate, |
| 57 DesktopNativeWidgetAura* desktop_native_widget_aura, | 52 DesktopNativeWidgetAura* desktop_native_widget_aura) |
| 58 const gfx::Rect& initial_bounds) | |
| 59 : root_window_(NULL), | 53 : root_window_(NULL), |
| 60 message_handler_(new HWNDMessageHandler(this)), | 54 message_handler_(new HWNDMessageHandler(this)), |
| 61 native_widget_delegate_(native_widget_delegate), | 55 native_widget_delegate_(native_widget_delegate), |
| 62 desktop_native_widget_aura_(desktop_native_widget_aura), | 56 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 63 root_window_host_delegate_(NULL), | 57 root_window_host_delegate_(NULL), |
| 64 content_window_(NULL), | 58 content_window_(NULL), |
| 59 drag_drop_client_(NULL), |
| 65 should_animate_window_close_(false), | 60 should_animate_window_close_(false), |
| 66 pending_close_(false), | 61 pending_close_(false), |
| 67 has_non_client_view_(false), | 62 has_non_client_view_(false), |
| 68 tooltip_(NULL) { | 63 tooltip_(NULL) { |
| 69 } | 64 } |
| 70 | 65 |
| 71 DesktopRootWindowHostWin::~DesktopRootWindowHostWin() { | 66 DesktopRootWindowHostWin::~DesktopRootWindowHostWin() { |
| 72 // WARNING: |content_window_| has been destroyed by the time we get here. | 67 // WARNING: |content_window_| has been destroyed by the time we get here. |
| 73 aura::client::SetFocusClient(root_window_, NULL); | 68 desktop_native_widget_aura_->OnDesktopRootWindowHostDestroyed( |
| 74 aura::client::SetActivationClient(root_window_, NULL); | 69 root_window_); |
| 75 aura::client::SetScreenPositionClient(root_window_, NULL); | |
| 76 aura::client::SetDispatcherClient(root_window_, NULL); | |
| 77 aura::client::SetCursorClient(root_window_, NULL); | |
| 78 aura::client::SetDragDropClient(root_window_, NULL); | |
| 79 } | 70 } |
| 80 | 71 |
| 81 // static | 72 // static |
| 82 aura::Window* DesktopRootWindowHostWin::GetContentWindowForHWND(HWND hwnd) { | 73 aura::Window* DesktopRootWindowHostWin::GetContentWindowForHWND(HWND hwnd) { |
| 83 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(hwnd); | 74 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(hwnd); |
| 84 return root ? root->GetProperty(kContentWindowForRootWindow) : NULL; | 75 return root ? root->GetProperty(kContentWindowForRootWindow) : NULL; |
| 85 } | 76 } |
| 86 | 77 |
| 87 // static | 78 // static |
| 88 ui::NativeTheme* DesktopRootWindowHost::GetNativeTheme(aura::Window* window) { | 79 ui::NativeTheme* DesktopRootWindowHost::GetNativeTheme(aura::Window* window) { |
| 89 // Use NativeThemeWin for windows shown on the desktop, those not on the | 80 // Use NativeThemeWin for windows shown on the desktop, those not on the |
| 90 // desktop come from Ash and get NativeThemeAura. | 81 // desktop come from Ash and get NativeThemeAura. |
| 91 aura::RootWindow* root = window ? window->GetRootWindow() : NULL; | 82 aura::RootWindow* root = window ? window->GetRootWindow() : NULL; |
| 92 if (root) { | 83 if (root) { |
| 93 HWND root_hwnd = root->GetAcceleratedWidget(); | 84 HWND root_hwnd = root->GetAcceleratedWidget(); |
| 94 if (root_hwnd && | 85 if (root_hwnd && |
| 95 DesktopRootWindowHostWin::GetContentWindowForHWND(root_hwnd)) { | 86 DesktopRootWindowHostWin::GetContentWindowForHWND(root_hwnd)) { |
| 96 return ui::NativeThemeWin::instance(); | 87 return ui::NativeThemeWin::instance(); |
| 97 } | 88 } |
| 98 } | 89 } |
| 99 return ui::NativeThemeAura::instance(); | 90 return ui::NativeThemeAura::instance(); |
| 100 } | 91 } |
| 101 | 92 |
| 102 //////////////////////////////////////////////////////////////////////////////// | 93 //////////////////////////////////////////////////////////////////////////////// |
| 103 // DesktopRootWindowHostWin, DesktopRootWindowHost implementation: | 94 // DesktopRootWindowHostWin, DesktopRootWindowHost implementation: |
| 104 | 95 |
| 105 aura::RootWindow* DesktopRootWindowHostWin::Init( | 96 void DesktopRootWindowHostWin::Init( |
| 106 aura::Window* content_window, | 97 aura::Window* content_window, |
| 107 const Widget::InitParams& params) { | 98 const Widget::InitParams& params, |
| 99 aura::RootWindow::CreateParams* rw_create_params) { |
| 108 // TODO(beng): SetInitParams(). | 100 // TODO(beng): SetInitParams(). |
| 109 content_window_ = content_window; | 101 content_window_ = content_window; |
| 110 | 102 |
| 103 aura::client::SetAnimationHost(content_window_, this); |
| 104 |
| 111 ConfigureWindowStyles(message_handler_.get(), params, | 105 ConfigureWindowStyles(message_handler_.get(), params, |
| 112 GetWidget()->widget_delegate(), | 106 GetWidget()->widget_delegate(), |
| 113 native_widget_delegate_); | 107 native_widget_delegate_); |
| 114 | 108 |
| 115 HWND parent_hwnd = NULL; | 109 HWND parent_hwnd = NULL; |
| 116 if (params.parent && params.parent->GetRootWindow()) | 110 if (params.parent && params.parent->GetRootWindow()) |
| 117 parent_hwnd = params.parent->GetRootWindow()->GetAcceleratedWidget(); | 111 parent_hwnd = params.parent->GetRootWindow()->GetAcceleratedWidget(); |
| 118 | 112 |
| 119 message_handler_->set_remove_standard_frame(params.remove_standard_frame); | 113 message_handler_->set_remove_standard_frame(params.remove_standard_frame); |
| 120 | 114 |
| 121 has_non_client_view_ = Widget::RequiresNonClientView(params.type); | 115 has_non_client_view_ = Widget::RequiresNonClientView(params.type); |
| 122 | 116 |
| 123 gfx::Rect pixel_bounds = gfx::win::DIPToScreenRect(params.bounds); | 117 gfx::Rect pixel_bounds = gfx::win::DIPToScreenRect(params.bounds); |
| 124 message_handler_->Init(parent_hwnd, pixel_bounds); | 118 message_handler_->Init(parent_hwnd, pixel_bounds); |
| 125 | 119 |
| 126 aura::RootWindow::CreateParams rw_params(params.bounds); | 120 rw_create_params->host = this; |
| 127 rw_params.host = this; | 121 } |
| 128 root_window_ = new aura::RootWindow(rw_params); | |
| 129 | 122 |
| 130 SetWindowTransparency(); | 123 void DesktopRootWindowHostWin::OnRootWindowCreated( |
| 131 root_window_->Init(); | 124 aura::RootWindow* root, |
| 132 root_window_->AddChild(content_window_); | 125 const Widget::InitParams& params) { |
| 133 | 126 root_window_ = root; |
| 134 desktop_native_widget_aura_->InstallWindowModalityController(root_window_); | |
| 135 desktop_native_widget_aura_->CreateCaptureClient(root_window_); | |
| 136 | |
| 137 corewm::FocusController* focus_controller = | |
| 138 new corewm::FocusController(new DesktopFocusRules(content_window)); | |
| 139 focus_client_.reset(focus_controller); | |
| 140 aura::client::SetFocusClient(root_window_, focus_controller); | |
| 141 aura::client::SetActivationClient(root_window_, focus_controller); | |
| 142 root_window_->AddPreTargetHandler(focus_controller); | |
| 143 | |
| 144 dispatcher_client_.reset(new DesktopDispatcherClient); | |
| 145 aura::client::SetDispatcherClient(root_window_, | |
| 146 dispatcher_client_.get()); | |
| 147 | |
| 148 cursor_client_.reset( | |
| 149 new views::corewm::CursorManager( | |
| 150 scoped_ptr<corewm::NativeCursorManager>( | |
| 151 new views::DesktopNativeCursorManager( | |
| 152 root_window_, | |
| 153 scoped_ptr<DesktopCursorLoaderUpdater>())))); | |
| 154 aura::client::SetCursorClient(root_window_, | |
| 155 cursor_client_.get()); | |
| 156 | |
| 157 position_client_.reset(new DesktopScreenPositionClient()); | |
| 158 aura::client::SetScreenPositionClient(root_window_, | |
| 159 position_client_.get()); | |
| 160 | |
| 161 desktop_native_widget_aura_->InstallInputMethodEventFilter(root_window_); | |
| 162 | |
| 163 drag_drop_client_.reset(new DesktopDragDropClientWin(root_window_, | |
| 164 GetHWND())); | |
| 165 aura::client::SetDragDropClient(root_window_, drag_drop_client_.get()); | |
| 166 | 127 |
| 167 root_window_->SetProperty(kContentWindowForRootWindow, content_window_); | 128 root_window_->SetProperty(kContentWindowForRootWindow, content_window_); |
| 168 | 129 |
| 169 aura::client::SetAnimationHost(content_window_, this); | |
| 170 | |
| 171 should_animate_window_close_ = | 130 should_animate_window_close_ = |
| 172 content_window_->type() != aura::client::WINDOW_TYPE_NORMAL && | 131 content_window_->type() != aura::client::WINDOW_TYPE_NORMAL && |
| 173 !views::corewm::WindowAnimationsDisabled(content_window_); | 132 !views::corewm::WindowAnimationsDisabled(content_window_); |
| 174 | 133 |
| 175 return root_window_; | 134 // TODO this is not invoked *after* Init(), but should be ok. |
| 135 SetWindowTransparency(); |
| 176 } | 136 } |
| 177 | 137 |
| 178 scoped_ptr<corewm::Tooltip> DesktopRootWindowHostWin::CreateTooltip() { | 138 scoped_ptr<corewm::Tooltip> DesktopRootWindowHostWin::CreateTooltip() { |
| 179 DCHECK(!tooltip_); | 139 DCHECK(!tooltip_); |
| 180 tooltip_ = new corewm::TooltipWin(GetAcceleratedWidget()); | 140 tooltip_ = new corewm::TooltipWin(GetAcceleratedWidget()); |
| 181 return scoped_ptr<corewm::Tooltip>(tooltip_); | 141 return scoped_ptr<corewm::Tooltip>(tooltip_); |
| 182 } | 142 } |
| 183 | 143 |
| 144 scoped_ptr<aura::client::DragDropClient> |
| 145 DesktopRootWindowHostWin::CreateDragDropClient( |
| 146 DesktopNativeCursorManager* cursor_manager) { |
| 147 drag_drop_client_ = new DesktopDragDropClientWin(root_window_, GetHWND()); |
| 148 return scoped_ptr<aura::client::DragDropClient>(drag_drop_client_).Pass(); |
| 149 } |
| 150 |
| 184 void DesktopRootWindowHostWin::Close() { | 151 void DesktopRootWindowHostWin::Close() { |
| 185 if (should_animate_window_close_) { | 152 if (should_animate_window_close_) { |
| 186 pending_close_ = true; | 153 pending_close_ = true; |
| 187 content_window_->Hide(); | 154 content_window_->Hide(); |
| 188 const bool is_animating = | 155 const bool is_animating = |
| 189 content_window_->layer()->GetAnimator()->IsAnimatingProperty( | 156 content_window_->layer()->GetAnimator()->IsAnimatingProperty( |
| 190 ui::LayerAnimationElement::VISIBILITY); | 157 ui::LayerAnimationElement::VISIBILITY); |
| 191 // Animation may not start for a number of reasons. | 158 // Animation may not start for a number of reasons. |
| 192 if (!is_animating) | 159 if (!is_animating) |
| 193 message_handler_->Close(); | 160 message_handler_->Close(); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 447 |
| 481 void DesktopRootWindowHostWin::SetCursor(gfx::NativeCursor cursor) { | 448 void DesktopRootWindowHostWin::SetCursor(gfx::NativeCursor cursor) { |
| 482 ui::CursorLoaderWin cursor_loader; | 449 ui::CursorLoaderWin cursor_loader; |
| 483 cursor_loader.SetPlatformCursor(&cursor); | 450 cursor_loader.SetPlatformCursor(&cursor); |
| 484 | 451 |
| 485 message_handler_->SetCursor(cursor.platform()); | 452 message_handler_->SetCursor(cursor.platform()); |
| 486 } | 453 } |
| 487 | 454 |
| 488 bool DesktopRootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) { | 455 bool DesktopRootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) { |
| 489 aura::client::CursorClient* cursor_client = | 456 aura::client::CursorClient* cursor_client = |
| 490 aura::client::GetCursorClient(GetRootWindow()); | 457 aura::client::GetCursorClient(root_window_); |
| 491 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { | 458 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { |
| 492 *location_return = gfx::Point(0, 0); | 459 *location_return = gfx::Point(0, 0); |
| 493 return false; | 460 return false; |
| 494 } | 461 } |
| 495 POINT pt = {0}; | 462 POINT pt = {0}; |
| 496 ::GetCursorPos(&pt); | 463 ::GetCursorPos(&pt); |
| 497 *location_return = | 464 *location_return = |
| 498 gfx::Point(static_cast<int>(pt.x), static_cast<int>(pt.y)); | 465 gfx::Point(static_cast<int>(pt.x), static_cast<int>(pt.y)); |
| 499 return true; | 466 return true; |
| 500 } | 467 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 670 |
| 704 void DesktopRootWindowHostWin::HandleAccelerator( | 671 void DesktopRootWindowHostWin::HandleAccelerator( |
| 705 const ui::Accelerator& accelerator) { | 672 const ui::Accelerator& accelerator) { |
| 706 GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); | 673 GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); |
| 707 } | 674 } |
| 708 | 675 |
| 709 void DesktopRootWindowHostWin::HandleCreate() { | 676 void DesktopRootWindowHostWin::HandleCreate() { |
| 710 // TODO(beng): moar | 677 // TODO(beng): moar |
| 711 NOTIMPLEMENTED(); | 678 NOTIMPLEMENTED(); |
| 712 | 679 |
| 713 native_widget_delegate_->OnNativeWidgetCreated(true); | |
| 714 | |
| 715 // 1. Window property association | 680 // 1. Window property association |
| 716 // 2. MouseWheel. | 681 // 2. MouseWheel. |
| 717 } | 682 } |
| 718 | 683 |
| 719 void DesktopRootWindowHostWin::HandleDestroying() { | 684 void DesktopRootWindowHostWin::HandleDestroying() { |
| 720 drag_drop_client_->OnNativeWidgetDestroying(GetHWND()); | 685 drag_drop_client_->OnNativeWidgetDestroying(GetHWND()); |
| 721 native_widget_delegate_->OnNativeWidgetDestroying(); | 686 native_widget_delegate_->OnNativeWidgetDestroying(); |
| 722 } | 687 } |
| 723 | 688 |
| 724 void DesktopRootWindowHostWin::HandleDestroyed() { | 689 void DesktopRootWindowHostWin::HandleDestroyed() { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 } | 869 } |
| 905 return false; | 870 return false; |
| 906 } | 871 } |
| 907 | 872 |
| 908 //////////////////////////////////////////////////////////////////////////////// | 873 //////////////////////////////////////////////////////////////////////////////// |
| 909 // DesktopRootWindowHost, public: | 874 // DesktopRootWindowHost, public: |
| 910 | 875 |
| 911 // static | 876 // static |
| 912 DesktopRootWindowHost* DesktopRootWindowHost::Create( | 877 DesktopRootWindowHost* DesktopRootWindowHost::Create( |
| 913 internal::NativeWidgetDelegate* native_widget_delegate, | 878 internal::NativeWidgetDelegate* native_widget_delegate, |
| 914 DesktopNativeWidgetAura* desktop_native_widget_aura, | 879 DesktopNativeWidgetAura* desktop_native_widget_aura) { |
| 915 const gfx::Rect& initial_bounds) { | |
| 916 return new DesktopRootWindowHostWin(native_widget_delegate, | 880 return new DesktopRootWindowHostWin(native_widget_delegate, |
| 917 desktop_native_widget_aura, | 881 desktop_native_widget_aura); |
| 918 initial_bounds); | |
| 919 } | 882 } |
| 920 | 883 |
| 921 } // namespace views | 884 } // namespace views |
| OLD | NEW |