OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "modules/accessibility/AXMenuListOption.h" | 26 #include "modules/accessibility/AXMenuListOption.h" |
27 | 27 |
28 #include "SkMatrix44.h" | 28 #include "SkMatrix44.h" |
| 29 #include "core/html/HTMLSelectElement.h" |
29 #include "modules/accessibility/AXMenuListPopup.h" | 30 #include "modules/accessibility/AXMenuListPopup.h" |
30 #include "modules/accessibility/AXObjectCacheImpl.h" | 31 #include "modules/accessibility/AXObjectCacheImpl.h" |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 using namespace HTMLNames; | 35 using namespace HTMLNames; |
35 | 36 |
36 AXMenuListOption::AXMenuListOption(HTMLOptionElement* element, | 37 AXMenuListOption::AXMenuListOption(HTMLOptionElement* element, |
37 AXObjectCacheImpl& axObjectCache) | 38 AXObjectCacheImpl& axObjectCache) |
38 : AXMockObject(axObjectCache), m_element(element) {} | 39 : AXMockObject(axObjectCache), m_element(element) {} |
39 | 40 |
40 AXMenuListOption::~AXMenuListOption() { | 41 AXMenuListOption::~AXMenuListOption() { |
41 ASSERT(!m_element); | 42 DCHECK(!m_element); |
42 } | 43 } |
43 | 44 |
44 void AXMenuListOption::detach() { | 45 void AXMenuListOption::detach() { |
45 m_element = nullptr; | 46 m_element = nullptr; |
46 AXMockObject::detach(); | 47 AXMockObject::detach(); |
47 } | 48 } |
48 | 49 |
49 AccessibilityRole AXMenuListOption::roleValue() const { | 50 AccessibilityRole AXMenuListOption::roleValue() const { |
50 const AtomicString& ariaRole = getAttribute(roleAttr); | 51 const AtomicString& ariaRole = getAttribute(roleAttr); |
51 if (ariaRole.isEmpty()) | 52 if (ariaRole.isEmpty()) |
52 return MenuListOptionRole; | 53 return MenuListOptionRole; |
53 | 54 |
54 AccessibilityRole role = ariaRoleToWebCoreRole(ariaRole); | 55 AccessibilityRole role = ariaRoleToWebCoreRole(ariaRole); |
55 if (role) | 56 if (role) |
56 return role; | 57 return role; |
57 return MenuListOptionRole; | 58 return MenuListOptionRole; |
58 } | 59 } |
59 | 60 |
| 61 AXObject* AXMenuListOption::computeParent() const { |
| 62 Node* node = getNode(); |
| 63 if (!node) |
| 64 return nullptr; |
| 65 Node* select = toHTMLOptionElement(node)->ownerSelectElement(); |
| 66 if (!select) |
| 67 return nullptr; |
| 68 AXObject* selectAXObject = axObjectCache().getOrCreate(select); |
| 69 if (selectAXObject->hasChildren()) { |
| 70 const auto& childObjects = selectAXObject->children(); |
| 71 DCHECK(!childObjects.isEmpty()); |
| 72 DCHECK_EQ(childObjects.size(), 1UL); |
| 73 DCHECK(childObjects[0]->isMenuListPopup()); |
| 74 toAXMenuListPopup(childObjects[0].get())->updateChildrenIfNecessary(); |
| 75 } else { |
| 76 selectAXObject->updateChildrenIfNecessary(); |
| 77 } |
| 78 return m_parent.get(); |
| 79 } |
| 80 |
60 Element* AXMenuListOption::actionElement() const { | 81 Element* AXMenuListOption::actionElement() const { |
61 return m_element; | 82 return m_element; |
62 } | 83 } |
63 | 84 |
64 bool AXMenuListOption::isEnabled() const { | 85 bool AXMenuListOption::isEnabled() const { |
65 // isDisabledFormControl() returns true if the parent <select> element is | 86 // isDisabledFormControl() returns true if the parent <select> element is |
66 // disabled, which we don't want. | 87 // disabled, which we don't want. |
67 return m_element && !m_element->ownElementDisabled(); | 88 return m_element && !m_element->ownElementDisabled(); |
68 } | 89 } |
69 | 90 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 AXObject** outContainer, | 129 AXObject** outContainer, |
109 FloatRect& outBoundsInContainer, | 130 FloatRect& outBoundsInContainer, |
110 SkMatrix44& outContainerTransform) const { | 131 SkMatrix44& outContainerTransform) const { |
111 *outContainer = nullptr; | 132 *outContainer = nullptr; |
112 outBoundsInContainer = FloatRect(); | 133 outBoundsInContainer = FloatRect(); |
113 outContainerTransform.setIdentity(); | 134 outContainerTransform.setIdentity(); |
114 | 135 |
115 AXObject* parent = parentObject(); | 136 AXObject* parent = parentObject(); |
116 if (!parent) | 137 if (!parent) |
117 return; | 138 return; |
118 ASSERT(parent->isMenuListPopup()); | 139 DCHECK(parent->isMenuListPopup()); |
119 | 140 |
120 AXObject* grandparent = parent->parentObject(); | 141 AXObject* grandparent = parent->parentObject(); |
121 if (!grandparent) | 142 if (!grandparent) |
122 return; | 143 return; |
123 ASSERT(grandparent->isMenuList()); | 144 DCHECK(grandparent->isMenuList()); |
124 grandparent->getRelativeBounds(outContainer, outBoundsInContainer, | 145 grandparent->getRelativeBounds(outContainer, outBoundsInContainer, |
125 outContainerTransform); | 146 outContainerTransform); |
126 } | 147 } |
127 | 148 |
128 String AXMenuListOption::textAlternative(bool recursive, | 149 String AXMenuListOption::textAlternative(bool recursive, |
129 bool inAriaLabelledByTraversal, | 150 bool inAriaLabelledByTraversal, |
130 AXObjectSet& visited, | 151 AXObjectSet& visited, |
131 AXNameFrom& nameFrom, | 152 AXNameFrom& nameFrom, |
132 AXRelatedObjectVector* relatedObjects, | 153 AXRelatedObjectVector* relatedObjects, |
133 NameSources* nameSources) const { | 154 NameSources* nameSources) const { |
134 // If nameSources is non-null, relatedObjects is used in filling it in, so it | 155 // If nameSources is non-null, relatedObjects is used in filling it in, so it |
135 // must be non-null as well. | 156 // must be non-null as well. |
136 if (nameSources) | 157 if (nameSources) |
137 ASSERT(relatedObjects); | 158 DCHECK(relatedObjects); |
138 | 159 |
139 if (!getNode()) | 160 if (!getNode()) |
140 return String(); | 161 return String(); |
141 | 162 |
142 bool foundTextAlternative = false; | 163 bool foundTextAlternative = false; |
143 String textAlternative = ariaTextAlternative( | 164 String textAlternative = ariaTextAlternative( |
144 recursive, inAriaLabelledByTraversal, visited, nameFrom, relatedObjects, | 165 recursive, inAriaLabelledByTraversal, visited, nameFrom, relatedObjects, |
145 nameSources, &foundTextAlternative); | 166 nameSources, &foundTextAlternative); |
146 if (foundTextAlternative && !nameSources) | 167 if (foundTextAlternative && !nameSources) |
147 return textAlternative; | 168 return textAlternative; |
148 | 169 |
149 nameFrom = AXNameFromContents; | 170 nameFrom = AXNameFromContents; |
150 textAlternative = m_element->displayLabel(); | 171 textAlternative = m_element->displayLabel(); |
151 if (nameSources) { | 172 if (nameSources) { |
152 nameSources->push_back(NameSource(foundTextAlternative)); | 173 nameSources->push_back(NameSource(foundTextAlternative)); |
153 nameSources->back().type = nameFrom; | 174 nameSources->back().type = nameFrom; |
154 nameSources->back().text = textAlternative; | 175 nameSources->back().text = textAlternative; |
155 foundTextAlternative = true; | 176 foundTextAlternative = true; |
156 } | 177 } |
157 | 178 |
158 return textAlternative; | 179 return textAlternative; |
159 } | 180 } |
160 | 181 |
161 DEFINE_TRACE(AXMenuListOption) { | 182 DEFINE_TRACE(AXMenuListOption) { |
162 visitor->trace(m_element); | 183 visitor->trace(m_element); |
163 AXMockObject::trace(visitor); | 184 AXMockObject::trace(visitor); |
164 } | 185 } |
165 | 186 |
166 } // namespace blink | 187 } // namespace blink |
OLD | NEW |