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

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

Issue 2852763002: Added a system caret used for accessibility on Windows. (Closed)
Patch Set: Disabled all tests Created 3 years, 5 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
« no previous file with comments | « ui/views/win/hwnd_message_handler.h ('k') | ui/views/win/hwnd_message_handler_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 touch_down_contexts_(0), 361 touch_down_contexts_(0),
356 last_mouse_hwheel_time_(0), 362 last_mouse_hwheel_time_(0),
357 dwm_transition_desired_(false), 363 dwm_transition_desired_(false),
358 sent_window_size_changing_(false), 364 sent_window_size_changing_(false),
359 left_button_down_on_caption_(false), 365 left_button_down_on_caption_(false),
360 background_fullscreen_hack_(false), 366 background_fullscreen_hack_(false),
361 autohide_factory_(this), 367 autohide_factory_(this),
362 weak_factory_(this) {} 368 weak_factory_(this) {}
363 369
364 HWNDMessageHandler::~HWNDMessageHandler() { 370 HWNDMessageHandler::~HWNDMessageHandler() {
371 DCHECK(delegate_->GetHWNDMessageDelegateInputMethod());
372 delegate_->GetHWNDMessageDelegateInputMethod()->RemoveObserver(this);
365 delegate_ = NULL; 373 delegate_ = NULL;
366 // Prevent calls back into this class via WNDPROC now that we've been 374 // Prevent calls back into this class via WNDPROC now that we've been
367 // destroyed. 375 // destroyed.
368 ClearUserData(); 376 ClearUserData();
369 } 377 }
370 378
371 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { 379 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
372 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); 380 TRACE_EVENT0("views", "HWNDMessageHandler::Init");
373 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, 381 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_,
374 &last_work_area_); 382 &last_work_area_);
(...skipping 13 matching lines...) Expand all
388 GetProcAddress(GetModuleHandle(L"user32.dll"), 396 GetProcAddress(GetModuleHandle(L"user32.dll"),
389 "EnableChildWindowDpiMessage")); 397 "EnableChildWindowDpiMessage"));
390 }(); 398 }();
391 if (enable_child_window_dpi_message_func) 399 if (enable_child_window_dpi_message_func)
392 enable_child_window_dpi_message_func(hwnd(), TRUE); 400 enable_child_window_dpi_message_func(hwnd(), TRUE);
393 } 401 }
394 402
395 prop_window_target_.reset(new ui::ViewProp(hwnd(), 403 prop_window_target_.reset(new ui::ViewProp(hwnd(),
396 ui::WindowEventTarget::kWin32InputEventTarget, 404 ui::WindowEventTarget::kWin32InputEventTarget,
397 static_cast<ui::WindowEventTarget*>(this))); 405 static_cast<ui::WindowEventTarget*>(this)));
406 DCHECK(delegate_->GetHWNDMessageDelegateInputMethod());
407 delegate_->GetHWNDMessageDelegateInputMethod()->AddObserver(this);
398 408
399 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function 409 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function
400 // returns NULL if Direct Manipulation is not available. 410 // returns NULL if Direct Manipulation is not available.
401 direct_manipulation_helper_ = 411 direct_manipulation_helper_ =
402 gfx::win::DirectManipulationHelper::CreateInstance(); 412 gfx::win::DirectManipulationHelper::CreateInstance();
403 if (direct_manipulation_helper_) 413 if (direct_manipulation_helper_)
404 direct_manipulation_helper_->Initialize(hwnd()); 414 direct_manipulation_helper_->Initialize(hwnd());
405 415
406 // Disable pen flicks (http://crbug.com/506977) 416 // Disable pen flicks (http://crbug.com/506977)
407 base::win::DisableFlicks(hwnd()); 417 base::win::DisableFlicks(hwnd());
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 delegate_->HandleDestroyed(); 952 delegate_->HandleDestroyed();
943 } 953 }
944 } 954 }
945 955
946 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) 956 if (message == WM_ACTIVATE && IsTopLevelWindow(window))
947 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), 957 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param),
948 reinterpret_cast<HWND>(l_param)); 958 reinterpret_cast<HWND>(l_param));
949 return result; 959 return result;
950 } 960 }
951 961
962 void HWNDMessageHandler::OnTextInputTypeChanged(
963 const ui::TextInputClient* client) {
964 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
965 DestroyAXSystemCaret();
966 return;
967 }
968
969 OnCaretBoundsChanged(client);
970 }
971
972 void HWNDMessageHandler::OnFocus() {}
973
974 void HWNDMessageHandler::OnBlur() {}
975
976 void HWNDMessageHandler::OnCaretBoundsChanged(
977 const ui::TextInputClient* client) {
978 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
979 return;
980
981 if (!ax_system_caret_)
982 ax_system_caret_ = std::make_unique<ui::AXSystemCaretWin>(hwnd());
983
984 const gfx::Rect dip_caret_bounds(client->GetCaretBounds());
985 gfx::Rect caret_bounds =
986 display::win::ScreenWin::DIPToScreenRect(hwnd(), dip_caret_bounds);
987 // Collapse any selection.
988 caret_bounds.set_width(1);
989 ax_system_caret_->MoveCaretTo(caret_bounds);
990 }
991
992 void HWNDMessageHandler::OnTextInputStateChanged(
993 const ui::TextInputClient* client) {}
994
995 void HWNDMessageHandler::OnInputMethodDestroyed(
996 const ui::InputMethod* input_method) {
997 DestroyAXSystemCaret();
998 }
999
1000 void HWNDMessageHandler::OnShowImeIfNeeded() {}
1001
952 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, 1002 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message,
953 WPARAM w_param, 1003 WPARAM w_param,
954 LPARAM l_param, 1004 LPARAM l_param,
955 bool* handled) { 1005 bool* handled) {
956 // Don't track forwarded mouse messages. We expect the caller to track the 1006 // Don't track forwarded mouse messages. We expect the caller to track the
957 // mouse. 1007 // mouse.
958 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 1008 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
959 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false); 1009 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false);
960 *handled = IsMsgHandled(); 1010 *handled = IsMsgHandled();
961 return ret; 1011 return ret;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 1576
1527 // Only the lower 32 bits of l_param are valid when checking the object id 1577 // Only the lower 32 bits of l_param are valid when checking the object id
1528 // because it sometimes gets sign-extended incorrectly (but not always). 1578 // because it sometimes gets sign-extended incorrectly (but not always).
1529 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); 1579 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param));
1530 1580
1531 // Accessibility readers will send an OBJID_CLIENT message 1581 // Accessibility readers will send an OBJID_CLIENT message
1532 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) { 1582 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) {
1533 // Retrieve MSAA dispatch object for the root view. 1583 // Retrieve MSAA dispatch object for the root view.
1534 base::win::ScopedComPtr<IAccessible> root( 1584 base::win::ScopedComPtr<IAccessible> root(
1535 delegate_->GetNativeViewAccessible()); 1585 delegate_->GetNativeViewAccessible());
1536
1537 // Create a reference that MSAA will marshall to the client.
1538 reference_result = LresultFromObject(IID_IAccessible, w_param, 1586 reference_result = LresultFromObject(IID_IAccessible, w_param,
1539 static_cast<IAccessible*>(root.Detach())); 1587 static_cast<IAccessible*>(root.Detach()));
1588 } else if (::GetFocus() == hwnd() && ax_system_caret_ &&
1589 static_cast<DWORD>(OBJID_CARET) == obj_id) {
1590 base::win::ScopedComPtr<IAccessible> ax_system_caret_accessible =
1591 ax_system_caret_->GetCaret();
1592 reference_result = LresultFromObject(IID_IAccessible, w_param,
1593 ax_system_caret_accessible.Detach());
1540 } 1594 }
1541 1595
1542 return reference_result; 1596 return reference_result;
1543 } 1597 }
1544 1598
1545 LRESULT HWNDMessageHandler::OnImeMessages(UINT message, 1599 LRESULT HWNDMessageHandler::OnImeMessages(UINT message,
1546 WPARAM w_param, 1600 WPARAM w_param,
1547 LPARAM l_param) { 1601 LPARAM l_param) {
1548 LRESULT result = 0; 1602 LRESULT result = 0;
1549 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 1603 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 // Ignore size/move/maximize in fullscreen mode. 2227 // Ignore size/move/maximize in fullscreen mode.
2174 if (IsFullscreen() && (((notification_code & sc_mask) == SC_SIZE) || 2228 if (IsFullscreen() && (((notification_code & sc_mask) == SC_SIZE) ||
2175 ((notification_code & sc_mask) == SC_MOVE) || 2229 ((notification_code & sc_mask) == SC_MOVE) ||
2176 ((notification_code & sc_mask) == SC_MAXIMIZE))) 2230 ((notification_code & sc_mask) == SC_MAXIMIZE)))
2177 return; 2231 return;
2178 if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { 2232 if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) {
2179 if ((notification_code & sc_mask) == SC_MINIMIZE || 2233 if ((notification_code & sc_mask) == SC_MINIMIZE ||
2180 (notification_code & sc_mask) == SC_MAXIMIZE || 2234 (notification_code & sc_mask) == SC_MAXIMIZE ||
2181 (notification_code & sc_mask) == SC_RESTORE) { 2235 (notification_code & sc_mask) == SC_RESTORE) {
2182 delegate_->ResetWindowControls(); 2236 delegate_->ResetWindowControls();
2237 DestroyAXSystemCaret();
2183 } else if ((notification_code & sc_mask) == SC_MOVE || 2238 } else if ((notification_code & sc_mask) == SC_MOVE ||
2184 (notification_code & sc_mask) == SC_SIZE) { 2239 (notification_code & sc_mask) == SC_SIZE) {
2185 if (!IsVisible()) { 2240 if (!IsVisible()) {
2186 // Circumvent ScopedRedrawLocks and force visibility before entering a 2241 // Circumvent ScopedRedrawLocks and force visibility before entering a
2187 // resize or move modal loop to get continuous sizing/moving feedback. 2242 // resize or move modal loop to get continuous sizing/moving feedback.
2188 SetWindowLong(hwnd(), GWL_STYLE, 2243 SetWindowLong(hwnd(), GWL_STYLE,
2189 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE); 2244 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE);
2190 } 2245 }
2246 DestroyAXSystemCaret();
2191 } 2247 }
2192 } 2248 }
2193 2249
2194 // Handle SC_KEYMENU, which means that the user has pressed the ALT 2250 // Handle SC_KEYMENU, which means that the user has pressed the ALT
2195 // key and released it, so we should focus the menu bar. 2251 // key and released it, so we should focus the menu bar.
2196 if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) { 2252 if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) {
2197 int modifiers = ui::EF_NONE; 2253 int modifiers = ui::EF_NONE;
2198 if (ui::win::IsShiftPressed()) 2254 if (ui::win::IsShiftPressed())
2199 modifiers |= ui::EF_SHIFT_DOWN; 2255 modifiers |= ui::EF_SHIFT_DOWN;
2200 if (ui::win::IsCtrlPressed()) 2256 if (ui::win::IsCtrlPressed())
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
2995 // not treat this like a fullscreen window. 3051 // not treat this like a fullscreen window.
2996 MONITORINFO monitor_info = {sizeof(monitor_info)}; 3052 MONITORINFO monitor_info = {sizeof(monitor_info)};
2997 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 3053 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
2998 &monitor_info); 3054 &monitor_info);
2999 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 3055 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
3000 shrunk_rect.set_height(shrunk_rect.height() - 1); 3056 shrunk_rect.set_height(shrunk_rect.height() - 1);
3001 background_fullscreen_hack_ = true; 3057 background_fullscreen_hack_ = true;
3002 SetBoundsInternal(shrunk_rect, false); 3058 SetBoundsInternal(shrunk_rect, false);
3003 } 3059 }
3004 3060
3061 void HWNDMessageHandler::DestroyAXSystemCaret() {
3062 ax_system_caret_ = nullptr;
3063 }
3064
3005 } // namespace views 3065 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/win/hwnd_message_handler.h ('k') | ui/views/win/hwnd_message_handler_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698