Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: ui/base/win/hwnd_util.cc

Issue 9346026: For child windows, use parent coordinate system and bounds (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/win/hwnd_util.h" 5 #include "ui/base/win/hwnd_util.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "ui/gfx/rect.h" 9 #include "ui/gfx/rect.h"
10 #include "ui/gfx/size.h" 10 #include "ui/gfx/size.h"
11 11
12 namespace ui { 12 namespace ui {
13 13
14 namespace { 14 namespace {
15 15
16 // Adjust the window to fit, returning true if the window was resized or moved. 16 // Adjust the window to fit, returning true if the window was resized or moved.
17 bool AdjustWindowToFit(HWND hwnd, const RECT& bounds) { 17 bool AdjustWindowToFit(HWND window, HWND parent, const RECT& bounds) {
18 // Get the monitor. 18 // Get the monitor.
19 HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); 19 HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST);
20 if (!hmon) { 20 if (!hmon) {
21 NOTREACHED() << "Unable to find default monitor"; 21 NOTREACHED() << "Unable to find default monitor";
22 // No monitor available. 22 // No monitor available.
23 return false; 23 return false;
24 } 24 }
25 25
26 MONITORINFO mi; 26 MONITORINFO mi;
27 mi.cbSize = sizeof(mi); 27 mi.cbSize = sizeof(mi);
28 GetMonitorInfo(hmon, &mi); 28 GetMonitorInfo(hmon, &mi);
29 gfx::Rect window_rect(bounds); 29 gfx::Rect window_rect(bounds);
30 gfx::Rect monitor_rect(mi.rcWork); 30 gfx::Rect fit_bounds;
31 gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); 31 if (::GetWindowLong(window, GWL_STYLE) & WS_CHILD) {
32 RECT parent_rect;
33 ::GetWindowRect(parent, &parent_rect);
34 fit_bounds = parent_rect;
35 fit_bounds.Offset(-parent_rect.left, -parent_rect.top);
36 } else {
37 fit_bounds = mi.rcWork;
38 }
39 gfx::Rect new_window_rect = window_rect.AdjustToFit(fit_bounds);
32 if (!new_window_rect.Equals(window_rect)) { 40 if (!new_window_rect.Equals(window_rect)) {
33 // Window doesn't fit on monitor, move and possibly resize. 41 // Window doesn't fit on monitor, move and possibly resize.
34 SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), 42 SetWindowPos(window, 0, new_window_rect.x(), new_window_rect.y(),
35 new_window_rect.width(), new_window_rect.height(), 43 new_window_rect.width(), new_window_rect.height(),
36 SWP_NOACTIVATE | SWP_NOZORDER); 44 SWP_NOACTIVATE | SWP_NOZORDER);
37 return true; 45 return true;
38 } else { 46 } else {
39 return false; 47 return false;
40 } 48 }
41 } 49 }
42 50
43 } // namespace 51 } // namespace
44 52
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // for the window. 159 // for the window.
152 WINDOWINFO win_info = {0}; 160 WINDOWINFO win_info = {0};
153 win_info.cbSize = sizeof(WINDOWINFO); 161 win_info.cbSize = sizeof(WINDOWINFO);
154 GetWindowInfo(window, &win_info); 162 GetWindowInfo(window, &win_info);
155 163
156 // Calculate the window size needed for the content size. 164 // Calculate the window size needed for the content size.
157 165
158 if (!pref_is_client || 166 if (!pref_is_client ||
159 AdjustWindowRectEx(&window_bounds, win_info.dwStyle, FALSE, 167 AdjustWindowRectEx(&window_bounds, win_info.dwStyle, FALSE,
160 win_info.dwExStyle)) { 168 win_info.dwExStyle)) {
161 if (!AdjustWindowToFit(window, window_bounds)) { 169 if (!AdjustWindowToFit(window, parent, window_bounds)) {
162 // The window fits, reset the bounds. 170 // The window fits, reset the bounds.
163 SetWindowPos(window, 0, window_bounds.left, window_bounds.top, 171 SetWindowPos(window, 0, window_bounds.left, window_bounds.top,
164 window_bounds.right - window_bounds.left, 172 window_bounds.right - window_bounds.left,
165 window_bounds.bottom - window_bounds.top, 173 window_bounds.bottom - window_bounds.top,
166 SWP_NOACTIVATE | SWP_NOZORDER); 174 SWP_NOACTIVATE | SWP_NOZORDER);
167 } // else case, AdjustWindowToFit set the bounds for us. 175 } // else case, AdjustWindowToFit set the bounds for us.
168 } else { 176 } else {
169 NOTREACHED() << "Unable to adjust window to fit"; 177 NOTREACHED() << "Unable to adjust window to fit";
170 } 178 }
171 } 179 }
172 180
173 void CheckWindowCreated(HWND hwnd) { 181 void CheckWindowCreated(HWND hwnd) {
174 if (!hwnd) 182 if (!hwnd)
175 LOG_GETLASTERROR(FATAL); 183 LOG_GETLASTERROR(FATAL);
176 } 184 }
177 185
178 void ShowSystemMenu(HWND window, int screen_x, int screen_y) { 186 void ShowSystemMenu(HWND window, int screen_x, int screen_y) {
179 UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD; 187 UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD;
180 if (base::i18n::IsRTL()) 188 if (base::i18n::IsRTL())
181 flags |= TPM_RIGHTALIGN; 189 flags |= TPM_RIGHTALIGN;
182 HMENU system_menu = GetSystemMenu(window, FALSE); 190 HMENU system_menu = GetSystemMenu(window, FALSE);
183 int command = TrackPopupMenu(system_menu, flags, screen_x, screen_y, 0, 191 int command = TrackPopupMenu(system_menu, flags, screen_x, screen_y, 0,
184 window, NULL); 192 window, NULL);
185 if (command) 193 if (command)
186 SendMessage(window, WM_SYSCOMMAND, command, 0); 194 SendMessage(window, WM_SYSCOMMAND, command, 0);
187 } 195 }
188 196
189 } // namespace ui 197 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698