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

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

Issue 2962273002: Revert of Added a system caret used for accessibility on Windows. (Closed)
Patch Set: 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"
25 #include "base/win/scoped_gdi_object.h" 24 #include "base/win/scoped_gdi_object.h"
26 #include "base/win/windows_version.h" 25 #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"
32 #include "ui/base/view_prop.h" 26 #include "ui/base/view_prop.h"
33 #include "ui/base/win/internal_constants.h" 27 #include "ui/base/win/internal_constants.h"
34 #include "ui/base/win/lock_state.h" 28 #include "ui/base/win/lock_state.h"
35 #include "ui/base/win/mouse_wheel_util.h" 29 #include "ui/base/win/mouse_wheel_util.h"
36 #include "ui/base/win/shell.h" 30 #include "ui/base/win/shell.h"
37 #include "ui/base/win/touch_input.h" 31 #include "ui/base/win/touch_input.h"
38 #include "ui/display/win/dpi.h" 32 #include "ui/display/win/dpi.h"
39 #include "ui/display/win/screen_win.h" 33 #include "ui/display/win/screen_win.h"
40 #include "ui/events/event.h" 34 #include "ui/events/event.h"
41 #include "ui/events/event_constants.h" 35 #include "ui/events/event_constants.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 touch_down_contexts_(0), 355 touch_down_contexts_(0),
362 last_mouse_hwheel_time_(0), 356 last_mouse_hwheel_time_(0),
363 dwm_transition_desired_(false), 357 dwm_transition_desired_(false),
364 sent_window_size_changing_(false), 358 sent_window_size_changing_(false),
365 left_button_down_on_caption_(false), 359 left_button_down_on_caption_(false),
366 background_fullscreen_hack_(false), 360 background_fullscreen_hack_(false),
367 autohide_factory_(this), 361 autohide_factory_(this),
368 weak_factory_(this) {} 362 weak_factory_(this) {}
369 363
370 HWNDMessageHandler::~HWNDMessageHandler() { 364 HWNDMessageHandler::~HWNDMessageHandler() {
371 DCHECK(delegate_->GetHWNDMessageDelegateInputMethod());
372 delegate_->GetHWNDMessageDelegateInputMethod()->RemoveObserver(this);
373 delegate_ = NULL; 365 delegate_ = NULL;
374 // Prevent calls back into this class via WNDPROC now that we've been 366 // Prevent calls back into this class via WNDPROC now that we've been
375 // destroyed. 367 // destroyed.
376 ClearUserData(); 368 ClearUserData();
377 } 369 }
378 370
379 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { 371 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
380 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); 372 TRACE_EVENT0("views", "HWNDMessageHandler::Init");
381 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, 373 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_,
382 &last_work_area_); 374 &last_work_area_);
(...skipping 13 matching lines...) Expand all
396 GetProcAddress(GetModuleHandle(L"user32.dll"), 388 GetProcAddress(GetModuleHandle(L"user32.dll"),
397 "EnableChildWindowDpiMessage")); 389 "EnableChildWindowDpiMessage"));
398 }(); 390 }();
399 if (enable_child_window_dpi_message_func) 391 if (enable_child_window_dpi_message_func)
400 enable_child_window_dpi_message_func(hwnd(), TRUE); 392 enable_child_window_dpi_message_func(hwnd(), TRUE);
401 } 393 }
402 394
403 prop_window_target_.reset(new ui::ViewProp(hwnd(), 395 prop_window_target_.reset(new ui::ViewProp(hwnd(),
404 ui::WindowEventTarget::kWin32InputEventTarget, 396 ui::WindowEventTarget::kWin32InputEventTarget,
405 static_cast<ui::WindowEventTarget*>(this))); 397 static_cast<ui::WindowEventTarget*>(this)));
406 DCHECK(delegate_->GetHWNDMessageDelegateInputMethod());
407 delegate_->GetHWNDMessageDelegateInputMethod()->AddObserver(this);
408 398
409 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function 399 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function
410 // returns NULL if Direct Manipulation is not available. 400 // returns NULL if Direct Manipulation is not available.
411 direct_manipulation_helper_ = 401 direct_manipulation_helper_ =
412 gfx::win::DirectManipulationHelper::CreateInstance(); 402 gfx::win::DirectManipulationHelper::CreateInstance();
413 if (direct_manipulation_helper_) 403 if (direct_manipulation_helper_)
414 direct_manipulation_helper_->Initialize(hwnd()); 404 direct_manipulation_helper_->Initialize(hwnd());
415 405
416 // Disable pen flicks (http://crbug.com/506977) 406 // Disable pen flicks (http://crbug.com/506977)
417 base::win::DisableFlicks(hwnd()); 407 base::win::DisableFlicks(hwnd());
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 delegate_->HandleDestroyed(); 942 delegate_->HandleDestroyed();
953 } 943 }
954 } 944 }
955 945
956 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) 946 if (message == WM_ACTIVATE && IsTopLevelWindow(window))
957 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), 947 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param),
958 reinterpret_cast<HWND>(l_param)); 948 reinterpret_cast<HWND>(l_param));
959 return result; 949 return result;
960 } 950 }
961 951
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
1002 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, 952 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message,
1003 WPARAM w_param, 953 WPARAM w_param,
1004 LPARAM l_param, 954 LPARAM l_param,
1005 bool* handled) { 955 bool* handled) {
1006 // Don't track forwarded mouse messages. We expect the caller to track the 956 // Don't track forwarded mouse messages. We expect the caller to track the
1007 // mouse. 957 // mouse.
1008 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 958 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
1009 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false); 959 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false);
1010 *handled = IsMsgHandled(); 960 *handled = IsMsgHandled();
1011 return ret; 961 return ret;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 1526
1577 // Only the lower 32 bits of l_param are valid when checking the object id 1527 // Only the lower 32 bits of l_param are valid when checking the object id
1578 // because it sometimes gets sign-extended incorrectly (but not always). 1528 // because it sometimes gets sign-extended incorrectly (but not always).
1579 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); 1529 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param));
1580 1530
1581 // Accessibility readers will send an OBJID_CLIENT message 1531 // Accessibility readers will send an OBJID_CLIENT message
1582 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) { 1532 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) {
1583 // Retrieve MSAA dispatch object for the root view. 1533 // Retrieve MSAA dispatch object for the root view.
1584 base::win::ScopedComPtr<IAccessible> root( 1534 base::win::ScopedComPtr<IAccessible> root(
1585 delegate_->GetNativeViewAccessible()); 1535 delegate_->GetNativeViewAccessible());
1536
1537 // Create a reference that MSAA will marshall to the client.
1586 reference_result = LresultFromObject(IID_IAccessible, w_param, 1538 reference_result = LresultFromObject(IID_IAccessible, w_param,
1587 static_cast<IAccessible*>(root.Detach())); 1539 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());
1594 } 1540 }
1595 1541
1596 return reference_result; 1542 return reference_result;
1597 } 1543 }
1598 1544
1599 LRESULT HWNDMessageHandler::OnImeMessages(UINT message, 1545 LRESULT HWNDMessageHandler::OnImeMessages(UINT message,
1600 WPARAM w_param, 1546 WPARAM w_param,
1601 LPARAM l_param) { 1547 LPARAM l_param) {
1602 LRESULT result = 0; 1548 LRESULT result = 0;
1603 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 1549 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 // Ignore size/move/maximize in fullscreen mode. 2173 // Ignore size/move/maximize in fullscreen mode.
2228 if (IsFullscreen() && (((notification_code & sc_mask) == SC_SIZE) || 2174 if (IsFullscreen() && (((notification_code & sc_mask) == SC_SIZE) ||
2229 ((notification_code & sc_mask) == SC_MOVE) || 2175 ((notification_code & sc_mask) == SC_MOVE) ||
2230 ((notification_code & sc_mask) == SC_MAXIMIZE))) 2176 ((notification_code & sc_mask) == SC_MAXIMIZE)))
2231 return; 2177 return;
2232 if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { 2178 if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) {
2233 if ((notification_code & sc_mask) == SC_MINIMIZE || 2179 if ((notification_code & sc_mask) == SC_MINIMIZE ||
2234 (notification_code & sc_mask) == SC_MAXIMIZE || 2180 (notification_code & sc_mask) == SC_MAXIMIZE ||
2235 (notification_code & sc_mask) == SC_RESTORE) { 2181 (notification_code & sc_mask) == SC_RESTORE) {
2236 delegate_->ResetWindowControls(); 2182 delegate_->ResetWindowControls();
2237 DestroyAXSystemCaret();
2238 } else if ((notification_code & sc_mask) == SC_MOVE || 2183 } else if ((notification_code & sc_mask) == SC_MOVE ||
2239 (notification_code & sc_mask) == SC_SIZE) { 2184 (notification_code & sc_mask) == SC_SIZE) {
2240 if (!IsVisible()) { 2185 if (!IsVisible()) {
2241 // Circumvent ScopedRedrawLocks and force visibility before entering a 2186 // Circumvent ScopedRedrawLocks and force visibility before entering a
2242 // resize or move modal loop to get continuous sizing/moving feedback. 2187 // resize or move modal loop to get continuous sizing/moving feedback.
2243 SetWindowLong(hwnd(), GWL_STYLE, 2188 SetWindowLong(hwnd(), GWL_STYLE,
2244 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE); 2189 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE);
2245 } 2190 }
2246 DestroyAXSystemCaret();
2247 } 2191 }
2248 } 2192 }
2249 2193
2250 // Handle SC_KEYMENU, which means that the user has pressed the ALT 2194 // Handle SC_KEYMENU, which means that the user has pressed the ALT
2251 // key and released it, so we should focus the menu bar. 2195 // key and released it, so we should focus the menu bar.
2252 if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) { 2196 if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) {
2253 int modifiers = ui::EF_NONE; 2197 int modifiers = ui::EF_NONE;
2254 if (ui::win::IsShiftPressed()) 2198 if (ui::win::IsShiftPressed())
2255 modifiers |= ui::EF_SHIFT_DOWN; 2199 modifiers |= ui::EF_SHIFT_DOWN;
2256 if (ui::win::IsCtrlPressed()) 2200 if (ui::win::IsCtrlPressed())
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 // not treat this like a fullscreen window. 2995 // not treat this like a fullscreen window.
3052 MONITORINFO monitor_info = {sizeof(monitor_info)}; 2996 MONITORINFO monitor_info = {sizeof(monitor_info)};
3053 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 2997 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
3054 &monitor_info); 2998 &monitor_info);
3055 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 2999 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
3056 shrunk_rect.set_height(shrunk_rect.height() - 1); 3000 shrunk_rect.set_height(shrunk_rect.height() - 1);
3057 background_fullscreen_hack_ = true; 3001 background_fullscreen_hack_ = true;
3058 SetBoundsInternal(shrunk_rect, false); 3002 SetBoundsInternal(shrunk_rect, false);
3059 } 3003 }
3060 3004
3061 void HWNDMessageHandler::DestroyAXSystemCaret() {
3062 ax_system_caret_ = nullptr;
3063 }
3064
3065 } // namespace views 3005 } // 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