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

Side by Side Diff: content/browser/accessibility/browser_accessibility_com_win.cc

Issue 2864953002: Split out the MSCOM pieces of BrowserAccessibilityWin into a seperate class. (Closed)
Patch Set: follow up comment 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) 2017 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/accessibility/browser_accessibility_win.h" 5 #include "content/browser/accessibility/browser_accessibility_com_win.h"
6 6
7 #include <UIAutomationClient.h> 7 #include <UIAutomationClient.h>
8 #include <UIAutomationCoreApi.h> 8 #include <UIAutomationCoreApi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <iterator> 11 #include <iterator>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/win/enum_variant.h" 19 #include "base/win/enum_variant.h"
20 #include "base/win/scoped_comptr.h" 20 #include "base/win/scoped_comptr.h"
21 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
22 #include "content/browser/accessibility/browser_accessibility_event_win.h" 22 #include "content/browser/accessibility/browser_accessibility_event_win.h"
23 #include "content/browser/accessibility/browser_accessibility_manager_win.h" 23 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 24 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
25 #include "content/browser/accessibility/browser_accessibility_win.h"
25 #include "content/common/accessibility_messages.h" 26 #include "content/common/accessibility_messages.h"
26 #include "content/common/accessibility_mode.h" 27 #include "content/common/accessibility_mode.h"
27 #include "content/public/common/content_client.h" 28 #include "content/public/common/content_client.h"
28 #include "third_party/skia/include/core/SkColor.h" 29 #include "third_party/skia/include/core/SkColor.h"
29 #include "ui/accessibility/ax_text_utils.h" 30 #include "ui/accessibility/ax_text_utils.h"
30 #include "ui/base/win/accessibility_ids_win.h" 31 #include "ui/base/win/accessibility_ids_win.h"
31 #include "ui/base/win/accessibility_misc_utils.h" 32 #include "ui/base/win/accessibility_misc_utils.h"
32 #include "ui/base/win/atl_module.h" 33 #include "ui/base/win/atl_module.h"
33 34
34 namespace { 35 namespace {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 UMA_API_TABLECELL_GET_ROW_INDEX = 155, 196 UMA_API_TABLECELL_GET_ROW_INDEX = 155,
196 UMA_API_UNSELECT_COLUMN = 156, 197 UMA_API_UNSELECT_COLUMN = 156,
197 UMA_API_UNSELECT_ROW = 157, 198 UMA_API_UNSELECT_ROW = 157,
198 199
199 // This must always be the last enum. It's okay for its value to 200 // This must always be the last enum. It's okay for its value to
200 // increase, but none of the other enum values may change. 201 // increase, but none of the other enum values may change.
201 UMA_API_MAX 202 UMA_API_MAX
202 }; 203 };
203 204
204 #define WIN_ACCESSIBILITY_API_HISTOGRAM(enum_value) \ 205 #define WIN_ACCESSIBILITY_API_HISTOGRAM(enum_value) \
205 UMA_HISTOGRAM_ENUMERATION("Accessibility.WinAPIs", enum_value, UMA_API_MAX) 206 UMA_HISTOGRAM_ENUMERATION("Accessibility.WinAPIs", enum_value, UMA_API_MAX)
206 207
207 // There is no easy way to decouple |kScreenReader| and |kHTML| accessibility 208 // There is no easy way to decouple |kScreenReader| and |kHTML| accessibility
208 // modes when Windows screen readers are used. For example, certain roles use 209 // modes when Windows screen readers are used. For example, certain roles use
209 // the HTML tag name. Input fields require their type attribute to be exposed. 210 // the HTML tag name. Input fields require their type attribute to be exposed.
210 const uint32_t kScreenReaderAndHTMLAccessibilityModes = 211 const uint32_t kScreenReaderAndHTMLAccessibilityModes =
211 content::AccessibilityMode::kScreenReader | 212 content::AccessibilityMode::kScreenReader |
212 content::AccessibilityMode::kHTML; 213 content::AccessibilityMode::kHTML;
213 214
214 const WCHAR *const IA2_RELATION_DETAILS = L"details"; 215 const WCHAR* const IA2_RELATION_DETAILS = L"details";
215 const WCHAR *const IA2_RELATION_DETAILS_FOR = L"detailsFor"; 216 const WCHAR* const IA2_RELATION_DETAILS_FOR = L"detailsFor";
216 const WCHAR *const IA2_RELATION_ERROR_MESSAGE = L"errorMessage"; 217 const WCHAR* const IA2_RELATION_ERROR_MESSAGE = L"errorMessage";
217 218
218 } // namespace 219 } // namespace
219 220
220 namespace content { 221 namespace content {
221 222
223 using AXPlatformPositionInstance = AXPlatformPosition::AXPositionInstance;
224 using AXPlatformRange = ui::AXRange<AXPlatformPositionInstance::element_type>;
225
222 // These nonstandard GUIDs are taken directly from the Mozilla sources 226 // These nonstandard GUIDs are taken directly from the Mozilla sources
223 // (accessible/src/msaa/nsAccessNodeWrap.cpp); some documentation is here: 227 // (accessible/src/msaa/nsAccessNodeWrap.cpp); some documentation is here:
224 // http://developer.mozilla.org/en/Accessibility/AT-APIs/ImplementationFeatures/ MSAA 228 // http://developer.mozilla.org/en/Accessibility/AT-APIs/ImplementationFeatures/ MSAA
225 const GUID GUID_ISimpleDOM = {0x0c539790, 229 const GUID GUID_ISimpleDOM = {0x0c539790,
226 0x12e4, 230 0x12e4,
227 0x11cf, 231 0x11cf,
228 {0xb6, 0x61, 0x00, 0xaa, 0x00, 0x4c, 0xd6, 0xd8}}; 232 {0xb6, 0x61, 0x00, 0xaa, 0x00, 0x4c, 0xd6, 0xd8}};
229 const GUID GUID_IAccessibleContentDocument = { 233 const GUID GUID_IAccessibleContentDocument = {
230 0xa5d8e1f3, 234 0xa5d8e1f3,
231 0x3571, 235 0x3571,
232 0x4d8f, 236 0x4d8f,
233 {0x95, 0x21, 0x07, 0xed, 0x28, 0xfb, 0x07, 0x2e}}; 237 {0x95, 0x21, 0x07, 0xed, 0x28, 0xfb, 0x07, 0x2e}};
234 238
235 const base::char16 BrowserAccessibilityWin::kEmbeddedCharacter = L'\xfffc'; 239 const base::char16 BrowserAccessibilityComWin::kEmbeddedCharacter = L'\xfffc';
236 240
237 void AddAccessibilityModeFlags(AccessibilityMode mode_flags) { 241 void AddAccessibilityModeFlags(AccessibilityMode mode_flags) {
238 BrowserAccessibilityStateImpl::GetInstance()->AddAccessibilityModeFlags( 242 BrowserAccessibilityStateImpl::GetInstance()->AddAccessibilityModeFlags(
239 mode_flags); 243 mode_flags);
240 } 244 }
241 245
242 // 246 //
243 // BrowserAccessibilityRelation 247 // BrowserAccessibilityRelation
244 // 248 //
245 // A simple implementation of IAccessibleRelation, used to represent 249 // A simple implementation of IAccessibleRelation, used to represent
246 // a relationship between two accessible nodes in the tree. 250 // a relationship between two accessible nodes in the tree.
247 // 251 //
248 252
249 class BrowserAccessibilityRelation 253 class BrowserAccessibilityRelation
250 : public CComObjectRootEx<CComMultiThreadModel>, 254 : public CComObjectRootEx<CComMultiThreadModel>,
251 public IAccessibleRelation { 255 public IAccessibleRelation {
252 BEGIN_COM_MAP(BrowserAccessibilityRelation) 256 BEGIN_COM_MAP(BrowserAccessibilityRelation)
253 COM_INTERFACE_ENTRY(IAccessibleRelation) 257 COM_INTERFACE_ENTRY(IAccessibleRelation)
254 END_COM_MAP() 258 END_COM_MAP()
255 259
256 CONTENT_EXPORT BrowserAccessibilityRelation() {} 260 CONTENT_EXPORT BrowserAccessibilityRelation() {}
257 CONTENT_EXPORT virtual ~BrowserAccessibilityRelation() {} 261 CONTENT_EXPORT virtual ~BrowserAccessibilityRelation() {}
258 262
259 CONTENT_EXPORT void Initialize(BrowserAccessibilityWin* owner, 263 CONTENT_EXPORT void Initialize(BrowserAccessibilityComWin* owner,
260 const base::string16& type); 264 const base::string16& type);
261 CONTENT_EXPORT void AddTarget(int target_id); 265 CONTENT_EXPORT void AddTarget(int target_id);
262 CONTENT_EXPORT void RemoveTarget(int target_id); 266 CONTENT_EXPORT void RemoveTarget(int target_id);
263 267
264 // Accessors. 268 // Accessors.
265 const base::string16& get_type() const { return type_; } 269 const base::string16& get_type() const { return type_; }
266 const std::vector<int>& get_target_ids() const { return target_ids_; } 270 const std::vector<int>& get_target_ids() const { return target_ids_; }
267 271
268 // IAccessibleRelation methods. 272 // IAccessibleRelation methods.
269 CONTENT_EXPORT STDMETHODIMP get_relationType(BSTR* relation_type) override; 273 CONTENT_EXPORT STDMETHODIMP get_relationType(BSTR* relation_type) override;
270 CONTENT_EXPORT STDMETHODIMP get_nTargets(long* n_targets) override; 274 CONTENT_EXPORT STDMETHODIMP get_nTargets(long* n_targets) override;
271 CONTENT_EXPORT STDMETHODIMP 275 CONTENT_EXPORT STDMETHODIMP get_target(long target_index,
272 get_target(long target_index, IUnknown** target) override; 276 IUnknown** target) override;
273 CONTENT_EXPORT STDMETHODIMP 277 CONTENT_EXPORT STDMETHODIMP get_targets(long max_targets,
274 get_targets(long max_targets, IUnknown** targets, long* n_targets) override; 278 IUnknown** targets,
279 long* n_targets) override;
275 280
276 // IAccessibleRelation methods not implemented. 281 // IAccessibleRelation methods not implemented.
277 CONTENT_EXPORT STDMETHODIMP 282 CONTENT_EXPORT STDMETHODIMP
278 get_localizedRelationType(BSTR* relation_type) override { 283 get_localizedRelationType(BSTR* relation_type) override {
279 return E_NOTIMPL; 284 return E_NOTIMPL;
280 } 285 }
281 286
282 private: 287 private:
283 base::string16 type_; 288 base::string16 type_;
284 base::win::ScopedComPtr<BrowserAccessibilityWin> owner_; 289 base::win::ScopedComPtr<BrowserAccessibilityComWin> owner_;
285 std::vector<int> target_ids_; 290 std::vector<int> target_ids_;
286 }; 291 };
287 292
288 void BrowserAccessibilityRelation::Initialize(BrowserAccessibilityWin* owner, 293 void BrowserAccessibilityRelation::Initialize(BrowserAccessibilityComWin* owner,
289 const base::string16& type) { 294 const base::string16& type) {
290 owner_ = owner; 295 owner_ = owner;
291 type_ = type; 296 type_ = type;
292 } 297 }
293 298
294 void BrowserAccessibilityRelation::AddTarget(int target_id) { 299 void BrowserAccessibilityRelation::AddTarget(int target_id) {
295 target_ids_.push_back(target_id); 300 target_ids_.push_back(target_id);
296 } 301 }
297 302
298 void BrowserAccessibilityRelation::RemoveTarget(int target_id) { 303 void BrowserAccessibilityRelation::RemoveTarget(int target_id) {
299 target_ids_.erase( 304 target_ids_.erase(
300 std::remove(target_ids_.begin(), target_ids_.end(), target_id), 305 std::remove(target_ids_.begin(), target_ids_.end(), target_id),
301 target_ids_.end()); 306 target_ids_.end());
302 } 307 }
303 308
304 STDMETHODIMP BrowserAccessibilityRelation::get_relationType( 309 STDMETHODIMP BrowserAccessibilityRelation::get_relationType(
305 BSTR* relation_type) { 310 BSTR* relation_type) {
306 if (!relation_type) 311 if (!relation_type)
307 return E_INVALIDARG; 312 return E_INVALIDARG;
308 313
309 if (!owner_->instance_active()) 314 if (!owner_->GetOwner()->instance_active())
310 return E_FAIL; 315 return E_FAIL;
311 316
312 *relation_type = SysAllocString(type_.c_str()); 317 *relation_type = SysAllocString(type_.c_str());
313 DCHECK(*relation_type); 318 DCHECK(*relation_type);
314 return S_OK; 319 return S_OK;
315 } 320 }
316 321
317 STDMETHODIMP BrowserAccessibilityRelation::get_nTargets(long* n_targets) { 322 STDMETHODIMP BrowserAccessibilityRelation::get_nTargets(long* n_targets) {
318 if (!n_targets) 323 if (!n_targets)
319 return E_INVALIDARG; 324 return E_INVALIDARG;
320 325
321 if (!owner_->instance_active()) 326 if (!owner_->GetOwner()->instance_active())
322 return E_FAIL; 327 return E_FAIL;
323 328
324 *n_targets = static_cast<long>(target_ids_.size()); 329 *n_targets = static_cast<long>(target_ids_.size());
325 330
326 for (long i = *n_targets - 1; i >= 0; --i) { 331 for (long i = *n_targets - 1; i >= 0; --i) {
327 BrowserAccessibilityWin* result = owner_->GetFromID(target_ids_[i]); 332 BrowserAccessibilityComWin* result = owner_->GetFromID(target_ids_[i]);
328 if (!result || !result->instance_active()) { 333 if (!result || !result->GetOwner()->instance_active()) {
329 *n_targets = 0; 334 *n_targets = 0;
330 break; 335 break;
331 } 336 }
332 } 337 }
333 return S_OK; 338 return S_OK;
334 } 339 }
335 340
336 STDMETHODIMP BrowserAccessibilityRelation::get_target(long target_index, 341 STDMETHODIMP BrowserAccessibilityRelation::get_target(long target_index,
337 IUnknown** target) { 342 IUnknown** target) {
338 if (!target) 343 if (!target)
339 return E_INVALIDARG; 344 return E_INVALIDARG;
340 345
341 if (!owner_->instance_active()) 346 if (!owner_->GetOwner()->instance_active())
347 return E_FAIL;
348
349 auto* manager = owner_->GetOwner()->manager();
350 if (!manager)
342 return E_FAIL; 351 return E_FAIL;
343 352
344 if (target_index < 0 || 353 if (target_index < 0 ||
345 target_index >= static_cast<long>(target_ids_.size())) { 354 target_index >= static_cast<long>(target_ids_.size())) {
346 return E_INVALIDARG; 355 return E_INVALIDARG;
347 } 356 }
348 357
349 BrowserAccessibility* result = owner_->GetFromID(target_ids_[target_index]); 358 BrowserAccessibility* result = manager->GetFromID(target_ids_[target_index]);
350 if (!result || !result->instance_active()) 359 if (!result || !result->instance_active())
351 return E_FAIL; 360 return E_FAIL;
352 361
353 *target = static_cast<IAccessible*>( 362 *target = static_cast<IAccessible*>(
354 ToBrowserAccessibilityWin(result)->NewReference()); 363 ToBrowserAccessibilityComWin(result)->NewReference());
355 return S_OK; 364 return S_OK;
356 } 365 }
357 366
358 STDMETHODIMP BrowserAccessibilityRelation::get_targets(long max_targets, 367 STDMETHODIMP BrowserAccessibilityRelation::get_targets(long max_targets,
359 IUnknown** targets, 368 IUnknown** targets,
360 long* n_targets) { 369 long* n_targets) {
361 if (!targets || !n_targets) 370 if (!targets || !n_targets)
362 return E_INVALIDARG; 371 return E_INVALIDARG;
363 372
364 if (!owner_->instance_active()) 373 if (!owner_->GetOwner()->instance_active())
365 return E_FAIL; 374 return E_FAIL;
366 375
367 long count = static_cast<long>(target_ids_.size()); 376 long count = static_cast<long>(target_ids_.size());
368 if (count > max_targets) 377 if (count > max_targets)
369 count = max_targets; 378 count = max_targets;
370 379
371 *n_targets = count; 380 *n_targets = count;
372 if (count == 0) 381 if (count == 0)
373 return S_FALSE; 382 return S_FALSE;
374 383
375 for (long i = 0; i < count; ++i) { 384 for (long i = 0; i < count; ++i) {
376 HRESULT result = get_target(i, &targets[i]); 385 HRESULT result = get_target(i, &targets[i]);
377 if (result != S_OK) 386 if (result != S_OK)
378 return result; 387 return result;
379 } 388 }
380 389
381 return S_OK; 390 return S_OK;
382 } 391 }
383 392
384 // 393 //
385 // BrowserAccessibilityWin::WinAttributes 394 // BrowserAccessibilityComWin::WinAttributes
386 // 395 //
387 396
388 BrowserAccessibilityWin::WinAttributes::WinAttributes() 397 BrowserAccessibilityComWin::WinAttributes::WinAttributes()
389 : ia_role(0), 398 : ia_role(0), ia_state(0), ia2_role(0), ia2_state(0) {}
390 ia_state(0),
391 ia2_role(0),
392 ia2_state(0) {
393 }
394 399
395 BrowserAccessibilityWin::WinAttributes::~WinAttributes() { 400 BrowserAccessibilityComWin::WinAttributes::~WinAttributes() {}
396 }
397 401
398 // 402 //
399 // BrowserAccessibilityWin 403 // BrowserAccessibilityComWin
400 // 404 //
405 BrowserAccessibilityComWin::BrowserAccessibilityComWin()
406 : owner_(nullptr),
407 win_attributes_(new WinAttributes()),
408 previous_scroll_x_(0),
409 previous_scroll_y_(0) {}
401 410
402 // static 411 BrowserAccessibilityComWin::~BrowserAccessibilityComWin() {
403 BrowserAccessibility* BrowserAccessibility::Create() {
404 ui::win::CreateATLModuleIfNeeded();
405 CComObject<BrowserAccessibilityWin>* instance;
406 HRESULT hr = CComObject<BrowserAccessibilityWin>::CreateInstance(&instance);
407 DCHECK(SUCCEEDED(hr));
408 return instance->NewReference();
409 }
410
411 BrowserAccessibilityWin::BrowserAccessibilityWin()
412 : win_attributes_(new WinAttributes()),
413 previous_scroll_x_(0),
414 previous_scroll_y_(0) {
415 }
416
417 BrowserAccessibilityWin::~BrowserAccessibilityWin() {
418 for (BrowserAccessibilityRelation* relation : relations_) 412 for (BrowserAccessibilityRelation* relation : relations_)
419 relation->Release(); 413 relation->Release();
420 } 414 }
421 415
422 // 416 //
423 // IAccessible methods. 417 // IAccessible methods.
424 // 418 //
425 // Conventions: 419 // Conventions:
426 // * Always test for instance_active() first and return E_FAIL if it's false. 420 // * Always test for GetOwner() and GetOwner()->instance_active first and
421 // return E_FAIL if either are false.
427 // * Always check for invalid arguments first, even if they're unused. 422 // * Always check for invalid arguments first, even if they're unused.
428 // * Return S_FALSE if the only output is a string argument and it's empty. 423 // * Return S_FALSE if the only output is a string argument and it's empty.
424 // * There are some methods that don't touch any state such as get_toolkitName.
425 // For these rare cases, you may not need to call GetOwner().
429 // 426 //
430 427
431 HRESULT BrowserAccessibilityWin::accDoDefaultAction(VARIANT var_id) { 428 HRESULT BrowserAccessibilityComWin::accDoDefaultAction(VARIANT var_id) {
432 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_DO_DEFAULT_ACTION); 429 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_DO_DEFAULT_ACTION);
433 if (!instance_active()) 430
431 if (!GetOwner() || !GetOwner()->instance_active())
434 return E_FAIL; 432 return E_FAIL;
435 433
436 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 434 auto* manager = GetOwner()->manager();
435 if (!manager)
436 return E_FAIL;
437
438 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id);
437 if (!target) 439 if (!target)
438 return E_INVALIDARG; 440 return E_INVALIDARG;
439 441
440 // Return an error if it's not clickable. 442 // Return an error if it's not clickable.
441 if (!target->HasIntAttribute(ui::AX_ATTR_ACTION)) 443 if (!target->GetOwner()->HasIntAttribute(ui::AX_ATTR_ACTION))
442 return DISP_E_MEMBERNOTFOUND; 444 return DISP_E_MEMBERNOTFOUND;
443 445
444 manager_->DoDefaultAction(*target); 446 manager->DoDefaultAction(*target->GetOwner());
445 return S_OK; 447 return S_OK;
446 } 448 }
447 449
448 STDMETHODIMP BrowserAccessibilityWin::accHitTest(LONG x_left, 450 STDMETHODIMP BrowserAccessibilityComWin::accHitTest(LONG x_left,
449 LONG y_top, 451 LONG y_top,
450 VARIANT* child) { 452 VARIANT* child) {
451 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_HIT_TEST); 453 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_HIT_TEST);
452 if (!instance_active()) 454
455 if (!GetOwner() || !GetOwner()->instance_active())
456 return E_FAIL;
457
458 auto* manager = GetOwner()->manager();
459 if (!manager)
453 return E_FAIL; 460 return E_FAIL;
454 461
455 if (!child) 462 if (!child)
456 return E_INVALIDARG; 463 return E_INVALIDARG;
457 464
458 gfx::Point point(x_left, y_top); 465 gfx::Point point(x_left, y_top);
459 if (!GetScreenBoundsRect().Contains(point)) { 466 if (!GetOwner()->GetScreenBoundsRect().Contains(point)) {
460 // Return S_FALSE and VT_EMPTY when outside the object's boundaries. 467 // Return S_FALSE and VT_EMPTY when outside the object's boundaries.
461 child->vt = VT_EMPTY; 468 child->vt = VT_EMPTY;
462 return S_FALSE; 469 return S_FALSE;
463 } 470 }
464 471
465 BrowserAccessibility* result = manager_->CachingAsyncHitTest(point); 472 BrowserAccessibility* result = manager->CachingAsyncHitTest(point);
466 if (result == this) { 473 if (result == GetOwner()) {
467 // Point is within this object. 474 // Point is within this object.
468 child->vt = VT_I4; 475 child->vt = VT_I4;
469 child->lVal = CHILDID_SELF; 476 child->lVal = CHILDID_SELF;
470 } else { 477 } else {
471 child->vt = VT_DISPATCH; 478 child->vt = VT_DISPATCH;
472 child->pdispVal = ToBrowserAccessibilityWin(result)->NewReference(); 479 child->pdispVal = ToBrowserAccessibilityComWin(result)->NewReference();
473 } 480 }
474 return S_OK; 481 return S_OK;
475 } 482 }
476 483
477 STDMETHODIMP BrowserAccessibilityWin::accLocation(LONG* x_left, 484 STDMETHODIMP BrowserAccessibilityComWin::accLocation(LONG* x_left,
478 LONG* y_top, 485 LONG* y_top,
479 LONG* width, 486 LONG* width,
480 LONG* height, 487 LONG* height,
481 VARIANT var_id) { 488 VARIANT var_id) {
482 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_LOCATION); 489 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_LOCATION);
483 if (!instance_active()) 490 if (!GetOwner() || !GetOwner()->instance_active())
484 return E_FAIL; 491 return E_FAIL;
485 492
486 return GetPlatformNodeWin()->accLocation(x_left, y_top, width, height, 493 return AXPlatformNodeWin::accLocation(x_left, y_top, width, height, var_id);
487 var_id);
488 } 494 }
489 495
490 STDMETHODIMP BrowserAccessibilityWin::accNavigate(LONG nav_dir, 496 STDMETHODIMP BrowserAccessibilityComWin::accNavigate(LONG nav_dir,
491 VARIANT start, 497 VARIANT start,
492 VARIANT* end) { 498 VARIANT* end) {
493 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_NAVIGATE); 499 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_NAVIGATE);
500 if (!GetOwner() || !GetOwner()->instance_active())
501 return E_FAIL;
494 502
495 // Forward all directions but NAVDIR_ to the platform node implementation. 503 // Forward all directions but NAVDIR_ to the platform node implementation.
496 if (nav_dir != NAVDIR_DOWN && nav_dir != NAVDIR_UP && 504 if (nav_dir != NAVDIR_DOWN && nav_dir != NAVDIR_UP &&
497 nav_dir != NAVDIR_LEFT && nav_dir != NAVDIR_RIGHT) { 505 nav_dir != NAVDIR_LEFT && nav_dir != NAVDIR_RIGHT) {
498 return GetPlatformNodeWin()->accNavigate(nav_dir, start, end); 506 return AXPlatformNodeWin::accNavigate(nav_dir, start, end);
499 } 507 }
500 508
501 BrowserAccessibilityWin* target = GetTargetFromChildID(start); 509 BrowserAccessibilityComWin* target = GetTargetFromChildID(start);
502 if (!target) 510 if (!target)
503 return E_INVALIDARG; 511 return E_INVALIDARG;
504 512
505 BrowserAccessibility* result = nullptr; 513 BrowserAccessibility* result = nullptr;
506 switch (nav_dir) { 514 switch (nav_dir) {
507 case NAVDIR_DOWN: 515 case NAVDIR_DOWN:
508 result = target->GetTableCell(GetTableRow() + GetTableRowSpan(), 516 result = target->GetOwner()->GetTableCell(
509 GetTableColumn()); 517 GetOwner()->GetTableRow() + GetOwner()->GetTableRowSpan(),
518 GetOwner()->GetTableColumn());
510 break; 519 break;
511 case NAVDIR_UP: 520 case NAVDIR_UP:
512 result = target->GetTableCell(GetTableRow() - 1, GetTableColumn()); 521 result = target->GetOwner()->GetTableCell(GetOwner()->GetTableRow() - 1,
522 GetOwner()->GetTableColumn());
513 break; 523 break;
514 case NAVDIR_LEFT: 524 case NAVDIR_LEFT:
515 result = target->GetTableCell(GetTableRow(), GetTableColumn() - 1); 525 result = target->GetOwner()->GetTableCell(
526 GetOwner()->GetTableRow(), GetOwner()->GetTableColumn() - 1);
516 break; 527 break;
517 case NAVDIR_RIGHT: 528 case NAVDIR_RIGHT:
518 result = target->GetTableCell(GetTableRow(), 529 result = target->GetOwner()->GetTableCell(
519 GetTableColumn() + GetTableColumnSpan()); 530 GetOwner()->GetTableRow(),
531 GetOwner()->GetTableColumn() + GetOwner()->GetTableColumnSpan());
520 break; 532 break;
521 } 533 }
522 534
523 if (!result) { 535 if (!result) {
524 end->vt = VT_EMPTY; 536 end->vt = VT_EMPTY;
525 return S_FALSE; 537 return S_FALSE;
526 } 538 }
527 539
528 end->vt = VT_DISPATCH; 540 end->vt = VT_DISPATCH;
529 end->pdispVal = ToBrowserAccessibilityWin(result)->NewReference(); 541 end->pdispVal = ToBrowserAccessibilityComWin(result)->NewReference();
530 return S_OK; 542 return S_OK;
531 } 543 }
532 544
533 STDMETHODIMP BrowserAccessibilityWin::get_accChild(VARIANT var_child, 545 STDMETHODIMP BrowserAccessibilityComWin::get_accChild(VARIANT var_child,
534 IDispatch** disp_child) { 546 IDispatch** disp_child) {
535 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD); 547 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD);
536 if (!instance_active()) 548 if (!GetOwner() || !GetOwner()->instance_active())
537 return E_FAIL; 549 return E_FAIL;
538 550
539 if (!disp_child) 551 if (!disp_child)
540 return E_INVALIDARG; 552 return E_INVALIDARG;
541 553
542 *disp_child = NULL; 554 *disp_child = NULL;
543 555
544 BrowserAccessibilityWin* target = GetTargetFromChildID(var_child); 556 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_child);
545 if (!target) 557 if (!target)
546 return E_INVALIDARG; 558 return E_INVALIDARG;
547 559
548 (*disp_child) = target->NewReference(); 560 (*disp_child) = target->NewReference();
549 return S_OK; 561 return S_OK;
550 } 562 }
551 563
552 STDMETHODIMP BrowserAccessibilityWin::get_accChildCount(LONG* child_count) { 564 STDMETHODIMP BrowserAccessibilityComWin::get_accChildCount(LONG* child_count) {
553 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD_COUNT); 565 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD_COUNT);
554 if (!instance_active()) 566 if (!GetOwner() || !GetOwner()->instance_active())
555 return E_FAIL; 567 return E_FAIL;
556 568
557 if (!child_count) 569 if (!child_count)
558 return E_INVALIDARG; 570 return E_INVALIDARG;
559 571
560 *child_count = PlatformChildCount(); 572 *child_count = GetOwner()->PlatformChildCount();
561 573
562 return S_OK; 574 return S_OK;
563 } 575 }
564 576
565 STDMETHODIMP BrowserAccessibilityWin::get_accDefaultAction(VARIANT var_id, 577 STDMETHODIMP BrowserAccessibilityComWin::get_accDefaultAction(
566 BSTR* def_action) { 578 VARIANT var_id,
579 BSTR* def_action) {
567 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DEFAULT_ACTION); 580 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DEFAULT_ACTION);
568 if (!instance_active()) 581 if (!GetOwner() || !GetOwner()->instance_active())
569 return E_FAIL; 582 return E_FAIL;
570 583
571 if (!def_action) 584 if (!def_action)
572 return E_INVALIDARG; 585 return E_INVALIDARG;
573 586
574 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 587 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id);
575 if (!target) 588 if (!target)
576 return E_INVALIDARG; 589 return E_INVALIDARG;
577 590
578 return target->get_localizedName(0, def_action); 591 return target->get_localizedName(0, def_action);
579 } 592 }
580 593
581 STDMETHODIMP BrowserAccessibilityWin::get_accDescription(VARIANT var_id, 594 STDMETHODIMP BrowserAccessibilityComWin::get_accDescription(VARIANT var_id,
582 BSTR* desc) { 595 BSTR* desc) {
583 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DESCRIPTION); 596 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DESCRIPTION);
584 if (!instance_active()) 597 if (!GetOwner() || !GetOwner()->instance_active())
585 return E_FAIL; 598 return E_FAIL;
586 599
587 if (!desc) 600 if (!desc)
588 return E_INVALIDARG; 601 return E_INVALIDARG;
589 602
590 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 603 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id);
591 if (!target) 604 if (!target)
592 return E_INVALIDARG; 605 return E_INVALIDARG;
593 606
594 base::string16 description_str = target->description(); 607 base::string16 description_str = target->description();
595 if (description_str.empty()) 608 if (description_str.empty())
596 return S_FALSE; 609 return S_FALSE;
597 610
598 *desc = SysAllocString(description_str.c_str()); 611 *desc = SysAllocString(description_str.c_str());
599 612
600 DCHECK(*desc); 613 DCHECK(*desc);
601 return S_OK; 614 return S_OK;
602 } 615 }
603 616
604 STDMETHODIMP BrowserAccessibilityWin::get_accFocus(VARIANT* focus_child) { 617 STDMETHODIMP BrowserAccessibilityComWin::get_accFocus(VARIANT* focus_child) {
605 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_FOCUS); 618 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_FOCUS);
606 if (!instance_active()) 619 if (!GetOwner() || !GetOwner()->instance_active())
620 return E_FAIL;
621
622 auto* manager = GetOwner()->manager();
623 if (!manager)
607 return E_FAIL; 624 return E_FAIL;
608 625
609 if (!focus_child) 626 if (!focus_child)
610 return E_INVALIDARG; 627 return E_INVALIDARG;
611 628
612 BrowserAccessibilityWin* focus = 629 BrowserAccessibilityWin* focus =
613 static_cast<BrowserAccessibilityWin*>(manager_->GetFocus()); 630 static_cast<BrowserAccessibilityWin*>(manager->GetFocus());
614 if (focus == this) { 631 if (focus == GetOwner()) {
615 focus_child->vt = VT_I4; 632 focus_child->vt = VT_I4;
616 focus_child->lVal = CHILDID_SELF; 633 focus_child->lVal = CHILDID_SELF;
617 } else if (focus == NULL) { 634 } else if (focus == NULL) {
618 focus_child->vt = VT_EMPTY; 635 focus_child->vt = VT_EMPTY;
619 } else { 636 } else {
620 focus_child->vt = VT_DISPATCH; 637 focus_child->vt = VT_DISPATCH;
621 focus_child->pdispVal = focus->NewReference(); 638 focus_child->pdispVal = focus->GetCOM()->NewReference();
622 } 639 }
623 640
624 return S_OK; 641 return S_OK;
625 } 642 }
626 643
627 STDMETHODIMP BrowserAccessibilityWin::get_accHelp(VARIANT var_id, BSTR* help) { 644 STDMETHODIMP BrowserAccessibilityComWin::get_accHelp(VARIANT var_id,
645 BSTR* help) {
628 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_HELP); 646 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_HELP);
629 if (!instance_active()) 647 if (!GetOwner() || !GetOwner()->instance_active())
630 return E_FAIL; 648 return E_FAIL;
631 649
632 return GetPlatformNodeWin()->get_accHelp(var_id, help); 650 return AXPlatformNodeWin::get_accHelp(var_id, help);
633 } 651 }
634 652
635 STDMETHODIMP BrowserAccessibilityWin::get_accKeyboardShortcut(VARIANT var_id, 653 STDMETHODIMP BrowserAccessibilityComWin::get_accKeyboardShortcut(
636 BSTR* acc_key) { 654 VARIANT var_id,
655 BSTR* acc_key) {
637 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_KEYBOARD_SHORTCUT); 656 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_KEYBOARD_SHORTCUT);
638 if (!instance_active()) 657 if (!GetOwner() || !GetOwner()->instance_active())
639 return E_FAIL; 658 return E_FAIL;
640 659
641 if (!acc_key) 660 if (!acc_key)
642 return E_INVALIDARG; 661 return E_INVALIDARG;
643 662
644 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 663 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id);
645 if (!target) 664 if (!target)
646 return E_INVALIDARG; 665 return E_INVALIDARG;
647 666
648 if (target->HasStringAttribute(ui::AX_ATTR_KEY_SHORTCUTS)) { 667 if (target->HasStringAttribute(ui::AX_ATTR_KEY_SHORTCUTS)) {
649 return target->GetStringAttributeAsBstr( 668 return target->GetStringAttributeAsBstr(ui::AX_ATTR_KEY_SHORTCUTS, acc_key);
650 ui::AX_ATTR_KEY_SHORTCUTS, acc_key);
651 } 669 }
652 670
653 return target->GetStringAttributeAsBstr( 671 return target->GetStringAttributeAsBstr(ui::AX_ATTR_SHORTCUT, acc_key);
654 ui::AX_ATTR_SHORTCUT, acc_key);
655 } 672 }
656 673
657 STDMETHODIMP BrowserAccessibilityWin::get_accName(VARIANT var_id, BSTR* name) { 674 STDMETHODIMP BrowserAccessibilityComWin::get_accName(VARIANT var_id,
675 BSTR* name) {
658 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_NAME); 676 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_NAME);
659 if (!instance_active()) 677 if (!GetOwner() || !GetOwner()->instance_active())
660 return E_FAIL; 678 return E_FAIL;
661 679
662 return GetPlatformNodeWin()->get_accName(var_id, name); 680 return AXPlatformNodeWin::get_accName(var_id, name);
663 } 681 }
664 682
665 STDMETHODIMP BrowserAccessibilityWin::get_accParent(IDispatch** disp_parent) { 683 STDMETHODIMP BrowserAccessibilityComWin::get_accParent(
684 IDispatch** disp_parent) {
666 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_PARENT); 685 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_PARENT);
667 if (!instance_active()) 686 if (!GetOwner() || !GetOwner()->instance_active())
668 return E_FAIL; 687 return E_FAIL;
669 688
670 if (!disp_parent) 689 if (!disp_parent)
671 return E_INVALIDARG; 690 return E_INVALIDARG;
672 691
673 IAccessible* parent_obj = ToBrowserAccessibilityWin(PlatformGetParent()); 692 IAccessible* parent_obj =
693 ToBrowserAccessibilityComWin(GetOwner()->PlatformGetParent());
674 if (parent_obj == NULL) { 694 if (parent_obj == NULL) {
675 // This happens if we're the root of the tree; 695 // This happens if we're the root of the tree;
676 // return the IAccessible for the window. 696 // return the IAccessible for the window.
677 parent_obj = 697 parent_obj = GetOwner()
678 manager_->ToBrowserAccessibilityManagerWin()->GetParentIAccessible(); 698 ->manager()
699 ->ToBrowserAccessibilityManagerWin()
700 ->GetParentIAccessible();
679 // |parent| can only be NULL if the manager was created before the parent 701 // |parent| can only be NULL if the manager was created before the parent
680 // IAccessible was known and it wasn't subsequently set before a client 702 // IAccessible was known and it wasn't subsequently set before a client
681 // requested it. This has been fixed. |parent| may also be NULL during 703 // requested it. This has been fixed. |parent| may also be NULL during
682 // destruction. Possible cases where this could occur include tabs being 704 // destruction. Possible cases where this could occur include tabs being
683 // dragged to a new window, etc. 705 // dragged to a new window, etc.
684 if (!parent_obj) { 706 if (!parent_obj) {
685 DVLOG(1) << "In Function: " << __func__ 707 DVLOG(1) << "In Function: " << __func__
686 << ". Parent IAccessible interface is NULL. Returning failure"; 708 << ". Parent IAccessible interface is NULL. Returning failure";
687 return E_FAIL; 709 return E_FAIL;
688 } 710 }
689 } 711 }
690 parent_obj->AddRef(); 712 parent_obj->AddRef();
691 *disp_parent = parent_obj; 713 *disp_parent = parent_obj;
692 return S_OK; 714 return S_OK;
693 } 715 }
694 716
695 STDMETHODIMP BrowserAccessibilityWin::get_accRole(VARIANT var_id, 717 STDMETHODIMP BrowserAccessibilityComWin::get_accRole(VARIANT var_id,
696 VARIANT* role) { 718 VARIANT* role) {
697 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_ROLE); 719 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_ROLE);
698 if (!instance_active()) 720 if (!GetOwner() || !GetOwner()->instance_active())
699 return E_FAIL; 721 return E_FAIL;
700 722
701 if (!role) 723 if (!role)
702 return E_INVALIDARG; 724 return E_INVALIDARG;
703 725
704 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 726 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id);
705 if (!target) 727 if (!target)
706 return E_INVALIDARG; 728 return E_INVALIDARG;
707 729
708 if (!target->role_name().empty()) { 730 if (!target->role_name().empty()) {
709 role->vt = VT_BSTR; 731 role->vt = VT_BSTR;
710 role->bstrVal = SysAllocString(target->role_name().c_str()); 732 role->bstrVal = SysAllocString(target->role_name().c_str());
711 } else { 733 } else {
712 role->vt = VT_I4; 734 role->vt = VT_I4;
713 role->lVal = target->ia_role(); 735 role->lVal = target->ia_role();
714 } 736 }
715 return S_OK; 737 return S_OK;
716 } 738 }
717 739
718 STDMETHODIMP BrowserAccessibilityWin::get_accState(VARIANT var_id, 740 STDMETHODIMP BrowserAccessibilityComWin::get_accState(VARIANT var_id,
719 VARIANT* state) { 741 VARIANT* state) {
720 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_STATE); 742 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_STATE);
721 if (!instance_active()) 743 if (!GetOwner() || !GetOwner()->instance_active())
744 return E_FAIL;
745
746 auto* manager = GetOwner()->manager();
747 if (!manager)
722 return E_FAIL; 748 return E_FAIL;
723 749
724 if (!state) 750 if (!state)
725 return E_INVALIDARG; 751 return E_INVALIDARG;
726 752
727 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 753 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id);
728 if (!target) 754 if (!target)
729 return E_INVALIDARG; 755 return E_INVALIDARG;
730 756
731 state->vt = VT_I4; 757 state->vt = VT_I4;
732 state->lVal = target->ia_state(); 758 state->lVal = target->ia_state();
733 if (manager_->GetFocus() == this) 759 if (manager->GetFocus() == GetOwner())
734 state->lVal |= STATE_SYSTEM_FOCUSED; 760 state->lVal |= STATE_SYSTEM_FOCUSED;
735 761
736 return S_OK; 762 return S_OK;
737 } 763 }
738 764
739 STDMETHODIMP BrowserAccessibilityWin::get_accValue(VARIANT var_id, 765 STDMETHODIMP BrowserAccessibilityComWin::get_accValue(VARIANT var_id,
740 BSTR* value) { 766 BSTR* value) {
741 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_VALUE); 767 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_VALUE);
742 if (!instance_active()) 768 if (!GetOwner() || !GetOwner()->instance_active())
743 return E_FAIL; 769 return E_FAIL;
744 770
745 if (!value) 771 if (!value)
746 return E_INVALIDARG; 772 return E_INVALIDARG;
747 773
748 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 774 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id);
749 if (!target) 775 if (!target)
750 return E_INVALIDARG; 776 return E_INVALIDARG;
751 777
752 if (target->ia_role() == ROLE_SYSTEM_PROGRESSBAR || 778 if (target->ia_role() == ROLE_SYSTEM_PROGRESSBAR ||
753 target->ia_role() == ROLE_SYSTEM_SCROLLBAR || 779 target->ia_role() == ROLE_SYSTEM_SCROLLBAR ||
754 target->ia_role() == ROLE_SYSTEM_SLIDER) { 780 target->ia_role() == ROLE_SYSTEM_SLIDER) {
755 base::string16 value_text = target->GetValueText(); 781 base::string16 value_text = target->GetValueText();
756 *value = SysAllocString(value_text.c_str()); 782 *value = SysAllocString(value_text.c_str());
757 DCHECK(*value); 783 DCHECK(*value);
758 return S_OK; 784 return S_OK;
759 } 785 }
760 786
761 // Expose color well value. 787 // Expose color well value.
762 if (target->ia2_role() == IA2_ROLE_COLOR_CHOOSER) { 788 if (target->ia2_role() == IA2_ROLE_COLOR_CHOOSER) {
763 unsigned int color = static_cast<unsigned int>( 789 unsigned int color = static_cast<unsigned int>(
764 target->GetIntAttribute(ui::AX_ATTR_COLOR_VALUE)); 790 target->GetOwner()->GetIntAttribute(ui::AX_ATTR_COLOR_VALUE));
765 unsigned int red = SkColorGetR(color); 791 unsigned int red = SkColorGetR(color);
766 unsigned int green = SkColorGetG(color); 792 unsigned int green = SkColorGetG(color);
767 unsigned int blue = SkColorGetB(color); 793 unsigned int blue = SkColorGetB(color);
768 base::string16 value_text; 794 base::string16 value_text;
769 value_text = base::UintToString16(red * 100 / 255) + L"% red " + 795 value_text = base::UintToString16(red * 100 / 255) + L"% red " +
770 base::UintToString16(green * 100 / 255) + L"% green " + 796 base::UintToString16(green * 100 / 255) + L"% green " +
771 base::UintToString16(blue * 100 / 255) + L"% blue"; 797 base::UintToString16(blue * 100 / 255) + L"% blue";
772 *value = SysAllocString(value_text.c_str()); 798 *value = SysAllocString(value_text.c_str());
773 DCHECK(*value); 799 DCHECK(*value);
774 return S_OK; 800 return S_OK;
775 } 801 }
776 802
777 *value = SysAllocString(target->value().c_str()); 803 *value = SysAllocString(target->value().c_str());
778 DCHECK(*value); 804 DCHECK(*value);
779 return S_OK; 805 return S_OK;
780 } 806 }
781 807
782 STDMETHODIMP BrowserAccessibilityWin::get_accHelpTopic(BSTR* help_file, 808 STDMETHODIMP BrowserAccessibilityComWin::get_accHelpTopic(BSTR* help_file,
783 VARIANT var_id, 809 VARIANT var_id,
784 LONG* topic_id) { 810 LONG* topic_id) {
785 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_HELP_TOPIC); 811 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_HELP_TOPIC);
786 return E_NOTIMPL; 812 return E_NOTIMPL;
787 } 813 }
788 814
789 STDMETHODIMP BrowserAccessibilityWin::get_accSelection(VARIANT* selected) { 815 STDMETHODIMP BrowserAccessibilityComWin::get_accSelection(VARIANT* selected) {
790 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_SELECTION); 816 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_SELECTION);
791 if (!instance_active()) 817 if (!GetOwner() || !GetOwner()->instance_active())
792 return E_FAIL; 818 return E_FAIL;
793 819
794 if (GetRole() != ui::AX_ROLE_LIST_BOX) 820 if (GetOwner()->GetRole() != ui::AX_ROLE_LIST_BOX)
795 return E_NOTIMPL; 821 return E_NOTIMPL;
796 822
797 unsigned long selected_count = 0; 823 unsigned long selected_count = 0;
798 for (size_t i = 0; i < InternalChildCount(); ++i) { 824 for (size_t i = 0; i < GetOwner()->InternalChildCount(); ++i) {
799 if (InternalGetChild(i)->HasState(ui::AX_STATE_SELECTED)) 825 if (GetOwner()->InternalGetChild(i)->HasState(ui::AX_STATE_SELECTED))
800 ++selected_count; 826 ++selected_count;
801 } 827 }
802 828
803 if (selected_count == 0) { 829 if (selected_count == 0) {
804 selected->vt = VT_EMPTY; 830 selected->vt = VT_EMPTY;
805 return S_OK; 831 return S_OK;
806 } 832 }
807 833
808 if (selected_count == 1) { 834 if (selected_count == 1) {
809 for (size_t i = 0; i < InternalChildCount(); ++i) { 835 for (size_t i = 0; i < GetOwner()->InternalChildCount(); ++i) {
810 if (InternalGetChild(i)->HasState(ui::AX_STATE_SELECTED)) { 836 if (GetOwner()->InternalGetChild(i)->HasState(ui::AX_STATE_SELECTED)) {
811 selected->vt = VT_DISPATCH; 837 selected->vt = VT_DISPATCH;
812 selected->pdispVal = 838 selected->pdispVal =
813 ToBrowserAccessibilityWin(InternalGetChild(i))->NewReference(); 839 ToBrowserAccessibilityComWin(GetOwner()->InternalGetChild(i))
840 ->NewReference();
814 return S_OK; 841 return S_OK;
815 } 842 }
816 } 843 }
817 } 844 }
818 845
819 // Multiple items are selected. 846 // Multiple items are selected.
820 base::win::EnumVariant* enum_variant = 847 base::win::EnumVariant* enum_variant =
821 new base::win::EnumVariant(selected_count); 848 new base::win::EnumVariant(selected_count);
822 enum_variant->AddRef(); 849 enum_variant->AddRef();
823 unsigned long index = 0; 850 unsigned long index = 0;
824 for (size_t i = 0; i < InternalChildCount(); ++i) { 851 for (size_t i = 0; i < GetOwner()->InternalChildCount(); ++i) {
825 if (InternalGetChild(i)->HasState(ui::AX_STATE_SELECTED)) { 852 if (GetOwner()->InternalGetChild(i)->HasState(ui::AX_STATE_SELECTED)) {
826 enum_variant->ItemAt(index)->vt = VT_DISPATCH; 853 enum_variant->ItemAt(index)->vt = VT_DISPATCH;
827 enum_variant->ItemAt(index)->pdispVal = 854 enum_variant->ItemAt(index)->pdispVal =
828 ToBrowserAccessibilityWin(InternalGetChild(i))->NewReference(); 855 ToBrowserAccessibilityComWin(GetOwner()->InternalGetChild(i))
856 ->NewReference();
829 ++index; 857 ++index;
830 } 858 }
831 } 859 }
832 selected->vt = VT_UNKNOWN; 860 selected->vt = VT_UNKNOWN;
833 selected->punkVal = static_cast<IUnknown*>( 861 selected->punkVal = static_cast<IUnknown*>(
834 static_cast<base::win::IUnknownImpl*>(enum_variant)); 862 static_cast<base::win::IUnknownImpl*>(enum_variant));
835 return S_OK; 863 return S_OK;
836 } 864 }
837 865
838 STDMETHODIMP BrowserAccessibilityWin::accSelect( 866 STDMETHODIMP BrowserAccessibilityComWin::accSelect(LONG flags_sel,
839 LONG flags_sel, VARIANT var_id) { 867 VARIANT var_id) {
840 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_SELECT); 868 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_SELECT);
841 if (!instance_active()) 869 if (!GetOwner() || !GetOwner()->instance_active())
870 return E_FAIL;
871
872 auto* manager = GetOwner()->manager();
873 if (!manager)
842 return E_FAIL; 874 return E_FAIL;
843 875
844 if (flags_sel & SELFLAG_TAKEFOCUS) { 876 if (flags_sel & SELFLAG_TAKEFOCUS) {
845 manager_->SetFocus(*this); 877 manager->SetFocus(*GetOwner());
846 return S_OK; 878 return S_OK;
847 } 879 }
848 880
849 return S_FALSE; 881 return S_FALSE;
850 } 882 }
851 883
852 STDMETHODIMP 884 STDMETHODIMP
853 BrowserAccessibilityWin::put_accName(VARIANT var_id, BSTR put_name) { 885 BrowserAccessibilityComWin::put_accName(VARIANT var_id, BSTR put_name) {
854 return E_NOTIMPL; 886 return E_NOTIMPL;
855 } 887 }
856 STDMETHODIMP 888 STDMETHODIMP
857 BrowserAccessibilityWin::put_accValue(VARIANT var_id, BSTR put_val) { 889 BrowserAccessibilityComWin::put_accValue(VARIANT var_id, BSTR put_val) {
858 return E_NOTIMPL; 890 return E_NOTIMPL;
859 } 891 }
860 892
861 // 893 //
862 // IAccessible2 methods. 894 // IAccessible2 methods.
863 // 895 //
864 896
865 STDMETHODIMP BrowserAccessibilityWin::role(LONG* role) { 897 STDMETHODIMP BrowserAccessibilityComWin::role(LONG* role) {
866 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ROLE); 898 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ROLE);
867 if (!instance_active()) 899 if (!GetOwner() || !GetOwner()->instance_active())
868 return E_FAIL; 900 return E_FAIL;
869 901
870 if (!role) 902 if (!role)
871 return E_INVALIDARG; 903 return E_INVALIDARG;
872 904
873 *role = ia2_role(); 905 *role = ia2_role();
874 return S_OK; 906 return S_OK;
875 } 907 }
876 908
877 STDMETHODIMP BrowserAccessibilityWin::get_attributes(BSTR* attributes) { 909 STDMETHODIMP BrowserAccessibilityComWin::get_attributes(BSTR* attributes) {
878 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IA2_GET_ATTRIBUTES); 910 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IA2_GET_ATTRIBUTES);
911 if (!GetOwner() || !GetOwner()->instance_active())
912 return E_FAIL;
879 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 913 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
880 if (!attributes) 914 if (!attributes)
881 return E_INVALIDARG; 915 return E_INVALIDARG;
882 *attributes = nullptr; 916 *attributes = nullptr;
883 917
884 if (!instance_active()) 918 if (!GetOwner() || !GetOwner()->instance_active())
885 return E_FAIL; 919 return E_FAIL;
886 920
887 base::string16 str; 921 base::string16 str;
888 for (const base::string16& attribute : ia2_attributes()) 922 for (const base::string16& attribute : ia2_attributes())
889 str += attribute + L';'; 923 str += attribute + L';';
890 924
891 if (str.empty()) 925 if (str.empty())
892 return S_FALSE; 926 return S_FALSE;
893 927
894 *attributes = SysAllocString(str.c_str()); 928 *attributes = SysAllocString(str.c_str());
895 DCHECK(*attributes); 929 DCHECK(*attributes);
896 return S_OK; 930 return S_OK;
897 } 931 }
898 932
899 STDMETHODIMP BrowserAccessibilityWin::get_states(AccessibleStates* states) { 933 STDMETHODIMP BrowserAccessibilityComWin::get_states(AccessibleStates* states) {
900 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_STATES); 934 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_STATES);
935 if (!GetOwner() || !GetOwner()->instance_active())
936 return E_FAIL;
901 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 937 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
902 if (!instance_active())
903 return E_FAIL;
904 938
905 if (!states) 939 if (!states)
906 return E_INVALIDARG; 940 return E_INVALIDARG;
907 941
908 *states = ia2_state(); 942 *states = ia2_state();
909 943
910 return S_OK; 944 return S_OK;
911 } 945 }
912 946
913 STDMETHODIMP BrowserAccessibilityWin::get_uniqueID(LONG* unique_id) { 947 STDMETHODIMP BrowserAccessibilityComWin::get_uniqueID(LONG* unique_id) {
914 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID); 948 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID);
915 if (!instance_active()) 949 if (!GetOwner() || !GetOwner()->instance_active())
916 return E_FAIL; 950 return E_FAIL;
917 951
918 if (!unique_id) 952 if (!unique_id)
919 return E_INVALIDARG; 953 return E_INVALIDARG;
920 954
921 *unique_id = -this->unique_id(); 955 *unique_id = -GetOwner()->unique_id();
922 return S_OK; 956 return S_OK;
923 } 957 }
924 958
925 STDMETHODIMP BrowserAccessibilityWin::get_windowHandle(HWND* window_handle) { 959 STDMETHODIMP BrowserAccessibilityComWin::get_windowHandle(HWND* window_handle) {
926 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_WINDOW_HANDLE); 960 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_WINDOW_HANDLE);
927 if (!instance_active()) 961 if (!GetOwner() || !GetOwner()->instance_active())
928 return E_FAIL; 962 return E_FAIL;
929 963
930 if (!window_handle) 964 if (!window_handle)
931 return E_INVALIDARG; 965 return E_INVALIDARG;
932 966
933 *window_handle = 967 *window_handle = GetOwner()
934 manager_->ToBrowserAccessibilityManagerWin()->GetParentHWND(); 968 ->manager()
969 ->ToBrowserAccessibilityManagerWin()
970 ->GetParentHWND();
935 if (!*window_handle) 971 if (!*window_handle)
936 return E_FAIL; 972 return E_FAIL;
937 973
938 return S_OK; 974 return S_OK;
939 } 975 }
940 976
941 STDMETHODIMP BrowserAccessibilityWin::get_indexInParent(LONG* index_in_parent) { 977 STDMETHODIMP BrowserAccessibilityComWin::get_indexInParent(
978 LONG* index_in_parent) {
942 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_INDEX_IN_PARENT); 979 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_INDEX_IN_PARENT);
943 if (!instance_active()) 980 if (!GetOwner() || !GetOwner()->instance_active())
944 return E_FAIL; 981 return E_FAIL;
945 982
946 if (!index_in_parent) 983 if (!index_in_parent)
947 return E_INVALIDARG; 984 return E_INVALIDARG;
948 985
949 *index_in_parent = this->GetIndexInParent(); 986 *index_in_parent = GetIndexInParent();
950 return S_OK; 987 return S_OK;
951 } 988 }
952 989
953 STDMETHODIMP BrowserAccessibilityWin::get_nRelations(LONG* n_relations) { 990 STDMETHODIMP BrowserAccessibilityComWin::get_nRelations(LONG* n_relations) {
954 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_RELATIONS); 991 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_RELATIONS);
955 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 992 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
956 if (!instance_active()) 993 if (!GetOwner() || !GetOwner()->instance_active())
957 return E_FAIL; 994 return E_FAIL;
958 995
959 if (!n_relations) 996 if (!n_relations)
960 return E_INVALIDARG; 997 return E_INVALIDARG;
961 998
962 *n_relations = relations_.size(); 999 *n_relations = relations_.size();
963 return S_OK; 1000 return S_OK;
964 } 1001 }
965 1002
966 STDMETHODIMP BrowserAccessibilityWin::get_relation( 1003 STDMETHODIMP BrowserAccessibilityComWin::get_relation(
967 LONG relation_index, 1004 LONG relation_index,
968 IAccessibleRelation** relation) { 1005 IAccessibleRelation** relation) {
969 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_RELATION); 1006 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_RELATION);
970 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1007 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
971 if (!instance_active()) 1008 if (!GetOwner() || !GetOwner()->instance_active())
972 return E_FAIL; 1009 return E_FAIL;
973 1010
974 if (relation_index < 0 || 1011 if (relation_index < 0 ||
975 relation_index >= static_cast<long>(relations_.size())) { 1012 relation_index >= static_cast<long>(relations_.size())) {
976 return E_INVALIDARG; 1013 return E_INVALIDARG;
977 } 1014 }
978 1015
979 if (!relation) 1016 if (!relation)
980 return E_INVALIDARG; 1017 return E_INVALIDARG;
981 1018
982 relations_[relation_index]->AddRef(); 1019 relations_[relation_index]->AddRef();
983 *relation = relations_[relation_index]; 1020 *relation = relations_[relation_index];
984 return S_OK; 1021 return S_OK;
985 } 1022 }
986 1023
987 STDMETHODIMP BrowserAccessibilityWin::get_relations( 1024 STDMETHODIMP BrowserAccessibilityComWin::get_relations(
988 LONG max_relations, 1025 LONG max_relations,
989 IAccessibleRelation** relations, 1026 IAccessibleRelation** relations,
990 LONG* n_relations) { 1027 LONG* n_relations) {
991 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_RELATIONS); 1028 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_RELATIONS);
992 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1029 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
993 if (!instance_active()) 1030 if (!GetOwner() || !GetOwner()->instance_active())
994 return E_FAIL; 1031 return E_FAIL;
995 1032
996 if (!relations || !n_relations) 1033 if (!relations || !n_relations)
997 return E_INVALIDARG; 1034 return E_INVALIDARG;
998 1035
999 long count = static_cast<long>(relations_.size()); 1036 long count = static_cast<long>(relations_.size());
1000 *n_relations = count; 1037 *n_relations = count;
1001 if (count == 0) 1038 if (count == 0)
1002 return S_FALSE; 1039 return S_FALSE;
1003 1040
1004 for (long i = 0; i < count; ++i) { 1041 for (long i = 0; i < count; ++i) {
1005 relations_[i]->AddRef(); 1042 relations_[i]->AddRef();
1006 relations[i] = relations_[i]; 1043 relations[i] = relations_[i];
1007 } 1044 }
1008 1045
1009 return S_OK; 1046 return S_OK;
1010 } 1047 }
1011 1048
1012 STDMETHODIMP BrowserAccessibilityWin::scrollTo(IA2ScrollType scroll_type) { 1049 STDMETHODIMP BrowserAccessibilityComWin::scrollTo(IA2ScrollType scroll_type) {
1013 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IA2_SCROLL_TO); 1050 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IA2_SCROLL_TO);
1014 if (!instance_active()) 1051 if (!GetOwner() || !GetOwner()->instance_active())
1015 return E_FAIL; 1052 return E_FAIL;
1016 1053
1017 gfx::Rect r = GetFrameBoundsRect(); 1054 auto* manager = GetOwner()->manager();
1018 switch(scroll_type) { 1055
1056 if (!manager)
1057 return E_FAIL;
1058
1059 gfx::Rect r = GetOwner()->GetFrameBoundsRect();
1060 switch (scroll_type) {
1019 case IA2_SCROLL_TYPE_TOP_LEFT: 1061 case IA2_SCROLL_TYPE_TOP_LEFT:
1020 manager_->ScrollToMakeVisible(*this, gfx::Rect(r.x(), r.y(), 0, 0)); 1062 manager->ScrollToMakeVisible(*GetOwner(), gfx::Rect(r.x(), r.y(), 0, 0));
1021 break; 1063 break;
1022 case IA2_SCROLL_TYPE_BOTTOM_RIGHT: 1064 case IA2_SCROLL_TYPE_BOTTOM_RIGHT:
1023 manager_->ScrollToMakeVisible(*this, 1065 manager->ScrollToMakeVisible(*GetOwner(),
1024 gfx::Rect(r.right(), r.bottom(), 0, 0)); 1066 gfx::Rect(r.right(), r.bottom(), 0, 0));
1025 break; 1067 break;
1026 case IA2_SCROLL_TYPE_TOP_EDGE: 1068 case IA2_SCROLL_TYPE_TOP_EDGE:
1027 manager_->ScrollToMakeVisible(*this, 1069 manager->ScrollToMakeVisible(*GetOwner(),
1028 gfx::Rect(r.x(), r.y(), r.width(), 0)); 1070 gfx::Rect(r.x(), r.y(), r.width(), 0));
1029 break; 1071 break;
1030 case IA2_SCROLL_TYPE_BOTTOM_EDGE: 1072 case IA2_SCROLL_TYPE_BOTTOM_EDGE:
1031 manager_->ScrollToMakeVisible(*this, 1073 manager->ScrollToMakeVisible(*GetOwner(),
1032 gfx::Rect(r.x(), r.bottom(), r.width(), 0)); 1074 gfx::Rect(r.x(), r.bottom(), r.width(), 0));
1033 break; 1075 break;
1034 case IA2_SCROLL_TYPE_LEFT_EDGE: 1076 case IA2_SCROLL_TYPE_LEFT_EDGE:
1035 manager_->ScrollToMakeVisible(*this, 1077 manager->ScrollToMakeVisible(*GetOwner(),
1036 gfx::Rect(r.x(), r.y(), 0, r.height())); 1078 gfx::Rect(r.x(), r.y(), 0, r.height()));
1037 break; 1079 break;
1038 case IA2_SCROLL_TYPE_RIGHT_EDGE: 1080 case IA2_SCROLL_TYPE_RIGHT_EDGE:
1039 manager_->ScrollToMakeVisible(*this, 1081 manager->ScrollToMakeVisible(*GetOwner(),
1040 gfx::Rect(r.right(), r.y(), 0, r.height())); 1082 gfx::Rect(r.right(), r.y(), 0, r.height()));
1041 break; 1083 break;
1042 case IA2_SCROLL_TYPE_ANYWHERE: 1084 case IA2_SCROLL_TYPE_ANYWHERE:
1043 default: 1085 default:
1044 manager_->ScrollToMakeVisible(*this, r); 1086 manager->ScrollToMakeVisible(*GetOwner(), r);
1045 break; 1087 break;
1046 } 1088 }
1047 1089
1048 return S_OK; 1090 return S_OK;
1049 } 1091 }
1050 1092
1051 STDMETHODIMP BrowserAccessibilityWin::scrollToPoint( 1093 STDMETHODIMP BrowserAccessibilityComWin::scrollToPoint(
1052 IA2CoordinateType coordinate_type, 1094 IA2CoordinateType coordinate_type,
1053 LONG x, 1095 LONG x,
1054 LONG y) { 1096 LONG y) {
1055 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_TO_POINT); 1097 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_TO_POINT);
1056 if (!instance_active()) 1098 if (!GetOwner() || !GetOwner()->instance_active())
1099 return E_FAIL;
1100
1101 auto* manager = GetOwner()->manager();
1102 if (!manager)
1057 return E_FAIL; 1103 return E_FAIL;
1058 1104
1059 gfx::Point scroll_to(x, y); 1105 gfx::Point scroll_to(x, y);
1060 1106
1061 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 1107 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
1062 scroll_to -= manager_->GetViewBounds().OffsetFromOrigin(); 1108 scroll_to -= manager->GetViewBounds().OffsetFromOrigin();
1063 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 1109 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
1064 if (PlatformGetParent()) 1110 if (GetOwner()->PlatformGetParent()) {
1065 scroll_to += PlatformGetParent()->GetFrameBoundsRect().OffsetFromOrigin(); 1111 scroll_to += GetOwner()
1112 ->PlatformGetParent()
1113 ->GetFrameBoundsRect()
1114 .OffsetFromOrigin();
1115 }
1066 } else { 1116 } else {
1067 return E_INVALIDARG; 1117 return E_INVALIDARG;
1068 } 1118 }
1069 1119
1070 manager_->ScrollToPoint(*this, scroll_to); 1120 manager->ScrollToPoint(*GetOwner(), scroll_to);
1071 1121
1072 return S_OK; 1122 return S_OK;
1073 } 1123 }
1074 1124
1075 STDMETHODIMP BrowserAccessibilityWin::get_groupPosition( 1125 STDMETHODIMP BrowserAccessibilityComWin::get_groupPosition(
1076 LONG* group_level, 1126 LONG* group_level,
1077 LONG* similar_items_in_group, 1127 LONG* similar_items_in_group,
1078 LONG* position_in_group) { 1128 LONG* position_in_group) {
1079 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_GROUP_POSITION); 1129 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_GROUP_POSITION);
1080 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1130 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1081 if (!instance_active()) 1131 if (!GetOwner() || !GetOwner()->instance_active())
1082 return E_FAIL; 1132 return E_FAIL;
1083 1133
1084 if (!group_level || !similar_items_in_group || !position_in_group) 1134 if (!group_level || !similar_items_in_group || !position_in_group)
1085 return E_INVALIDARG; 1135 return E_INVALIDARG;
1086 1136
1087 *group_level = GetIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL); 1137 *group_level = GetOwner()->GetIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL);
1088 *similar_items_in_group = GetIntAttribute(ui::AX_ATTR_SET_SIZE); 1138 *similar_items_in_group = GetOwner()->GetIntAttribute(ui::AX_ATTR_SET_SIZE);
1089 *position_in_group = GetIntAttribute(ui::AX_ATTR_POS_IN_SET); 1139 *position_in_group = GetOwner()->GetIntAttribute(ui::AX_ATTR_POS_IN_SET);
1090 1140
1091 if (*group_level == *similar_items_in_group == *position_in_group == 0) 1141 if (*group_level == *similar_items_in_group == *position_in_group == 0)
1092 return S_FALSE; 1142 return S_FALSE;
1093 return S_OK; 1143 return S_OK;
1094 } 1144 }
1095 1145
1096 STDMETHODIMP 1146 STDMETHODIMP
1097 BrowserAccessibilityWin::get_localizedExtendedRole( 1147 BrowserAccessibilityComWin::get_localizedExtendedRole(
1098 BSTR* localized_extended_role) { 1148 BSTR* localized_extended_role) {
1099 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_EXTENDED_ROLE); 1149 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_EXTENDED_ROLE);
1100 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1150 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1101 1151 if (!GetOwner() || !GetOwner()->instance_active())
1102 if (!instance_active())
1103 return E_FAIL; 1152 return E_FAIL;
1104 1153
1105 if (!localized_extended_role) 1154 if (!localized_extended_role)
1106 return E_INVALIDARG; 1155 return E_INVALIDARG;
1107 1156
1108 return GetStringAttributeAsBstr( 1157 return GetStringAttributeAsBstr(ui::AX_ATTR_ROLE_DESCRIPTION,
1109 ui::AX_ATTR_ROLE_DESCRIPTION, localized_extended_role); 1158 localized_extended_role);
1110 } 1159 }
1111 1160
1112 // 1161 //
1113 // IAccessible2 methods not implemented. 1162 // IAccessible2 methods not implemented.
1114 // 1163 //
1115 1164
1116 STDMETHODIMP BrowserAccessibilityWin::get_extendedRole(BSTR* extended_role) { 1165 STDMETHODIMP BrowserAccessibilityComWin::get_extendedRole(BSTR* extended_role) {
1117 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_EXTENDED_ROLE); 1166 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_EXTENDED_ROLE);
1118 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1167 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1119 return E_NOTIMPL; 1168 return E_NOTIMPL;
1120 } 1169 }
1121 STDMETHODIMP 1170 STDMETHODIMP
1122 BrowserAccessibilityWin::get_nExtendedStates(LONG* n_extended_states) { 1171 BrowserAccessibilityComWin::get_nExtendedStates(LONG* n_extended_states) {
1123 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_EXTENDED_STATES); 1172 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_EXTENDED_STATES);
1124 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1173 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1125 return E_NOTIMPL; 1174 return E_NOTIMPL;
1126 } 1175 }
1127 STDMETHODIMP 1176 STDMETHODIMP
1128 BrowserAccessibilityWin::get_extendedStates(LONG max_extended_states, 1177 BrowserAccessibilityComWin::get_extendedStates(LONG max_extended_states,
1129 BSTR** extended_states, 1178 BSTR** extended_states,
1130 LONG* n_extended_states) { 1179 LONG* n_extended_states) {
1131 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_EXTENDED_STATES); 1180 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_EXTENDED_STATES);
1132 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1181 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1133 return E_NOTIMPL; 1182 return E_NOTIMPL;
1134 } 1183 }
1135 STDMETHODIMP 1184 STDMETHODIMP
1136 BrowserAccessibilityWin::get_localizedExtendedStates( 1185 BrowserAccessibilityComWin::get_localizedExtendedStates(
1137 LONG max_localized_extended_states, 1186 LONG max_localized_extended_states,
1138 BSTR** localized_extended_states, 1187 BSTR** localized_extended_states,
1139 LONG* n_localized_extended_states) { 1188 LONG* n_localized_extended_states) {
1140 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_EXTENDED_STATES); 1189 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_EXTENDED_STATES);
1141 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1190 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1142 return E_NOTIMPL; 1191 return E_NOTIMPL;
1143 } 1192 }
1144 STDMETHODIMP BrowserAccessibilityWin::get_locale(IA2Locale* locale) { 1193 STDMETHODIMP BrowserAccessibilityComWin::get_locale(IA2Locale* locale) {
1145 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALE); 1194 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALE);
1146 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1195 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1147 return E_NOTIMPL; 1196 return E_NOTIMPL;
1148 } 1197 }
1149 1198
1150 // 1199 //
1151 // IAccessibleApplication methods. 1200 // IAccessibleApplication methods.
1152 // 1201 //
1153 1202
1154 STDMETHODIMP BrowserAccessibilityWin::get_appName(BSTR* app_name) { 1203 STDMETHODIMP BrowserAccessibilityComWin::get_appName(BSTR* app_name) {
1155 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_APP_NAME); 1204 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_APP_NAME);
1156 // No need to check |instance_active()| because this interface is 1205 // No need to check |GetOwner()| or |GetOwner->manager()| because this
1157 // global, and doesn't depend on any local state. 1206 // interface is global, and doesn't depend on any local state.
1158 1207
1159 if (!app_name) 1208 if (!app_name)
1160 return E_INVALIDARG; 1209 return E_INVALIDARG;
1161 1210
1162 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out 1211 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
1163 // the part before the "/". 1212 // the part before the "/".
1164 std::vector<std::string> product_components = base::SplitString( 1213 std::vector<std::string> product_components =
1165 GetContentClient()->GetProduct(), "/", 1214 base::SplitString(GetContentClient()->GetProduct(), "/",
1166 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1215 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1167 DCHECK_EQ(2U, product_components.size()); 1216 DCHECK_EQ(2U, product_components.size());
1168 if (product_components.size() != 2) 1217 if (product_components.size() != 2)
1169 return E_FAIL; 1218 return E_FAIL;
1170 *app_name = SysAllocString(base::UTF8ToUTF16(product_components[0]).c_str()); 1219 *app_name = SysAllocString(base::UTF8ToUTF16(product_components[0]).c_str());
1171 DCHECK(*app_name); 1220 DCHECK(*app_name);
1172 return *app_name ? S_OK : E_FAIL; 1221 return *app_name ? S_OK : E_FAIL;
1173 } 1222 }
1174 1223
1175 STDMETHODIMP BrowserAccessibilityWin::get_appVersion(BSTR* app_version) { 1224 STDMETHODIMP BrowserAccessibilityComWin::get_appVersion(BSTR* app_version) {
1176 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_APP_VERSION); 1225 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_APP_VERSION);
1177 // No need to check |instance_active()| because this interface is 1226 // No need to check |GetOwner()->manager()| because this interface is
1178 // global, and doesn't depend on any local state. 1227 // global, and doesn't depend on any local state.
1179 1228
1180 if (!app_version) 1229 if (!app_version)
1181 return E_INVALIDARG; 1230 return E_INVALIDARG;
1182 1231
1183 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out 1232 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
1184 // the part after the "/". 1233 // the part after the "/".
1185 std::vector<std::string> product_components = base::SplitString( 1234 std::vector<std::string> product_components =
1186 GetContentClient()->GetProduct(), "/", 1235 base::SplitString(GetContentClient()->GetProduct(), "/",
1187 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1236 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1188 DCHECK_EQ(2U, product_components.size()); 1237 DCHECK_EQ(2U, product_components.size());
1189 if (product_components.size() != 2) 1238 if (product_components.size() != 2)
1190 return E_FAIL; 1239 return E_FAIL;
1191 *app_version = 1240 *app_version =
1192 SysAllocString(base::UTF8ToUTF16(product_components[1]).c_str()); 1241 SysAllocString(base::UTF8ToUTF16(product_components[1]).c_str());
1193 DCHECK(*app_version); 1242 DCHECK(*app_version);
1194 return *app_version ? S_OK : E_FAIL; 1243 return *app_version ? S_OK : E_FAIL;
1195 } 1244 }
1196 1245
1197 STDMETHODIMP BrowserAccessibilityWin::get_toolkitName(BSTR* toolkit_name) { 1246 STDMETHODIMP BrowserAccessibilityComWin::get_toolkitName(BSTR* toolkit_name) {
1198 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TOOLKIT_NAME); 1247 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TOOLKIT_NAME);
1199 // No need to check |instance_active()| because this interface is
1200 // global, and doesn't depend on any local state.
1201
1202 if (!toolkit_name) 1248 if (!toolkit_name)
1203 return E_INVALIDARG; 1249 return E_INVALIDARG;
1204 1250
1205 // This is hard-coded; all products based on the Chromium engine 1251 // This is hard-coded; all products based on the Chromium engine
1206 // will have the same toolkit name, so that assistive technology can 1252 // will have the same toolkit name, so that assistive technology can
1207 // detect any Chrome-based product. 1253 // detect any Chrome-based product.
1208 *toolkit_name = SysAllocString(L"Chrome"); 1254 *toolkit_name = SysAllocString(L"Chrome");
1209 DCHECK(*toolkit_name); 1255 DCHECK(*toolkit_name);
1210 return *toolkit_name ? S_OK : E_FAIL; 1256 return *toolkit_name ? S_OK : E_FAIL;
1211 } 1257 }
1212 1258
1213 STDMETHODIMP BrowserAccessibilityWin::get_toolkitVersion( 1259 STDMETHODIMP BrowserAccessibilityComWin::get_toolkitVersion(
1214 BSTR* toolkit_version) { 1260 BSTR* toolkit_version) {
1215 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TOOLKIT_VERSION); 1261 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TOOLKIT_VERSION);
1216 // No need to check |instance_active()| because this interface is
1217 // global, and doesn't depend on any local state.
1218
1219 if (!toolkit_version) 1262 if (!toolkit_version)
1220 return E_INVALIDARG; 1263 return E_INVALIDARG;
1221 1264
1222 std::string user_agent = GetContentClient()->GetUserAgent(); 1265 std::string user_agent = GetContentClient()->GetUserAgent();
1223 *toolkit_version = SysAllocString(base::UTF8ToUTF16(user_agent).c_str()); 1266 *toolkit_version = SysAllocString(base::UTF8ToUTF16(user_agent).c_str());
1224 DCHECK(*toolkit_version); 1267 DCHECK(*toolkit_version);
1225 return *toolkit_version ? S_OK : E_FAIL; 1268 return *toolkit_version ? S_OK : E_FAIL;
1226 } 1269 }
1227 1270
1228 // 1271 //
1229 // IAccessibleImage methods. 1272 // IAccessibleImage methods.
1230 // 1273 //
1231 1274
1232 STDMETHODIMP BrowserAccessibilityWin::get_description(BSTR* desc) { 1275 STDMETHODIMP BrowserAccessibilityComWin::get_description(BSTR* desc) {
1233 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_DESCRIPTION); 1276 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_DESCRIPTION);
1234 if (!instance_active()) 1277 if (!GetOwner() || !GetOwner()->instance_active())
1235 return E_FAIL; 1278 return E_FAIL;
1236 1279
1237 if (!desc) 1280 if (!desc)
1238 return E_INVALIDARG; 1281 return E_INVALIDARG;
1239 1282
1240 if (description().empty()) 1283 if (description().empty())
1241 return S_FALSE; 1284 return S_FALSE;
1242 1285
1243 *desc = SysAllocString(description().c_str()); 1286 *desc = SysAllocString(description().c_str());
1244 1287
1245 DCHECK(*desc); 1288 DCHECK(*desc);
1246 return S_OK; 1289 return S_OK;
1247 } 1290 }
1248 1291
1249 STDMETHODIMP BrowserAccessibilityWin::get_imagePosition( 1292 STDMETHODIMP BrowserAccessibilityComWin::get_imagePosition(
1250 IA2CoordinateType coordinate_type, 1293 IA2CoordinateType coordinate_type,
1251 LONG* x, 1294 LONG* x,
1252 LONG* y) { 1295 LONG* y) {
1253 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IMAGE_POSITION); 1296 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IMAGE_POSITION);
1254 if (!instance_active()) 1297 if (!GetOwner() || !GetOwner()->instance_active())
1255 return E_FAIL; 1298 return E_FAIL;
1256 1299
1257 if (!x || !y) 1300 if (!x || !y)
1258 return E_INVALIDARG; 1301 return E_INVALIDARG;
1259 1302
1260 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 1303 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
1261 gfx::Rect bounds = GetScreenBoundsRect(); 1304 gfx::Rect bounds = GetOwner()->GetScreenBoundsRect();
1262 *x = bounds.x(); 1305 *x = bounds.x();
1263 *y = bounds.y(); 1306 *y = bounds.y();
1264 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 1307 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
1265 gfx::Rect bounds = GetPageBoundsRect(); 1308 gfx::Rect bounds = GetOwner()->GetPageBoundsRect();
1266 gfx::Rect parent_bounds = PlatformGetParent() 1309 gfx::Rect parent_bounds =
1267 ? PlatformGetParent()->GetPageBoundsRect() 1310 GetOwner()->PlatformGetParent()
1268 : gfx::Rect(); 1311 ? GetOwner()->PlatformGetParent()->GetPageBoundsRect()
1312 : gfx::Rect();
1269 *x = bounds.x() - parent_bounds.x(); 1313 *x = bounds.x() - parent_bounds.x();
1270 *y = bounds.y() - parent_bounds.y(); 1314 *y = bounds.y() - parent_bounds.y();
1271 } else { 1315 } else {
1272 return E_INVALIDARG; 1316 return E_INVALIDARG;
1273 } 1317 }
1274 1318
1275 return S_OK; 1319 return S_OK;
1276 } 1320 }
1277 1321
1278 STDMETHODIMP BrowserAccessibilityWin::get_imageSize(LONG* height, LONG* width) { 1322 STDMETHODIMP BrowserAccessibilityComWin::get_imageSize(LONG* height,
1323 LONG* width) {
1279 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IMAGE_SIZE); 1324 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IMAGE_SIZE);
1280 if (!instance_active()) 1325 if (!GetOwner() || !GetOwner()->instance_active())
1281 return E_FAIL; 1326 return E_FAIL;
1282 1327
1283 if (!height || !width) 1328 if (!height || !width)
1284 return E_INVALIDARG; 1329 return E_INVALIDARG;
1285 1330
1286 *height = GetPageBoundsRect().height(); 1331 *height = GetOwner()->GetPageBoundsRect().height();
1287 *width = GetPageBoundsRect().width(); 1332 *width = GetOwner()->GetPageBoundsRect().width();
1288 return S_OK; 1333 return S_OK;
1289 } 1334 }
1290 1335
1291 // 1336 //
1292 // IAccessibleTable methods. 1337 // IAccessibleTable methods.
1293 // 1338 //
1294 1339
1295 STDMETHODIMP BrowserAccessibilityWin::get_accessibleAt( 1340 STDMETHODIMP BrowserAccessibilityComWin::get_accessibleAt(
1296 long row, 1341 long row,
1297 long column, 1342 long column,
1298 IUnknown** accessible) { 1343 IUnknown** accessible) {
1299 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACCESSIBLE_AT); 1344 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACCESSIBLE_AT);
1300 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1345 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1301 if (!instance_active()) 1346 if (!GetOwner() || !GetOwner()->instance_active())
1302 return E_FAIL; 1347 return E_FAIL;
1303 1348
1304 if (!accessible) 1349 if (!accessible)
1305 return E_INVALIDARG; 1350 return E_INVALIDARG;
1306 1351
1307 BrowserAccessibility* cell = 1352 BrowserAccessibility* cell =
1308 GetTableCell(static_cast<int>(row), static_cast<int>(column)); 1353 GetOwner()->GetTableCell(static_cast<int>(row), static_cast<int>(column));
1309 if (cell && ToBrowserAccessibilityWin(cell)) { 1354 if (cell && ToBrowserAccessibilityComWin(cell)) {
1310 *accessible = static_cast<IAccessible*>( 1355 *accessible = static_cast<IAccessible*>(
1311 ToBrowserAccessibilityWin(cell)->NewReference()); 1356 ToBrowserAccessibilityComWin(cell)->NewReference());
1312 return S_OK; 1357 return S_OK;
1313 } 1358 }
1314 1359
1315 *accessible = nullptr; 1360 *accessible = nullptr;
1316 return E_INVALIDARG; 1361 return E_INVALIDARG;
1317 } 1362 }
1318 1363
1319 STDMETHODIMP BrowserAccessibilityWin::get_caption(IUnknown** accessible) { 1364 STDMETHODIMP BrowserAccessibilityComWin::get_caption(IUnknown** accessible) {
1320 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CAPTION); 1365 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CAPTION);
1321 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1366 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1322 if (!instance_active()) 1367 if (!GetOwner() || !GetOwner()->instance_active())
1323 return E_FAIL; 1368 return E_FAIL;
1324 1369
1325 if (!accessible) 1370 if (!accessible)
1326 return E_INVALIDARG; 1371 return E_INVALIDARG;
1327 1372
1328 // TODO(dmazzoni): implement 1373 // TODO(dmazzoni): implement
1329 *accessible = nullptr; 1374 *accessible = nullptr;
1330 return S_FALSE; 1375 return S_FALSE;
1331 } 1376 }
1332 1377
1333 STDMETHODIMP BrowserAccessibilityWin::get_childIndex(long row, 1378 STDMETHODIMP BrowserAccessibilityComWin::get_childIndex(long row,
1334 long column, 1379 long column,
1335 long* cell_index) { 1380 long* cell_index) {
1336 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CHILD_INDEX); 1381 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CHILD_INDEX);
1337 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1382 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1338 if (!instance_active()) 1383 if (!GetOwner() || !GetOwner()->instance_active())
1339 return E_FAIL; 1384 return E_FAIL;
1340 1385
1341 if (!cell_index) 1386 if (!cell_index)
1342 return E_INVALIDARG; 1387 return E_INVALIDARG;
1343 1388
1344 BrowserAccessibility* cell = 1389 BrowserAccessibility* cell =
1345 GetTableCell(static_cast<int>(row), static_cast<int>(column)); 1390 GetOwner()->GetTableCell(static_cast<int>(row), static_cast<int>(column));
1346 if (cell) { 1391 if (cell) {
1347 *cell_index = static_cast<LONG>(cell->GetTableCellIndex()); 1392 *cell_index = static_cast<LONG>(cell->GetTableCellIndex());
1348 return S_OK; 1393 return S_OK;
1349 } 1394 }
1350 1395
1351 *cell_index = 0; 1396 *cell_index = 0;
1352 return E_INVALIDARG; 1397 return E_INVALIDARG;
1353 } 1398 }
1354 1399
1355 STDMETHODIMP BrowserAccessibilityWin::get_columnDescription(long column, 1400 STDMETHODIMP BrowserAccessibilityComWin::get_columnDescription(
1356 BSTR* description) { 1401 long column,
1402 BSTR* description) {
1357 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_DESCRIPTION); 1403 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_DESCRIPTION);
1358 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1404 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1359 if (!instance_active()) 1405 if (!GetOwner() || !GetOwner()->instance_active())
1360 return E_FAIL; 1406 return E_FAIL;
1361 1407
1362 if (!description) 1408 if (!description)
1363 return E_INVALIDARG; 1409 return E_INVALIDARG;
1364 1410
1365 int columns = GetTableColumnCount(); 1411 int columns = GetOwner()->GetTableColumnCount();
1366 if (column < 0 || column >= columns) 1412 if (column < 0 || column >= columns)
1367 return E_INVALIDARG; 1413 return E_INVALIDARG;
1368 1414
1369 int rows = GetTableRowCount(); 1415 int rows = GetOwner()->GetTableRowCount();
1370 if (rows <= 0) { 1416 if (rows <= 0) {
1371 *description = nullptr; 1417 *description = nullptr;
1372 return S_FALSE; 1418 return S_FALSE;
1373 } 1419 }
1374 1420
1375 for (int i = 0; i < rows; ++i) { 1421 for (int i = 0; i < rows; ++i) {
1376 const BrowserAccessibility* cell = GetTableCell(i, column); 1422 BrowserAccessibility* cell = GetOwner()->GetTableCell(i, column);
1377 if (ToBrowserAccessibilityWin(cell) && 1423 if (ToBrowserAccessibilityComWin(cell) &&
1378 cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER) { 1424 cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER) {
1379 base::string16 cell_name = cell->GetString16Attribute( 1425 base::string16 cell_name = cell->GetString16Attribute(ui::AX_ATTR_NAME);
1380 ui::AX_ATTR_NAME);
1381 if (cell_name.size() > 0) { 1426 if (cell_name.size() > 0) {
1382 *description = SysAllocString(cell_name.c_str()); 1427 *description = SysAllocString(cell_name.c_str());
1383 return S_OK; 1428 return S_OK;
1384 } 1429 }
1385 1430
1386 if (ToBrowserAccessibilityWin(cell)->description().size() > 0) { 1431 if (ToBrowserAccessibilityComWin(cell)->description().size() > 0) {
1387 *description = SysAllocString( 1432 *description = SysAllocString(
1388 ToBrowserAccessibilityWin(cell)->description().c_str()); 1433 ToBrowserAccessibilityComWin(cell)->description().c_str());
1389 return S_OK; 1434 return S_OK;
1390 } 1435 }
1391 } 1436 }
1392 } 1437 }
1393 1438
1394 *description = nullptr; 1439 *description = nullptr;
1395 return S_FALSE; 1440 return S_FALSE;
1396 } 1441 }
1397 1442
1398 STDMETHODIMP BrowserAccessibilityWin::get_columnExtentAt( 1443 STDMETHODIMP BrowserAccessibilityComWin::get_columnExtentAt(
1399 long row, 1444 long row,
1400 long column, 1445 long column,
1401 long* n_columns_spanned) { 1446 long* n_columns_spanned) {
1402 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_EXTENT_AT); 1447 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_EXTENT_AT);
1403 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1448 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1404 if (!instance_active()) 1449 if (!GetOwner() || !GetOwner()->instance_active())
1405 return E_FAIL; 1450 return E_FAIL;
1406 1451
1407 if (!n_columns_spanned) 1452 if (!n_columns_spanned)
1408 return E_INVALIDARG; 1453 return E_INVALIDARG;
1409 1454
1410 BrowserAccessibility* cell = 1455 BrowserAccessibility* cell =
1411 GetTableCell(static_cast<int>(row), static_cast<int>(column)); 1456 GetOwner()->GetTableCell(static_cast<int>(row), static_cast<int>(column));
1412 if (!cell) 1457 if (!cell)
1413 return E_INVALIDARG; 1458 return E_INVALIDARG;
1414 1459
1415 *n_columns_spanned = cell->GetTableColumnSpan(); 1460 *n_columns_spanned = cell->GetTableColumnSpan();
1416 return S_OK; 1461 return S_OK;
1417 } 1462 }
1418 1463
1419 STDMETHODIMP BrowserAccessibilityWin::get_columnHeader( 1464 STDMETHODIMP BrowserAccessibilityComWin::get_columnHeader(
1420 IAccessibleTable** accessible_table, 1465 IAccessibleTable** accessible_table,
1421 long* starting_row_index) { 1466 long* starting_row_index) {
1422 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_HEADER); 1467 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_HEADER);
1423 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1468 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1424 // TODO(dmazzoni): implement 1469 // TODO(dmazzoni): implement
1425 return E_NOTIMPL; 1470 return E_NOTIMPL;
1426 } 1471 }
1427 1472
1428 STDMETHODIMP BrowserAccessibilityWin::get_columnIndex(long cell_index, 1473 STDMETHODIMP BrowserAccessibilityComWin::get_columnIndex(long cell_index,
1429 long* column_index) { 1474 long* column_index) {
1430 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_INDEX); 1475 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_INDEX);
1431 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1476 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1432 if (!instance_active()) 1477 if (!GetOwner() || !GetOwner()->instance_active())
1433 return E_FAIL; 1478 return E_FAIL;
1434 1479
1435 if (!column_index) 1480 if (!column_index)
1436 return E_INVALIDARG; 1481 return E_INVALIDARG;
1437 1482
1438 BrowserAccessibility* cell = GetTableCell(cell_index); 1483 BrowserAccessibility* cell = GetOwner()->GetTableCell(cell_index);
1439 if (!cell) 1484 if (!cell)
1440 return E_INVALIDARG; 1485 return E_INVALIDARG;
1441 *column_index = cell->GetTableColumn(); 1486 *column_index = cell->GetTableColumn();
1442 return S_OK; 1487 return S_OK;
1443 } 1488 }
1444 1489
1445 STDMETHODIMP BrowserAccessibilityWin::get_nColumns(long* column_count) { 1490 STDMETHODIMP BrowserAccessibilityComWin::get_nColumns(long* column_count) {
1446 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_COLUMNS); 1491 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_COLUMNS);
1447 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1492 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1448 if (!instance_active()) 1493 if (!GetOwner() || !GetOwner()->instance_active())
1449 return E_FAIL; 1494 return E_FAIL;
1450 1495
1451 if (!column_count) 1496 if (!column_count)
1452 return E_INVALIDARG; 1497 return E_INVALIDARG;
1453 1498
1454 *column_count = GetTableColumnCount(); 1499 *column_count = GetOwner()->GetTableColumnCount();
1455 return S_OK; 1500 return S_OK;
1456 } 1501 }
1457 1502
1458 STDMETHODIMP BrowserAccessibilityWin::get_nRows(long* row_count) { 1503 STDMETHODIMP BrowserAccessibilityComWin::get_nRows(long* row_count) {
1459 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_ROWS); 1504 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_ROWS);
1460 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1505 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1461 if (!instance_active()) 1506 if (!GetOwner() || !GetOwner()->instance_active())
1462 return E_FAIL; 1507 return E_FAIL;
1463 1508
1464 if (!row_count) 1509 if (!row_count)
1465 return E_INVALIDARG; 1510 return E_INVALIDARG;
1466 1511
1467 *row_count = GetTableRowCount(); 1512 *row_count = GetOwner()->GetTableRowCount();
1468 return S_OK; 1513 return S_OK;
1469 } 1514 }
1470 1515
1471 STDMETHODIMP BrowserAccessibilityWin::get_nSelectedChildren(long* cell_count) { 1516 STDMETHODIMP BrowserAccessibilityComWin::get_nSelectedChildren(
1517 long* cell_count) {
1472 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_CHILDREN); 1518 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_CHILDREN);
1473 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1519 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1474 if (!instance_active()) 1520 if (!GetOwner() || !GetOwner()->instance_active())
1475 return E_FAIL; 1521 return E_FAIL;
1476 1522
1477 if (!cell_count) 1523 if (!cell_count)
1478 return E_INVALIDARG; 1524 return E_INVALIDARG;
1479 1525
1480 // TODO(dmazzoni): add support for selected cells/rows/columns in tables. 1526 // TODO(dmazzoni): add support for selected cells/rows/columns in tables.
1481 *cell_count = 0; 1527 *cell_count = 0;
1482 return S_FALSE; 1528 return S_FALSE;
1483 } 1529 }
1484 1530
1485 STDMETHODIMP BrowserAccessibilityWin::get_nSelectedColumns(long* column_count) { 1531 STDMETHODIMP BrowserAccessibilityComWin::get_nSelectedColumns(
1532 long* column_count) {
1486 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_COLUMNS); 1533 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_COLUMNS);
1487 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1534 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1488 if (!instance_active()) 1535 if (!GetOwner() || !GetOwner()->instance_active())
1489 return E_FAIL; 1536 return E_FAIL;
1490 1537
1491 if (!column_count) 1538 if (!column_count)
1492 return E_INVALIDARG; 1539 return E_INVALIDARG;
1493 1540
1494 *column_count = 0; 1541 *column_count = 0;
1495 return S_FALSE; 1542 return S_FALSE;
1496 } 1543 }
1497 1544
1498 STDMETHODIMP BrowserAccessibilityWin::get_nSelectedRows(long* row_count) { 1545 STDMETHODIMP BrowserAccessibilityComWin::get_nSelectedRows(long* row_count) {
1499 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_ROWS); 1546 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_ROWS);
1500 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1547 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1501 if (!instance_active()) 1548 if (!GetOwner() || !GetOwner()->instance_active())
1502 return E_FAIL; 1549 return E_FAIL;
1503 1550
1504 if (!row_count) 1551 if (!row_count)
1505 return E_INVALIDARG; 1552 return E_INVALIDARG;
1506 1553
1507 *row_count = 0; 1554 *row_count = 0;
1508 return S_FALSE; 1555 return S_FALSE;
1509 } 1556 }
1510 1557
1511 STDMETHODIMP BrowserAccessibilityWin::get_rowDescription(long row, 1558 STDMETHODIMP BrowserAccessibilityComWin::get_rowDescription(long row,
1512 BSTR* description) { 1559 BSTR* description) {
1513 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_DESCRIPTION); 1560 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_DESCRIPTION);
1514 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1561 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1515 if (!instance_active()) 1562 if (!GetOwner() || !GetOwner()->instance_active())
1516 return E_FAIL; 1563 return E_FAIL;
1517 1564
1518 if (!description) 1565 if (!description)
1519 return E_INVALIDARG; 1566 return E_INVALIDARG;
1520 1567
1521 if (row < 0 || row >= GetTableRowCount()) 1568 if (row < 0 || row >= GetOwner()->GetTableRowCount())
1522 return E_INVALIDARG; 1569 return E_INVALIDARG;
1523 1570
1524 int columns = GetTableColumnCount(); 1571 int columns = GetOwner()->GetTableColumnCount();
1525 if (columns <= 0) { 1572 if (columns <= 0) {
1526 *description = nullptr; 1573 *description = nullptr;
1527 return S_FALSE; 1574 return S_FALSE;
1528 } 1575 }
1529 1576
1530 for (int i = 0; i < columns; ++i) { 1577 for (int i = 0; i < columns; ++i) {
1531 const BrowserAccessibility* cell = GetTableCell(row, i); 1578 BrowserAccessibility* cell = GetOwner()->GetTableCell(row, i);
1532 if (ToBrowserAccessibilityWin(cell) && 1579 if (ToBrowserAccessibilityComWin(cell) &&
1533 cell->GetRole() == ui::AX_ROLE_ROW_HEADER) { 1580 cell->GetRole() == ui::AX_ROLE_ROW_HEADER) {
1534 base::string16 cell_name = cell->GetString16Attribute( 1581 base::string16 cell_name = cell->GetString16Attribute(ui::AX_ATTR_NAME);
1535 ui::AX_ATTR_NAME);
1536 if (cell_name.size() > 0) { 1582 if (cell_name.size() > 0) {
1537 *description = SysAllocString(cell_name.c_str()); 1583 *description = SysAllocString(cell_name.c_str());
1538 return S_OK; 1584 return S_OK;
1539 } 1585 }
1540 1586
1541 if (ToBrowserAccessibilityWin(cell)->description().size() > 0) { 1587 if (ToBrowserAccessibilityComWin(cell)->description().size() > 0) {
1542 *description = SysAllocString( 1588 *description = SysAllocString(
1543 ToBrowserAccessibilityWin(cell)->description().c_str()); 1589 ToBrowserAccessibilityComWin(cell)->description().c_str());
1544 return S_OK; 1590 return S_OK;
1545 } 1591 }
1546 } 1592 }
1547 } 1593 }
1548 1594
1549 *description = nullptr; 1595 *description = nullptr;
1550 return S_FALSE; 1596 return S_FALSE;
1551 } 1597 }
1552 1598
1553 STDMETHODIMP BrowserAccessibilityWin::get_rowExtentAt(long row, 1599 STDMETHODIMP BrowserAccessibilityComWin::get_rowExtentAt(long row,
1554 long column, 1600 long column,
1555 long* n_rows_spanned) { 1601 long* n_rows_spanned) {
1556 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_EXTENT_AT); 1602 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_EXTENT_AT);
1557 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1603 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1558 if (!instance_active()) 1604 if (!GetOwner() || !GetOwner()->instance_active())
1559 return E_FAIL; 1605 return E_FAIL;
1560 1606
1561 if (!n_rows_spanned) 1607 if (!n_rows_spanned)
1562 return E_INVALIDARG; 1608 return E_INVALIDARG;
1563 1609
1564 BrowserAccessibility* cell = GetTableCell(row, column); 1610 BrowserAccessibility* cell = GetOwner()->GetTableCell(row, column);
1565 if (!cell) 1611 if (!cell)
1566 return E_INVALIDARG; 1612 return E_INVALIDARG;
1567 1613
1568 *n_rows_spanned = GetTableRowSpan(); 1614 *n_rows_spanned = GetOwner()->GetTableRowSpan();
1569 return S_OK; 1615 return S_OK;
1570 } 1616 }
1571 1617
1572 STDMETHODIMP BrowserAccessibilityWin::get_rowHeader( 1618 STDMETHODIMP BrowserAccessibilityComWin::get_rowHeader(
1573 IAccessibleTable** accessible_table, 1619 IAccessibleTable** accessible_table,
1574 long* starting_column_index) { 1620 long* starting_column_index) {
1575 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_HEADER); 1621 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_HEADER);
1576 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1622 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1577 // TODO(dmazzoni): implement 1623 // TODO(dmazzoni): implement
1578 return E_NOTIMPL; 1624 return E_NOTIMPL;
1579 } 1625 }
1580 1626
1581 STDMETHODIMP BrowserAccessibilityWin::get_rowIndex(long cell_index, 1627 STDMETHODIMP BrowserAccessibilityComWin::get_rowIndex(long cell_index,
1582 long* row_index) { 1628 long* row_index) {
1583 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_INDEX); 1629 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_INDEX);
1584 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1630 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1585 if (!instance_active()) 1631 if (!GetOwner() || !GetOwner()->instance_active())
1586 return E_FAIL; 1632 return E_FAIL;
1587 1633
1588 if (!row_index) 1634 if (!row_index)
1589 return E_INVALIDARG; 1635 return E_INVALIDARG;
1590 1636
1591 BrowserAccessibility* cell = GetTableCell(cell_index); 1637 BrowserAccessibility* cell = GetOwner()->GetTableCell(cell_index);
1592 if (!cell) 1638 if (!cell)
1593 return E_INVALIDARG; 1639 return E_INVALIDARG;
1594 1640
1595 *row_index = cell->GetTableRow(); 1641 *row_index = cell->GetTableRow();
1596 return S_OK; 1642 return S_OK;
1597 } 1643 }
1598 1644
1599 STDMETHODIMP BrowserAccessibilityWin::get_selectedChildren(long max_children, 1645 STDMETHODIMP BrowserAccessibilityComWin::get_selectedChildren(
1600 long** children, 1646 long max_children,
1601 long* n_children) { 1647 long** children,
1648 long* n_children) {
1602 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_CHILDREN); 1649 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_CHILDREN);
1603 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1650 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1604 if (!instance_active()) 1651 if (!GetOwner() || !GetOwner()->instance_active())
1605 return E_FAIL; 1652 return E_FAIL;
1606 1653
1607 if (!children || !n_children) 1654 if (!children || !n_children)
1608 return E_INVALIDARG; 1655 return E_INVALIDARG;
1609 1656
1610 // TODO(dmazzoni): Implement this. 1657 // TODO(dmazzoni): Implement this.
1611 *n_children = 0; 1658 *n_children = 0;
1612 return S_FALSE; 1659 return S_FALSE;
1613 } 1660 }
1614 1661
1615 STDMETHODIMP BrowserAccessibilityWin::get_selectedColumns(long max_columns, 1662 STDMETHODIMP BrowserAccessibilityComWin::get_selectedColumns(long max_columns,
1616 long** columns, 1663 long** columns,
1617 long* n_columns) { 1664 long* n_columns) {
1618 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_COLUMNS); 1665 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_COLUMNS);
1619 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1666 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1620 if (!instance_active()) 1667 if (!GetOwner() || !GetOwner()->instance_active())
1621 return E_FAIL; 1668 return E_FAIL;
1622 1669
1623 if (!columns || !n_columns) 1670 if (!columns || !n_columns)
1624 return E_INVALIDARG; 1671 return E_INVALIDARG;
1625 1672
1626 // TODO(dmazzoni): Implement this. 1673 // TODO(dmazzoni): Implement this.
1627 *n_columns = 0; 1674 *n_columns = 0;
1628 return S_FALSE; 1675 return S_FALSE;
1629 } 1676 }
1630 1677
1631 STDMETHODIMP BrowserAccessibilityWin::get_selectedRows(long max_rows, 1678 STDMETHODIMP BrowserAccessibilityComWin::get_selectedRows(long max_rows,
1632 long** rows, 1679 long** rows,
1633 long* n_rows) { 1680 long* n_rows) {
1634 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_ROWS); 1681 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_ROWS);
1635 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1682 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1636 if (!instance_active()) 1683 if (!GetOwner() || !GetOwner()->instance_active())
1637 return E_FAIL; 1684 return E_FAIL;
1638 1685
1639 if (!rows || !n_rows) 1686 if (!rows || !n_rows)
1640 return E_INVALIDARG; 1687 return E_INVALIDARG;
1641 1688
1642 // TODO(dmazzoni): Implement this. 1689 // TODO(dmazzoni): Implement this.
1643 *n_rows = 0; 1690 *n_rows = 0;
1644 return S_FALSE; 1691 return S_FALSE;
1645 } 1692 }
1646 1693
1647 STDMETHODIMP BrowserAccessibilityWin::get_summary(IUnknown** accessible) { 1694 STDMETHODIMP BrowserAccessibilityComWin::get_summary(IUnknown** accessible) {
1648 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SUMMARY); 1695 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SUMMARY);
1649 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1696 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1650 if (!instance_active()) 1697 if (!GetOwner() || !GetOwner()->instance_active())
1651 return E_FAIL; 1698 return E_FAIL;
1652 1699
1653 if (!accessible) 1700 if (!accessible)
1654 return E_INVALIDARG; 1701 return E_INVALIDARG;
1655 1702
1656 // TODO(dmazzoni): implement 1703 // TODO(dmazzoni): implement
1657 *accessible = nullptr; 1704 *accessible = nullptr;
1658 return S_FALSE; 1705 return S_FALSE;
1659 } 1706 }
1660 1707
1661 STDMETHODIMP BrowserAccessibilityWin::get_isColumnSelected( 1708 STDMETHODIMP BrowserAccessibilityComWin::get_isColumnSelected(
1662 long column, 1709 long column,
1663 boolean* is_selected) { 1710 boolean* is_selected) {
1664 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IS_COLUMN_SELECTED); 1711 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IS_COLUMN_SELECTED);
1665 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1712 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1666 if (!instance_active()) 1713 if (!GetOwner() || !GetOwner()->instance_active())
1667 return E_FAIL; 1714 return E_FAIL;
1668 1715
1669 if (!is_selected) 1716 if (!is_selected)
1670 return E_INVALIDARG; 1717 return E_INVALIDARG;
1671 1718
1672 // TODO(dmazzoni): Implement this. 1719 // TODO(dmazzoni): Implement this.
1673 *is_selected = false; 1720 *is_selected = false;
1674 return S_OK; 1721 return S_OK;
1675 } 1722 }
1676 1723
1677 STDMETHODIMP BrowserAccessibilityWin::get_isRowSelected(long row, 1724 STDMETHODIMP BrowserAccessibilityComWin::get_isRowSelected(
1678 boolean* is_selected) { 1725 long row,
1726 boolean* is_selected) {
1679 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IS_ROW_SELECTED); 1727 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IS_ROW_SELECTED);
1680 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1728 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1681 if (!instance_active()) 1729 if (!GetOwner() || !GetOwner()->instance_active())
1682 return E_FAIL; 1730 return E_FAIL;
1683 1731
1684 if (!is_selected) 1732 if (!is_selected)
1685 return E_INVALIDARG; 1733 return E_INVALIDARG;
1686 1734
1687 // TODO(dmazzoni): Implement this. 1735 // TODO(dmazzoni): Implement this.
1688 *is_selected = false; 1736 *is_selected = false;
1689 return S_OK; 1737 return S_OK;
1690 } 1738 }
1691 1739
1692 STDMETHODIMP BrowserAccessibilityWin::get_isSelected(long row, 1740 STDMETHODIMP BrowserAccessibilityComWin::get_isSelected(long row,
1693 long column, 1741 long column,
1694 boolean* is_selected) { 1742 boolean* is_selected) {
1695 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IS_SELECTED); 1743 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IS_SELECTED);
1696 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1744 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1697 if (!instance_active()) 1745 if (!GetOwner() || !GetOwner()->instance_active())
1698 return E_FAIL; 1746 return E_FAIL;
1699 1747
1700 if (!is_selected) 1748 if (!is_selected)
1701 return E_INVALIDARG; 1749 return E_INVALIDARG;
1702 1750
1703 // TODO(dmazzoni): Implement this. 1751 // TODO(dmazzoni): Implement this.
1704 *is_selected = false; 1752 *is_selected = false;
1705 return S_OK; 1753 return S_OK;
1706 } 1754 }
1707 1755
1708 STDMETHODIMP BrowserAccessibilityWin::get_rowColumnExtentsAtIndex( 1756 STDMETHODIMP BrowserAccessibilityComWin::get_rowColumnExtentsAtIndex(
1709 long index, 1757 long index,
1710 long* row, 1758 long* row,
1711 long* column, 1759 long* column,
1712 long* row_extents, 1760 long* row_extents,
1713 long* column_extents, 1761 long* column_extents,
1714 boolean* is_selected) { 1762 boolean* is_selected) {
1715 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_COLUMN_EXTENTS_AT_INDEX); 1763 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_COLUMN_EXTENTS_AT_INDEX);
1716 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1764 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1717 if (!instance_active()) 1765 if (!GetOwner() || !GetOwner()->instance_active())
1718 return E_FAIL; 1766 return E_FAIL;
1719 1767
1720 if (!row || !column || !row_extents || !column_extents || !is_selected) 1768 if (!row || !column || !row_extents || !column_extents || !is_selected)
1721 return E_INVALIDARG; 1769 return E_INVALIDARG;
1722 1770
1723 BrowserAccessibility* cell = GetTableCell(index); 1771 BrowserAccessibility* cell = GetOwner()->GetTableCell(index);
1724 if (!cell) 1772 if (!cell)
1725 return E_INVALIDARG; 1773 return E_INVALIDARG;
1726 1774
1727 *row = cell->GetTableRow(); 1775 *row = cell->GetTableRow();
1728 *column = cell->GetTableColumn(); 1776 *column = cell->GetTableColumn();
1729 *row_extents = GetTableRowSpan(); 1777 *row_extents = GetOwner()->GetTableRowSpan();
1730 *column_extents = GetTableColumnSpan(); 1778 *column_extents = GetOwner()->GetTableColumnSpan();
1731 *is_selected = false; // Not supported. 1779 *is_selected = false; // Not supported.
1732 1780
1733 return S_OK; 1781 return S_OK;
1734 } 1782 }
1735 1783
1736 STDMETHODIMP BrowserAccessibilityWin::selectRow(long row) { 1784 STDMETHODIMP BrowserAccessibilityComWin::selectRow(long row) {
1737 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SELECT_ROW); 1785 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SELECT_ROW);
1738 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1786 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1739 return E_NOTIMPL; 1787 return E_NOTIMPL;
1740 } 1788 }
1741 1789
1742 STDMETHODIMP BrowserAccessibilityWin::selectColumn(long column) { 1790 STDMETHODIMP BrowserAccessibilityComWin::selectColumn(long column) {
1743 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SELECT_COLUMN); 1791 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SELECT_COLUMN);
1744 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1792 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1745 return E_NOTIMPL; 1793 return E_NOTIMPL;
1746 } 1794 }
1747 1795
1748 STDMETHODIMP BrowserAccessibilityWin::unselectRow(long row) { 1796 STDMETHODIMP BrowserAccessibilityComWin::unselectRow(long row) {
1749 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_UNSELECT_ROW); 1797 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_UNSELECT_ROW);
1750 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1798 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1751 return E_NOTIMPL; 1799 return E_NOTIMPL;
1752 } 1800 }
1753 1801
1754 STDMETHODIMP BrowserAccessibilityWin::unselectColumn(long column) { 1802 STDMETHODIMP BrowserAccessibilityComWin::unselectColumn(long column) {
1755 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_UNSELECT_COLUMN); 1803 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_UNSELECT_COLUMN);
1756 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1804 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1757 return E_NOTIMPL; 1805 return E_NOTIMPL;
1758 } 1806 }
1759 1807
1760 STDMETHODIMP 1808 STDMETHODIMP
1761 BrowserAccessibilityWin::get_modelChange(IA2TableModelChange* model_change) { 1809 BrowserAccessibilityComWin::get_modelChange(IA2TableModelChange* model_change) {
1762 return E_NOTIMPL; 1810 return E_NOTIMPL;
1763 } 1811 }
1764 1812
1765 // 1813 //
1766 // IAccessibleTable2 methods. 1814 // IAccessibleTable2 methods.
1767 // 1815 //
1768 1816
1769 STDMETHODIMP BrowserAccessibilityWin::get_cellAt(long row, 1817 STDMETHODIMP BrowserAccessibilityComWin::get_cellAt(long row,
1770 long column, 1818 long column,
1771 IUnknown** cell) { 1819 IUnknown** cell) {
1772 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CELL_AT); 1820 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CELL_AT);
1773 AddAccessibilityModeFlags(AccessibilityMode::kScreenReader); 1821 AddAccessibilityModeFlags(AccessibilityMode::kScreenReader);
1774 if (!instance_active()) 1822 if (!GetOwner() || !GetOwner()->instance_active())
1775 return E_FAIL; 1823 return E_FAIL;
1776 1824
1777 if (!cell) 1825 if (!cell)
1778 return E_INVALIDARG; 1826 return E_INVALIDARG;
1779 1827
1780 BrowserAccessibility* table_cell = 1828 BrowserAccessibility* table_cell =
1781 GetTableCell(static_cast<int>(row), static_cast<int>(column)); 1829 GetOwner()->GetTableCell(static_cast<int>(row), static_cast<int>(column));
1782 if (ToBrowserAccessibilityWin(table_cell)) { 1830 if (ToBrowserAccessibilityComWin(table_cell)) {
1783 return ToBrowserAccessibilityWin(table_cell) 1831 return ToBrowserAccessibilityComWin(table_cell)
1784 ->QueryInterface(IID_IUnknown, reinterpret_cast<void**>(cell)); 1832 ->QueryInterface(IID_IUnknown, reinterpret_cast<void**>(cell));
1785 } 1833 }
1786 1834
1787 *cell = nullptr; 1835 *cell = nullptr;
1788 return E_INVALIDARG; 1836 return E_INVALIDARG;
1789 } 1837 }
1790 1838
1791 STDMETHODIMP BrowserAccessibilityWin::get_nSelectedCells(long* cell_count) { 1839 STDMETHODIMP BrowserAccessibilityComWin::get_nSelectedCells(long* cell_count) {
1792 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_CELLS); 1840 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTED_CELLS);
1793 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1841 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1794 return get_nSelectedChildren(cell_count); 1842 return get_nSelectedChildren(cell_count);
1795 } 1843 }
1796 1844
1797 STDMETHODIMP BrowserAccessibilityWin::get_selectedCells( 1845 STDMETHODIMP BrowserAccessibilityComWin::get_selectedCells(
1798 IUnknown*** cells, 1846 IUnknown*** cells,
1799 long* n_selected_cells) { 1847 long* n_selected_cells) {
1800 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_CELLS); 1848 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTED_CELLS);
1801 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1849 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1802 if (!instance_active()) 1850 if (!GetOwner() || !GetOwner()->instance_active())
1803 return E_FAIL; 1851 return E_FAIL;
1804 1852
1805 if (!cells || !n_selected_cells) 1853 if (!cells || !n_selected_cells)
1806 return E_INVALIDARG; 1854 return E_INVALIDARG;
1807 1855
1808 // TODO(dmazzoni): Implement this. 1856 // TODO(dmazzoni): Implement this.
1809 *n_selected_cells = 0; 1857 *n_selected_cells = 0;
1810 return S_OK; 1858 return S_OK;
1811 } 1859 }
1812 1860
1813 STDMETHODIMP BrowserAccessibilityWin::get_selectedColumns(long** columns, 1861 STDMETHODIMP BrowserAccessibilityComWin::get_selectedColumns(long** columns,
1814 long* n_columns) { 1862 long* n_columns) {
1815 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLE2_GET_SELECTED_COLUMNS); 1863 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLE2_GET_SELECTED_COLUMNS);
1816 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1864 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1817 if (!instance_active()) 1865 if (!GetOwner() || !GetOwner()->instance_active())
1818 return E_FAIL; 1866 return E_FAIL;
1819 1867
1820 if (!columns || !n_columns) 1868 if (!columns || !n_columns)
1821 return E_INVALIDARG; 1869 return E_INVALIDARG;
1822 1870
1823 // TODO(dmazzoni): Implement this. 1871 // TODO(dmazzoni): Implement this.
1824 *n_columns = 0; 1872 *n_columns = 0;
1825 return S_OK; 1873 return S_OK;
1826 } 1874 }
1827 1875
1828 STDMETHODIMP BrowserAccessibilityWin::get_selectedRows(long** rows, 1876 STDMETHODIMP BrowserAccessibilityComWin::get_selectedRows(long** rows,
1829 long* n_rows) { 1877 long* n_rows) {
1830 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLE2_GET_SELECTED_ROWS); 1878 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLE2_GET_SELECTED_ROWS);
1831 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1879 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1832 if (!instance_active()) 1880 if (!GetOwner() || !GetOwner()->instance_active())
1833 return E_FAIL; 1881 return E_FAIL;
1834 1882
1835 if (!rows || !n_rows) 1883 if (!rows || !n_rows)
1836 return E_INVALIDARG; 1884 return E_INVALIDARG;
1837 1885
1838 // TODO(dmazzoni): Implement this. 1886 // TODO(dmazzoni): Implement this.
1839 *n_rows = 0; 1887 *n_rows = 0;
1840 return S_OK; 1888 return S_OK;
1841 } 1889 }
1842 1890
1843
1844 // 1891 //
1845 // IAccessibleTableCell methods. 1892 // IAccessibleTableCell methods.
1846 // 1893 //
1847 1894
1848 STDMETHODIMP BrowserAccessibilityWin::get_columnExtent( 1895 STDMETHODIMP BrowserAccessibilityComWin::get_columnExtent(
1849 long* n_columns_spanned) { 1896 long* n_columns_spanned) {
1850 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_EXTENT); 1897 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_EXTENT);
1851 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1898 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1852 if (!instance_active()) 1899 if (!GetOwner() || !GetOwner()->instance_active())
1853 return E_FAIL; 1900 return E_FAIL;
1854 1901
1855 if (!n_columns_spanned) 1902 if (!n_columns_spanned)
1856 return E_INVALIDARG; 1903 return E_INVALIDARG;
1857 1904
1858 *n_columns_spanned = GetTableColumnSpan(); 1905 *n_columns_spanned = GetOwner()->GetTableColumnSpan();
1859 return S_OK; 1906 return S_OK;
1860 } 1907 }
1861 1908
1862 STDMETHODIMP BrowserAccessibilityWin::get_columnHeaderCells( 1909 STDMETHODIMP BrowserAccessibilityComWin::get_columnHeaderCells(
1863 IUnknown*** cell_accessibles, 1910 IUnknown*** cell_accessibles,
1864 long* n_column_header_cells) { 1911 long* n_column_header_cells) {
1865 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_HEADER_CELLS); 1912 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COLUMN_HEADER_CELLS);
1866 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1913 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1867 if (!instance_active()) 1914 if (!GetOwner() || !GetOwner()->instance_active())
1868 return E_FAIL; 1915 return E_FAIL;
1869 1916
1870 if (!cell_accessibles || !n_column_header_cells) 1917 if (!cell_accessibles || !n_column_header_cells)
1871 return E_INVALIDARG; 1918 return E_INVALIDARG;
1872 1919
1873 *n_column_header_cells = 0; 1920 *n_column_header_cells = 0;
1874 BrowserAccessibility* table = GetTable(); 1921 BrowserAccessibility* table = GetOwner()->GetTable();
1875 if (!table) { 1922 if (!table) {
1876 NOTREACHED(); 1923 NOTREACHED();
1877 return S_FALSE; 1924 return S_FALSE;
1878 } 1925 }
1879 1926
1880 int column = GetTableColumn(); 1927 int column = GetOwner()->GetTableColumn();
1881 int columns = GetTableColumnCount(); 1928 int columns = GetOwner()->GetTableColumnCount();
1882 int rows = GetTableRowCount(); 1929 int rows = GetOwner()->GetTableRowCount();
1883 if (columns <= 0 || rows <= 0 || column < 0 || column >= columns) 1930 if (columns <= 0 || rows <= 0 || column < 0 || column >= columns)
1884 return S_FALSE; 1931 return S_FALSE;
1885 1932
1886 for (int i = 0; i < rows; ++i) { 1933 for (int i = 0; i < rows; ++i) {
1887 BrowserAccessibility* cell = GetTableCell(i, column); 1934 BrowserAccessibility* cell = GetOwner()->GetTableCell(i, column);
1888 if (cell && cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER) 1935 if (cell && cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER)
1889 (*n_column_header_cells)++; 1936 (*n_column_header_cells)++;
1890 } 1937 }
1891 1938
1892 *cell_accessibles = static_cast<IUnknown**>(CoTaskMemAlloc( 1939 *cell_accessibles = static_cast<IUnknown**>(
1893 (*n_column_header_cells) * sizeof(cell_accessibles[0]))); 1940 CoTaskMemAlloc((*n_column_header_cells) * sizeof(cell_accessibles[0])));
1894 int index = 0; 1941 int index = 0;
1895 for (int i = 0; i < rows; ++i) { 1942 for (int i = 0; i < rows; ++i) {
1896 BrowserAccessibility* cell = GetTableCell(i, column); 1943 BrowserAccessibility* cell = GetOwner()->GetTableCell(i, column);
1897 if (cell && cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER) { 1944 if (cell && cell->GetRole() == ui::AX_ROLE_COLUMN_HEADER) {
1898 (*cell_accessibles)[index] = static_cast<IAccessible*>( 1945 (*cell_accessibles)[index] = static_cast<IAccessible*>(
1899 ToBrowserAccessibilityWin(cell)->NewReference()); 1946 ToBrowserAccessibilityComWin(cell)->NewReference());
1900 ++index; 1947 ++index;
1901 } 1948 }
1902 } 1949 }
1903 1950
1904 return S_OK; 1951 return S_OK;
1905 } 1952 }
1906 1953
1907 STDMETHODIMP BrowserAccessibilityWin::get_columnIndex(long* column_index) { 1954 STDMETHODIMP BrowserAccessibilityComWin::get_columnIndex(long* column_index) {
1908 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLECELL_GET_COLUMN_INDEX); 1955 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLECELL_GET_COLUMN_INDEX);
1909 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1956 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1910 if (!instance_active()) 1957 if (!GetOwner() || !GetOwner()->instance_active())
1911 return E_FAIL; 1958 return E_FAIL;
1912 1959
1913 if (!column_index) 1960 if (!column_index)
1914 return E_INVALIDARG; 1961 return E_INVALIDARG;
1915 1962
1916 *column_index = GetTableColumn(); 1963 *column_index = GetOwner()->GetTableColumn();
1917 return S_OK; 1964 return S_OK;
1918 } 1965 }
1919 1966
1920 STDMETHODIMP BrowserAccessibilityWin::get_rowExtent(long* n_rows_spanned) { 1967 STDMETHODIMP BrowserAccessibilityComWin::get_rowExtent(long* n_rows_spanned) {
1921 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_EXTENT); 1968 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_EXTENT);
1922 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1969 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1923 if (!instance_active()) 1970 if (!GetOwner() || !GetOwner()->instance_active())
1924 return E_FAIL; 1971 return E_FAIL;
1925 1972
1926 if (!n_rows_spanned) 1973 if (!n_rows_spanned)
1927 return E_INVALIDARG; 1974 return E_INVALIDARG;
1928 1975
1929 *n_rows_spanned = GetTableRowSpan(); 1976 *n_rows_spanned = GetOwner()->GetTableRowSpan();
1930 return S_OK; 1977 return S_OK;
1931 } 1978 }
1932 1979
1933 STDMETHODIMP BrowserAccessibilityWin::get_rowHeaderCells( 1980 STDMETHODIMP BrowserAccessibilityComWin::get_rowHeaderCells(
1934 IUnknown*** cell_accessibles, 1981 IUnknown*** cell_accessibles,
1935 long* n_row_header_cells) { 1982 long* n_row_header_cells) {
1936 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_HEADER_CELLS); 1983 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_HEADER_CELLS);
1937 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1984 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1938 if (!instance_active()) 1985 if (!GetOwner() || !GetOwner()->instance_active())
1939 return E_FAIL; 1986 return E_FAIL;
1940 1987
1941 if (!cell_accessibles || !n_row_header_cells) 1988 if (!cell_accessibles || !n_row_header_cells)
1942 return E_INVALIDARG; 1989 return E_INVALIDARG;
1943 1990
1944 *n_row_header_cells = 0; 1991 *n_row_header_cells = 0;
1945 BrowserAccessibility* table = GetTable(); 1992 BrowserAccessibility* table = GetOwner()->GetTable();
1946 if (!table) { 1993 if (!table) {
1947 NOTREACHED(); 1994 NOTREACHED();
1948 return S_FALSE; 1995 return S_FALSE;
1949 } 1996 }
1950 1997
1951 int row = GetTableRow(); 1998 int row = GetOwner()->GetTableRow();
1952 int columns = GetTableColumnCount(); 1999 int columns = GetOwner()->GetTableColumnCount();
1953 int rows = GetTableRowCount(); 2000 int rows = GetOwner()->GetTableRowCount();
1954 if (columns <= 0 || rows <= 0 || row < 0 || row >= rows) 2001 if (columns <= 0 || rows <= 0 || row < 0 || row >= rows)
1955 return S_FALSE; 2002 return S_FALSE;
1956 2003
1957 for (int i = 0; i < columns; ++i) { 2004 for (int i = 0; i < columns; ++i) {
1958 BrowserAccessibility* cell = GetTableCell(row, i); 2005 BrowserAccessibility* cell = GetOwner()->GetTableCell(row, i);
1959 if (cell && cell->GetRole() == ui::AX_ROLE_ROW_HEADER) 2006 if (cell && cell->GetRole() == ui::AX_ROLE_ROW_HEADER)
1960 (*n_row_header_cells)++; 2007 (*n_row_header_cells)++;
1961 } 2008 }
1962 2009
1963 *cell_accessibles = static_cast<IUnknown**>(CoTaskMemAlloc( 2010 *cell_accessibles = static_cast<IUnknown**>(
1964 (*n_row_header_cells) * sizeof(cell_accessibles[0]))); 2011 CoTaskMemAlloc((*n_row_header_cells) * sizeof(cell_accessibles[0])));
1965 int index = 0; 2012 int index = 0;
1966 for (int i = 0; i < columns; ++i) { 2013 for (int i = 0; i < columns; ++i) {
1967 BrowserAccessibility* cell = GetTableCell(row, i); 2014 BrowserAccessibility* cell = GetOwner()->GetTableCell(row, i);
1968 if (cell && cell->GetRole() == ui::AX_ROLE_ROW_HEADER) { 2015 if (cell && cell->GetRole() == ui::AX_ROLE_ROW_HEADER) {
1969 (*cell_accessibles)[index] = static_cast<IAccessible*>( 2016 (*cell_accessibles)[index] = static_cast<IAccessible*>(
1970 ToBrowserAccessibilityWin(cell)->NewReference()); 2017 ToBrowserAccessibilityComWin(cell)->NewReference());
1971 ++index; 2018 ++index;
1972 } 2019 }
1973 } 2020 }
1974 2021
1975 return S_OK; 2022 return S_OK;
1976 } 2023 }
1977 2024
1978 STDMETHODIMP BrowserAccessibilityWin::get_rowIndex(long* row_index) { 2025 STDMETHODIMP BrowserAccessibilityComWin::get_rowIndex(long* row_index) {
1979 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLECELL_GET_ROW_INDEX); 2026 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLECELL_GET_ROW_INDEX);
1980 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2027 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1981 if (!instance_active()) 2028 if (!GetOwner() || !GetOwner()->instance_active())
1982 return E_FAIL; 2029 return E_FAIL;
1983 2030
1984 if (!row_index) 2031 if (!row_index)
1985 return E_INVALIDARG; 2032 return E_INVALIDARG;
1986 2033
1987 *row_index = GetTableRow(); 2034 *row_index = GetOwner()->GetTableRow();
1988 return S_OK; 2035 return S_OK;
1989 } 2036 }
1990 2037
1991 STDMETHODIMP BrowserAccessibilityWin::get_isSelected(boolean* is_selected) { 2038 STDMETHODIMP BrowserAccessibilityComWin::get_isSelected(boolean* is_selected) {
1992 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLECELL_GET_IS_SELECTED); 2039 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TABLECELL_GET_IS_SELECTED);
1993 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2040 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1994 if (!instance_active()) 2041 if (!GetOwner() || !GetOwner()->instance_active())
1995 return E_FAIL; 2042 return E_FAIL;
1996 2043
1997 if (!is_selected) 2044 if (!is_selected)
1998 return E_INVALIDARG; 2045 return E_INVALIDARG;
1999 2046
2000 *is_selected = false; 2047 *is_selected = false;
2001 return S_OK; 2048 return S_OK;
2002 } 2049 }
2003 2050
2004 STDMETHODIMP BrowserAccessibilityWin::get_rowColumnExtents( 2051 STDMETHODIMP BrowserAccessibilityComWin::get_rowColumnExtents(
2005 long* row_index, 2052 long* row_index,
2006 long* column_index, 2053 long* column_index,
2007 long* row_extents, 2054 long* row_extents,
2008 long* column_extents, 2055 long* column_extents,
2009 boolean* is_selected) { 2056 boolean* is_selected) {
2010 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_COLUMN_EXTENTS); 2057 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ROW_COLUMN_EXTENTS);
2011 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2058 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2012 if (!instance_active()) 2059 if (!GetOwner() || !GetOwner()->instance_active())
2013 return E_FAIL; 2060 return E_FAIL;
2014 2061
2015 if (!row_index || 2062 if (!row_index || !column_index || !row_extents || !column_extents ||
2016 !column_index ||
2017 !row_extents ||
2018 !column_extents ||
2019 !is_selected) { 2063 !is_selected) {
2020 return E_INVALIDARG; 2064 return E_INVALIDARG;
2021 } 2065 }
2022 2066
2023 *row_index = GetTableRow(); 2067 *row_index = GetOwner()->GetTableRow();
2024 *column_index = GetTableColumn(); 2068 *column_index = GetOwner()->GetTableColumn();
2025 *row_extents = GetTableRowSpan(); 2069 *row_extents = GetOwner()->GetTableRowSpan();
2026 *column_extents = GetTableColumnSpan(); 2070 *column_extents = GetOwner()->GetTableColumnSpan();
2027 *is_selected = false; // Not supported. 2071 *is_selected = false; // Not supported.
2028 2072
2029 return S_OK; 2073 return S_OK;
2030 } 2074 }
2031 2075
2032 STDMETHODIMP BrowserAccessibilityWin::get_table(IUnknown** table) { 2076 STDMETHODIMP BrowserAccessibilityComWin::get_table(IUnknown** table) {
2033 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TABLE); 2077 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TABLE);
2034 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2078 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2035 if (!instance_active()) 2079 if (!GetOwner() || !GetOwner()->instance_active())
2036 return E_FAIL; 2080 return E_FAIL;
2037 2081
2038 if (!table) 2082 if (!table)
2039 return E_INVALIDARG; 2083 return E_INVALIDARG;
2040 2084
2041 BrowserAccessibility* find_table = GetTable(); 2085 BrowserAccessibility* find_table = GetOwner()->GetTable();
2042 if (!find_table || !ToBrowserAccessibilityWin(find_table)) { 2086 if (!find_table || !ToBrowserAccessibilityComWin(find_table)) {
2043 *table = nullptr; 2087 *table = nullptr;
2044 return S_FALSE; 2088 return S_FALSE;
2045 } 2089 }
2046 2090
2047 *table = static_cast<IAccessibleTable*>( 2091 *table = static_cast<IAccessibleTable*>(
2048 ToBrowserAccessibilityWin(find_table)->NewReference()); 2092 ToBrowserAccessibilityComWin(find_table)->NewReference());
2049 return S_OK; 2093 return S_OK;
2050 } 2094 }
2051 2095
2052 // 2096 //
2053 // IAccessibleText methods. 2097 // IAccessibleText methods.
2054 // 2098 //
2055 2099
2056 STDMETHODIMP BrowserAccessibilityWin::get_nCharacters(LONG* n_characters) { 2100 STDMETHODIMP BrowserAccessibilityComWin::get_nCharacters(LONG* n_characters) {
2057 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_CHARACTERS); 2101 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_CHARACTERS);
2058 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2102 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2059 AccessibilityMode::kInlineTextBoxes); 2103 AccessibilityMode::kInlineTextBoxes);
2060 if (!instance_active()) 2104 if (!GetOwner() || !GetOwner()->instance_active())
2061 return E_FAIL; 2105 return E_FAIL;
2062 2106
2063 if (!n_characters) 2107 if (!n_characters)
2064 return E_INVALIDARG; 2108 return E_INVALIDARG;
2065 2109
2066 *n_characters = static_cast<LONG>(GetText().size()); 2110 *n_characters = static_cast<LONG>(GetOwner()->GetText().size());
2067 return S_OK; 2111 return S_OK;
2068 } 2112 }
2069 2113
2070 STDMETHODIMP BrowserAccessibilityWin::get_caretOffset(LONG* offset) { 2114 STDMETHODIMP BrowserAccessibilityComWin::get_caretOffset(LONG* offset) {
2071 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CARET_OFFSET); 2115 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CARET_OFFSET);
2072 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2116 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2073 if (!instance_active()) 2117 if (!GetOwner() || !GetOwner()->instance_active())
2074 return E_FAIL; 2118 return E_FAIL;
2075 2119
2076 if (!offset) 2120 if (!offset)
2077 return E_INVALIDARG; 2121 return E_INVALIDARG;
2078 2122
2079 if (!HasCaret()) 2123 if (!GetOwner()->HasCaret())
2080 return S_FALSE; 2124 return S_FALSE;
2081 2125
2082 int selection_start, selection_end; 2126 int selection_start, selection_end;
2083 GetSelectionOffsets(&selection_start, &selection_end); 2127 GetSelectionOffsets(&selection_start, &selection_end);
2084 // The caret is always at the end of the selection. 2128 // The caret is always at the end of the selection.
2085 *offset = selection_end; 2129 *offset = selection_end;
2086 if (*offset < 0) 2130 if (*offset < 0)
2087 return S_FALSE; 2131 return S_FALSE;
2088 2132
2089 return S_OK; 2133 return S_OK;
2090 } 2134 }
2091 2135
2092 STDMETHODIMP BrowserAccessibilityWin::get_characterExtents( 2136 STDMETHODIMP BrowserAccessibilityComWin::get_characterExtents(
2093 LONG offset, 2137 LONG offset,
2094 IA2CoordinateType coordinate_type, 2138 IA2CoordinateType coordinate_type,
2095 LONG* out_x, 2139 LONG* out_x,
2096 LONG* out_y, 2140 LONG* out_y,
2097 LONG* out_width, 2141 LONG* out_width,
2098 LONG* out_height) { 2142 LONG* out_height) {
2099 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CHARACTER_EXTENTS); 2143 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CHARACTER_EXTENTS);
2100 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2144 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2101 AccessibilityMode::kInlineTextBoxes); 2145 AccessibilityMode::kInlineTextBoxes);
2102 if (!instance_active()) 2146 if (!GetOwner() || !GetOwner()->instance_active())
2103 return E_FAIL; 2147 return E_FAIL;
2104 2148
2105 if (!out_x || !out_y || !out_width || !out_height) 2149 if (!out_x || !out_y || !out_width || !out_height)
2106 return E_INVALIDARG; 2150 return E_INVALIDARG;
2107 2151
2108 const base::string16& text_str = GetText(); 2152 const base::string16& text_str = GetOwner()->GetText();
2109 HandleSpecialTextOffset(&offset); 2153 HandleSpecialTextOffset(&offset);
2110 if (offset < 0 || offset > static_cast<LONG>(text_str.size())) 2154 if (offset < 0 || offset > static_cast<LONG>(text_str.size()))
2111 return E_INVALIDARG; 2155 return E_INVALIDARG;
2112 2156
2113 gfx::Rect character_bounds; 2157 gfx::Rect character_bounds;
2114 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 2158 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
2115 character_bounds = GetScreenBoundsForRange(offset, 1); 2159 character_bounds = GetOwner()->GetScreenBoundsForRange(offset, 1);
2116 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 2160 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
2117 character_bounds = GetPageBoundsForRange(offset, 1); 2161 character_bounds = GetOwner()->GetPageBoundsForRange(offset, 1);
2118 if (PlatformGetParent()) 2162 if (GetOwner()->PlatformGetParent()) {
2119 character_bounds -= 2163 character_bounds -= GetOwner()
2120 PlatformGetParent()->GetPageBoundsRect().OffsetFromOrigin(); 2164 ->PlatformGetParent()
2165 ->GetPageBoundsRect()
2166 .OffsetFromOrigin();
2167 }
2121 } else { 2168 } else {
2122 return E_INVALIDARG; 2169 return E_INVALIDARG;
2123 } 2170 }
2124 2171
2125 *out_x = character_bounds.x(); 2172 *out_x = character_bounds.x();
2126 *out_y = character_bounds.y(); 2173 *out_y = character_bounds.y();
2127 *out_width = character_bounds.width(); 2174 *out_width = character_bounds.width();
2128 *out_height = character_bounds.height(); 2175 *out_height = character_bounds.height();
2129 2176
2130 return S_OK; 2177 return S_OK;
2131 } 2178 }
2132 2179
2133 STDMETHODIMP BrowserAccessibilityWin::get_nSelections(LONG* n_selections) { 2180 STDMETHODIMP BrowserAccessibilityComWin::get_nSelections(LONG* n_selections) {
2134 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTIONS); 2181 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_SELECTIONS);
2135 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2182 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2136 if (!instance_active()) 2183 if (!GetOwner() || !GetOwner()->instance_active())
2137 return E_FAIL; 2184 return E_FAIL;
2138 2185
2139 if (!n_selections) 2186 if (!n_selections)
2140 return E_INVALIDARG; 2187 return E_INVALIDARG;
2141 2188
2142 *n_selections = 0; 2189 *n_selections = 0;
2143 int selection_start, selection_end; 2190 int selection_start, selection_end;
2144 GetSelectionOffsets(&selection_start, &selection_end); 2191 GetSelectionOffsets(&selection_start, &selection_end);
2145 if (selection_start >= 0 && selection_end >= 0 && 2192 if (selection_start >= 0 && selection_end >= 0 &&
2146 selection_start != selection_end) { 2193 selection_start != selection_end) {
2147 *n_selections = 1; 2194 *n_selections = 1;
2148 } 2195 }
2149 2196
2150 return S_OK; 2197 return S_OK;
2151 } 2198 }
2152 2199
2153 STDMETHODIMP BrowserAccessibilityWin::get_selection(LONG selection_index, 2200 STDMETHODIMP BrowserAccessibilityComWin::get_selection(LONG selection_index,
2154 LONG* start_offset, 2201 LONG* start_offset,
2155 LONG* end_offset) { 2202 LONG* end_offset) {
2156 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTION); 2203 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_SELECTION);
2157 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2204 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2158 if (!instance_active()) 2205 if (!GetOwner() || !GetOwner()->instance_active())
2159 return E_FAIL; 2206 return E_FAIL;
2160 2207
2161 if (!start_offset || !end_offset || selection_index != 0) 2208 if (!start_offset || !end_offset || selection_index != 0)
2162 return E_INVALIDARG; 2209 return E_INVALIDARG;
2163 2210
2164 *start_offset = 0; 2211 *start_offset = 0;
2165 *end_offset = 0; 2212 *end_offset = 0;
2166 int selection_start, selection_end; 2213 int selection_start, selection_end;
2167 GetSelectionOffsets(&selection_start, &selection_end); 2214 GetSelectionOffsets(&selection_start, &selection_end);
2168 if (selection_start >= 0 && selection_end >= 0 && 2215 if (selection_start >= 0 && selection_end >= 0 &&
2169 selection_start != selection_end) { 2216 selection_start != selection_end) {
2170 // We should ignore the direction of the selection when exposing start and 2217 // We should ignore the direction of the selection when exposing start and
2171 // end offsets. According to the IA2 Spec the end offset is always increased 2218 // end offsets. According to the IA2 Spec the end offset is always increased
2172 // by one past the end of the selection. This wouldn't make sense if 2219 // by one past the end of the selection. This wouldn't make sense if
2173 // end < start. 2220 // end < start.
2174 if (selection_end < selection_start) 2221 if (selection_end < selection_start)
2175 std::swap(selection_start, selection_end); 2222 std::swap(selection_start, selection_end);
2176 2223
2177 *start_offset = selection_start; 2224 *start_offset = selection_start;
2178 *end_offset = selection_end; 2225 *end_offset = selection_end;
2179 return S_OK; 2226 return S_OK;
2180 } 2227 }
2181 2228
2182 return E_INVALIDARG; 2229 return E_INVALIDARG;
2183 } 2230 }
2184 2231
2185 STDMETHODIMP BrowserAccessibilityWin::get_text(LONG start_offset, 2232 STDMETHODIMP BrowserAccessibilityComWin::get_text(LONG start_offset,
2186 LONG end_offset, 2233 LONG end_offset,
2187 BSTR* text) { 2234 BSTR* text) {
2188 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT); 2235 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT);
2189 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2236 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2190 if (!instance_active()) 2237 if (!GetOwner() || !GetOwner()->instance_active())
2191 return E_FAIL; 2238 return E_FAIL;
2192 2239
2193 if (!text) 2240 if (!text)
2194 return E_INVALIDARG; 2241 return E_INVALIDARG;
2195 2242
2196 const base::string16& text_str = GetText(); 2243 const base::string16& text_str = GetOwner()->GetText();
2197 HandleSpecialTextOffset(&start_offset); 2244 HandleSpecialTextOffset(&start_offset);
2198 HandleSpecialTextOffset(&end_offset); 2245 HandleSpecialTextOffset(&end_offset);
2199 2246
2200 // The spec allows the arguments to be reversed. 2247 // The spec allows the arguments to be reversed.
2201 if (start_offset > end_offset) { 2248 if (start_offset > end_offset) {
2202 LONG tmp = start_offset; 2249 LONG tmp = start_offset;
2203 start_offset = end_offset; 2250 start_offset = end_offset;
2204 end_offset = tmp; 2251 end_offset = tmp;
2205 } 2252 }
2206 2253
2207 // The spec does not allow the start or end offsets to be out or range; 2254 // The spec does not allow the start or end offsets to be out or range;
2208 // we must return an error if so. 2255 // we must return an error if so.
2209 LONG len = text_str.length(); 2256 LONG len = text_str.length();
2210 if (start_offset < 0) 2257 if (start_offset < 0)
2211 return E_INVALIDARG; 2258 return E_INVALIDARG;
2212 if (end_offset > len) 2259 if (end_offset > len)
2213 return E_INVALIDARG; 2260 return E_INVALIDARG;
2214 2261
2215 base::string16 substr = text_str.substr(start_offset, 2262 base::string16 substr =
2216 end_offset - start_offset); 2263 text_str.substr(start_offset, end_offset - start_offset);
2217 2264
2218 if (substr.empty()) 2265 if (substr.empty())
2219 return S_FALSE; 2266 return S_FALSE;
2220 2267
2221 *text = SysAllocString(substr.c_str()); 2268 *text = SysAllocString(substr.c_str());
2222 DCHECK(*text); 2269 DCHECK(*text);
2223 return S_OK; 2270 return S_OK;
2224 } 2271 }
2225 2272
2226 STDMETHODIMP BrowserAccessibilityWin::get_textAtOffset( 2273 STDMETHODIMP BrowserAccessibilityComWin::get_textAtOffset(
2227 LONG offset, 2274 LONG offset,
2228 IA2TextBoundaryType boundary_type, 2275 IA2TextBoundaryType boundary_type,
2229 LONG* start_offset, 2276 LONG* start_offset,
2230 LONG* end_offset, 2277 LONG* end_offset,
2231 BSTR* text) { 2278 BSTR* text) {
2232 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT_AT_OFFSET); 2279 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT_AT_OFFSET);
2233 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2280 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2234 AccessibilityMode::kInlineTextBoxes); 2281 AccessibilityMode::kInlineTextBoxes);
2235 if (!instance_active()) 2282 if (!GetOwner() || !GetOwner()->instance_active())
2236 return E_FAIL; 2283 return E_FAIL;
2237 2284
2238 if (!start_offset || !end_offset || !text) 2285 if (!start_offset || !end_offset || !text)
2239 return E_INVALIDARG; 2286 return E_INVALIDARG;
2240 2287
2241 HandleSpecialTextOffset(&offset); 2288 HandleSpecialTextOffset(&offset);
2242 if (offset < 0) 2289 if (offset < 0)
2243 return E_INVALIDARG; 2290 return E_INVALIDARG;
2244 2291
2245 const base::string16& text_str = GetText(); 2292 const base::string16& text_str = GetOwner()->GetText();
2246 LONG text_len = text_str.length(); 2293 LONG text_len = text_str.length();
2247 if (offset > text_len) 2294 if (offset > text_len)
2248 return E_INVALIDARG; 2295 return E_INVALIDARG;
2249 2296
2250 // The IAccessible2 spec says we don't have to implement the "sentence" 2297 // The IAccessible2 spec says we don't have to implement the "sentence"
2251 // boundary type, we can just let the screenreader handle it. 2298 // boundary type, we can just let the screenreader handle it.
2252 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) { 2299 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) {
2253 *start_offset = 0; 2300 *start_offset = 0;
2254 *end_offset = 0; 2301 *end_offset = 0;
2255 *text = NULL; 2302 *text = NULL;
2256 return S_FALSE; 2303 return S_FALSE;
2257 } 2304 }
2258 2305
2259 // According to the IA2 Spec, only line boundaries should succeed when 2306 // According to the IA2 Spec, only line boundaries should succeed when
2260 // the offset is one past the end of the text. 2307 // the offset is one past the end of the text.
2261 if (offset == text_len) { 2308 if (offset == text_len) {
2262 if (boundary_type == IA2_TEXT_BOUNDARY_LINE) { 2309 if (boundary_type == IA2_TEXT_BOUNDARY_LINE) {
2263 --offset; 2310 --offset;
2264 } else { 2311 } else {
2265 *start_offset = 0; 2312 *start_offset = 0;
2266 *end_offset = 0; 2313 *end_offset = 0;
2267 *text = nullptr; 2314 *text = nullptr;
2268 return S_FALSE; 2315 return S_FALSE;
2269 } 2316 }
2270 } 2317 }
2271 2318
2272 *start_offset = FindBoundary( 2319 *start_offset =
2273 text_str, boundary_type, offset, ui::BACKWARDS_DIRECTION); 2320 FindBoundary(text_str, boundary_type, offset, ui::BACKWARDS_DIRECTION);
2274 *end_offset = FindBoundary( 2321 *end_offset =
2275 text_str, boundary_type, offset, ui::FORWARDS_DIRECTION); 2322 FindBoundary(text_str, boundary_type, offset, ui::FORWARDS_DIRECTION);
2276 return get_text(*start_offset, *end_offset, text); 2323 return get_text(*start_offset, *end_offset, text);
2277 } 2324 }
2278 2325
2279 STDMETHODIMP BrowserAccessibilityWin::get_textBeforeOffset( 2326 STDMETHODIMP BrowserAccessibilityComWin::get_textBeforeOffset(
2280 LONG offset, 2327 LONG offset,
2281 IA2TextBoundaryType boundary_type, 2328 IA2TextBoundaryType boundary_type,
2282 LONG* start_offset, 2329 LONG* start_offset,
2283 LONG* end_offset, 2330 LONG* end_offset,
2284 BSTR* text) { 2331 BSTR* text) {
2285 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT_BEFORE_OFFSET); 2332 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT_BEFORE_OFFSET);
2286 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2333 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2287 AccessibilityMode::kInlineTextBoxes); 2334 AccessibilityMode::kInlineTextBoxes);
2288 if (!instance_active()) 2335 if (!GetOwner() || !GetOwner()->instance_active())
2289 return E_FAIL; 2336 return E_FAIL;
2290 2337
2291 if (!start_offset || !end_offset || !text) 2338 if (!start_offset || !end_offset || !text)
2292 return E_INVALIDARG; 2339 return E_INVALIDARG;
2293 2340
2294 // The IAccessible2 spec says we don't have to implement the "sentence" 2341 // The IAccessible2 spec says we don't have to implement the "sentence"
2295 // boundary type, we can just let the screenreader handle it. 2342 // boundary type, we can just let the screenreader handle it.
2296 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) { 2343 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) {
2297 *start_offset = 0; 2344 *start_offset = 0;
2298 *end_offset = 0; 2345 *end_offset = 0;
2299 *text = NULL; 2346 *text = NULL;
2300 return S_FALSE; 2347 return S_FALSE;
2301 } 2348 }
2302 2349
2303 const base::string16& text_str = GetText(); 2350 const base::string16& text_str = GetOwner()->GetText();
2304 2351
2305 *start_offset = FindBoundary( 2352 *start_offset =
2306 text_str, boundary_type, offset, ui::BACKWARDS_DIRECTION); 2353 FindBoundary(text_str, boundary_type, offset, ui::BACKWARDS_DIRECTION);
2307 *end_offset = offset; 2354 *end_offset = offset;
2308 return get_text(*start_offset, *end_offset, text); 2355 return get_text(*start_offset, *end_offset, text);
2309 } 2356 }
2310 2357
2311 STDMETHODIMP BrowserAccessibilityWin::get_textAfterOffset( 2358 STDMETHODIMP BrowserAccessibilityComWin::get_textAfterOffset(
2312 LONG offset, 2359 LONG offset,
2313 IA2TextBoundaryType boundary_type, 2360 IA2TextBoundaryType boundary_type,
2314 LONG* start_offset, 2361 LONG* start_offset,
2315 LONG* end_offset, 2362 LONG* end_offset,
2316 BSTR* text) { 2363 BSTR* text) {
2317 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT_AFTER_OFFSET); 2364 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TEXT_AFTER_OFFSET);
2318 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2365 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2319 AccessibilityMode::kInlineTextBoxes); 2366 AccessibilityMode::kInlineTextBoxes);
2320 if (!instance_active()) 2367 if (!GetOwner() || !GetOwner()->instance_active())
2321 return E_FAIL; 2368 return E_FAIL;
2322 2369
2323 if (!start_offset || !end_offset || !text) 2370 if (!start_offset || !end_offset || !text)
2324 return E_INVALIDARG; 2371 return E_INVALIDARG;
2325 2372
2326 // The IAccessible2 spec says we don't have to implement the "sentence" 2373 // The IAccessible2 spec says we don't have to implement the "sentence"
2327 // boundary type, we can just let the screenreader handle it. 2374 // boundary type, we can just let the screenreader handle it.
2328 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) { 2375 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) {
2329 *start_offset = 0; 2376 *start_offset = 0;
2330 *end_offset = 0; 2377 *end_offset = 0;
2331 *text = NULL; 2378 *text = NULL;
2332 return S_FALSE; 2379 return S_FALSE;
2333 } 2380 }
2334 2381
2335 const base::string16& text_str = GetText(); 2382 const base::string16& text_str = GetOwner()->GetText();
2336 2383
2337 *start_offset = offset; 2384 *start_offset = offset;
2338 *end_offset = FindBoundary( 2385 *end_offset =
2339 text_str, boundary_type, offset, ui::FORWARDS_DIRECTION); 2386 FindBoundary(text_str, boundary_type, offset, ui::FORWARDS_DIRECTION);
2340 return get_text(*start_offset, *end_offset, text); 2387 return get_text(*start_offset, *end_offset, text);
2341 } 2388 }
2342 2389
2343 STDMETHODIMP BrowserAccessibilityWin::get_newText(IA2TextSegment* new_text) { 2390 STDMETHODIMP BrowserAccessibilityComWin::get_newText(IA2TextSegment* new_text) {
2344 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NEW_TEXT); 2391 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NEW_TEXT);
2345 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2392 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2346 if (!instance_active()) 2393 if (!GetOwner() || !GetOwner()->instance_active())
2347 return E_FAIL; 2394 return E_FAIL;
2348 2395
2349 if (!new_text) 2396 if (!new_text)
2350 return E_INVALIDARG; 2397 return E_INVALIDARG;
2351 2398
2352 if (!old_win_attributes_) 2399 if (!old_win_attributes_)
2353 return E_FAIL; 2400 return E_FAIL;
2354 2401
2355 int start, old_len, new_len; 2402 int start, old_len, new_len;
2356 ComputeHypertextRemovedAndInserted(&start, &old_len, &new_len); 2403 ComputeHypertextRemovedAndInserted(&start, &old_len, &new_len);
2357 if (new_len == 0) 2404 if (new_len == 0)
2358 return E_FAIL; 2405 return E_FAIL;
2359 2406
2360 base::string16 substr = GetText().substr(start, new_len); 2407 base::string16 substr = GetOwner()->GetText().substr(start, new_len);
2361 new_text->text = SysAllocString(substr.c_str()); 2408 new_text->text = SysAllocString(substr.c_str());
2362 new_text->start = static_cast<long>(start); 2409 new_text->start = static_cast<long>(start);
2363 new_text->end = static_cast<long>(start + new_len); 2410 new_text->end = static_cast<long>(start + new_len);
2364 return S_OK; 2411 return S_OK;
2365 } 2412 }
2366 2413
2367 STDMETHODIMP BrowserAccessibilityWin::get_oldText(IA2TextSegment* old_text) { 2414 STDMETHODIMP BrowserAccessibilityComWin::get_oldText(IA2TextSegment* old_text) {
2368 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_OLD_TEXT); 2415 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_OLD_TEXT);
2369 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2416 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2370 if (!instance_active()) 2417 if (!GetOwner() || !GetOwner()->instance_active())
2371 return E_FAIL; 2418 return E_FAIL;
2372 2419
2373 if (!old_text) 2420 if (!old_text)
2374 return E_INVALIDARG; 2421 return E_INVALIDARG;
2375 2422
2376 if (!old_win_attributes_) 2423 if (!old_win_attributes_)
2377 return E_FAIL; 2424 return E_FAIL;
2378 2425
2379 int start, old_len, new_len; 2426 int start, old_len, new_len;
2380 ComputeHypertextRemovedAndInserted(&start, &old_len, &new_len); 2427 ComputeHypertextRemovedAndInserted(&start, &old_len, &new_len);
2381 if (old_len == 0) 2428 if (old_len == 0)
2382 return E_FAIL; 2429 return E_FAIL;
2383 2430
2384 base::string16 old_hypertext = old_win_attributes_->hypertext; 2431 base::string16 old_hypertext = old_win_attributes_->hypertext;
2385 base::string16 substr = old_hypertext.substr(start, old_len); 2432 base::string16 substr = old_hypertext.substr(start, old_len);
2386 old_text->text = SysAllocString(substr.c_str()); 2433 old_text->text = SysAllocString(substr.c_str());
2387 old_text->start = static_cast<long>(start); 2434 old_text->start = static_cast<long>(start);
2388 old_text->end = static_cast<long>(start + old_len); 2435 old_text->end = static_cast<long>(start + old_len);
2389 return S_OK; 2436 return S_OK;
2390 } 2437 }
2391 2438
2392 STDMETHODIMP BrowserAccessibilityWin::get_offsetAtPoint( 2439 STDMETHODIMP BrowserAccessibilityComWin::get_offsetAtPoint(
2393 LONG x, 2440 LONG x,
2394 LONG y, 2441 LONG y,
2395 IA2CoordinateType coord_type, 2442 IA2CoordinateType coord_type,
2396 LONG* offset) { 2443 LONG* offset) {
2397 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_OFFSET_AT_POINT); 2444 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_OFFSET_AT_POINT);
2398 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2445 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2399 AccessibilityMode::kInlineTextBoxes); 2446 AccessibilityMode::kInlineTextBoxes);
2400 if (!instance_active()) 2447 if (!GetOwner() || !GetOwner()->instance_active())
2401 return E_FAIL; 2448 return E_FAIL;
2402 2449
2403 if (!offset) 2450 if (!offset)
2404 return E_INVALIDARG; 2451 return E_INVALIDARG;
2405 2452
2406 // TODO(dmazzoni): implement this. We're returning S_OK for now so that 2453 // TODO(dmazzoni): implement this. We're returning S_OK for now so that
2407 // screen readers still return partially accurate results rather than 2454 // screen readers still return partially accurate results rather than
2408 // completely failing. 2455 // completely failing.
2409 *offset = 0; 2456 *offset = 0;
2410 return S_OK; 2457 return S_OK;
2411 } 2458 }
2412 2459
2413 STDMETHODIMP BrowserAccessibilityWin::scrollSubstringTo( 2460 STDMETHODIMP BrowserAccessibilityComWin::scrollSubstringTo(
2414 LONG start_index, 2461 LONG start_index,
2415 LONG end_index, 2462 LONG end_index,
2416 IA2ScrollType scroll_type) { 2463 IA2ScrollType scroll_type) {
2417 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_SUBSTRING_TO); 2464 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_SUBSTRING_TO);
2418 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2465 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2419 AccessibilityMode::kInlineTextBoxes); 2466 AccessibilityMode::kInlineTextBoxes);
2420 // TODO(dmazzoni): adjust this for the start and end index, too. 2467 // TODO(dmazzoni): adjust this for the start and end index, too.
2421 return scrollTo(scroll_type); 2468 return scrollTo(scroll_type);
2422 } 2469 }
2423 2470
2424 STDMETHODIMP BrowserAccessibilityWin::scrollSubstringToPoint( 2471 STDMETHODIMP BrowserAccessibilityComWin::scrollSubstringToPoint(
2425 LONG start_index, 2472 LONG start_index,
2426 LONG end_index, 2473 LONG end_index,
2427 IA2CoordinateType coordinate_type, 2474 IA2CoordinateType coordinate_type,
2428 LONG x, 2475 LONG x,
2429 LONG y) { 2476 LONG y) {
2430 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_SUBSTRING_TO_POINT); 2477 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_SUBSTRING_TO_POINT);
2431 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 2478 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
2432 AccessibilityMode::kInlineTextBoxes); 2479 AccessibilityMode::kInlineTextBoxes);
2480 if (!GetOwner() || !GetOwner()->instance_active())
2481 return E_FAIL;
2482
2433 if (start_index > end_index) 2483 if (start_index > end_index)
2434 std::swap(start_index, end_index); 2484 std::swap(start_index, end_index);
2435 LONG length = end_index - start_index + 1; 2485 LONG length = end_index - start_index + 1;
2436 DCHECK_GE(length, 0); 2486 DCHECK_GE(length, 0);
2437 2487
2438 gfx::Rect string_bounds = GetPageBoundsForRange(start_index, length); 2488 gfx::Rect string_bounds =
2439 string_bounds -= GetPageBoundsRect().OffsetFromOrigin(); 2489 GetOwner()->GetPageBoundsForRange(start_index, length);
2490 string_bounds -= GetOwner()->GetPageBoundsRect().OffsetFromOrigin();
2440 x -= string_bounds.x(); 2491 x -= string_bounds.x();
2441 y -= string_bounds.y(); 2492 y -= string_bounds.y();
2442 2493
2443 return scrollToPoint(coordinate_type, x, y); 2494 return scrollToPoint(coordinate_type, x, y);
2444 } 2495 }
2445 2496
2446 STDMETHODIMP BrowserAccessibilityWin::addSelection(LONG start_offset, 2497 STDMETHODIMP BrowserAccessibilityComWin::addSelection(LONG start_offset,
2447 LONG end_offset) { 2498 LONG end_offset) {
2448 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ADD_SELECTION); 2499 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ADD_SELECTION);
2449 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2500 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2450 if (!instance_active()) 2501 if (!GetOwner() || !GetOwner()->instance_active())
2451 return E_FAIL; 2502 return E_FAIL;
2452 2503
2453 // We only support one selection. 2504 // We only support one selection.
2454 SetIA2HypertextSelection(start_offset, end_offset); 2505 SetIA2HypertextSelection(start_offset, end_offset);
2455 return S_OK; 2506 return S_OK;
2456 } 2507 }
2457 2508
2458 STDMETHODIMP BrowserAccessibilityWin::removeSelection(LONG selection_index) { 2509 STDMETHODIMP BrowserAccessibilityComWin::removeSelection(LONG selection_index) {
2459 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_REMOVE_SELECTION); 2510 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_REMOVE_SELECTION);
2460 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2511 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2461 if (!instance_active()) 2512 if (!GetOwner() || !GetOwner()->instance_active())
2462 return E_FAIL; 2513 return E_FAIL;
2463 2514
2464 if (selection_index != 0) 2515 if (selection_index != 0)
2465 return E_INVALIDARG; 2516 return E_INVALIDARG;
2466 2517
2467 // Simply collapse the selection to the position of the caret if a caret is 2518 // Simply collapse the selection to the position of the caret if a caret is
2468 // visible, otherwise set the selection to 0. 2519 // visible, otherwise set the selection to 0.
2469 LONG caret_offset = 0; 2520 LONG caret_offset = 0;
2470 int selection_start, selection_end; 2521 int selection_start, selection_end;
2471 GetSelectionOffsets(&selection_start, &selection_end); 2522 GetSelectionOffsets(&selection_start, &selection_end);
2472 if (HasCaret() && selection_end >= 0) 2523 if (GetOwner()->HasCaret() && selection_end >= 0)
2473 caret_offset = selection_end; 2524 caret_offset = selection_end;
2474 SetIA2HypertextSelection(caret_offset, caret_offset); 2525 SetIA2HypertextSelection(caret_offset, caret_offset);
2475 return S_OK; 2526 return S_OK;
2476 } 2527 }
2477 2528
2478 STDMETHODIMP BrowserAccessibilityWin::setCaretOffset(LONG offset) { 2529 STDMETHODIMP BrowserAccessibilityComWin::setCaretOffset(LONG offset) {
2479 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SET_CARET_OFFSET); 2530 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SET_CARET_OFFSET);
2480 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2531 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2481 if (!instance_active()) 2532 if (!GetOwner() || !GetOwner()->instance_active())
2482 return E_FAIL; 2533 return E_FAIL;
2483 SetIA2HypertextSelection(offset, offset); 2534 SetIA2HypertextSelection(offset, offset);
2484 return S_OK; 2535 return S_OK;
2485 } 2536 }
2486 2537
2487 STDMETHODIMP BrowserAccessibilityWin::setSelection(LONG selection_index, 2538 STDMETHODIMP BrowserAccessibilityComWin::setSelection(LONG selection_index,
2488 LONG start_offset, 2539 LONG start_offset,
2489 LONG end_offset) { 2540 LONG end_offset) {
2490 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SET_SELECTION); 2541 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SET_SELECTION);
2491 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2542 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2492 if (!instance_active()) 2543 if (!GetOwner() || !GetOwner()->instance_active())
2493 return E_FAIL; 2544 return E_FAIL;
2494 if (selection_index != 0) 2545 if (selection_index != 0)
2495 return E_INVALIDARG; 2546 return E_INVALIDARG;
2496 SetIA2HypertextSelection(start_offset, end_offset); 2547 SetIA2HypertextSelection(start_offset, end_offset);
2497 return S_OK; 2548 return S_OK;
2498 } 2549 }
2499 2550
2500 STDMETHODIMP BrowserAccessibilityWin::get_attributes(LONG offset, 2551 STDMETHODIMP BrowserAccessibilityComWin::get_attributes(LONG offset,
2501 LONG* start_offset, 2552 LONG* start_offset,
2502 LONG* end_offset, 2553 LONG* end_offset,
2503 BSTR* text_attributes) { 2554 BSTR* text_attributes) {
2504 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IATEXT_GET_ATTRIBUTES); 2555 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IATEXT_GET_ATTRIBUTES);
2505 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2556 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2506 if (!start_offset || !end_offset || !text_attributes) 2557 if (!start_offset || !end_offset || !text_attributes)
2507 return E_INVALIDARG; 2558 return E_INVALIDARG;
2508 2559
2509 *start_offset = *end_offset = 0; 2560 *start_offset = *end_offset = 0;
2510 *text_attributes = nullptr; 2561 *text_attributes = nullptr;
2511 if (!instance_active()) 2562 if (!GetOwner() || !GetOwner()->instance_active())
2512 return E_FAIL; 2563 return E_FAIL;
2513 2564
2514 const base::string16 text = GetText(); 2565 const base::string16 text = GetOwner()->GetText();
2515 HandleSpecialTextOffset(&offset); 2566 HandleSpecialTextOffset(&offset);
2516 if (offset < 0 || offset > static_cast<LONG>(text.size())) 2567 if (offset < 0 || offset > static_cast<LONG>(text.size()))
2517 return E_INVALIDARG; 2568 return E_INVALIDARG;
2518 2569
2519 ComputeStylesIfNeeded(); 2570 ComputeStylesIfNeeded();
2520 *start_offset = FindStartOfStyle(offset, ui::BACKWARDS_DIRECTION); 2571 *start_offset = FindStartOfStyle(offset, ui::BACKWARDS_DIRECTION);
2521 *end_offset = FindStartOfStyle(offset, ui::FORWARDS_DIRECTION); 2572 *end_offset = FindStartOfStyle(offset, ui::FORWARDS_DIRECTION);
2522 2573
2523 base::string16 attributes_str; 2574 base::string16 attributes_str;
2524 const std::vector<base::string16>& attributes = 2575 const std::vector<base::string16>& attributes =
2525 offset_to_text_attributes().find(*start_offset)->second; 2576 offset_to_text_attributes().find(*start_offset)->second;
2526 for (const base::string16& attribute : attributes) { 2577 for (const base::string16& attribute : attributes) {
2527 attributes_str += attribute + L';'; 2578 attributes_str += attribute + L';';
2528 } 2579 }
2529 2580
2530 if (attributes.empty()) 2581 if (attributes.empty())
2531 return S_FALSE; 2582 return S_FALSE;
2532 2583
2533 *text_attributes = SysAllocString(attributes_str.c_str()); 2584 *text_attributes = SysAllocString(attributes_str.c_str());
2534 DCHECK(*text_attributes); 2585 DCHECK(*text_attributes);
2535 return S_OK; 2586 return S_OK;
2536 } 2587 }
2537 2588
2538 // 2589 //
2539 // IAccessibleHypertext methods. 2590 // IAccessibleHypertext methods.
2540 // 2591 //
2541 2592
2542 STDMETHODIMP BrowserAccessibilityWin::get_nHyperlinks(long* hyperlink_count) { 2593 STDMETHODIMP BrowserAccessibilityComWin::get_nHyperlinks(
2594 long* hyperlink_count) {
2543 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_HYPERLINKS); 2595 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_N_HYPERLINKS);
2544 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2596 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2545 if (!instance_active()) 2597 if (!GetOwner() || !GetOwner()->instance_active())
2546 return E_FAIL; 2598 return E_FAIL;
2547 2599
2548 if (!hyperlink_count) 2600 if (!hyperlink_count)
2549 return E_INVALIDARG; 2601 return E_INVALIDARG;
2550 2602
2551 *hyperlink_count = hyperlink_offset_to_index().size(); 2603 *hyperlink_count = hyperlink_offset_to_index().size();
2552 return S_OK; 2604 return S_OK;
2553 } 2605 }
2554 2606
2555 STDMETHODIMP BrowserAccessibilityWin::get_hyperlink( 2607 STDMETHODIMP BrowserAccessibilityComWin::get_hyperlink(
2556 long index, 2608 long index,
2557 IAccessibleHyperlink** hyperlink) { 2609 IAccessibleHyperlink** hyperlink) {
2558 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_HYPERLINK); 2610 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_HYPERLINK);
2559 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2611 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2560 if (!instance_active()) 2612 if (!GetOwner() || !GetOwner()->instance_active())
2561 return E_FAIL; 2613 return E_FAIL;
2562 2614
2563 if (!hyperlink || 2615 if (!hyperlink || index < 0 ||
2564 index < 0 ||
2565 index >= static_cast<long>(hyperlinks().size())) { 2616 index >= static_cast<long>(hyperlinks().size())) {
2566 return E_INVALIDARG; 2617 return E_INVALIDARG;
2567 } 2618 }
2568 2619
2569 int32_t id = hyperlinks()[index]; 2620 int32_t id = hyperlinks()[index];
2570 BrowserAccessibilityWin* link = 2621 BrowserAccessibilityComWin* link =
2571 ToBrowserAccessibilityWin(GetFromUniqueID(id)); 2622 ToBrowserAccessibilityComWin(GetOwner()->GetFromUniqueID(id));
2572 if (!link) 2623 if (!link)
2573 return E_FAIL; 2624 return E_FAIL;
2574 2625
2575 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference()); 2626 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference());
2576 return S_OK; 2627 return S_OK;
2577 } 2628 }
2578 2629
2579 STDMETHODIMP BrowserAccessibilityWin::get_hyperlinkIndex( 2630 STDMETHODIMP BrowserAccessibilityComWin::get_hyperlinkIndex(
2580 long char_index, 2631 long char_index,
2581 long* hyperlink_index) { 2632 long* hyperlink_index) {
2582 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_HYPERLINK_INDEX); 2633 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_HYPERLINK_INDEX);
2583 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2634 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2584 if (!instance_active()) 2635 if (!GetOwner() || !GetOwner()->instance_active())
2585 return E_FAIL; 2636 return E_FAIL;
2586 2637
2587 if (!hyperlink_index) 2638 if (!hyperlink_index)
2588 return E_INVALIDARG; 2639 return E_INVALIDARG;
2589 2640
2590 if (char_index < 0 || char_index >= static_cast<long>(GetText().size())) { 2641 if (char_index < 0 ||
2642 char_index >= static_cast<long>(GetOwner()->GetText().size())) {
2591 return E_INVALIDARG; 2643 return E_INVALIDARG;
2592 } 2644 }
2593 2645
2594 std::map<int32_t, int32_t>::iterator it = 2646 std::map<int32_t, int32_t>::iterator it =
2595 hyperlink_offset_to_index().find(char_index); 2647 hyperlink_offset_to_index().find(char_index);
2596 if (it == hyperlink_offset_to_index().end()) { 2648 if (it == hyperlink_offset_to_index().end()) {
2597 *hyperlink_index = -1; 2649 *hyperlink_index = -1;
2598 return S_FALSE; 2650 return S_FALSE;
2599 } 2651 }
2600 2652
2601 *hyperlink_index = it->second; 2653 *hyperlink_index = it->second;
2602 return S_OK; 2654 return S_OK;
2603 } 2655 }
2604 2656
2605 // 2657 //
2606 // IAccessibleHyperlink methods. 2658 // IAccessibleHyperlink methods.
2607 // 2659 //
2608 2660
2609 // Currently, only text links are supported. 2661 // Currently, only text links are supported.
2610 STDMETHODIMP BrowserAccessibilityWin::get_anchor(long index, VARIANT* anchor) { 2662 STDMETHODIMP BrowserAccessibilityComWin::get_anchor(long index,
2663 VARIANT* anchor) {
2611 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ANCHOR); 2664 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ANCHOR);
2612 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2665 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2613 if (!instance_active() || !IsHyperlink()) 2666 if (!GetOwner()->instance_active() || !IsHyperlink())
2614 return E_FAIL; 2667 return E_FAIL;
2615 2668
2616 // IA2 text links can have only one anchor, that is the text inside them. 2669 // IA2 text links can have only one anchor, that is the text inside them.
2617 if (index != 0 || !anchor) 2670 if (index != 0 || !anchor)
2618 return E_INVALIDARG; 2671 return E_INVALIDARG;
2619 2672
2620 BSTR ia2_hypertext = SysAllocString(GetText().c_str()); 2673 BSTR ia2_hypertext = SysAllocString(GetOwner()->GetText().c_str());
2621 DCHECK(ia2_hypertext); 2674 DCHECK(ia2_hypertext);
2622 anchor->vt = VT_BSTR; 2675 anchor->vt = VT_BSTR;
2623 anchor->bstrVal = ia2_hypertext; 2676 anchor->bstrVal = ia2_hypertext;
2624 2677
2625 // Returning S_FALSE is not mentioned in the IA2 Spec, but it might have been 2678 // Returning S_FALSE is not mentioned in the IA2 Spec, but it might have been
2626 // an oversight. 2679 // an oversight.
2627 if (!SysStringLen(ia2_hypertext)) 2680 if (!SysStringLen(ia2_hypertext))
2628 return S_FALSE; 2681 return S_FALSE;
2629 2682
2630 return S_OK; 2683 return S_OK;
2631 } 2684 }
2632 2685
2633 // Currently, only text links are supported. 2686 // Currently, only text links are supported.
2634 STDMETHODIMP BrowserAccessibilityWin::get_anchorTarget(long index, 2687 STDMETHODIMP BrowserAccessibilityComWin::get_anchorTarget(
2635 VARIANT* anchor_target) { 2688 long index,
2689 VARIANT* anchor_target) {
2636 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ANCHOR_TARGET); 2690 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ANCHOR_TARGET);
2637 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2691 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2638 if (!instance_active() || !IsHyperlink()) 2692 if (!GetOwner()->instance_active() || !IsHyperlink())
2639 return E_FAIL; 2693 return E_FAIL;
2640 2694
2641 // IA2 text links can have at most one target, that is when they represent an 2695 // IA2 text links can have at most one target, that is when they represent an
2642 // HTML hyperlink, i.e. an <a> element with a "href" attribute. 2696 // HTML hyperlink, i.e. an <a> element with a "href" attribute.
2643 if (index != 0 || !anchor_target) 2697 if (index != 0 || !anchor_target)
2644 return E_INVALIDARG; 2698 return E_INVALIDARG;
2645 2699
2646 BSTR target; 2700 BSTR target;
2647 if (!(ia_state() & STATE_SYSTEM_LINKED) || 2701 if (!(ia_state() & STATE_SYSTEM_LINKED) ||
2648 FAILED(GetStringAttributeAsBstr(ui::AX_ATTR_URL, &target))) { 2702 FAILED(GetStringAttributeAsBstr(ui::AX_ATTR_URL, &target))) {
2649 target = SysAllocString(L""); 2703 target = SysAllocString(L"");
2650 } 2704 }
2651 DCHECK(target); 2705 DCHECK(target);
2652 anchor_target->vt = VT_BSTR; 2706 anchor_target->vt = VT_BSTR;
2653 anchor_target->bstrVal = target; 2707 anchor_target->bstrVal = target;
2654 2708
2655 // Returning S_FALSE is not mentioned in the IA2 Spec, but it might have been 2709 // Returning S_FALSE is not mentioned in the IA2 Spec, but it might have been
2656 // an oversight. 2710 // an oversight.
2657 if (!SysStringLen(target)) 2711 if (!SysStringLen(target))
2658 return S_FALSE; 2712 return S_FALSE;
2659 2713
2660 return S_OK; 2714 return S_OK;
2661 } 2715 }
2662 2716
2663 STDMETHODIMP BrowserAccessibilityWin::get_startIndex(long* index) { 2717 STDMETHODIMP BrowserAccessibilityComWin::get_startIndex(long* index) {
2664 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_START_INDEX); 2718 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_START_INDEX);
2665 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2719 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2666 if (!instance_active() || !IsHyperlink()) 2720 if (!GetOwner()->instance_active() || !IsHyperlink())
2667 return E_FAIL; 2721 return E_FAIL;
2668 2722
2669 if (!index) 2723 if (!index)
2670 return E_INVALIDARG; 2724 return E_INVALIDARG;
2671 2725
2672 int32_t hypertext_offset = 0; 2726 int32_t hypertext_offset = 0;
2673 auto* parent = PlatformGetParent(); 2727 auto* parent = GetOwner()->PlatformGetParent();
2674 if (parent) { 2728 if (parent) {
2675 hypertext_offset = 2729 hypertext_offset =
2676 ToBrowserAccessibilityWin(parent)->GetHypertextOffsetFromChild(*this); 2730 ToBrowserAccessibilityComWin(parent)->GetHypertextOffsetFromChild(
2731 *this);
2677 } 2732 }
2678 *index = static_cast<LONG>(hypertext_offset); 2733 *index = static_cast<LONG>(hypertext_offset);
2679 return S_OK; 2734 return S_OK;
2680 } 2735 }
2681 2736
2682 STDMETHODIMP BrowserAccessibilityWin::get_endIndex(long* index) { 2737 STDMETHODIMP BrowserAccessibilityComWin::get_endIndex(long* index) {
2683 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_END_INDEX); 2738 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_END_INDEX);
2684 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2739 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2685 LONG start_index; 2740 LONG start_index;
2686 HRESULT hr = get_startIndex(&start_index); 2741 HRESULT hr = get_startIndex(&start_index);
2687 if (hr == S_OK) 2742 if (hr == S_OK)
2688 *index = start_index + 1; 2743 *index = start_index + 1;
2689 return hr; 2744 return hr;
2690 } 2745 }
2691 2746
2692 // This method is deprecated in the IA2 Spec. 2747 // This method is deprecated in the IA2 Spec.
2693 STDMETHODIMP BrowserAccessibilityWin::get_valid(boolean* valid) { 2748 STDMETHODIMP BrowserAccessibilityComWin::get_valid(boolean* valid) {
2694 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_VALID); 2749 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_VALID);
2695 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2750 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2696 return E_NOTIMPL; 2751 return E_NOTIMPL;
2697 } 2752 }
2698 2753
2699 // 2754 //
2700 // IAccessibleAction partly implemented. 2755 // IAccessibleAction partly implemented.
2701 // 2756 //
2702 2757
2703 STDMETHODIMP BrowserAccessibilityWin::nActions(long* n_actions) { 2758 STDMETHODIMP BrowserAccessibilityComWin::nActions(long* n_actions) {
2704 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_N_ACTIONS); 2759 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_N_ACTIONS);
2705 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2760 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2706 if (!instance_active()) 2761 if (!GetOwner() || !GetOwner()->instance_active())
2707 return E_FAIL; 2762 return E_FAIL;
2708 2763
2709 if (!n_actions) 2764 if (!n_actions)
2710 return E_INVALIDARG; 2765 return E_INVALIDARG;
2711 2766
2712 // |IsHyperlink| is required for |IAccessibleHyperlink::anchor/anchorTarget| 2767 // |IsHyperlink| is required for |IAccessibleHyperlink::anchor/anchorTarget|
2713 // to work properly because the |IAccessibleHyperlink| interface inherits from 2768 // to work properly because the |IAccessibleHyperlink| interface inherits from
2714 // |IAccessibleAction|. 2769 // |IAccessibleAction|.
2715 if (IsHyperlink() || HasIntAttribute(ui::AX_ATTR_ACTION)) { 2770 if (IsHyperlink() || GetOwner()->HasIntAttribute(ui::AX_ATTR_ACTION)) {
2716 *n_actions = 1; 2771 *n_actions = 1;
2717 } else { 2772 } else {
2718 *n_actions = 0; 2773 *n_actions = 0;
2719 } 2774 }
2720 2775
2721 return S_OK; 2776 return S_OK;
2722 } 2777 }
2723 2778
2724 STDMETHODIMP BrowserAccessibilityWin::doAction(long action_index) { 2779 STDMETHODIMP BrowserAccessibilityComWin::doAction(long action_index) {
2725 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_DO_ACTION); 2780 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_DO_ACTION);
2726 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2781 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2727 if (!instance_active()) 2782 if (!GetOwner() || !GetOwner()->instance_active())
2728 return E_FAIL; 2783 return E_FAIL;
2729 2784
2730 if (!HasIntAttribute(ui::AX_ATTR_ACTION) || action_index != 0) 2785 if (!GetOwner()->HasIntAttribute(ui::AX_ATTR_ACTION) || action_index != 0)
2731 return E_INVALIDARG; 2786 return E_INVALIDARG;
2732 2787
2733 manager_->DoDefaultAction(*this); 2788 GetOwner()->manager()->DoDefaultAction(*GetOwner());
2734 return S_OK; 2789 return S_OK;
2735 } 2790 }
2736 2791
2737 STDMETHODIMP 2792 STDMETHODIMP
2738 BrowserAccessibilityWin::get_description(long action_index, BSTR* description) { 2793 BrowserAccessibilityComWin::get_description(long action_index,
2794 BSTR* description) {
2739 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IAACTION_GET_DESCRIPTION); 2795 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IAACTION_GET_DESCRIPTION);
2740 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2796 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2741 return E_NOTIMPL; 2797 return E_NOTIMPL;
2742 } 2798 }
2743 2799
2744 STDMETHODIMP BrowserAccessibilityWin::get_keyBinding(long action_index, 2800 STDMETHODIMP BrowserAccessibilityComWin::get_keyBinding(long action_index,
2745 long n_max_bindings, 2801 long n_max_bindings,
2746 BSTR** key_bindings, 2802 BSTR** key_bindings,
2747 long* n_bindings) { 2803 long* n_bindings) {
2748 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_KEY_BINDING); 2804 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_KEY_BINDING);
2749 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2805 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2750 return E_NOTIMPL; 2806 return E_NOTIMPL;
2751 } 2807 }
2752 2808
2753 STDMETHODIMP BrowserAccessibilityWin::get_name(long action_index, BSTR* name) { 2809 STDMETHODIMP BrowserAccessibilityComWin::get_name(long action_index,
2810 BSTR* name) {
2754 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NAME); 2811 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NAME);
2755 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2812 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2756 if (!instance_active()) 2813 if (!GetOwner() || !GetOwner()->instance_active())
2757 return E_FAIL; 2814 return E_FAIL;
2758 2815
2759 if (!name) 2816 if (!name)
2760 return E_INVALIDARG; 2817 return E_INVALIDARG;
2761 2818
2762 int action; 2819 int action;
2763 if (!GetIntAttribute(ui::AX_ATTR_ACTION, &action) || action_index != 0) { 2820 if (!GetOwner()->GetIntAttribute(ui::AX_ATTR_ACTION, &action) ||
2821 action_index != 0) {
2764 *name = nullptr; 2822 *name = nullptr;
2765 return E_INVALIDARG; 2823 return E_INVALIDARG;
2766 } 2824 }
2767 2825
2768 base::string16 action_verb = 2826 base::string16 action_verb =
2769 ui::ActionToUnlocalizedString(static_cast<ui::AXSupportedAction>(action)); 2827 ui::ActionToUnlocalizedString(static_cast<ui::AXSupportedAction>(action));
2770 if (action_verb.empty() || action_verb == L"none") { 2828 if (action_verb.empty() || action_verb == L"none") {
2771 *name = nullptr; 2829 *name = nullptr;
2772 return S_FALSE; 2830 return S_FALSE;
2773 } 2831 }
2774 2832
2775 *name = SysAllocString(action_verb.c_str()); 2833 *name = SysAllocString(action_verb.c_str());
2776 DCHECK(name); 2834 DCHECK(name);
2777 return S_OK; 2835 return S_OK;
2778 } 2836 }
2779 2837
2780 STDMETHODIMP 2838 STDMETHODIMP
2781 BrowserAccessibilityWin::get_localizedName(long action_index, 2839 BrowserAccessibilityComWin::get_localizedName(long action_index,
2782 BSTR* localized_name) { 2840 BSTR* localized_name) {
2783 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_NAME); 2841 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_NAME);
2784 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2842 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2785 if (!instance_active()) 2843 if (!GetOwner() || !GetOwner()->instance_active())
2786 return E_FAIL; 2844 return E_FAIL;
2787 2845
2788 if (!localized_name) 2846 if (!localized_name)
2789 return E_INVALIDARG; 2847 return E_INVALIDARG;
2790 2848
2791 int action; 2849 int action;
2792 if (!GetIntAttribute(ui::AX_ATTR_ACTION, &action) || action_index != 0) { 2850 if (!GetOwner()->GetIntAttribute(ui::AX_ATTR_ACTION, &action) ||
2851 action_index != 0) {
2793 *localized_name = nullptr; 2852 *localized_name = nullptr;
2794 return E_INVALIDARG; 2853 return E_INVALIDARG;
2795 } 2854 }
2796 2855
2797 base::string16 action_verb = 2856 base::string16 action_verb =
2798 ui::ActionToString(static_cast<ui::AXSupportedAction>(action)); 2857 ui::ActionToString(static_cast<ui::AXSupportedAction>(action));
2799 if (action_verb.empty()) { 2858 if (action_verb.empty()) {
2800 *localized_name = nullptr; 2859 *localized_name = nullptr;
2801 return S_FALSE; 2860 return S_FALSE;
2802 } 2861 }
2803 2862
2804 *localized_name = SysAllocString(action_verb.c_str()); 2863 *localized_name = SysAllocString(action_verb.c_str());
2805 DCHECK(localized_name); 2864 DCHECK(localized_name);
2806 return S_OK; 2865 return S_OK;
2807 } 2866 }
2808 2867
2809 // 2868 //
2810 // IAccessibleValue methods. 2869 // IAccessibleValue methods.
2811 // 2870 //
2812 2871
2813 STDMETHODIMP BrowserAccessibilityWin::get_currentValue(VARIANT* value) { 2872 STDMETHODIMP BrowserAccessibilityComWin::get_currentValue(VARIANT* value) {
2814 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CURRENT_VALUE); 2873 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CURRENT_VALUE);
2815 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2874 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2816 if (!instance_active()) 2875 if (!GetOwner() || !GetOwner()->instance_active())
2817 return E_FAIL; 2876 return E_FAIL;
2818 2877
2819 if (!value) 2878 if (!value)
2820 return E_INVALIDARG; 2879 return E_INVALIDARG;
2821 2880
2822 float float_val; 2881 float float_val;
2823 if (GetFloatAttribute( 2882 if (GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, &float_val)) {
2824 ui::AX_ATTR_VALUE_FOR_RANGE, &float_val)) {
2825 value->vt = VT_R8; 2883 value->vt = VT_R8;
2826 value->dblVal = float_val; 2884 value->dblVal = float_val;
2827 return S_OK; 2885 return S_OK;
2828 } 2886 }
2829 2887
2830 value->vt = VT_EMPTY; 2888 value->vt = VT_EMPTY;
2831 return S_FALSE; 2889 return S_FALSE;
2832 } 2890 }
2833 2891
2834 STDMETHODIMP BrowserAccessibilityWin::get_minimumValue(VARIANT* value) { 2892 STDMETHODIMP BrowserAccessibilityComWin::get_minimumValue(VARIANT* value) {
2835 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_MINIMUM_VALUE); 2893 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_MINIMUM_VALUE);
2836 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2894 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2837 if (!instance_active()) 2895 if (!GetOwner() || !GetOwner()->instance_active())
2838 return E_FAIL; 2896 return E_FAIL;
2839 2897
2840 if (!value) 2898 if (!value)
2841 return E_INVALIDARG; 2899 return E_INVALIDARG;
2842 2900
2843 float float_val; 2901 float float_val;
2844 if (GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE, 2902 if (GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE, &float_val)) {
2845 &float_val)) {
2846 value->vt = VT_R8; 2903 value->vt = VT_R8;
2847 value->dblVal = float_val; 2904 value->dblVal = float_val;
2848 return S_OK; 2905 return S_OK;
2849 } 2906 }
2850 2907
2851 value->vt = VT_EMPTY; 2908 value->vt = VT_EMPTY;
2852 return S_FALSE; 2909 return S_FALSE;
2853 } 2910 }
2854 2911
2855 STDMETHODIMP BrowserAccessibilityWin::get_maximumValue(VARIANT* value) { 2912 STDMETHODIMP BrowserAccessibilityComWin::get_maximumValue(VARIANT* value) {
2856 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_MAXIMUM_VALUE); 2913 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_MAXIMUM_VALUE);
2857 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2914 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2858 if (!instance_active()) 2915 if (!GetOwner() || !GetOwner()->instance_active())
2859 return E_FAIL; 2916 return E_FAIL;
2860 2917
2861 if (!value) 2918 if (!value)
2862 return E_INVALIDARG; 2919 return E_INVALIDARG;
2863 2920
2864 float float_val; 2921 float float_val;
2865 if (GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE, 2922 if (GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE, &float_val)) {
2866 &float_val)) {
2867 value->vt = VT_R8; 2923 value->vt = VT_R8;
2868 value->dblVal = float_val; 2924 value->dblVal = float_val;
2869 return S_OK; 2925 return S_OK;
2870 } 2926 }
2871 2927
2872 value->vt = VT_EMPTY; 2928 value->vt = VT_EMPTY;
2873 return S_FALSE; 2929 return S_FALSE;
2874 } 2930 }
2875 2931
2876 STDMETHODIMP BrowserAccessibilityWin::setCurrentValue(VARIANT new_value) { 2932 STDMETHODIMP BrowserAccessibilityComWin::setCurrentValue(VARIANT new_value) {
2877 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SET_CURRENT_VALUE); 2933 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SET_CURRENT_VALUE);
2878 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 2934 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2879 // TODO(dmazzoni): Implement this. 2935 // TODO(dmazzoni): Implement this.
2880 return E_NOTIMPL; 2936 return E_NOTIMPL;
2881 } 2937 }
2882 2938
2883 // 2939 //
2884 // ISimpleDOMDocument methods. 2940 // ISimpleDOMDocument methods.
2885 // 2941 //
2886 2942
2887 STDMETHODIMP BrowserAccessibilityWin::get_URL(BSTR* url) { 2943 STDMETHODIMP BrowserAccessibilityComWin::get_URL(BSTR* url) {
2888 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_URL); 2944 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_URL);
2889 if (!instance_active()) 2945 if (!GetOwner() || !GetOwner()->instance_active())
2946 return E_FAIL;
2947
2948 auto* manager = GetOwner()->manager();
2949 if (!manager)
2890 return E_FAIL; 2950 return E_FAIL;
2891 2951
2892 if (!url) 2952 if (!url)
2893 return E_INVALIDARG; 2953 return E_INVALIDARG;
2894 2954
2895 if (this != manager_->GetRoot()) 2955 if (GetOwner() != manager->GetRoot())
2896 return E_FAIL; 2956 return E_FAIL;
2897 2957
2898 std::string str = manager_->GetTreeData().url; 2958 std::string str = manager->GetTreeData().url;
2899 if (str.empty()) 2959 if (str.empty())
2900 return S_FALSE; 2960 return S_FALSE;
2901 2961
2902 *url = SysAllocString(base::UTF8ToUTF16(str).c_str()); 2962 *url = SysAllocString(base::UTF8ToUTF16(str).c_str());
2903 DCHECK(*url); 2963 DCHECK(*url);
2904 2964
2905 return S_OK; 2965 return S_OK;
2906 } 2966 }
2907 2967
2908 STDMETHODIMP BrowserAccessibilityWin::get_title(BSTR* title) { 2968 STDMETHODIMP BrowserAccessibilityComWin::get_title(BSTR* title) {
2909 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TITLE); 2969 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_TITLE);
2910 if (!instance_active()) 2970 if (!GetOwner() || !GetOwner()->instance_active())
2971 return E_FAIL;
2972
2973 auto* manager = GetOwner()->manager();
2974 if (!manager)
2911 return E_FAIL; 2975 return E_FAIL;
2912 2976
2913 if (!title) 2977 if (!title)
2914 return E_INVALIDARG; 2978 return E_INVALIDARG;
2915 2979
2916 std::string str = manager_->GetTreeData().title; 2980 std::string str = manager->GetTreeData().title;
2917 if (str.empty()) 2981 if (str.empty())
2918 return S_FALSE; 2982 return S_FALSE;
2919 2983
2920 *title = SysAllocString(base::UTF8ToUTF16(str).c_str()); 2984 *title = SysAllocString(base::UTF8ToUTF16(str).c_str());
2921 DCHECK(*title); 2985 DCHECK(*title);
2922 2986
2923 return S_OK; 2987 return S_OK;
2924 } 2988 }
2925 2989
2926 STDMETHODIMP BrowserAccessibilityWin::get_mimeType(BSTR* mime_type) { 2990 STDMETHODIMP BrowserAccessibilityComWin::get_mimeType(BSTR* mime_type) {
2927 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_MIME_TYPE); 2991 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_MIME_TYPE);
2928 if (!instance_active()) 2992 if (!GetOwner() || !GetOwner()->instance_active())
2993 return E_FAIL;
2994
2995 auto* manager = GetOwner()->manager();
2996 if (!manager)
2929 return E_FAIL; 2997 return E_FAIL;
2930 2998
2931 if (!mime_type) 2999 if (!mime_type)
2932 return E_INVALIDARG; 3000 return E_INVALIDARG;
2933 3001
2934 std::string str = manager_->GetTreeData().mimetype; 3002 std::string str = manager->GetTreeData().mimetype;
2935 if (str.empty()) 3003 if (str.empty())
2936 return S_FALSE; 3004 return S_FALSE;
2937 3005
2938 *mime_type = SysAllocString(base::UTF8ToUTF16(str).c_str()); 3006 *mime_type = SysAllocString(base::UTF8ToUTF16(str).c_str());
2939 DCHECK(*mime_type); 3007 DCHECK(*mime_type);
2940 3008
2941 return S_OK; 3009 return S_OK;
2942 } 3010 }
2943 3011
2944 STDMETHODIMP BrowserAccessibilityWin::get_docType(BSTR* doc_type) { 3012 STDMETHODIMP BrowserAccessibilityComWin::get_docType(BSTR* doc_type) {
2945 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_DOC_TYPE); 3013 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_DOC_TYPE);
2946 if (!instance_active()) 3014 if (!GetOwner() || !GetOwner()->instance_active())
3015 return E_FAIL;
3016
3017 auto* manager = GetOwner()->manager();
3018 if (!manager)
2947 return E_FAIL; 3019 return E_FAIL;
2948 3020
2949 if (!doc_type) 3021 if (!doc_type)
2950 return E_INVALIDARG; 3022 return E_INVALIDARG;
2951 3023
2952 std::string str = manager_->GetTreeData().doctype; 3024 std::string str = manager->GetTreeData().doctype;
2953 if (str.empty()) 3025 if (str.empty())
2954 return S_FALSE; 3026 return S_FALSE;
2955 3027
2956 *doc_type = SysAllocString(base::UTF8ToUTF16(str).c_str()); 3028 *doc_type = SysAllocString(base::UTF8ToUTF16(str).c_str());
2957 DCHECK(*doc_type); 3029 DCHECK(*doc_type);
2958 3030
2959 return S_OK; 3031 return S_OK;
2960 } 3032 }
2961 3033
2962 STDMETHODIMP 3034 STDMETHODIMP
2963 BrowserAccessibilityWin::get_nameSpaceURIForID(short name_space_id, 3035 BrowserAccessibilityComWin::get_nameSpaceURIForID(short name_space_id,
2964 BSTR* name_space_uri) { 3036 BSTR* name_space_uri) {
2965 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NAMESPACE_URI_FOR_ID); 3037 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NAMESPACE_URI_FOR_ID);
2966 return E_NOTIMPL; 3038 return E_NOTIMPL;
2967 } 3039 }
2968 3040
2969 STDMETHODIMP 3041 STDMETHODIMP
2970 BrowserAccessibilityWin::put_alternateViewMediaTypes( 3042 BrowserAccessibilityComWin::put_alternateViewMediaTypes(
2971 BSTR* comma_separated_media_types) { 3043 BSTR* comma_separated_media_types) {
2972 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_PUT_ALTERNATE_VIEW_MEDIA_TYPES); 3044 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_PUT_ALTERNATE_VIEW_MEDIA_TYPES);
2973 return E_NOTIMPL; 3045 return E_NOTIMPL;
2974 } 3046 }
2975 3047
2976 // 3048 //
2977 // ISimpleDOMNode methods. 3049 // ISimpleDOMNode methods.
2978 // 3050 //
2979 3051
2980 STDMETHODIMP BrowserAccessibilityWin::get_nodeInfo( 3052 STDMETHODIMP BrowserAccessibilityComWin::get_nodeInfo(
2981 BSTR* node_name, 3053 BSTR* node_name,
2982 short* name_space_id, 3054 short* name_space_id,
2983 BSTR* node_value, 3055 BSTR* node_value,
2984 unsigned int* num_children, 3056 unsigned int* num_children,
2985 unsigned int* unique_id, 3057 unsigned int* unique_id,
2986 unsigned short* node_type) { 3058 unsigned short* node_type) {
2987 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NODE_INFO); 3059 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NODE_INFO);
2988 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3060 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
2989 if (!instance_active()) 3061 if (!GetOwner() || !GetOwner()->instance_active())
2990 return E_FAIL; 3062 return E_FAIL;
2991 3063
2992 if (!node_name || !name_space_id || !node_value || !num_children || 3064 if (!node_name || !name_space_id || !node_value || !num_children ||
2993 !unique_id || !node_type) { 3065 !unique_id || !node_type) {
2994 return E_INVALIDARG; 3066 return E_INVALIDARG;
2995 } 3067 }
2996 3068
2997 base::string16 tag; 3069 base::string16 tag;
2998 if (GetString16Attribute(ui::AX_ATTR_HTML_TAG, &tag)) 3070 if (GetOwner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG, &tag))
2999 *node_name = SysAllocString(tag.c_str()); 3071 *node_name = SysAllocString(tag.c_str());
3000 else 3072 else
3001 *node_name = nullptr; 3073 *node_name = nullptr;
3002 3074
3003 *name_space_id = 0; 3075 *name_space_id = 0;
3004 *node_value = SysAllocString(value().c_str()); 3076 *node_value = SysAllocString(value().c_str());
3005 *num_children = PlatformChildCount(); 3077 *num_children = GetOwner()->PlatformChildCount();
3006 *unique_id = -this->unique_id(); 3078 *unique_id = -GetOwner()->unique_id();
3007 3079
3008 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || 3080 if (GetOwner()->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA ||
3009 GetRole() == ui::AX_ROLE_WEB_AREA) { 3081 GetOwner()->GetRole() == ui::AX_ROLE_WEB_AREA) {
3010 *node_type = NODETYPE_DOCUMENT; 3082 *node_type = NODETYPE_DOCUMENT;
3011 } else if (IsTextOnlyObject()) { 3083 } else if (GetOwner()->IsTextOnlyObject()) {
3012 *node_type = NODETYPE_TEXT; 3084 *node_type = NODETYPE_TEXT;
3013 } else { 3085 } else {
3014 *node_type = NODETYPE_ELEMENT; 3086 *node_type = NODETYPE_ELEMENT;
3015 } 3087 }
3016 3088
3017 return S_OK; 3089 return S_OK;
3018 } 3090 }
3019 3091
3020 STDMETHODIMP BrowserAccessibilityWin::get_attributes( 3092 STDMETHODIMP BrowserAccessibilityComWin::get_attributes(
3021 unsigned short max_attribs, 3093 unsigned short max_attribs,
3022 BSTR* attrib_names, 3094 BSTR* attrib_names,
3023 short* name_space_id, 3095 short* name_space_id,
3024 BSTR* attrib_values, 3096 BSTR* attrib_values,
3025 unsigned short* num_attribs) { 3097 unsigned short* num_attribs) {
3026 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ISIMPLEDOMNODE_GET_ATTRIBUTES); 3098 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ISIMPLEDOMNODE_GET_ATTRIBUTES);
3027 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3099 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3028 if (!instance_active()) 3100 if (!GetOwner() || !GetOwner()->instance_active())
3029 return E_FAIL; 3101 return E_FAIL;
3030 3102
3031 if (!attrib_names || !name_space_id || !attrib_values || !num_attribs) 3103 if (!attrib_names || !name_space_id || !attrib_values || !num_attribs)
3032 return E_INVALIDARG; 3104 return E_INVALIDARG;
3033 3105
3034 *num_attribs = max_attribs; 3106 *num_attribs = max_attribs;
3035 if (*num_attribs > GetHtmlAttributes().size()) 3107 if (*num_attribs > GetOwner()->GetHtmlAttributes().size())
3036 *num_attribs = GetHtmlAttributes().size(); 3108 *num_attribs = GetOwner()->GetHtmlAttributes().size();
3037 3109
3038 for (unsigned short i = 0; i < *num_attribs; ++i) { 3110 for (unsigned short i = 0; i < *num_attribs; ++i) {
3039 attrib_names[i] = SysAllocString( 3111 attrib_names[i] = SysAllocString(
3040 base::UTF8ToUTF16(GetHtmlAttributes()[i].first).c_str()); 3112 base::UTF8ToUTF16(GetOwner()->GetHtmlAttributes()[i].first).c_str());
3041 name_space_id[i] = 0; 3113 name_space_id[i] = 0;
3042 attrib_values[i] = SysAllocString( 3114 attrib_values[i] = SysAllocString(
3043 base::UTF8ToUTF16(GetHtmlAttributes()[i].second).c_str()); 3115 base::UTF8ToUTF16(GetOwner()->GetHtmlAttributes()[i].second).c_str());
3044 } 3116 }
3045 return S_OK; 3117 return S_OK;
3046 } 3118 }
3047 3119
3048 STDMETHODIMP BrowserAccessibilityWin::get_attributesForNames( 3120 STDMETHODIMP BrowserAccessibilityComWin::get_attributesForNames(
3049 unsigned short num_attribs, 3121 unsigned short num_attribs,
3050 BSTR* attrib_names, 3122 BSTR* attrib_names,
3051 short* name_space_id, 3123 short* name_space_id,
3052 BSTR* attrib_values) { 3124 BSTR* attrib_values) {
3053 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ATTRIBUTES_FOR_NAMES); 3125 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ATTRIBUTES_FOR_NAMES);
3054 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3126 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3055 if (!instance_active()) 3127 if (!GetOwner() || !GetOwner()->instance_active())
3056 return E_FAIL; 3128 return E_FAIL;
3057 3129
3058 if (!attrib_names || !name_space_id || !attrib_values) 3130 if (!attrib_names || !name_space_id || !attrib_values)
3059 return E_INVALIDARG; 3131 return E_INVALIDARG;
3060 3132
3061 for (unsigned short i = 0; i < num_attribs; ++i) { 3133 for (unsigned short i = 0; i < num_attribs; ++i) {
3062 name_space_id[i] = 0; 3134 name_space_id[i] = 0;
3063 bool found = false; 3135 bool found = false;
3064 std::string name = base::UTF16ToUTF8((LPCWSTR)attrib_names[i]); 3136 std::string name = base::UTF16ToUTF8((LPCWSTR)attrib_names[i]);
3065 for (unsigned int j = 0; j < GetHtmlAttributes().size(); ++j) { 3137 for (unsigned int j = 0; j < GetOwner()->GetHtmlAttributes().size(); ++j) {
3066 if (GetHtmlAttributes()[j].first == name) { 3138 if (GetOwner()->GetHtmlAttributes()[j].first == name) {
3067 attrib_values[i] = SysAllocString( 3139 attrib_values[i] = SysAllocString(
3068 base::UTF8ToUTF16(GetHtmlAttributes()[j].second).c_str()); 3140 base::UTF8ToUTF16(GetOwner()->GetHtmlAttributes()[j].second)
3141 .c_str());
3069 found = true; 3142 found = true;
3070 break; 3143 break;
3071 } 3144 }
3072 } 3145 }
3073 if (!found) { 3146 if (!found) {
3074 attrib_values[i] = NULL; 3147 attrib_values[i] = NULL;
3075 } 3148 }
3076 } 3149 }
3077 return S_OK; 3150 return S_OK;
3078 } 3151 }
3079 3152
3080 STDMETHODIMP BrowserAccessibilityWin::get_computedStyle( 3153 STDMETHODIMP BrowserAccessibilityComWin::get_computedStyle(
3081 unsigned short max_style_properties, 3154 unsigned short max_style_properties,
3082 boolean use_alternate_view, 3155 boolean use_alternate_view,
3083 BSTR* style_properties, 3156 BSTR* style_properties,
3084 BSTR* style_values, 3157 BSTR* style_values,
3085 unsigned short *num_style_properties) { 3158 unsigned short* num_style_properties) {
3086 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COMPUTED_STYLE); 3159 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COMPUTED_STYLE);
3087 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3160 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3088 if (!instance_active()) 3161 if (!GetOwner() || !GetOwner()->instance_active())
3089 return E_FAIL; 3162 return E_FAIL;
3090 3163
3091 if (!style_properties || !style_values) 3164 if (!style_properties || !style_values)
3092 return E_INVALIDARG; 3165 return E_INVALIDARG;
3093 3166
3094 // We only cache a single style property for now: DISPLAY 3167 // We only cache a single style property for now: DISPLAY
3095 3168
3096 base::string16 display; 3169 base::string16 display;
3097 if (max_style_properties == 0 || 3170 if (max_style_properties == 0 ||
3098 !GetString16Attribute(ui::AX_ATTR_DISPLAY, &display)) { 3171 !GetOwner()->GetString16Attribute(ui::AX_ATTR_DISPLAY, &display)) {
3099 *num_style_properties = 0; 3172 *num_style_properties = 0;
3100 return S_OK; 3173 return S_OK;
3101 } 3174 }
3102 3175
3103 *num_style_properties = 1; 3176 *num_style_properties = 1;
3104 style_properties[0] = SysAllocString(L"display"); 3177 style_properties[0] = SysAllocString(L"display");
3105 style_values[0] = SysAllocString(display.c_str()); 3178 style_values[0] = SysAllocString(display.c_str());
3106 3179
3107 return S_OK; 3180 return S_OK;
3108 } 3181 }
3109 3182
3110 STDMETHODIMP BrowserAccessibilityWin::get_computedStyleForProperties( 3183 STDMETHODIMP BrowserAccessibilityComWin::get_computedStyleForProperties(
3111 unsigned short num_style_properties, 3184 unsigned short num_style_properties,
3112 boolean use_alternate_view, 3185 boolean use_alternate_view,
3113 BSTR* style_properties, 3186 BSTR* style_properties,
3114 BSTR* style_values) { 3187 BSTR* style_values) {
3115 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COMPUTED_STYLE_FOR_PROPERTIES); 3188 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_COMPUTED_STYLE_FOR_PROPERTIES);
3116 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3189 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3117 if (!instance_active()) 3190 if (!GetOwner() || !GetOwner()->instance_active())
3118 return E_FAIL; 3191 return E_FAIL;
3119 3192
3120 if (!style_properties || !style_values) 3193 if (!style_properties || !style_values)
3121 return E_INVALIDARG; 3194 return E_INVALIDARG;
3122 3195
3123 // We only cache a single style property for now: DISPLAY 3196 // We only cache a single style property for now: DISPLAY
3124 3197
3125 for (unsigned short i = 0; i < num_style_properties; ++i) { 3198 for (unsigned short i = 0; i < num_style_properties; ++i) {
3126 base::string16 name = base::ToLowerASCII( 3199 base::string16 name = base::ToLowerASCII(
3127 reinterpret_cast<const base::char16*>(style_properties[i])); 3200 reinterpret_cast<const base::char16*>(style_properties[i]));
3128 if (name == L"display") { 3201 if (name == L"display") {
3129 base::string16 display = GetString16Attribute( 3202 base::string16 display =
3130 ui::AX_ATTR_DISPLAY); 3203 GetOwner()->GetString16Attribute(ui::AX_ATTR_DISPLAY);
3131 style_values[i] = SysAllocString(display.c_str()); 3204 style_values[i] = SysAllocString(display.c_str());
3132 } else { 3205 } else {
3133 style_values[i] = NULL; 3206 style_values[i] = NULL;
3134 } 3207 }
3135 } 3208 }
3136 3209
3137 return S_OK; 3210 return S_OK;
3138 } 3211 }
3139 3212
3140 STDMETHODIMP BrowserAccessibilityWin::scrollTo(boolean placeTopLeft) { 3213 STDMETHODIMP BrowserAccessibilityComWin::scrollTo(boolean placeTopLeft) {
3141 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ISIMPLEDOMNODE_SCROLL_TO); 3214 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ISIMPLEDOMNODE_SCROLL_TO);
3142 return scrollTo(placeTopLeft ? 3215 return scrollTo(placeTopLeft ? IA2_SCROLL_TYPE_TOP_LEFT
3143 IA2_SCROLL_TYPE_TOP_LEFT : IA2_SCROLL_TYPE_ANYWHERE); 3216 : IA2_SCROLL_TYPE_ANYWHERE);
3144 } 3217 }
3145 3218
3146 STDMETHODIMP BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode** node) { 3219 STDMETHODIMP BrowserAccessibilityComWin::get_parentNode(ISimpleDOMNode** node) {
3147 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PARENT_NODE); 3220 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PARENT_NODE);
3148 if (!instance_active()) 3221 if (!GetOwner() || !GetOwner()->instance_active())
3149 return E_FAIL; 3222 return E_FAIL;
3150 3223
3151 if (!node) 3224 if (!node)
3152 return E_INVALIDARG; 3225 return E_INVALIDARG;
3153 3226
3154 *node = ToBrowserAccessibilityWin(PlatformGetParent())->NewReference(); 3227 *node = ToBrowserAccessibilityComWin(GetOwner()->PlatformGetParent())
3228 ->NewReference();
3155 return S_OK; 3229 return S_OK;
3156 } 3230 }
3157 3231
3158 STDMETHODIMP BrowserAccessibilityWin::get_firstChild(ISimpleDOMNode** node) { 3232 STDMETHODIMP BrowserAccessibilityComWin::get_firstChild(ISimpleDOMNode** node) {
3159 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_FIRST_CHILD); 3233 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_FIRST_CHILD);
3160 if (!instance_active()) 3234 if (!GetOwner() || !GetOwner()->instance_active())
3161 return E_FAIL; 3235 return E_FAIL;
3162 3236
3163 if (!node) 3237 if (!node)
3164 return E_INVALIDARG; 3238 return E_INVALIDARG;
3165 3239
3166 if (PlatformChildCount() == 0) { 3240 if (GetOwner()->PlatformChildCount() == 0) {
3167 *node = NULL; 3241 *node = NULL;
3168 return S_FALSE; 3242 return S_FALSE;
3169 } 3243 }
3170 3244
3171 *node = ToBrowserAccessibilityWin(PlatformGetChild(0))->NewReference(); 3245 *node = ToBrowserAccessibilityComWin(GetOwner()->PlatformGetChild(0))
3246 ->NewReference();
3172 return S_OK; 3247 return S_OK;
3173 } 3248 }
3174 3249
3175 STDMETHODIMP BrowserAccessibilityWin::get_lastChild(ISimpleDOMNode** node) { 3250 STDMETHODIMP BrowserAccessibilityComWin::get_lastChild(ISimpleDOMNode** node) {
3176 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LAST_CHILD); 3251 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LAST_CHILD);
3177 if (!instance_active()) 3252 if (!GetOwner() || !GetOwner()->instance_active())
3178 return E_FAIL; 3253 return E_FAIL;
3179 3254
3180 if (!node) 3255 if (!node)
3181 return E_INVALIDARG; 3256 return E_INVALIDARG;
3182 3257
3183 if (PlatformChildCount() == 0) { 3258 if (GetOwner()->PlatformChildCount() == 0) {
3184 *node = NULL; 3259 *node = NULL;
3185 return S_FALSE; 3260 return S_FALSE;
3186 } 3261 }
3187 3262
3188 *node = ToBrowserAccessibilityWin( 3263 *node =
3189 PlatformGetChild(PlatformChildCount() - 1))->NewReference(); 3264 ToBrowserAccessibilityComWin(
3265 GetOwner()->PlatformGetChild(GetOwner()->PlatformChildCount() - 1))
3266 ->NewReference();
3190 return S_OK; 3267 return S_OK;
3191 } 3268 }
3192 3269
3193 STDMETHODIMP BrowserAccessibilityWin::get_previousSibling( 3270 STDMETHODIMP BrowserAccessibilityComWin::get_previousSibling(
3194 ISimpleDOMNode** node) { 3271 ISimpleDOMNode** node) {
3195 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PREVIOUS_SIBLING); 3272 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PREVIOUS_SIBLING);
3196 if (!instance_active()) 3273 if (!GetOwner() || !GetOwner()->instance_active())
3197 return E_FAIL; 3274 return E_FAIL;
3198 3275
3199 if (!node) 3276 if (!node)
3200 return E_INVALIDARG; 3277 return E_INVALIDARG;
3201 3278
3202 if (!PlatformGetParent() || GetIndexInParent() <= 0) { 3279 if (!GetOwner()->PlatformGetParent() || GetIndexInParent() <= 0) {
3203 *node = NULL; 3280 *node = NULL;
3204 return S_FALSE; 3281 return S_FALSE;
3205 } 3282 }
3206 3283
3207 *node = ToBrowserAccessibilityWin( 3284 *node = ToBrowserAccessibilityComWin(
3208 PlatformGetParent()->InternalGetChild(GetIndexInParent() - 1)) 3285 GetOwner()->PlatformGetParent()->InternalGetChild(
3286 GetIndexInParent() - 1))
3209 ->NewReference(); 3287 ->NewReference();
3210 return S_OK; 3288 return S_OK;
3211 } 3289 }
3212 3290
3213 STDMETHODIMP BrowserAccessibilityWin::get_nextSibling(ISimpleDOMNode** node) { 3291 STDMETHODIMP BrowserAccessibilityComWin::get_nextSibling(
3292 ISimpleDOMNode** node) {
3214 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NEXT_SIBLING); 3293 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NEXT_SIBLING);
3215 if (!instance_active()) 3294 if (!GetOwner() || !GetOwner()->instance_active())
3216 return E_FAIL; 3295 return E_FAIL;
3217 3296
3218 if (!node) 3297 if (!node)
3219 return E_INVALIDARG; 3298 return E_INVALIDARG;
3220 3299
3221 if (!PlatformGetParent() || GetIndexInParent() < 0 || 3300 if (!GetOwner()->PlatformGetParent() || GetIndexInParent() < 0 ||
3222 GetIndexInParent() >= 3301 GetIndexInParent() >=
3223 static_cast<int>(PlatformGetParent()->InternalChildCount()) - 1) { 3302 static_cast<int>(
3303 GetOwner()->PlatformGetParent()->InternalChildCount()) -
3304 1) {
3224 *node = NULL; 3305 *node = NULL;
3225 return S_FALSE; 3306 return S_FALSE;
3226 } 3307 }
3227 3308
3228 *node = ToBrowserAccessibilityWin( 3309 *node = ToBrowserAccessibilityComWin(
3229 PlatformGetParent()->InternalGetChild(GetIndexInParent() + 1)) 3310 GetOwner()->PlatformGetParent()->InternalGetChild(
3311 GetIndexInParent() + 1))
3230 ->NewReference(); 3312 ->NewReference();
3231 return S_OK; 3313 return S_OK;
3232 } 3314 }
3233 3315
3234 STDMETHODIMP BrowserAccessibilityWin::get_childAt( 3316 STDMETHODIMP BrowserAccessibilityComWin::get_childAt(unsigned int child_index,
3235 unsigned int child_index, 3317 ISimpleDOMNode** node) {
3236 ISimpleDOMNode** node) {
3237 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CHILD_AT); 3318 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CHILD_AT);
3238 if (!instance_active()) 3319 if (!GetOwner() || !GetOwner()->instance_active())
3239 return E_FAIL; 3320 return E_FAIL;
3240 3321
3241 if (!node) 3322 if (!node)
3242 return E_INVALIDARG; 3323 return E_INVALIDARG;
3243 3324
3244 if (child_index >= PlatformChildCount()) 3325 if (child_index >= GetOwner()->PlatformChildCount())
3245 return E_INVALIDARG; 3326 return E_INVALIDARG;
3246 3327
3247 BrowserAccessibility* child = PlatformGetChild(child_index); 3328 BrowserAccessibility* child = GetOwner()->PlatformGetChild(child_index);
3248 if (!child) { 3329 if (!child) {
3249 *node = NULL; 3330 *node = NULL;
3250 return S_FALSE; 3331 return S_FALSE;
3251 } 3332 }
3252 3333
3253 *node = ToBrowserAccessibilityWin(child)->NewReference(); 3334 *node = ToBrowserAccessibilityComWin(child)->NewReference();
3254 return S_OK; 3335 return S_OK;
3255 } 3336 }
3256 3337
3257 // We only support this method for retrieving MathML content. 3338 // We only support this method for retrieving MathML content.
3258 STDMETHODIMP BrowserAccessibilityWin::get_innerHTML(BSTR* innerHTML) { 3339 STDMETHODIMP BrowserAccessibilityComWin::get_innerHTML(BSTR* innerHTML) {
3259 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_INNER_HTML); 3340 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_INNER_HTML);
3260 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3341 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3261 if (GetRole() != ui::AX_ROLE_MATH) 3342 if (!GetOwner() || !GetOwner()->instance_active())
3343 return E_FAIL;
3344 if (GetOwner()->GetRole() != ui::AX_ROLE_MATH)
3262 return E_NOTIMPL; 3345 return E_NOTIMPL;
3263 if (!instance_active())
3264 return E_FAIL;
3265 3346
3266 base::string16 inner_html = GetString16Attribute(ui::AX_ATTR_INNER_HTML); 3347 base::string16 inner_html =
3348 GetOwner()->GetString16Attribute(ui::AX_ATTR_INNER_HTML);
3267 *innerHTML = SysAllocString(inner_html.c_str()); 3349 *innerHTML = SysAllocString(inner_html.c_str());
3268 DCHECK(*innerHTML); 3350 DCHECK(*innerHTML);
3269 return S_OK; 3351 return S_OK;
3270 } 3352 }
3271 3353
3272 STDMETHODIMP 3354 STDMETHODIMP
3273 BrowserAccessibilityWin::get_localInterface(void** local_interface) { 3355 BrowserAccessibilityComWin::get_localInterface(void** local_interface) {
3274 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCAL_INTERFACE); 3356 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCAL_INTERFACE);
3275 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3357 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3276 return E_NOTIMPL; 3358 return E_NOTIMPL;
3277 } 3359 }
3278 3360
3279 STDMETHODIMP BrowserAccessibilityWin::get_language(BSTR* language) { 3361 STDMETHODIMP BrowserAccessibilityComWin::get_language(BSTR* language) {
3280 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LANGUAGE); 3362 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LANGUAGE);
3281 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3363 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3282 if (!language) 3364 if (!language)
3283 return E_INVALIDARG; 3365 return E_INVALIDARG;
3284 *language = nullptr; 3366 *language = nullptr;
3285 3367
3286 if (!instance_active()) 3368 if (!GetOwner() || !GetOwner()->instance_active())
3287 return E_FAIL; 3369 return E_FAIL;
3288 3370
3289 base::string16 lang = GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE); 3371 base::string16 lang =
3372 GetOwner()->GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE);
3290 if (lang.empty()) 3373 if (lang.empty())
3291 lang = L"en-US"; 3374 lang = L"en-US";
3292 3375
3293 *language = SysAllocString(lang.c_str()); 3376 *language = SysAllocString(lang.c_str());
3294 DCHECK(*language); 3377 DCHECK(*language);
3295 return S_OK; 3378 return S_OK;
3296 } 3379 }
3297 3380
3298 // 3381 //
3299 // ISimpleDOMText methods. 3382 // ISimpleDOMText methods.
3300 // 3383 //
3301 3384
3302 STDMETHODIMP BrowserAccessibilityWin::get_domText(BSTR* dom_text) { 3385 STDMETHODIMP BrowserAccessibilityComWin::get_domText(BSTR* dom_text) {
3303 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_DOM_TEXT); 3386 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_DOM_TEXT);
3304 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3387 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3305 if (!instance_active()) 3388 if (!GetOwner() || !GetOwner()->instance_active())
3306 return E_FAIL; 3389 return E_FAIL;
3307 3390
3308 if (!dom_text) 3391 if (!dom_text)
3309 return E_INVALIDARG; 3392 return E_INVALIDARG;
3310 3393
3311 return GetStringAttributeAsBstr( 3394 return GetStringAttributeAsBstr(ui::AX_ATTR_NAME, dom_text);
3312 ui::AX_ATTR_NAME, dom_text);
3313 } 3395 }
3314 3396
3315 STDMETHODIMP BrowserAccessibilityWin::get_clippedSubstringBounds( 3397 STDMETHODIMP BrowserAccessibilityComWin::get_clippedSubstringBounds(
3316 unsigned int start_index, 3398 unsigned int start_index,
3317 unsigned int end_index, 3399 unsigned int end_index,
3318 int* out_x, 3400 int* out_x,
3319 int* out_y, 3401 int* out_y,
3320 int* out_width, 3402 int* out_width,
3321 int* out_height) { 3403 int* out_height) {
3322 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CLIPPED_SUBSTRING_BOUNDS); 3404 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CLIPPED_SUBSTRING_BOUNDS);
3323 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 3405 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
3324 AccessibilityMode::kInlineTextBoxes); 3406 AccessibilityMode::kInlineTextBoxes);
3325 // TODO(dmazzoni): fully support this API by intersecting the 3407 // TODO(dmazzoni): fully support this API by intersecting the
3326 // rect with the container's rect. 3408 // rect with the container's rect.
3327 return get_unclippedSubstringBounds( 3409 return get_unclippedSubstringBounds(start_index, end_index, out_x, out_y,
3328 start_index, end_index, out_x, out_y, out_width, out_height); 3410 out_width, out_height);
3329 } 3411 }
3330 3412
3331 STDMETHODIMP BrowserAccessibilityWin::get_unclippedSubstringBounds( 3413 STDMETHODIMP BrowserAccessibilityComWin::get_unclippedSubstringBounds(
3332 unsigned int start_index, 3414 unsigned int start_index,
3333 unsigned int end_index, 3415 unsigned int end_index,
3334 int* out_x, 3416 int* out_x,
3335 int* out_y, 3417 int* out_y,
3336 int* out_width, 3418 int* out_width,
3337 int* out_height) { 3419 int* out_height) {
3338 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNCLIPPED_SUBSTRING_BOUNDS); 3420 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNCLIPPED_SUBSTRING_BOUNDS);
3339 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 3421 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
3340 AccessibilityMode::kInlineTextBoxes); 3422 AccessibilityMode::kInlineTextBoxes);
3341 if (!instance_active()) 3423 if (!GetOwner() || !GetOwner()->instance_active())
3342 return E_FAIL; 3424 return E_FAIL;
3343 3425
3344 if (!out_x || !out_y || !out_width || !out_height) 3426 if (!out_x || !out_y || !out_width || !out_height)
3345 return E_INVALIDARG; 3427 return E_INVALIDARG;
3346 3428
3347 unsigned int text_length = static_cast<unsigned int>(GetText().size()); 3429 unsigned int text_length =
3430 static_cast<unsigned int>(GetOwner()->GetText().size());
3348 if (start_index > text_length || end_index > text_length || 3431 if (start_index > text_length || end_index > text_length ||
3349 start_index > end_index) { 3432 start_index > end_index) {
3350 return E_INVALIDARG; 3433 return E_INVALIDARG;
3351 } 3434 }
3352 3435
3353 gfx::Rect bounds = GetScreenBoundsForRange( 3436 gfx::Rect bounds =
3354 start_index, end_index - start_index); 3437 GetOwner()->GetScreenBoundsForRange(start_index, end_index - start_index);
3355 *out_x = bounds.x(); 3438 *out_x = bounds.x();
3356 *out_y = bounds.y(); 3439 *out_y = bounds.y();
3357 *out_width = bounds.width(); 3440 *out_width = bounds.width();
3358 *out_height = bounds.height(); 3441 *out_height = bounds.height();
3359 return S_OK; 3442 return S_OK;
3360 } 3443 }
3361 3444
3362 STDMETHODIMP BrowserAccessibilityWin::scrollToSubstring( 3445 STDMETHODIMP BrowserAccessibilityComWin::scrollToSubstring(
3363 unsigned int start_index, 3446 unsigned int start_index,
3364 unsigned int end_index) { 3447 unsigned int end_index) {
3365 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_TO_SUBSTRING); 3448 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_SCROLL_TO_SUBSTRING);
3366 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes | 3449 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes |
3367 AccessibilityMode::kInlineTextBoxes); 3450 AccessibilityMode::kInlineTextBoxes);
3368 if (!instance_active()) 3451 if (!GetOwner() || !GetOwner()->instance_active())
3369 return E_FAIL; 3452 return E_FAIL;
3370 3453
3371 unsigned int text_length = static_cast<unsigned int>(GetText().size()); 3454 auto* manager = GetOwner()->manager();
3455 if (!manager)
3456 return E_FAIL;
3457
3458 unsigned int text_length =
3459 static_cast<unsigned int>(GetOwner()->GetText().size());
3372 if (start_index > text_length || end_index > text_length || 3460 if (start_index > text_length || end_index > text_length ||
3373 start_index > end_index) { 3461 start_index > end_index) {
3374 return E_INVALIDARG; 3462 return E_INVALIDARG;
3375 } 3463 }
3376 3464
3377 manager_->ScrollToMakeVisible( 3465 manager->ScrollToMakeVisible(
3378 *this, GetPageBoundsForRange(start_index, end_index - start_index)); 3466 *GetOwner(),
3467 GetOwner()->GetPageBoundsForRange(start_index, end_index - start_index));
3379 3468
3380 return S_OK; 3469 return S_OK;
3381 } 3470 }
3382 3471
3383 STDMETHODIMP BrowserAccessibilityWin::get_fontFamily(BSTR* font_family) { 3472 STDMETHODIMP BrowserAccessibilityComWin::get_fontFamily(BSTR* font_family) {
3384 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_FONT_FAMILY); 3473 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_FONT_FAMILY);
3385 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 3474 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
3386 if (!font_family) 3475 if (!font_family)
3387 return E_INVALIDARG; 3476 return E_INVALIDARG;
3388 *font_family = nullptr; 3477 *font_family = nullptr;
3389 3478
3390 if (!instance_active()) 3479 if (!GetOwner() || !GetOwner()->instance_active())
3391 return E_FAIL; 3480 return E_FAIL;
3392 3481
3393 base::string16 family = 3482 base::string16 family =
3394 GetInheritedString16Attribute(ui::AX_ATTR_FONT_FAMILY); 3483 GetOwner()->GetInheritedString16Attribute(ui::AX_ATTR_FONT_FAMILY);
3395 if (family.empty()) 3484 if (family.empty())
3396 return S_FALSE; 3485 return S_FALSE;
3397 3486
3398 *font_family = SysAllocString(family.c_str()); 3487 *font_family = SysAllocString(family.c_str());
3399 DCHECK(*font_family); 3488 DCHECK(*font_family);
3400 return S_OK; 3489 return S_OK;
3401 } 3490 }
3402 3491
3403 // 3492 //
3404 // IServiceProvider methods. 3493 // IServiceProvider methods.
3405 // 3494 //
3406 3495
3407 STDMETHODIMP BrowserAccessibilityWin::QueryService(REFGUID guid_service, 3496 STDMETHODIMP BrowserAccessibilityComWin::QueryService(REFGUID guid_service,
3408 REFIID riid, 3497 REFIID riid,
3409 void** object) { 3498 void** object) {
3410 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_QUERY_SERVICE); 3499 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_QUERY_SERVICE);
3411 if (!instance_active()) 3500 if (!GetOwner() || !GetOwner()->instance_active())
3412 return E_FAIL; 3501 return E_FAIL;
3413 3502
3414 if (guid_service == GUID_IAccessibleContentDocument) { 3503 if (guid_service == GUID_IAccessibleContentDocument) {
3415 // Special Mozilla extension: return the accessible for the root document. 3504 // Special Mozilla extension: return the accessible for the root document.
3416 // Screen readers use this to distinguish between a document loaded event 3505 // Screen readers use this to distinguish between a document loaded event
3417 // on the root document vs on an iframe. 3506 // on the root document vs on an iframe.
3418 BrowserAccessibility* node = this; 3507 BrowserAccessibility* node = GetOwner();
3419 while (node->PlatformGetParent()) 3508 while (node->PlatformGetParent())
3420 node = node->PlatformGetParent()->manager()->GetRoot(); 3509 node = node->PlatformGetParent()->manager()->GetRoot();
3421 return ToBrowserAccessibilityWin(node)->QueryInterface( 3510 return ToBrowserAccessibilityComWin(node)->QueryInterface(IID_IAccessible2,
3422 IID_IAccessible2, object); 3511 object);
3423 } 3512 }
3424 3513
3425 if (guid_service == IID_IAccessible || 3514 if (guid_service == IID_IAccessible || guid_service == IID_IAccessible2 ||
3426 guid_service == IID_IAccessible2 ||
3427 guid_service == IID_IAccessibleAction || 3515 guid_service == IID_IAccessibleAction ||
3428 guid_service == IID_IAccessibleApplication || 3516 guid_service == IID_IAccessibleApplication ||
3429 guid_service == IID_IAccessibleHyperlink || 3517 guid_service == IID_IAccessibleHyperlink ||
3430 guid_service == IID_IAccessibleHypertext || 3518 guid_service == IID_IAccessibleHypertext ||
3431 guid_service == IID_IAccessibleImage || 3519 guid_service == IID_IAccessibleImage ||
3432 guid_service == IID_IAccessibleTable || 3520 guid_service == IID_IAccessibleTable ||
3433 guid_service == IID_IAccessibleTable2 || 3521 guid_service == IID_IAccessibleTable2 ||
3434 guid_service == IID_IAccessibleTableCell || 3522 guid_service == IID_IAccessibleTableCell ||
3435 guid_service == IID_IAccessibleText || 3523 guid_service == IID_IAccessibleText ||
3436 guid_service == IID_IAccessibleValue || 3524 guid_service == IID_IAccessibleValue ||
3437 guid_service == IID_ISimpleDOMDocument || 3525 guid_service == IID_ISimpleDOMDocument ||
3438 guid_service == IID_ISimpleDOMNode || 3526 guid_service == IID_ISimpleDOMNode ||
3439 guid_service == IID_ISimpleDOMText || 3527 guid_service == IID_ISimpleDOMText || guid_service == GUID_ISimpleDOM) {
3440 guid_service == GUID_ISimpleDOM) {
3441 return QueryInterface(riid, object); 3528 return QueryInterface(riid, object);
3442 } 3529 }
3443 3530
3444 // We only support the IAccessibleEx interface on Windows 8 and above. This 3531 // We only support the IAccessibleEx interface on Windows 8 and above. This
3445 // is needed for the on-screen Keyboard to show up in metro mode, when the 3532 // is needed for the on-screen Keyboard to show up in metro mode, when the
3446 // user taps an editable portion on the page. 3533 // user taps an editable portion on the page.
3447 // All methods in the IAccessibleEx interface are unimplemented. 3534 // All methods in the IAccessibleEx interface are unimplemented.
3448 if (riid == IID_IAccessibleEx && 3535 if (riid == IID_IAccessibleEx &&
3449 base::win::GetVersion() >= base::win::VERSION_WIN8) { 3536 base::win::GetVersion() >= base::win::VERSION_WIN8) {
3450 return QueryInterface(riid, object); 3537 return QueryInterface(riid, object);
3451 } 3538 }
3452 3539
3453 *object = NULL; 3540 *object = NULL;
3454 return E_FAIL; 3541 return E_FAIL;
3455 } 3542 }
3456 3543
3457 STDMETHODIMP 3544 STDMETHODIMP
3458 BrowserAccessibilityWin::GetObjectForChild(long child_id, IAccessibleEx** ret) { 3545 BrowserAccessibilityComWin::GetObjectForChild(long child_id,
3546 IAccessibleEx** ret) {
3459 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_OBJECT_FOR_CHILD); 3547 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_OBJECT_FOR_CHILD);
3460 return E_NOTIMPL; 3548 return E_NOTIMPL;
3461 } 3549 }
3462 3550
3463 STDMETHODIMP 3551 STDMETHODIMP
3464 BrowserAccessibilityWin::GetIAccessiblePair(IAccessible** acc, long* child_id) { 3552 BrowserAccessibilityComWin::GetIAccessiblePair(IAccessible** acc,
3553 long* child_id) {
3465 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IACCESSIBLE_PAIR); 3554 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_IACCESSIBLE_PAIR);
3466 return E_NOTIMPL; 3555 return E_NOTIMPL;
3467 } 3556 }
3468 3557
3469 STDMETHODIMP BrowserAccessibilityWin::GetRuntimeId(SAFEARRAY** runtime_id) { 3558 STDMETHODIMP BrowserAccessibilityComWin::GetRuntimeId(SAFEARRAY** runtime_id) {
3470 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_RUNTIME_ID); 3559 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_RUNTIME_ID);
3471 return E_NOTIMPL; 3560 return E_NOTIMPL;
3472 } 3561 }
3473 3562
3474 STDMETHODIMP 3563 STDMETHODIMP
3475 BrowserAccessibilityWin::ConvertReturnedElement( 3564 BrowserAccessibilityComWin::ConvertReturnedElement(
3476 IRawElementProviderSimple* element, 3565 IRawElementProviderSimple* element,
3477 IAccessibleEx** acc) { 3566 IAccessibleEx** acc) {
3478 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_CONVERT_RETURNED_ELEMENT); 3567 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_CONVERT_RETURNED_ELEMENT);
3479 return E_NOTIMPL; 3568 return E_NOTIMPL;
3480 } 3569 }
3481 3570
3482 STDMETHODIMP BrowserAccessibilityWin::GetPatternProvider(PATTERNID id, 3571 STDMETHODIMP BrowserAccessibilityComWin::GetPatternProvider(
3483 IUnknown** provider) { 3572 PATTERNID id,
3573 IUnknown** provider) {
3484 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PATTERN_PROVIDER); 3574 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PATTERN_PROVIDER);
3485 DVLOG(1) << "In Function: " << __func__ << " for pattern id: " << id; 3575 DVLOG(1) << "In Function: " << __func__ << " for pattern id: " << id;
3576 if (!GetOwner() || !GetOwner()->instance_active())
3577 return E_FAIL;
3578
3486 if (id == UIA_ValuePatternId || id == UIA_TextPatternId) { 3579 if (id == UIA_ValuePatternId || id == UIA_TextPatternId) {
3487 if (HasState(ui::AX_STATE_EDITABLE)) { 3580 if (GetOwner()->HasState(ui::AX_STATE_EDITABLE)) {
3488 DVLOG(1) << "Returning UIA text provider"; 3581 DVLOG(1) << "Returning UIA text provider";
3489 base::win::UIATextProvider::CreateTextProvider( 3582 base::win::UIATextProvider::CreateTextProvider(GetValueText(), true,
3490 GetValueText(), true, provider); 3583 provider);
3491 return S_OK; 3584 return S_OK;
3492 } 3585 }
3493 } 3586 }
3494 return E_NOTIMPL; 3587 return E_NOTIMPL;
3495 } 3588 }
3496 3589
3497 STDMETHODIMP BrowserAccessibilityWin::GetPropertyValue(PROPERTYID id, 3590 STDMETHODIMP BrowserAccessibilityComWin::GetPropertyValue(PROPERTYID id,
3498 VARIANT* ret) { 3591 VARIANT* ret) {
3499 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PROPERTY_VALUE); 3592 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PROPERTY_VALUE);
3500 DVLOG(1) << "In Function: " << __func__ << " for property id: " << id; 3593 DVLOG(1) << "In Function: " << __func__ << " for property id: " << id;
3594 if (!GetOwner() || !GetOwner()->instance_active())
3595 return E_FAIL;
3596
3501 V_VT(ret) = VT_EMPTY; 3597 V_VT(ret) = VT_EMPTY;
3502 if (id == UIA_ControlTypePropertyId) { 3598 if (id == UIA_ControlTypePropertyId) {
3503 if (HasState(ui::AX_STATE_EDITABLE)) { 3599 if (GetOwner()->HasState(ui::AX_STATE_EDITABLE)) {
3504 V_VT(ret) = VT_I4; 3600 V_VT(ret) = VT_I4;
3505 ret->lVal = UIA_EditControlTypeId; 3601 ret->lVal = UIA_EditControlTypeId;
3506 DVLOG(1) << "Returning Edit control type"; 3602 DVLOG(1) << "Returning Edit control type";
3507 } else { 3603 } else {
3508 DVLOG(1) << "Returning empty control type"; 3604 DVLOG(1) << "Returning empty control type";
3509 } 3605 }
3510 } 3606 }
3511 return S_OK; 3607 return S_OK;
3512 } 3608 }
3513 3609
3514 STDMETHODIMP BrowserAccessibilityWin::get_ProviderOptions( 3610 STDMETHODIMP BrowserAccessibilityComWin::get_ProviderOptions(
3515 ProviderOptions* ret) { 3611 ProviderOptions* ret) {
3516 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PROVIDER_OPTIONS); 3612 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PROVIDER_OPTIONS);
3517 return E_NOTIMPL; 3613 return E_NOTIMPL;
3518 } 3614 }
3519 3615
3520 STDMETHODIMP BrowserAccessibilityWin::get_HostRawElementProvider( 3616 STDMETHODIMP BrowserAccessibilityComWin::get_HostRawElementProvider(
3521 IRawElementProviderSimple** provider) { 3617 IRawElementProviderSimple** provider) {
3522 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_HOST_RAW_ELEMENT_PROVIDER); 3618 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_HOST_RAW_ELEMENT_PROVIDER);
3523 return E_NOTIMPL; 3619 return E_NOTIMPL;
3524 } 3620 }
3525 3621
3526 // 3622 //
3527 // CComObjectRootEx methods. 3623 // CComObjectRootEx methods.
3528 // 3624 //
3529 3625
3530 // static 3626 // static
3531 HRESULT WINAPI BrowserAccessibilityWin::InternalQueryInterface( 3627 HRESULT WINAPI BrowserAccessibilityComWin::InternalQueryInterface(
3532 void* this_ptr, 3628 void* this_ptr,
3533 const _ATL_INTMAP_ENTRY* entries, 3629 const _ATL_INTMAP_ENTRY* entries,
3534 REFIID iid, 3630 REFIID iid,
3535 void** object) { 3631 void** object) {
3536 BrowserAccessibilityWin* accessibility = 3632 BrowserAccessibilityComWin* accessibility =
3537 reinterpret_cast<BrowserAccessibilityWin*>(this_ptr); 3633 reinterpret_cast<BrowserAccessibilityComWin*>(this_ptr);
3538 int32_t ia_role = accessibility->ia_role(); 3634 int32_t ia_role = accessibility->ia_role();
3539 if (iid == IID_IAccessibleImage) { 3635 if (iid == IID_IAccessibleImage) {
3540 if (ia_role != ROLE_SYSTEM_GRAPHIC) { 3636 if (ia_role != ROLE_SYSTEM_GRAPHIC) {
3541 *object = NULL; 3637 *object = NULL;
3542 return E_NOINTERFACE; 3638 return E_NOINTERFACE;
3543 } 3639 }
3544 } else if (iid == IID_IAccessibleTable || iid == IID_IAccessibleTable2) { 3640 } else if (iid == IID_IAccessibleTable || iid == IID_IAccessibleTable2) {
3545 if (ia_role != ROLE_SYSTEM_TABLE) { 3641 if (ia_role != ROLE_SYSTEM_TABLE) {
3546 *object = NULL; 3642 *object = NULL;
3547 return E_NOINTERFACE; 3643 return E_NOINTERFACE;
3548 } 3644 }
3549 } else if (iid == IID_IAccessibleTableCell) { 3645 } else if (iid == IID_IAccessibleTableCell) {
3550 if (!accessibility->IsCellOrTableHeaderRole()) { 3646 if (!accessibility->GetOwner()->IsCellOrTableHeaderRole()) {
3551 *object = NULL; 3647 *object = NULL;
3552 return E_NOINTERFACE; 3648 return E_NOINTERFACE;
3553 } 3649 }
3554 } else if (iid == IID_IAccessibleValue) { 3650 } else if (iid == IID_IAccessibleValue) {
3555 if (ia_role != ROLE_SYSTEM_PROGRESSBAR && 3651 if (ia_role != ROLE_SYSTEM_PROGRESSBAR &&
3556 ia_role != ROLE_SYSTEM_SCROLLBAR && 3652 ia_role != ROLE_SYSTEM_SCROLLBAR && ia_role != ROLE_SYSTEM_SLIDER) {
3557 ia_role != ROLE_SYSTEM_SLIDER) {
3558 *object = NULL; 3653 *object = NULL;
3559 return E_NOINTERFACE; 3654 return E_NOINTERFACE;
3560 } 3655 }
3561 } else if (iid == IID_ISimpleDOMDocument) { 3656 } else if (iid == IID_ISimpleDOMDocument) {
3562 if (ia_role != ROLE_SYSTEM_DOCUMENT) { 3657 if (ia_role != ROLE_SYSTEM_DOCUMENT) {
3563 *object = NULL; 3658 *object = NULL;
3564 return E_NOINTERFACE; 3659 return E_NOINTERFACE;
3565 } 3660 }
3566 } else if (iid == IID_IAccessibleHyperlink) { 3661 } else if (iid == IID_IAccessibleHyperlink) {
3567 auto* ax_object = 3662 auto* ax_object =
3568 reinterpret_cast<const BrowserAccessibilityWin*>(this_ptr); 3663 reinterpret_cast<const BrowserAccessibilityComWin*>(this_ptr);
3569 if (!ax_object || !ax_object->IsHyperlink()) { 3664 if (!ax_object || !ax_object->IsHyperlink()) {
3570 *object = nullptr; 3665 *object = nullptr;
3571 return E_NOINTERFACE; 3666 return E_NOINTERFACE;
3572 } 3667 }
3573 } 3668 }
3574 3669
3575 return CComObjectRootBase::InternalQueryInterface( 3670 return CComObjectRootBase::InternalQueryInterface(this_ptr, entries, iid,
3576 this_ptr, entries, iid, object); 3671 object);
3577 } 3672 }
3578 3673
3579 void BrowserAccessibilityWin::ComputeStylesIfNeeded() { 3674 void BrowserAccessibilityComWin::ComputeStylesIfNeeded() {
3580 if (!offset_to_text_attributes().empty()) 3675 if (!offset_to_text_attributes().empty())
3581 return; 3676 return;
3582 3677
3583 std::map<int, std::vector<base::string16>> attributes_map; 3678 std::map<int, std::vector<base::string16>> attributes_map;
3584 if (PlatformIsLeaf() || IsSimpleTextControl()) { 3679 if (GetOwner()->PlatformIsLeaf() || GetOwner()->IsSimpleTextControl()) {
3585 attributes_map[0] = ComputeTextAttributes(); 3680 attributes_map[0] = ComputeTextAttributes();
3586 std::map<int, std::vector<base::string16>> spelling_attributes = 3681 std::map<int, std::vector<base::string16>> spelling_attributes =
3587 GetSpellingAttributes(); 3682 GetSpellingAttributes();
3588 for (auto& spelling_attribute : spelling_attributes) { 3683 for (auto& spelling_attribute : spelling_attributes) {
3589 auto attributes_iterator = attributes_map.find(spelling_attribute.first); 3684 auto attributes_iterator = attributes_map.find(spelling_attribute.first);
3590 if (attributes_iterator == attributes_map.end()) { 3685 if (attributes_iterator == attributes_map.end()) {
3591 attributes_map[spelling_attribute.first] = 3686 attributes_map[spelling_attribute.first] =
3592 std::move(spelling_attribute.second); 3687 std::move(spelling_attribute.second);
3593 } else { 3688 } else {
3594 std::vector<base::string16>& existing_attributes = 3689 std::vector<base::string16>& existing_attributes =
(...skipping 10 matching lines...) Expand all
3605 existing_attributes.insert(existing_attributes.end(), 3700 existing_attributes.insert(existing_attributes.end(),
3606 spelling_attribute.second.begin(), 3701 spelling_attribute.second.begin(),
3607 spelling_attribute.second.end()); 3702 spelling_attribute.second.end());
3608 } 3703 }
3609 } 3704 }
3610 win_attributes_->offset_to_text_attributes.swap(attributes_map); 3705 win_attributes_->offset_to_text_attributes.swap(attributes_map);
3611 return; 3706 return;
3612 } 3707 }
3613 3708
3614 int start_offset = 0; 3709 int start_offset = 0;
3615 for (size_t i = 0; i < PlatformChildCount(); ++i) { 3710 for (size_t i = 0; i < GetOwner()->PlatformChildCount(); ++i) {
3616 auto* child = ToBrowserAccessibilityWin(PlatformGetChild(i)); 3711 auto* child = ToBrowserAccessibilityComWin(GetOwner()->PlatformGetChild(i));
3617 DCHECK(child); 3712 DCHECK(child);
3618 std::vector<base::string16> attributes(child->ComputeTextAttributes()); 3713 std::vector<base::string16> attributes(child->ComputeTextAttributes());
3619 3714
3620 if (attributes_map.empty()) { 3715 if (attributes_map.empty()) {
3621 attributes_map[start_offset] = attributes; 3716 attributes_map[start_offset] = attributes;
3622 } else { 3717 } else {
3623 // Only add the attributes for this child if we are at the start of a new 3718 // Only add the attributes for this child if we are at the start of a new
3624 // style span. 3719 // style span.
3625 std::vector<base::string16> previous_attributes = 3720 std::vector<base::string16> previous_attributes =
3626 attributes_map.rbegin()->second; 3721 attributes_map.rbegin()->second;
3627 if (!std::equal(attributes.begin(), attributes.end(), 3722 if (!std::equal(attributes.begin(), attributes.end(),
3628 previous_attributes.begin())) { 3723 previous_attributes.begin())) {
3629 attributes_map[start_offset] = attributes; 3724 attributes_map[start_offset] = attributes;
3630 } 3725 }
3631 } 3726 }
3632 3727
3633 if (child->IsTextOnlyObject()) 3728 if (child->GetOwner()->IsTextOnlyObject())
3634 start_offset += child->GetText().length(); 3729 start_offset += child->GetOwner()->GetText().length();
3635 else 3730 else
3636 start_offset += 1; 3731 start_offset += 1;
3637 } 3732 }
3638 3733
3639 win_attributes_->offset_to_text_attributes.swap(attributes_map); 3734 win_attributes_->offset_to_text_attributes.swap(attributes_map);
3640 } 3735 }
3641 3736
3642 // |offset| could either be a text character or a child index in case of 3737 // |offset| could either be a text character or a child index in case of
3643 // non-text objects. 3738 // non-text objects.
3644 // TODO(nektar): Remove this function once selection bugs are fixed in Blink. 3739 // TODO(nektar): Remove this function once selection bugs are fixed in Blink.
3645 BrowserAccessibilityWin::AXPlatformPositionInstance 3740 AXPlatformPosition::AXPositionInstance
3646 BrowserAccessibilityWin::CreatePositionForSelectionAt(int offset) const { 3741 BrowserAccessibilityComWin::CreatePositionForSelectionAt(int offset) const {
3647 if (!IsNativeTextControl() && !IsTextOnlyObject()) { 3742 if (!GetOwner()->IsNativeTextControl() && !GetOwner()->IsTextOnlyObject()) {
3648 DCHECK(manager_); 3743 auto* manager = GetOwner()->manager();
3649 const BrowserAccessibilityWin* child = this; 3744 DCHECK(manager);
3745 const BrowserAccessibilityComWin* child = this;
3650 // TODO(nektar): Make parents of text-only objects not include the text of 3746 // TODO(nektar): Make parents of text-only objects not include the text of
3651 // children in their hypertext. 3747 // children in their hypertext.
3652 for (size_t i = 0; i < InternalChildCount(); ++i) { 3748 for (size_t i = 0; i < GetOwner()->InternalChildCount(); ++i) {
3653 int new_offset = offset; 3749 int new_offset = offset;
3654 child = ToBrowserAccessibilityWin(InternalGetChild(i)); 3750 child = ToBrowserAccessibilityComWin(GetOwner()->InternalGetChild(i));
3655 DCHECK(child); 3751 DCHECK(child);
3656 if (child->IsTextOnlyObject()) { 3752 if (child->GetOwner()->IsTextOnlyObject()) {
3657 new_offset -= child->GetText().length(); 3753 new_offset -= child->GetOwner()->GetText().length();
3658 } else { 3754 } else {
3659 new_offset -= 1; 3755 new_offset -= 1;
3660 } 3756 }
3661 if (new_offset <= 0) 3757 if (new_offset <= 0)
3662 break; 3758 break;
3663 offset = new_offset; 3759 offset = new_offset;
3664 } 3760 }
3665 AXPlatformPositionInstance position = 3761 AXPlatformPositionInstance position =
3666 AXPlatformPosition::CreateTextPosition(manager_->ax_tree_id(), 3762 AXPlatformPosition::CreateTextPosition(
3667 child->GetId(), offset, 3763 manager->ax_tree_id(), child->GetOwner()->GetId(), offset,
3668 ui::AX_TEXT_AFFINITY_DOWNSTREAM) 3764 ui::AX_TEXT_AFFINITY_DOWNSTREAM)
3669 ->AsLeafTextPosition(); 3765 ->AsLeafTextPosition();
3670 if (position->GetAnchor() && 3766 if (position->GetAnchor() &&
3671 position->GetAnchor()->GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX) { 3767 position->GetAnchor()->GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX) {
3672 return position->CreateParentPosition(); 3768 return position->CreateParentPosition();
3673 } 3769 }
3674 return position; 3770 return position;
3675 } 3771 }
3676 return CreatePositionAt(offset); 3772 return GetOwner()->CreatePositionAt(offset);
3677 }
3678
3679 base::string16 BrowserAccessibilityWin::GetText() const {
3680 if (PlatformIsChildOfLeaf())
3681 return BrowserAccessibility::GetText();
3682 return win_attributes_->hypertext;
3683 } 3773 }
3684 3774
3685 // 3775 //
3686 // Private methods. 3776 // Private methods.
3687 // 3777 //
3688 3778
3689 void BrowserAccessibilityWin::UpdateStep1ComputeWinAttributes() { 3779 void BrowserAccessibilityComWin::UpdateStep1ComputeWinAttributes() {
3690 // Swap win_attributes_ to old_win_attributes_, allowing us to see 3780 // Swap win_attributes_ to old_win_attributes_, allowing us to see
3691 // exactly what changed and fire appropriate events. Note that 3781 // exactly what changed and fire appropriate events. Note that
3692 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents. 3782 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents.
3693 old_win_attributes_.swap(win_attributes_); 3783 old_win_attributes_.swap(win_attributes_);
3694 win_attributes_.reset(new WinAttributes()); 3784 win_attributes_.reset(new WinAttributes());
3695 3785
3696 InitRoleAndState(); 3786 InitRoleAndState();
3697 3787
3698 win_attributes_->ia2_attributes.clear(); 3788 win_attributes_->ia2_attributes.clear();
3699 3789
(...skipping 22 matching lines...) Expand all
3722 win_attributes_->ia2_attributes.push_back(L"checkable:true"); 3812 win_attributes_->ia2_attributes.push_back(L"checkable:true");
3723 } 3813 }
3724 3814
3725 // Expose live region attributes. 3815 // Expose live region attributes.
3726 StringAttributeToIA2(ui::AX_ATTR_LIVE_STATUS, "live"); 3816 StringAttributeToIA2(ui::AX_ATTR_LIVE_STATUS, "live");
3727 StringAttributeToIA2(ui::AX_ATTR_LIVE_RELEVANT, "relevant"); 3817 StringAttributeToIA2(ui::AX_ATTR_LIVE_RELEVANT, "relevant");
3728 BoolAttributeToIA2(ui::AX_ATTR_LIVE_ATOMIC, "atomic"); 3818 BoolAttributeToIA2(ui::AX_ATTR_LIVE_ATOMIC, "atomic");
3729 BoolAttributeToIA2(ui::AX_ATTR_LIVE_BUSY, "busy"); 3819 BoolAttributeToIA2(ui::AX_ATTR_LIVE_BUSY, "busy");
3730 3820
3731 // Expose container live region attributes. 3821 // Expose container live region attributes.
3732 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_STATUS, 3822 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_STATUS, "container-live");
3733 "container-live");
3734 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_RELEVANT, 3823 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_RELEVANT,
3735 "container-relevant"); 3824 "container-relevant");
3736 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_ATOMIC, 3825 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_ATOMIC, "container-atomic");
3737 "container-atomic"); 3826 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_BUSY, "container-busy");
3738 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_BUSY,
3739 "container-busy");
3740 3827
3741 // Expose the non-standard explicit-name IA2 attribute. 3828 // Expose the non-standard explicit-name IA2 attribute.
3742 int name_from; 3829 int name_from;
3743 if (GetIntAttribute(ui::AX_ATTR_NAME_FROM, &name_from) && 3830 if (GetOwner()->GetIntAttribute(ui::AX_ATTR_NAME_FROM, &name_from) &&
3744 name_from != ui::AX_NAME_FROM_CONTENTS) { 3831 name_from != ui::AX_NAME_FROM_CONTENTS) {
3745 win_attributes_->ia2_attributes.push_back(L"explicit-name:true"); 3832 win_attributes_->ia2_attributes.push_back(L"explicit-name:true");
3746 } 3833 }
3747 3834
3748 // Expose the aria-current attribute. 3835 // Expose the aria-current attribute.
3749 int32_t aria_current_state; 3836 int32_t aria_current_state;
3750 if (GetIntAttribute(ui::AX_ATTR_ARIA_CURRENT_STATE, &aria_current_state)) { 3837 if (GetOwner()->GetIntAttribute(ui::AX_ATTR_ARIA_CURRENT_STATE,
3838 &aria_current_state)) {
3751 switch (static_cast<ui::AXAriaCurrentState>(aria_current_state)) { 3839 switch (static_cast<ui::AXAriaCurrentState>(aria_current_state)) {
3752 case ui::AX_ARIA_CURRENT_STATE_NONE: 3840 case ui::AX_ARIA_CURRENT_STATE_NONE:
3753 break; 3841 break;
3754 case ui::AX_ARIA_CURRENT_STATE_FALSE: 3842 case ui::AX_ARIA_CURRENT_STATE_FALSE:
3755 win_attributes_->ia2_attributes.push_back(L"current:false"); 3843 win_attributes_->ia2_attributes.push_back(L"current:false");
3756 break; 3844 break;
3757 case ui::AX_ARIA_CURRENT_STATE_TRUE: 3845 case ui::AX_ARIA_CURRENT_STATE_TRUE:
3758 win_attributes_->ia2_attributes.push_back(L"current:true"); 3846 win_attributes_->ia2_attributes.push_back(L"current:true");
3759 break; 3847 break;
3760 case ui::AX_ARIA_CURRENT_STATE_PAGE: 3848 case ui::AX_ARIA_CURRENT_STATE_PAGE:
3761 win_attributes_->ia2_attributes.push_back(L"current:page"); 3849 win_attributes_->ia2_attributes.push_back(L"current:page");
3762 break; 3850 break;
3763 case ui::AX_ARIA_CURRENT_STATE_STEP: 3851 case ui::AX_ARIA_CURRENT_STATE_STEP:
3764 win_attributes_->ia2_attributes.push_back(L"current:step"); 3852 win_attributes_->ia2_attributes.push_back(L"current:step");
3765 break; 3853 break;
3766 case ui::AX_ARIA_CURRENT_STATE_LOCATION: 3854 case ui::AX_ARIA_CURRENT_STATE_LOCATION:
3767 win_attributes_->ia2_attributes.push_back(L"current:location"); 3855 win_attributes_->ia2_attributes.push_back(L"current:location");
3768 break; 3856 break;
3769 case ui::AX_ARIA_CURRENT_STATE_DATE: 3857 case ui::AX_ARIA_CURRENT_STATE_DATE:
3770 win_attributes_->ia2_attributes.push_back(L"current:date"); 3858 win_attributes_->ia2_attributes.push_back(L"current:date");
3771 break; 3859 break;
3772 case ui::AX_ARIA_CURRENT_STATE_TIME: 3860 case ui::AX_ARIA_CURRENT_STATE_TIME:
3773 win_attributes_->ia2_attributes.push_back(L"current:time"); 3861 win_attributes_->ia2_attributes.push_back(L"current:time");
3774 break; 3862 break;
3775 } 3863 }
3776 } 3864 }
3777 3865
3778 // Expose table cell index. 3866 // Expose table cell index.
3779 if (IsCellOrTableHeaderRole()) { 3867 if (GetOwner()->IsCellOrTableHeaderRole()) {
3780 BrowserAccessibility* table = PlatformGetParent(); 3868 BrowserAccessibility* table = GetOwner()->PlatformGetParent();
3781 while (table && !table->IsTableLikeRole()) 3869 while (table && !table->IsTableLikeRole())
3782 table = table->PlatformGetParent(); 3870 table = table->PlatformGetParent();
3783 if (table) { 3871 if (table) {
3784 const std::vector<int32_t>& unique_cell_ids = 3872 const std::vector<int32_t>& unique_cell_ids =
3785 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); 3873 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS);
3786 for (size_t i = 0; i < unique_cell_ids.size(); ++i) { 3874 for (size_t i = 0; i < unique_cell_ids.size(); ++i) {
3787 if (unique_cell_ids[i] == GetId()) { 3875 if (unique_cell_ids[i] == GetOwner()->GetId()) {
3788 win_attributes_->ia2_attributes.push_back( 3876 win_attributes_->ia2_attributes.push_back(
3789 base::string16(L"table-cell-index:") + base::IntToString16(i)); 3877 base::string16(L"table-cell-index:") + base::IntToString16(i));
3790 } 3878 }
3791 } 3879 }
3792 } 3880 }
3793 } 3881 }
3794 3882
3795 // Expose aria-colcount and aria-rowcount in a table, grid or treegrid. 3883 // Expose aria-colcount and aria-rowcount in a table, grid or treegrid.
3796 if (IsTableLikeRole()) { 3884 if (GetOwner()->IsTableLikeRole()) {
3797 IntAttributeToIA2(ui::AX_ATTR_ARIA_COLUMN_COUNT, "colcount"); 3885 IntAttributeToIA2(ui::AX_ATTR_ARIA_COLUMN_COUNT, "colcount");
3798 IntAttributeToIA2(ui::AX_ATTR_ARIA_ROW_COUNT, "rowcount"); 3886 IntAttributeToIA2(ui::AX_ATTR_ARIA_ROW_COUNT, "rowcount");
3799 } 3887 }
3800 3888
3801 // Expose aria-colindex and aria-rowindex in a cell or row. 3889 // Expose aria-colindex and aria-rowindex in a cell or row.
3802 if (IsCellOrTableHeaderRole() || GetRole() == ui::AX_ROLE_ROW) { 3890 if (GetOwner()->IsCellOrTableHeaderRole() ||
3803 if (GetRole() != ui::AX_ROLE_ROW) 3891 GetOwner()->GetRole() == ui::AX_ROLE_ROW) {
3892 if (GetOwner()->GetRole() != ui::AX_ROLE_ROW)
3804 IntAttributeToIA2(ui::AX_ATTR_ARIA_CELL_COLUMN_INDEX, "colindex"); 3893 IntAttributeToIA2(ui::AX_ATTR_ARIA_CELL_COLUMN_INDEX, "colindex");
3805 IntAttributeToIA2(ui::AX_ATTR_ARIA_CELL_ROW_INDEX, "rowindex"); 3894 IntAttributeToIA2(ui::AX_ATTR_ARIA_CELL_ROW_INDEX, "rowindex");
3806 } 3895 }
3807 3896
3808 // Expose row or column header sort direction. 3897 // Expose row or column header sort direction.
3809 int32_t sort_direction; 3898 int32_t sort_direction;
3810 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER || 3899 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER ||
3811 ia_role() == ROLE_SYSTEM_ROWHEADER) && 3900 ia_role() == ROLE_SYSTEM_ROWHEADER) &&
3812 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION, &sort_direction)) { 3901 GetOwner()->GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION,
3902 &sort_direction)) {
3813 switch (static_cast<ui::AXSortDirection>(sort_direction)) { 3903 switch (static_cast<ui::AXSortDirection>(sort_direction)) {
3814 case ui::AX_SORT_DIRECTION_NONE: 3904 case ui::AX_SORT_DIRECTION_NONE:
3815 break; 3905 break;
3816 case ui::AX_SORT_DIRECTION_UNSORTED: 3906 case ui::AX_SORT_DIRECTION_UNSORTED:
3817 win_attributes_->ia2_attributes.push_back(L"sort:none"); 3907 win_attributes_->ia2_attributes.push_back(L"sort:none");
3818 break; 3908 break;
3819 case ui::AX_SORT_DIRECTION_ASCENDING: 3909 case ui::AX_SORT_DIRECTION_ASCENDING:
3820 win_attributes_->ia2_attributes.push_back(L"sort:ascending"); 3910 win_attributes_->ia2_attributes.push_back(L"sort:ascending");
3821 break; 3911 break;
3822 case ui::AX_SORT_DIRECTION_DESCENDING: 3912 case ui::AX_SORT_DIRECTION_DESCENDING:
3823 win_attributes_->ia2_attributes.push_back(L"sort:descending"); 3913 win_attributes_->ia2_attributes.push_back(L"sort:descending");
3824 break; 3914 break;
3825 case ui::AX_SORT_DIRECTION_OTHER: 3915 case ui::AX_SORT_DIRECTION_OTHER:
3826 win_attributes_->ia2_attributes.push_back(L"sort:other"); 3916 win_attributes_->ia2_attributes.push_back(L"sort:other");
3827 break; 3917 break;
3828 } 3918 }
3829 } 3919 }
3830 3920
3831 win_attributes_->name = GetString16Attribute(ui::AX_ATTR_NAME); 3921 win_attributes_->name = GetOwner()->GetString16Attribute(ui::AX_ATTR_NAME);
3832 win_attributes_->description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); 3922 win_attributes_->description =
3923 GetOwner()->GetString16Attribute(ui::AX_ATTR_DESCRIPTION);
3833 StringAttributeToIA2(ui::AX_ATTR_PLACEHOLDER, "placeholder"); 3924 StringAttributeToIA2(ui::AX_ATTR_PLACEHOLDER, "placeholder");
3834 3925
3835 base::string16 value = GetValue(); 3926 base::string16 value = GetOwner()->GetValue();
3836 // On Windows, the value of a document should be its url. 3927 // On Windows, the value of a document should be its url.
3837 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || 3928 if (GetOwner()->GetRole() == ui::AX_ROLE_ROOT_WEB_AREA ||
3838 GetRole() == ui::AX_ROLE_WEB_AREA) { 3929 GetOwner()->GetRole() == ui::AX_ROLE_WEB_AREA) {
3839 value = base::UTF8ToUTF16(manager_->GetTreeData().url); 3930 value = base::UTF8ToUTF16(GetOwner()->manager()->GetTreeData().url);
3840 } 3931 }
3841 // If this doesn't have a value and is linked then set its value to the url 3932 // If this doesn't have a value and is linked then set its value to the url
3842 // attribute. This allows screen readers to read an empty link's destination. 3933 // attribute. This allows screen readers to read an empty link's destination.
3843 if (value.empty() && (ia_state() & STATE_SYSTEM_LINKED)) 3934 if (value.empty() && (ia_state() & STATE_SYSTEM_LINKED))
3844 value = GetString16Attribute(ui::AX_ATTR_URL); 3935 value = GetOwner()->GetString16Attribute(ui::AX_ATTR_URL);
3845 win_attributes_->value = value; 3936 win_attributes_->value = value;
3846 3937
3847 ClearOwnRelations(); 3938 ClearOwnRelations();
3848 AddBidirectionalRelations(IA2_RELATION_CONTROLLER_FOR, 3939 AddBidirectionalRelations(IA2_RELATION_CONTROLLER_FOR,
3849 IA2_RELATION_CONTROLLED_BY, 3940 IA2_RELATION_CONTROLLED_BY,
3850 ui::AX_ATTR_CONTROLS_IDS); 3941 ui::AX_ATTR_CONTROLS_IDS);
3851 AddBidirectionalRelations(IA2_RELATION_DESCRIBED_BY, 3942 AddBidirectionalRelations(IA2_RELATION_DESCRIBED_BY,
3852 IA2_RELATION_DESCRIPTION_FOR, 3943 IA2_RELATION_DESCRIPTION_FOR,
3853 ui::AX_ATTR_DESCRIBEDBY_IDS); 3944 ui::AX_ATTR_DESCRIBEDBY_IDS);
3854 AddBidirectionalRelations(IA2_RELATION_FLOWS_TO, IA2_RELATION_FLOWS_FROM, 3945 AddBidirectionalRelations(IA2_RELATION_FLOWS_TO, IA2_RELATION_FLOWS_FROM,
3855 ui::AX_ATTR_FLOWTO_IDS); 3946 ui::AX_ATTR_FLOWTO_IDS);
3856 AddBidirectionalRelations(IA2_RELATION_LABELLED_BY, IA2_RELATION_LABEL_FOR, 3947 AddBidirectionalRelations(IA2_RELATION_LABELLED_BY, IA2_RELATION_LABEL_FOR,
3857 ui::AX_ATTR_LABELLEDBY_IDS); 3948 ui::AX_ATTR_LABELLEDBY_IDS);
3858 AddBidirectionalRelations(IA2_RELATION_DETAILS, IA2_RELATION_DETAILS_FOR, 3949 AddBidirectionalRelations(IA2_RELATION_DETAILS, IA2_RELATION_DETAILS_FOR,
3859 ui::AX_ATTR_DETAILS_IDS); 3950 ui::AX_ATTR_DETAILS_IDS);
3860 3951
3861 int member_of_id; 3952 int member_of_id;
3862 if (GetIntAttribute(ui::AX_ATTR_MEMBER_OF_ID, &member_of_id)) 3953 if (GetOwner()->GetIntAttribute(ui::AX_ATTR_MEMBER_OF_ID, &member_of_id))
3863 AddRelation(IA2_RELATION_MEMBER_OF, member_of_id); 3954 AddRelation(IA2_RELATION_MEMBER_OF, member_of_id);
3864 3955
3865 int error_message_id; 3956 int error_message_id;
3866 if (GetIntAttribute(ui::AX_ATTR_ERRORMESSAGE_ID, &error_message_id)) 3957 if (GetOwner()->GetIntAttribute(ui::AX_ATTR_ERRORMESSAGE_ID,
3958 &error_message_id))
3867 AddRelation(IA2_RELATION_ERROR_MESSAGE, error_message_id); 3959 AddRelation(IA2_RELATION_ERROR_MESSAGE, error_message_id);
3868 3960
3869 // Expose slider value. 3961 // Expose slider value.
3870 if (ia_role() == ROLE_SYSTEM_PROGRESSBAR || 3962 if (ia_role() == ROLE_SYSTEM_PROGRESSBAR ||
3871 ia_role() == ROLE_SYSTEM_SCROLLBAR || 3963 ia_role() == ROLE_SYSTEM_SCROLLBAR || ia_role() == ROLE_SYSTEM_SLIDER) {
3872 ia_role() == ROLE_SYSTEM_SLIDER) {
3873 base::string16 value_text = GetValueText(); 3964 base::string16 value_text = GetValueText();
3874 SanitizeStringAttributeForIA2(value_text, &value_text); 3965 SanitizeStringAttributeForIA2(value_text, &value_text);
3875 win_attributes_->ia2_attributes.push_back(L"valuetext:" + value_text); 3966 win_attributes_->ia2_attributes.push_back(L"valuetext:" + value_text);
3876 } 3967 }
3877 3968
3878 UpdateRequiredAttributes(); 3969 UpdateRequiredAttributes();
3879 // If this is a web area for a presentational iframe, give it a role of 3970 // If this is a web area for a presentational iframe, give it a role of
3880 // something other than DOCUMENT so that the fact that it's a separate doc 3971 // something other than DOCUMENT so that the fact that it's a separate doc
3881 // is not exposed to AT. 3972 // is not exposed to AT.
3882 if (IsWebAreaForPresentationalIframe()) { 3973 if (GetOwner()->IsWebAreaForPresentationalIframe()) {
3883 win_attributes_->ia_role = ROLE_SYSTEM_GROUPING; 3974 win_attributes_->ia_role = ROLE_SYSTEM_GROUPING;
3884 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING; 3975 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING;
3885 } 3976 }
3886 } 3977 }
3887 3978
3888 void BrowserAccessibilityWin::UpdateStep2ComputeHypertext() { 3979 void BrowserAccessibilityComWin::UpdateStep2ComputeHypertext() {
3889 if (IsSimpleTextControl()) { 3980 if (GetOwner()->IsSimpleTextControl()) {
3890 win_attributes_->hypertext = value(); 3981 win_attributes_->hypertext = value();
3891 return; 3982 return;
3892 } 3983 }
3893 3984
3894 if (!PlatformChildCount()) { 3985 if (!GetOwner()->PlatformChildCount()) {
3895 if (IsRichTextControl()) { 3986 if (GetOwner()->IsRichTextControl()) {
3896 // We don't want to expose any associated label in IA2 Hypertext. 3987 // We don't want to expose any associated label in IA2 Hypertext.
3897 return; 3988 return;
3898 } 3989 }
3899 win_attributes_->hypertext = name(); 3990 win_attributes_->hypertext = name();
3900 return; 3991 return;
3901 } 3992 }
3902 3993
3903 // Construct the hypertext for this node, which contains the concatenation 3994 // Construct the hypertext for this node, which contains the concatenation
3904 // of all of the static text and widespace of this node's children and an 3995 // of all of the static text and widespace of this node's children and an
3905 // embedded object character for all the other children. Build up a map from 3996 // embedded object character for all the other children. Build up a map from
3906 // the character index of each embedded object character to the id of the 3997 // the character index of each embedded object character to the id of the
3907 // child object it points to. 3998 // child object it points to.
3908 for (unsigned int i = 0; i < PlatformChildCount(); ++i) { 3999 for (unsigned int i = 0; i < GetOwner()->PlatformChildCount(); ++i) {
3909 auto* child = ToBrowserAccessibilityWin(PlatformGetChild(i)); 4000 auto* child = ToBrowserAccessibilityComWin(GetOwner()->PlatformGetChild(i));
3910 DCHECK(child); 4001 DCHECK(child);
3911 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext. 4002 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext.
3912 if (child->IsTextOnlyObject()) { 4003 if (child->GetOwner()->IsTextOnlyObject()) {
3913 win_attributes_->hypertext += child->name(); 4004 win_attributes_->hypertext += child->name();
3914 } else { 4005 } else {
3915 int32_t char_offset = static_cast<int32_t>(GetText().size()); 4006 int32_t char_offset = static_cast<int32_t>(GetOwner()->GetText().size());
3916 int32_t child_unique_id = child->unique_id(); 4007 int32_t child_unique_id = child->GetOwner()->unique_id();
3917 int32_t index = hyperlinks().size(); 4008 int32_t index = hyperlinks().size();
3918 win_attributes_->hyperlink_offset_to_index[char_offset] = index; 4009 win_attributes_->hyperlink_offset_to_index[char_offset] = index;
3919 win_attributes_->hyperlinks.push_back(child_unique_id); 4010 win_attributes_->hyperlinks.push_back(child_unique_id);
3920 win_attributes_->hypertext += kEmbeddedCharacter; 4011 win_attributes_->hypertext += kEmbeddedCharacter;
3921 } 4012 }
3922 } 4013 }
3923 } 4014 }
3924 4015
3925 void BrowserAccessibilityWin::UpdateStep3FireEvents(bool is_subtree_creation) { 4016 void BrowserAccessibilityComWin::UpdateStep3FireEvents(
4017 bool is_subtree_creation) {
3926 // Fire an event when a new subtree is created. 4018 // Fire an event when a new subtree is created.
3927 if (is_subtree_creation) 4019 if (is_subtree_creation)
3928 FireNativeEvent(EVENT_OBJECT_SHOW); 4020 FireNativeEvent(EVENT_OBJECT_SHOW);
3929 4021
3930 // The rest of the events only fire on changes, not on new objects. 4022 // The rest of the events only fire on changes, not on new objects.
3931 if (old_win_attributes_->ia_role != 0 || 4023 if (old_win_attributes_->ia_role != 0 ||
3932 !old_win_attributes_->role_name.empty()) { 4024 !old_win_attributes_->role_name.empty()) {
3933 // Fire an event if the name, description, help, or value changes. 4025 // Fire an event if the name, description, help, or value changes.
3934 if (name() != old_win_attributes_->name) 4026 if (name() != old_win_attributes_->name)
3935 FireNativeEvent(EVENT_OBJECT_NAMECHANGE); 4027 FireNativeEvent(EVENT_OBJECT_NAMECHANGE);
3936 if (description() != old_win_attributes_->description) 4028 if (description() != old_win_attributes_->description)
3937 FireNativeEvent(EVENT_OBJECT_DESCRIPTIONCHANGE); 4029 FireNativeEvent(EVENT_OBJECT_DESCRIPTIONCHANGE);
3938 if (value() != old_win_attributes_->value) 4030 if (value() != old_win_attributes_->value)
3939 FireNativeEvent(EVENT_OBJECT_VALUECHANGE); 4031 FireNativeEvent(EVENT_OBJECT_VALUECHANGE);
3940 if (ia_state() != old_win_attributes_->ia_state) 4032 if (ia_state() != old_win_attributes_->ia_state)
3941 FireNativeEvent(EVENT_OBJECT_STATECHANGE); 4033 FireNativeEvent(EVENT_OBJECT_STATECHANGE);
3942 4034
3943 // Handle selection being added or removed. 4035 // Handle selection being added or removed.
3944 bool is_selected_now = (ia_state() & STATE_SYSTEM_SELECTED) != 0; 4036 bool is_selected_now = (ia_state() & STATE_SYSTEM_SELECTED) != 0;
3945 bool was_selected_before = 4037 bool was_selected_before =
3946 (old_win_attributes_->ia_state & STATE_SYSTEM_SELECTED) != 0; 4038 (old_win_attributes_->ia_state & STATE_SYSTEM_SELECTED) != 0;
3947 if (is_selected_now || was_selected_before) { 4039 if (is_selected_now || was_selected_before) {
3948 bool multiselect = false; 4040 bool multiselect = false;
3949 if (PlatformGetParent() && 4041 if (GetOwner()->PlatformGetParent() &&
3950 PlatformGetParent()->HasState(ui::AX_STATE_MULTISELECTABLE)) 4042 GetOwner()->PlatformGetParent()->HasState(
4043 ui::AX_STATE_MULTISELECTABLE))
3951 multiselect = true; 4044 multiselect = true;
3952 4045
3953 if (multiselect) { 4046 if (multiselect) {
3954 // In a multi-select box, fire SELECTIONADD and SELECTIONREMOVE events. 4047 // In a multi-select box, fire SELECTIONADD and SELECTIONREMOVE events.
3955 if (is_selected_now && !was_selected_before) { 4048 if (is_selected_now && !was_selected_before) {
3956 FireNativeEvent(EVENT_OBJECT_SELECTIONADD); 4049 FireNativeEvent(EVENT_OBJECT_SELECTIONADD);
3957 } else if (!is_selected_now && was_selected_before) { 4050 } else if (!is_selected_now && was_selected_before) {
3958 FireNativeEvent(EVENT_OBJECT_SELECTIONREMOVE); 4051 FireNativeEvent(EVENT_OBJECT_SELECTIONREMOVE);
3959 } 4052 }
3960 } else if (is_selected_now && !was_selected_before) { 4053 } else if (is_selected_now && !was_selected_before) {
3961 // In a single-select box, only fire SELECTION events. 4054 // In a single-select box, only fire SELECTION events.
3962 FireNativeEvent(EVENT_OBJECT_SELECTION); 4055 FireNativeEvent(EVENT_OBJECT_SELECTION);
3963 } 4056 }
3964 } 4057 }
3965 4058
3966 // Fire an event if this container object has scrolled. 4059 // Fire an event if this container object has scrolled.
3967 int sx = 0; 4060 int sx = 0;
3968 int sy = 0; 4061 int sy = 0;
3969 if (GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && 4062 if (GetOwner()->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) &&
3970 GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { 4063 GetOwner()->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) {
3971 if (sx != previous_scroll_x_ || sy != previous_scroll_y_) 4064 if (sx != previous_scroll_x_ || sy != previous_scroll_y_)
3972 FireNativeEvent(EVENT_SYSTEM_SCROLLINGEND); 4065 FireNativeEvent(EVENT_SYSTEM_SCROLLINGEND);
3973 previous_scroll_x_ = sx; 4066 previous_scroll_x_ = sx;
3974 previous_scroll_y_ = sy; 4067 previous_scroll_y_ = sy;
3975 } 4068 }
3976 4069
3977 // Fire hypertext-related events. 4070 // Fire hypertext-related events.
3978 int start, old_len, new_len; 4071 int start, old_len, new_len;
3979 ComputeHypertextRemovedAndInserted(&start, &old_len, &new_len); 4072 ComputeHypertextRemovedAndInserted(&start, &old_len, &new_len);
3980 if (old_len > 0) { 4073 if (old_len > 0) {
3981 // In-process screen readers may call IAccessibleText::get_oldText 4074 // In-process screen readers may call IAccessibleText::get_oldText
3982 // in reaction to this event to retrieve the text that was removed. 4075 // in reaction to this event to retrieve the text that was removed.
3983 FireNativeEvent(IA2_EVENT_TEXT_REMOVED); 4076 FireNativeEvent(IA2_EVENT_TEXT_REMOVED);
3984 } 4077 }
3985 if (new_len > 0) { 4078 if (new_len > 0) {
3986 // In-process screen readers may call IAccessibleText::get_newText 4079 // In-process screen readers may call IAccessibleText::get_newText
3987 // in reaction to this event to retrieve the text that was inserted. 4080 // in reaction to this event to retrieve the text that was inserted.
3988 FireNativeEvent(IA2_EVENT_TEXT_INSERTED); 4081 FireNativeEvent(IA2_EVENT_TEXT_INSERTED);
3989 } 4082 }
3990 4083
3991 // Changing a static text node can affect the IAccessibleText hypertext 4084 // Changing a static text node can affect the IAccessibleText hypertext
3992 // of the parent node, so force an update on the parent. 4085 // of the parent node, so force an update on the parent.
3993 BrowserAccessibilityWin* parent = 4086 BrowserAccessibilityComWin* parent =
3994 ToBrowserAccessibilityWin(PlatformGetParent()); 4087 ToBrowserAccessibilityComWin(GetOwner()->PlatformGetParent());
3995 if (parent && IsTextOnlyObject() && 4088 if (parent && GetOwner()->IsTextOnlyObject() &&
3996 name() != old_win_attributes_->name) { 4089 name() != old_win_attributes_->name) {
3997 parent->UpdatePlatformAttributes(); 4090 parent->GetOwner()->UpdatePlatformAttributes();
3998 } 4091 }
3999 } 4092 }
4000 4093
4001 old_win_attributes_.reset(nullptr); 4094 old_win_attributes_.reset(nullptr);
4002 } 4095 }
4003 4096
4004 void BrowserAccessibilityWin::UpdatePlatformAttributes() { 4097 std::vector<base::string16> BrowserAccessibilityComWin::ComputeTextAttributes()
4005 UpdateStep1ComputeWinAttributes();
4006 UpdateStep2ComputeHypertext();
4007 UpdateStep3FireEvents(false);
4008 }
4009
4010 void BrowserAccessibilityWin::OnSubtreeWillBeDeleted() {
4011 FireNativeEvent(EVENT_OBJECT_HIDE);
4012 }
4013
4014 void BrowserAccessibilityWin::NativeAddReference() {
4015 AddRef();
4016 }
4017
4018 void BrowserAccessibilityWin::NativeReleaseReference() {
4019 Release();
4020 }
4021
4022 bool BrowserAccessibilityWin::IsNative() const {
4023 return true;
4024 }
4025
4026 void BrowserAccessibilityWin::OnLocationChanged() {
4027 FireNativeEvent(EVENT_OBJECT_LOCATIONCHANGE);
4028 }
4029
4030 std::vector<base::string16> BrowserAccessibilityWin::ComputeTextAttributes()
4031 const { 4098 const {
4032 std::vector<base::string16> attributes; 4099 std::vector<base::string16> attributes;
4033 4100
4034 // We include list markers for now, but there might be other objects that are 4101 // We include list markers for now, but there might be other objects that are
4035 // auto generated. 4102 // auto generated.
4036 // TODO(nektar): Compute what objects are auto-generated in Blink. 4103 // TODO(nektar): Compute what objects are auto-generated in Blink.
4037 if (GetRole() == ui::AX_ROLE_LIST_MARKER) 4104 if (GetOwner()->GetRole() == ui::AX_ROLE_LIST_MARKER)
4038 attributes.push_back(L"auto-generated:true"); 4105 attributes.push_back(L"auto-generated:true");
4039 else 4106 else
4040 attributes.push_back(L"auto-generated:false"); 4107 attributes.push_back(L"auto-generated:false");
4041 4108
4042 int color; 4109 int color;
4043 base::string16 color_value(L"transparent"); 4110 base::string16 color_value(L"transparent");
4044 if (GetIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR, &color)) { 4111 if (GetOwner()->GetIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR, &color)) {
4045 unsigned int alpha = SkColorGetA(color); 4112 unsigned int alpha = SkColorGetA(color);
4046 unsigned int red = SkColorGetR(color); 4113 unsigned int red = SkColorGetR(color);
4047 unsigned int green = SkColorGetG(color); 4114 unsigned int green = SkColorGetG(color);
4048 unsigned int blue = SkColorGetB(color); 4115 unsigned int blue = SkColorGetB(color);
4049 if (alpha) { 4116 if (alpha) {
4050 color_value = L"rgb(" + base::UintToString16(red) + L',' + 4117 color_value = L"rgb(" + base::UintToString16(red) + L',' +
4051 base::UintToString16(green) + L',' + 4118 base::UintToString16(green) + L',' +
4052 base::UintToString16(blue) + L')'; 4119 base::UintToString16(blue) + L')';
4053 } 4120 }
4054 } 4121 }
4055 SanitizeStringAttributeForIA2(color_value, &color_value); 4122 SanitizeStringAttributeForIA2(color_value, &color_value);
4056 attributes.push_back(L"background-color:" + color_value); 4123 attributes.push_back(L"background-color:" + color_value);
4057 4124
4058 if (GetIntAttribute(ui::AX_ATTR_COLOR, &color)) { 4125 if (GetOwner()->GetIntAttribute(ui::AX_ATTR_COLOR, &color)) {
4059 unsigned int red = SkColorGetR(color); 4126 unsigned int red = SkColorGetR(color);
4060 unsigned int green = SkColorGetG(color); 4127 unsigned int green = SkColorGetG(color);
4061 unsigned int blue = SkColorGetB(color); 4128 unsigned int blue = SkColorGetB(color);
4062 color_value = L"rgb(" + base::UintToString16(red) + L',' + 4129 color_value = L"rgb(" + base::UintToString16(red) + L',' +
4063 base::UintToString16(green) + L',' + 4130 base::UintToString16(green) + L',' +
4064 base::UintToString16(blue) + L')'; 4131 base::UintToString16(blue) + L')';
4065 } else { 4132 } else {
4066 color_value = L"rgb(0,0,0)"; 4133 color_value = L"rgb(0,0,0)";
4067 } 4134 }
4068 SanitizeStringAttributeForIA2(color_value, &color_value); 4135 SanitizeStringAttributeForIA2(color_value, &color_value);
4069 attributes.push_back(L"color:" + color_value); 4136 attributes.push_back(L"color:" + color_value);
4070 4137
4071 base::string16 font_family( 4138 base::string16 font_family(
4072 GetInheritedString16Attribute(ui::AX_ATTR_FONT_FAMILY)); 4139 GetOwner()->GetInheritedString16Attribute(ui::AX_ATTR_FONT_FAMILY));
4073 // Attribute has no default value. 4140 // Attribute has no default value.
4074 if (!font_family.empty()) { 4141 if (!font_family.empty()) {
4075 SanitizeStringAttributeForIA2(font_family, &font_family); 4142 SanitizeStringAttributeForIA2(font_family, &font_family);
4076 attributes.push_back(L"font-family:" + font_family); 4143 attributes.push_back(L"font-family:" + font_family);
4077 } 4144 }
4078 4145
4079 float font_size; 4146 float font_size;
4080 // Attribute has no default value. 4147 // Attribute has no default value.
4081 if (GetFloatAttribute(ui::AX_ATTR_FONT_SIZE, &font_size)) { 4148 if (GetFloatAttribute(ui::AX_ATTR_FONT_SIZE, &font_size)) {
4082 // The IA2 Spec requires the value to be in pt, not in pixels. 4149 // The IA2 Spec requires the value to be in pt, not in pixels.
4083 // There are 72 points per inch. 4150 // There are 72 points per inch.
4084 // We assume that there are 96 pixels per inch on a standard display. 4151 // We assume that there are 96 pixels per inch on a standard display.
4085 // TODO(nektar): Figure out the current value of pixels per inch. 4152 // TODO(nektar): Figure out the current value of pixels per inch.
4086 float points = font_size * 72.0 / 96.0; 4153 float points = font_size * 72.0 / 96.0;
4087 attributes.push_back(L"font-size:" + 4154 attributes.push_back(L"font-size:" +
4088 base::UTF8ToUTF16(base::DoubleToString(points)) + 4155 base::UTF8ToUTF16(base::DoubleToString(points)) +
4089 L"pt"); 4156 L"pt");
4090 } 4157 }
4091 4158
4092 auto text_style = 4159 auto text_style = static_cast<ui::AXTextStyle>(
4093 static_cast<ui::AXTextStyle>(GetIntAttribute(ui::AX_ATTR_TEXT_STYLE)); 4160 GetOwner()->GetIntAttribute(ui::AX_ATTR_TEXT_STYLE));
4094 if (text_style == ui::AX_TEXT_STYLE_NONE) { 4161 if (text_style == ui::AX_TEXT_STYLE_NONE) {
4095 attributes.push_back(L"font-style:normal"); 4162 attributes.push_back(L"font-style:normal");
4096 attributes.push_back(L"font-weight:normal"); 4163 attributes.push_back(L"font-weight:normal");
4097 } else { 4164 } else {
4098 if (text_style & ui::AX_TEXT_STYLE_ITALIC) { 4165 if (text_style & ui::AX_TEXT_STYLE_ITALIC) {
4099 attributes.push_back(L"font-style:italic"); 4166 attributes.push_back(L"font-style:italic");
4100 } else { 4167 } else {
4101 attributes.push_back(L"font-style:normal"); 4168 attributes.push_back(L"font-style:normal");
4102 } 4169 }
4103 4170
4104 if (text_style & ui::AX_TEXT_STYLE_BOLD) { 4171 if (text_style & ui::AX_TEXT_STYLE_BOLD) {
4105 attributes.push_back(L"font-weight:bold"); 4172 attributes.push_back(L"font-weight:bold");
4106 } else { 4173 } else {
4107 attributes.push_back(L"font-weight:normal"); 4174 attributes.push_back(L"font-weight:normal");
4108 } 4175 }
4109 } 4176 }
4110 4177
4111 auto invalid_state = static_cast<ui::AXInvalidState>( 4178 auto invalid_state = static_cast<ui::AXInvalidState>(
4112 GetIntAttribute(ui::AX_ATTR_INVALID_STATE)); 4179 GetOwner()->GetIntAttribute(ui::AX_ATTR_INVALID_STATE));
4113 switch (invalid_state) { 4180 switch (invalid_state) {
4114 case ui::AX_INVALID_STATE_NONE: 4181 case ui::AX_INVALID_STATE_NONE:
4115 case ui::AX_INVALID_STATE_FALSE: 4182 case ui::AX_INVALID_STATE_FALSE:
4116 attributes.push_back(L"invalid:false"); 4183 attributes.push_back(L"invalid:false");
4117 break; 4184 break;
4118 case ui::AX_INVALID_STATE_TRUE: 4185 case ui::AX_INVALID_STATE_TRUE:
4119 attributes.push_back(L"invalid:true"); 4186 attributes.push_back(L"invalid:true");
4120 break; 4187 break;
4121 case ui::AX_INVALID_STATE_SPELLING: 4188 case ui::AX_INVALID_STATE_SPELLING:
4122 case ui::AX_INVALID_STATE_GRAMMAR: { 4189 case ui::AX_INVALID_STATE_GRAMMAR: {
4123 base::string16 spelling_grammar_value; 4190 base::string16 spelling_grammar_value;
4124 if (invalid_state & ui::AX_INVALID_STATE_SPELLING) 4191 if (invalid_state & ui::AX_INVALID_STATE_SPELLING)
4125 spelling_grammar_value = L"spelling"; 4192 spelling_grammar_value = L"spelling";
4126 else if (invalid_state & ui::AX_INVALID_STATE_GRAMMAR) 4193 else if (invalid_state & ui::AX_INVALID_STATE_GRAMMAR)
4127 spelling_grammar_value = L"grammar"; 4194 spelling_grammar_value = L"grammar";
4128 else 4195 else
4129 spelling_grammar_value = L"spelling,grammar"; 4196 spelling_grammar_value = L"spelling,grammar";
4130 attributes.push_back(L"invalid:" + spelling_grammar_value); 4197 attributes.push_back(L"invalid:" + spelling_grammar_value);
4131 break; 4198 break;
4132 } 4199 }
4133 case ui::AX_INVALID_STATE_OTHER: { 4200 case ui::AX_INVALID_STATE_OTHER: {
4134 base::string16 aria_invalid_value; 4201 base::string16 aria_invalid_value;
4135 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE, 4202 if (GetOwner()->GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE,
4136 &aria_invalid_value)) { 4203 &aria_invalid_value)) {
4137 SanitizeStringAttributeForIA2(aria_invalid_value, &aria_invalid_value); 4204 SanitizeStringAttributeForIA2(aria_invalid_value, &aria_invalid_value);
4138 attributes.push_back(L"invalid:" + aria_invalid_value); 4205 attributes.push_back(L"invalid:" + aria_invalid_value);
4139 } else { 4206 } else {
4140 // Set the attribute to L"true", since we cannot be more specific. 4207 // Set the attribute to L"true", since we cannot be more specific.
4141 attributes.push_back(L"invalid:true"); 4208 attributes.push_back(L"invalid:true");
4142 } 4209 }
4143 break; 4210 break;
4144 } 4211 }
4145 } 4212 }
4146 4213
4147 base::string16 language(GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE)); 4214 base::string16 language(
4215 GetOwner()->GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE));
4148 // Default value should be L"en-US". 4216 // Default value should be L"en-US".
4149 if (language.empty()) { 4217 if (language.empty()) {
4150 attributes.push_back(L"language:en-US"); 4218 attributes.push_back(L"language:en-US");
4151 } else { 4219 } else {
4152 SanitizeStringAttributeForIA2(language, &language); 4220 SanitizeStringAttributeForIA2(language, &language);
4153 attributes.push_back(L"language:" + language); 4221 attributes.push_back(L"language:" + language);
4154 } 4222 }
4155 4223
4156 // TODO(nektar): Add Blink support for the following attributes. 4224 // TODO(nektar): Add Blink support for the following attributes.
4157 // Currently set to their default values as dictated by the IA2 Spec. 4225 // Currently set to their default values as dictated by the IA2 Spec.
(...skipping 21 matching lines...) Expand all
4179 // TODO(nektar): Figure out a more specific value. 4247 // TODO(nektar): Figure out a more specific value.
4180 attributes.push_back(L"text-underline-style:solid"); 4248 attributes.push_back(L"text-underline-style:solid");
4181 attributes.push_back(L"text-underline-type:single"); 4249 attributes.push_back(L"text-underline-type:single");
4182 } else { 4250 } else {
4183 attributes.push_back(L"text-underline-style:none"); 4251 attributes.push_back(L"text-underline-style:none");
4184 attributes.push_back(L"text-underline-type:none"); 4252 attributes.push_back(L"text-underline-type:none");
4185 } 4253 }
4186 attributes.push_back(L"text-underline-width:auto"); 4254 attributes.push_back(L"text-underline-width:auto");
4187 4255
4188 auto text_direction = static_cast<ui::AXTextDirection>( 4256 auto text_direction = static_cast<ui::AXTextDirection>(
4189 GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION)); 4257 GetOwner()->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION));
4190 switch (text_direction) { 4258 switch (text_direction) {
4191 case ui::AX_TEXT_DIRECTION_NONE: 4259 case ui::AX_TEXT_DIRECTION_NONE:
4192 case ui::AX_TEXT_DIRECTION_LTR: 4260 case ui::AX_TEXT_DIRECTION_LTR:
4193 attributes.push_back(L"writing-mode:lr"); 4261 attributes.push_back(L"writing-mode:lr");
4194 break; 4262 break;
4195 case ui::AX_TEXT_DIRECTION_RTL: 4263 case ui::AX_TEXT_DIRECTION_RTL:
4196 attributes.push_back(L"writing-mode:rl"); 4264 attributes.push_back(L"writing-mode:rl");
4197 break; 4265 break;
4198 case ui::AX_TEXT_DIRECTION_TTB: 4266 case ui::AX_TEXT_DIRECTION_TTB:
4199 attributes.push_back(L"writing-mode:tb"); 4267 attributes.push_back(L"writing-mode:tb");
4200 break; 4268 break;
4201 case ui::AX_TEXT_DIRECTION_BTT: 4269 case ui::AX_TEXT_DIRECTION_BTT:
4202 // Not listed in the IA2 Spec. 4270 // Not listed in the IA2 Spec.
4203 attributes.push_back(L"writing-mode:bt"); 4271 attributes.push_back(L"writing-mode:bt");
4204 break; 4272 break;
4205 } 4273 }
4206 4274
4207 return attributes; 4275 return attributes;
4208 } 4276 }
4209 4277
4210 BrowserAccessibilityWin* BrowserAccessibilityWin::NewReference() { 4278 BrowserAccessibilityComWin* BrowserAccessibilityComWin::NewReference() {
4211 AddRef(); 4279 AddRef();
4212 return this; 4280 return this;
4213 } 4281 }
4214 4282
4215 std::map<int, std::vector<base::string16>> 4283 std::map<int, std::vector<base::string16>>
4216 BrowserAccessibilityWin::GetSpellingAttributes() const { 4284 BrowserAccessibilityComWin::GetSpellingAttributes() {
4217 std::map<int, std::vector<base::string16>> spelling_attributes; 4285 std::map<int, std::vector<base::string16>> spelling_attributes;
4218 if (IsTextOnlyObject()) { 4286 if (GetOwner()->IsTextOnlyObject()) {
4219 const std::vector<int32_t>& marker_types = 4287 const std::vector<int32_t>& marker_types =
4220 GetIntListAttribute(ui::AX_ATTR_MARKER_TYPES); 4288 GetOwner()->GetIntListAttribute(ui::AX_ATTR_MARKER_TYPES);
4221 const std::vector<int>& marker_starts = 4289 const std::vector<int>& marker_starts =
4222 GetIntListAttribute(ui::AX_ATTR_MARKER_STARTS); 4290 GetOwner()->GetIntListAttribute(ui::AX_ATTR_MARKER_STARTS);
4223 const std::vector<int>& marker_ends = 4291 const std::vector<int>& marker_ends =
4224 GetIntListAttribute(ui::AX_ATTR_MARKER_ENDS); 4292 GetOwner()->GetIntListAttribute(ui::AX_ATTR_MARKER_ENDS);
4225 for (size_t i = 0; i < marker_types.size(); ++i) { 4293 for (size_t i = 0; i < marker_types.size(); ++i) {
4226 if (!(static_cast<ui::AXMarkerType>(marker_types[i]) & 4294 if (!(static_cast<ui::AXMarkerType>(marker_types[i]) &
4227 ui::AX_MARKER_TYPE_SPELLING)) 4295 ui::AX_MARKER_TYPE_SPELLING))
4228 continue; 4296 continue;
4229 int start_offset = marker_starts[i]; 4297 int start_offset = marker_starts[i];
4230 int end_offset = marker_ends[i]; 4298 int end_offset = marker_ends[i];
4231 std::vector<base::string16> start_attributes; 4299 std::vector<base::string16> start_attributes;
4232 start_attributes.push_back(L"invalid:spelling"); 4300 start_attributes.push_back(L"invalid:spelling");
4233 std::vector<base::string16> end_attributes; 4301 std::vector<base::string16> end_attributes;
4234 end_attributes.push_back(L"invalid:false"); 4302 end_attributes.push_back(L"invalid:false");
4235 spelling_attributes[start_offset] = start_attributes; 4303 spelling_attributes[start_offset] = start_attributes;
4236 spelling_attributes[end_offset] = end_attributes; 4304 spelling_attributes[end_offset] = end_attributes;
4237 } 4305 }
4238 } 4306 }
4239 if (IsSimpleTextControl()) { 4307 if (GetOwner()->IsSimpleTextControl()) {
4240 int start_offset = 0; 4308 int start_offset = 0;
4241 for (const BrowserAccessibility* static_text = 4309 for (BrowserAccessibility* static_text =
4242 BrowserAccessibilityManager::NextTextOnlyObject( 4310 BrowserAccessibilityManager::NextTextOnlyObject(
4243 InternalGetChild(0)); 4311 GetOwner()->InternalGetChild(0));
4244 static_text; static_text = static_text->GetNextSibling()) { 4312 static_text; static_text = static_text->GetNextSibling()) {
4245 auto* text_win = ToBrowserAccessibilityWin(static_text); 4313 auto* text_win = ToBrowserAccessibilityComWin(static_text);
4246 if (text_win) { 4314 if (text_win) {
4247 std::map<int, std::vector<base::string16>> text_spelling_attributes = 4315 std::map<int, std::vector<base::string16>> text_spelling_attributes =
4248 text_win->GetSpellingAttributes(); 4316 text_win->GetSpellingAttributes();
4249 for (auto& attribute : text_spelling_attributes) { 4317 for (auto& attribute : text_spelling_attributes) {
4250 spelling_attributes[start_offset + attribute.first] = 4318 spelling_attributes[start_offset + attribute.first] =
4251 std::move(attribute.second); 4319 std::move(attribute.second);
4252 } 4320 }
4253 start_offset += static_cast<int>(text_win->GetText().length()); 4321 start_offset +=
4322 static_cast<int>(text_win->GetOwner()->GetText().length());
4254 } 4323 }
4255 } 4324 }
4256 } 4325 }
4257 return spelling_attributes; 4326 return spelling_attributes;
4258 } 4327 }
4259 4328
4260 BrowserAccessibilityWin* BrowserAccessibilityWin::GetTargetFromChildID( 4329 BrowserAccessibilityComWin* BrowserAccessibilityComWin::GetTargetFromChildID(
4261 const VARIANT& var_id) { 4330 const VARIANT& var_id) {
4331 if (!GetOwner() || !GetOwner()->instance_active())
4332 return nullptr;
4333
4262 if (var_id.vt != VT_I4) 4334 if (var_id.vt != VT_I4)
4263 return nullptr; 4335 return nullptr;
4264 4336
4265 LONG child_id = var_id.lVal; 4337 LONG child_id = var_id.lVal;
4266 if (child_id == CHILDID_SELF) 4338 if (child_id == CHILDID_SELF)
4267 return this; 4339 return this;
4268 4340
4269 if (child_id >= 1 && child_id <= static_cast<LONG>(PlatformChildCount())) 4341 if (child_id >= 1 &&
4270 return ToBrowserAccessibilityWin(PlatformGetChild(child_id - 1)); 4342 child_id <= static_cast<LONG>(GetOwner()->PlatformChildCount()))
4343 return ToBrowserAccessibilityComWin(
4344 GetOwner()->PlatformGetChild(child_id - 1));
4271 4345
4272 BrowserAccessibilityWin* child = ToBrowserAccessibilityWin( 4346 BrowserAccessibilityComWin* child = ToBrowserAccessibilityComWin(
4273 BrowserAccessibility::GetFromUniqueID(-child_id)); 4347 BrowserAccessibility::GetFromUniqueID(-child_id));
4274 if (child && child->IsDescendantOf(this)) 4348 if (child && child->GetOwner()->IsDescendantOf(GetOwner()))
4275 return child; 4349 return child;
4276 4350
4277 return nullptr; 4351 return nullptr;
4278 } 4352 }
4279 4353
4280 HRESULT BrowserAccessibilityWin::GetStringAttributeAsBstr( 4354 HRESULT BrowserAccessibilityComWin::GetStringAttributeAsBstr(
4281 ui::AXStringAttribute attribute, 4355 ui::AXStringAttribute attribute,
4282 BSTR* value_bstr) { 4356 BSTR* value_bstr) {
4283 base::string16 str; 4357 base::string16 str;
4358 if (!GetOwner() || !GetOwner()->instance_active())
4359 return E_FAIL;
4284 4360
4285 if (!GetString16Attribute(attribute, &str)) 4361 if (!GetOwner()->GetString16Attribute(attribute, &str))
4286 return S_FALSE; 4362 return S_FALSE;
4287 4363
4288 *value_bstr = SysAllocString(str.c_str()); 4364 *value_bstr = SysAllocString(str.c_str());
4289 DCHECK(*value_bstr); 4365 DCHECK(*value_bstr);
4290 4366
4291 return S_OK; 4367 return S_OK;
4292 } 4368 }
4293 4369
4294 // Static 4370 // Static
4295 void BrowserAccessibilityWin::SanitizeStringAttributeForIA2( 4371 void BrowserAccessibilityComWin::SanitizeStringAttributeForIA2(
4296 const base::string16& input, 4372 const base::string16& input,
4297 base::string16* output) { 4373 base::string16* output) {
4298 DCHECK(output); 4374 DCHECK(output);
4299 // According to the IA2 Spec, these characters need to be escaped with a 4375 // According to the IA2 Spec, these characters need to be escaped with a
4300 // backslash: backslash, colon, comma, equals and semicolon. 4376 // backslash: backslash, colon, comma, equals and semicolon.
4301 // Note that backslash must be replaced first. 4377 // Note that backslash must be replaced first.
4302 base::ReplaceChars(input, L"\\", L"\\\\", output); 4378 base::ReplaceChars(input, L"\\", L"\\\\", output);
4303 base::ReplaceChars(*output, L":", L"\\:", output); 4379 base::ReplaceChars(*output, L":", L"\\:", output);
4304 base::ReplaceChars(*output, L",", L"\\,", output); 4380 base::ReplaceChars(*output, L",", L"\\,", output);
4305 base::ReplaceChars(*output, L"=", L"\\=", output); 4381 base::ReplaceChars(*output, L"=", L"\\=", output);
4306 base::ReplaceChars(*output, L";", L"\\;", output); 4382 base::ReplaceChars(*output, L";", L"\\;", output);
4307 } 4383 }
4308 4384
4309 void BrowserAccessibilityWin::SetIA2HypertextSelection(LONG start_offset, 4385 void BrowserAccessibilityComWin::SetIA2HypertextSelection(LONG start_offset,
4310 LONG end_offset) { 4386 LONG end_offset) {
4311 HandleSpecialTextOffset(&start_offset); 4387 HandleSpecialTextOffset(&start_offset);
4312 HandleSpecialTextOffset(&end_offset); 4388 HandleSpecialTextOffset(&end_offset);
4313 AXPlatformPositionInstance start_position = 4389 AXPlatformPositionInstance start_position =
4314 CreatePositionForSelectionAt(static_cast<int>(start_offset)); 4390 CreatePositionForSelectionAt(static_cast<int>(start_offset));
4315 AXPlatformPositionInstance end_position = 4391 AXPlatformPositionInstance end_position =
4316 CreatePositionForSelectionAt(static_cast<int>(end_offset)); 4392 CreatePositionForSelectionAt(static_cast<int>(end_offset));
4317 manager_->SetSelection(AXPlatformRange(start_position->AsTextPosition(), 4393 GetOwner()->manager()->SetSelection(AXPlatformRange(
4318 end_position->AsTextPosition())); 4394 start_position->AsTextPosition(), end_position->AsTextPosition()));
4319 } 4395 }
4320 4396
4321 void BrowserAccessibilityWin::StringAttributeToIA2( 4397 void BrowserAccessibilityComWin::StringAttributeToIA2(
4322 ui::AXStringAttribute attribute, 4398 ui::AXStringAttribute attribute,
4323 const char* ia2_attr) { 4399 const char* ia2_attr) {
4324 base::string16 value; 4400 base::string16 value;
4325 if (GetString16Attribute(attribute, &value)) { 4401 if (GetOwner()->GetString16Attribute(attribute, &value)) {
4326 SanitizeStringAttributeForIA2(value, &value); 4402 SanitizeStringAttributeForIA2(value, &value);
4327 win_attributes_->ia2_attributes.push_back( 4403 win_attributes_->ia2_attributes.push_back(base::ASCIIToUTF16(ia2_attr) +
4328 base::ASCIIToUTF16(ia2_attr) + L":" + value); 4404 L":" + value);
4329 } 4405 }
4330 } 4406 }
4331 4407
4332 void BrowserAccessibilityWin::BoolAttributeToIA2( 4408 void BrowserAccessibilityComWin::BoolAttributeToIA2(
4333 ui::AXBoolAttribute attribute, 4409 ui::AXBoolAttribute attribute,
4334 const char* ia2_attr) { 4410 const char* ia2_attr) {
4335 bool value; 4411 bool value;
4336 if (GetBoolAttribute(attribute, &value)) { 4412 if (GetOwner()->GetBoolAttribute(attribute, &value)) {
4337 win_attributes_->ia2_attributes.push_back( 4413 win_attributes_->ia2_attributes.push_back(
4338 (base::ASCIIToUTF16(ia2_attr) + L":") + 4414 (base::ASCIIToUTF16(ia2_attr) + L":") + (value ? L"true" : L"false"));
4339 (value ? L"true" : L"false"));
4340 } 4415 }
4341 } 4416 }
4342 4417
4343 void BrowserAccessibilityWin::IntAttributeToIA2( 4418 void BrowserAccessibilityComWin::IntAttributeToIA2(ui::AXIntAttribute attribute,
4344 ui::AXIntAttribute attribute, 4419 const char* ia2_attr) {
4345 const char* ia2_attr) {
4346 int value; 4420 int value;
4347 if (GetIntAttribute(attribute, &value)) { 4421 if (GetOwner()->GetIntAttribute(attribute, &value)) {
4348 win_attributes_->ia2_attributes.push_back( 4422 win_attributes_->ia2_attributes.push_back(
4349 base::ASCIIToUTF16(ia2_attr) + L":" + 4423 base::ASCIIToUTF16(ia2_attr) + L":" + base::IntToString16(value));
4350 base::IntToString16(value));
4351 } 4424 }
4352 } 4425 }
4353 4426
4354 bool BrowserAccessibilityWin::IsHyperlink() const { 4427 bool BrowserAccessibilityComWin::IsHyperlink() const {
4355 int32_t hyperlink_index = -1; 4428 int32_t hyperlink_index = -1;
4356 auto* parent = PlatformGetParent(); 4429 auto* parent = GetOwner()->PlatformGetParent();
4357 if (parent) { 4430 if (parent) {
4358 hyperlink_index = 4431 hyperlink_index =
4359 ToBrowserAccessibilityWin(parent)->GetHyperlinkIndexFromChild(*this); 4432 ToBrowserAccessibilityComWin(parent)->GetHyperlinkIndexFromChild(*this);
4360 } 4433 }
4361 4434
4362 if (hyperlink_index >= 0) 4435 if (hyperlink_index >= 0)
4363 return true; 4436 return true;
4364 return false; 4437 return false;
4365 } 4438 }
4366 4439
4367 BrowserAccessibilityWin* 4440 BrowserAccessibilityComWin*
4368 BrowserAccessibilityWin::GetHyperlinkFromHypertextOffset(int offset) const { 4441 BrowserAccessibilityComWin::GetHyperlinkFromHypertextOffset(int offset) const {
4369 std::map<int32_t, int32_t>::iterator iterator = 4442 std::map<int32_t, int32_t>::iterator iterator =
4370 hyperlink_offset_to_index().find(offset); 4443 hyperlink_offset_to_index().find(offset);
4371 if (iterator == hyperlink_offset_to_index().end()) 4444 if (iterator == hyperlink_offset_to_index().end())
4372 return nullptr; 4445 return nullptr;
4373 4446
4374 int32_t index = iterator->second; 4447 int32_t index = iterator->second;
4375 DCHECK_GE(index, 0); 4448 DCHECK_GE(index, 0);
4376 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size())); 4449 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size()));
4377 int32_t id = hyperlinks()[index]; 4450 int32_t id = hyperlinks()[index];
4378 BrowserAccessibilityWin* hyperlink = 4451 BrowserAccessibilityComWin* hyperlink =
4379 ToBrowserAccessibilityWin(GetFromUniqueID(id)); 4452 ToBrowserAccessibilityComWin(GetOwner()->GetFromUniqueID(id));
4380 if (!hyperlink) 4453 if (!hyperlink)
4381 return nullptr; 4454 return nullptr;
4382 return hyperlink; 4455 return hyperlink;
4383 } 4456 }
4384 4457
4385 int32_t BrowserAccessibilityWin::GetHyperlinkIndexFromChild( 4458 int32_t BrowserAccessibilityComWin::GetHyperlinkIndexFromChild(
4386 const BrowserAccessibilityWin& child) const { 4459 const BrowserAccessibilityComWin& child) const {
4387 if (hyperlinks().empty()) 4460 if (hyperlinks().empty())
4388 return -1; 4461 return -1;
4389 4462
4390 auto iterator = 4463 auto iterator = std::find(hyperlinks().begin(), hyperlinks().end(),
4391 std::find(hyperlinks().begin(), hyperlinks().end(), child.unique_id()); 4464 child.GetOwner()->unique_id());
4392 if (iterator == hyperlinks().end()) 4465 if (iterator == hyperlinks().end())
4393 return -1; 4466 return -1;
4394 4467
4395 return static_cast<int32_t>(iterator - hyperlinks().begin()); 4468 return static_cast<int32_t>(iterator - hyperlinks().begin());
4396 } 4469 }
4397 4470
4398 int32_t BrowserAccessibilityWin::GetHypertextOffsetFromHyperlinkIndex( 4471 int32_t BrowserAccessibilityComWin::GetHypertextOffsetFromHyperlinkIndex(
4399 int32_t hyperlink_index) const { 4472 int32_t hyperlink_index) const {
4400 for (auto& offset_index : hyperlink_offset_to_index()) { 4473 for (auto& offset_index : hyperlink_offset_to_index()) {
4401 if (offset_index.second == hyperlink_index) 4474 if (offset_index.second == hyperlink_index)
4402 return offset_index.first; 4475 return offset_index.first;
4403 } 4476 }
4404 4477
4405 return -1; 4478 return -1;
4406 } 4479 }
4407 4480
4408 int32_t BrowserAccessibilityWin::GetHypertextOffsetFromChild( 4481 int32_t BrowserAccessibilityComWin::GetHypertextOffsetFromChild(
4409 const BrowserAccessibilityWin& child) const { 4482 BrowserAccessibilityComWin& child) {
4410 DCHECK(child.PlatformGetParent() == this); 4483 DCHECK(child.GetOwner()->PlatformGetParent() == GetOwner());
4411 4484
4412 // Handle the case when we are dealing with a direct text-only child. 4485 // Handle the case when we are dealing with a direct text-only child.
4413 // (Note that this object might be a platform leaf, e.g. an ARIA searchbox, 4486 // (Note that this object might be a platform leaf, e.g. an ARIA searchbox,
4414 // and so |InternalChild...| functions need to be used. Also, direct text-only 4487 // and so |GetOwner()->InternalChild...| functions need to be used. Also,
4415 // children should not be present at tree roots and so no cross-tree traversal 4488 // direct text-only children should not be present at tree roots and so no
4416 // is necessary.) 4489 // cross-tree traversal is necessary.)
4417 if (child.IsTextOnlyObject()) { 4490 if (child.GetOwner()->IsTextOnlyObject()) {
4418 int32_t hypertextOffset = 0; 4491 int32_t hypertextOffset = 0;
4419 int32_t index_in_parent = child.GetIndexInParent(); 4492 int32_t index_in_parent = child.GetIndexInParent();
4420 DCHECK_GE(index_in_parent, 0); 4493 DCHECK_GE(index_in_parent, 0);
4421 DCHECK_LT(index_in_parent, static_cast<int32_t>(InternalChildCount())); 4494 DCHECK_LT(index_in_parent,
4495 static_cast<int32_t>(GetOwner()->InternalChildCount()));
4422 for (uint32_t i = 0; i < static_cast<uint32_t>(index_in_parent); ++i) { 4496 for (uint32_t i = 0; i < static_cast<uint32_t>(index_in_parent); ++i) {
4423 const BrowserAccessibilityWin* sibling = 4497 const BrowserAccessibilityComWin* sibling =
4424 ToBrowserAccessibilityWin(InternalGetChild(i)); 4498 ToBrowserAccessibilityComWin(GetOwner()->InternalGetChild(i));
4425 DCHECK(sibling); 4499 DCHECK(sibling);
4426 if (sibling->IsTextOnlyObject()) 4500 if (sibling->GetOwner()->IsTextOnlyObject())
4427 hypertextOffset += sibling->GetText().size(); 4501 hypertextOffset += sibling->GetOwner()->GetText().size();
4428 else 4502 else
4429 ++hypertextOffset; 4503 ++hypertextOffset;
4430 } 4504 }
4431 return hypertextOffset; 4505 return hypertextOffset;
4432 } 4506 }
4433 4507
4434 int32_t hyperlink_index = GetHyperlinkIndexFromChild(child); 4508 int32_t hyperlink_index = GetHyperlinkIndexFromChild(child);
4435 if (hyperlink_index < 0) 4509 if (hyperlink_index < 0)
4436 return -1; 4510 return -1;
4437 4511
4438 return GetHypertextOffsetFromHyperlinkIndex(hyperlink_index); 4512 return GetHypertextOffsetFromHyperlinkIndex(hyperlink_index);
4439 } 4513 }
4440 4514
4441 int32_t BrowserAccessibilityWin::GetHypertextOffsetFromDescendant( 4515 int32_t BrowserAccessibilityComWin::GetHypertextOffsetFromDescendant(
4442 const BrowserAccessibilityWin& descendant) const { 4516 const BrowserAccessibilityComWin& descendant) const {
4443 auto* parent_object = 4517 auto* parent_object =
4444 ToBrowserAccessibilityWin(descendant.PlatformGetParent()); 4518 ToBrowserAccessibilityComWin(descendant.GetOwner()->PlatformGetParent());
4445 auto* current_object = const_cast<BrowserAccessibilityWin*>(&descendant); 4519 auto* current_object = const_cast<BrowserAccessibilityComWin*>(&descendant);
4446 while (parent_object && parent_object != this) { 4520 while (parent_object && parent_object != this) {
4447 current_object = parent_object; 4521 current_object = parent_object;
4448 parent_object = 4522 parent_object = ToBrowserAccessibilityComWin(
4449 ToBrowserAccessibilityWin(current_object->PlatformGetParent()); 4523 current_object->GetOwner()->PlatformGetParent());
4450 } 4524 }
4451 if (!parent_object) 4525 if (!parent_object)
4452 return -1; 4526 return -1;
4453 4527
4454 return parent_object->GetHypertextOffsetFromChild(*current_object); 4528 return parent_object->GetHypertextOffsetFromChild(*current_object);
4455 } 4529 }
4456 4530
4457 int BrowserAccessibilityWin::GetHypertextOffsetFromEndpoint( 4531 int BrowserAccessibilityComWin::GetHypertextOffsetFromEndpoint(
4458 const BrowserAccessibilityWin& endpoint_object, 4532 const BrowserAccessibilityComWin& endpoint_object,
4459 int endpoint_offset) const { 4533 int endpoint_offset) const {
4460 // There are three cases: 4534 // There are three cases:
4461 // 1. Either the selection endpoint is inside this object or is an ancestor of 4535 // 1. Either the selection endpoint is inside this object or is an ancestor of
4462 // of this object. endpoint_offset should be returned. 4536 // of this object. endpoint_offset should be returned.
4463 // 2. The selection endpoint is a pure descendant of this object. The offset 4537 // 2. The selection endpoint is a pure descendant of this object. The offset
4464 // of the character corresponding to the subtree in which the endpoint is 4538 // of the character corresponding to the subtree in which the endpoint is
4465 // located should be returned. 4539 // located should be returned.
4466 // 3. The selection endpoint is in a completely different part of the tree. 4540 // 3. The selection endpoint is in a completely different part of the tree.
4467 // Either 0 or text_length should be returned depending on the direction that 4541 // Either 0 or text_length should be returned depending on the direction that
4468 // one needs to travel to find the endpoint. 4542 // one needs to travel to find the endpoint.
4469 4543
4470 // Case 1. 4544 // Case 1.
4471 // 4545 //
4472 // IsDescendantOf includes the case when endpoint_object == this. 4546 // IsDescendantOf includes the case when endpoint_object == this.
4473 if (IsDescendantOf(&endpoint_object)) 4547 if (GetOwner()->IsDescendantOf(endpoint_object.GetOwner()))
4474 return endpoint_offset; 4548 return endpoint_offset;
4475 4549
4476 const BrowserAccessibility* common_parent = this; 4550 const BrowserAccessibility* common_parent = GetOwner();
4477 int32_t index_in_common_parent = GetIndexInParent(); 4551 int32_t index_in_common_parent = GetOwner()->GetIndexInParent();
4478 while (common_parent && !endpoint_object.IsDescendantOf(common_parent)) { 4552 while (common_parent &&
4553 !endpoint_object.GetOwner()->IsDescendantOf(common_parent)) {
4479 index_in_common_parent = common_parent->GetIndexInParent(); 4554 index_in_common_parent = common_parent->GetIndexInParent();
4480 common_parent = common_parent->PlatformGetParent(); 4555 common_parent = common_parent->PlatformGetParent();
4481 } 4556 }
4482 if (!common_parent) 4557 if (!common_parent)
4483 return -1; 4558 return -1;
4484 4559
4485 DCHECK_GE(index_in_common_parent, 0); 4560 DCHECK_GE(index_in_common_parent, 0);
4486 DCHECK(!(common_parent->IsTextOnlyObject())); 4561 DCHECK(!(common_parent->IsTextOnlyObject()));
4487 4562
4488 // Case 2. 4563 // Case 2.
4489 // 4564 //
4490 // We already checked in case 1 if our endpoint is inside this object. 4565 // We already checked in case 1 if our endpoint is inside this object.
4491 // We can safely assume that it is a descendant or in a completely different 4566 // We can safely assume that it is a descendant or in a completely different
4492 // part of the tree. 4567 // part of the tree.
4493 if (common_parent == this) { 4568 if (common_parent == GetOwner()) {
4494 int32_t hypertext_offset = 4569 int32_t hypertext_offset =
4495 GetHypertextOffsetFromDescendant(endpoint_object); 4570 GetHypertextOffsetFromDescendant(endpoint_object);
4496 if (endpoint_object.PlatformGetParent() == this && 4571 if (endpoint_object.GetOwner()->PlatformGetParent() == GetOwner() &&
4497 endpoint_object.IsTextOnlyObject()) { 4572 endpoint_object.GetOwner()->IsTextOnlyObject()) {
4498 hypertext_offset += endpoint_offset; 4573 hypertext_offset += endpoint_offset;
4499 } 4574 }
4500 4575
4501 return hypertext_offset; 4576 return hypertext_offset;
4502 } 4577 }
4503 4578
4504 // Case 3. 4579 // Case 3.
4505 // 4580 //
4506 // We can safely assume that the endpoint is in another part of the tree or 4581 // We can safely assume that the endpoint is in another part of the tree or
4507 // at common parent, and that this object is a descendant of common parent. 4582 // at common parent, and that this object is a descendant of common parent.
4508 int32_t endpoint_index_in_common_parent = -1; 4583 int32_t endpoint_index_in_common_parent = -1;
4509 for (uint32_t i = 0; i < common_parent->InternalChildCount(); ++i) { 4584 for (uint32_t i = 0; i < common_parent->InternalChildCount(); ++i) {
4510 const BrowserAccessibility* child = common_parent->InternalGetChild(i); 4585 const BrowserAccessibility* child = common_parent->InternalGetChild(i);
4511 DCHECK(child); 4586 DCHECK(child);
4512 if (endpoint_object.IsDescendantOf(child)) { 4587 if (endpoint_object.GetOwner()->IsDescendantOf(child)) {
4513 endpoint_index_in_common_parent = child->GetIndexInParent(); 4588 endpoint_index_in_common_parent = child->GetIndexInParent();
4514 break; 4589 break;
4515 } 4590 }
4516 } 4591 }
4517 DCHECK_GE(endpoint_index_in_common_parent, 0); 4592 DCHECK_GE(endpoint_index_in_common_parent, 0);
4518 4593
4519 if (endpoint_index_in_common_parent < index_in_common_parent) 4594 if (endpoint_index_in_common_parent < index_in_common_parent)
4520 return 0; 4595 return 0;
4521 if (endpoint_index_in_common_parent > index_in_common_parent) 4596 if (endpoint_index_in_common_parent > index_in_common_parent)
4522 return GetText().size(); 4597 return GetOwner()->GetText().size();
4523 4598
4524 NOTREACHED(); 4599 NOTREACHED();
4525 return -1; 4600 return -1;
4526 } 4601 }
4527 4602
4528 int BrowserAccessibilityWin::GetSelectionAnchor() const { 4603 int BrowserAccessibilityComWin::GetSelectionAnchor() const {
4529 int32_t anchor_id = manager_->GetTreeData().sel_anchor_object_id; 4604 int32_t anchor_id = GetOwner()->manager()->GetTreeData().sel_anchor_object_id;
4530 const BrowserAccessibilityWin* anchor_object = GetFromID(anchor_id); 4605 const BrowserAccessibilityComWin* anchor_object = GetFromID(anchor_id);
4531 if (!anchor_object) 4606 if (!anchor_object)
4532 return -1; 4607 return -1;
4533 4608
4534 int anchor_offset = manager_->GetTreeData().sel_anchor_offset; 4609 int anchor_offset = GetOwner()->manager()->GetTreeData().sel_anchor_offset;
4535 return GetHypertextOffsetFromEndpoint(*anchor_object, anchor_offset); 4610 return GetHypertextOffsetFromEndpoint(*anchor_object, anchor_offset);
4536 } 4611 }
4537 4612
4538 int BrowserAccessibilityWin::GetSelectionFocus() const { 4613 int BrowserAccessibilityComWin::GetSelectionFocus() const {
4539 int32_t focus_id = manager_->GetTreeData().sel_focus_object_id; 4614 int32_t focus_id = GetOwner()->manager()->GetTreeData().sel_focus_object_id;
4540 const BrowserAccessibilityWin* focus_object = GetFromID(focus_id); 4615 const BrowserAccessibilityComWin* focus_object = GetFromID(focus_id);
4541 if (!focus_object) 4616 if (!focus_object)
4542 return -1; 4617 return -1;
4543 4618
4544 int focus_offset = manager_->GetTreeData().sel_focus_offset; 4619 int focus_offset = GetOwner()->manager()->GetTreeData().sel_focus_offset;
4545 return GetHypertextOffsetFromEndpoint(*focus_object, focus_offset); 4620 return GetHypertextOffsetFromEndpoint(*focus_object, focus_offset);
4546 } 4621 }
4547 4622
4548 void BrowserAccessibilityWin::GetSelectionOffsets( 4623 void BrowserAccessibilityComWin::GetSelectionOffsets(int* selection_start,
4549 int* selection_start, int* selection_end) const { 4624 int* selection_end) const {
4550 DCHECK(selection_start && selection_end); 4625 DCHECK(selection_start && selection_end);
4551 4626
4552 if (IsSimpleTextControl() && 4627 if (GetOwner()->IsSimpleTextControl() &&
4553 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, selection_start) && 4628 GetOwner()->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START,
4554 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, selection_end)) { 4629 selection_start) &&
4630 GetOwner()->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, selection_end)) {
4555 return; 4631 return;
4556 } 4632 }
4557 4633
4558 *selection_start = GetSelectionAnchor(); 4634 *selection_start = GetSelectionAnchor();
4559 *selection_end = GetSelectionFocus(); 4635 *selection_end = GetSelectionFocus();
4560 if (*selection_start < 0 || *selection_end < 0) 4636 if (*selection_start < 0 || *selection_end < 0)
4561 return; 4637 return;
4562 4638
4563 // There are three cases when a selection would start and end on the same 4639 // There are three cases when a selection would start and end on the same
4564 // character: 4640 // character:
4565 // 1. Anchor and focus are both in a subtree that is to the right of this 4641 // 1. Anchor and focus are both in a subtree that is to the right of this
4566 // object. 4642 // object.
4567 // 2. Anchor and focus are both in a subtree that is to the left of this 4643 // 2. Anchor and focus are both in a subtree that is to the left of this
4568 // object. 4644 // object.
4569 // 3. Anchor and focus are in a subtree represented by a single embedded 4645 // 3. Anchor and focus are in a subtree represented by a single embedded
4570 // object character. 4646 // object character.
4571 // Only case 3 refers to a valid selection because cases 1 and 2 fall 4647 // Only case 3 refers to a valid selection because cases 1 and 2 fall
4572 // outside this object in their entirety. 4648 // outside this object in their entirety.
4573 // Selections that span more than one character are by definition inside this 4649 // Selections that span more than one character are by definition inside this
4574 // object, so checking them is not necessary. 4650 // object, so checking them is not necessary.
4575 if (*selection_start == *selection_end && !HasCaret()) { 4651 if (*selection_start == *selection_end && !GetOwner()->HasCaret()) {
4576 *selection_start = -1; 4652 *selection_start = -1;
4577 *selection_end = -1; 4653 *selection_end = -1;
4578 return; 4654 return;
4579 } 4655 }
4580 4656
4581 // The IA2 Spec says that if the largest of the two offsets falls on an 4657 // The IA2 Spec says that if the largest of the two offsets falls on an
4582 // embedded object character and if there is a selection in that embedded 4658 // embedded object character and if there is a selection in that embedded
4583 // object, it should be incremented by one so that it points after the 4659 // object, it should be incremented by one so that it points after the
4584 // embedded object character. 4660 // embedded object character.
4585 // This is a signal to AT software that the embedded object is also part of 4661 // This is a signal to AT software that the embedded object is also part of
4586 // the selection. 4662 // the selection.
4587 int* largest_offset = 4663 int* largest_offset =
4588 (*selection_start <= *selection_end) ? selection_end : selection_start; 4664 (*selection_start <= *selection_end) ? selection_end : selection_start;
4589 BrowserAccessibilityWin* hyperlink = 4665 BrowserAccessibilityComWin* hyperlink =
4590 GetHyperlinkFromHypertextOffset(*largest_offset); 4666 GetHyperlinkFromHypertextOffset(*largest_offset);
4591 if (!hyperlink) 4667 if (!hyperlink)
4592 return; 4668 return;
4593 4669
4594 LONG n_selections = 0; 4670 LONG n_selections = 0;
4595 HRESULT hr = hyperlink->get_nSelections(&n_selections); 4671 HRESULT hr = hyperlink->get_nSelections(&n_selections);
4596 DCHECK(SUCCEEDED(hr)); 4672 DCHECK(SUCCEEDED(hr));
4597 if (n_selections > 0) 4673 if (n_selections > 0)
4598 ++(*largest_offset); 4674 ++(*largest_offset);
4599 } 4675 }
4600 4676
4601 base::string16 BrowserAccessibilityWin::GetValueText() { 4677 base::string16 BrowserAccessibilityComWin::GetValueText() {
4602 float fval; 4678 float fval;
4603 base::string16 value = this->value(); 4679 base::string16 result = value();
4604 4680
4605 if (value.empty() && 4681 if (result.empty() && GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, &fval)) {
4606 GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, &fval)) { 4682 result = base::UTF8ToUTF16(base::DoubleToString(fval));
4607 value = base::UTF8ToUTF16(base::DoubleToString(fval));
4608 } 4683 }
4609 return value; 4684 return result;
4610 } 4685 }
4611 4686
4612 bool BrowserAccessibilityWin::IsSameHypertextCharacter(size_t old_char_index, 4687 bool BrowserAccessibilityComWin::IsSameHypertextCharacter(
4613 size_t new_char_index) { 4688 size_t old_char_index,
4689 size_t new_char_index) {
4614 CHECK(old_win_attributes_); 4690 CHECK(old_win_attributes_);
4615 4691
4616 // For anything other than the "embedded character", we just compare the 4692 // For anything other than the "embedded character", we just compare the
4617 // characters directly. 4693 // characters directly.
4618 base::char16 old_ch = old_win_attributes_->hypertext[old_char_index]; 4694 base::char16 old_ch = old_win_attributes_->hypertext[old_char_index];
4619 base::char16 new_ch = win_attributes_->hypertext[new_char_index]; 4695 base::char16 new_ch = win_attributes_->hypertext[new_char_index];
4620 if (old_ch != new_ch) 4696 if (old_ch != new_ch)
4621 return false; 4697 return false;
4622 if (old_ch == new_ch && new_ch != kEmbeddedCharacter) 4698 if (old_ch == new_ch && new_ch != kEmbeddedCharacter)
4623 return true; 4699 return true;
4624 4700
4625 // If it's an embedded character, they're only identical if the child id 4701 // If it's an embedded character, they're only identical if the child id
4626 // the hyperlink points to is the same. 4702 // the hyperlink points to is the same.
4627 std::map<int32_t, int32_t>& old_offset_to_index = 4703 std::map<int32_t, int32_t>& old_offset_to_index =
4628 old_win_attributes_->hyperlink_offset_to_index; 4704 old_win_attributes_->hyperlink_offset_to_index;
4629 std::vector<int32_t>& old_hyperlinks = old_win_attributes_->hyperlinks; 4705 std::vector<int32_t>& old_hyperlinks = old_win_attributes_->hyperlinks;
4630 int32_t old_hyperlinks_count = static_cast<int32_t>(old_hyperlinks.size()); 4706 int32_t old_hyperlinks_count = static_cast<int32_t>(old_hyperlinks.size());
4631 std::map<int32_t, int32_t>::iterator iter; 4707 std::map<int32_t, int32_t>::iterator iter;
4632 iter = old_offset_to_index.find(old_char_index); 4708 iter = old_offset_to_index.find(old_char_index);
4633 int old_index = (iter != old_offset_to_index.end()) ? iter->second : -1; 4709 int old_index = (iter != old_offset_to_index.end()) ? iter->second : -1;
4634 int old_child_id = (old_index >= 0 && old_index < old_hyperlinks_count) ? 4710 int old_child_id = (old_index >= 0 && old_index < old_hyperlinks_count)
4635 old_hyperlinks[old_index] : -1; 4711 ? old_hyperlinks[old_index]
4712 : -1;
4636 4713
4637 std::map<int32_t, int32_t>& new_offset_to_index = 4714 std::map<int32_t, int32_t>& new_offset_to_index =
4638 win_attributes_->hyperlink_offset_to_index; 4715 win_attributes_->hyperlink_offset_to_index;
4639 std::vector<int32_t>& new_hyperlinks = win_attributes_->hyperlinks; 4716 std::vector<int32_t>& new_hyperlinks = win_attributes_->hyperlinks;
4640 int32_t new_hyperlinks_count = static_cast<int32_t>(new_hyperlinks.size()); 4717 int32_t new_hyperlinks_count = static_cast<int32_t>(new_hyperlinks.size());
4641 iter = new_offset_to_index.find(new_char_index); 4718 iter = new_offset_to_index.find(new_char_index);
4642 int new_index = (iter != new_offset_to_index.end()) ? iter->second : -1; 4719 int new_index = (iter != new_offset_to_index.end()) ? iter->second : -1;
4643 int new_child_id = (new_index >= 0 && new_index < new_hyperlinks_count) ? 4720 int new_child_id = (new_index >= 0 && new_index < new_hyperlinks_count)
4644 new_hyperlinks[new_index] : -1; 4721 ? new_hyperlinks[new_index]
4722 : -1;
4645 4723
4646 return old_child_id == new_child_id; 4724 return old_child_id == new_child_id;
4647 } 4725 }
4648 4726
4649 void BrowserAccessibilityWin::ComputeHypertextRemovedAndInserted( 4727 void BrowserAccessibilityComWin::ComputeHypertextRemovedAndInserted(
4650 int* start, int* old_len, int* new_len) { 4728 int* start,
4729 int* old_len,
4730 int* new_len) {
4651 CHECK(old_win_attributes_); 4731 CHECK(old_win_attributes_);
4652 4732
4653 *start = 0; 4733 *start = 0;
4654 *old_len = 0; 4734 *old_len = 0;
4655 *new_len = 0; 4735 *new_len = 0;
4656 4736
4657 const base::string16& old_text = old_win_attributes_->hypertext; 4737 const base::string16& old_text = old_win_attributes_->hypertext;
4658 const base::string16& new_text = GetText(); 4738 const base::string16& new_text = GetOwner()->GetText();
4659 4739
4660 size_t common_prefix = 0; 4740 size_t common_prefix = 0;
4661 while (common_prefix < old_text.size() && 4741 while (common_prefix < old_text.size() && common_prefix < new_text.size() &&
4662 common_prefix < new_text.size() &&
4663 IsSameHypertextCharacter(common_prefix, common_prefix)) { 4742 IsSameHypertextCharacter(common_prefix, common_prefix)) {
4664 ++common_prefix; 4743 ++common_prefix;
4665 } 4744 }
4666 4745
4667 size_t common_suffix = 0; 4746 size_t common_suffix = 0;
4668 while (common_prefix + common_suffix < old_text.size() && 4747 while (common_prefix + common_suffix < old_text.size() &&
4669 common_prefix + common_suffix < new_text.size() && 4748 common_prefix + common_suffix < new_text.size() &&
4670 IsSameHypertextCharacter( 4749 IsSameHypertextCharacter(old_text.size() - common_suffix - 1,
4671 old_text.size() - common_suffix - 1, 4750 new_text.size() - common_suffix - 1)) {
4672 new_text.size() - common_suffix - 1)) {
4673 ++common_suffix; 4751 ++common_suffix;
4674 } 4752 }
4675 4753
4676 *start = common_prefix; 4754 *start = common_prefix;
4677 *old_len = old_text.size() - common_prefix - common_suffix; 4755 *old_len = old_text.size() - common_prefix - common_suffix;
4678 *new_len = new_text.size() - common_prefix - common_suffix; 4756 *new_len = new_text.size() - common_prefix - common_suffix;
4679 } 4757 }
4680 4758
4681 void BrowserAccessibilityWin::HandleSpecialTextOffset(LONG* offset) { 4759 void BrowserAccessibilityComWin::HandleSpecialTextOffset(LONG* offset) {
4682 if (*offset == IA2_TEXT_OFFSET_LENGTH) { 4760 if (*offset == IA2_TEXT_OFFSET_LENGTH) {
4683 *offset = static_cast<LONG>(GetText().length()); 4761 *offset = static_cast<LONG>(GetOwner()->GetText().length());
4684 } else if (*offset == IA2_TEXT_OFFSET_CARET) { 4762 } else if (*offset == IA2_TEXT_OFFSET_CARET) {
4685 // We shouldn't call |get_caretOffset| here as it affects UMA counts. 4763 // We shouldn't call |get_caretOffset| here as it affects UMA counts.
4686 int selection_start, selection_end; 4764 int selection_start, selection_end;
4687 GetSelectionOffsets(&selection_start, &selection_end); 4765 GetSelectionOffsets(&selection_start, &selection_end);
4688 *offset = selection_end; 4766 *offset = selection_end;
4689 } 4767 }
4690 } 4768 }
4691 4769
4692 ui::TextBoundaryType BrowserAccessibilityWin::IA2TextBoundaryToTextBoundary( 4770 ui::TextBoundaryType BrowserAccessibilityComWin::IA2TextBoundaryToTextBoundary(
4693 IA2TextBoundaryType ia2_boundary) { 4771 IA2TextBoundaryType ia2_boundary) {
4694 switch(ia2_boundary) { 4772 switch (ia2_boundary) {
4695 case IA2_TEXT_BOUNDARY_CHAR: 4773 case IA2_TEXT_BOUNDARY_CHAR:
4696 return ui::CHAR_BOUNDARY; 4774 return ui::CHAR_BOUNDARY;
4697 case IA2_TEXT_BOUNDARY_WORD: 4775 case IA2_TEXT_BOUNDARY_WORD:
4698 return ui::WORD_BOUNDARY; 4776 return ui::WORD_BOUNDARY;
4699 case IA2_TEXT_BOUNDARY_LINE: 4777 case IA2_TEXT_BOUNDARY_LINE:
4700 return ui::LINE_BOUNDARY; 4778 return ui::LINE_BOUNDARY;
4701 case IA2_TEXT_BOUNDARY_SENTENCE: 4779 case IA2_TEXT_BOUNDARY_SENTENCE:
4702 return ui::SENTENCE_BOUNDARY; 4780 return ui::SENTENCE_BOUNDARY;
4703 case IA2_TEXT_BOUNDARY_PARAGRAPH: 4781 case IA2_TEXT_BOUNDARY_PARAGRAPH:
4704 return ui::PARAGRAPH_BOUNDARY; 4782 return ui::PARAGRAPH_BOUNDARY;
4705 case IA2_TEXT_BOUNDARY_ALL: 4783 case IA2_TEXT_BOUNDARY_ALL:
4706 return ui::ALL_BOUNDARY; 4784 return ui::ALL_BOUNDARY;
4707 } 4785 }
4708 NOTREACHED(); 4786 NOTREACHED();
4709 return ui::CHAR_BOUNDARY; 4787 return ui::CHAR_BOUNDARY;
4710 } 4788 }
4711 4789
4712 LONG BrowserAccessibilityWin::FindBoundary( 4790 LONG BrowserAccessibilityComWin::FindBoundary(
4713 const base::string16& text, 4791 const base::string16& text,
4714 IA2TextBoundaryType ia2_boundary, 4792 IA2TextBoundaryType ia2_boundary,
4715 LONG start_offset, 4793 LONG start_offset,
4716 ui::TextBoundaryDirection direction) { 4794 ui::TextBoundaryDirection direction) {
4717 // If the boundary is relative to the caret, use the selection 4795 // If the boundary is relative to the caret, use the selection
4718 // affinity, otherwise default to downstream affinity. 4796 // affinity, otherwise default to downstream affinity.
4719 ui::AXTextAffinity affinity = start_offset == IA2_TEXT_OFFSET_CARET 4797 ui::AXTextAffinity affinity =
4720 ? manager_->GetTreeData().sel_focus_affinity 4798 start_offset == IA2_TEXT_OFFSET_CARET
4721 : ui::AX_TEXT_AFFINITY_DOWNSTREAM; 4799 ? GetOwner()->manager()->GetTreeData().sel_focus_affinity
4800 : ui::AX_TEXT_AFFINITY_DOWNSTREAM;
4722 4801
4723 HandleSpecialTextOffset(&start_offset); 4802 HandleSpecialTextOffset(&start_offset);
4724 if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD) { 4803 if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD) {
4725 switch (direction) { 4804 switch (direction) {
4726 case ui::FORWARDS_DIRECTION: { 4805 case ui::FORWARDS_DIRECTION: {
4727 AXPlatformPositionInstance position = 4806 AXPlatformPositionInstance position = GetOwner()->CreatePositionAt(
4728 CreatePositionAt(static_cast<int>(start_offset), affinity); 4807 static_cast<int>(start_offset), affinity);
4729 AXPlatformPositionInstance next_word = 4808 AXPlatformPositionInstance next_word =
4730 position->CreateNextWordStartPosition(); 4809 position->CreateNextWordStartPosition();
4731 if (next_word->anchor_id() != GetId()) 4810 if (next_word->anchor_id() != GetOwner()->GetId())
4732 next_word = position->CreatePositionAtEndOfAnchor(); 4811 next_word = position->CreatePositionAtEndOfAnchor();
4733 return next_word->text_offset(); 4812 return next_word->text_offset();
4734 } 4813 }
4735 case ui::BACKWARDS_DIRECTION: { 4814 case ui::BACKWARDS_DIRECTION: {
4736 AXPlatformPositionInstance position = 4815 AXPlatformPositionInstance position = GetOwner()->CreatePositionAt(
4737 CreatePositionAt(static_cast<int>(start_offset), affinity); 4816 static_cast<int>(start_offset), affinity);
4738 AXPlatformPositionInstance previous_word; 4817 AXPlatformPositionInstance previous_word;
4739 if (!position->AtStartOfWord()) { 4818 if (!position->AtStartOfWord()) {
4740 previous_word = position->CreatePreviousWordStartPosition(); 4819 previous_word = position->CreatePreviousWordStartPosition();
4741 if (previous_word->anchor_id() != GetId()) 4820 if (previous_word->anchor_id() != GetOwner()->GetId())
4742 previous_word = position->CreatePositionAtStartOfAnchor(); 4821 previous_word = position->CreatePositionAtStartOfAnchor();
4743 } else { 4822 } else {
4744 previous_word = std::move(position); 4823 previous_word = std::move(position);
4745 } 4824 }
4746 return previous_word->text_offset(); 4825 return previous_word->text_offset();
4747 } 4826 }
4748 } 4827 }
4749 } 4828 }
4750 4829
4751 if (ia2_boundary == IA2_TEXT_BOUNDARY_LINE) { 4830 if (ia2_boundary == IA2_TEXT_BOUNDARY_LINE) {
4752 switch (direction) { 4831 switch (direction) {
4753 case ui::FORWARDS_DIRECTION: { 4832 case ui::FORWARDS_DIRECTION: {
4754 AXPlatformPositionInstance position = 4833 AXPlatformPositionInstance position = GetOwner()->CreatePositionAt(
4755 CreatePositionAt(static_cast<int>(start_offset), affinity); 4834 static_cast<int>(start_offset), affinity);
4756 AXPlatformPositionInstance next_line = 4835 AXPlatformPositionInstance next_line =
4757 position->CreateNextLineStartPosition(); 4836 position->CreateNextLineStartPosition();
4758 if (next_line->anchor_id() != GetId()) 4837 if (next_line->anchor_id() != GetOwner()->GetId())
4759 next_line = position->CreatePositionAtEndOfAnchor(); 4838 next_line = position->CreatePositionAtEndOfAnchor();
4760 return next_line->text_offset(); 4839 return next_line->text_offset();
4761 } 4840 }
4762 case ui::BACKWARDS_DIRECTION: { 4841 case ui::BACKWARDS_DIRECTION: {
4763 AXPlatformPositionInstance position = 4842 AXPlatformPositionInstance position = GetOwner()->CreatePositionAt(
4764 CreatePositionAt(static_cast<int>(start_offset), affinity); 4843 static_cast<int>(start_offset), affinity);
4765 AXPlatformPositionInstance previous_line; 4844 AXPlatformPositionInstance previous_line;
4766 if (!position->AtStartOfLine()) { 4845 if (!position->AtStartOfLine()) {
4767 previous_line = position->CreatePreviousLineStartPosition(); 4846 previous_line = position->CreatePreviousLineStartPosition();
4768 if (previous_line->anchor_id() != GetId()) 4847 if (previous_line->anchor_id() != GetOwner()->GetId())
4769 previous_line = position->CreatePositionAtStartOfAnchor(); 4848 previous_line = position->CreatePositionAtStartOfAnchor();
4770 } else { 4849 } else {
4771 previous_line = std::move(position); 4850 previous_line = std::move(position);
4772 } 4851 }
4773 return previous_line->text_offset(); 4852 return previous_line->text_offset();
4774 } 4853 }
4775 } 4854 }
4776 } 4855 }
4777 4856
4778 // TODO(nektar): |AXPosition| can handle other types of boundaries as well. 4857 // TODO(nektar): |AXPosition| can handle other types of boundaries as well.
4779 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary); 4858 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary);
4780 return ui::FindAccessibleTextBoundary(text, GetLineStartOffsets(), boundary, 4859 return ui::FindAccessibleTextBoundary(text, GetOwner()->GetLineStartOffsets(),
4781 start_offset, direction, affinity); 4860 boundary, start_offset, direction,
4861 affinity);
4782 } 4862 }
4783 4863
4784 LONG BrowserAccessibilityWin::FindStartOfStyle( 4864 LONG BrowserAccessibilityComWin::FindStartOfStyle(
4785 LONG start_offset, 4865 LONG start_offset,
4786 ui::TextBoundaryDirection direction) const { 4866 ui::TextBoundaryDirection direction) const {
4787 LONG text_length = static_cast<LONG>(GetText().length()); 4867 LONG text_length = static_cast<LONG>(GetOwner()->GetText().length());
4788 DCHECK_GE(start_offset, 0); 4868 DCHECK_GE(start_offset, 0);
4789 DCHECK_LE(start_offset, text_length); 4869 DCHECK_LE(start_offset, text_length);
4790 4870
4791 switch (direction) { 4871 switch (direction) {
4792 case ui::BACKWARDS_DIRECTION: { 4872 case ui::BACKWARDS_DIRECTION: {
4793 if (offset_to_text_attributes().empty()) 4873 if (offset_to_text_attributes().empty())
4794 return 0; 4874 return 0;
4795 4875
4796 auto iterator = offset_to_text_attributes().upper_bound(start_offset); 4876 auto iterator = offset_to_text_attributes().upper_bound(start_offset);
4797 --iterator; 4877 --iterator;
4798 return static_cast<LONG>(iterator->first); 4878 return static_cast<LONG>(iterator->first);
4799 } 4879 }
4800 case ui::FORWARDS_DIRECTION: { 4880 case ui::FORWARDS_DIRECTION: {
4801 const auto iterator = 4881 const auto iterator =
4802 offset_to_text_attributes().upper_bound(start_offset); 4882 offset_to_text_attributes().upper_bound(start_offset);
4803 if (iterator == offset_to_text_attributes().end()) 4883 if (iterator == offset_to_text_attributes().end())
4804 return text_length; 4884 return text_length;
4805 return static_cast<LONG>(iterator->first); 4885 return static_cast<LONG>(iterator->first);
4806 } 4886 }
4807 } 4887 }
4808 4888
4809 NOTREACHED(); 4889 NOTREACHED();
4810 return start_offset; 4890 return start_offset;
4811 } 4891 }
4812 4892
4813 BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32_t id) const { 4893 BrowserAccessibilityComWin* BrowserAccessibilityComWin::GetFromID(
4814 if (!instance_active()) 4894 int32_t id) const {
4895 if (!GetOwner() || !GetOwner()->instance_active())
4815 return nullptr; 4896 return nullptr;
4816 return ToBrowserAccessibilityWin(manager_->GetFromID(id)); 4897 return ToBrowserAccessibilityComWin(GetOwner()->manager()->GetFromID(id));
4817 } 4898 }
4818 4899
4819 bool BrowserAccessibilityWin::IsListBoxOptionOrMenuListOption() { 4900 bool BrowserAccessibilityComWin::IsListBoxOptionOrMenuListOption() {
4820 if (!PlatformGetParent()) 4901 if (!GetOwner()->PlatformGetParent())
4821 return false; 4902 return false;
4822 4903
4823 int32_t role = GetRole(); 4904 int32_t role = GetOwner()->GetRole();
4824 int32_t parent_role = PlatformGetParent()->GetRole(); 4905 int32_t parent_role = GetOwner()->PlatformGetParent()->GetRole();
4825 4906
4826 if (role == ui::AX_ROLE_LIST_BOX_OPTION && 4907 if (role == ui::AX_ROLE_LIST_BOX_OPTION &&
4827 parent_role == ui::AX_ROLE_LIST_BOX) { 4908 parent_role == ui::AX_ROLE_LIST_BOX) {
4828 return true; 4909 return true;
4829 } 4910 }
4830 4911
4831 if (role == ui::AX_ROLE_MENU_LIST_OPTION && 4912 if (role == ui::AX_ROLE_MENU_LIST_OPTION &&
4832 parent_role == ui::AX_ROLE_MENU_LIST_POPUP) { 4913 parent_role == ui::AX_ROLE_MENU_LIST_POPUP) {
4833 return true; 4914 return true;
4834 } 4915 }
4835 4916
4836 return false; 4917 return false;
4837 } 4918 }
4838 4919
4839 void BrowserAccessibilityWin::AddRelation(const base::string16& relation_type, 4920 void BrowserAccessibilityComWin::AddRelation(
4840 int target_id) { 4921 const base::string16& relation_type,
4922 int target_id) {
4841 // Reflexive relations don't need to be exposed through IA2. 4923 // Reflexive relations don't need to be exposed through IA2.
4842 if (target_id == GetId()) 4924 if (target_id == GetOwner()->GetId())
4843 return; 4925 return;
4844 4926
4845 CComObject<BrowserAccessibilityRelation>* relation; 4927 CComObject<BrowserAccessibilityRelation>* relation;
4846 HRESULT hr = 4928 HRESULT hr =
4847 CComObject<BrowserAccessibilityRelation>::CreateInstance(&relation); 4929 CComObject<BrowserAccessibilityRelation>::CreateInstance(&relation);
4848 DCHECK(SUCCEEDED(hr)); 4930 DCHECK(SUCCEEDED(hr));
4849 relation->AddRef(); 4931 relation->AddRef();
4850 relation->Initialize(this, relation_type); 4932 relation->Initialize(this, relation_type);
4851 relation->AddTarget(target_id); 4933 relation->AddTarget(target_id);
4852 relations_.push_back(relation); 4934 relations_.push_back(relation);
4853 } 4935 }
4854 4936
4855 void BrowserAccessibilityWin::AddBidirectionalRelations( 4937 void BrowserAccessibilityComWin::AddBidirectionalRelations(
4856 const base::string16& relation_type, 4938 const base::string16& relation_type,
4857 const base::string16& reverse_relation_type, 4939 const base::string16& reverse_relation_type,
4858 ui::AXIntListAttribute attribute) { 4940 ui::AXIntListAttribute attribute) {
4859 if (!HasIntListAttribute(attribute)) 4941 if (!GetOwner()->HasIntListAttribute(attribute))
4860 return; 4942 return;
4861 4943
4862 const std::vector<int32_t>& target_ids = GetIntListAttribute(attribute); 4944 const std::vector<int32_t>& target_ids =
4945 GetOwner()->GetIntListAttribute(attribute);
4863 // Reflexive relations don't need to be exposed through IA2. 4946 // Reflexive relations don't need to be exposed through IA2.
4864 std::vector<int32_t> filtered_target_ids; 4947 std::vector<int32_t> filtered_target_ids;
4865 int32_t current_id = GetId(); 4948 int32_t current_id = GetOwner()->GetId();
4866 std::copy_if(target_ids.begin(), target_ids.end(), 4949 std::copy_if(target_ids.begin(), target_ids.end(),
4867 std::back_inserter(filtered_target_ids), 4950 std::back_inserter(filtered_target_ids),
4868 [current_id](int32_t id) { return id != current_id; }); 4951 [current_id](int32_t id) { return id != current_id; });
4869 if (filtered_target_ids.empty()) 4952 if (filtered_target_ids.empty())
4870 return; 4953 return;
4871 4954
4872 CComObject<BrowserAccessibilityRelation>* relation; 4955 CComObject<BrowserAccessibilityRelation>* relation;
4873 HRESULT hr = 4956 HRESULT hr =
4874 CComObject<BrowserAccessibilityRelation>::CreateInstance(&relation); 4957 CComObject<BrowserAccessibilityRelation>::CreateInstance(&relation);
4875 DCHECK(SUCCEEDED(hr)); 4958 DCHECK(SUCCEEDED(hr));
4876 relation->AddRef(); 4959 relation->AddRef();
4877 relation->Initialize(this, relation_type); 4960 relation->Initialize(this, relation_type);
4878 4961
4879 for (int target_id : filtered_target_ids) { 4962 for (int target_id : filtered_target_ids) {
4880 BrowserAccessibilityWin* target = 4963 BrowserAccessibilityComWin* target =
4881 GetFromID(static_cast<int32_t>(target_id)); 4964 GetFromID(static_cast<int32_t>(target_id));
4882 if (!target || !target->instance_active()) 4965 if (!target || !target->GetOwner()->instance_active())
4883 continue; 4966 continue;
4884 relation->AddTarget(target_id); 4967 relation->AddTarget(target_id);
4885 target->AddRelation(reverse_relation_type, GetId()); 4968 target->AddRelation(reverse_relation_type, GetOwner()->GetId());
4886 } 4969 }
4887 4970
4888 relations_.push_back(relation); 4971 relations_.push_back(relation);
4889 } 4972 }
4890 4973
4891 // Clears all the forward relations from this object to any other object and the 4974 // Clears all the forward relations from this object to any other object and the
4892 // associated reverse relations on the other objects, but leaves any reverse 4975 // associated reverse relations on the other objects, but leaves any reverse
4893 // relations on this object alone. 4976 // relations on this object alone.
4894 void BrowserAccessibilityWin::ClearOwnRelations() { 4977 void BrowserAccessibilityComWin::ClearOwnRelations() {
4895 RemoveBidirectionalRelationsOfType(IA2_RELATION_CONTROLLER_FOR, 4978 RemoveBidirectionalRelationsOfType(IA2_RELATION_CONTROLLER_FOR,
4896 IA2_RELATION_CONTROLLED_BY); 4979 IA2_RELATION_CONTROLLED_BY);
4897 RemoveBidirectionalRelationsOfType(IA2_RELATION_DESCRIBED_BY, 4980 RemoveBidirectionalRelationsOfType(IA2_RELATION_DESCRIBED_BY,
4898 IA2_RELATION_DESCRIPTION_FOR); 4981 IA2_RELATION_DESCRIPTION_FOR);
4899 RemoveBidirectionalRelationsOfType(IA2_RELATION_FLOWS_TO, 4982 RemoveBidirectionalRelationsOfType(IA2_RELATION_FLOWS_TO,
4900 IA2_RELATION_FLOWS_FROM); 4983 IA2_RELATION_FLOWS_FROM);
4901 RemoveBidirectionalRelationsOfType(IA2_RELATION_LABELLED_BY, 4984 RemoveBidirectionalRelationsOfType(IA2_RELATION_LABELLED_BY,
4902 IA2_RELATION_LABEL_FOR); 4985 IA2_RELATION_LABEL_FOR);
4903 4986
4904 relations_.erase( 4987 relations_.erase(
4905 std::remove_if(relations_.begin(), relations_.end(), 4988 std::remove_if(relations_.begin(), relations_.end(),
4906 [](BrowserAccessibilityRelation* relation) { 4989 [](BrowserAccessibilityRelation* relation) {
4907 if (relation->get_type() == IA2_RELATION_MEMBER_OF) { 4990 if (relation->get_type() == IA2_RELATION_MEMBER_OF) {
4908 relation->Release(); 4991 relation->Release();
4909 return true; 4992 return true;
4910 } 4993 }
4911 return false; 4994 return false;
4912 }), 4995 }),
4913 relations_.end()); 4996 relations_.end());
4914 } 4997 }
4915 4998
4916 void BrowserAccessibilityWin::RemoveBidirectionalRelationsOfType( 4999 void BrowserAccessibilityComWin::RemoveBidirectionalRelationsOfType(
4917 const base::string16& relation_type, 5000 const base::string16& relation_type,
4918 const base::string16& reverse_relation_type) { 5001 const base::string16& reverse_relation_type) {
4919 for (auto iter = relations_.begin(); iter != relations_.end();) { 5002 for (auto iter = relations_.begin(); iter != relations_.end();) {
4920 BrowserAccessibilityRelation* relation = *iter; 5003 BrowserAccessibilityRelation* relation = *iter;
4921 DCHECK(relation); 5004 DCHECK(relation);
4922 if (relation->get_type() == relation_type) { 5005 if (relation->get_type() == relation_type) {
4923 for (int target_id : relation->get_target_ids()) { 5006 for (int target_id : relation->get_target_ids()) {
4924 BrowserAccessibilityWin* target = 5007 BrowserAccessibilityComWin* target =
4925 GetFromID(static_cast<int32_t>(target_id)); 5008 GetFromID(static_cast<int32_t>(target_id));
4926 if (!target || !target->instance_active()) 5009 if (!target || !target->GetOwner()->instance_active())
4927 continue; 5010 continue;
4928 DCHECK_NE(target, this); 5011 DCHECK_NE(target, this);
4929 target->RemoveTargetFromRelation(reverse_relation_type, GetId()); 5012 target->RemoveTargetFromRelation(reverse_relation_type,
5013 GetOwner()->GetId());
4930 } 5014 }
4931 iter = relations_.erase(iter); 5015 iter = relations_.erase(iter);
4932 relation->Release(); 5016 relation->Release();
4933 } else { 5017 } else {
4934 ++iter; 5018 ++iter;
4935 } 5019 }
4936 } 5020 }
4937 } 5021 }
4938 5022
4939 void BrowserAccessibilityWin::RemoveTargetFromRelation( 5023 void BrowserAccessibilityComWin::RemoveTargetFromRelation(
4940 const base::string16& relation_type, 5024 const base::string16& relation_type,
4941 int target_id) { 5025 int target_id) {
4942 for (auto iter = relations_.begin(); iter != relations_.end();) { 5026 for (auto iter = relations_.begin(); iter != relations_.end();) {
4943 BrowserAccessibilityRelation* relation = *iter; 5027 BrowserAccessibilityRelation* relation = *iter;
4944 DCHECK(relation); 5028 DCHECK(relation);
4945 if (relation->get_type() == relation_type) { 5029 if (relation->get_type() == relation_type) {
4946 // If |target_id| is not present, |RemoveTarget| will do nothing. 5030 // If |target_id| is not present, |RemoveTarget| will do nothing.
4947 relation->RemoveTarget(target_id); 5031 relation->RemoveTarget(target_id);
4948 } 5032 }
4949 if (relation->get_target_ids().empty()) { 5033 if (relation->get_target_ids().empty()) {
4950 iter = relations_.erase(iter); 5034 iter = relations_.erase(iter);
4951 relation->Release(); 5035 relation->Release();
4952 } else { 5036 } else {
4953 ++iter; 5037 ++iter;
4954 } 5038 }
4955 } 5039 }
4956 } 5040 }
4957 5041
4958 void BrowserAccessibilityWin::UpdateRequiredAttributes() { 5042 void BrowserAccessibilityComWin::UpdateRequiredAttributes() {
4959 if (IsCellOrTableHeaderRole()) { 5043 if (GetOwner()->IsCellOrTableHeaderRole()) {
4960 // Expose colspan attribute. 5044 // Expose colspan attribute.
4961 base::string16 colspan; 5045 base::string16 colspan;
4962 if (GetHtmlAttribute("aria-colspan", &colspan)) { 5046 if (GetOwner()->GetHtmlAttribute("aria-colspan", &colspan)) {
4963 SanitizeStringAttributeForIA2(colspan, &colspan); 5047 SanitizeStringAttributeForIA2(colspan, &colspan);
4964 win_attributes_->ia2_attributes.push_back(L"colspan:" + colspan); 5048 win_attributes_->ia2_attributes.push_back(L"colspan:" + colspan);
4965 } 5049 }
4966 // Expose rowspan attribute. 5050 // Expose rowspan attribute.
4967 base::string16 rowspan; 5051 base::string16 rowspan;
4968 if (GetHtmlAttribute("aria-rowspan", &rowspan)) { 5052 if (GetOwner()->GetHtmlAttribute("aria-rowspan", &rowspan)) {
4969 SanitizeStringAttributeForIA2(rowspan, &rowspan); 5053 SanitizeStringAttributeForIA2(rowspan, &rowspan);
4970 win_attributes_->ia2_attributes.push_back(L"rowspan:" + rowspan); 5054 win_attributes_->ia2_attributes.push_back(L"rowspan:" + rowspan);
4971 } 5055 }
4972 } 5056 }
4973 5057
4974 // Expose dropeffect attribute. 5058 // Expose dropeffect attribute.
4975 base::string16 drop_effect; 5059 base::string16 drop_effect;
4976 if (GetHtmlAttribute("aria-dropeffect", &drop_effect)) { 5060 if (GetOwner()->GetHtmlAttribute("aria-dropeffect", &drop_effect)) {
4977 SanitizeStringAttributeForIA2(drop_effect, &drop_effect); 5061 SanitizeStringAttributeForIA2(drop_effect, &drop_effect);
4978 win_attributes_->ia2_attributes.push_back(L"dropeffect:" + drop_effect); 5062 win_attributes_->ia2_attributes.push_back(L"dropeffect:" + drop_effect);
4979 } 5063 }
4980 5064
4981 // Expose grabbed attribute. 5065 // Expose grabbed attribute.
4982 base::string16 grabbed; 5066 base::string16 grabbed;
4983 if (GetHtmlAttribute("aria-grabbed", &grabbed)) { 5067 if (GetOwner()->GetHtmlAttribute("aria-grabbed", &grabbed)) {
4984 SanitizeStringAttributeForIA2(grabbed, &grabbed); 5068 SanitizeStringAttributeForIA2(grabbed, &grabbed);
4985 win_attributes_->ia2_attributes.push_back(L"grabbed:" + grabbed); 5069 win_attributes_->ia2_attributes.push_back(L"grabbed:" + grabbed);
4986 } 5070 }
4987 5071
4988 // Expose class attribute. 5072 // Expose class attribute.
4989 base::string16 class_attr; 5073 base::string16 class_attr;
4990 if (GetHtmlAttribute("class", &class_attr)) { 5074 if (GetOwner()->GetHtmlAttribute("class", &class_attr)) {
4991 SanitizeStringAttributeForIA2(class_attr, &class_attr); 5075 SanitizeStringAttributeForIA2(class_attr, &class_attr);
4992 win_attributes_->ia2_attributes.push_back(L"class:" + class_attr); 5076 win_attributes_->ia2_attributes.push_back(L"class:" + class_attr);
4993 } 5077 }
4994 5078
4995 // Expose datetime attribute. 5079 // Expose datetime attribute.
4996 base::string16 datetime; 5080 base::string16 datetime;
4997 if (GetRole() == ui::AX_ROLE_TIME && 5081 if (GetOwner()->GetRole() == ui::AX_ROLE_TIME &&
4998 GetHtmlAttribute("datetime", &datetime)) { 5082 GetOwner()->GetHtmlAttribute("datetime", &datetime)) {
4999 SanitizeStringAttributeForIA2(datetime, &datetime); 5083 SanitizeStringAttributeForIA2(datetime, &datetime);
5000 win_attributes_->ia2_attributes.push_back(L"datetime:" + datetime); 5084 win_attributes_->ia2_attributes.push_back(L"datetime:" + datetime);
5001 } 5085 }
5002 5086
5003 // Expose id attribute. 5087 // Expose id attribute.
5004 base::string16 id; 5088 base::string16 id;
5005 if (GetHtmlAttribute("id", &id)) { 5089 if (GetOwner()->GetHtmlAttribute("id", &id)) {
5006 SanitizeStringAttributeForIA2(id, &id); 5090 SanitizeStringAttributeForIA2(id, &id);
5007 win_attributes_->ia2_attributes.push_back(L"id:" + id); 5091 win_attributes_->ia2_attributes.push_back(L"id:" + id);
5008 } 5092 }
5009 5093
5010 // Expose src attribute. 5094 // Expose src attribute.
5011 base::string16 src; 5095 base::string16 src;
5012 if (GetRole() == ui::AX_ROLE_IMAGE && GetHtmlAttribute("src", &src)) { 5096 if (GetOwner()->GetRole() == ui::AX_ROLE_IMAGE &&
5097 GetOwner()->GetHtmlAttribute("src", &src)) {
5013 SanitizeStringAttributeForIA2(src, &src); 5098 SanitizeStringAttributeForIA2(src, &src);
5014 win_attributes_->ia2_attributes.push_back(L"src:" + src); 5099 win_attributes_->ia2_attributes.push_back(L"src:" + src);
5015 } 5100 }
5016 5101
5017 // Expose input-text type attribute. 5102 // Expose input-text type attribute.
5018 base::string16 type; 5103 base::string16 type;
5019 base::string16 html_tag = GetString16Attribute(ui::AX_ATTR_HTML_TAG); 5104 base::string16 html_tag =
5020 if (IsSimpleTextControl() && html_tag == L"input" && 5105 GetOwner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG);
5021 GetHtmlAttribute("type", &type)) { 5106 if (GetOwner()->IsSimpleTextControl() && html_tag == L"input" &&
5107 GetOwner()->GetHtmlAttribute("type", &type)) {
5022 SanitizeStringAttributeForIA2(type, &type); 5108 SanitizeStringAttributeForIA2(type, &type);
5023 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type); 5109 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type);
5024 } 5110 }
5025 } 5111 }
5026 5112
5027 void BrowserAccessibilityWin::FireNativeEvent(LONG win_event_type) const { 5113 void BrowserAccessibilityComWin::FireNativeEvent(LONG win_event_type) const {
5028 (new BrowserAccessibilityEventWin( 5114 (new BrowserAccessibilityEventWin(BrowserAccessibilityEvent::FromTreeChange,
5029 BrowserAccessibilityEvent::FromTreeChange, 5115 ui::AX_EVENT_NONE, win_event_type,
5030 ui::AX_EVENT_NONE, 5116 GetOwner()))
5031 win_event_type, 5117 ->Fire();
5032 this))->Fire();
5033 } 5118 }
5034 5119
5035 ui::AXPlatformNodeWin* BrowserAccessibilityWin::GetPlatformNodeWin() const { 5120 void BrowserAccessibilityComWin::InitRoleAndState() {
5036 DCHECK(platform_node_);
5037 return static_cast<ui::AXPlatformNodeWin*>(platform_node_);
5038 }
5039
5040 void BrowserAccessibilityWin::InitRoleAndState() {
5041 int32_t ia_role = 0; 5121 int32_t ia_role = 0;
5042 int32_t ia_state = 0; 5122 int32_t ia_state = 0;
5043 base::string16 role_name; 5123 base::string16 role_name;
5044 int32_t ia2_role = 0; 5124 int32_t ia2_role = 0;
5045 int32_t ia2_state = IA2_STATE_OPAQUE; 5125 int32_t ia2_state = IA2_STATE_OPAQUE;
5046 5126
5047 if (HasState(ui::AX_STATE_BUSY)) 5127 if (GetOwner()->HasState(ui::AX_STATE_BUSY))
5048 ia_state |= STATE_SYSTEM_BUSY; 5128 ia_state |= STATE_SYSTEM_BUSY;
5049 5129
5050 const auto checked_state = static_cast<ui::AXCheckedState>( 5130 const auto checked_state = static_cast<ui::AXCheckedState>(
5051 GetIntAttribute(ui::AX_ATTR_CHECKED_STATE)); 5131 GetOwner()->GetIntAttribute(ui::AX_ATTR_CHECKED_STATE));
5052 switch (checked_state) { 5132 switch (checked_state) {
5053 case ui::AX_CHECKED_STATE_TRUE: 5133 case ui::AX_CHECKED_STATE_TRUE:
5054 ia_state |= STATE_SYSTEM_CHECKED; 5134 ia_state |= STATE_SYSTEM_CHECKED;
5055 break; 5135 break;
5056 case ui::AX_CHECKED_STATE_MIXED: 5136 case ui::AX_CHECKED_STATE_MIXED:
5057 ia_state |= STATE_SYSTEM_MIXED; 5137 ia_state |= STATE_SYSTEM_MIXED;
5058 break; 5138 break;
5059 default: 5139 default:
5060 break; 5140 break;
5061 } 5141 }
5062 5142
5063 if (HasState(ui::AX_STATE_COLLAPSED)) 5143 if (GetOwner()->HasState(ui::AX_STATE_COLLAPSED))
5064 ia_state |= STATE_SYSTEM_COLLAPSED; 5144 ia_state |= STATE_SYSTEM_COLLAPSED;
5065 if (HasState(ui::AX_STATE_EXPANDED)) 5145 if (GetOwner()->HasState(ui::AX_STATE_EXPANDED))
5066 ia_state |= STATE_SYSTEM_EXPANDED; 5146 ia_state |= STATE_SYSTEM_EXPANDED;
5067 if (HasState(ui::AX_STATE_FOCUSABLE)) 5147 if (GetOwner()->HasState(ui::AX_STATE_FOCUSABLE))
5068 ia_state |= STATE_SYSTEM_FOCUSABLE; 5148 ia_state |= STATE_SYSTEM_FOCUSABLE;
5069 if (HasState(ui::AX_STATE_HASPOPUP)) 5149 if (GetOwner()->HasState(ui::AX_STATE_HASPOPUP))
5070 ia_state |= STATE_SYSTEM_HASPOPUP; 5150 ia_state |= STATE_SYSTEM_HASPOPUP;
5071 if (HasIntAttribute(ui::AX_ATTR_INVALID_STATE) && 5151 if (GetOwner()->HasIntAttribute(ui::AX_ATTR_INVALID_STATE) &&
5072 GetIntAttribute(ui::AX_ATTR_INVALID_STATE) != ui::AX_INVALID_STATE_FALSE) 5152 GetOwner()->GetIntAttribute(ui::AX_ATTR_INVALID_STATE) !=
5153 ui::AX_INVALID_STATE_FALSE)
5073 ia2_state |= IA2_STATE_INVALID_ENTRY; 5154 ia2_state |= IA2_STATE_INVALID_ENTRY;
5074 if (HasState(ui::AX_STATE_INVISIBLE)) 5155 if (GetOwner()->HasState(ui::AX_STATE_INVISIBLE))
5075 ia_state |= STATE_SYSTEM_INVISIBLE; 5156 ia_state |= STATE_SYSTEM_INVISIBLE;
5076 if (HasState(ui::AX_STATE_LINKED)) 5157 if (GetOwner()->HasState(ui::AX_STATE_LINKED))
5077 ia_state |= STATE_SYSTEM_LINKED; 5158 ia_state |= STATE_SYSTEM_LINKED;
5078 if (HasState(ui::AX_STATE_MULTISELECTABLE)) { 5159 if (GetOwner()->HasState(ui::AX_STATE_MULTISELECTABLE)) {
5079 ia_state |= STATE_SYSTEM_EXTSELECTABLE; 5160 ia_state |= STATE_SYSTEM_EXTSELECTABLE;
5080 ia_state |= STATE_SYSTEM_MULTISELECTABLE; 5161 ia_state |= STATE_SYSTEM_MULTISELECTABLE;
5081 } 5162 }
5082 // TODO(ctguil): Support STATE_SYSTEM_EXTSELECTABLE/accSelect. 5163 // TODO(ctguil): Support STATE_SYSTEM_EXTSELECTABLE/accSelect.
5083 if (HasState(ui::AX_STATE_OFFSCREEN)) 5164 if (GetOwner()->HasState(ui::AX_STATE_OFFSCREEN))
5084 ia_state |= STATE_SYSTEM_OFFSCREEN; 5165 ia_state |= STATE_SYSTEM_OFFSCREEN;
5085 if (HasState(ui::AX_STATE_PRESSED)) 5166 if (GetOwner()->HasState(ui::AX_STATE_PRESSED))
5086 ia_state |= STATE_SYSTEM_PRESSED; 5167 ia_state |= STATE_SYSTEM_PRESSED;
5087 if (HasState(ui::AX_STATE_PROTECTED)) 5168 if (GetOwner()->HasState(ui::AX_STATE_PROTECTED))
5088 ia_state |= STATE_SYSTEM_PROTECTED; 5169 ia_state |= STATE_SYSTEM_PROTECTED;
5089 if (HasState(ui::AX_STATE_REQUIRED)) 5170 if (GetOwner()->HasState(ui::AX_STATE_REQUIRED))
5090 ia2_state |= IA2_STATE_REQUIRED; 5171 ia2_state |= IA2_STATE_REQUIRED;
5091 if (HasState(ui::AX_STATE_SELECTABLE)) 5172 if (GetOwner()->HasState(ui::AX_STATE_SELECTABLE))
5092 ia_state |= STATE_SYSTEM_SELECTABLE; 5173 ia_state |= STATE_SYSTEM_SELECTABLE;
5093 if (HasState(ui::AX_STATE_SELECTED)) 5174 if (GetOwner()->HasState(ui::AX_STATE_SELECTED))
5094 ia_state |= STATE_SYSTEM_SELECTED; 5175 ia_state |= STATE_SYSTEM_SELECTED;
5095 if (HasState(ui::AX_STATE_VISITED)) 5176 if (GetOwner()->HasState(ui::AX_STATE_VISITED))
5096 ia_state |= STATE_SYSTEM_TRAVERSED; 5177 ia_state |= STATE_SYSTEM_TRAVERSED;
5097 if (HasState(ui::AX_STATE_DISABLED)) 5178 if (GetOwner()->HasState(ui::AX_STATE_DISABLED))
5098 ia_state |= STATE_SYSTEM_UNAVAILABLE; 5179 ia_state |= STATE_SYSTEM_UNAVAILABLE;
5099 if (HasState(ui::AX_STATE_VERTICAL)) 5180 if (GetOwner()->HasState(ui::AX_STATE_VERTICAL))
5100 ia2_state |= IA2_STATE_VERTICAL; 5181 ia2_state |= IA2_STATE_VERTICAL;
5101 if (HasState(ui::AX_STATE_HORIZONTAL)) 5182 if (GetOwner()->HasState(ui::AX_STATE_HORIZONTAL))
5102 ia2_state |= IA2_STATE_HORIZONTAL; 5183 ia2_state |= IA2_STATE_HORIZONTAL;
5103 if (HasState(ui::AX_STATE_VISITED)) 5184 if (GetOwner()->HasState(ui::AX_STATE_VISITED))
5104 ia_state |= STATE_SYSTEM_TRAVERSED; 5185 ia_state |= STATE_SYSTEM_TRAVERSED;
5105 5186
5106 // Expose whether or not the mouse is over an element, but suppress 5187 // Expose whether or not the mouse is over an element, but suppress
5107 // this for tests because it can make the test results flaky depending 5188 // this for tests because it can make the test results flaky depending
5108 // on the position of the mouse. 5189 // on the position of the mouse.
5109 BrowserAccessibilityStateImpl* accessibility_state = 5190 BrowserAccessibilityStateImpl* accessibility_state =
5110 BrowserAccessibilityStateImpl::GetInstance(); 5191 BrowserAccessibilityStateImpl::GetInstance();
5111 if (!accessibility_state->disable_hot_tracking_for_testing()) { 5192 if (!accessibility_state->disable_hot_tracking_for_testing()) {
5112 if (HasState(ui::AX_STATE_HOVERED)) 5193 if (GetOwner()->HasState(ui::AX_STATE_HOVERED))
5113 ia_state |= STATE_SYSTEM_HOTTRACKED; 5194 ia_state |= STATE_SYSTEM_HOTTRACKED;
5114 } 5195 }
5115 5196
5116 if (HasState(ui::AX_STATE_EDITABLE)) 5197 if (GetOwner()->HasState(ui::AX_STATE_EDITABLE))
5117 ia2_state |= IA2_STATE_EDITABLE; 5198 ia2_state |= IA2_STATE_EDITABLE;
5118 5199
5119 if (GetBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE)) 5200 if (GetOwner()->GetBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE))
5120 ia2_state |= IA2_STATE_EDITABLE; 5201 ia2_state |= IA2_STATE_EDITABLE;
5121 5202
5122 if (!GetStringAttribute(ui::AX_ATTR_AUTO_COMPLETE).empty()) 5203 if (!GetOwner()->GetStringAttribute(ui::AX_ATTR_AUTO_COMPLETE).empty())
5123 ia2_state |= IA2_STATE_SUPPORTS_AUTOCOMPLETION; 5204 ia2_state |= IA2_STATE_SUPPORTS_AUTOCOMPLETION;
5124 5205
5125 if (GetBoolAttribute(ui::AX_ATTR_MODAL)) 5206 if (GetOwner()->GetBoolAttribute(ui::AX_ATTR_MODAL))
5126 ia2_state |= IA2_STATE_MODAL; 5207 ia2_state |= IA2_STATE_MODAL;
5127 5208
5128 base::string16 html_tag = GetString16Attribute( 5209 base::string16 html_tag =
5129 ui::AX_ATTR_HTML_TAG); 5210 GetOwner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG);
5130 switch (GetRole()) { 5211 switch (GetOwner()->GetRole()) {
5131 case ui::AX_ROLE_ALERT: 5212 case ui::AX_ROLE_ALERT:
5132 ia_role = ROLE_SYSTEM_ALERT; 5213 ia_role = ROLE_SYSTEM_ALERT;
5133 break; 5214 break;
5134 case ui::AX_ROLE_ALERT_DIALOG: 5215 case ui::AX_ROLE_ALERT_DIALOG:
5135 ia_role = ROLE_SYSTEM_DIALOG; 5216 ia_role = ROLE_SYSTEM_DIALOG;
5136 break; 5217 break;
5137 case ui::AX_ROLE_ANCHOR: 5218 case ui::AX_ROLE_ANCHOR:
5138 ia_role = ROLE_SYSTEM_LINK; 5219 ia_role = ROLE_SYSTEM_LINK;
5139 break; 5220 break;
5140 case ui::AX_ROLE_APPLICATION: 5221 case ui::AX_ROLE_APPLICATION:
(...skipping 15 matching lines...) Expand all
5156 ia2_role = IA2_ROLE_SECTION; 5237 ia2_role = IA2_ROLE_SECTION;
5157 break; 5238 break;
5158 case ui::AX_ROLE_BUSY_INDICATOR: 5239 case ui::AX_ROLE_BUSY_INDICATOR:
5159 ia_role = ROLE_SYSTEM_ANIMATION; 5240 ia_role = ROLE_SYSTEM_ANIMATION;
5160 ia_state |= STATE_SYSTEM_READONLY; 5241 ia_state |= STATE_SYSTEM_READONLY;
5161 break; 5242 break;
5162 case ui::AX_ROLE_BUTTON: 5243 case ui::AX_ROLE_BUTTON:
5163 ia_role = ROLE_SYSTEM_PUSHBUTTON; 5244 ia_role = ROLE_SYSTEM_PUSHBUTTON;
5164 break; 5245 break;
5165 case ui::AX_ROLE_CANVAS: 5246 case ui::AX_ROLE_CANVAS:
5166 if (GetBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK)) { 5247 if (GetOwner()->GetBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK)) {
5167 role_name = L"canvas"; 5248 role_name = L"canvas";
5168 ia2_role = IA2_ROLE_CANVAS; 5249 ia2_role = IA2_ROLE_CANVAS;
5169 } else { 5250 } else {
5170 ia_role = ROLE_SYSTEM_GRAPHIC; 5251 ia_role = ROLE_SYSTEM_GRAPHIC;
5171 } 5252 }
5172 break; 5253 break;
5173 case ui::AX_ROLE_CAPTION: 5254 case ui::AX_ROLE_CAPTION:
5174 ia_role = ROLE_SYSTEM_TEXT; 5255 ia_role = ROLE_SYSTEM_TEXT;
5175 ia2_role = IA2_ROLE_CAPTION; 5256 ia2_role = IA2_ROLE_CAPTION;
5176 break; 5257 break;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
5242 ia_role = ROLE_SYSTEM_PUSHBUTTON; 5323 ia_role = ROLE_SYSTEM_PUSHBUTTON;
5243 break; 5324 break;
5244 case ui::AX_ROLE_DOCUMENT: 5325 case ui::AX_ROLE_DOCUMENT:
5245 case ui::AX_ROLE_ROOT_WEB_AREA: 5326 case ui::AX_ROLE_ROOT_WEB_AREA:
5246 case ui::AX_ROLE_WEB_AREA: 5327 case ui::AX_ROLE_WEB_AREA:
5247 ia_role = ROLE_SYSTEM_DOCUMENT; 5328 ia_role = ROLE_SYSTEM_DOCUMENT;
5248 ia_state |= STATE_SYSTEM_READONLY; 5329 ia_state |= STATE_SYSTEM_READONLY;
5249 ia_state |= STATE_SYSTEM_FOCUSABLE; 5330 ia_state |= STATE_SYSTEM_FOCUSABLE;
5250 break; 5331 break;
5251 case ui::AX_ROLE_EMBEDDED_OBJECT: 5332 case ui::AX_ROLE_EMBEDDED_OBJECT:
5252 if (PlatformChildCount()) { 5333 if (GetOwner()->PlatformChildCount()) {
5253 // Windows screen readers assume that IA2_ROLE_EMBEDDED_OBJECT 5334 // Windows screen readers assume that IA2_ROLE_EMBEDDED_OBJECT
5254 // doesn't have any children, but it may be something like a 5335 // doesn't have any children, but it may be something like a
5255 // browser plugin that has a document inside. 5336 // browser plugin that has a document inside.
5256 ia_role = ROLE_SYSTEM_GROUPING; 5337 ia_role = ROLE_SYSTEM_GROUPING;
5257 } else { 5338 } else {
5258 ia_role = ROLE_SYSTEM_CLIENT; 5339 ia_role = ROLE_SYSTEM_CLIENT;
5259 ia2_role = IA2_ROLE_EMBEDDED_OBJECT; 5340 ia2_role = IA2_ROLE_EMBEDDED_OBJECT;
5260 } 5341 }
5261 break; 5342 break;
5262 case ui::AX_ROLE_FIGCAPTION: 5343 case ui::AX_ROLE_FIGCAPTION:
(...skipping 15 matching lines...) Expand all
5278 ia2_role = IA2_ROLE_FOOTER; 5359 ia2_role = IA2_ROLE_FOOTER;
5279 break; 5360 break;
5280 case ui::AX_ROLE_GRID: 5361 case ui::AX_ROLE_GRID:
5281 ia_role = ROLE_SYSTEM_TABLE; 5362 ia_role = ROLE_SYSTEM_TABLE;
5282 // TODO(aleventhal) this changed between ARIA 1.0 and 1.1, 5363 // TODO(aleventhal) this changed between ARIA 1.0 and 1.1,
5283 // need to determine whether grids/treegrids should really be readonly 5364 // need to determine whether grids/treegrids should really be readonly
5284 // or editable by default 5365 // or editable by default
5285 // ia_state |= STATE_SYSTEM_READONLY; 5366 // ia_state |= STATE_SYSTEM_READONLY;
5286 break; 5367 break;
5287 case ui::AX_ROLE_GROUP: { 5368 case ui::AX_ROLE_GROUP: {
5288 base::string16 aria_role = GetString16Attribute( 5369 base::string16 aria_role =
5289 ui::AX_ATTR_ROLE); 5370 GetOwner()->GetString16Attribute(ui::AX_ATTR_ROLE);
5290 if (aria_role == L"group" || html_tag == L"fieldset") { 5371 if (aria_role == L"group" || html_tag == L"fieldset") {
5291 ia_role = ROLE_SYSTEM_GROUPING; 5372 ia_role = ROLE_SYSTEM_GROUPING;
5292 } else if (html_tag == L"li") { 5373 } else if (html_tag == L"li") {
5293 ia_role = ROLE_SYSTEM_LISTITEM; 5374 ia_role = ROLE_SYSTEM_LISTITEM;
5294 ia_state |= STATE_SYSTEM_READONLY; 5375 ia_state |= STATE_SYSTEM_READONLY;
5295 } else { 5376 } else {
5296 if (html_tag.empty()) 5377 if (html_tag.empty())
5297 role_name = L"div"; 5378 role_name = L"div";
5298 else 5379 else
5299 role_name = html_tag; 5380 role_name = html_tag;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
5448 if (html_tag == L"section") { 5529 if (html_tag == L"section") {
5449 ia_role = ROLE_SYSTEM_GROUPING; 5530 ia_role = ROLE_SYSTEM_GROUPING;
5450 ia2_role = IA2_ROLE_SECTION; 5531 ia2_role = IA2_ROLE_SECTION;
5451 } else { 5532 } else {
5452 ia_role = ROLE_SYSTEM_PANE; 5533 ia_role = ROLE_SYSTEM_PANE;
5453 } 5534 }
5454 break; 5535 break;
5455 case ui::AX_ROLE_ROW: { 5536 case ui::AX_ROLE_ROW: {
5456 // Role changes depending on whether row is inside a treegrid 5537 // Role changes depending on whether row is inside a treegrid
5457 // https://www.w3.org/TR/core-aam-1.1/#role-map-row 5538 // https://www.w3.org/TR/core-aam-1.1/#role-map-row
5458 ia_role = IsInTreeGrid(this) ? ROLE_SYSTEM_OUTLINEITEM : ROLE_SYSTEM_ROW; 5539 ia_role =
5540 IsInTreeGrid(GetOwner()) ? ROLE_SYSTEM_OUTLINEITEM : ROLE_SYSTEM_ROW;
5459 break; 5541 break;
5460 } 5542 }
5461 case ui::AX_ROLE_ROW_HEADER: 5543 case ui::AX_ROLE_ROW_HEADER:
5462 ia_role = ROLE_SYSTEM_ROWHEADER; 5544 ia_role = ROLE_SYSTEM_ROWHEADER;
5463 break; 5545 break;
5464 case ui::AX_ROLE_RUBY: 5546 case ui::AX_ROLE_RUBY:
5465 ia_role = ROLE_SYSTEM_TEXT; 5547 ia_role = ROLE_SYSTEM_TEXT;
5466 ia2_role = IA2_ROLE_TEXT_FRAME; 5548 ia2_role = IA2_ROLE_TEXT_FRAME;
5467 break; 5549 break;
5468 case ui::AX_ROLE_RULER: 5550 case ui::AX_ROLE_RULER:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
5531 ia_role = ROLE_SYSTEM_LISTITEM; 5613 ia_role = ROLE_SYSTEM_LISTITEM;
5532 ia_state |= STATE_SYSTEM_READONLY; 5614 ia_state |= STATE_SYSTEM_READONLY;
5533 break; 5615 break;
5534 case ui::AX_ROLE_TOGGLE_BUTTON: 5616 case ui::AX_ROLE_TOGGLE_BUTTON:
5535 ia_role = ROLE_SYSTEM_PUSHBUTTON; 5617 ia_role = ROLE_SYSTEM_PUSHBUTTON;
5536 ia2_role = IA2_ROLE_TOGGLE_BUTTON; 5618 ia2_role = IA2_ROLE_TOGGLE_BUTTON;
5537 break; 5619 break;
5538 case ui::AX_ROLE_TEXT_FIELD: 5620 case ui::AX_ROLE_TEXT_FIELD:
5539 case ui::AX_ROLE_SEARCH_BOX: 5621 case ui::AX_ROLE_SEARCH_BOX:
5540 ia_role = ROLE_SYSTEM_TEXT; 5622 ia_role = ROLE_SYSTEM_TEXT;
5541 if (HasState(ui::AX_STATE_MULTILINE)) { 5623 if (GetOwner()->HasState(ui::AX_STATE_MULTILINE)) {
5542 ia2_state |= IA2_STATE_MULTI_LINE; 5624 ia2_state |= IA2_STATE_MULTI_LINE;
5543 } else { 5625 } else {
5544 ia2_state |= IA2_STATE_SINGLE_LINE; 5626 ia2_state |= IA2_STATE_SINGLE_LINE;
5545 } 5627 }
5546 if (HasState(ui::AX_STATE_READ_ONLY)) 5628 if (GetOwner()->HasState(ui::AX_STATE_READ_ONLY))
5547 ia_state |= STATE_SYSTEM_READONLY; 5629 ia_state |= STATE_SYSTEM_READONLY;
5548 ia2_state |= IA2_STATE_SELECTABLE_TEXT; 5630 ia2_state |= IA2_STATE_SELECTABLE_TEXT;
5549 break; 5631 break;
5550 case ui::AX_ROLE_ABBR: 5632 case ui::AX_ROLE_ABBR:
5551 case ui::AX_ROLE_TIME: 5633 case ui::AX_ROLE_TIME:
5552 role_name = html_tag; 5634 role_name = html_tag;
5553 ia_role = ROLE_SYSTEM_TEXT; 5635 ia_role = ROLE_SYSTEM_TEXT;
5554 ia2_role = IA2_ROLE_TEXT_FRAME; 5636 ia2_role = IA2_ROLE_TEXT_FRAME;
5555 break; 5637 break;
5556 case ui::AX_ROLE_TIMER: 5638 case ui::AX_ROLE_TIMER:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5595 ia_role = ROLE_SYSTEM_CLIENT; 5677 ia_role = ROLE_SYSTEM_CLIENT;
5596 break; 5678 break;
5597 } 5679 }
5598 5680
5599 // Compute the final value of READONLY for MSAA. 5681 // Compute the final value of READONLY for MSAA.
5600 // 5682 //
5601 // We always set the READONLY state for elements that have the 5683 // We always set the READONLY state for elements that have the
5602 // aria-readonly attribute and for a few roles (in the switch above), 5684 // aria-readonly attribute and for a few roles (in the switch above),
5603 // including read-only text fields. 5685 // including read-only text fields.
5604 // The majority of focusable controls should not have the read-only state set. 5686 // The majority of focusable controls should not have the read-only state set.
5605 if (HasState(ui::AX_STATE_FOCUSABLE) && ia_role != ROLE_SYSTEM_DOCUMENT && 5687 if (GetOwner()->HasState(ui::AX_STATE_FOCUSABLE) &&
5606 ia_role != ROLE_SYSTEM_TEXT) { 5688 ia_role != ROLE_SYSTEM_DOCUMENT && ia_role != ROLE_SYSTEM_TEXT) {
5607 ia_state &= ~(STATE_SYSTEM_READONLY); 5689 ia_state &= ~(STATE_SYSTEM_READONLY);
5608 } 5690 }
5609 if (!HasState(ui::AX_STATE_READ_ONLY)) 5691 if (!GetOwner()->HasState(ui::AX_STATE_READ_ONLY))
5610 ia_state &= ~(STATE_SYSTEM_READONLY); 5692 ia_state &= ~(STATE_SYSTEM_READONLY);
5611 if (GetBoolAttribute(ui::AX_ATTR_ARIA_READONLY)) 5693 if (GetOwner()->GetBoolAttribute(ui::AX_ATTR_ARIA_READONLY))
5612 ia_state |= STATE_SYSTEM_READONLY; 5694 ia_state |= STATE_SYSTEM_READONLY;
5613 5695
5614 // The role should always be set. 5696 // The role should always be set.
5615 DCHECK(!role_name.empty() || ia_role); 5697 DCHECK(!role_name.empty() || ia_role);
5616 5698
5617 // If we didn't explicitly set the IAccessible2 role, make it the same 5699 // If we didn't explicitly set the IAccessible2 role, make it the same
5618 // as the MSAA role. 5700 // as the MSAA role.
5619 if (!ia2_role) 5701 if (!ia2_role)
5620 ia2_role = ia_role; 5702 ia2_role = ia_role;
5621 5703
5622 win_attributes_->ia_role = ia_role; 5704 win_attributes_->ia_role = ia_role;
5623 win_attributes_->ia_state = ia_state; 5705 win_attributes_->ia_state = ia_state;
5624 win_attributes_->role_name = role_name; 5706 win_attributes_->role_name = role_name;
5625 win_attributes_->ia2_role = ia2_role; 5707 win_attributes_->ia2_role = ia2_role;
5626 win_attributes_->ia2_state = ia2_state; 5708 win_attributes_->ia2_state = ia2_state;
5627 } 5709 }
5628 5710
5629 bool BrowserAccessibilityWin::IsInTreeGrid(const BrowserAccessibility* item) { 5711 bool BrowserAccessibilityComWin::IsInTreeGrid(
5712 const BrowserAccessibility* item) {
5630 BrowserAccessibility* container = item->PlatformGetParent(); 5713 BrowserAccessibility* container = item->PlatformGetParent();
5631 if (container && container->GetRole() == ui::AX_ROLE_GROUP) { 5714 if (container && container->GetRole() == ui::AX_ROLE_GROUP) {
5632 // If parent was a rowgroup, we need to look at the grandparent 5715 // If parent was a rowgroup, we need to look at the grandparent
5633 container = container->PlatformGetParent(); 5716 container = container->PlatformGetParent();
5634 } 5717 }
5635 5718
5636 if (!container) { 5719 if (!container) {
5637 return false; 5720 return false;
5638 } 5721 }
5639 5722
5640 return container->GetRole() == ui::AX_ROLE_TREE_GRID; 5723 return container->GetRole() == ui::AX_ROLE_TREE_GRID;
5641 } 5724 }
5642 5725
5643 BrowserAccessibilityWin* ToBrowserAccessibilityWin(BrowserAccessibility* obj) { 5726 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin(
5644 DCHECK(!obj || obj->IsNative()); 5727 BrowserAccessibility* obj) {
5645 return static_cast<BrowserAccessibilityWin*>(obj); 5728 if (!obj || !obj->IsNative())
5646 } 5729 return nullptr;
5647 5730 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM();
5648 const BrowserAccessibilityWin* 5731 return result;
5649 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) {
5650 DCHECK(!obj || obj->IsNative());
5651 return static_cast<const BrowserAccessibilityWin*>(obj);
5652 } 5732 }
5653 5733
5654 } // namespace content 5734 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698