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

Side by Side Diff: views/window/window_win.cc

Issue 7015051: Re-land: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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 | « views/window/window_win.h ('k') | 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 "views/window/window_win.h" 5 #include "views/window/window_win.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 private: 228 private:
229 // The window having its style changed. 229 // The window having its style changed.
230 WindowWin* window_; 230 WindowWin* window_;
231 }; 231 };
232 232
233 //////////////////////////////////////////////////////////////////////////////// 233 ////////////////////////////////////////////////////////////////////////////////
234 // WindowWin, public: 234 // WindowWin, public:
235 235
236 WindowWin::WindowWin(internal::NativeWindowDelegate* delegate)
237 : WidgetWin(delegate->AsNativeWidgetDelegate()),
238 delegate_(delegate),
239 focus_on_creation_(true),
240 restored_enabled_(false),
241 fullscreen_(false),
242 is_active_(false),
243 lock_updates_(false),
244 saved_window_style_(0),
245 ignore_window_pos_changes_(false),
246 ignore_pos_changes_factory_(this),
247 force_hidden_count_(0),
248 is_right_mouse_pressed_on_caption_(false),
249 last_monitor_(NULL),
250 is_in_size_move_(false) {
251 is_window_ = true;
252 // Initialize these values to 0 so that subclasses can override the default
253 // behavior before calling Init.
254 set_window_style(0);
255 set_window_ex_style(0);
256 }
257
258
259
236 WindowWin::~WindowWin() { 260 WindowWin::~WindowWin() {
237 } 261 }
238 262
239 void WindowWin::Show(int show_state) { 263 void WindowWin::Show(int show_state) {
240 ShowWindow(show_state); 264 ShowWindow(show_state);
241 // When launched from certain programs like bash and Windows Live Messenger, 265 // When launched from certain programs like bash and Windows Live Messenger,
242 // show_state is set to SW_HIDE, so we need to correct that condition. We 266 // show_state is set to SW_HIDE, so we need to correct that condition. We
243 // don't just change show_state to SW_SHOWNORMAL because MSDN says we must 267 // don't just change show_state to SW_SHOWNORMAL because MSDN says we must
244 // always first call ShowWindow with the specified value from STARTUPINFO, 268 // always first call ShowWindow with the specified value from STARTUPINFO,
245 // otherwise all future ShowWindow calls will be ignored (!!#@@#!). Instead, 269 // otherwise all future ShowWindow calls will be ignored (!!#@@#!). Instead,
(...skipping 30 matching lines...) Expand all
276 NONCLIENTMETRICS ncm; 300 NONCLIENTMETRICS ncm;
277 base::win::GetNonClientMetrics(&ncm); 301 base::win::GetNonClientMetrics(&ncm);
278 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); 302 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
279 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 303 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
280 return gfx::Font(caption_font); 304 return gfx::Font(caption_font);
281 } 305 }
282 306
283 /////////////////////////////////////////////////////////////////////////////// 307 ///////////////////////////////////////////////////////////////////////////////
284 // WindowWin, protected: 308 // WindowWin, protected:
285 309
286 WindowWin::WindowWin()
287 : ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)),
288 focus_on_creation_(true),
289 restored_enabled_(false),
290 fullscreen_(false),
291 is_active_(false),
292 lock_updates_(false),
293 saved_window_style_(0),
294 ignore_window_pos_changes_(false),
295 ignore_pos_changes_factory_(this),
296 force_hidden_count_(0),
297 is_right_mouse_pressed_on_caption_(false),
298 last_monitor_(NULL),
299 is_in_size_move_(false) {
300 SetNativeWindow(this);
301 is_window_ = true;
302 // Initialize these values to 0 so that subclasses can override the default
303 // behavior before calling Init.
304 set_window_style(0);
305 set_window_ex_style(0);
306 }
307
308 gfx::Insets WindowWin::GetClientAreaInsets() const { 310 gfx::Insets WindowWin::GetClientAreaInsets() const {
309 // Returning an empty Insets object causes the default handling in 311 // Returning an empty Insets object causes the default handling in
310 // WidgetWin::OnNCCalcSize() to be invoked. 312 // WidgetWin::OnNCCalcSize() to be invoked.
311 if (delegate_->IsUsingNativeFrame()) 313 if (delegate_->IsUsingNativeFrame())
312 return gfx::Insets(); 314 return gfx::Insets();
313 315
314 if (IsMaximized()) { 316 if (IsMaximized()) {
315 // Windows automatically adds a standard width border to all sides when a 317 // Windows automatically adds a standard width border to all sides when a
316 // window is maximized. 318 // window is maximized.
317 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); 319 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 366
365 LRESULT WindowWin::OnAppCommand(HWND window, short app_command, WORD device, 367 LRESULT WindowWin::OnAppCommand(HWND window, short app_command, WORD device,
366 int keystate) { 368 int keystate) {
367 // We treat APPCOMMAND ids as an extension of our command namespace, and just 369 // We treat APPCOMMAND ids as an extension of our command namespace, and just
368 // let the delegate figure out what to do... 370 // let the delegate figure out what to do...
369 return GetWindow()->window_delegate()->ExecuteWindowsCommand(app_command) || 371 return GetWindow()->window_delegate()->ExecuteWindowsCommand(app_command) ||
370 WidgetWin::OnAppCommand(window, app_command, device, keystate); 372 WidgetWin::OnAppCommand(window, app_command, device, keystate);
371 } 373 }
372 374
373 void WindowWin::OnClose() { 375 void WindowWin::OnClose() {
374 GetWindow()->CloseWindow(); 376 GetWindow()->Close();
375 } 377 }
376 378
377 void WindowWin::OnCommand(UINT notification_code, int command_id, HWND window) { 379 void WindowWin::OnCommand(UINT notification_code, int command_id, HWND window) {
378 // If the notification code is > 1 it means it is control specific and we 380 // If the notification code is > 1 it means it is control specific and we
379 // should ignore it. 381 // should ignore it.
380 if (notification_code > 1 || 382 if (notification_code > 1 ||
381 GetWindow()->window_delegate()->ExecuteWindowsCommand(command_id)) { 383 GetWindow()->window_delegate()->ExecuteWindowsCommand(command_id)) {
382 WidgetWin::OnCommand(notification_code, command_id, window); 384 WidgetWin::OnCommand(notification_code, command_id, window);
383 } 385 }
384 } 386 }
(...skipping 20 matching lines...) Expand all
405 is_in_size_move_ = true; 407 is_in_size_move_ = true;
406 WidgetWin::OnEnterSizeMove(); 408 WidgetWin::OnEnterSizeMove();
407 delegate_->OnNativeWindowBeginUserBoundsChange(); 409 delegate_->OnNativeWindowBeginUserBoundsChange();
408 } 410 }
409 411
410 void WindowWin::OnExitSizeMove() { 412 void WindowWin::OnExitSizeMove() {
411 is_in_size_move_ = false; 413 is_in_size_move_ = false;
412 WidgetWin::OnExitSizeMove(); 414 WidgetWin::OnExitSizeMove();
413 delegate_->OnNativeWindowEndUserBoundsChange(); 415 delegate_->OnNativeWindowEndUserBoundsChange();
414 416
415 if (!GetThemeProvider()->ShouldUseNativeFrame()) { 417 if (!ShouldUseNativeFrame()) {
416 // Sending SWP_FRAMECHANGED forces a non-client repaint, which fixes the 418 // Sending SWP_FRAMECHANGED forces a non-client repaint, which fixes the
417 // glitch in rendering the bottom pixel of the window caused by us 419 // glitch in rendering the bottom pixel of the window caused by us
418 // offsetting the client rect there (See comment in GetClientAreaInsets()). 420 // offsetting the client rect there (See comment in GetClientAreaInsets()).
419 SetWindowPos(NULL, 0, 0, 0, 0, 421 SetWindowPos(NULL, 0, 0, 0, 0,
420 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER); 422 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
421 } 423 }
422 } 424 }
423 425
424 void WindowWin::OnFinalMessage(HWND window) { 426 void WindowWin::OnFinalMessage(HWND window) {
425 delegate_->OnNativeWindowDestroyed(); 427 delegate_->OnNativeWindowDestroyed();
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 768
767 // Handle SC_KEYMENU, which means that the user has pressed the ALT 769 // Handle SC_KEYMENU, which means that the user has pressed the ALT
768 // key and released it, so we should focus the menu bar. 770 // key and released it, so we should focus the menu bar.
769 if ((notification_code & sc_mask) == SC_KEYMENU && click.x == 0) { 771 if ((notification_code & sc_mask) == SC_KEYMENU && click.x == 0) {
770 // Retrieve the status of shift and control keys to prevent consuming 772 // Retrieve the status of shift and control keys to prevent consuming
771 // shift+alt keys, which are used by Windows to change input languages. 773 // shift+alt keys, which are used by Windows to change input languages.
772 Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU), 774 Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU),
773 !!(GetKeyState(VK_SHIFT) & 0x8000), 775 !!(GetKeyState(VK_SHIFT) & 0x8000),
774 !!(GetKeyState(VK_CONTROL) & 0x8000), 776 !!(GetKeyState(VK_CONTROL) & 0x8000),
775 false); 777 false);
776 GetFocusManager()->ProcessAccelerator(accelerator); 778 AsNativeWidget()->GetWidget()->GetFocusManager()->
779 ProcessAccelerator(accelerator);
777 return; 780 return;
778 } 781 }
779 782
780 // If the delegate can't handle it, the system implementation will be called. 783 // If the delegate can't handle it, the system implementation will be called.
781 if (!delegate_->ExecuteCommand(notification_code)) { 784 if (!delegate_->ExecuteCommand(notification_code)) {
782 DefWindowProc(GetNativeView(), WM_SYSCOMMAND, notification_code, 785 DefWindowProc(GetNativeView(), WM_SYSCOMMAND, notification_code,
783 MAKELPARAM(click.x, click.y)); 786 MAKELPARAM(click.x, click.y));
784 } 787 }
785 } 788 }
786 789
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 } else { 888 } else {
886 // The window does not get keyboard messages unless we focus it, not sure 889 // The window does not get keyboard messages unless we focus it, not sure
887 // why. 890 // why.
888 SetFocus(GetNativeView()); 891 SetFocus(GetNativeView());
889 } 892 }
890 } 893 }
891 894
892 //////////////////////////////////////////////////////////////////////////////// 895 ////////////////////////////////////////////////////////////////////////////////
893 // WindowWin, NativeWindow implementation: 896 // WindowWin, NativeWindow implementation:
894 897
898 Window* WindowWin::GetWindow() {
899 return delegate_->AsWindow();
900 }
901
902 const Window* WindowWin::GetWindow() const {
903 return delegate_->AsWindow();
904 }
905
895 NativeWidget* WindowWin::AsNativeWidget() { 906 NativeWidget* WindowWin::AsNativeWidget() {
896 return this; 907 return this;
897 } 908 }
898 909
899 const NativeWidget* WindowWin::AsNativeWidget() const { 910 const NativeWidget* WindowWin::AsNativeWidget() const {
900 return this; 911 return this;
901 } 912 }
902 913
903 gfx::Rect WindowWin::GetRestoredBounds() const { 914 gfx::Rect WindowWin::GetRestoredBounds() const {
904 // If we're in fullscreen mode, we've changed the normal bounds to the monitor 915 // If we're in fullscreen mode, we've changed the normal bounds to the monitor
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1167
1157 bool WindowWin::IsFullscreen() const { 1168 bool WindowWin::IsFullscreen() const {
1158 return fullscreen_; 1169 return fullscreen_;
1159 } 1170 }
1160 1171
1161 void WindowWin::SetAlwaysOnTop(bool always_on_top) { 1172 void WindowWin::SetAlwaysOnTop(bool always_on_top) {
1162 ::SetWindowPos(GetNativeView(), always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 1173 ::SetWindowPos(GetNativeView(), always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST,
1163 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); 1174 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1164 } 1175 }
1165 1176
1166 bool WindowWin::IsAppWindow() const {
1167 return false;
1168 }
1169
1170 void WindowWin::SetUseDragFrame(bool use_drag_frame) { 1177 void WindowWin::SetUseDragFrame(bool use_drag_frame) {
1171 if (use_drag_frame) { 1178 if (use_drag_frame) {
1172 // Make the frame slightly transparent during the drag operation. 1179 // Make the frame slightly transparent during the drag operation.
1173 drag_frame_saved_window_style_ = GetWindowLong(GWL_STYLE); 1180 drag_frame_saved_window_style_ = GetWindowLong(GWL_STYLE);
1174 drag_frame_saved_window_ex_style_ = GetWindowLong(GWL_EXSTYLE); 1181 drag_frame_saved_window_ex_style_ = GetWindowLong(GWL_EXSTYLE);
1175 SetWindowLong(GWL_EXSTYLE, 1182 SetWindowLong(GWL_EXSTYLE,
1176 drag_frame_saved_window_ex_style_ | WS_EX_LAYERED); 1183 drag_frame_saved_window_ex_style_ | WS_EX_LAYERED);
1177 // Remove the captions tyle so the window doesn't have window controls for a 1184 // Remove the captions tyle so the window doesn't have window controls for a
1178 // more "transparent" look. 1185 // more "transparent" look.
1179 SetWindowLong(GWL_STYLE, drag_frame_saved_window_style_ & ~WS_CAPTION); 1186 SetWindowLong(GWL_STYLE, drag_frame_saved_window_style_ & ~WS_CAPTION);
1180 SetLayeredWindowAttributes(GetNativeWindow(), RGB(0xFF, 0xFF, 0xFF), 1187 SetLayeredWindowAttributes(GetNativeWindow(), RGB(0xFF, 0xFF, 0xFF),
1181 kDragFrameWindowAlpha, LWA_ALPHA); 1188 kDragFrameWindowAlpha, LWA_ALPHA);
1182 } else { 1189 } else {
1183 SetWindowLong(GWL_STYLE, drag_frame_saved_window_style_); 1190 SetWindowLong(GWL_STYLE, drag_frame_saved_window_style_);
1184 SetWindowLong(GWL_EXSTYLE, drag_frame_saved_window_ex_style_); 1191 SetWindowLong(GWL_EXSTYLE, drag_frame_saved_window_ex_style_);
1185 } 1192 }
1186 } 1193 }
1187 1194
1188 NonClientFrameView* WindowWin::CreateFrameViewForWindow() { 1195 NonClientFrameView* WindowWin::CreateFrameViewForWindow() {
1189 if (ShouldUseNativeFrame()) 1196 if (ShouldUseNativeFrame())
1190 return new NativeFrameView(this); 1197 return new NativeFrameView(GetWindow());
1191 return new CustomFrameView(this); 1198 return new CustomFrameView(GetWindow());
1192 } 1199 }
1193 1200
1194 void WindowWin::UpdateFrameAfterFrameChange() { 1201 void WindowWin::UpdateFrameAfterFrameChange() {
1195 // We've either gained or lost a custom window region, so reset it now. 1202 // We've either gained or lost a custom window region, so reset it now.
1196 ResetWindowRegion(true); 1203 ResetWindowRegion(true);
1197 } 1204 }
1198 1205
1199 gfx::NativeWindow WindowWin::GetNativeWindow() const { 1206 gfx::NativeWindow WindowWin::GetNativeWindow() const {
1200 return GetNativeView(); 1207 return GetNativeView();
1201 } 1208 }
1202 1209
1203 bool WindowWin::ShouldUseNativeFrame() const { 1210 bool WindowWin::ShouldUseNativeFrame() const {
1204 ui::ThemeProvider* tp = GetThemeProvider(); 1211 return WidgetWin::IsAeroGlassEnabled();
1205 if (!tp)
1206 return WidgetWin::IsAeroGlassEnabled();
1207 return tp->ShouldUseNativeFrame();
1208 } 1212 }
1209 1213
1210 void WindowWin::FrameTypeChanged() { 1214 void WindowWin::FrameTypeChanged() {
1211 // Called when the frame type could possibly be changing (theme change or 1215 // Called when the frame type could possibly be changing (theme change or
1212 // DWM composition change). 1216 // DWM composition change).
1213 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 1217 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
1214 // We need to toggle the rendering policy of the DWM/glass frame as we 1218 // We need to toggle the rendering policy of the DWM/glass frame as we
1215 // change from opaque to glass. "Non client rendering enabled" means that 1219 // change from opaque to glass. "Non client rendering enabled" means that
1216 // the DWM's glass non-client rendering is enabled, which is why 1220 // the DWM's glass non-client rendering is enabled, which is why
1217 // DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the 1221 // DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 // it from doing so. 1341 // it from doing so.
1338 ScopedRedrawLock lock(this); 1342 ScopedRedrawLock lock(this);
1339 return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0); 1343 return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0);
1340 } 1344 }
1341 1345
1342 void WindowWin::ExecuteSystemMenuCommand(int command) { 1346 void WindowWin::ExecuteSystemMenuCommand(int command) {
1343 if (command) 1347 if (command)
1344 SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0); 1348 SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0);
1345 } 1349 }
1346 1350
1347 namespace {
1348 BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) {
1349 NativeWidget* native_widget =
1350 NativeWidget::GetNativeWidgetForNativeView(hwnd);
1351 if (native_widget)
1352 Window::CloseSecondaryWidget(native_widget->GetWidget());
1353 return TRUE;
1354 }
1355 } // namespace
1356
1357 void Window::CloseAllSecondaryWindows() {
1358 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0);
1359 }
1360
1361 //////////////////////////////////////////////////////////////////////////////// 1351 ////////////////////////////////////////////////////////////////////////////////
1362 // NativeWindow, public: 1352 // NativeWindow, public:
1363 1353
1364 // static 1354 // static
1365 Window* NativeWindow::CreateNativeWindow() { 1355 NativeWindow* NativeWindow::CreateNativeWindow(
1366 return new WindowWin; 1356 internal::NativeWindowDelegate* delegate) {
1357 return new WindowWin(delegate);
1367 } 1358 }
1368 1359
1369 } // namespace views 1360 } // namespace views
OLDNEW
« no previous file with comments | « views/window/window_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698