| 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 <oleacc.h> | 8 #include <oleacc.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <wtsapi32.h> | 10 #include <wtsapi32.h> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "ui/gfx/icon_util.h" | 28 #include "ui/gfx/icon_util.h" |
| 29 #include "ui/gfx/insets.h" | 29 #include "ui/gfx/insets.h" |
| 30 #include "ui/gfx/path.h" | 30 #include "ui/gfx/path.h" |
| 31 #include "ui/gfx/path_win.h" | 31 #include "ui/gfx/path_win.h" |
| 32 #include "ui/gfx/screen.h" | 32 #include "ui/gfx/screen.h" |
| 33 #include "ui/gfx/win/dpi.h" | 33 #include "ui/gfx/win/dpi.h" |
| 34 #include "ui/gfx/win/hwnd_util.h" | 34 #include "ui/gfx/win/hwnd_util.h" |
| 35 #include "ui/native_theme/native_theme_win.h" | 35 #include "ui/native_theme/native_theme_win.h" |
| 36 #include "ui/views/views_delegate.h" | 36 #include "ui/views/views_delegate.h" |
| 37 #include "ui/views/widget/monitor_win.h" | 37 #include "ui/views/widget/monitor_win.h" |
| 38 #include "ui/views/widget/native_widget_win.h" | |
| 39 #include "ui/views/widget/widget_hwnd_utils.h" | 38 #include "ui/views/widget/widget_hwnd_utils.h" |
| 40 #include "ui/views/win/appbar.h" | 39 #include "ui/views/win/appbar.h" |
| 41 #include "ui/views/win/fullscreen_handler.h" | 40 #include "ui/views/win/fullscreen_handler.h" |
| 42 #include "ui/views/win/hwnd_message_handler_delegate.h" | 41 #include "ui/views/win/hwnd_message_handler_delegate.h" |
| 43 #include "ui/views/win/scoped_fullscreen_visibility.h" | 42 #include "ui/views/win/scoped_fullscreen_visibility.h" |
| 44 | 43 |
| 45 #if !defined(USE_AURA) | 44 #if !defined(USE_AURA) |
| 46 #include "ui/views/accessibility/native_view_accessibility_win.h" | 45 #include "ui/views/accessibility/native_view_accessibility_win.h" |
| 47 #include "ui/views/widget/child_window_message_processor.h" | 46 #include "ui/views/widget/child_window_message_processor.h" |
| 48 #endif | 47 #endif |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 | 935 |
| 937 LRESULT HWNDMessageHandler::OnWndProc(UINT message, | 936 LRESULT HWNDMessageHandler::OnWndProc(UINT message, |
| 938 WPARAM w_param, | 937 WPARAM w_param, |
| 939 LPARAM l_param) { | 938 LPARAM l_param) { |
| 940 HWND window = hwnd(); | 939 HWND window = hwnd(); |
| 941 LRESULT result = 0; | 940 LRESULT result = 0; |
| 942 | 941 |
| 943 if (delegate_ && delegate_->PreHandleMSG(message, w_param, l_param, &result)) | 942 if (delegate_ && delegate_->PreHandleMSG(message, w_param, l_param, &result)) |
| 944 return result; | 943 return result; |
| 945 | 944 |
| 946 #if !defined(USE_AURA) | |
| 947 // First allow messages sent by child controls to be processed directly by | |
| 948 // their associated views. If such a view is present, it will handle the | |
| 949 // message *instead of* this NativeWidgetWin. | |
| 950 if (ProcessChildWindowMessage(message, w_param, l_param, &result)) | |
| 951 return result; | |
| 952 #endif | |
| 953 | |
| 954 // Otherwise we handle everything else. | 945 // Otherwise we handle everything else. |
| 955 // NOTE: We inline ProcessWindowMessage() as 'this' may be destroyed during | 946 // NOTE: We inline ProcessWindowMessage() as 'this' may be destroyed during |
| 956 // dispatch and ProcessWindowMessage() doesn't deal with that well. | 947 // dispatch and ProcessWindowMessage() doesn't deal with that well. |
| 957 const BOOL old_msg_handled = msg_handled_; | 948 const BOOL old_msg_handled = msg_handled_; |
| 958 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 949 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
| 959 const BOOL processed = | 950 const BOOL processed = |
| 960 _ProcessWindowMessage(window, message, w_param, l_param, result, 0); | 951 _ProcessWindowMessage(window, message, w_param, l_param, result, 0); |
| 961 if (!ref) | 952 if (!ref) |
| 962 return 0; | 953 return 0; |
| 963 msg_handled_ = old_msg_handled; | 954 msg_handled_ = old_msg_handled; |
| 964 | 955 |
| 965 if (!processed) | 956 if (!processed) |
| 966 result = DefWindowProc(window, message, w_param, l_param); | 957 result = DefWindowProc(window, message, w_param, l_param); |
| 967 | 958 |
| 968 // DefWindowProc() may have destroyed the window in a nested message loop. | 959 // DefWindowProc() may have destroyed the window in a nested message loop. |
| 969 if (!::IsWindow(window)) | 960 if (!::IsWindow(window)) |
| 970 return result; | 961 return result; |
| 971 | 962 |
| 972 if (delegate_) | 963 if (delegate_) |
| 973 delegate_->PostHandleMSG(message, w_param, l_param); | 964 delegate_->PostHandleMSG(message, w_param, l_param); |
| 974 if (message == WM_NCDESTROY) { | 965 if (message == WM_NCDESTROY) { |
| 975 #if !defined(USE_AURA) | |
| 976 base::MessageLoopForUI::current()->RemoveObserver(this); | |
| 977 #endif | |
| 978 if (delegate_) | 966 if (delegate_) |
| 979 delegate_->HandleDestroyed(); | 967 delegate_->HandleDestroyed(); |
| 980 } | 968 } |
| 981 | 969 |
| 982 // Only top level widget should store/restore focus. | 970 // Only top level widget should store/restore focus. |
| 983 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) | 971 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) |
| 984 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param)); | 972 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param)); |
| 985 | 973 |
| 986 if (message == WM_ENABLE && restore_focus_when_enabled_) { | 974 if (message == WM_ENABLE && restore_focus_when_enabled_) { |
| 987 // This path should be executed only for top level as | 975 // This path should be executed only for top level as |
| 988 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. | 976 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. |
| 989 DCHECK(delegate_->CanSaveFocus()); | 977 DCHECK(delegate_->CanSaveFocus()); |
| 990 restore_focus_when_enabled_ = false; | 978 restore_focus_when_enabled_ = false; |
| 991 delegate_->RestoreFocusOnEnable(); | 979 delegate_->RestoreFocusOnEnable(); |
| 992 } | 980 } |
| 993 return result; | 981 return result; |
| 994 } | 982 } |
| 995 | 983 |
| 996 //////////////////////////////////////////////////////////////////////////////// | 984 //////////////////////////////////////////////////////////////////////////////// |
| 997 // HWNDMessageHandler, MessageLoopForUI::Observer implementation: | |
| 998 | |
| 999 base::EventStatus HWNDMessageHandler::WillProcessEvent( | |
| 1000 const base::NativeEvent& event) { | |
| 1001 return base::EVENT_CONTINUE; | |
| 1002 } | |
| 1003 | |
| 1004 void HWNDMessageHandler::DidProcessEvent(const base::NativeEvent& event) { | |
| 1005 RedrawInvalidRect(); | |
| 1006 } | |
| 1007 | |
| 1008 //////////////////////////////////////////////////////////////////////////////// | |
| 1009 // HWNDMessageHandler, private: | 985 // HWNDMessageHandler, private: |
| 1010 | 986 |
| 1011 int HWNDMessageHandler::GetAppbarAutohideEdges(HMONITOR monitor) { | 987 int HWNDMessageHandler::GetAppbarAutohideEdges(HMONITOR monitor) { |
| 1012 autohide_factory_.InvalidateWeakPtrs(); | 988 autohide_factory_.InvalidateWeakPtrs(); |
| 1013 return Appbar::instance()->GetAutohideEdges( | 989 return Appbar::instance()->GetAutohideEdges( |
| 1014 monitor, | 990 monitor, |
| 1015 base::Bind(&HWNDMessageHandler::OnAppbarAutohideEdgesChanged, | 991 base::Bind(&HWNDMessageHandler::OnAppbarAutohideEdgesChanged, |
| 1016 autohide_factory_.GetWeakPtr())); | 992 autohide_factory_.GetWeakPtr())); |
| 1017 } | 993 } |
| 1018 | 994 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 } | 1212 } |
| 1237 | 1213 |
| 1238 void HWNDMessageHandler::UnlockUpdates(bool force) { | 1214 void HWNDMessageHandler::UnlockUpdates(bool force) { |
| 1239 if ((force || !ui::win::IsAeroGlassEnabled()) && --lock_updates_count_ <= 0) { | 1215 if ((force || !ui::win::IsAeroGlassEnabled()) && --lock_updates_count_ <= 0) { |
| 1240 SetWindowLong(hwnd(), GWL_STYLE, | 1216 SetWindowLong(hwnd(), GWL_STYLE, |
| 1241 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE); | 1217 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE); |
| 1242 lock_updates_count_ = 0; | 1218 lock_updates_count_ = 0; |
| 1243 } | 1219 } |
| 1244 } | 1220 } |
| 1245 | 1221 |
| 1246 void HWNDMessageHandler::RedrawInvalidRect() { | |
| 1247 // TODO(cpu): Remove the caller and this class as a message loop observer | |
| 1248 // because we don't need agressive repaints via RDW_UPDATENOW in Aura. The | |
| 1249 // general tracking bug for repaint issues is 177115. | |
| 1250 #if !defined(USE_AURA) | |
| 1251 if (!use_layered_buffer_) { | |
| 1252 RECT r = { 0, 0, 0, 0 }; | |
| 1253 if (GetUpdateRect(hwnd(), &r, FALSE) && !IsRectEmpty(&r)) { | |
| 1254 RedrawWindow(hwnd(), &r, NULL, | |
| 1255 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); | |
| 1256 } | |
| 1257 } | |
| 1258 #endif | |
| 1259 } | |
| 1260 | |
| 1261 void HWNDMessageHandler::RedrawLayeredWindowContents() { | 1222 void HWNDMessageHandler::RedrawLayeredWindowContents() { |
| 1262 waiting_for_redraw_layered_window_contents_ = false; | 1223 waiting_for_redraw_layered_window_contents_ = false; |
| 1263 if (invalid_rect_.IsEmpty()) | 1224 if (invalid_rect_.IsEmpty()) |
| 1264 return; | 1225 return; |
| 1265 | 1226 |
| 1266 // We need to clip to the dirty rect ourselves. | 1227 // We need to clip to the dirty rect ourselves. |
| 1267 layered_window_contents_->sk_canvas()->save(SkCanvas::kClip_SaveFlag); | 1228 layered_window_contents_->sk_canvas()->save(SkCanvas::kClip_SaveFlag); |
| 1268 double scale = gfx::win::GetDeviceScaleFactor(); | 1229 double scale = gfx::win::GetDeviceScaleFactor(); |
| 1269 layered_window_contents_->sk_canvas()->scale( | 1230 layered_window_contents_->sk_canvas()->scale( |
| 1270 SkScalar(scale),SkScalar(scale)); | 1231 SkScalar(scale),SkScalar(scale)); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 | 1346 |
| 1386 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && | 1347 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && |
| 1387 ui::AreTouchEventsEnabled()) | 1348 ui::AreTouchEventsEnabled()) |
| 1388 RegisterTouchWindow(hwnd(), TWF_WANTPALM); | 1349 RegisterTouchWindow(hwnd(), TWF_WANTPALM); |
| 1389 | 1350 |
| 1390 // We need to allow the delegate to size its contents since the window may not | 1351 // We need to allow the delegate to size its contents since the window may not |
| 1391 // receive a size notification when its initial bounds are specified at window | 1352 // receive a size notification when its initial bounds are specified at window |
| 1392 // creation time. | 1353 // creation time. |
| 1393 ClientAreaSizeChanged(); | 1354 ClientAreaSizeChanged(); |
| 1394 | 1355 |
| 1395 #if !defined(USE_AURA) | |
| 1396 // We need to add ourselves as a message loop observer so that we can repaint | |
| 1397 // aggressively if the contents of our window become invalid. Unfortunately | |
| 1398 // WM_PAINT messages are starved and we get flickery redrawing when resizing | |
| 1399 // if we do not do this. | |
| 1400 base::MessageLoopForUI::current()->AddObserver(this); | |
| 1401 #endif | |
| 1402 | |
| 1403 delegate_->HandleCreate(); | 1356 delegate_->HandleCreate(); |
| 1404 | 1357 |
| 1405 WTSRegisterSessionNotification(hwnd(), NOTIFY_FOR_THIS_SESSION); | 1358 WTSRegisterSessionNotification(hwnd(), NOTIFY_FOR_THIS_SESSION); |
| 1406 | 1359 |
| 1407 // TODO(beng): move more of NWW::OnCreate here. | 1360 // TODO(beng): move more of NWW::OnCreate here. |
| 1408 return 0; | 1361 return 0; |
| 1409 } | 1362 } |
| 1410 | 1363 |
| 1411 void HWNDMessageHandler::OnDestroy() { | 1364 void HWNDMessageHandler::OnDestroy() { |
| 1412 WTSUnRegisterSessionNotification(hwnd()); | 1365 WTSUnRegisterSessionNotification(hwnd()); |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2433 SetMsgHandled(FALSE); | 2386 SetMsgHandled(FALSE); |
| 2434 } | 2387 } |
| 2435 | 2388 |
| 2436 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { | 2389 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { |
| 2437 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 2390 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
| 2438 for (size_t i = 0; i < touch_events.size() && ref; ++i) | 2391 for (size_t i = 0; i < touch_events.size() && ref; ++i) |
| 2439 delegate_->HandleTouchEvent(touch_events[i]); | 2392 delegate_->HandleTouchEvent(touch_events[i]); |
| 2440 } | 2393 } |
| 2441 | 2394 |
| 2442 } // namespace views | 2395 } // namespace views |
| OLD | NEW |