| 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/gfx/win/hwnd_util.h" | 5 #include "ui/gfx/win/hwnd_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/win/metro.h" | 9 #include "base/win/metro.h" |
| 10 #include "base/win/win_util.h" | 10 #include "base/win/win_util.h" |
| 11 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
| 12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Adjust the window to fit. | 19 // Adjust the window to fit. |
| 20 void AdjustWindowToFit(HWND hwnd, const RECT& bounds, bool fit_to_monitor) { | 20 void AdjustWindowToFit(HWND hwnd, const RECT& bounds, bool fit_to_monitor) { |
| 21 if (fit_to_monitor) { | 21 if (fit_to_monitor) { |
| 22 // Get the monitor. | 22 // Get the monitor. |
| 23 HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); | 23 HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); |
| 24 if (hmon) { | 24 if (hmon) { |
| 25 MONITORINFO mi; | 25 MONITORINFO mi; |
| 26 mi.cbSize = sizeof(mi); | 26 mi.cbSize = sizeof(mi); |
| 27 base::win::GetMonitorInfoWrapper(hmon, &mi); | 27 GetMonitorInfo(hmon, &mi); |
| 28 Rect window_rect(bounds); | 28 Rect window_rect(bounds); |
| 29 Rect monitor_rect(mi.rcWork); | 29 Rect monitor_rect(mi.rcWork); |
| 30 Rect new_window_rect = window_rect; | 30 Rect new_window_rect = window_rect; |
| 31 new_window_rect.AdjustToFit(monitor_rect); | 31 new_window_rect.AdjustToFit(monitor_rect); |
| 32 if (new_window_rect != window_rect) { | 32 if (new_window_rect != window_rect) { |
| 33 // Window doesn't fit on monitor, move and possibly resize. | 33 // Window doesn't fit on monitor, move and possibly resize. |
| 34 SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), | 34 SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), |
| 35 new_window_rect.width(), new_window_rect.height(), | 35 new_window_rect.width(), new_window_rect.height(), |
| 36 SWP_NOACTIVATE | SWP_NOZORDER); | 36 SWP_NOACTIVATE | SWP_NOZORDER); |
| 37 return; | 37 return; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // If there is a parent, center over the parents bounds. | 143 // If there is a parent, center over the parents bounds. |
| 144 ::GetWindowRect(parent, ¢er_bounds); | 144 ::GetWindowRect(parent, ¢er_bounds); |
| 145 } | 145 } |
| 146 | 146 |
| 147 if (::IsRectEmpty(¢er_bounds)) { | 147 if (::IsRectEmpty(¢er_bounds)) { |
| 148 // No parent or no parent rect. Center over the monitor the window is on. | 148 // No parent or no parent rect. Center over the monitor the window is on. |
| 149 HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); | 149 HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); |
| 150 if (monitor) { | 150 if (monitor) { |
| 151 MONITORINFO mi = {0}; | 151 MONITORINFO mi = {0}; |
| 152 mi.cbSize = sizeof(mi); | 152 mi.cbSize = sizeof(mi); |
| 153 base::win::GetMonitorInfoWrapper(monitor, &mi); | 153 GetMonitorInfo(monitor, &mi); |
| 154 center_bounds = mi.rcWork; | 154 center_bounds = mi.rcWork; |
| 155 } else { | 155 } else { |
| 156 NOTREACHED() << "Unable to get default monitor"; | 156 NOTREACHED() << "Unable to get default monitor"; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 window_bounds.left = center_bounds.left; | 160 window_bounds.left = center_bounds.left; |
| 161 if (pref.width() < (center_bounds.right - center_bounds.left)) { | 161 if (pref.width() < (center_bounds.right - center_bounds.left)) { |
| 162 window_bounds.left += | 162 window_bounds.left += |
| 163 (center_bounds.right - center_bounds.left - pref.width()) / 2; | 163 (center_bounds.right - center_bounds.left - pref.width()) / 2; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 HMODULE metro = base::win::GetMetroModule(); | 235 HMODULE metro = base::win::GetMetroModule(); |
| 236 if (!metro) | 236 if (!metro) |
| 237 return get_real_hwnd ? ::GetDesktopWindow() : HWND_DESKTOP; | 237 return get_real_hwnd ? ::GetDesktopWindow() : HWND_DESKTOP; |
| 238 // In windows 8 metro-mode the root window is not the desktop. | 238 // In windows 8 metro-mode the root window is not the desktop. |
| 239 RootWindow root_window = | 239 RootWindow root_window = |
| 240 reinterpret_cast<RootWindow>(::GetProcAddress(metro, "GetRootWindow")); | 240 reinterpret_cast<RootWindow>(::GetProcAddress(metro, "GetRootWindow")); |
| 241 return root_window(); | 241 return root_window(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace gfx | 244 } // namespace gfx |
| OLD | NEW |