|
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 #include "config.h" |
|
30 #include "AccessibilitySlider.h" |
|
31 |
|
32 #include "AXObjectCache.h" |
|
33 #include "HTMLInputElement.h" |
|
34 #include "HTMLNames.h" |
|
35 #include "RenderObject.h" |
|
36 #include "RenderSlider.h" |
|
37 |
|
38 namespace WebCore { |
|
39 |
|
40 using namespace HTMLNames; |
|
41 |
|
42 AccessibilitySlider::AccessibilitySlider(RenderObject* renderer) |
|
43 : AccessibilityRenderObject(renderer) |
|
44 { |
|
45 } |
|
46 |
|
47 PassRefPtr<AccessibilitySlider> AccessibilitySlider::create(RenderObject* renderer) |
|
48 { |
|
49 return adoptRef(new AccessibilitySlider(renderer)); |
|
50 } |
|
51 |
|
52 const AccessibilityObject::AccessibilityChildrenVector& AccessibilitySlider::children() |
|
53 { |
|
54 if (!m_haveChildren) |
|
55 addChildren(); |
|
56 return m_children; |
|
57 } |
|
58 |
|
59 AccessibilityOrientation AccessibilitySlider::orientation() const |
|
60 { |
|
61 // Default to horizontal in the unknown case. |
|
62 if (!m_renderer) |
|
63 return AccessibilityOrientationHorizontal; |
|
64 |
|
65 RenderStyle* style = m_renderer->style(); |
|
66 if (!style) |
|
67 return AccessibilityOrientationHorizontal; |
|
68 |
|
69 ControlPart styleAppearance = style->appearance(); |
|
70 switch (styleAppearance) { |
|
71 case SliderThumbHorizontalPart: |
|
72 case SliderHorizontalPart: |
|
73 case MediaSliderPart: |
|
74 return AccessibilityOrientationHorizontal; |
|
75 |
|
76 case SliderThumbVerticalPart: |
|
77 case SliderVerticalPart: |
|
78 case MediaVolumeSliderPart: |
|
79 return AccessibilityOrientationVertical; |
|
80 |
|
81 default: |
|
82 return AccessibilityOrientationHorizontal; |
|
83 } |
|
84 } |
|
85 |
|
86 void AccessibilitySlider::addChildren() |
|
87 { |
|
88 ASSERT(!m_haveChildren); |
|
89 |
|
90 m_haveChildren = true; |
|
91 |
|
92 AccessibilitySliderThumb* thumb = static_cast<AccessibilitySliderThumb*>(m_renderer->document()->axObjectCache()->getOrCreate(SliderThumbRole)); |
|
93 thumb->setParentObject(this); |
|
94 m_children.append(thumb); |
|
95 } |
|
96 |
|
97 const AtomicString& AccessibilitySlider::getAttribute(const QualifiedName& attribute) const |
|
98 { |
|
99 return element()->getAttribute(attribute); |
|
100 } |
|
101 |
|
102 bool AccessibilitySlider::accessibilityIsIgnored() const |
|
103 { |
|
104 AccessibilityObjectInclusion decision = accessibilityIsIgnoredBase(); |
|
105 if (decision == IncludeObject) |
|
106 return false; |
|
107 if (decision == IgnoreObject) |
|
108 return true; |
|
109 |
|
110 return false; |
|
111 } |
|
112 |
|
113 float AccessibilitySlider::valueForRange() const |
|
114 { |
|
115 return element()->value().toFloat(); |
|
116 } |
|
117 |
|
118 float AccessibilitySlider::maxValueForRange() const |
|
119 { |
|
120 return getAttribute(maxAttr).toFloat(); |
|
121 } |
|
122 |
|
123 float AccessibilitySlider::minValueForRange() const |
|
124 { |
|
125 return getAttribute(minAttr).toFloat(); |
|
126 } |
|
127 |
|
128 void AccessibilitySlider::setValue(const String& value) |
|
129 { |
|
130 HTMLInputElement* input = element(); |
|
131 |
|
132 if (input->value() == value) |
|
133 return; |
|
134 |
|
135 input->setValue(value); |
|
136 |
|
137 // Fire change event manually, as RenderSlider::setValueForPosition does. |
|
138 input->dispatchFormControlChangeEvent(); |
|
139 } |
|
140 |
|
141 HTMLInputElement* AccessibilitySlider::element() const |
|
142 { |
|
143 return static_cast<HTMLInputElement*>(m_renderer->node()); |
|
144 } |
|
145 |
|
146 |
|
147 AccessibilitySliderThumb::AccessibilitySliderThumb() |
|
148 : m_parentSlider(0) |
|
149 { |
|
150 } |
|
151 |
|
152 PassRefPtr<AccessibilitySliderThumb> AccessibilitySliderThumb::create() |
|
153 { |
|
154 return adoptRef(new AccessibilitySliderThumb()); |
|
155 } |
|
156 |
|
157 IntRect AccessibilitySliderThumb::elementRect() const |
|
158 { |
|
159 if (!m_parentSlider->renderer()) |
|
160 return IntRect(); |
|
161 |
|
162 IntRect intRect = toRenderSlider(m_parentSlider->renderer())->thumbRect(); |
|
163 FloatQuad floatQuad = m_parentSlider->renderer()->localToAbsoluteQuad(FloatRect(intRect)); |
|
164 |
|
165 return floatQuad.enclosingBoundingBox(); |
|
166 } |
|
167 |
|
168 IntSize AccessibilitySliderThumb::size() const |
|
169 { |
|
170 return elementRect().size(); |
|
171 } |
|
172 |
|
173 } // namespace WebCore |