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

Side by Side Diff: content/browser/renderer_host/legacy_render_widget_host_win.cc

Issue 2781613003: Added a class acting as a fake caret for accessibility. (Closed)
Patch Set: Fixed compilation error due to rebase. 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) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 "content/browser/renderer_host/legacy_render_widget_host_win.h" 5 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
6 6
7 #include <objbase.h> 7 #include <objbase.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility>
10 11
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/win/win_util.h" 13 #include "base/win/win_util.h"
13 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
14 #include "content/browser/accessibility/browser_accessibility_manager_win.h" 15 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
15 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 16 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
16 #include "content/browser/accessibility/browser_accessibility_win.h" 17 #include "content/browser/accessibility/browser_accessibility_win.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h" 18 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 19 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
19 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "ui/accessibility/platform/ax_fake_caret_win.h"
20 #include "ui/base/view_prop.h" 22 #include "ui/base/view_prop.h"
21 #include "ui/base/win/internal_constants.h" 23 #include "ui/base/win/internal_constants.h"
22 #include "ui/base/win/window_event_target.h" 24 #include "ui/base/win/window_event_target.h"
23 #include "ui/display/win/screen_win.h" 25 #include "ui/display/win/screen_win.h"
24 #include "ui/gfx/geometry/rect.h" 26 #include "ui/gfx/geometry/rect.h"
25 #include "ui/gfx/win/direct_manipulation.h" 27 #include "ui/gfx/win/direct_manipulation.h"
26 28
27 namespace content { 29 namespace content {
28 30
29 // A custom MSAA object id used to determine if a screen reader or some 31 // A custom MSAA object id used to determine if a screen reader or some
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { 82 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) {
81 gfx::Rect bounds_in_pixel = display::win::ScreenWin::DIPToClientRect(hwnd(), 83 gfx::Rect bounds_in_pixel = display::win::ScreenWin::DIPToClientRect(hwnd(),
82 bounds); 84 bounds);
83 ::SetWindowPos(hwnd(), NULL, bounds_in_pixel.x(), bounds_in_pixel.y(), 85 ::SetWindowPos(hwnd(), NULL, bounds_in_pixel.x(), bounds_in_pixel.y(),
84 bounds_in_pixel.width(), bounds_in_pixel.height(), 86 bounds_in_pixel.width(), bounds_in_pixel.height(),
85 SWP_NOREDRAW); 87 SWP_NOREDRAW);
86 if (direct_manipulation_helper_) 88 if (direct_manipulation_helper_)
87 direct_manipulation_helper_->SetBounds(bounds_in_pixel); 89 direct_manipulation_helper_->SetBounds(bounds_in_pixel);
88 } 90 }
89 91
92 void LegacyRenderWidgetHostHWND::MoveCaretTo(const gfx::Rect& bounds) {
93 DCHECK(ax_fake_caret_);
94 ax_fake_caret_->MoveCaretTo(bounds);
95 }
96
90 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { 97 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) {
91 if (host_) { 98 if (host_) {
92 host_->OnLegacyWindowDestroyed(); 99 host_->OnLegacyWindowDestroyed();
93 host_ = NULL; 100 host_ = NULL;
94 } 101 }
95 102
96 // Re-enable flicks for just a moment 103 // Re-enable flicks for just a moment
97 base::win::EnableFlicks(hwnd); 104 base::win::EnableFlicks(hwnd);
98 105
99 delete this; 106 delete this;
100 } 107 }
101 108
102 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) 109 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent)
103 : mouse_tracking_enabled_(false), 110 : mouse_tracking_enabled_(false), host_(nullptr) {
104 host_(NULL) {
105 RECT rect = {0}; 111 RECT rect = {0};
106 Base::Create(parent, rect, L"Chrome Legacy Window", 112 Base::Create(parent, rect, L"Chrome Legacy Window",
107 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 113 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
108 WS_EX_TRANSPARENT); 114 WS_EX_TRANSPARENT);
115 // We create the fake caret regardless of accessibility mode since not all
116 // assistive software that makes use of a fake caret is classified as a screen
117 // reader, e.g. the built-in Windows Magnifier.
118 ax_fake_caret_ = std::make_unique<ui::AXFakeCaretWin>(hwnd());
109 } 119 }
110 120
111 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { 121 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() {
112 DCHECK(!::IsWindow(hwnd())); 122 DCHECK(!::IsWindow(hwnd()));
113 } 123 }
114 124
115 bool LegacyRenderWidgetHostHWND::Init() { 125 bool LegacyRenderWidgetHostHWND::Init() {
116 if (base::win::GetVersion() >= base::win::VERSION_WIN7) 126 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
117 RegisterTouchWindow(hwnd(), TWF_WANTPALM); 127 RegisterTouchWindow(hwnd(), TWF_WANTPALM);
118 128
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 174
165 if (kIdScreenReaderHoneyPot == obj_id) { 175 if (kIdScreenReaderHoneyPot == obj_id) {
166 // When an MSAA client has responded to our fake event on this id, 176 // When an MSAA client has responded to our fake event on this id,
167 // enable basic accessibility support. (Full screen reader support is 177 // enable basic accessibility support. (Full screen reader support is
168 // detected later when specific more advanced APIs are accessed.) 178 // detected later when specific more advanced APIs are accessed.)
169 BrowserAccessibilityStateImpl::GetInstance()->AddAccessibilityModeFlags( 179 BrowserAccessibilityStateImpl::GetInstance()->AddAccessibilityModeFlags(
170 AccessibilityMode::kNativeAPIs | AccessibilityMode::kWebContents); 180 AccessibilityMode::kNativeAPIs | AccessibilityMode::kWebContents);
171 return static_cast<LRESULT>(0L); 181 return static_cast<LRESULT>(0L);
172 } 182 }
173 183
174 if (static_cast<DWORD>(OBJID_CLIENT) != obj_id || !host_) 184 if (!host_)
175 return static_cast<LRESULT>(0L); 185 return static_cast<LRESULT>(0L);
176 186
177 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( 187 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) {
178 host_->GetRenderWidgetHost()); 188 RenderWidgetHostImpl* rwhi =
179 if (!rwhi) 189 RenderWidgetHostImpl::From(host_->GetRenderWidgetHost());
180 return static_cast<LRESULT>(0L); 190 if (!rwhi)
191 return static_cast<LRESULT>(0L);
181 192
182 BrowserAccessibilityManagerWin* manager = 193 BrowserAccessibilityManagerWin* manager =
183 static_cast<BrowserAccessibilityManagerWin*>( 194 static_cast<BrowserAccessibilityManagerWin*>(
184 rwhi->GetRootBrowserAccessibilityManager()); 195 rwhi->GetRootBrowserAccessibilityManager());
185 if (!manager || !manager->GetRoot()) 196 if (!manager || !manager->GetRoot())
186 return static_cast<LRESULT>(0L); 197 return static_cast<LRESULT>(0L);
187 198
188 base::win::ScopedComPtr<IAccessible> root( 199 base::win::ScopedComPtr<IAccessible> root(
189 ToBrowserAccessibilityWin(manager->GetRoot())->GetCOM()); 200 ToBrowserAccessibilityWin(manager->GetRoot())->GetCOM());
190 return LresultFromObject(IID_IAccessible, w_param, 201 return LresultFromObject(IID_IAccessible, w_param,
191 static_cast<IAccessible*>(root.Detach())); 202 static_cast<IAccessible*>(root.Detach()));
203 }
204
205 if (static_cast<DWORD>(OBJID_CARET) == obj_id && host_->HasFocus()) {
206 DCHECK(ax_fake_caret_);
207 base::win::ScopedComPtr<IAccessible> fake_caret_accessible =
208 ax_fake_caret_->GetCaret();
209 return LresultFromObject(IID_IAccessible, w_param,
210 fake_caret_accessible.Detach());
211 }
212
213 return static_cast<LRESULT>(0L);
192 } 214 }
193 215
194 // We send keyboard/mouse/touch messages to the parent window via SendMessage. 216 // We send keyboard/mouse/touch messages to the parent window via SendMessage.
195 // While this works, this has the side effect of converting input messages into 217 // While this works, this has the side effect of converting input messages into
196 // sent messages which changes their priority and could technically result 218 // sent messages which changes their priority and could technically result
197 // in these messages starving other messages in the queue. Additionally 219 // in these messages starving other messages in the queue. Additionally
198 // keyboard/mouse hooks would not see these messages. The alternative approach 220 // keyboard/mouse hooks would not see these messages. The alternative approach
199 // is to set and release capture as needed on the parent to ensure that it 221 // is to set and release capture as needed on the parent to ensure that it
200 // receives all mouse events. However that was shelved due to possible issues 222 // receives all mouse events. However that was shelved due to possible issues
201 // with capture changes. 223 // with capture changes.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 direct_manipulation_helper_->Activate(hwnd()); 444 direct_manipulation_helper_->Activate(hwnd());
423 } else if (window_pos->flags & SWP_HIDEWINDOW) { 445 } else if (window_pos->flags & SWP_HIDEWINDOW) {
424 direct_manipulation_helper_->Deactivate(hwnd()); 446 direct_manipulation_helper_->Deactivate(hwnd());
425 } 447 }
426 } 448 }
427 SetMsgHandled(FALSE); 449 SetMsgHandled(FALSE);
428 return 0; 450 return 0;
429 } 451 }
430 452
431 } // namespace content 453 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698