| 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 "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/focus_manager.h" | 10 #include "ui/aura/focus_manager.h" |
| 11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/window_property.h" | 12 #include "ui/aura/window_property.h" |
| 13 #include "ui/base/cursor/cursor_loader_win.h" | 13 #include "ui/base/cursor/cursor_loader_win.h" |
| 14 #include "ui/base/ime/input_method_win.h" | 14 #include "ui/base/ime/input_method_win.h" |
| 15 #include "ui/base/win/dpi.h" |
| 15 #include "ui/base/win/shell.h" | 16 #include "ui/base/win/shell.h" |
| 16 #include "ui/gfx/insets.h" | 17 #include "ui/gfx/insets.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 18 #include "ui/gfx/path_win.h" | 19 #include "ui/gfx/path_win.h" |
| 19 #include "ui/native_theme/native_theme_aura.h" | 20 #include "ui/native_theme/native_theme_aura.h" |
| 20 #include "ui/native_theme/native_theme_win.h" | 21 #include "ui/native_theme/native_theme_win.h" |
| 21 #include "ui/views/corewm/compound_event_filter.h" | 22 #include "ui/views/corewm/compound_event_filter.h" |
| 22 #include "ui/views/corewm/corewm_switches.h" | 23 #include "ui/views/corewm/corewm_switches.h" |
| 23 #include "ui/views/corewm/cursor_manager.h" | 24 #include "ui/views/corewm/cursor_manager.h" |
| 24 #include "ui/views/corewm/focus_controller.h" | 25 #include "ui/views/corewm/focus_controller.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 native_widget_delegate_); | 106 native_widget_delegate_); |
| 106 | 107 |
| 107 HWND parent_hwnd = NULL; | 108 HWND parent_hwnd = NULL; |
| 108 aura::Window* parent_window = params.parent; | 109 aura::Window* parent_window = params.parent; |
| 109 if (parent_window) | 110 if (parent_window) |
| 110 parent_hwnd = parent_window->GetRootWindow()->GetAcceleratedWidget(); | 111 parent_hwnd = parent_window->GetRootWindow()->GetAcceleratedWidget(); |
| 111 | 112 |
| 112 message_handler_->set_remove_standard_frame(params.remove_standard_frame); | 113 message_handler_->set_remove_standard_frame(params.remove_standard_frame); |
| 113 | 114 |
| 114 has_non_client_view_ = Widget::RequiresNonClientView(params.type); | 115 has_non_client_view_ = Widget::RequiresNonClientView(params.type); |
| 115 message_handler_->Init(parent_hwnd, params.bounds); | 116 |
| 117 gfx::Rect pixel_bounds = ui::win::DIPToScreenRect(params.bounds); |
| 118 message_handler_->Init(parent_hwnd, pixel_bounds); |
| 116 | 119 |
| 117 aura::RootWindow::CreateParams rw_params(params.bounds); | 120 aura::RootWindow::CreateParams rw_params(params.bounds); |
| 118 rw_params.host = this; | 121 rw_params.host = this; |
| 119 root_window_ = new aura::RootWindow(rw_params); | 122 root_window_ = new aura::RootWindow(rw_params); |
| 120 | 123 |
| 121 // TODO(beng): We probably need to move these two calls to some function that | 124 // TODO(beng): We probably need to move these two calls to some function that |
| 122 // can change depending on the native-ness of the frame. For right | 125 // can change depending on the native-ness of the frame. For right |
| 123 // now in the hack-n-slash days of win-aura, we can just | 126 // now in the hack-n-slash days of win-aura, we can just |
| 124 // unilaterally turn this on. | 127 // unilaterally turn this on. |
| 125 root_window_->compositor()->SetHostHasTransparentBackground(true); | 128 root_window_->compositor()->SetHostHasTransparentBackground(true); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return this; | 206 return this; |
| 204 } | 207 } |
| 205 | 208 |
| 206 void DesktopRootWindowHostWin::ShowWindowWithState( | 209 void DesktopRootWindowHostWin::ShowWindowWithState( |
| 207 ui::WindowShowState show_state) { | 210 ui::WindowShowState show_state) { |
| 208 message_handler_->ShowWindowWithState(show_state); | 211 message_handler_->ShowWindowWithState(show_state); |
| 209 } | 212 } |
| 210 | 213 |
| 211 void DesktopRootWindowHostWin::ShowMaximizedWithBounds( | 214 void DesktopRootWindowHostWin::ShowMaximizedWithBounds( |
| 212 const gfx::Rect& restored_bounds) { | 215 const gfx::Rect& restored_bounds) { |
| 213 message_handler_->ShowMaximizedWithBounds(restored_bounds); | 216 gfx::Rect pixel_bounds = ui::win::DIPToScreenRect(restored_bounds); |
| 217 message_handler_->ShowMaximizedWithBounds(pixel_bounds); |
| 214 } | 218 } |
| 215 | 219 |
| 216 bool DesktopRootWindowHostWin::IsVisible() const { | 220 bool DesktopRootWindowHostWin::IsVisible() const { |
| 217 return message_handler_->IsVisible(); | 221 return message_handler_->IsVisible(); |
| 218 } | 222 } |
| 219 | 223 |
| 220 void DesktopRootWindowHostWin::SetSize(const gfx::Size& size) { | 224 void DesktopRootWindowHostWin::SetSize(const gfx::Size& size) { |
| 221 message_handler_->SetSize(size); | 225 gfx::Size size_in_pixels = ui::win::DIPToScreenSize(size); |
| 226 message_handler_->SetSize(size_in_pixels); |
| 222 } | 227 } |
| 223 | 228 |
| 224 void DesktopRootWindowHostWin::CenterWindow(const gfx::Size& size) { | 229 void DesktopRootWindowHostWin::CenterWindow(const gfx::Size& size) { |
| 225 message_handler_->CenterWindow(size); | 230 gfx::Size size_in_pixels = ui::win::DIPToScreenSize(size); |
| 231 message_handler_->CenterWindow(size_in_pixels); |
| 226 } | 232 } |
| 227 | 233 |
| 228 void DesktopRootWindowHostWin::GetWindowPlacement( | 234 void DesktopRootWindowHostWin::GetWindowPlacement( |
| 229 gfx::Rect* bounds, | 235 gfx::Rect* bounds, |
| 230 ui::WindowShowState* show_state) const { | 236 ui::WindowShowState* show_state) const { |
| 231 message_handler_->GetWindowPlacement(bounds, show_state); | 237 message_handler_->GetWindowPlacement(bounds, show_state); |
| 238 *bounds = ui::win::ScreenToDIPRect(*bounds); |
| 232 } | 239 } |
| 233 | 240 |
| 234 gfx::Rect DesktopRootWindowHostWin::GetWindowBoundsInScreen() const { | 241 gfx::Rect DesktopRootWindowHostWin::GetWindowBoundsInScreen() const { |
| 235 return message_handler_->GetWindowBoundsInScreen(); | 242 gfx::Rect pixel_bounds = message_handler_->GetWindowBoundsInScreen(); |
| 243 return ui::win::ScreenToDIPRect(pixel_bounds); |
| 236 } | 244 } |
| 237 | 245 |
| 238 gfx::Rect DesktopRootWindowHostWin::GetClientAreaBoundsInScreen() const { | 246 gfx::Rect DesktopRootWindowHostWin::GetClientAreaBoundsInScreen() const { |
| 239 return message_handler_->GetClientAreaBoundsInScreen(); | 247 gfx::Rect pixel_bounds = message_handler_->GetClientAreaBoundsInScreen(); |
| 248 return ui::win::ScreenToDIPRect(pixel_bounds); |
| 240 } | 249 } |
| 241 | 250 |
| 242 gfx::Rect DesktopRootWindowHostWin::GetRestoredBounds() const { | 251 gfx::Rect DesktopRootWindowHostWin::GetRestoredBounds() const { |
| 243 return message_handler_->GetRestoredBounds(); | 252 gfx::Rect pixel_bounds = message_handler_->GetRestoredBounds(); |
| 253 return ui::win::ScreenToDIPRect(pixel_bounds); |
| 244 } | 254 } |
| 245 | 255 |
| 246 gfx::Rect DesktopRootWindowHostWin::GetWorkAreaBoundsInScreen() const { | 256 gfx::Rect DesktopRootWindowHostWin::GetWorkAreaBoundsInScreen() const { |
| 247 MONITORINFO monitor_info; | 257 MONITORINFO monitor_info; |
| 248 monitor_info.cbSize = sizeof(monitor_info); | 258 monitor_info.cbSize = sizeof(monitor_info); |
| 249 GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(), | 259 GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(), |
| 250 MONITOR_DEFAULTTONEAREST), | 260 MONITOR_DEFAULTTONEAREST), |
| 251 &monitor_info); | 261 &monitor_info); |
| 252 return gfx::Rect(monitor_info.rcWork); | 262 gfx::Rect pixel_bounds = gfx::Rect(monitor_info.rcWork); |
| 263 return ui::win::ScreenToDIPRect(pixel_bounds); |
| 253 } | 264 } |
| 254 | 265 |
| 255 void DesktopRootWindowHostWin::SetShape(gfx::NativeRegion native_region) { | 266 void DesktopRootWindowHostWin::SetShape(gfx::NativeRegion native_region) { |
| 256 SkPath path; | 267 SkPath path; |
| 257 native_region->getBoundaryPath(&path); | 268 native_region->getBoundaryPath(&path); |
| 258 message_handler_->SetRegion(gfx::CreateHRGNFromSkPath(path)); | 269 message_handler_->SetRegion(gfx::CreateHRGNFromSkPath(path)); |
| 259 } | 270 } |
| 260 | 271 |
| 261 void DesktopRootWindowHostWin::Activate() { | 272 void DesktopRootWindowHostWin::Activate() { |
| 262 message_handler_->Activate(); | 273 message_handler_->Activate(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 401 } |
| 391 | 402 |
| 392 void DesktopRootWindowHostWin::Hide() { | 403 void DesktopRootWindowHostWin::Hide() { |
| 393 if (!pending_close_) | 404 if (!pending_close_) |
| 394 message_handler_->Hide(); | 405 message_handler_->Hide(); |
| 395 } | 406 } |
| 396 | 407 |
| 397 void DesktopRootWindowHostWin::ToggleFullScreen() { | 408 void DesktopRootWindowHostWin::ToggleFullScreen() { |
| 398 } | 409 } |
| 399 | 410 |
| 411 // GetBounds and SetBounds work in pixel coordinates, whereas other get/set |
| 412 // methods work in DIP. |
| 413 |
| 400 gfx::Rect DesktopRootWindowHostWin::GetBounds() const { | 414 gfx::Rect DesktopRootWindowHostWin::GetBounds() const { |
| 401 // Match the logic in HWNDMessageHandler::ClientAreaSizeChanged(). | 415 // Match the logic in HWNDMessageHandler::ClientAreaSizeChanged(). |
| 402 gfx::Rect bounds(WidgetSizeIsClientSize() ? GetClientAreaBoundsInScreen() | 416 gfx::Rect bounds(WidgetSizeIsClientSize() ? |
| 403 : GetWindowBoundsInScreen()); | 417 message_handler_->GetClientAreaBoundsInScreen() : |
| 418 message_handler_->GetWindowBoundsInScreen()); |
| 404 gfx::Rect without_expansion(bounds.x() - window_expansion_.x(), | 419 gfx::Rect without_expansion(bounds.x() - window_expansion_.x(), |
| 405 bounds.y() - window_expansion_.y(), | 420 bounds.y() - window_expansion_.y(), |
| 406 bounds.width() - window_expansion_.width(), | 421 bounds.width() - window_expansion_.width(), |
| 407 bounds.height() - window_expansion_.height()); | 422 bounds.height() - window_expansion_.height()); |
| 408 return without_expansion; | 423 return without_expansion; |
| 409 } | 424 } |
| 410 | 425 |
| 411 void DesktopRootWindowHostWin::SetBounds(const gfx::Rect& bounds) { | 426 void DesktopRootWindowHostWin::SetBounds(const gfx::Rect& bounds) { |
| 412 gfx::Rect expanded(bounds.x() + window_expansion_.x(), | 427 gfx::Rect expanded(bounds.x() + window_expansion_.x(), |
| 413 bounds.y() + window_expansion_.y(), | 428 bounds.y() + window_expansion_.y(), |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 native_widget_delegate_->OnNativeWidgetVisibilityChanged(visible); | 718 native_widget_delegate_->OnNativeWidgetVisibilityChanged(visible); |
| 704 } | 719 } |
| 705 | 720 |
| 706 void DesktopRootWindowHostWin::HandleClientSizeChanged( | 721 void DesktopRootWindowHostWin::HandleClientSizeChanged( |
| 707 const gfx::Size& new_size) { | 722 const gfx::Size& new_size) { |
| 708 gfx::Size without_expansion(new_size.width() - window_expansion_.width(), | 723 gfx::Size without_expansion(new_size.width() - window_expansion_.width(), |
| 709 new_size.height() - window_expansion_.height()); | 724 new_size.height() - window_expansion_.height()); |
| 710 if (root_window_host_delegate_) | 725 if (root_window_host_delegate_) |
| 711 root_window_host_delegate_->OnHostResized(new_size); | 726 root_window_host_delegate_->OnHostResized(new_size); |
| 712 // TODO(beng): replace with a layout manager?? | 727 // TODO(beng): replace with a layout manager?? |
| 713 content_window_->SetBounds(gfx::Rect(without_expansion)); | 728 gfx::Size dip_size = ui::win::ScreenToDIPSize(without_expansion); |
| 714 native_widget_delegate_->OnNativeWidgetSizeChanged(new_size); | 729 content_window_->SetBounds(gfx::Rect(dip_size)); |
| 730 native_widget_delegate_->OnNativeWidgetSizeChanged(dip_size); |
| 715 } | 731 } |
| 716 | 732 |
| 717 void DesktopRootWindowHostWin::HandleFrameChanged() { | 733 void DesktopRootWindowHostWin::HandleFrameChanged() { |
| 718 // Replace the frame and layout the contents. | 734 // Replace the frame and layout the contents. |
| 719 GetWidget()->non_client_view()->UpdateFrame(true); | 735 GetWidget()->non_client_view()->UpdateFrame(true); |
| 720 } | 736 } |
| 721 | 737 |
| 722 void DesktopRootWindowHostWin::HandleNativeFocus(HWND last_focused_window) { | 738 void DesktopRootWindowHostWin::HandleNativeFocus(HWND last_focused_window) { |
| 723 // TODO(beng): inform the native_widget_delegate_. | 739 // TODO(beng): inform the native_widget_delegate_. |
| 724 InputMethod* input_method = GetInputMethod(); | 740 InputMethod* input_method = GetInputMethod(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 DesktopRootWindowHost* DesktopRootWindowHost::Create( | 852 DesktopRootWindowHost* DesktopRootWindowHost::Create( |
| 837 internal::NativeWidgetDelegate* native_widget_delegate, | 853 internal::NativeWidgetDelegate* native_widget_delegate, |
| 838 DesktopNativeWidgetAura* desktop_native_widget_aura, | 854 DesktopNativeWidgetAura* desktop_native_widget_aura, |
| 839 const gfx::Rect& initial_bounds) { | 855 const gfx::Rect& initial_bounds) { |
| 840 return new DesktopRootWindowHostWin(native_widget_delegate, | 856 return new DesktopRootWindowHostWin(native_widget_delegate, |
| 841 desktop_native_widget_aura, | 857 desktop_native_widget_aura, |
| 842 initial_bounds); | 858 initial_bounds); |
| 843 } | 859 } |
| 844 | 860 |
| 845 } // namespace views | 861 } // namespace views |
| OLD | NEW |