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

Side by Side Diff: ui/views/win/hwnd_message_handler.cc

Issue 1566083002: Makes sure the keyboard typing isn't blocked when InputMethod::OnFocus() is not correctly called. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compiled. Created 4 years, 11 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
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/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>
11 #include <tpcshrd.h> 11 #include <tpcshrd.h>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/debug/alias.h" 15 #include "base/debug/alias.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/strings/string_number_conversions.h"
17 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
18 #include "base/win/scoped_gdi_object.h" 19 #include "base/win/scoped_gdi_object.h"
19 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
20 #include "ui/base/touch/touch_enabled.h" 21 #include "ui/base/touch/touch_enabled.h"
21 #include "ui/base/view_prop.h" 22 #include "ui/base/view_prop.h"
22 #include "ui/base/win/internal_constants.h" 23 #include "ui/base/win/internal_constants.h"
23 #include "ui/base/win/lock_state.h" 24 #include "ui/base/win/lock_state.h"
24 #include "ui/base/win/mouse_wheel_util.h" 25 #include "ui/base/win/mouse_wheel_util.h"
25 #include "ui/base/win/shell.h" 26 #include "ui/base/win/shell.h"
26 #include "ui/base/win/touch_input.h" 27 #include "ui/base/win/touch_input.h"
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 if (!ref || !::IsWindow(window)) 922 if (!ref || !::IsWindow(window))
922 return result; 923 return result;
923 } 924 }
924 925
925 if (delegate_) { 926 if (delegate_) {
926 delegate_->PostHandleMSG(message, w_param, l_param); 927 delegate_->PostHandleMSG(message, w_param, l_param);
927 if (message == WM_NCDESTROY) 928 if (message == WM_NCDESTROY)
928 delegate_->HandleDestroyed(); 929 delegate_->HandleDestroyed();
929 } 930 }
930 931
931 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) 932 if (message == WM_ACTIVATE) {
932 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param)); 933 if (IsTopLevelWindow(window))
934 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param));
935 else
936 delegate_->AddLog("WM_ACTIVATE on non-top-level window.");
937 }
933 return result; 938 return result;
934 } 939 }
935 940
936 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, 941 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message,
937 WPARAM w_param, 942 WPARAM w_param,
938 LPARAM l_param, 943 LPARAM l_param,
939 bool* handled) { 944 bool* handled) {
940 // Don't track forwarded mouse messages. We expect the caller to track the 945 // Don't track forwarded mouse messages. We expect the caller to track the
941 // mouse. 946 // mouse.
942 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 947 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 SetFocus(hwnd()); 1031 SetFocus(hwnd());
1027 } 1032 }
1028 } 1033 }
1029 1034
1030 void HWNDMessageHandler::PostProcessActivateMessage(int activation_state, 1035 void HWNDMessageHandler::PostProcessActivateMessage(int activation_state,
1031 bool minimized) { 1036 bool minimized) {
1032 DCHECK(IsTopLevelWindow(hwnd())); 1037 DCHECK(IsTopLevelWindow(hwnd()));
1033 const bool active = activation_state != WA_INACTIVE && !minimized; 1038 const bool active = activation_state != WA_INACTIVE && !minimized;
1034 if (delegate_->CanActivate()) 1039 if (delegate_->CanActivate())
1035 delegate_->HandleActivationChanged(active); 1040 delegate_->HandleActivationChanged(active);
1041 else
1042 delegate_->AddLog("Missing call to HandleActivationChanged.");
1036 } 1043 }
1037 1044
1038 void HWNDMessageHandler::RestoreEnabledIfNecessary() { 1045 void HWNDMessageHandler::RestoreEnabledIfNecessary() {
1039 if (delegate_->IsModal() && !restored_enabled_) { 1046 if (delegate_->IsModal() && !restored_enabled_) {
1040 restored_enabled_ = true; 1047 restored_enabled_ = true;
1041 // If we were run modally, we need to undo the disabled-ness we inflicted on 1048 // If we were run modally, we need to undo the disabled-ness we inflicted on
1042 // the owner's parent hierarchy. 1049 // the owner's parent hierarchy.
1043 HWND start = ::GetWindow(hwnd(), GW_OWNER); 1050 HWND start = ::GetWindow(hwnd(), GW_OWNER);
1044 while (start) { 1051 while (start) {
1045 ::EnableWindow(start, TRUE); 1052 ::EnableWindow(start, TRUE);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 attempts), 1231 attempts),
1225 base::TimeDelta::FromMilliseconds(500)); 1232 base::TimeDelta::FromMilliseconds(500));
1226 return; 1233 return;
1227 } 1234 }
1228 InvalidateRect(hwnd(), NULL, FALSE); 1235 InvalidateRect(hwnd(), NULL, FALSE);
1229 } 1236 }
1230 1237
1231 // Message handlers ------------------------------------------------------------ 1238 // Message handlers ------------------------------------------------------------
1232 1239
1233 void HWNDMessageHandler::OnActivateApp(BOOL active, DWORD thread_id) { 1240 void HWNDMessageHandler::OnActivateApp(BOOL active, DWORD thread_id) {
1241 delegate_->AddLog("WM_ACTIVATEAPP: " + base::IntToString(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
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_->AddLog("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_->AddLog("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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 SetMsgHandled(FALSE); 1566 SetMsgHandled(FALSE);
1556 } 1567 }
1557 1568
1558 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { 1569 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) {
1559 delegate_->HandleMove(); 1570 delegate_->HandleMove();
1560 } 1571 }
1561 1572
1562 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, 1573 LRESULT HWNDMessageHandler::OnNCActivate(UINT message,
1563 WPARAM w_param, 1574 WPARAM w_param,
1564 LPARAM l_param) { 1575 LPARAM l_param) {
1576 delegate_->AddLog("WM_NCACTIVATE: " + base::UintToString(w_param));
1565 // Per MSDN, w_param is either TRUE or FALSE. However, MSDN also hints that: 1577 // Per MSDN, w_param is either TRUE or FALSE. However, MSDN also hints that:
1566 // "If the window is minimized when this message is received, the application 1578 // "If the window is minimized when this message is received, the application
1567 // should pass the message to the DefWindowProc function." 1579 // should pass the message to the DefWindowProc function."
1568 // It is found out that the high word of w_param might be set when the window 1580 // It is found out that the high word of w_param might be set when the window
1569 // is minimized or restored. To handle this, w_param's high word should be 1581 // is minimized or restored. To handle this, w_param's high word should be
1570 // cleared before it is converted to BOOL. 1582 // cleared before it is converted to BOOL.
1571 BOOL active = static_cast<BOOL>(LOWORD(w_param)); 1583 BOOL active = static_cast<BOOL>(LOWORD(w_param));
1572 1584
1573 bool inactive_rendering_disabled = delegate_->IsInactiveRenderingDisabled(); 1585 bool inactive_rendering_disabled = delegate_->IsInactiveRenderingDisabled();
1574 1586
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 2579
2568 default: 2580 default:
2569 left_button_down_on_caption_ = false; 2581 left_button_down_on_caption_ = false;
2570 break; 2582 break;
2571 } 2583 }
2572 return handled; 2584 return handled;
2573 } 2585 }
2574 2586
2575 2587
2576 } // namespace views 2588 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698