| 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/aura/window_tree_host_win.h" | 5 #include "ui/aura/window_tree_host_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 return new WindowTreeHostWin(bounds); | 34 return new WindowTreeHostWin(bounds); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 gfx::Size WindowTreeHost::GetNativeScreenSize() { | 38 gfx::Size WindowTreeHost::GetNativeScreenSize() { |
| 39 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | 39 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
| 40 GetSystemMetrics(SM_CYSCREEN)); | 40 GetSystemMetrics(SM_CYSCREEN)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds) | 43 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds) |
| 44 : fullscreen_(false), | 44 : has_capture_(false) { |
| 45 has_capture_(false), | |
| 46 saved_window_style_(0), | |
| 47 saved_window_ex_style_(0) { | |
| 48 if (use_popup_as_root_window_for_test) | 45 if (use_popup_as_root_window_for_test) |
| 49 set_window_style(WS_POPUP); | 46 set_window_style(WS_POPUP); |
| 50 Init(NULL, bounds); | 47 Init(NULL, bounds); |
| 51 SetWindowText(hwnd(), L"aura::RootWindow!"); | 48 SetWindowText(hwnd(), L"aura::RootWindow!"); |
| 52 CreateCompositor(GetAcceleratedWidget()); | 49 CreateCompositor(GetAcceleratedWidget()); |
| 53 } | 50 } |
| 54 | 51 |
| 55 WindowTreeHostWin::~WindowTreeHostWin() { | 52 WindowTreeHostWin::~WindowTreeHostWin() { |
| 56 DestroyCompositor(); | 53 DestroyCompositor(); |
| 57 DestroyDispatcher(); | 54 DestroyDispatcher(); |
| 58 DestroyWindow(hwnd()); | 55 DestroyWindow(hwnd()); |
| 59 } | 56 } |
| 60 | 57 |
| 61 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() { | 58 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() { |
| 62 return hwnd(); | 59 return hwnd(); |
| 63 } | 60 } |
| 64 | 61 |
| 65 void WindowTreeHostWin::Show() { | 62 void WindowTreeHostWin::Show() { |
| 66 ShowWindow(hwnd(), SW_SHOWNORMAL); | 63 ShowWindow(hwnd(), SW_SHOWNORMAL); |
| 67 } | 64 } |
| 68 | 65 |
| 69 void WindowTreeHostWin::Hide() { | 66 void WindowTreeHostWin::Hide() { |
| 70 NOTIMPLEMENTED(); | 67 NOTIMPLEMENTED(); |
| 71 } | 68 } |
| 72 | 69 |
| 73 void WindowTreeHostWin::ToggleFullScreen() { | |
| 74 gfx::Rect target_rect; | |
| 75 if (!fullscreen_) { | |
| 76 fullscreen_ = true; | |
| 77 saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); | |
| 78 saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); | |
| 79 GetWindowRect(hwnd(), &saved_window_rect_); | |
| 80 SetWindowLong(hwnd(), GWL_STYLE, | |
| 81 saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); | |
| 82 SetWindowLong(hwnd(), GWL_EXSTYLE, | |
| 83 saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | | |
| 84 WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); | |
| 85 | |
| 86 MONITORINFO mi; | |
| 87 mi.cbSize = sizeof(mi); | |
| 88 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST), &mi); | |
| 89 target_rect = gfx::Rect(mi.rcMonitor); | |
| 90 } else { | |
| 91 fullscreen_ = false; | |
| 92 SetWindowLong(hwnd(), GWL_STYLE, saved_window_style_); | |
| 93 SetWindowLong(hwnd(), GWL_EXSTYLE, saved_window_ex_style_); | |
| 94 target_rect = gfx::Rect(saved_window_rect_); | |
| 95 } | |
| 96 SetWindowPos(hwnd(), | |
| 97 NULL, | |
| 98 target_rect.x(), | |
| 99 target_rect.y(), | |
| 100 target_rect.width(), | |
| 101 target_rect.height(), | |
| 102 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); | |
| 103 } | |
| 104 | |
| 105 gfx::Rect WindowTreeHostWin::GetBounds() const { | 70 gfx::Rect WindowTreeHostWin::GetBounds() const { |
| 106 RECT r; | 71 RECT r; |
| 107 GetClientRect(hwnd(), &r); | 72 GetClientRect(hwnd(), &r); |
| 108 return gfx::Rect(r); | 73 return gfx::Rect(r); |
| 109 } | 74 } |
| 110 | 75 |
| 111 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { | 76 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { |
| 112 if (fullscreen_) { | |
| 113 saved_window_rect_.right = saved_window_rect_.left + bounds.width(); | |
| 114 saved_window_rect_.bottom = saved_window_rect_.top + bounds.height(); | |
| 115 return; | |
| 116 } | |
| 117 RECT window_rect; | 77 RECT window_rect; |
| 118 window_rect.left = bounds.x(); | 78 window_rect.left = bounds.x(); |
| 119 window_rect.top = bounds.y(); | 79 window_rect.top = bounds.y(); |
| 120 window_rect.right = bounds.right() ; | 80 window_rect.right = bounds.right() ; |
| 121 window_rect.bottom = bounds.bottom(); | 81 window_rect.bottom = bounds.bottom(); |
| 122 AdjustWindowRectEx(&window_rect, | 82 AdjustWindowRectEx(&window_rect, |
| 123 GetWindowLong(hwnd(), GWL_STYLE), | 83 GetWindowLong(hwnd(), GWL_STYLE), |
| 124 FALSE, | 84 FALSE, |
| 125 GetWindowLong(hwnd(), GWL_EXSTYLE)); | 85 GetWindowLong(hwnd(), GWL_EXSTYLE)); |
| 126 SetWindowPos( | 86 SetWindowPos( |
| 127 hwnd(), | 87 hwnd(), |
| 128 NULL, | 88 NULL, |
| 129 window_rect.left, | 89 window_rect.left, |
| 130 window_rect.top, | 90 window_rect.top, |
| 131 window_rect.right - window_rect.left, | 91 window_rect.right - window_rect.left, |
| 132 window_rect.bottom - window_rect.top, | 92 window_rect.bottom - window_rect.top, |
| 133 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); | 93 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); |
| 134 | 94 |
| 135 // Explicity call OnHostResized when the scale has changed because | 95 // Explicity call OnHostResized when the scale has changed because |
| 136 // the window size may not have changed. | 96 // the window size may not have changed. |
| 137 float current_scale = compositor()->device_scale_factor(); | 97 float current_scale = compositor()->device_scale_factor(); |
| 138 float new_scale = gfx::Screen::GetScreenFor(window())-> | 98 float new_scale = gfx::Screen::GetScreenFor(window())-> |
| 139 GetDisplayNearestWindow(window()).device_scale_factor(); | 99 GetDisplayNearestWindow(window()).device_scale_factor(); |
| 140 if (current_scale != new_scale) | 100 if (current_scale != new_scale) |
| 141 OnHostResized(bounds.size()); | 101 OnHostResized(bounds.size()); |
| 142 } | 102 } |
| 143 | 103 |
| 144 gfx::Insets WindowTreeHostWin::GetInsets() const { | |
| 145 return gfx::Insets(); | |
| 146 } | |
| 147 | |
| 148 void WindowTreeHostWin::SetInsets(const gfx::Insets& insets) { | |
| 149 } | |
| 150 | |
| 151 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const { | 104 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const { |
| 152 RECT r; | 105 RECT r; |
| 153 GetClientRect(hwnd(), &r); | 106 GetClientRect(hwnd(), &r); |
| 154 return gfx::Point(r.left, r.top); | 107 return gfx::Point(r.left, r.top); |
| 155 } | 108 } |
| 156 | 109 |
| 157 | 110 |
| 158 void WindowTreeHostWin::SetCapture() { | 111 void WindowTreeHostWin::SetCapture() { |
| 159 if (!has_capture_) { | 112 if (!has_capture_) { |
| 160 has_capture_ = true; | 113 has_capture_ = true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 GetCursorPos(&pt); | 133 GetCursorPos(&pt); |
| 181 ScreenToClient(hwnd(), &pt); | 134 ScreenToClient(hwnd(), &pt); |
| 182 const gfx::Size size = GetBounds().size(); | 135 const gfx::Size size = GetBounds().size(); |
| 183 *location_return = | 136 *location_return = |
| 184 gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))), | 137 gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))), |
| 185 max(0, min(size.height(), static_cast<int>(pt.y)))); | 138 max(0, min(size.height(), static_cast<int>(pt.y)))); |
| 186 return (pt.x >= 0 && static_cast<int>(pt.x) < size.width() && | 139 return (pt.x >= 0 && static_cast<int>(pt.x) < size.width() && |
| 187 pt.y >= 0 && static_cast<int>(pt.y) < size.height()); | 140 pt.y >= 0 && static_cast<int>(pt.y) < size.height()); |
| 188 } | 141 } |
| 189 | 142 |
| 190 bool WindowTreeHostWin::ConfineCursorToRootWindow() { | |
| 191 RECT window_rect; | |
| 192 GetWindowRect(hwnd(), &window_rect); | |
| 193 return ClipCursor(&window_rect) != 0; | |
| 194 } | |
| 195 | |
| 196 void WindowTreeHostWin::UnConfineCursor() { | |
| 197 ClipCursor(NULL); | |
| 198 } | |
| 199 | |
| 200 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) { | 143 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) { |
| 201 // Custom web cursors are handled directly. | 144 // Custom web cursors are handled directly. |
| 202 if (native_cursor == ui::kCursorCustom) | 145 if (native_cursor == ui::kCursorCustom) |
| 203 return; | 146 return; |
| 204 | 147 |
| 205 ui::CursorLoaderWin cursor_loader; | 148 ui::CursorLoaderWin cursor_loader; |
| 206 cursor_loader.SetPlatformCursor(&native_cursor); | 149 cursor_loader.SetPlatformCursor(&native_cursor); |
| 207 ::SetCursor(native_cursor.platform()); | 150 ::SetCursor(native_cursor.platform()); |
| 208 } | 151 } |
| 209 | 152 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 namespace test { | 243 namespace test { |
| 301 | 244 |
| 302 // static | 245 // static |
| 303 void SetUsePopupAsRootWindowForTest(bool use) { | 246 void SetUsePopupAsRootWindowForTest(bool use) { |
| 304 use_popup_as_root_window_for_test = use; | 247 use_popup_as_root_window_for_test = use; |
| 305 } | 248 } |
| 306 | 249 |
| 307 } // namespace test | 250 } // namespace test |
| 308 | 251 |
| 309 } // namespace aura | 252 } // namespace aura |
| OLD | NEW |