| OLD | NEW |
| (Empty) |
| 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 #include "core/accessibility/AXMediaControls.h" | |
| 32 | |
| 33 #include "core/html/HTMLMediaElement.h" | |
| 34 #include "platform/text/PlatformLocale.h" | |
| 35 | |
| 36 namespace blink { | |
| 37 | |
| 38 using blink::WebLocalizedString; | |
| 39 using namespace HTMLNames; | |
| 40 | |
| 41 static inline String queryString(WebLocalizedString::Name name) | |
| 42 { | |
| 43 return Locale::defaultLocale().queryString(name); | |
| 44 } | |
| 45 | |
| 46 AccessibilityMediaControl::AccessibilityMediaControl(RenderObject* renderer) | |
| 47 : AXRenderObject(renderer) | |
| 48 { | |
| 49 } | |
| 50 | |
| 51 PassRefPtr<AXObject> AccessibilityMediaControl::create(RenderObject* renderer) | |
| 52 { | |
| 53 ASSERT(renderer->node()); | |
| 54 | |
| 55 switch (mediaControlElementType(renderer->node())) { | |
| 56 case MediaSlider: | |
| 57 return AccessibilityMediaTimeline::create(renderer); | |
| 58 | |
| 59 case MediaCurrentTimeDisplay: | |
| 60 case MediaTimeRemainingDisplay: | |
| 61 return AccessibilityMediaTimeDisplay::create(renderer); | |
| 62 | |
| 63 case MediaControlsPanel: | |
| 64 return AXMediaControlsContainer::create(renderer); | |
| 65 | |
| 66 default: | |
| 67 return adoptRef(new AccessibilityMediaControl(renderer)); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 MediaControlElementType AccessibilityMediaControl::controlType() const | |
| 72 { | |
| 73 if (!renderer() || !renderer()->node()) | |
| 74 return MediaTimelineContainer; // Timeline container is not accessible. | |
| 75 | |
| 76 return mediaControlElementType(renderer()->node()); | |
| 77 } | |
| 78 | |
| 79 String AccessibilityMediaControl::title() const | |
| 80 { | |
| 81 // FIXME: the ControlsPanel container should never be visible in the | |
| 82 // accessibility hierarchy. | |
| 83 if (controlType() == MediaControlsPanel) | |
| 84 return queryString(WebLocalizedString::AXMediaDefault); | |
| 85 | |
| 86 return AXRenderObject::title(); | |
| 87 } | |
| 88 | |
| 89 String AccessibilityMediaControl::accessibilityDescription() const | |
| 90 { | |
| 91 switch (controlType()) { | |
| 92 case MediaEnterFullscreenButton: | |
| 93 return queryString(WebLocalizedString::AXMediaEnterFullscreenButton); | |
| 94 case MediaExitFullscreenButton: | |
| 95 return queryString(WebLocalizedString::AXMediaExitFullscreenButton); | |
| 96 case MediaMuteButton: | |
| 97 return queryString(WebLocalizedString::AXMediaMuteButton); | |
| 98 case MediaPlayButton: | |
| 99 return queryString(WebLocalizedString::AXMediaPlayButton); | |
| 100 case MediaUnMuteButton: | |
| 101 return queryString(WebLocalizedString::AXMediaUnMuteButton); | |
| 102 case MediaPauseButton: | |
| 103 return queryString(WebLocalizedString::AXMediaPauseButton); | |
| 104 case MediaStatusDisplay: | |
| 105 return queryString(WebLocalizedString::AXMediaStatusDisplay); | |
| 106 case MediaCurrentTimeDisplay: | |
| 107 return queryString(WebLocalizedString::AXMediaCurrentTimeDisplay); | |
| 108 case MediaTimeRemainingDisplay: | |
| 109 return queryString(WebLocalizedString::AXMediaTimeRemainingDisplay); | |
| 110 case MediaShowClosedCaptionsButton: | |
| 111 return queryString(WebLocalizedString::AXMediaShowClosedCaptionsButton); | |
| 112 case MediaHideClosedCaptionsButton: | |
| 113 return queryString(WebLocalizedString::AXMediaHideClosedCaptionsButton); | |
| 114 case MediaCastOffButton: | |
| 115 return queryString(WebLocalizedString::AxMediaCastOffButton); | |
| 116 case MediaCastOnButton: | |
| 117 return queryString(WebLocalizedString::AxMediaCastOnButton); | |
| 118 default: | |
| 119 return queryString(WebLocalizedString::AXMediaDefault); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 String AccessibilityMediaControl::helpText() const | |
| 124 { | |
| 125 switch (controlType()) { | |
| 126 case MediaEnterFullscreenButton: | |
| 127 return queryString(WebLocalizedString::AXMediaEnterFullscreenButtonHelp)
; | |
| 128 case MediaExitFullscreenButton: | |
| 129 return queryString(WebLocalizedString::AXMediaExitFullscreenButtonHelp); | |
| 130 case MediaMuteButton: | |
| 131 return queryString(WebLocalizedString::AXMediaMuteButtonHelp); | |
| 132 case MediaPlayButton: | |
| 133 return queryString(WebLocalizedString::AXMediaPlayButtonHelp); | |
| 134 case MediaUnMuteButton: | |
| 135 return queryString(WebLocalizedString::AXMediaUnMuteButtonHelp); | |
| 136 case MediaPauseButton: | |
| 137 return queryString(WebLocalizedString::AXMediaPauseButtonHelp); | |
| 138 case MediaStatusDisplay: | |
| 139 return queryString(WebLocalizedString::AXMediaStatusDisplayHelp); | |
| 140 case MediaCurrentTimeDisplay: | |
| 141 return queryString(WebLocalizedString::AXMediaCurrentTimeDisplayHelp); | |
| 142 case MediaTimeRemainingDisplay: | |
| 143 return queryString(WebLocalizedString::AXMediaTimeRemainingDisplayHelp); | |
| 144 case MediaShowClosedCaptionsButton: | |
| 145 return queryString(WebLocalizedString::AXMediaShowClosedCaptionsButtonHe
lp); | |
| 146 case MediaHideClosedCaptionsButton: | |
| 147 return queryString(WebLocalizedString::AXMediaHideClosedCaptionsButtonHe
lp); | |
| 148 case MediaCastOffButton: | |
| 149 return queryString(WebLocalizedString::AxMediaCastOffButtonHelp); | |
| 150 case MediaCastOnButton: | |
| 151 return queryString(WebLocalizedString::AxMediaCastOnButtonHelp); | |
| 152 default: | |
| 153 return queryString(WebLocalizedString::AXMediaDefault); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 bool AccessibilityMediaControl::computeAccessibilityIsIgnored() const | |
| 158 { | |
| 159 if (!m_renderer || !m_renderer->style() || m_renderer->style()->visibility()
!= VISIBLE || controlType() == MediaTimelineContainer) | |
| 160 return true; | |
| 161 | |
| 162 return accessibilityIsIgnoredByDefault(); | |
| 163 } | |
| 164 | |
| 165 AccessibilityRole AccessibilityMediaControl::roleValue() const | |
| 166 { | |
| 167 switch (controlType()) { | |
| 168 case MediaEnterFullscreenButton: | |
| 169 case MediaExitFullscreenButton: | |
| 170 case MediaMuteButton: | |
| 171 case MediaPlayButton: | |
| 172 case MediaUnMuteButton: | |
| 173 case MediaPauseButton: | |
| 174 case MediaShowClosedCaptionsButton: | |
| 175 case MediaHideClosedCaptionsButton: | |
| 176 return ButtonRole; | |
| 177 | |
| 178 case MediaStatusDisplay: | |
| 179 return StaticTextRole; | |
| 180 | |
| 181 case MediaTimelineContainer: | |
| 182 return GroupRole; | |
| 183 | |
| 184 default: | |
| 185 break; | |
| 186 } | |
| 187 | |
| 188 return UnknownRole; | |
| 189 } | |
| 190 | |
| 191 | |
| 192 | |
| 193 // | |
| 194 // AXMediaControlsContainer | |
| 195 | |
| 196 AXMediaControlsContainer::AXMediaControlsContainer(RenderObject* renderer) | |
| 197 : AccessibilityMediaControl(renderer) | |
| 198 { | |
| 199 } | |
| 200 | |
| 201 PassRefPtr<AXObject> AXMediaControlsContainer::create(RenderObject* renderer) | |
| 202 { | |
| 203 return adoptRef(new AXMediaControlsContainer(renderer)); | |
| 204 } | |
| 205 | |
| 206 String AXMediaControlsContainer::accessibilityDescription() const | |
| 207 { | |
| 208 return queryString(controllingVideoElement() ? WebLocalizedString::AXMediaVi
deoElement : WebLocalizedString::AXMediaAudioElement); | |
| 209 } | |
| 210 | |
| 211 String AXMediaControlsContainer::helpText() const | |
| 212 { | |
| 213 return queryString(controllingVideoElement() ? WebLocalizedString::AXMediaVi
deoElementHelp : WebLocalizedString::AXMediaAudioElementHelp); | |
| 214 } | |
| 215 | |
| 216 bool AXMediaControlsContainer::controllingVideoElement() const | |
| 217 { | |
| 218 Node* node = m_renderer->node(); | |
| 219 if (!node) | |
| 220 return true; | |
| 221 | |
| 222 return isHTMLVideoElement(toParentMediaElement(node)); | |
| 223 } | |
| 224 | |
| 225 bool AXMediaControlsContainer::computeAccessibilityIsIgnored() const | |
| 226 { | |
| 227 return accessibilityIsIgnoredByDefault(); | |
| 228 } | |
| 229 | |
| 230 // | |
| 231 // AccessibilityMediaTimeline | |
| 232 | |
| 233 static String localizedMediaTimeDescription(float /*time*/) | |
| 234 { | |
| 235 // FIXME: To be fixed. See | |
| 236 // http://trac.webkit.org/browser/trunk/Source/WebCore/platform/LocalizedStr
ings.cpp#L928 | |
| 237 return String(); | |
| 238 } | |
| 239 | |
| 240 AccessibilityMediaTimeline::AccessibilityMediaTimeline(RenderObject* renderer) | |
| 241 : AXSlider(renderer) | |
| 242 { | |
| 243 } | |
| 244 | |
| 245 PassRefPtr<AXObject> AccessibilityMediaTimeline::create(RenderObject* renderer) | |
| 246 { | |
| 247 return adoptRef(new AccessibilityMediaTimeline(renderer)); | |
| 248 } | |
| 249 | |
| 250 String AccessibilityMediaTimeline::valueDescription() const | |
| 251 { | |
| 252 Node* node = m_renderer->node(); | |
| 253 if (!isHTMLInputElement(node)) | |
| 254 return String(); | |
| 255 | |
| 256 return localizedMediaTimeDescription(toHTMLInputElement(node)->value().toFlo
at()); | |
| 257 } | |
| 258 | |
| 259 String AccessibilityMediaTimeline::helpText() const | |
| 260 { | |
| 261 return queryString(WebLocalizedString::AXMediaSliderHelp); | |
| 262 } | |
| 263 | |
| 264 | |
| 265 // | |
| 266 // AccessibilityMediaTimeDisplay | |
| 267 | |
| 268 AccessibilityMediaTimeDisplay::AccessibilityMediaTimeDisplay(RenderObject* rende
rer) | |
| 269 : AccessibilityMediaControl(renderer) | |
| 270 { | |
| 271 } | |
| 272 | |
| 273 PassRefPtr<AXObject> AccessibilityMediaTimeDisplay::create(RenderObject* rendere
r) | |
| 274 { | |
| 275 return adoptRef(new AccessibilityMediaTimeDisplay(renderer)); | |
| 276 } | |
| 277 | |
| 278 bool AccessibilityMediaTimeDisplay::computeAccessibilityIsIgnored() const | |
| 279 { | |
| 280 if (!m_renderer || !m_renderer->style() || m_renderer->style()->visibility()
!= VISIBLE) | |
| 281 return true; | |
| 282 | |
| 283 if (!m_renderer->style()->width().value()) | |
| 284 return true; | |
| 285 | |
| 286 return accessibilityIsIgnoredByDefault(); | |
| 287 } | |
| 288 | |
| 289 String AccessibilityMediaTimeDisplay::accessibilityDescription() const | |
| 290 { | |
| 291 if (controlType() == MediaCurrentTimeDisplay) | |
| 292 return queryString(WebLocalizedString::AXMediaCurrentTimeDisplay); | |
| 293 return queryString(WebLocalizedString::AXMediaTimeRemainingDisplay); | |
| 294 } | |
| 295 | |
| 296 String AccessibilityMediaTimeDisplay::stringValue() const | |
| 297 { | |
| 298 if (!m_renderer || !m_renderer->node()) | |
| 299 return String(); | |
| 300 | |
| 301 MediaControlTimeDisplayElement* element = static_cast<MediaControlTimeDispla
yElement*>(m_renderer->node()); | |
| 302 float time = element->currentValue(); | |
| 303 return localizedMediaTimeDescription(fabsf(time)); | |
| 304 } | |
| 305 | |
| 306 } // namespace blink | |
| OLD | NEW |