1/*
2 * Copyright (C) 2016 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 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28#include "AccessibilityAttachment.h"
29
30#include "HTMLAttachmentElement.h"
31#include "HTMLNames.h"
32#include "LocalizedStrings.h"
33#include "RenderAttachment.h"
34
35#if ENABLE(ATTACHMENT_ELEMENT)
36
37namespace WebCore {
38
39using namespace HTMLNames;
40
41AccessibilityAttachment::AccessibilityAttachment(RenderAttachment* renderer)
42 : AccessibilityRenderObject(renderer)
43{
44}
45
46Ref<AccessibilityAttachment> AccessibilityAttachment::create(RenderAttachment* renderer)
47{
48 return adoptRef(*new AccessibilityAttachment(renderer));
49}
50
51bool AccessibilityAttachment::hasProgress(float* progress) const
52{
53 auto& progressString = getAttribute(progressAttr);
54 bool validProgress;
55 float result = std::max<float>(std::min<float>(progressString.toFloat(&validProgress), 1), 0);
56 if (progress)
57 *progress = result;
58 return validProgress;
59}
60
61float AccessibilityAttachment::valueForRange() const
62{
63 float progress = 0;
64 hasProgress(&progress);
65 return progress;
66}
67
68HTMLAttachmentElement* AccessibilityAttachment::attachmentElement() const
69{
70 ASSERT(is<HTMLAttachmentElement>(node()));
71 if (!is<HTMLAttachmentElement>(node()))
72 return nullptr;
73
74 return downcast<HTMLAttachmentElement>(node());
75}
76
77String AccessibilityAttachment::roleDescription() const
78{
79 return AXAttachmentRoleText();
80}
81
82bool AccessibilityAttachment::computeAccessibilityIsIgnored() const
83{
84 return false;
85}
86
87void AccessibilityAttachment::accessibilityText(Vector<AccessibilityText>& textOrder) const
88{
89 HTMLAttachmentElement* attachmentElement = this->attachmentElement();
90 if (!attachmentElement)
91 return;
92
93 auto title = attachmentElement->attachmentTitle();
94 auto& subtitle = getAttribute(subtitleAttr);
95 auto& action = getAttribute(actionAttr);
96
97 if (action.length())
98 textOrder.append(AccessibilityText(action, AccessibilityTextSource::Action));
99
100 if (title.length())
101 textOrder.append(AccessibilityText(title, AccessibilityTextSource::Title));
102
103 if (subtitle.length())
104 textOrder.append(AccessibilityText(subtitle, AccessibilityTextSource::Subtitle));
105}
106
107} // namespace WebCore
108
109#endif // ENABLE(ATTACHMENT_ELEMENT)
110
111