 Chromium Code Reviews
 Chromium Code Reviews Issue 2781613003:
  Added a class acting as a fake caret for accessibility.  (Closed)
    
  
    Issue 2781613003:
  Added a class acting as a fake caret for accessibility.  (Closed) 
  | Index: ui/views/win/hwnd_message_handler.cc | 
| diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc | 
| index 94ba71385f4323bd06674ea29a4fb9beabdf41cf..9a84ac8aae233049cd9bd5e66efa25bcb2a6148d 100644 | 
| --- a/ui/views/win/hwnd_message_handler.cc | 
| +++ b/ui/views/win/hwnd_message_handler.cc | 
| @@ -20,8 +20,12 @@ | 
| #include "base/threading/thread_task_runner_handle.h" | 
| #include "base/time/time.h" | 
| #include "base/trace_event/trace_event.h" | 
| +#include "base/win/scoped_comptr.h" | 
| #include "base/win/scoped_gdi_object.h" | 
| #include "base/win/windows_version.h" | 
| +#include "ui/accessibility/platform/ax_fake_caret_win.h" | 
| +#include "ui/accessibility/platform/ax_platform_node_win.h" | 
| +#include "ui/base/ime/input_method_client.h" | 
| #include "ui/base/view_prop.h" | 
| #include "ui/base/win/internal_constants.h" | 
| #include "ui/base/win/lock_state.h" | 
| @@ -385,6 +389,9 @@ void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { | 
| ui::WindowEventTarget::kWin32InputEventTarget, | 
| static_cast<ui::WindowEventTarget*>(this))); | 
| + ax_fake_caret_ = std::make_unique<ui::AXFakeCaretWin>(hwnd()); | 
| + delegate_->AddInputMethodObserver(); | 
| + | 
| // Direct Manipulation is enabled on Windows 10+. The CreateInstance function | 
| // returns NULL if Direct Manipulation is not available. | 
| direct_manipulation_helper_ = | 
| @@ -929,6 +936,7 @@ LRESULT HWNDMessageHandler::OnWndProc(UINT message, | 
| delegate_->PostHandleMSG(message, w_param, l_param); | 
| if (message == WM_NCDESTROY) { | 
| RestoreEnabledIfNecessary(); | 
| + delegate_->RemoveInputMethodObserver(); | 
| delegate_->HandleDestroyed(); | 
| } | 
| } | 
| @@ -939,6 +947,13 @@ LRESULT HWNDMessageHandler::OnWndProc(UINT message, | 
| return result; | 
| } | 
| +void OnCaretBoundsChanged(const TextInputClient* client) { | 
| + DCHECK(ax_fake_caret_); | 
| + const gfx::Rect dip_screen_bounds(client->GetCaretBounds()); | 
| + const gfx::Rect screen_bounds = display::win::ScreenWin::DIPToScreenRect(hwnd(), dip_screen_bounds); | 
| + ax_fake_caret_->MoveCaretTo(screen_bounds); | 
| +} | 
| + | 
| LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, | 
| WPARAM w_param, | 
| LPARAM l_param, | 
| @@ -1521,10 +1536,14 @@ LRESULT HWNDMessageHandler::OnGetObject(UINT message, | 
| // Retrieve MSAA dispatch object for the root view. | 
| base::win::ScopedComPtr<IAccessible> root( | 
| delegate_->GetNativeViewAccessible()); | 
| - | 
| - // Create a reference that MSAA will marshall to the client. | 
| reference_result = LresultFromObject(IID_IAccessible, w_param, | 
| static_cast<IAccessible*>(root.Detach())); | 
| + } else if (static_cast<DWORD>(OBJID_CARET) == obj_id) { | 
| 
dmazzoni
2017/04/27 05:07:32
Only if focused???
 | 
| + DCHECK(ax_fake_caret_); | 
| + base::win::ScopedComPtr<IAccessible> fake_caret_accessible = | 
| + ax_fake_caret_->GetCaret(); | 
| + reference_result = LresultFromObject(IID_IAccessible, w_param, | 
| + fake_caret_accessible.Detach()); | 
| } | 
| return reference_result; |