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 <tchar.h> | 10 #include <tchar.h> |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 if (!ref || !::IsWindow(window)) | 921 if (!ref || !::IsWindow(window)) |
922 return result; | 922 return result; |
923 } | 923 } |
924 | 924 |
925 if (delegate_) { | 925 if (delegate_) { |
926 delegate_->PostHandleMSG(message, w_param, l_param); | 926 delegate_->PostHandleMSG(message, w_param, l_param); |
927 if (message == WM_NCDESTROY) | 927 if (message == WM_NCDESTROY) |
928 delegate_->HandleDestroyed(); | 928 delegate_->HandleDestroyed(); |
929 } | 929 } |
930 | 930 |
931 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) | 931 if (message == WM_ACTIVATE) { |
932 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param)); | 932 if (IsTopLevelWindow(window)) |
| 933 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param)); |
| 934 else |
| 935 delegate_->AddStringLog("WM_ACTIVATE on non-top-level window."); |
| 936 } |
933 return result; | 937 return result; |
934 } | 938 } |
935 | 939 |
936 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, | 940 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, |
937 WPARAM w_param, | 941 WPARAM w_param, |
938 LPARAM l_param, | 942 LPARAM l_param, |
939 bool* handled) { | 943 bool* handled) { |
940 // Don't track forwarded mouse messages. We expect the caller to track the | 944 // Don't track forwarded mouse messages. We expect the caller to track the |
941 // mouse. | 945 // mouse. |
942 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 946 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 SetFocus(hwnd()); | 1030 SetFocus(hwnd()); |
1027 } | 1031 } |
1028 } | 1032 } |
1029 | 1033 |
1030 void HWNDMessageHandler::PostProcessActivateMessage(int activation_state, | 1034 void HWNDMessageHandler::PostProcessActivateMessage(int activation_state, |
1031 bool minimized) { | 1035 bool minimized) { |
1032 DCHECK(IsTopLevelWindow(hwnd())); | 1036 DCHECK(IsTopLevelWindow(hwnd())); |
1033 const bool active = activation_state != WA_INACTIVE && !minimized; | 1037 const bool active = activation_state != WA_INACTIVE && !minimized; |
1034 if (delegate_->CanActivate()) | 1038 if (delegate_->CanActivate()) |
1035 delegate_->HandleActivationChanged(active); | 1039 delegate_->HandleActivationChanged(active); |
| 1040 else |
| 1041 delegate_->AddStringLog("Missing call to HandleActivationChanged."); |
1036 } | 1042 } |
1037 | 1043 |
1038 void HWNDMessageHandler::RestoreEnabledIfNecessary() { | 1044 void HWNDMessageHandler::RestoreEnabledIfNecessary() { |
1039 if (delegate_->IsModal() && !restored_enabled_) { | 1045 if (delegate_->IsModal() && !restored_enabled_) { |
1040 restored_enabled_ = true; | 1046 restored_enabled_ = true; |
1041 // If we were run modally, we need to undo the disabled-ness we inflicted on | 1047 // If we were run modally, we need to undo the disabled-ness we inflicted on |
1042 // the owner's parent hierarchy. | 1048 // the owner's parent hierarchy. |
1043 HWND start = ::GetWindow(hwnd(), GW_OWNER); | 1049 HWND start = ::GetWindow(hwnd(), GW_OWNER); |
1044 while (start) { | 1050 while (start) { |
1045 ::EnableWindow(start, TRUE); | 1051 ::EnableWindow(start, TRUE); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 attempts), | 1230 attempts), |
1225 base::TimeDelta::FromMilliseconds(500)); | 1231 base::TimeDelta::FromMilliseconds(500)); |
1226 return; | 1232 return; |
1227 } | 1233 } |
1228 InvalidateRect(hwnd(), NULL, FALSE); | 1234 InvalidateRect(hwnd(), NULL, FALSE); |
1229 } | 1235 } |
1230 | 1236 |
1231 // Message handlers ------------------------------------------------------------ | 1237 // Message handlers ------------------------------------------------------------ |
1232 | 1238 |
1233 void HWNDMessageHandler::OnActivateApp(BOOL active, DWORD thread_id) { | 1239 void HWNDMessageHandler::OnActivateApp(BOOL active, DWORD thread_id) { |
| 1240 delegate_->AddStringLog("WM_ACTIVATEAPP: "); |
| 1241 delegate_->AddBooleanLog((bool)active); |
1234 if (delegate_->IsWidgetWindow() && !active && | 1242 if (delegate_->IsWidgetWindow() && !active && |
1235 thread_id != GetCurrentThreadId()) { | 1243 thread_id != GetCurrentThreadId()) { |
1236 delegate_->HandleAppDeactivated(); | 1244 delegate_->HandleAppDeactivated(); |
1237 // Also update the native frame if it is rendering the non-client area. | 1245 // Also update the native frame if it is rendering the non-client area. |
1238 if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) | 1246 if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) |
1239 DefWindowProcWithRedrawLock(WM_NCACTIVATE, FALSE, 0); | 1247 DefWindowProcWithRedrawLock(WM_NCACTIVATE, FALSE, 0); |
1240 } | 1248 } |
1241 } | 1249 } |
1242 | 1250 |
1243 BOOL HWNDMessageHandler::OnAppCommand(HWND window, | 1251 BOOL HWNDMessageHandler::OnAppCommand(HWND window, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 } | 1487 } |
1480 | 1488 |
1481 void HWNDMessageHandler::OnInputLangChange(DWORD character_set, | 1489 void HWNDMessageHandler::OnInputLangChange(DWORD character_set, |
1482 HKL input_language_id) { | 1490 HKL input_language_id) { |
1483 delegate_->HandleInputLanguageChange(character_set, input_language_id); | 1491 delegate_->HandleInputLanguageChange(character_set, input_language_id); |
1484 } | 1492 } |
1485 | 1493 |
1486 LRESULT HWNDMessageHandler::OnKeyEvent(UINT message, | 1494 LRESULT HWNDMessageHandler::OnKeyEvent(UINT message, |
1487 WPARAM w_param, | 1495 WPARAM w_param, |
1488 LPARAM l_param) { | 1496 LPARAM l_param) { |
| 1497 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) |
| 1498 delegate_->AddStringLog("WM_KEYDOWN || WM_SYSKEYDOWN"); |
1489 MSG msg = { | 1499 MSG msg = { |
1490 hwnd(), message, w_param, l_param, static_cast<DWORD>(GetMessageTime())}; | 1500 hwnd(), message, w_param, l_param, static_cast<DWORD>(GetMessageTime())}; |
1491 ui::KeyEvent key(msg); | 1501 ui::KeyEvent key(msg); |
1492 delegate_->HandleKeyEvent(&key); | 1502 delegate_->HandleKeyEvent(&key); |
1493 if (!key.handled()) | 1503 if (!key.handled()) |
1494 SetMsgHandled(FALSE); | 1504 SetMsgHandled(FALSE); |
1495 return 0; | 1505 return 0; |
1496 } | 1506 } |
1497 | 1507 |
1498 void HWNDMessageHandler::OnKillFocus(HWND focused_window) { | 1508 void HWNDMessageHandler::OnKillFocus(HWND focused_window) { |
1499 delegate_->HandleNativeBlur(focused_window); | 1509 delegate_->HandleNativeBlur(focused_window); |
1500 SetMsgHandled(FALSE); | 1510 SetMsgHandled(FALSE); |
1501 } | 1511 } |
1502 | 1512 |
1503 LRESULT HWNDMessageHandler::OnMouseActivate(UINT message, | 1513 LRESULT HWNDMessageHandler::OnMouseActivate(UINT message, |
1504 WPARAM w_param, | 1514 WPARAM w_param, |
1505 LPARAM l_param) { | 1515 LPARAM l_param) { |
| 1516 delegate_->AddStringLog("WM_MOUSEACTIVATE"); |
1506 // Please refer to the comments in the header for the touch_down_contexts_ | 1517 // Please refer to the comments in the header for the touch_down_contexts_ |
1507 // member for the if statement below. | 1518 // member for the if statement below. |
1508 if (touch_down_contexts_) | 1519 if (touch_down_contexts_) |
1509 return MA_NOACTIVATE; | 1520 return MA_NOACTIVATE; |
1510 | 1521 |
1511 // On Windows, if we select the menu item by touch and if the window at the | 1522 // On Windows, if we select the menu item by touch and if the window at the |
1512 // location is another window on the same thread, that window gets a | 1523 // location is another window on the same thread, that window gets a |
1513 // WM_MOUSEACTIVATE message and ends up activating itself, which is not | 1524 // WM_MOUSEACTIVATE message and ends up activating itself, which is not |
1514 // correct. We workaround this by setting a property on the window at the | 1525 // correct. We workaround this by setting a property on the window at the |
1515 // current cursor location. We check for this property in our | 1526 // current cursor location. We check for this property in our |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 SetMsgHandled(FALSE); | 1571 SetMsgHandled(FALSE); |
1561 } | 1572 } |
1562 | 1573 |
1563 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { | 1574 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { |
1564 delegate_->HandleMove(); | 1575 delegate_->HandleMove(); |
1565 } | 1576 } |
1566 | 1577 |
1567 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, | 1578 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, |
1568 WPARAM w_param, | 1579 WPARAM w_param, |
1569 LPARAM l_param) { | 1580 LPARAM l_param) { |
| 1581 delegate_->AddStringLog("WM_NCACTIVATE: "); |
| 1582 delegate_->AddBooleanLog((bool)w_param); |
1570 // Per MSDN, w_param is either TRUE or FALSE. However, MSDN also hints that: | 1583 // Per MSDN, w_param is either TRUE or FALSE. However, MSDN also hints that: |
1571 // "If the window is minimized when this message is received, the application | 1584 // "If the window is minimized when this message is received, the application |
1572 // should pass the message to the DefWindowProc function." | 1585 // should pass the message to the DefWindowProc function." |
1573 // It is found out that the high word of w_param might be set when the window | 1586 // It is found out that the high word of w_param might be set when the window |
1574 // is minimized or restored. To handle this, w_param's high word should be | 1587 // is minimized or restored. To handle this, w_param's high word should be |
1575 // cleared before it is converted to BOOL. | 1588 // cleared before it is converted to BOOL. |
1576 BOOL active = static_cast<BOOL>(LOWORD(w_param)); | 1589 BOOL active = static_cast<BOOL>(LOWORD(w_param)); |
1577 | 1590 |
1578 bool inactive_rendering_disabled = delegate_->IsInactiveRenderingDisabled(); | 1591 bool inactive_rendering_disabled = delegate_->IsInactiveRenderingDisabled(); |
1579 | 1592 |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2572 | 2585 |
2573 default: | 2586 default: |
2574 left_button_down_on_caption_ = false; | 2587 left_button_down_on_caption_ = false; |
2575 break; | 2588 break; |
2576 } | 2589 } |
2577 return handled; | 2590 return handled; |
2578 } | 2591 } |
2579 | 2592 |
2580 | 2593 |
2581 } // namespace views | 2594 } // namespace views |
OLD | NEW |