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/views/win/hwnd_message_handler.h" | 5 #include "ui/views/win/hwnd_message_handler.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 431 |
432 // Modal dialog windows disable their owner windows; re-enable them now so | 432 // Modal dialog windows disable their owner windows; re-enable them now so |
433 // they can activate as foreground windows upon this window's destruction. | 433 // they can activate as foreground windows upon this window's destruction. |
434 RestoreEnabledIfNecessary(); | 434 RestoreEnabledIfNecessary(); |
435 | 435 |
436 if (!close_widget_factory_.HasWeakPtrs()) { | 436 if (!close_widget_factory_.HasWeakPtrs()) { |
437 // And we delay the close so that if we are called from an ATL callback, | 437 // And we delay the close so that if we are called from an ATL callback, |
438 // we don't destroy the window before the callback returned (as the caller | 438 // we don't destroy the window before the callback returned (as the caller |
439 // may delete ourselves on destroy and the ATL callback would still | 439 // may delete ourselves on destroy and the ATL callback would still |
440 // dereference us when the callback returns). | 440 // dereference us when the callback returns). |
441 MessageLoop::current()->PostTask( | 441 base::MessageLoop::current()->PostTask( |
442 FROM_HERE, | 442 FROM_HERE, |
443 base::Bind(&HWNDMessageHandler::CloseNow, | 443 base::Bind(&HWNDMessageHandler::CloseNow, |
444 close_widget_factory_.GetWeakPtr())); | 444 close_widget_factory_.GetWeakPtr())); |
445 } | 445 } |
446 } | 446 } |
447 | 447 |
448 void HWNDMessageHandler::CloseNow() { | 448 void HWNDMessageHandler::CloseNow() { |
449 // We may already have been destroyed if the selection resulted in a tab | 449 // We may already have been destroyed if the selection resulted in a tab |
450 // switch which will have reactivated the browser window and closed us, so | 450 // switch which will have reactivated the browser window and closed us, so |
451 // we need to check to see if we're still a window before trying to destroy | 451 // we need to check to see if we're still a window before trying to destroy |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 // We must update the back-buffer immediately, since Windows' handling of | 779 // We must update the back-buffer immediately, since Windows' handling of |
780 // invalid rects is somewhat mysterious. | 780 // invalid rects is somewhat mysterious. |
781 invalid_rect_.Union(rect); | 781 invalid_rect_.Union(rect); |
782 | 782 |
783 // In some situations, such as drag and drop, when Windows itself runs a | 783 // In some situations, such as drag and drop, when Windows itself runs a |
784 // nested message loop our message loop appears to be starved and we don't | 784 // nested message loop our message loop appears to be starved and we don't |
785 // receive calls to DidProcessMessage(). This only seems to affect layered | 785 // receive calls to DidProcessMessage(). This only seems to affect layered |
786 // windows, so we schedule a redraw manually using a task, since those never | 786 // windows, so we schedule a redraw manually using a task, since those never |
787 // seem to be starved. Also, wtf. | 787 // seem to be starved. Also, wtf. |
788 if (!paint_layered_window_factory_.HasWeakPtrs()) { | 788 if (!paint_layered_window_factory_.HasWeakPtrs()) { |
789 MessageLoop::current()->PostTask( | 789 base::MessageLoop::current()->PostTask( |
790 FROM_HERE, | 790 FROM_HERE, |
791 base::Bind(&HWNDMessageHandler::RedrawLayeredWindowContents, | 791 base::Bind(&HWNDMessageHandler::RedrawLayeredWindowContents, |
792 paint_layered_window_factory_.GetWeakPtr())); | 792 paint_layered_window_factory_.GetWeakPtr())); |
793 } | 793 } |
794 } else { | 794 } else { |
795 // InvalidateRect() expects client coordinates. | 795 // InvalidateRect() expects client coordinates. |
796 RECT r = rect.ToRECT(); | 796 RECT r = rect.ToRECT(); |
797 InvalidateRect(hwnd(), &r, FALSE); | 797 InvalidateRect(hwnd(), &r, FALSE); |
798 } | 798 } |
799 } | 799 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 if (!ProcessWindowMessage(window, message, w_param, l_param, result)) | 863 if (!ProcessWindowMessage(window, message, w_param, l_param, result)) |
864 result = DefWindowProc(window, message, w_param, l_param); | 864 result = DefWindowProc(window, message, w_param, l_param); |
865 | 865 |
866 // DefWindowProc() may have destroyed the window in a nested message loop. | 866 // DefWindowProc() may have destroyed the window in a nested message loop. |
867 if (!::IsWindow(window)) | 867 if (!::IsWindow(window)) |
868 return result; | 868 return result; |
869 | 869 |
870 if (delegate_) | 870 if (delegate_) |
871 delegate_->PostHandleMSG(message, w_param, l_param); | 871 delegate_->PostHandleMSG(message, w_param, l_param); |
872 if (message == WM_NCDESTROY) { | 872 if (message == WM_NCDESTROY) { |
873 MessageLoopForUI::current()->RemoveObserver(this); | 873 base::MessageLoopForUI::current()->RemoveObserver(this); |
874 if (delegate_) | 874 if (delegate_) |
875 delegate_->HandleDestroyed(); | 875 delegate_->HandleDestroyed(); |
876 } | 876 } |
877 | 877 |
878 // Only top level widget should store/restore focus. | 878 // Only top level widget should store/restore focus. |
879 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) | 879 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) |
880 PostProcessActivateMessage(LOWORD(w_param)); | 880 PostProcessActivateMessage(LOWORD(w_param)); |
881 if (message == WM_ENABLE && restore_focus_when_enabled_) { | 881 if (message == WM_ENABLE && restore_focus_when_enabled_) { |
882 // This path should be executed only for top level as | 882 // This path should be executed only for top level as |
883 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. | 883 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 | 1265 |
1266 // We need to allow the delegate to size its contents since the window may not | 1266 // We need to allow the delegate to size its contents since the window may not |
1267 // receive a size notification when its initial bounds are specified at window | 1267 // receive a size notification when its initial bounds are specified at window |
1268 // creation time. | 1268 // creation time. |
1269 ClientAreaSizeChanged(); | 1269 ClientAreaSizeChanged(); |
1270 | 1270 |
1271 // We need to add ourselves as a message loop observer so that we can repaint | 1271 // We need to add ourselves as a message loop observer so that we can repaint |
1272 // aggressively if the contents of our window become invalid. Unfortunately | 1272 // aggressively if the contents of our window become invalid. Unfortunately |
1273 // WM_PAINT messages are starved and we get flickery redrawing when resizing | 1273 // WM_PAINT messages are starved and we get flickery redrawing when resizing |
1274 // if we do not do this. | 1274 // if we do not do this. |
1275 MessageLoopForUI::current()->AddObserver(this); | 1275 base::MessageLoopForUI::current()->AddObserver(this); |
1276 | 1276 |
1277 delegate_->HandleCreate(); | 1277 delegate_->HandleCreate(); |
1278 | 1278 |
1279 // TODO(beng): move more of NWW::OnCreate here. | 1279 // TODO(beng): move more of NWW::OnCreate here. |
1280 return 0; | 1280 return 0; |
1281 } | 1281 } |
1282 | 1282 |
1283 void HWNDMessageHandler::OnDestroy() { | 1283 void HWNDMessageHandler::OnDestroy() { |
1284 delegate_->HandleDestroying(); | 1284 delegate_->HandleDestroying(); |
1285 } | 1285 } |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 // WARNING! Don't set SWP_FRAMECHANGED here, it breaks moving the child | 2071 // WARNING! Don't set SWP_FRAMECHANGED here, it breaks moving the child |
2072 // HWNDs for some reason. | 2072 // HWNDs for some reason. |
2073 window_pos->flags &= ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW); | 2073 window_pos->flags &= ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW); |
2074 window_pos->flags |= SWP_NOCOPYBITS; | 2074 window_pos->flags |= SWP_NOCOPYBITS; |
2075 | 2075 |
2076 // Now ignore all immediately-following SetWindowPos() changes. Windows | 2076 // Now ignore all immediately-following SetWindowPos() changes. Windows |
2077 // likes to (incorrectly) recalculate what our position/size should be | 2077 // likes to (incorrectly) recalculate what our position/size should be |
2078 // and send us further updates. | 2078 // and send us further updates. |
2079 ignore_window_pos_changes_ = true; | 2079 ignore_window_pos_changes_ = true; |
2080 DCHECK(!ignore_pos_changes_factory_.HasWeakPtrs()); | 2080 DCHECK(!ignore_pos_changes_factory_.HasWeakPtrs()); |
2081 MessageLoop::current()->PostTask( | 2081 base::MessageLoop::current()->PostTask( |
2082 FROM_HERE, | 2082 FROM_HERE, |
2083 base::Bind(&HWNDMessageHandler::StopIgnoringPosChanges, | 2083 base::Bind(&HWNDMessageHandler::StopIgnoringPosChanges, |
2084 ignore_pos_changes_factory_.GetWeakPtr())); | 2084 ignore_pos_changes_factory_.GetWeakPtr())); |
2085 } | 2085 } |
2086 last_monitor_ = monitor; | 2086 last_monitor_ = monitor; |
2087 last_monitor_rect_ = monitor_rect; | 2087 last_monitor_rect_ = monitor_rect; |
2088 last_work_area_ = work_area; | 2088 last_work_area_ = work_area; |
2089 } | 2089 } |
2090 } | 2090 } |
2091 | 2091 |
(...skipping 15 matching lines...) Expand all Loading... |
2107 DwmExtendFrameIntoClientArea(hwnd(), &m); | 2107 DwmExtendFrameIntoClientArea(hwnd(), &m); |
2108 } | 2108 } |
2109 if (window_pos->flags & SWP_SHOWWINDOW) | 2109 if (window_pos->flags & SWP_SHOWWINDOW) |
2110 delegate_->HandleVisibilityChanged(true); | 2110 delegate_->HandleVisibilityChanged(true); |
2111 else if (window_pos->flags & SWP_HIDEWINDOW) | 2111 else if (window_pos->flags & SWP_HIDEWINDOW) |
2112 delegate_->HandleVisibilityChanged(false); | 2112 delegate_->HandleVisibilityChanged(false); |
2113 SetMsgHandled(FALSE); | 2113 SetMsgHandled(FALSE); |
2114 } | 2114 } |
2115 | 2115 |
2116 } // namespace views | 2116 } // namespace views |
OLD | NEW |