| 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_window_tree_host_win.h" | 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_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/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.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/win/shell.h" | 17 #include "ui/base/win/shell.h" |
| 18 #include "ui/compositor/compositor_constants.h" | 18 #include "ui/compositor/compositor_constants.h" |
| 19 #include "ui/compositor/paint_context.h" | 19 #include "ui/compositor/paint_context.h" |
| 20 #include "ui/gfx/geometry/insets.h" | 20 #include "ui/gfx/geometry/insets.h" |
| 21 #include "ui/gfx/geometry/vector2d.h" | 21 #include "ui/gfx/geometry/vector2d.h" |
| 22 #include "ui/gfx/native_widget_types.h" | 22 #include "ui/gfx/native_widget_types.h" |
| 23 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
| 24 #include "ui/gfx/path_win.h" | 24 #include "ui/gfx/path_win.h" |
| 25 #include "ui/gfx/screen_win.h" |
| 25 #include "ui/gfx/win/dpi.h" | 26 #include "ui/gfx/win/dpi.h" |
| 26 #include "ui/native_theme/native_theme_aura.h" | 27 #include "ui/native_theme/native_theme_aura.h" |
| 27 #include "ui/native_theme/native_theme_win.h" | 28 #include "ui/native_theme/native_theme_win.h" |
| 28 #include "ui/views/corewm/tooltip_win.h" | 29 #include "ui/views/corewm/tooltip_win.h" |
| 29 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" | 30 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" |
| 30 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h" | 31 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h" |
| 31 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 32 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
| 32 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 33 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 33 #include "ui/views/widget/root_view.h" | 34 #include "ui/views/widget/root_view.h" |
| 34 #include "ui/views/widget/widget_delegate.h" | 35 #include "ui/views/widget/widget_delegate.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 native_widget_delegate_); | 132 native_widget_delegate_); |
| 132 | 133 |
| 133 HWND parent_hwnd = NULL; | 134 HWND parent_hwnd = NULL; |
| 134 if (params.parent && params.parent->GetHost()) | 135 if (params.parent && params.parent->GetHost()) |
| 135 parent_hwnd = params.parent->GetHost()->GetAcceleratedWidget(); | 136 parent_hwnd = params.parent->GetHost()->GetAcceleratedWidget(); |
| 136 | 137 |
| 137 message_handler_->set_remove_standard_frame(params.remove_standard_frame); | 138 message_handler_->set_remove_standard_frame(params.remove_standard_frame); |
| 138 | 139 |
| 139 has_non_client_view_ = Widget::RequiresNonClientView(params.type); | 140 has_non_client_view_ = Widget::RequiresNonClientView(params.type); |
| 140 | 141 |
| 141 gfx::Rect pixel_bounds = gfx::win::DIPToScreenRect(params.bounds); | 142 // We don't have an HWND yet, so scale relative to the nearest screen. |
| 143 gfx::Rect pixel_bounds = gfx::ScreenWin::DIPToScreenRect(nullptr, |
| 144 params.bounds); |
| 142 message_handler_->Init(parent_hwnd, pixel_bounds); | 145 message_handler_->Init(parent_hwnd, pixel_bounds); |
| 143 if (params.force_software_compositing) { | 146 if (params.force_software_compositing) { |
| 144 ::SetProp(GetAcceleratedWidget(), | 147 ::SetProp(GetAcceleratedWidget(), |
| 145 kForceSoftwareCompositor, | 148 kForceSoftwareCompositor, |
| 146 reinterpret_cast<HANDLE>(true)); | 149 reinterpret_cast<HANDLE>(true)); |
| 147 } | 150 } |
| 148 CreateCompositor(); | 151 CreateCompositor(); |
| 149 OnAcceleratedWidgetAvailable(); | 152 OnAcceleratedWidgetAvailable(); |
| 150 } | 153 } |
| 151 | 154 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 ui::WindowShowState show_state) { | 212 ui::WindowShowState show_state) { |
| 210 if (compositor()) | 213 if (compositor()) |
| 211 compositor()->SetVisible(true); | 214 compositor()->SetVisible(true); |
| 212 message_handler_->ShowWindowWithState(show_state); | 215 message_handler_->ShowWindowWithState(show_state); |
| 213 } | 216 } |
| 214 | 217 |
| 215 void DesktopWindowTreeHostWin::ShowMaximizedWithBounds( | 218 void DesktopWindowTreeHostWin::ShowMaximizedWithBounds( |
| 216 const gfx::Rect& restored_bounds) { | 219 const gfx::Rect& restored_bounds) { |
| 217 if (compositor()) | 220 if (compositor()) |
| 218 compositor()->SetVisible(true); | 221 compositor()->SetVisible(true); |
| 219 gfx::Rect pixel_bounds = gfx::win::DIPToScreenRect(restored_bounds); | 222 gfx::Rect pixel_bounds = gfx::ScreenWin::DIPToScreenRect(GetHWND(), |
| 223 restored_bounds); |
| 220 message_handler_->ShowMaximizedWithBounds(pixel_bounds); | 224 message_handler_->ShowMaximizedWithBounds(pixel_bounds); |
| 221 } | 225 } |
| 222 | 226 |
| 223 bool DesktopWindowTreeHostWin::IsVisible() const { | 227 bool DesktopWindowTreeHostWin::IsVisible() const { |
| 224 return message_handler_->IsVisible(); | 228 return message_handler_->IsVisible(); |
| 225 } | 229 } |
| 226 | 230 |
| 227 void DesktopWindowTreeHostWin::SetSize(const gfx::Size& size) { | 231 void DesktopWindowTreeHostWin::SetSize(const gfx::Size& size) { |
| 228 gfx::Size size_in_pixels = gfx::win::DIPToScreenSize(size); | 232 gfx::Size size_in_pixels = gfx::ScreenWin::DIPToScreenSize(GetHWND(), size); |
| 229 gfx::Size expanded = GetExpandedWindowSize( | 233 gfx::Size expanded = GetExpandedWindowSize( |
| 230 message_handler_->window_ex_style(), size_in_pixels); | 234 message_handler_->window_ex_style(), size_in_pixels); |
| 231 window_enlargement_ = | 235 window_enlargement_ = |
| 232 gfx::Vector2d(expanded.width() - size_in_pixels.width(), | 236 gfx::Vector2d(expanded.width() - size_in_pixels.width(), |
| 233 expanded.height() - size_in_pixels.height()); | 237 expanded.height() - size_in_pixels.height()); |
| 234 message_handler_->SetSize(expanded); | 238 message_handler_->SetSize(expanded); |
| 235 } | 239 } |
| 236 | 240 |
| 237 void DesktopWindowTreeHostWin::StackAbove(aura::Window* window) { | 241 void DesktopWindowTreeHostWin::StackAbove(aura::Window* window) { |
| 238 HWND hwnd = HWNDForNativeView(window); | 242 HWND hwnd = HWNDForNativeView(window); |
| 239 if (hwnd) | 243 if (hwnd) |
| 240 message_handler_->StackAbove(hwnd); | 244 message_handler_->StackAbove(hwnd); |
| 241 } | 245 } |
| 242 | 246 |
| 243 void DesktopWindowTreeHostWin::StackAtTop() { | 247 void DesktopWindowTreeHostWin::StackAtTop() { |
| 244 message_handler_->StackAtTop(); | 248 message_handler_->StackAtTop(); |
| 245 } | 249 } |
| 246 | 250 |
| 247 void DesktopWindowTreeHostWin::CenterWindow(const gfx::Size& size) { | 251 void DesktopWindowTreeHostWin::CenterWindow(const gfx::Size& size) { |
| 248 gfx::Size size_in_pixels = gfx::win::DIPToScreenSize(size); | 252 gfx::Size size_in_pixels = gfx::ScreenWin::DIPToScreenSize(GetHWND(), size); |
| 249 gfx::Size expanded_size; | 253 gfx::Size expanded_size; |
| 250 expanded_size = GetExpandedWindowSize(message_handler_->window_ex_style(), | 254 expanded_size = GetExpandedWindowSize(message_handler_->window_ex_style(), |
| 251 size_in_pixels); | 255 size_in_pixels); |
| 252 window_enlargement_ = | 256 window_enlargement_ = |
| 253 gfx::Vector2d(expanded_size.width() - size_in_pixels.width(), | 257 gfx::Vector2d(expanded_size.width() - size_in_pixels.width(), |
| 254 expanded_size.height() - size_in_pixels.height()); | 258 expanded_size.height() - size_in_pixels.height()); |
| 255 message_handler_->CenterWindow(expanded_size); | 259 message_handler_->CenterWindow(expanded_size); |
| 256 } | 260 } |
| 257 | 261 |
| 258 void DesktopWindowTreeHostWin::GetWindowPlacement( | 262 void DesktopWindowTreeHostWin::GetWindowPlacement( |
| 259 gfx::Rect* bounds, | 263 gfx::Rect* bounds, |
| 260 ui::WindowShowState* show_state) const { | 264 ui::WindowShowState* show_state) const { |
| 261 message_handler_->GetWindowPlacement(bounds, show_state); | 265 message_handler_->GetWindowPlacement(bounds, show_state); |
| 262 InsetBottomRight(bounds, window_enlargement_); | 266 InsetBottomRight(bounds, window_enlargement_); |
| 263 *bounds = gfx::win::ScreenToDIPRect(*bounds); | 267 *bounds = gfx::ScreenWin::ScreenToDIPRect(GetHWND(), *bounds); |
| 264 } | 268 } |
| 265 | 269 |
| 266 gfx::Rect DesktopWindowTreeHostWin::GetWindowBoundsInScreen() const { | 270 gfx::Rect DesktopWindowTreeHostWin::GetWindowBoundsInScreen() const { |
| 267 gfx::Rect pixel_bounds = message_handler_->GetWindowBoundsInScreen(); | 271 gfx::Rect pixel_bounds = message_handler_->GetWindowBoundsInScreen(); |
| 268 InsetBottomRight(&pixel_bounds, window_enlargement_); | 272 InsetBottomRight(&pixel_bounds, window_enlargement_); |
| 269 return gfx::win::ScreenToDIPRect(pixel_bounds); | 273 return gfx::ScreenWin::ScreenToDIPRect(GetHWND(), pixel_bounds); |
| 270 } | 274 } |
| 271 | 275 |
| 272 gfx::Rect DesktopWindowTreeHostWin::GetClientAreaBoundsInScreen() const { | 276 gfx::Rect DesktopWindowTreeHostWin::GetClientAreaBoundsInScreen() const { |
| 273 gfx::Rect pixel_bounds = message_handler_->GetClientAreaBoundsInScreen(); | 277 gfx::Rect pixel_bounds = message_handler_->GetClientAreaBoundsInScreen(); |
| 274 InsetBottomRight(&pixel_bounds, window_enlargement_); | 278 InsetBottomRight(&pixel_bounds, window_enlargement_); |
| 275 return gfx::win::ScreenToDIPRect(pixel_bounds); | 279 return gfx::ScreenWin::ScreenToDIPRect(GetHWND(), pixel_bounds); |
| 276 } | 280 } |
| 277 | 281 |
| 278 gfx::Rect DesktopWindowTreeHostWin::GetRestoredBounds() const { | 282 gfx::Rect DesktopWindowTreeHostWin::GetRestoredBounds() const { |
| 279 gfx::Rect pixel_bounds = message_handler_->GetRestoredBounds(); | 283 gfx::Rect pixel_bounds = message_handler_->GetRestoredBounds(); |
| 280 InsetBottomRight(&pixel_bounds, window_enlargement_); | 284 InsetBottomRight(&pixel_bounds, window_enlargement_); |
| 281 return gfx::win::ScreenToDIPRect(pixel_bounds); | 285 return gfx::ScreenWin::ScreenToDIPRect(GetHWND(), pixel_bounds); |
| 282 } | 286 } |
| 283 | 287 |
| 284 gfx::Rect DesktopWindowTreeHostWin::GetWorkAreaBoundsInScreen() const { | 288 gfx::Rect DesktopWindowTreeHostWin::GetWorkAreaBoundsInScreen() const { |
| 285 MONITORINFO monitor_info; | 289 MONITORINFO monitor_info; |
| 286 monitor_info.cbSize = sizeof(monitor_info); | 290 monitor_info.cbSize = sizeof(monitor_info); |
| 287 GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(), | 291 GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(), |
| 288 MONITOR_DEFAULTTONEAREST), | 292 MONITOR_DEFAULTTONEAREST), |
| 289 &monitor_info); | 293 &monitor_info); |
| 290 gfx::Rect pixel_bounds = gfx::Rect(monitor_info.rcWork); | 294 gfx::Rect pixel_bounds = gfx::Rect(monitor_info.rcWork); |
| 291 return gfx::win::ScreenToDIPRect(pixel_bounds); | 295 return gfx::ScreenWin::ScreenToDIPRect(GetHWND(), pixel_bounds); |
| 292 } | 296 } |
| 293 | 297 |
| 294 void DesktopWindowTreeHostWin::SetShape(SkRegion* native_region) { | 298 void DesktopWindowTreeHostWin::SetShape(SkRegion* native_region) { |
| 295 if (native_region) { | 299 if (native_region) { |
| 296 // TODO(wez): This would be a lot simpler if we were passed an SkPath. | 300 // TODO(wez): This would be a lot simpler if we were passed an SkPath. |
| 297 // See crbug.com/410593. | 301 // See crbug.com/410593. |
| 298 SkRegion* shape = native_region; | 302 SkRegion* shape = native_region; |
| 299 SkRegion device_region; | 303 SkRegion device_region; |
| 300 if (gfx::GetDPIScale() > 1.0) { | 304 if (gfx::GetDPIScale() > 1.0) { |
| 301 shape = &device_region; | 305 shape = &device_region; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 int DesktopWindowTreeHostWin::GetInitialShowState() const { | 639 int DesktopWindowTreeHostWin::GetInitialShowState() const { |
| 636 return CanActivate() ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE; | 640 return CanActivate() ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE; |
| 637 } | 641 } |
| 638 | 642 |
| 639 bool DesktopWindowTreeHostWin::WillProcessWorkAreaChange() const { | 643 bool DesktopWindowTreeHostWin::WillProcessWorkAreaChange() const { |
| 640 return GetWidget()->widget_delegate()->WillProcessWorkAreaChange(); | 644 return GetWidget()->widget_delegate()->WillProcessWorkAreaChange(); |
| 641 } | 645 } |
| 642 | 646 |
| 643 int DesktopWindowTreeHostWin::GetNonClientComponent( | 647 int DesktopWindowTreeHostWin::GetNonClientComponent( |
| 644 const gfx::Point& point) const { | 648 const gfx::Point& point) const { |
| 645 gfx::Point dip_position = gfx::win::ScreenToDIPPoint(point); | 649 gfx::Point dip_position = gfx::ScreenWin::ClientToDIPPoint(GetHWND(), point); |
| 646 return native_widget_delegate_->GetNonClientComponent(dip_position); | 650 return native_widget_delegate_->GetNonClientComponent(dip_position); |
| 647 } | 651 } |
| 648 | 652 |
| 649 void DesktopWindowTreeHostWin::GetWindowMask(const gfx::Size& size, | 653 void DesktopWindowTreeHostWin::GetWindowMask(const gfx::Size& size, |
| 650 gfx::Path* path) { | 654 gfx::Path* path) { |
| 651 if (GetWidget()->non_client_view()) { | 655 if (GetWidget()->non_client_view()) { |
| 652 GetWidget()->non_client_view()->GetWindowMask(size, path); | 656 GetWidget()->non_client_view()->GetWindowMask(size, path); |
| 653 } else if (!window_enlargement_.IsZero()) { | 657 } else if (!window_enlargement_.IsZero()) { |
| 654 gfx::Rect bounds(WidgetSizeIsClientSize() | 658 gfx::Rect bounds(WidgetSizeIsClientSize() |
| 655 ? message_handler_->GetClientAreaBoundsInScreen() | 659 ? message_handler_->GetClientAreaBoundsInScreen() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 666 void DesktopWindowTreeHostWin::GetMinMaxSize(gfx::Size* min_size, | 670 void DesktopWindowTreeHostWin::GetMinMaxSize(gfx::Size* min_size, |
| 667 gfx::Size* max_size) const { | 671 gfx::Size* max_size) const { |
| 668 *min_size = native_widget_delegate_->GetMinimumSize(); | 672 *min_size = native_widget_delegate_->GetMinimumSize(); |
| 669 *max_size = native_widget_delegate_->GetMaximumSize(); | 673 *max_size = native_widget_delegate_->GetMaximumSize(); |
| 670 } | 674 } |
| 671 | 675 |
| 672 gfx::Size DesktopWindowTreeHostWin::GetRootViewSize() const { | 676 gfx::Size DesktopWindowTreeHostWin::GetRootViewSize() const { |
| 673 return GetWidget()->GetRootView()->size(); | 677 return GetWidget()->GetRootView()->size(); |
| 674 } | 678 } |
| 675 | 679 |
| 680 gfx::Size DesktopWindowTreeHostWin::DIPToScreenSize( |
| 681 const gfx::Size& dip_size) const { |
| 682 return gfx::ScreenWin::DIPToScreenSize(GetHWND(), dip_size); |
| 683 } |
| 684 |
| 676 void DesktopWindowTreeHostWin::ResetWindowControls() { | 685 void DesktopWindowTreeHostWin::ResetWindowControls() { |
| 677 GetWidget()->non_client_view()->ResetWindowControls(); | 686 GetWidget()->non_client_view()->ResetWindowControls(); |
| 678 } | 687 } |
| 679 | 688 |
| 680 gfx::NativeViewAccessible DesktopWindowTreeHostWin::GetNativeViewAccessible() { | 689 gfx::NativeViewAccessible DesktopWindowTreeHostWin::GetNativeViewAccessible() { |
| 681 return GetWidget()->GetRootView()->GetNativeViewAccessible(); | 690 return GetWidget()->GetRootView()->GetNativeViewAccessible(); |
| 682 } | 691 } |
| 683 | 692 |
| 684 bool DesktopWindowTreeHostWin::ShouldHandleSystemCommands() const { | 693 bool DesktopWindowTreeHostWin::ShouldHandleSystemCommands() const { |
| 685 return GetWidget()->widget_delegate()->ShouldHandleSystemCommands(); | 694 return GetWidget()->widget_delegate()->ShouldHandleSystemCommands(); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 | 963 |
| 955 // static | 964 // static |
| 956 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( | 965 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( |
| 957 internal::NativeWidgetDelegate* native_widget_delegate, | 966 internal::NativeWidgetDelegate* native_widget_delegate, |
| 958 DesktopNativeWidgetAura* desktop_native_widget_aura) { | 967 DesktopNativeWidgetAura* desktop_native_widget_aura) { |
| 959 return new DesktopWindowTreeHostWin(native_widget_delegate, | 968 return new DesktopWindowTreeHostWin(native_widget_delegate, |
| 960 desktop_native_widget_aura); | 969 desktop_native_widget_aura); |
| 961 } | 970 } |
| 962 | 971 |
| 963 } // namespace views | 972 } // namespace views |
| OLD | NEW |