Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebAXObject.cpp
blobbdc91c392ea8230916eff8a7de9e2f86c4acb17d
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "config.h"
32 #include "public/web/WebAXObject.h"
34 #include "core/HTMLNames.h"
35 #include "core/css/CSSPrimitiveValueMappings.h"
36 #include "core/dom/Document.h"
37 #include "core/dom/Node.h"
38 #include "core/frame/FrameHost.h"
39 #include "core/frame/FrameView.h"
40 #include "core/frame/VisualViewport.h"
41 #include "core/input/EventHandler.h"
42 #include "core/layout/LayoutView.h"
43 #include "core/style/ComputedStyle.h"
44 #include "core/page/Page.h"
45 #include "modules/accessibility/AXObject.h"
46 #include "modules/accessibility/AXObjectCacheImpl.h"
47 #include "modules/accessibility/AXTable.h"
48 #include "modules/accessibility/AXTableCell.h"
49 #include "modules/accessibility/AXTableColumn.h"
50 #include "modules/accessibility/AXTableRow.h"
51 #include "platform/PlatformKeyboardEvent.h"
52 #include "public/platform/WebPoint.h"
53 #include "public/platform/WebRect.h"
54 #include "public/platform/WebString.h"
55 #include "public/platform/WebURL.h"
56 #include "public/web/WebDocument.h"
57 #include "public/web/WebElement.h"
58 #include "public/web/WebNode.h"
59 #include "web/WebLocalFrameImpl.h"
60 #include "web/WebViewImpl.h"
61 #include "wtf/text/StringBuilder.h"
63 namespace blink {
65 #if ENABLE(ASSERT)
66 // It's not safe to call some WebAXObject APIs if a layout is pending.
67 // Clients should call updateLayoutAndCheckValidity first.
68 static bool isLayoutClean(Document* document)
70 if (!document || !document->view())
71 return false;
72 return document->lifecycle().state() >= DocumentLifecycle::LayoutClean
73 || ((document->lifecycle().state() == DocumentLifecycle::StyleClean || document->lifecycle().state() == DocumentLifecycle::LayoutSubtreeChangeClean)
74 && !document->view()->needsLayout());
76 #endif
78 WebScopedAXContext::WebScopedAXContext(WebDocument& rootDocument)
79 : m_private(ScopedAXObjectCache::create(*rootDocument.unwrap<Document>()))
83 WebScopedAXContext::~WebScopedAXContext()
85 m_private.reset(0);
88 WebAXObject WebScopedAXContext::root() const
90 return WebAXObject(static_cast<AXObjectCacheImpl*>(m_private->get())->root());
93 void WebAXObject::reset()
95 m_private.reset();
98 void WebAXObject::assign(const WebAXObject& other)
100 m_private = other.m_private;
103 bool WebAXObject::equals(const WebAXObject& n) const
105 return m_private.get() == n.m_private.get();
108 bool WebAXObject::isDetached() const
110 if (m_private.isNull())
111 return true;
113 return m_private->isDetached();
116 int WebAXObject::axID() const
118 if (isDetached())
119 return -1;
121 return m_private->axObjectID();
124 bool WebAXObject::updateLayoutAndCheckValidity()
126 if (!isDetached()) {
127 Document* document = m_private->document();
128 if (!document || !document->topDocument().view())
129 return false;
130 document->view()->updateAllLifecyclePhases();
133 // Doing a layout can cause this object to be invalid, so check again.
134 return !isDetached();
137 WebString WebAXObject::actionVerb() const
139 if (isDetached())
140 return WebString();
142 return m_private->actionVerb();
145 bool WebAXObject::canDecrement() const
147 if (isDetached())
148 return false;
150 return m_private->isSlider();
153 bool WebAXObject::canIncrement() const
155 if (isDetached())
156 return false;
158 return m_private->isSlider();
161 bool WebAXObject::canPress() const
163 if (isDetached())
164 return false;
166 return m_private->actionElement() || m_private->isButton() || m_private->isMenuRelated();
169 bool WebAXObject::canSetFocusAttribute() const
171 if (isDetached())
172 return false;
174 return m_private->canSetFocusAttribute();
177 bool WebAXObject::canSetValueAttribute() const
179 if (isDetached())
180 return false;
182 return m_private->canSetValueAttribute();
185 unsigned WebAXObject::childCount() const
187 if (isDetached())
188 return 0;
190 return m_private->children().size();
193 WebAXObject WebAXObject::childAt(unsigned index) const
195 if (isDetached())
196 return WebAXObject();
198 if (m_private->children().size() <= index)
199 return WebAXObject();
201 return WebAXObject(m_private->children()[index]);
204 WebAXObject WebAXObject::parentObject() const
206 if (isDetached())
207 return WebAXObject();
209 return WebAXObject(m_private->parentObject());
212 bool WebAXObject::canSetSelectedAttribute() const
214 if (isDetached())
215 return false;
217 return m_private->canSetSelectedAttribute();
220 bool WebAXObject::isAnchor() const
222 if (isDetached())
223 return false;
225 return m_private->isAnchor();
228 bool WebAXObject::isAriaReadOnly() const
230 if (isDetached())
231 return false;
233 return equalIgnoringCase(m_private->getAttribute(HTMLNames::aria_readonlyAttr), "true");
236 WebString WebAXObject::ariaAutoComplete() const
238 if (isDetached())
239 return WebString();
241 return m_private->ariaAutoComplete();
244 bool WebAXObject::isButtonStateMixed() const
246 if (isDetached())
247 return false;
249 return m_private->checkboxOrRadioValue() == ButtonStateMixed;
252 bool WebAXObject::isChecked() const
254 if (isDetached())
255 return false;
257 return m_private->isChecked();
260 bool WebAXObject::isClickable() const
262 if (isDetached())
263 return false;
265 return m_private->isClickable();
268 bool WebAXObject::isCollapsed() const
270 if (isDetached())
271 return false;
273 return m_private->isCollapsed();
276 bool WebAXObject::isControl() const
278 if (isDetached())
279 return false;
281 return m_private->isControl();
284 bool WebAXObject::isEnabled() const
286 if (isDetached())
287 return false;
289 return m_private->isEnabled();
292 WebAXExpanded WebAXObject::isExpanded() const
294 if (isDetached())
295 return WebAXExpandedUndefined;
297 return static_cast<WebAXExpanded>(m_private->isExpanded());
300 bool WebAXObject::isFocused() const
302 if (isDetached())
303 return false;
305 return m_private->isFocused();
308 bool WebAXObject::isHovered() const
310 if (isDetached())
311 return false;
313 return m_private->isHovered();
316 bool WebAXObject::isIndeterminate() const
318 if (isDetached())
319 return false;
321 return m_private->isIndeterminate();
324 bool WebAXObject::isLinked() const
326 if (isDetached())
327 return false;
329 return m_private->isLinked();
332 bool WebAXObject::isLoaded() const
334 if (isDetached())
335 return false;
337 return m_private->isLoaded();
340 bool WebAXObject::isMultiSelectable() const
342 if (isDetached())
343 return false;
345 return m_private->isMultiSelectable();
348 bool WebAXObject::isOffScreen() const
350 if (isDetached())
351 return false;
353 return m_private->isOffScreen();
356 bool WebAXObject::isPasswordField() const
358 if (isDetached())
359 return false;
361 return m_private->isPasswordField();
364 bool WebAXObject::isPressed() const
366 if (isDetached())
367 return false;
369 return m_private->isPressed();
372 bool WebAXObject::isReadOnly() const
374 if (isDetached())
375 return false;
377 return m_private->isReadOnly();
380 bool WebAXObject::isRequired() const
382 if (isDetached())
383 return false;
385 return m_private->isRequired();
388 bool WebAXObject::isSelected() const
390 if (isDetached())
391 return false;
393 return m_private->isSelected();
396 bool WebAXObject::isSelectedOptionActive() const
398 if (isDetached())
399 return false;
401 return m_private->isSelectedOptionActive();
404 bool WebAXObject::isVisible() const
406 if (isDetached())
407 return false;
409 return m_private->isVisible();
412 bool WebAXObject::isVisited() const
414 if (isDetached())
415 return false;
417 return m_private->isVisited();
420 WebString WebAXObject::accessKey() const
422 if (isDetached())
423 return WebString();
425 return WebString(m_private->accessKey());
428 unsigned WebAXObject::backgroundColor() const
430 if (isDetached())
431 return 0;
433 // RGBA32 is an alias for unsigned int.
434 return m_private->backgroundColor();
437 unsigned WebAXObject::color() const
439 if (isDetached())
440 return 0;
442 // RGBA32 is an alias for unsigned int.
443 return m_private->color();
446 // Deprecated.
447 void WebAXObject::colorValue(int& r, int& g, int& b) const
449 if (isDetached())
450 return;
452 unsigned color = m_private->colorValue();
453 r = (color >> 16) & 0xFF;
454 g = (color >> 8) & 0xFF;
455 b = color & 0xFF;
458 unsigned WebAXObject::colorValue() const
460 if (isDetached())
461 return 0;
463 // RGBA32 is an alias for unsigned int.
464 return m_private->colorValue();
467 WebAXObject WebAXObject::ariaActiveDescendant() const
469 if (isDetached())
470 return WebAXObject();
472 return WebAXObject(m_private->activeDescendant());
475 bool WebAXObject::ariaControls(WebVector<WebAXObject>& controlsElements) const
477 if (isDetached())
478 return false;
480 AXObject::AccessibilityChildrenVector controls;
481 m_private->ariaControlsElements(controls);
483 WebVector<WebAXObject> result(controls.size());
484 for (size_t i = 0; i < controls.size(); i++)
485 result[i] = WebAXObject(controls[i]);
486 controlsElements.swap(result);
488 return true;
491 bool WebAXObject::ariaHasPopup() const
493 if (isDetached())
494 return false;
496 return m_private->ariaHasPopup();
499 bool WebAXObject::ariaFlowTo(WebVector<WebAXObject>& flowToElements) const
501 if (isDetached())
502 return false;
504 AXObject::AccessibilityChildrenVector flowTo;
505 m_private->ariaFlowToElements(flowTo);
507 WebVector<WebAXObject> result(flowTo.size());
508 for (size_t i = 0; i < flowTo.size(); i++)
509 result[i] = WebAXObject(flowTo[i]);
510 flowToElements.swap(result);
512 return true;
515 bool WebAXObject::isEditable() const
517 if (isDetached())
518 return false;
520 return m_private->isEditable();
523 bool WebAXObject::isMultiline() const
525 if (isDetached())
526 return false;
528 return m_private->isMultiline();
531 bool WebAXObject::isRichlyEditable() const
533 if (isDetached())
534 return false;
536 return m_private->isRichlyEditable();
539 int WebAXObject::posInSet() const
541 if (isDetached())
542 return 0;
544 return m_private->posInSet();
547 int WebAXObject::setSize() const
549 if (isDetached())
550 return 0;
552 return m_private->setSize();
555 bool WebAXObject::isInLiveRegion() const
557 if (isDetached())
558 return false;
560 return 0 != m_private->liveRegionRoot();
563 bool WebAXObject::liveRegionAtomic() const
565 if (isDetached())
566 return false;
568 return m_private->liveRegionAtomic();
571 bool WebAXObject::liveRegionBusy() const
573 if (isDetached())
574 return false;
576 return m_private->liveRegionBusy();
579 WebString WebAXObject::liveRegionRelevant() const
581 if (isDetached())
582 return WebString();
584 return m_private->liveRegionRelevant();
587 WebString WebAXObject::liveRegionStatus() const
589 if (isDetached())
590 return WebString();
592 return m_private->liveRegionStatus();
595 bool WebAXObject::containerLiveRegionAtomic() const
597 if (isDetached())
598 return false;
600 return m_private->containerLiveRegionAtomic();
603 bool WebAXObject::containerLiveRegionBusy() const
605 if (isDetached())
606 return false;
608 return m_private->containerLiveRegionBusy();
611 WebString WebAXObject::containerLiveRegionRelevant() const
613 if (isDetached())
614 return WebString();
616 return m_private->containerLiveRegionRelevant();
619 WebString WebAXObject::containerLiveRegionStatus() const
621 if (isDetached())
622 return WebString();
624 return m_private->containerLiveRegionStatus();
627 bool WebAXObject::ariaOwns(WebVector<WebAXObject>& ownsElements) const
629 // aria-owns rearranges the accessibility tree rather than just
630 // exposing an attribute.
632 // FIXME(dmazzoni): remove this function after we stop calling it
633 // from Chromium. http://crbug.com/489590
635 return false;
638 WebRect WebAXObject::boundingBoxRect() const
640 if (isDetached())
641 return WebRect();
643 ASSERT(isLayoutClean(m_private->document()));
645 return pixelSnappedIntRect(m_private->elementRect());
648 float WebAXObject::fontSize() const
650 if (isDetached())
651 return 0.0f;
653 return m_private->fontSize();
656 bool WebAXObject::canvasHasFallbackContent() const
658 if (isDetached())
659 return false;
661 return m_private->canvasHasFallbackContent();
664 WebPoint WebAXObject::clickPoint() const
666 if (isDetached())
667 return WebPoint();
669 return WebPoint(m_private->clickPoint());
672 WebAXInvalidState WebAXObject::invalidState() const
674 if (isDetached())
675 return WebAXInvalidStateUndefined;
677 return static_cast<WebAXInvalidState>(m_private->invalidState());
680 // Only used when invalidState() returns WebAXInvalidStateOther.
681 WebString WebAXObject::ariaInvalidValue() const
683 if (isDetached())
684 return WebString();
686 return m_private->ariaInvalidValue();
689 double WebAXObject::estimatedLoadingProgress() const
691 if (isDetached())
692 return 0.0;
694 return m_private->estimatedLoadingProgress();
697 int WebAXObject::headingLevel() const
699 if (isDetached())
700 return 0;
702 return m_private->headingLevel();
705 int WebAXObject::hierarchicalLevel() const
707 if (isDetached())
708 return 0;
710 return m_private->hierarchicalLevel();
713 // FIXME: This method passes in a point that has page scale applied but assumes that (0, 0)
714 // is the top left of the visual viewport. In other words, the point has the VisualViewport
715 // scale applied, but not the VisualViewport offset. crbug.com/459591.
716 WebAXObject WebAXObject::hitTest(const WebPoint& point) const
718 if (isDetached())
719 return WebAXObject();
721 IntPoint contentsPoint = m_private->documentFrameView()->soonToBeRemovedUnscaledViewportToContents(point);
722 AXObject* hit = m_private->accessibilityHitTest(contentsPoint);
724 if (hit)
725 return WebAXObject(hit);
727 if (m_private->elementRect().contains(contentsPoint))
728 return *this;
730 return WebAXObject();
733 WebString WebAXObject::keyboardShortcut() const
735 if (isDetached())
736 return WebString();
738 String accessKey = m_private->accessKey();
739 if (accessKey.isNull())
740 return WebString();
742 DEFINE_STATIC_LOCAL(String, modifierString, ());
743 if (modifierString.isNull()) {
744 unsigned modifiers = EventHandler::accessKeyModifiers();
745 // Follow the same order as Mozilla MSAA implementation:
746 // Ctrl+Alt+Shift+Meta+key. MSDN states that keyboard shortcut strings
747 // should not be localized and defines the separator as "+".
748 StringBuilder modifierStringBuilder;
749 if (modifiers & PlatformEvent::CtrlKey)
750 modifierStringBuilder.appendLiteral("Ctrl+");
751 if (modifiers & PlatformEvent::AltKey)
752 modifierStringBuilder.appendLiteral("Alt+");
753 if (modifiers & PlatformEvent::ShiftKey)
754 modifierStringBuilder.appendLiteral("Shift+");
755 if (modifiers & PlatformEvent::MetaKey)
756 modifierStringBuilder.appendLiteral("Win+");
757 modifierString = modifierStringBuilder.toString();
760 return String(modifierString + accessKey);
763 WebString WebAXObject::language() const
765 if (isDetached())
766 return WebString();
768 return m_private->language();
771 bool WebAXObject::performDefaultAction() const
773 if (isDetached())
774 return false;
776 return m_private->performDefaultAction();
779 bool WebAXObject::increment() const
781 if (isDetached())
782 return false;
784 if (canIncrement()) {
785 m_private->increment();
786 return true;
788 return false;
791 bool WebAXObject::decrement() const
793 if (isDetached())
794 return false;
796 if (canDecrement()) {
797 m_private->decrement();
798 return true;
800 return false;
803 WebAXOrientation WebAXObject::orientation() const
805 if (isDetached())
806 return WebAXOrientationUndefined;
808 return static_cast<WebAXOrientation>(m_private->orientation());
811 bool WebAXObject::press() const
813 if (isDetached())
814 return false;
816 return m_private->press();
819 WebAXRole WebAXObject::role() const
821 if (isDetached())
822 return WebAXRoleUnknown;
824 return static_cast<WebAXRole>(m_private->roleValue());
827 void WebAXObject::selection(WebAXObject& anchorObject, int& anchorOffset,
828 WebAXObject& focusObject, int& focusOffset) const
830 if (isDetached()) {
831 anchorObject = WebAXObject();
832 anchorOffset = -1;
833 focusObject = WebAXObject();
834 focusOffset = -1;
835 return;
838 AXObject::AXRange axSelection = m_private->selection();
839 anchorObject = WebAXObject(axSelection.anchorObject);
840 anchorOffset = axSelection.anchorOffset;
841 focusObject = WebAXObject(axSelection.focusObject);
842 focusOffset = axSelection.focusOffset;
843 return;
846 void WebAXObject::setSelection(const WebAXObject& anchorObject, int anchorOffset,
847 const WebAXObject& focusObject, int focusOffset) const
849 if (isDetached())
850 return;
852 AXObject::AXRange axSelection(anchorObject, anchorOffset,
853 focusObject, focusOffset);
854 m_private->setSelection(axSelection);
855 return;
858 unsigned WebAXObject::selectionEnd() const
860 if (isDetached())
861 return 0;
863 AXObject::AXRange axSelection = m_private->selectionUnderObject();
864 if (axSelection.focusOffset < 0)
865 return 0;
867 return axSelection.focusOffset;
870 unsigned WebAXObject::selectionStart() const
872 if (isDetached())
873 return 0;
875 AXObject::AXRange axSelection = m_private->selectionUnderObject();
876 if (axSelection.anchorOffset < 0)
877 return 0;
879 return axSelection.anchorOffset;
882 unsigned WebAXObject::selectionEndLineNumber() const
884 if (isDetached())
885 return 0;
887 VisiblePosition position = m_private->visiblePositionForIndex(selectionEnd());
888 int lineNumber = m_private->lineForPosition(position);
889 if (lineNumber < 0)
890 return 0;
892 return lineNumber;
895 unsigned WebAXObject::selectionStartLineNumber() const
897 if (isDetached())
898 return 0;
900 VisiblePosition position = m_private->visiblePositionForIndex(selectionStart());
901 int lineNumber = m_private->lineForPosition(position);
902 if (lineNumber < 0)
903 return 0;
905 return lineNumber;
908 void WebAXObject::setFocused(bool on) const
910 if (!isDetached())
911 m_private->setFocused(on);
914 void WebAXObject::setSelectedTextRange(int selectionStart, int selectionEnd) const
916 if (isDetached())
917 return;
919 m_private->setSelection(AXObject::AXRange(selectionStart, selectionEnd));
922 void WebAXObject::setValue(WebString value) const
924 if (isDetached())
925 return;
927 m_private->setValue(value);
930 void WebAXObject::showContextMenu() const
932 if (isDetached())
933 return;
935 Node* node = m_private->node();
936 if (!node)
937 return;
939 Element* element = nullptr;
940 if (node->isElementNode()) {
941 element = toElement(node);
942 } else {
943 node->updateDistribution();
944 ContainerNode* parent = ComposedTreeTraversal::parent(*node);
945 ASSERT_WITH_SECURITY_IMPLICATION(parent->isElementNode());
946 element = toElement(parent);
949 if (!element)
950 return;
952 LocalFrame* frame = element->document().frame();
953 if (!frame)
954 return;
956 WebViewImpl* view = WebLocalFrameImpl::fromFrame(frame)->viewImpl();
957 if (!view)
958 return;
960 view->showContextMenuForElement(WebElement(element));
963 WebString WebAXObject::stringValue() const
965 if (isDetached())
966 return WebString();
968 return m_private->stringValue();
971 WebAXTextDirection WebAXObject::textDirection() const
973 if (isDetached())
974 return WebAXTextDirectionLR;
976 return static_cast<WebAXTextDirection>(m_private->textDirection());
979 WebAXTextStyle WebAXObject::textStyle() const
981 if (isDetached())
982 return WebAXTextStyleNone;
984 return static_cast<WebAXTextStyle>(m_private->textStyle());
987 WebURL WebAXObject::url() const
989 if (isDetached())
990 return WebURL();
992 return m_private->url();
995 WebString WebAXObject::deprecatedAccessibilityDescription() const
997 if (isDetached())
998 return WebString();
1000 ASSERT(isLayoutClean(m_private->document()));
1002 return m_private->deprecatedAccessibilityDescription();
1005 bool WebAXObject::deprecatedAriaDescribedby(WebVector<WebAXObject>& describedbyElements) const
1007 if (isDetached())
1008 return false;
1010 AXObject::AccessibilityChildrenVector describedby;
1011 m_private->deprecatedAriaDescribedbyElements(describedby);
1013 WebVector<WebAXObject> result(describedby.size());
1014 for (size_t i = 0; i < describedby.size(); i++)
1015 result[i] = WebAXObject(describedby[i]);
1016 describedbyElements.swap(result);
1018 return true;
1021 bool WebAXObject::deprecatedAriaLabelledby(WebVector<WebAXObject>& labelledbyElements) const
1023 if (isDetached())
1024 return false;
1026 AXObject::AccessibilityChildrenVector labelledby;
1027 m_private->deprecatedAriaLabelledbyElements(labelledby);
1029 WebVector<WebAXObject> result(labelledby.size());
1030 for (size_t i = 0; i < labelledby.size(); i++)
1031 result[i] = WebAXObject(labelledby[i]);
1032 labelledbyElements.swap(result);
1034 return true;
1037 WebString WebAXObject::deprecatedHelpText() const
1039 if (isDetached())
1040 return WebString();
1042 return m_private->deprecatedHelpText();
1045 WebString WebAXObject::deprecatedPlaceholder() const
1047 if (isDetached())
1048 return WebString();
1050 return WebString(m_private->deprecatedPlaceholder());
1053 WebString WebAXObject::deprecatedTitle() const
1055 if (isDetached())
1056 return WebString();
1058 ASSERT(isLayoutClean(m_private->document()));
1060 return m_private->deprecatedTitle();
1063 WebAXObject WebAXObject::deprecatedTitleUIElement() const
1065 if (isDetached())
1066 return WebAXObject();
1068 if (!m_private->deprecatedExposesTitleUIElement())
1069 return WebAXObject();
1071 return WebAXObject(m_private->deprecatedTitleUIElement());
1074 WebString WebAXObject::accessibilityDescription() const
1076 return deprecatedAccessibilityDescription();
1079 bool WebAXObject::ariaDescribedby(WebVector<WebAXObject>& describedbyElements) const
1081 return deprecatedAriaDescribedby(describedbyElements);
1084 bool WebAXObject::ariaLabelledby(WebVector<WebAXObject>& labelledbyElements) const
1086 return deprecatedAriaLabelledby(labelledbyElements);
1089 WebString WebAXObject::helpText() const
1091 return deprecatedHelpText();
1094 WebString WebAXObject::placeholder() const
1096 return deprecatedPlaceholder();
1099 WebString WebAXObject::title() const
1101 return deprecatedTitle();
1104 WebAXObject WebAXObject::titleUIElement() const
1106 return deprecatedTitleUIElement();
1109 WebString WebAXObject::name(WebAXNameFrom& outNameFrom, WebVector<WebAXObject>& outNameObjects) const
1111 if (isDetached())
1112 return WebString();
1114 AXNameFrom nameFrom = AXNameFromAttribute;
1115 HeapVector<Member<AXObject>> nameObjects;
1116 WebString result = m_private->name(nameFrom, &nameObjects);
1117 outNameFrom = static_cast<WebAXNameFrom>(nameFrom);
1119 WebVector<WebAXObject> webNameObjects(nameObjects.size());
1120 for (size_t i = 0; i < nameObjects.size(); i++)
1121 webNameObjects[i] = WebAXObject(nameObjects[i]);
1122 outNameObjects.swap(webNameObjects);
1124 return result;
1127 WebString WebAXObject::description(WebAXNameFrom nameFrom, WebAXDescriptionFrom& outDescriptionFrom, WebVector<WebAXObject>& outDescriptionObjects) const
1129 if (isDetached())
1130 return WebString();
1132 AXDescriptionFrom descriptionFrom;
1133 HeapVector<Member<AXObject>> descriptionObjects;
1134 String result = m_private->description(static_cast<AXNameFrom>(nameFrom), descriptionFrom, &descriptionObjects);
1135 outDescriptionFrom = static_cast<WebAXDescriptionFrom>(descriptionFrom);
1137 WebVector<WebAXObject> webDescriptionObjects(descriptionObjects.size());
1138 for (size_t i = 0; i < descriptionObjects.size(); i++)
1139 webDescriptionObjects[i] = WebAXObject(descriptionObjects[i]);
1140 outDescriptionObjects.swap(webDescriptionObjects);
1142 return result;
1145 WebString WebAXObject::placeholder(WebAXNameFrom nameFrom, WebAXDescriptionFrom descriptionFrom) const
1147 if (isDetached())
1148 return WebString();
1150 return m_private->placeholder(static_cast<AXNameFrom>(nameFrom), static_cast<AXDescriptionFrom>(descriptionFrom));
1153 bool WebAXObject::supportsRangeValue() const
1155 if (isDetached())
1156 return false;
1158 return m_private->supportsRangeValue();
1161 WebString WebAXObject::valueDescription() const
1163 if (isDetached())
1164 return WebString();
1166 return m_private->valueDescription();
1169 float WebAXObject::valueForRange() const
1171 if (isDetached())
1172 return 0.0;
1174 return m_private->valueForRange();
1177 float WebAXObject::maxValueForRange() const
1179 if (isDetached())
1180 return 0.0;
1182 return m_private->maxValueForRange();
1185 float WebAXObject::minValueForRange() const
1187 if (isDetached())
1188 return 0.0;
1190 return m_private->minValueForRange();
1193 WebNode WebAXObject::node() const
1195 if (isDetached())
1196 return WebNode();
1198 Node* node = m_private->node();
1199 if (!node)
1200 return WebNode();
1202 return WebNode(node);
1205 WebDocument WebAXObject::document() const
1207 if (isDetached())
1208 return WebDocument();
1210 Document* document = m_private->document();
1211 if (!document)
1212 return WebDocument();
1214 return WebDocument(document);
1217 bool WebAXObject::hasComputedStyle() const
1219 if (isDetached())
1220 return false;
1222 Document* document = m_private->document();
1223 if (document)
1224 document->updateLayoutTreeIfNeeded();
1226 Node* node = m_private->node();
1227 if (!node)
1228 return false;
1230 return node->ensureComputedStyle();
1233 WebString WebAXObject::computedStyleDisplay() const
1235 if (isDetached())
1236 return WebString();
1238 Document* document = m_private->document();
1239 if (document)
1240 document->updateLayoutTreeIfNeeded();
1242 Node* node = m_private->node();
1243 if (!node)
1244 return WebString();
1246 const ComputedStyle* computedStyle = node->ensureComputedStyle();
1247 if (!computedStyle)
1248 return WebString();
1250 return WebString(CSSPrimitiveValue::create(computedStyle->display())->cssText());
1253 bool WebAXObject::accessibilityIsIgnored() const
1255 if (isDetached())
1256 return false;
1258 return m_private->accessibilityIsIgnored();
1261 bool WebAXObject::lineBreaks(WebVector<int>& result) const
1263 if (isDetached())
1264 return false;
1266 Vector<int> lineBreaksVector;
1267 m_private->lineBreaks(lineBreaksVector);
1269 size_t vectorSize = lineBreaksVector.size();
1270 WebVector<int> lineBreaksWebVector(vectorSize);
1271 for (size_t i = 0; i< vectorSize; i++)
1272 lineBreaksWebVector[i] = lineBreaksVector[i];
1273 result.swap(lineBreaksWebVector);
1275 return true;
1278 unsigned WebAXObject::columnCount() const
1280 if (isDetached())
1281 return false;
1283 if (!m_private->isAXTable())
1284 return 0;
1286 return toAXTable(m_private.get())->columnCount();
1289 unsigned WebAXObject::rowCount() const
1291 if (isDetached())
1292 return false;
1294 if (!m_private->isAXTable())
1295 return 0;
1297 return toAXTable(m_private.get())->rowCount();
1300 WebAXObject WebAXObject::cellForColumnAndRow(unsigned column, unsigned row) const
1302 if (isDetached())
1303 return WebAXObject();
1305 if (!m_private->isAXTable())
1306 return WebAXObject();
1308 AXTableCell* cell = toAXTable(m_private.get())->cellForColumnAndRow(column, row);
1309 return WebAXObject(static_cast<AXObject*>(cell));
1312 WebAXObject WebAXObject::headerContainerObject() const
1314 if (isDetached())
1315 return WebAXObject();
1317 if (!m_private->isAXTable())
1318 return WebAXObject();
1320 return WebAXObject(toAXTable(m_private.get())->headerContainer());
1323 WebAXObject WebAXObject::rowAtIndex(unsigned rowIndex) const
1325 if (isDetached())
1326 return WebAXObject();
1328 if (!m_private->isAXTable())
1329 return WebAXObject();
1331 const AXObject::AccessibilityChildrenVector& rows = toAXTable(m_private.get())->rows();
1332 if (rowIndex < rows.size())
1333 return WebAXObject(rows[rowIndex]);
1335 return WebAXObject();
1338 WebAXObject WebAXObject::columnAtIndex(unsigned columnIndex) const
1340 if (isDetached())
1341 return WebAXObject();
1343 if (!m_private->isAXTable())
1344 return WebAXObject();
1346 const AXObject::AccessibilityChildrenVector& columns = toAXTable(m_private.get())->columns();
1347 if (columnIndex < columns.size())
1348 return WebAXObject(columns[columnIndex]);
1350 return WebAXObject();
1353 unsigned WebAXObject::rowIndex() const
1355 if (isDetached())
1356 return 0;
1358 if (!m_private->isTableRow())
1359 return 0;
1361 return toAXTableRow(m_private.get())->rowIndex();
1364 WebAXObject WebAXObject::rowHeader() const
1366 if (isDetached())
1367 return WebAXObject();
1369 if (!m_private->isTableRow())
1370 return WebAXObject();
1372 return WebAXObject(toAXTableRow(m_private.get())->headerObject());
1375 void WebAXObject::rowHeaders(WebVector<WebAXObject>& rowHeaderElements) const
1377 if (isDetached())
1378 return;
1380 if (!m_private->isAXTable())
1381 return;
1383 AXObject::AccessibilityChildrenVector headers;
1384 toAXTable(m_private.get())->rowHeaders(headers);
1386 size_t headerCount = headers.size();
1387 WebVector<WebAXObject> result(headerCount);
1389 for (size_t i = 0; i < headerCount; i++)
1390 result[i] = WebAXObject(headers[i]);
1392 rowHeaderElements.swap(result);
1395 unsigned WebAXObject::columnIndex() const
1397 if (isDetached())
1398 return 0;
1400 if (m_private->roleValue() != ColumnRole)
1401 return 0;
1403 return toAXTableColumn(m_private.get())->columnIndex();
1406 WebAXObject WebAXObject::columnHeader() const
1408 if (isDetached())
1409 return WebAXObject();
1411 if (m_private->roleValue() != ColumnRole)
1412 return WebAXObject();
1414 return WebAXObject(toAXTableColumn(m_private.get())->headerObject());
1417 void WebAXObject::columnHeaders(WebVector<WebAXObject>& columnHeaderElements) const
1419 if (isDetached())
1420 return;
1422 if (!m_private->isAXTable())
1423 return;
1425 AXObject::AccessibilityChildrenVector headers;
1426 toAXTable(m_private.get())->columnHeaders(headers);
1428 size_t headerCount = headers.size();
1429 WebVector<WebAXObject> result(headerCount);
1431 for (size_t i = 0; i < headerCount; i++)
1432 result[i] = WebAXObject(headers[i]);
1434 columnHeaderElements.swap(result);
1437 unsigned WebAXObject::cellColumnIndex() const
1439 if (isDetached())
1440 return 0;
1442 if (!m_private->isTableCell())
1443 return 0;
1445 pair<unsigned, unsigned> columnRange;
1446 toAXTableCell(m_private.get())->columnIndexRange(columnRange);
1447 return columnRange.first;
1450 unsigned WebAXObject::cellColumnSpan() const
1452 if (isDetached())
1453 return 0;
1455 if (!m_private->isTableCell())
1456 return 0;
1458 pair<unsigned, unsigned> columnRange;
1459 toAXTableCell(m_private.get())->columnIndexRange(columnRange);
1460 return columnRange.second;
1463 unsigned WebAXObject::cellRowIndex() const
1465 if (isDetached())
1466 return 0;
1468 if (!m_private->isTableCell())
1469 return 0;
1471 pair<unsigned, unsigned> rowRange;
1472 toAXTableCell(m_private.get())->rowIndexRange(rowRange);
1473 return rowRange.first;
1476 unsigned WebAXObject::cellRowSpan() const
1478 if (isDetached())
1479 return 0;
1481 if (!m_private->isTableCell())
1482 return 0;
1484 pair<unsigned, unsigned> rowRange;
1485 toAXTableCell(m_private.get())->rowIndexRange(rowRange);
1486 return rowRange.second;
1489 WebAXSortDirection WebAXObject::sortDirection() const
1491 if (isDetached())
1492 return WebAXSortDirectionUndefined;
1494 return static_cast<WebAXSortDirection>(m_private->sortDirection());
1497 void WebAXObject::loadInlineTextBoxes() const
1499 if (isDetached())
1500 return;
1502 m_private->loadInlineTextBoxes();
1505 WebAXObject WebAXObject::nextOnLine() const
1507 if (isDetached())
1508 return WebAXObject();
1510 return WebAXObject(m_private.get()->nextOnLine());
1513 WebAXObject WebAXObject::previousOnLine() const
1515 if (isDetached())
1516 return WebAXObject();
1518 return WebAXObject(m_private.get()->previousOnLine());
1521 void WebAXObject::characterOffsets(WebVector<int>& offsets) const
1523 if (isDetached())
1524 return;
1526 Vector<int> offsetsVector;
1527 m_private->textCharacterOffsets(offsetsVector);
1529 size_t vectorSize = offsetsVector.size();
1530 WebVector<int> offsetsWebVector(vectorSize);
1531 for (size_t i = 0; i < vectorSize; i++)
1532 offsetsWebVector[i] = offsetsVector[i];
1533 offsets.swap(offsetsWebVector);
1536 void WebAXObject::wordBoundaries(WebVector<int>& starts, WebVector<int>& ends) const
1538 if (isDetached())
1539 return;
1541 Vector<AXObject::AXRange> wordBoundaries;
1542 m_private->wordBoundaries(wordBoundaries);
1544 WebVector<int> wordStartOffsets(wordBoundaries.size());
1545 WebVector<int> wordEndOffsets(wordBoundaries.size());
1546 for (size_t i = 0; i < wordBoundaries.size(); ++i) {
1547 ASSERT(wordBoundaries[i].isSimple());
1548 wordStartOffsets[i] = wordBoundaries[i].anchorOffset;
1549 wordEndOffsets[i] = wordBoundaries[i].focusOffset;
1552 starts.swap(wordStartOffsets);
1553 ends.swap(wordEndOffsets);
1556 bool WebAXObject::isScrollableContainer() const
1558 if (isDetached())
1559 return false;
1561 return m_private->isScrollableContainer();
1564 WebPoint WebAXObject::scrollOffset() const
1566 if (isDetached())
1567 return WebPoint();
1569 return m_private->scrollOffset();
1572 WebPoint WebAXObject::minimumScrollOffset() const
1574 if (isDetached())
1575 return WebPoint();
1577 return m_private->minimumScrollOffset();
1580 WebPoint WebAXObject::maximumScrollOffset() const
1582 if (isDetached())
1583 return WebPoint();
1585 return m_private->maximumScrollOffset();
1588 void WebAXObject::setScrollOffset(const WebPoint& offset) const
1590 if (isDetached())
1591 return;
1593 m_private->setScrollOffset(offset);
1596 void WebAXObject::scrollToMakeVisible() const
1598 if (!isDetached())
1599 m_private->scrollToMakeVisible();
1602 void WebAXObject::scrollToMakeVisibleWithSubFocus(const WebRect& subfocus) const
1604 if (!isDetached())
1605 m_private->scrollToMakeVisibleWithSubFocus(subfocus);
1608 void WebAXObject::scrollToGlobalPoint(const WebPoint& point) const
1610 if (!isDetached())
1611 m_private->scrollToGlobalPoint(point);
1614 WebAXObject::WebAXObject(AXObject* object)
1615 : m_private(object)
1619 WebAXObject& WebAXObject::operator=(AXObject* object)
1621 m_private = object;
1622 return *this;
1625 WebAXObject::operator AXObject*() const
1627 return m_private.get();
1630 } // namespace blink