| 1 | /* |
| 2 | * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
| 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "config.h" |
| 30 | #include "AccessibilityImageMapLink.h" |
| 31 | |
| 32 | #include "AXObjectCache.h" |
| 33 | #include "AccessibilityRenderObject.h" |
| 34 | #include "Document.h" |
| 35 | #include "HTMLNames.h" |
| 36 | #include "RenderBoxModelObject.h" |
| 37 | |
| 38 | namespace WebCore { |
| 39 | |
| 40 | using namespace HTMLNames; |
| 41 | |
| 42 | AccessibilityImageMapLink::AccessibilityImageMapLink() |
| 43 | : m_areaElement(nullptr) |
| 44 | , m_mapElement(nullptr) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | AccessibilityImageMapLink::~AccessibilityImageMapLink() = default; |
| 49 | |
| 50 | Ref<AccessibilityImageMapLink> AccessibilityImageMapLink::create() |
| 51 | { |
| 52 | return adoptRef(*new AccessibilityImageMapLink()); |
| 53 | } |
| 54 | |
| 55 | AccessibilityObject* AccessibilityImageMapLink::parentObject() const |
| 56 | { |
| 57 | if (m_parent) |
| 58 | return m_parent; |
| 59 | |
| 60 | if (!m_mapElement.get() || !m_mapElement->renderer()) |
| 61 | return nullptr; |
| 62 | |
| 63 | return m_mapElement->document().axObjectCache()->getOrCreate(m_mapElement->renderer()); |
| 64 | } |
| 65 | |
| 66 | AccessibilityRole AccessibilityImageMapLink::roleValue() const |
| 67 | { |
| 68 | if (!m_areaElement) |
| 69 | return AccessibilityRole::WebCoreLink; |
| 70 | |
| 71 | const AtomicString& ariaRole = getAttribute(roleAttr); |
| 72 | if (!ariaRole.isEmpty()) |
| 73 | return AccessibilityObject::ariaRoleToWebCoreRole(ariaRole); |
| 74 | |
| 75 | return AccessibilityRole::WebCoreLink; |
| 76 | } |
| 77 | |
| 78 | Element* AccessibilityImageMapLink::actionElement() const |
| 79 | { |
| 80 | return anchorElement(); |
| 81 | } |
| 82 | |
| 83 | Element* AccessibilityImageMapLink::anchorElement() const |
| 84 | { |
| 85 | return m_areaElement.get(); |
| 86 | } |
| 87 | |
| 88 | URL AccessibilityImageMapLink::url() const |
| 89 | { |
| 90 | if (!m_areaElement.get()) |
| 91 | return URL(); |
| 92 | |
| 93 | return m_areaElement->href(); |
| 94 | } |
| 95 | |
| 96 | void AccessibilityImageMapLink::accessibilityText(Vector<AccessibilityText>& textOrder) const |
| 97 | { |
| 98 | String description = accessibilityDescription(); |
| 99 | if (!description.isEmpty()) |
| 100 | textOrder.append(AccessibilityText(description, AccessibilityTextSource::Alternative)); |
| 101 | |
| 102 | const AtomicString& titleText = getAttribute(titleAttr); |
| 103 | if (!titleText.isEmpty()) |
| 104 | textOrder.append(AccessibilityText(titleText, AccessibilityTextSource::TitleTag)); |
| 105 | |
| 106 | const AtomicString& summary = getAttribute(summaryAttr); |
| 107 | if (!summary.isEmpty()) |
| 108 | textOrder.append(AccessibilityText(summary, AccessibilityTextSource::Summary)); |
| 109 | } |
| 110 | |
| 111 | String AccessibilityImageMapLink::accessibilityDescription() const |
| 112 | { |
| 113 | const AtomicString& ariaLabel = getAttribute(aria_labelAttr); |
| 114 | if (!ariaLabel.isEmpty()) |
| 115 | return ariaLabel; |
| 116 | const AtomicString& alt = getAttribute(altAttr); |
| 117 | if (!alt.isEmpty()) |
| 118 | return alt; |
| 119 | |
| 120 | return String(); |
| 121 | } |
| 122 | |
| 123 | String AccessibilityImageMapLink::title() const |
| 124 | { |
| 125 | const AtomicString& title = getAttribute(titleAttr); |
| 126 | if (!title.isEmpty()) |
| 127 | return title; |
| 128 | const AtomicString& summary = getAttribute(summaryAttr); |
| 129 | if (!summary.isEmpty()) |
| 130 | return summary; |
| 131 | |
| 132 | return String(); |
| 133 | } |
| 134 | |
| 135 | RenderElement* AccessibilityImageMapLink::imageMapLinkRenderer() const |
| 136 | { |
| 137 | if (!m_mapElement || !m_areaElement) |
| 138 | return nullptr; |
| 139 | |
| 140 | RenderElement* renderer = nullptr; |
| 141 | if (is<AccessibilityRenderObject>(m_parent)) |
| 142 | renderer = downcast<RenderElement>(downcast<AccessibilityRenderObject>(*m_parent).renderer()); |
| 143 | else |
| 144 | renderer = m_mapElement->renderer(); |
| 145 | |
| 146 | return renderer; |
| 147 | } |
| 148 | |
| 149 | void AccessibilityImageMapLink::detachFromParent() |
| 150 | { |
| 151 | AccessibilityMockObject::detachFromParent(); |
| 152 | m_areaElement = nullptr; |
| 153 | m_mapElement = nullptr; |
| 154 | } |
| 155 | |
| 156 | Path AccessibilityImageMapLink::elementPath() const |
| 157 | { |
| 158 | auto renderer = imageMapLinkRenderer(); |
| 159 | if (!renderer) |
| 160 | return Path(); |
| 161 | |
| 162 | return m_areaElement->computePath(renderer); |
| 163 | } |
| 164 | |
| 165 | LayoutRect AccessibilityImageMapLink::elementRect() const |
| 166 | { |
| 167 | auto renderer = imageMapLinkRenderer(); |
| 168 | if (!renderer) |
| 169 | return LayoutRect(); |
| 170 | |
| 171 | return m_areaElement->computeRect(renderer); |
| 172 | } |
| 173 | |
| 174 | String AccessibilityImageMapLink::stringValueForMSAA() const |
| 175 | { |
| 176 | return url(); |
| 177 | } |
| 178 | |
| 179 | String AccessibilityImageMapLink::nameForMSAA() const |
| 180 | { |
| 181 | return accessibilityDescription(); |
| 182 | } |
| 183 | |
| 184 | } // namespace WebCore |
| 185 | |