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

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

Issue 9784012: Windows: Don't try to center a popup over a parent window when the popup is bigger than the parent. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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) 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/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.
17 void AdjustWindowToFit(HWND hwnd, const RECT& bounds, bool fit_to_monitor) { 17 void AdjustWindowToFit(HWND hwnd, const RECT& bounds, bool fit_to_monitor) {
18 if (fit_to_monitor) { 18 if (fit_to_monitor) {
19 // Get the monitor. 19 // Get the monitor.
20 HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); 20 HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST);
21 if (hmon) { 21 if (hmon) {
22 MONITORINFO mi; 22 MONITORINFO mi;
23 mi.cbSize = sizeof(mi); 23 mi.cbSize = sizeof(mi);
24 GetMonitorInfo(hmon, &mi); 24 GetMonitorInfo(hmon, &mi);
25 gfx::Rect window_rect(bounds); 25 gfx::Rect window_rect(bounds);
26 gfx::Rect monitor_rect(mi.rcWork); 26 gfx::Rect monitor_rect(mi.rcWork);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); 127 HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST);
128 if (monitor) { 128 if (monitor) {
129 MONITORINFO mi = {0}; 129 MONITORINFO mi = {0};
130 mi.cbSize = sizeof(mi); 130 mi.cbSize = sizeof(mi);
131 GetMonitorInfo(monitor, &mi); 131 GetMonitorInfo(monitor, &mi);
132 center_bounds = mi.rcWork; 132 center_bounds = mi.rcWork;
133 } else { 133 } else {
134 NOTREACHED() << "Unable to get default monitor"; 134 NOTREACHED() << "Unable to get default monitor";
135 } 135 }
136 } 136 }
137 window_bounds.left = center_bounds.left + 137
138 (center_bounds.right - center_bounds.left - pref.width()) / 2; 138 window_bounds.left = center_bounds.left;
139 if (pref.width() < (center_bounds.right - center_bounds.left)) {
140 window_bounds.left +=
141 (center_bounds.right - center_bounds.left - pref.width()) / 2;
142 }
139 window_bounds.right = window_bounds.left + pref.width(); 143 window_bounds.right = window_bounds.left + pref.width();
140 window_bounds.top = center_bounds.top + 144
141 (center_bounds.bottom - center_bounds.top - pref.height()) / 2; 145 window_bounds.top = center_bounds.top;
146 if (pref.height() < (center_bounds.bottom - center_bounds.top)) {
147 window_bounds.top +=
148 (center_bounds.bottom - center_bounds.top - pref.height()) / 2;
149 }
142 window_bounds.bottom = window_bounds.top + pref.height(); 150 window_bounds.bottom = window_bounds.top + pref.height();
143 151
144 // If we're centering a child window, we are positioning in client 152 // If we're centering a child window, we are positioning in client
145 // coordinates, and as such we need to offset the target rectangle by the 153 // coordinates, and as such we need to offset the target rectangle by the
146 // position of the parent window. 154 // position of the parent window.
147 if (::GetWindowLong(window, GWL_STYLE) & WS_CHILD) { 155 if (::GetWindowLong(window, GWL_STYLE) & WS_CHILD) {
148 DCHECK(parent && ::GetParent(window) == parent); 156 DCHECK(parent && ::GetParent(window) == parent);
149 POINT topleft = { window_bounds.left, window_bounds.top }; 157 POINT topleft = { window_bounds.left, window_bounds.top };
150 ::MapWindowPoints(HWND_DESKTOP, parent, &topleft, 1); 158 ::MapWindowPoints(HWND_DESKTOP, parent, &topleft, 1);
151 window_bounds.left = topleft.x; 159 window_bounds.left = topleft.x;
(...skipping 15 matching lines...) Expand all
167 if (base::i18n::IsRTL()) 175 if (base::i18n::IsRTL())
168 flags |= TPM_RIGHTALIGN; 176 flags |= TPM_RIGHTALIGN;
169 HMENU system_menu = GetSystemMenu(window, FALSE); 177 HMENU system_menu = GetSystemMenu(window, FALSE);
170 int command = TrackPopupMenu(system_menu, flags, screen_x, screen_y, 0, 178 int command = TrackPopupMenu(system_menu, flags, screen_x, screen_y, 0,
171 window, NULL); 179 window, NULL);
172 if (command) 180 if (command)
173 SendMessage(window, WM_SYSCOMMAND, command, 0); 181 SendMessage(window, WM_SYSCOMMAND, command, 0);
174 } 182 }
175 183
176 } // namespace ui 184 } // 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