1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "third_party/blink/renderer/modules/accessibility/ax_media_element.h"
6
7 #include "third_party/blink/public/strings/grit/blink_strings.h"
8 #include "third_party/blink/renderer/core/html/media/html_media_element.h"
9 #include "third_party/blink/renderer/core/layout/layout_object.h"
10 #include "third_party/blink/renderer/platform/text/platform_locale.h"
11
12 namespace blink {
13
Create(LayoutObject * layout_object,AXObjectCacheImpl & ax_object_cache)14 AXObject* AccessibilityMediaElement::Create(
15 LayoutObject* layout_object,
16 AXObjectCacheImpl& ax_object_cache) {
17 DCHECK(layout_object->GetNode());
18 return MakeGarbageCollected<AccessibilityMediaElement>(layout_object,
19 ax_object_cache);
20 }
21
AccessibilityMediaElement(LayoutObject * layout_object,AXObjectCacheImpl & ax_object_cache)22 AccessibilityMediaElement::AccessibilityMediaElement(
23 LayoutObject* layout_object,
24 AXObjectCacheImpl& ax_object_cache)
25 : AXLayoutObject(layout_object, ax_object_cache) {}
26
TextAlternative(bool recursive,bool in_aria_labelled_by_traversal,AXObjectSet & visited,ax::mojom::NameFrom & name_from,AXRelatedObjectVector * related_objects,NameSources * name_sources) const27 String AccessibilityMediaElement::TextAlternative(
28 bool recursive,
29 bool in_aria_labelled_by_traversal,
30 AXObjectSet& visited,
31 ax::mojom::NameFrom& name_from,
32 AXRelatedObjectVector* related_objects,
33 NameSources* name_sources) const {
34 if (IsUnplayable()) {
35 HTMLMediaElement* element =
36 static_cast<HTMLMediaElement*>(layout_object_->GetNode());
37 return element->GetLocale().QueryString(IDS_MEDIA_PLAYBACK_ERROR);
38 }
39 return AXLayoutObject::TextAlternative(
40 recursive, in_aria_labelled_by_traversal, visited, name_from,
41 related_objects, name_sources);
42 }
43
Restriction() const44 AXRestriction AccessibilityMediaElement::Restriction() const {
45 if (IsUnplayable())
46 return kRestrictionDisabled;
47
48 return AXNodeObject::Restriction();
49 }
50
IsUnplayable() const51 bool AccessibilityMediaElement::IsUnplayable() const {
52 HTMLMediaElement* element =
53 static_cast<HTMLMediaElement*>(layout_object_->GetNode());
54 HTMLMediaElement::NetworkState network_state = element->getNetworkState();
55 return (element->error() ||
56 network_state == HTMLMediaElement::kNetworkEmpty ||
57 network_state == HTMLMediaElement::kNetworkNoSource);
58 }
59
60 } // namespace blink
61