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

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

Issue 2781613003: Added a class acting as a fake caret for accessibility. (Closed)
Patch Set: Added code that handles views. Created 3 years, 7 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 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/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "base/trace_event/trace_event.h" 22 #include "base/trace_event/trace_event.h"
23 #include "base/win/scoped_comptr.h"
23 #include "base/win/scoped_gdi_object.h" 24 #include "base/win/scoped_gdi_object.h"
24 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
26 #include "ui/accessibility/platform/ax_fake_caret_win.h"
27 #include "ui/accessibility/platform/ax_platform_node_win.h"
28 #include "ui/base/ime/input_method_client.h"
25 #include "ui/base/view_prop.h" 29 #include "ui/base/view_prop.h"
26 #include "ui/base/win/internal_constants.h" 30 #include "ui/base/win/internal_constants.h"
27 #include "ui/base/win/lock_state.h" 31 #include "ui/base/win/lock_state.h"
28 #include "ui/base/win/mouse_wheel_util.h" 32 #include "ui/base/win/mouse_wheel_util.h"
29 #include "ui/base/win/shell.h" 33 #include "ui/base/win/shell.h"
30 #include "ui/base/win/touch_input.h" 34 #include "ui/base/win/touch_input.h"
31 #include "ui/display/win/dpi.h" 35 #include "ui/display/win/dpi.h"
32 #include "ui/display/win/screen_win.h" 36 #include "ui/display/win/screen_win.h"
33 #include "ui/events/event.h" 37 #include "ui/events/event.h"
34 #include "ui/events/event_constants.h" 38 #include "ui/events/event_constants.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 "EnableChildWindowDpiMessage")); 382 "EnableChildWindowDpiMessage"));
379 }(); 383 }();
380 if (enable_child_window_dpi_message_func) 384 if (enable_child_window_dpi_message_func)
381 enable_child_window_dpi_message_func(hwnd(), TRUE); 385 enable_child_window_dpi_message_func(hwnd(), TRUE);
382 } 386 }
383 387
384 prop_window_target_.reset(new ui::ViewProp(hwnd(), 388 prop_window_target_.reset(new ui::ViewProp(hwnd(),
385 ui::WindowEventTarget::kWin32InputEventTarget, 389 ui::WindowEventTarget::kWin32InputEventTarget,
386 static_cast<ui::WindowEventTarget*>(this))); 390 static_cast<ui::WindowEventTarget*>(this)));
387 391
392 ax_fake_caret_ = std::make_unique<ui::AXFakeCaretWin>(hwnd());
393 delegate_->AddInputMethodObserver();
394
388 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function 395 // Direct Manipulation is enabled on Windows 10+. The CreateInstance function
389 // returns NULL if Direct Manipulation is not available. 396 // returns NULL if Direct Manipulation is not available.
390 direct_manipulation_helper_ = 397 direct_manipulation_helper_ =
391 gfx::win::DirectManipulationHelper::CreateInstance(); 398 gfx::win::DirectManipulationHelper::CreateInstance();
392 if (direct_manipulation_helper_) 399 if (direct_manipulation_helper_)
393 direct_manipulation_helper_->Initialize(hwnd()); 400 direct_manipulation_helper_->Initialize(hwnd());
394 401
395 // Disable pen flicks (http://crbug.com/506977) 402 // Disable pen flicks (http://crbug.com/506977)
396 base::win::DisableFlicks(hwnd()); 403 base::win::DisableFlicks(hwnd());
397 } 404 }
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 // DefWindowProc() may have destroyed the window and/or us in a nested 929 // DefWindowProc() may have destroyed the window and/or us in a nested
923 // message loop. 930 // message loop.
924 if (!ref || !::IsWindow(window)) 931 if (!ref || !::IsWindow(window))
925 return result; 932 return result;
926 } 933 }
927 934
928 if (delegate_) { 935 if (delegate_) {
929 delegate_->PostHandleMSG(message, w_param, l_param); 936 delegate_->PostHandleMSG(message, w_param, l_param);
930 if (message == WM_NCDESTROY) { 937 if (message == WM_NCDESTROY) {
931 RestoreEnabledIfNecessary(); 938 RestoreEnabledIfNecessary();
939 delegate_->RemoveInputMethodObserver();
932 delegate_->HandleDestroyed(); 940 delegate_->HandleDestroyed();
933 } 941 }
934 } 942 }
935 943
936 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) 944 if (message == WM_ACTIVATE && IsTopLevelWindow(window))
937 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), 945 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param),
938 reinterpret_cast<HWND>(l_param)); 946 reinterpret_cast<HWND>(l_param));
939 return result; 947 return result;
940 } 948 }
941 949
950 void OnCaretBoundsChanged(const TextInputClient* client) {
951 DCHECK(ax_fake_caret_);
952 const gfx::Rect dip_screen_bounds(client->GetCaretBounds());
953 const gfx::Rect screen_bounds = display::win::ScreenWin::DIPToScreenRect(hwnd( ), dip_screen_bounds);
954 ax_fake_caret_->MoveCaretTo(screen_bounds);
955 }
956
942 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, 957 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message,
943 WPARAM w_param, 958 WPARAM w_param,
944 LPARAM l_param, 959 LPARAM l_param,
945 bool* handled) { 960 bool* handled) {
946 // Don't track forwarded mouse messages. We expect the caller to track the 961 // Don't track forwarded mouse messages. We expect the caller to track the
947 // mouse. 962 // mouse.
948 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 963 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
949 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false); 964 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false);
950 *handled = IsMsgHandled(); 965 *handled = IsMsgHandled();
951 return ret; 966 return ret;
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 1529
1515 // Only the lower 32 bits of l_param are valid when checking the object id 1530 // Only the lower 32 bits of l_param are valid when checking the object id
1516 // because it sometimes gets sign-extended incorrectly (but not always). 1531 // because it sometimes gets sign-extended incorrectly (but not always).
1517 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); 1532 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param));
1518 1533
1519 // Accessibility readers will send an OBJID_CLIENT message 1534 // Accessibility readers will send an OBJID_CLIENT message
1520 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) { 1535 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) {
1521 // Retrieve MSAA dispatch object for the root view. 1536 // Retrieve MSAA dispatch object for the root view.
1522 base::win::ScopedComPtr<IAccessible> root( 1537 base::win::ScopedComPtr<IAccessible> root(
1523 delegate_->GetNativeViewAccessible()); 1538 delegate_->GetNativeViewAccessible());
1524
1525 // Create a reference that MSAA will marshall to the client.
1526 reference_result = LresultFromObject(IID_IAccessible, w_param, 1539 reference_result = LresultFromObject(IID_IAccessible, w_param,
1527 static_cast<IAccessible*>(root.Detach())); 1540 static_cast<IAccessible*>(root.Detach()));
1541 } else if (static_cast<DWORD>(OBJID_CARET) == obj_id) {
dmazzoni 2017/04/27 05:07:32 Only if focused???
1542 DCHECK(ax_fake_caret_);
1543 base::win::ScopedComPtr<IAccessible> fake_caret_accessible =
1544 ax_fake_caret_->GetCaret();
1545 reference_result = LresultFromObject(IID_IAccessible, w_param,
1546 fake_caret_accessible.Detach());
1528 } 1547 }
1529 1548
1530 return reference_result; 1549 return reference_result;
1531 } 1550 }
1532 1551
1533 LRESULT HWNDMessageHandler::OnImeMessages(UINT message, 1552 LRESULT HWNDMessageHandler::OnImeMessages(UINT message,
1534 WPARAM w_param, 1553 WPARAM w_param,
1535 LPARAM l_param) { 1554 LPARAM l_param) {
1536 LRESULT result = 0; 1555 LRESULT result = 0;
1537 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 1556 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
(...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after
2902 MONITORINFO monitor_info = {sizeof(monitor_info)}; 2921 MONITORINFO monitor_info = {sizeof(monitor_info)};
2903 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 2922 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
2904 &monitor_info); 2923 &monitor_info);
2905 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 2924 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
2906 shrunk_rect.set_height(shrunk_rect.height() - 1); 2925 shrunk_rect.set_height(shrunk_rect.height() - 1);
2907 background_fullscreen_hack_ = true; 2926 background_fullscreen_hack_ = true;
2908 SetBoundsInternal(shrunk_rect, false); 2927 SetBoundsInternal(shrunk_rect, false);
2909 } 2928 }
2910 2929
2911 } // namespace views 2930 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698