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