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> |
11 | 11 |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/debug/alias.h" | 16 #include "base/debug/alias.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 24 #include "base/win/scoped_comptr.h" |
24 #include "base/win/scoped_gdi_object.h" | 25 #include "base/win/scoped_gdi_object.h" |
25 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 27 #include "ui/accessibility/platform/ax_platform_node_win.h" |
| 28 #include "ui/accessibility/platform/ax_system_caret_win.h" |
| 29 #include "ui/base/ime/input_method.h" |
| 30 #include "ui/base/ime/text_input_client.h" |
| 31 #include "ui/base/ime/text_input_type.h" |
26 #include "ui/base/view_prop.h" | 32 #include "ui/base/view_prop.h" |
27 #include "ui/base/win/internal_constants.h" | 33 #include "ui/base/win/internal_constants.h" |
28 #include "ui/base/win/lock_state.h" | 34 #include "ui/base/win/lock_state.h" |
29 #include "ui/base/win/mouse_wheel_util.h" | 35 #include "ui/base/win/mouse_wheel_util.h" |
30 #include "ui/base/win/shell.h" | 36 #include "ui/base/win/shell.h" |
31 #include "ui/base/win/touch_input.h" | 37 #include "ui/base/win/touch_input.h" |
32 #include "ui/display/win/dpi.h" | 38 #include "ui/display/win/dpi.h" |
33 #include "ui/display/win/screen_win.h" | 39 #include "ui/display/win/screen_win.h" |
34 #include "ui/events/event.h" | 40 #include "ui/events/event.h" |
35 #include "ui/events/event_constants.h" | 41 #include "ui/events/event_constants.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 touch_down_contexts_(0), | 351 touch_down_contexts_(0), |
346 last_mouse_hwheel_time_(0), | 352 last_mouse_hwheel_time_(0), |
347 dwm_transition_desired_(false), | 353 dwm_transition_desired_(false), |
348 sent_window_size_changing_(false), | 354 sent_window_size_changing_(false), |
349 left_button_down_on_caption_(false), | 355 left_button_down_on_caption_(false), |
350 background_fullscreen_hack_(false), | 356 background_fullscreen_hack_(false), |
351 autohide_factory_(this), | 357 autohide_factory_(this), |
352 weak_factory_(this) {} | 358 weak_factory_(this) {} |
353 | 359 |
354 HWNDMessageHandler::~HWNDMessageHandler() { | 360 HWNDMessageHandler::~HWNDMessageHandler() { |
| 361 DCHECK(delegate_->GetHWNDMessageDelegateInputMethod()); |
| 362 delegate_->GetHWNDMessageDelegateInputMethod()->RemoveObserver(this); |
355 delegate_ = NULL; | 363 delegate_ = NULL; |
356 // Prevent calls back into this class via WNDPROC now that we've been | 364 // Prevent calls back into this class via WNDPROC now that we've been |
357 // destroyed. | 365 // destroyed. |
358 ClearUserData(); | 366 ClearUserData(); |
359 } | 367 } |
360 | 368 |
361 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { | 369 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { |
362 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); | 370 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); |
363 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, | 371 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, |
364 &last_work_area_); | 372 &last_work_area_); |
(...skipping 13 matching lines...) Expand all Loading... |
378 GetProcAddress(GetModuleHandle(L"user32.dll"), | 386 GetProcAddress(GetModuleHandle(L"user32.dll"), |
379 "EnableChildWindowDpiMessage")); | 387 "EnableChildWindowDpiMessage")); |
380 }(); | 388 }(); |
381 if (enable_child_window_dpi_message_func) | 389 if (enable_child_window_dpi_message_func) |
382 enable_child_window_dpi_message_func(hwnd(), TRUE); | 390 enable_child_window_dpi_message_func(hwnd(), TRUE); |
383 } | 391 } |
384 | 392 |
385 prop_window_target_.reset(new ui::ViewProp(hwnd(), | 393 prop_window_target_.reset(new ui::ViewProp(hwnd(), |
386 ui::WindowEventTarget::kWin32InputEventTarget, | 394 ui::WindowEventTarget::kWin32InputEventTarget, |
387 static_cast<ui::WindowEventTarget*>(this))); | 395 static_cast<ui::WindowEventTarget*>(this))); |
| 396 DCHECK(delegate_->GetHWNDMessageDelegateInputMethod()); |
| 397 delegate_->GetHWNDMessageDelegateInputMethod()->AddObserver(this); |
388 | 398 |
389 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function | 399 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function |
390 // returns NULL if Direct Manipulation is not available. | 400 // returns NULL if Direct Manipulation is not available. |
391 direct_manipulation_helper_ = | 401 direct_manipulation_helper_ = |
392 gfx::win::DirectManipulationHelper::CreateInstance(); | 402 gfx::win::DirectManipulationHelper::CreateInstance(); |
393 if (direct_manipulation_helper_) | 403 if (direct_manipulation_helper_) |
394 direct_manipulation_helper_->Initialize(hwnd()); | 404 direct_manipulation_helper_->Initialize(hwnd()); |
395 | 405 |
396 // Disable pen flicks (http://crbug.com/506977) | 406 // Disable pen flicks (http://crbug.com/506977) |
397 base::win::DisableFlicks(hwnd()); | 407 base::win::DisableFlicks(hwnd()); |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 delegate_->HandleDestroyed(); | 942 delegate_->HandleDestroyed(); |
933 } | 943 } |
934 } | 944 } |
935 | 945 |
936 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) | 946 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) |
937 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), | 947 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), |
938 reinterpret_cast<HWND>(l_param)); | 948 reinterpret_cast<HWND>(l_param)); |
939 return result; | 949 return result; |
940 } | 950 } |
941 | 951 |
| 952 void HWNDMessageHandler::OnTextInputTypeChanged( |
| 953 const ui::TextInputClient* client) { |
| 954 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
| 955 DestroyAXSystemCaret(); |
| 956 return; |
| 957 } |
| 958 |
| 959 OnCaretBoundsChanged(client); |
| 960 } |
| 961 |
| 962 void HWNDMessageHandler::OnFocus() {} |
| 963 |
| 964 void HWNDMessageHandler::OnBlur() {} |
| 965 |
| 966 void HWNDMessageHandler::OnCaretBoundsChanged( |
| 967 const ui::TextInputClient* client) { |
| 968 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
| 969 return; |
| 970 |
| 971 if (!ax_system_caret_) |
| 972 ax_system_caret_ = std::make_unique<ui::AXSystemCaretWin>(hwnd()); |
| 973 |
| 974 const gfx::Rect dip_caret_bounds(client->GetCaretBounds()); |
| 975 gfx::Rect caret_bounds = |
| 976 display::win::ScreenWin::DIPToScreenRect(hwnd(), dip_caret_bounds); |
| 977 // Collapse any selection. |
| 978 caret_bounds.set_width(1); |
| 979 ax_system_caret_->MoveCaretTo(caret_bounds); |
| 980 } |
| 981 |
| 982 void HWNDMessageHandler::OnTextInputStateChanged( |
| 983 const ui::TextInputClient* client) {} |
| 984 |
| 985 void HWNDMessageHandler::OnInputMethodDestroyed( |
| 986 const ui::InputMethod* input_method) { |
| 987 DestroyAXSystemCaret(); |
| 988 } |
| 989 |
| 990 void HWNDMessageHandler::OnShowImeIfNeeded() {} |
| 991 |
942 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, | 992 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, |
943 WPARAM w_param, | 993 WPARAM w_param, |
944 LPARAM l_param, | 994 LPARAM l_param, |
945 bool* handled) { | 995 bool* handled) { |
946 // Don't track forwarded mouse messages. We expect the caller to track the | 996 // Don't track forwarded mouse messages. We expect the caller to track the |
947 // mouse. | 997 // mouse. |
948 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 998 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
949 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false); | 999 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false); |
950 *handled = IsMsgHandled(); | 1000 *handled = IsMsgHandled(); |
951 return ret; | 1001 return ret; |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 | 1566 |
1517 // Only the lower 32 bits of l_param are valid when checking the object id | 1567 // Only the lower 32 bits of l_param are valid when checking the object id |
1518 // because it sometimes gets sign-extended incorrectly (but not always). | 1568 // because it sometimes gets sign-extended incorrectly (but not always). |
1519 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); | 1569 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); |
1520 | 1570 |
1521 // Accessibility readers will send an OBJID_CLIENT message | 1571 // Accessibility readers will send an OBJID_CLIENT message |
1522 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) { | 1572 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) { |
1523 // Retrieve MSAA dispatch object for the root view. | 1573 // Retrieve MSAA dispatch object for the root view. |
1524 base::win::ScopedComPtr<IAccessible> root( | 1574 base::win::ScopedComPtr<IAccessible> root( |
1525 delegate_->GetNativeViewAccessible()); | 1575 delegate_->GetNativeViewAccessible()); |
1526 | |
1527 // Create a reference that MSAA will marshall to the client. | |
1528 reference_result = LresultFromObject(IID_IAccessible, w_param, | 1576 reference_result = LresultFromObject(IID_IAccessible, w_param, |
1529 static_cast<IAccessible*>(root.Detach())); | 1577 static_cast<IAccessible*>(root.Detach())); |
| 1578 } else if (::GetFocus() == hwnd() && ax_system_caret_ && |
| 1579 static_cast<DWORD>(OBJID_CARET) == obj_id) { |
| 1580 base::win::ScopedComPtr<IAccessible> ax_system_caret_accessible = |
| 1581 ax_system_caret_->GetCaret(); |
| 1582 reference_result = LresultFromObject(IID_IAccessible, w_param, |
| 1583 ax_system_caret_accessible.Detach()); |
1530 } | 1584 } |
1531 | 1585 |
1532 return reference_result; | 1586 return reference_result; |
1533 } | 1587 } |
1534 | 1588 |
1535 LRESULT HWNDMessageHandler::OnImeMessages(UINT message, | 1589 LRESULT HWNDMessageHandler::OnImeMessages(UINT message, |
1536 WPARAM w_param, | 1590 WPARAM w_param, |
1537 LPARAM l_param) { | 1591 LPARAM l_param) { |
1538 LRESULT result = 0; | 1592 LRESULT result = 0; |
1539 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 1593 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2243 // Ignore size/move/maximize in fullscreen mode. | 2297 // Ignore size/move/maximize in fullscreen mode. |
2244 if (IsFullscreen() && (((notification_code & sc_mask) == SC_SIZE) || | 2298 if (IsFullscreen() && (((notification_code & sc_mask) == SC_SIZE) || |
2245 ((notification_code & sc_mask) == SC_MOVE) || | 2299 ((notification_code & sc_mask) == SC_MOVE) || |
2246 ((notification_code & sc_mask) == SC_MAXIMIZE))) | 2300 ((notification_code & sc_mask) == SC_MAXIMIZE))) |
2247 return; | 2301 return; |
2248 if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { | 2302 if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { |
2249 if ((notification_code & sc_mask) == SC_MINIMIZE || | 2303 if ((notification_code & sc_mask) == SC_MINIMIZE || |
2250 (notification_code & sc_mask) == SC_MAXIMIZE || | 2304 (notification_code & sc_mask) == SC_MAXIMIZE || |
2251 (notification_code & sc_mask) == SC_RESTORE) { | 2305 (notification_code & sc_mask) == SC_RESTORE) { |
2252 delegate_->ResetWindowControls(); | 2306 delegate_->ResetWindowControls(); |
| 2307 DestroyAXSystemCaret(); |
2253 } else if ((notification_code & sc_mask) == SC_MOVE || | 2308 } else if ((notification_code & sc_mask) == SC_MOVE || |
2254 (notification_code & sc_mask) == SC_SIZE) { | 2309 (notification_code & sc_mask) == SC_SIZE) { |
2255 if (!IsVisible()) { | 2310 if (!IsVisible()) { |
2256 // Circumvent ScopedRedrawLocks and force visibility before entering a | 2311 // Circumvent ScopedRedrawLocks and force visibility before entering a |
2257 // resize or move modal loop to get continuous sizing/moving feedback. | 2312 // resize or move modal loop to get continuous sizing/moving feedback. |
2258 SetWindowLong(hwnd(), GWL_STYLE, | 2313 SetWindowLong(hwnd(), GWL_STYLE, |
2259 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE); | 2314 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE); |
2260 } | 2315 } |
| 2316 DestroyAXSystemCaret(); |
2261 } | 2317 } |
2262 } | 2318 } |
2263 | 2319 |
2264 // Handle SC_KEYMENU, which means that the user has pressed the ALT | 2320 // Handle SC_KEYMENU, which means that the user has pressed the ALT |
2265 // key and released it, so we should focus the menu bar. | 2321 // key and released it, so we should focus the menu bar. |
2266 if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) { | 2322 if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) { |
2267 int modifiers = ui::EF_NONE; | 2323 int modifiers = ui::EF_NONE; |
2268 if (ui::win::IsShiftPressed()) | 2324 if (ui::win::IsShiftPressed()) |
2269 modifiers |= ui::EF_SHIFT_DOWN; | 2325 modifiers |= ui::EF_SHIFT_DOWN; |
2270 if (ui::win::IsCtrlPressed()) | 2326 if (ui::win::IsCtrlPressed()) |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2912 // not treat this like a fullscreen window. | 2968 // not treat this like a fullscreen window. |
2913 MONITORINFO monitor_info = {sizeof(monitor_info)}; | 2969 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
2914 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), | 2970 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), |
2915 &monitor_info); | 2971 &monitor_info); |
2916 gfx::Rect shrunk_rect(monitor_info.rcMonitor); | 2972 gfx::Rect shrunk_rect(monitor_info.rcMonitor); |
2917 shrunk_rect.set_height(shrunk_rect.height() - 1); | 2973 shrunk_rect.set_height(shrunk_rect.height() - 1); |
2918 background_fullscreen_hack_ = true; | 2974 background_fullscreen_hack_ = true; |
2919 SetBoundsInternal(shrunk_rect, false); | 2975 SetBoundsInternal(shrunk_rect, false); |
2920 } | 2976 } |
2921 | 2977 |
| 2978 void HWNDMessageHandler::DestroyAXSystemCaret() { |
| 2979 ax_system_caret_ = nullptr; |
| 2980 } |
| 2981 |
2922 } // namespace views | 2982 } // namespace views |
OLD | NEW |