| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef AXObject_h | 5 #ifndef AXObject_h |
| 6 #define AXObject_h | 6 #define AXObject_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 kAXDescriptionFromUninitialized = -1, | 281 kAXDescriptionFromUninitialized = -1, |
| 282 kAXDescriptionFromAttribute = 0, | 282 kAXDescriptionFromAttribute = 0, |
| 283 kAXDescriptionFromContents, | 283 kAXDescriptionFromContents, |
| 284 kAXDescriptionFromRelatedElement, | 284 kAXDescriptionFromRelatedElement, |
| 285 }; | 285 }; |
| 286 | 286 |
| 287 // TODO(sashab): Add pure virtual methods to this class to remove dependencies | 287 // TODO(sashab): Add pure virtual methods to this class to remove dependencies |
| 288 // on AXObjectImpl from outside of modules/. | 288 // on AXObjectImpl from outside of modules/. |
| 289 class CORE_EXPORT AXObject { | 289 class CORE_EXPORT AXObject { |
| 290 public: | 290 public: |
| 291 typedef HeapVector<Member<AXObject>> AXObjectVector; |
| 292 |
| 293 struct AXRange { |
| 294 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 295 // The deepest descendant in which the range starts. |
| 296 // (nullptr means the current object.) |
| 297 Persistent<AXObject> anchor_object; |
| 298 // The number of characters and child objects in the anchor object |
| 299 // before the range starts. |
| 300 int anchor_offset; |
| 301 // When the same character offset could correspond to two possible |
| 302 // cursor positions, upstream means it's on the previous line rather |
| 303 // than the next line. |
| 304 TextAffinity anchor_affinity; |
| 305 |
| 306 // The deepest descendant in which the range ends. |
| 307 // (nullptr means the current object.) |
| 308 Persistent<AXObject> focus_object; |
| 309 // The number of characters and child objects in the focus object |
| 310 // before the range ends. |
| 311 int focus_offset; |
| 312 // When the same character offset could correspond to two possible |
| 313 // cursor positions, upstream means it's on the previous line rather |
| 314 // than the next line. |
| 315 TextAffinity focus_affinity; |
| 316 |
| 317 AXRange() |
| 318 : anchor_object(nullptr), |
| 319 anchor_offset(-1), |
| 320 anchor_affinity(TextAffinity::kUpstream), |
| 321 focus_object(nullptr), |
| 322 focus_offset(-1), |
| 323 focus_affinity(TextAffinity::kDownstream) {} |
| 324 |
| 325 AXRange(int start_offset, int end_offset) |
| 326 : anchor_object(nullptr), |
| 327 anchor_offset(start_offset), |
| 328 anchor_affinity(TextAffinity::kUpstream), |
| 329 focus_object(nullptr), |
| 330 focus_offset(end_offset), |
| 331 focus_affinity(TextAffinity::kDownstream) {} |
| 332 |
| 333 AXRange(AXObjectImpl* anchor_object, |
| 334 int anchor_offset, |
| 335 TextAffinity anchor_affinity, |
| 336 AXObject* focus_object, |
| 337 int focus_offset, |
| 338 TextAffinity focus_affinity) |
| 339 : anchor_object(anchor_object), |
| 340 anchor_offset(anchor_offset), |
| 341 anchor_affinity(anchor_affinity), |
| 342 focus_object(focus_object), |
| 343 focus_offset(focus_offset), |
| 344 focus_affinity(focus_affinity) {} |
| 345 |
| 346 bool IsValid() const { |
| 347 return ((anchor_object && focus_object) || |
| 348 (!anchor_object && !focus_object)) && |
| 349 anchor_offset >= 0 && focus_offset >= 0; |
| 350 } |
| 351 |
| 352 // Determines if the range only refers to text offsets under the current |
| 353 // object. |
| 354 bool IsSimple() const { |
| 355 return anchor_object == focus_object || !anchor_object || !focus_object; |
| 356 } |
| 357 }; |
| 358 |
| 291 // Static helper functions. | 359 // Static helper functions. |
| 292 static bool IsInsideFocusableElementOrARIAWidget(const Node&); | 360 static bool IsInsideFocusableElementOrARIAWidget(const Node&); |
| 361 |
| 362 // Properties of static elements. |
| 363 virtual const AtomicString& AccessKey() const = 0; |
| 364 virtual bool CanvasHasFallbackContent() const = 0; |
| 365 virtual String FontFamily() const = 0; |
| 366 // Font size is in pixels. |
| 367 virtual float FontSize() const = 0; |
| 368 |
| 369 // Value should be 1-based. 0 means not supported. |
| 370 virtual int HeadingLevel() const { return 0; } |
| 371 // Value should be 1-based. 0 means not supported. |
| 372 virtual unsigned HierarchicalLevel() const { return 0; } |
| 373 // Return the content of an image or canvas as an image data url in |
| 374 // PNG format. If |maxSize| is not empty and if the image is larger than |
| 375 // those dimensions, the image will be resized proportionally first to fit. |
| 376 virtual String ImageDataUrl(const IntSize& max_size) const = 0; |
| 377 virtual AXObject* InPageLinkTarget() const = 0; |
| 378 virtual AccessibilityOrientation Orientation() const = 0; |
| 379 virtual AccessibilityTextDirection GetTextDirection() const = 0; |
| 380 virtual TextStyle GetTextStyle() const = 0; |
| 381 virtual AXObjectVector RadioButtonsInGroup() const = 0; |
| 382 virtual KURL Url() const = 0; |
| 383 |
| 384 // Load inline text boxes for just this node, even if |
| 385 // settings->inlineTextBoxAccessibilityEnabled() is false. |
| 386 virtual void LoadInlineTextBoxes() = 0; |
| 387 |
| 388 // Walk the AXObjects on the same line. This is supported on any |
| 389 // object type but primarily intended to be used for inline text boxes. |
| 390 virtual AXObject* NextOnLine() const = 0; |
| 391 virtual AXObject* PreviousOnLine() const = 0; |
| 392 |
| 393 // For all node objects. The start and end character offset of each |
| 394 // marker, such as spelling or grammar error. |
| 395 virtual void Markers(Vector<DocumentMarker::MarkerType>&, |
| 396 Vector<AXRange>&) const = 0; |
| 397 // For an inline text box. |
| 398 // The integer horizontal pixel offset of each character in the string; |
| 399 // negative values for RTL. |
| 400 virtual void TextCharacterOffsets(Vector<int>&) const = 0; |
| 401 // The start and end character offset of each word in the object's text. |
| 402 virtual void GetWordBoundaries(Vector<AXRange>&) const = 0; |
| 403 |
| 404 // Properties of interactive elements. |
| 405 virtual InvalidState GetInvalidState() const = 0; |
| 406 // Only used when invalidState() returns InvalidStateOther. |
| 407 virtual String AriaInvalidValue() const = 0; |
| 408 virtual String ValueDescription() const = 0; |
| 409 virtual float ValueForRange() const = 0; |
| 410 virtual float MaxValueForRange() const = 0; |
| 411 virtual float MinValueForRange() const = 0; |
| 412 virtual String StringValue() const = 0; |
| 413 |
| 414 // ARIA attributes. |
| 415 virtual bool SupportsRangeValue() const = 0; |
| 416 |
| 417 // Properties of the object's owning document or page. |
| 418 virtual double EstimatedLoadingProgress() const = 0; |
| 419 |
| 420 // ARIA live-region features. |
| 421 virtual AXObject* LiveRegionRoot() const = 0; |
| 422 |
| 423 // DOM and layout tree access. |
| 424 virtual Node* GetNode() const = 0; |
| 425 virtual LocalFrameView* DocumentFrameView() const = 0; |
| 426 |
| 427 // Get the bounds in frame-relative coordinates as a LayoutRect. |
| 428 virtual LayoutRect GetBoundsInFrameCoordinates() const = 0; |
| 429 |
| 430 // Every object's bounding box is returned relative to a |
| 431 // container object (which is guaranteed to be an ancestor) and |
| 432 // optionally a transformation matrix that needs to be applied too. |
| 433 // To compute the absolute bounding box of an element, start with its |
| 434 // boundsInContainer and apply the transform. Then as long as its container is |
| 435 // not null, walk up to its container and offset by the container's offset |
| 436 // from origin, the container's scroll position if any, and apply the |
| 437 // container's transform. Do this until you reach the root of the tree. |
| 438 virtual void GetRelativeBounds(AXObject** out_container, |
| 439 FloatRect& out_bounds_in_container, |
| 440 SkMatrix44& out_container_transform) const; |
| 441 |
| 442 // Hit testing. |
| 443 // Called on the root AX object to return the deepest available element. |
| 444 virtual AXObject* AccessibilityHitTest(const IntPoint&) const = 0; |
| 445 |
| 446 virtual const AtomicString& ContainerLiveRegionStatus() const = 0; |
| 447 virtual const AtomicString& ContainerLiveRegionRelevant() const = 0; |
| 448 virtual bool ContainerLiveRegionAtomic() const = 0; |
| 449 virtual bool ContainerLiveRegionBusy() const = 0; |
| 450 |
| 451 // DOM and layout tree access. |
| 452 virtual Node* GetNode() const = 0; |
| 453 virtual Document* GetDocument() const = 0; |
| 454 virtual String Language() const = 0; |
| 455 |
| 456 // Scrollable containers. |
| 457 virtual bool IsScrollableContainer() const = 0; |
| 458 virtual IntPoint GetScrollOffset() const = 0; |
| 459 virtual IntPoint MinimumScrollOffset() const = 0; |
| 460 virtual IntPoint MaximumScrollOffset() const = 0; |
| 461 virtual void SetScrollOffset(const IntPoint&) const = 0; |
| 462 |
| 463 // Modify or take an action on an object. |
| 464 virtual void Increment() = 0; |
| 465 virtual void Decrement() = 0; |
| 466 virtual bool PerformDefaultAction() = 0; |
| 467 virtual bool Press() = 0; |
| 468 // Make this object visible by scrolling as many nested scrollable views as |
| 469 // needed. |
| 470 virtual void ScrollToMakeVisible() const = 0; |
| 471 // Same, but if the whole object can't be made visible, try for this subrect, |
| 472 // in local coordinates. |
| 473 virtual void ScrollToMakeVisibleWithSubFocus(const IntRect&) const = 0; |
| 474 // Scroll this object to a given point in global coordinates of the top-level |
| 475 // window. |
| 476 virtual void ScrollToGlobalPoint(const IntPoint&) const = 0; |
| 477 virtual void SetFocused(bool) = 0; |
| 478 virtual void SetSequentialFocusNavigationStartingPoint() = 0; |
| 479 virtual void SetValue(const String&) = 0; |
| 480 |
| 481 // Check object role or purpose. |
| 482 virtual AccessibilityRole RoleValue() const = 0; |
| 483 |
| 484 // Methods that retrieve or manipulate the current selection. |
| 485 |
| 486 // Get the current selection from anywhere in the accessibility tree. |
| 487 virtual AXRange Selection() const { return AXRange(); } |
| 488 // Gets only the start and end offsets of the selection computed using the |
| 489 // current object as the starting point. Returns a null selection if there is |
| 490 // no selection in the subtree rooted at this object. |
| 491 virtual AXRange SelectionUnderObject() const { return AXRange(); } |
| 492 virtual void SetSelection(const AXRange&) {} |
| 493 |
| 494 // Text metrics. Most of these should be deprecated, needs major cleanup. |
| 495 virtual VisiblePosition VisiblePositionForIndex(int) const = 0; |
| 496 virtual int LineForPosition(const VisiblePosition&) const = 0; |
| 497 virtual void LineBreaks(Vector<int>&) const = 0; |
| 498 |
| 499 // Whether objects are ignored, i.e. not included in the tree. |
| 500 virtual bool AccessibilityIsIgnored() = 0; |
| 501 ; |
| 502 |
| 503 // Accessible name calculation |
| 504 |
| 505 // Retrieves the accessible name of the object, an enum indicating where the |
| 506 // name was derived from, and a list of objects that were used to derive the |
| 507 // name, if any. |
| 508 virtual String GetName(AXNameFrom&, AXObjectVector* name_objects) const = 0; |
| 509 |
| 510 typedef HeapVector<DescriptionSource> DescriptionSources; |
| 511 // Takes the result of nameFrom from calling |name|, above, and retrieves the |
| 512 // accessible description of the object, which is secondary to |name|, an enum |
| 513 // indicating where the description was derived from, and a list of objects |
| 514 // that were used to derive the description, if any. |
| 515 virtual String Description(AXNameFrom, |
| 516 AXDescriptionFrom&, |
| 517 AXObjectVector* description_objects) const = 0; |
| 518 |
| 519 // Takes the result of nameFrom and descriptionFrom from calling |name| and |
| 520 // |description|, above, and retrieves the placeholder of the object, if |
| 521 // present and if it wasn't already exposed by one of the two functions above. |
| 522 virtual String Placeholder(AXNameFrom) const = 0; |
| 523 |
| 524 // Methods from WebAXObject. |
| 525 // For a table |
| 526 virtual int AriaColumnCount() const = 0; |
| 527 virtual unsigned AriaColumnIndex() const = 0; |
| 528 virtual int AriaRowCount() const = 0; |
| 529 virtual unsigned AriaRowIndex() const = 0; |
| 530 virtual unsigned ColumnCount() const = 0; |
| 531 virtual unsigned RowCount() const = 0; |
| 532 virtual WebAXObject CellForColumnAndRow(unsigned column, |
| 533 unsigned row) const = 0; |
| 534 virtual WebAXObject HeaderContainerObject() const = 0; |
| 535 virtual WebAXObject RowAtIndex(unsigned row_index) const = 0; |
| 536 virtual WebAXObject ColumnAtIndex(unsigned column_index) const = 0; |
| 537 virtual void RowHeaders(WebVector<WebAXObject>&) const = 0; |
| 538 virtual void ColumnHeaders(WebVector<WebAXObject>&) const = 0; |
| 539 |
| 540 // For a table row |
| 541 virtual unsigned RowIndex() const = 0; |
| 542 virtual WebAXObject RowHeader() const = 0; |
| 543 |
| 544 // For a table column |
| 545 virtual unsigned ColumnIndex() const = 0; |
| 546 virtual WebAXObject ColumnHeader() const = 0; |
| 547 |
| 548 // For a table cell |
| 549 virtual unsigned CellColumnIndex() const = 0; |
| 550 virtual unsigned CellColumnSpan() const = 0; |
| 551 virtual unsigned CellRowIndex() const = 0; |
| 552 virtual unsigned CellRowSpan() const = 0; |
| 553 virtual WebAXSortDirection SortDirection() const = 0; |
| 293 }; | 554 }; |
| 294 | 555 |
| 295 } // namespace blink | 556 } // namespace blink |
| 296 | 557 |
| 297 #endif // AXObject_h | 558 #endif // AXObject_h |
| OLD | NEW |