eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 Computer, 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 | |
| 30 | #include "config.h" |
| 31 | |
| 32 | #if ENABLE(VIDEO) |
| 33 | |
| 34 | #include "AccessibilityMediaControls.h" |
| 35 | |
| 36 | #include "AXObjectCache.h" |
| 37 | #include "HTMLInputElement.h" |
jer.noble@apple.com | a05cec4 | 2011-12-02 17:35:54 +0000 | [diff] [blame] | 38 | #include "HTMLMediaElement.h" |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 39 | #include "HTMLNames.h" |
| 40 | #include "LocalizedStrings.h" |
| 41 | #include "MediaControlElements.h" |
| 42 | #include "RenderObject.h" |
| 43 | #include "RenderSlider.h" |
| 44 | |
| 45 | namespace WebCore { |
| 46 | |
| 47 | using namespace HTMLNames; |
| 48 | |
| 49 | |
| 50 | AccessibilityMediaControl::AccessibilityMediaControl(RenderObject* renderer) |
| 51 | : AccessibilityRenderObject(renderer) |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | PassRefPtr<AccessibilityObject> AccessibilityMediaControl::create(RenderObject* renderer) |
| 56 | { |
darin@apple.com | 2b241a6 | 2011-11-16 06:46:27 +0000 | [diff] [blame] | 57 | ASSERT(renderer->node()); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 58 | |
darin@apple.com | 2b241a6 | 2011-11-16 06:46:27 +0000 | [diff] [blame] | 59 | switch (mediaControlElementType(renderer->node())) { |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 60 | case MediaSlider: |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 61 | return AccessibilityMediaTimeline::create(renderer); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 62 | |
| 63 | case MediaCurrentTimeDisplay: |
| 64 | case MediaTimeRemainingDisplay: |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 65 | return AccessibilityMediaTimeDisplay::create(renderer); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 66 | |
| 67 | case MediaControlsPanel: |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 68 | return AccessibilityMediaControlsContainer::create(renderer); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 69 | |
dmazzoni@google.com | c35bf3d | 2012-07-24 06:26:32 +0000 | [diff] [blame] | 70 | default: { |
| 71 | AccessibilityMediaControl* obj = new AccessibilityMediaControl(renderer); |
| 72 | obj->init(); |
| 73 | return adoptRef(obj); |
| 74 | } |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 75 | } |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | MediaControlElementType AccessibilityMediaControl::controlType() const |
| 79 | { |
| 80 | if (!renderer() || !renderer()->node()) |
cfleizach@apple.com | 00ff18e | 2010-04-05 20:41:38 +0000 | [diff] [blame] | 81 | return MediaTimelineContainer; // Timeline container is not accessible. |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 82 | |
darin@apple.com | 2b241a6 | 2011-11-16 06:46:27 +0000 | [diff] [blame] | 83 | return mediaControlElementType(renderer()->node()); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | String AccessibilityMediaControl::controlTypeName() const |
| 87 | { |
abarth@webkit.org | b1e7d63 | 2012-08-29 23:04:26 +0000 | [diff] [blame] | 88 | DEFINE_STATIC_LOCAL(const String, mediaEnterFullscreenButtonName, (ASCIILiteral("EnterFullscreenButton"))); |
| 89 | DEFINE_STATIC_LOCAL(const String, mediaExitFullscreenButtonName, (ASCIILiteral("ExitFullscreenButton"))); |
| 90 | DEFINE_STATIC_LOCAL(const String, mediaMuteButtonName, (ASCIILiteral("MuteButton"))); |
| 91 | DEFINE_STATIC_LOCAL(const String, mediaPlayButtonName, (ASCIILiteral("PlayButton"))); |
| 92 | DEFINE_STATIC_LOCAL(const String, mediaSeekBackButtonName, (ASCIILiteral("SeekBackButton"))); |
| 93 | DEFINE_STATIC_LOCAL(const String, mediaSeekForwardButtonName, (ASCIILiteral("SeekForwardButton"))); |
| 94 | DEFINE_STATIC_LOCAL(const String, mediaRewindButtonName, (ASCIILiteral("RewindButton"))); |
| 95 | DEFINE_STATIC_LOCAL(const String, mediaReturnToRealtimeButtonName, (ASCIILiteral("ReturnToRealtimeButton"))); |
| 96 | DEFINE_STATIC_LOCAL(const String, mediaUnMuteButtonName, (ASCIILiteral("UnMuteButton"))); |
| 97 | DEFINE_STATIC_LOCAL(const String, mediaPauseButtonName, (ASCIILiteral("PauseButton"))); |
| 98 | DEFINE_STATIC_LOCAL(const String, mediaStatusDisplayName, (ASCIILiteral("StatusDisplay"))); |
| 99 | DEFINE_STATIC_LOCAL(const String, mediaCurrentTimeDisplay, (ASCIILiteral("CurrentTimeDisplay"))); |
| 100 | DEFINE_STATIC_LOCAL(const String, mediaTimeRemainingDisplay, (ASCIILiteral("TimeRemainingDisplay"))); |
| 101 | DEFINE_STATIC_LOCAL(const String, mediaShowClosedCaptionsButtonName, (ASCIILiteral("ShowClosedCaptionsButton"))); |
| 102 | DEFINE_STATIC_LOCAL(const String, mediaHideClosedCaptionsButtonName, (ASCIILiteral("HideClosedCaptionsButton"))); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 103 | |
| 104 | switch (controlType()) { |
jer.noble@apple.com | f2c2325 | 2012-03-16 19:21:31 +0000 | [diff] [blame] | 105 | case MediaEnterFullscreenButton: |
| 106 | return mediaEnterFullscreenButtonName; |
| 107 | case MediaExitFullscreenButton: |
| 108 | return mediaExitFullscreenButtonName; |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 109 | case MediaMuteButton: |
| 110 | return mediaMuteButtonName; |
| 111 | case MediaPlayButton: |
| 112 | return mediaPlayButtonName; |
| 113 | case MediaSeekBackButton: |
| 114 | return mediaSeekBackButtonName; |
| 115 | case MediaSeekForwardButton: |
| 116 | return mediaSeekForwardButtonName; |
| 117 | case MediaRewindButton: |
| 118 | return mediaRewindButtonName; |
| 119 | case MediaReturnToRealtimeButton: |
| 120 | return mediaReturnToRealtimeButtonName; |
| 121 | case MediaUnMuteButton: |
| 122 | return mediaUnMuteButtonName; |
| 123 | case MediaPauseButton: |
| 124 | return mediaPauseButtonName; |
| 125 | case MediaStatusDisplay: |
| 126 | return mediaStatusDisplayName; |
| 127 | case MediaCurrentTimeDisplay: |
| 128 | return mediaCurrentTimeDisplay; |
| 129 | case MediaTimeRemainingDisplay: |
| 130 | return mediaTimeRemainingDisplay; |
eric.carlson@apple.com | 9f2f9c6 | 2009-11-19 18:14:01 +0000 | [diff] [blame] | 131 | case MediaShowClosedCaptionsButton: |
| 132 | return mediaShowClosedCaptionsButtonName; |
| 133 | case MediaHideClosedCaptionsButton: |
| 134 | return mediaHideClosedCaptionsButtonName; |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 135 | |
| 136 | default: |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | return String(); |
| 141 | } |
| 142 | |
cfleizach@apple.com | 1eb3e14 | 2012-10-19 16:24:43 +0000 | [diff] [blame] | 143 | void AccessibilityMediaControl::accessibilityText(Vector<AccessibilityText>& textOrder) |
| 144 | { |
| 145 | String description = accessibilityDescription(); |
| 146 | if (!description.isEmpty()) |
| 147 | textOrder.append(AccessibilityText(description, AlternativeText)); |
| 148 | |
| 149 | String title = this->title(); |
| 150 | if (!title.isEmpty()) |
| 151 | textOrder.append(AccessibilityText(title, AlternativeText)); |
| 152 | |
| 153 | String helptext = helpText(); |
| 154 | if (!helptext.isEmpty()) |
| 155 | textOrder.append(AccessibilityText(helptext, HelpText)); |
| 156 | } |
| 157 | |
| 158 | |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 159 | String AccessibilityMediaControl::title() const |
| 160 | { |
abarth@webkit.org | b1e7d63 | 2012-08-29 23:04:26 +0000 | [diff] [blame] | 161 | DEFINE_STATIC_LOCAL(const String, controlsPanel, (ASCIILiteral("ControlsPanel"))); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 162 | |
| 163 | if (controlType() == MediaControlsPanel) |
| 164 | return localizedMediaControlElementString(controlsPanel); |
| 165 | |
| 166 | return AccessibilityRenderObject::title(); |
| 167 | } |
| 168 | |
| 169 | String AccessibilityMediaControl::accessibilityDescription() const |
| 170 | { |
| 171 | return localizedMediaControlElementString(controlTypeName()); |
| 172 | } |
| 173 | |
| 174 | String AccessibilityMediaControl::helpText() const |
| 175 | { |
| 176 | return localizedMediaControlElementHelpText(controlTypeName()); |
| 177 | } |
| 178 | |
| 179 | bool AccessibilityMediaControl::accessibilityIsIgnored() const |
| 180 | { |
| 181 | if (!m_renderer || !m_renderer->style() || m_renderer->style()->visibility() != VISIBLE || controlType() == MediaTimelineContainer) |
| 182 | return true; |
| 183 | |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | AccessibilityRole AccessibilityMediaControl::roleValue() const |
| 188 | { |
| 189 | switch (controlType()) { |
jer.noble@apple.com | f2c2325 | 2012-03-16 19:21:31 +0000 | [diff] [blame] | 190 | case MediaEnterFullscreenButton: |
| 191 | case MediaExitFullscreenButton: |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 192 | case MediaMuteButton: |
| 193 | case MediaPlayButton: |
| 194 | case MediaSeekBackButton: |
| 195 | case MediaSeekForwardButton: |
| 196 | case MediaRewindButton: |
| 197 | case MediaReturnToRealtimeButton: |
| 198 | case MediaUnMuteButton: |
| 199 | case MediaPauseButton: |
eric.carlson@apple.com | 9f2f9c6 | 2009-11-19 18:14:01 +0000 | [diff] [blame] | 200 | case MediaShowClosedCaptionsButton: |
| 201 | case MediaHideClosedCaptionsButton: |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 202 | return ButtonRole; |
| 203 | |
| 204 | case MediaStatusDisplay: |
| 205 | return StaticTextRole; |
| 206 | |
| 207 | case MediaTimelineContainer: |
| 208 | return GroupRole; |
| 209 | |
| 210 | default: |
| 211 | break; |
| 212 | } |
| 213 | |
| 214 | return UnknownRole; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | |
| 219 | // |
| 220 | // AccessibilityMediaControlsContainer |
| 221 | |
| 222 | AccessibilityMediaControlsContainer::AccessibilityMediaControlsContainer(RenderObject* renderer) |
| 223 | : AccessibilityMediaControl(renderer) |
| 224 | { |
| 225 | } |
| 226 | |
| 227 | PassRefPtr<AccessibilityObject> AccessibilityMediaControlsContainer::create(RenderObject* renderer) |
| 228 | { |
dmazzoni@google.com | c35bf3d | 2012-07-24 06:26:32 +0000 | [diff] [blame] | 229 | AccessibilityMediaControlsContainer* obj = new AccessibilityMediaControlsContainer(renderer); |
| 230 | obj->init(); |
| 231 | return adoptRef(obj); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | String AccessibilityMediaControlsContainer::accessibilityDescription() const |
| 235 | { |
| 236 | return localizedMediaControlElementString(elementTypeName()); |
| 237 | } |
| 238 | |
| 239 | String AccessibilityMediaControlsContainer::helpText() const |
| 240 | { |
| 241 | return localizedMediaControlElementHelpText(elementTypeName()); |
| 242 | } |
| 243 | |
| 244 | bool AccessibilityMediaControlsContainer::controllingVideoElement() const |
| 245 | { |
| 246 | if (!m_renderer->node()) |
| 247 | return true; |
| 248 | |
| 249 | MediaControlTimeDisplayElement* element = static_cast<MediaControlTimeDisplayElement*>(m_renderer->node()); |
| 250 | |
jer.noble@apple.com | a05cec4 | 2011-12-02 17:35:54 +0000 | [diff] [blame] | 251 | return toParentMediaElement(element)->isVideo(); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | const String AccessibilityMediaControlsContainer::elementTypeName() const |
| 255 | { |
abarth@webkit.org | b1e7d63 | 2012-08-29 23:04:26 +0000 | [diff] [blame] | 256 | DEFINE_STATIC_LOCAL(const String, videoElement, (ASCIILiteral("VideoElement"))); |
| 257 | DEFINE_STATIC_LOCAL(const String, audioElement, (ASCIILiteral("AudioElement"))); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 258 | |
| 259 | if (controllingVideoElement()) |
| 260 | return videoElement; |
| 261 | return audioElement; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | // |
| 266 | // AccessibilityMediaTimeline |
| 267 | |
| 268 | AccessibilityMediaTimeline::AccessibilityMediaTimeline(RenderObject* renderer) |
| 269 | : AccessibilitySlider(renderer) |
| 270 | { |
| 271 | } |
| 272 | |
| 273 | PassRefPtr<AccessibilityObject> AccessibilityMediaTimeline::create(RenderObject* renderer) |
| 274 | { |
dmazzoni@google.com | c35bf3d | 2012-07-24 06:26:32 +0000 | [diff] [blame] | 275 | AccessibilityMediaTimeline* obj = new AccessibilityMediaTimeline(renderer); |
| 276 | obj->init(); |
| 277 | return adoptRef(obj); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | String AccessibilityMediaTimeline::valueDescription() const |
| 281 | { |
darin@apple.com | 2b241a6 | 2011-11-16 06:46:27 +0000 | [diff] [blame] | 282 | Node* node = m_renderer->node(); |
| 283 | if (!node->hasTagName(inputTag)) |
| 284 | return String(); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 285 | |
darin@apple.com | 2b241a6 | 2011-11-16 06:46:27 +0000 | [diff] [blame] | 286 | float time = static_cast<HTMLInputElement*>(node)->value().toFloat(); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 287 | return localizedMediaTimeDescription(time); |
| 288 | } |
| 289 | |
| 290 | String AccessibilityMediaTimeline::helpText() const |
| 291 | { |
abarth@webkit.org | b1e7d63 | 2012-08-29 23:04:26 +0000 | [diff] [blame] | 292 | DEFINE_STATIC_LOCAL(const String, slider, (ASCIILiteral("Slider"))); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 293 | return localizedMediaControlElementHelpText(slider); |
| 294 | } |
| 295 | |
| 296 | |
| 297 | // |
| 298 | // AccessibilityMediaTimeDisplay |
| 299 | |
| 300 | AccessibilityMediaTimeDisplay::AccessibilityMediaTimeDisplay(RenderObject* renderer) |
| 301 | : AccessibilityMediaControl(renderer) |
| 302 | { |
| 303 | } |
| 304 | |
| 305 | PassRefPtr<AccessibilityObject> AccessibilityMediaTimeDisplay::create(RenderObject* renderer) |
| 306 | { |
dmazzoni@google.com | c35bf3d | 2012-07-24 06:26:32 +0000 | [diff] [blame] | 307 | AccessibilityMediaTimeDisplay* obj = new AccessibilityMediaTimeDisplay(renderer); |
| 308 | obj->init(); |
| 309 | return adoptRef(obj); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | bool AccessibilityMediaTimeDisplay::accessibilityIsIgnored() const |
| 313 | { |
| 314 | if (!m_renderer || !m_renderer->style() || m_renderer->style()->visibility() != VISIBLE) |
| 315 | return true; |
| 316 | |
| 317 | return !m_renderer->style()->width().value(); |
| 318 | } |
| 319 | |
| 320 | String AccessibilityMediaTimeDisplay::accessibilityDescription() const |
| 321 | { |
gyuyoung.kim@samsung.com | 9a89c26 | 2012-11-04 17:27:45 +0000 | [diff] [blame] | 322 | DEFINE_STATIC_LOCAL(const String, currentTimeDisplay, (ASCIILiteral("CurrentTimeDisplay"))); |
| 323 | DEFINE_STATIC_LOCAL(const String, timeRemainingDisplay, (ASCIILiteral("TimeRemainingDisplay"))); |
eric.carlson@apple.com | c779078 | 2009-08-25 23:07:19 +0000 | [diff] [blame] | 324 | |
| 325 | if (controlType() == MediaCurrentTimeDisplay) |
| 326 | return localizedMediaControlElementString(currentTimeDisplay); |
| 327 | |
| 328 | return localizedMediaControlElementString(timeRemainingDisplay); |
| 329 | } |
| 330 | |
| 331 | String AccessibilityMediaTimeDisplay::stringValue() const |
| 332 | { |
| 333 | if (!m_renderer || !m_renderer->node()) |
| 334 | return String(); |
| 335 | |
| 336 | MediaControlTimeDisplayElement* element = static_cast<MediaControlTimeDisplayElement*>(m_renderer->node()); |
| 337 | float time = element->currentValue(); |
| 338 | return localizedMediaTimeDescription(fabsf(time)); |
| 339 | } |
| 340 | |
| 341 | } // namespace WebCore |
| 342 | |
| 343 | #endif // ENABLE(VIDEO) |