2 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include "core/accessibility/AXSlider.h"
32 #include "core/accessibility/AXObjectCacheImpl.h"
33 #include "core/dom/shadow/ShadowRoot.h"
34 #include "core/html/HTMLInputElement.h"
35 #include "core/html/shadow/ShadowElementNames.h"
36 #include "core/rendering/RenderObject.h"
40 using namespace HTMLNames;
42 AXSlider::AXSlider(RenderObject* renderer)
43 : AXRenderObject(renderer)
47 PassRefPtr<AXSlider> AXSlider::create(RenderObject* renderer)
49 return adoptRef(new AXSlider(renderer));
52 AccessibilityOrientation AXSlider::orientation() const
54 // Default to horizontal in the unknown case.
56 return AccessibilityOrientationHorizontal;
58 RenderStyle* style = m_renderer->style();
60 return AccessibilityOrientationHorizontal;
62 ControlPart styleAppearance = style->appearance();
63 switch (styleAppearance) {
64 case SliderThumbHorizontalPart:
65 case SliderHorizontalPart:
67 case MediaFullScreenVolumeSliderPart:
68 return AccessibilityOrientationHorizontal;
70 case SliderThumbVerticalPart:
71 case SliderVerticalPart:
72 case MediaVolumeSliderPart:
73 return AccessibilityOrientationVertical;
76 return AccessibilityOrientationHorizontal;
80 void AXSlider::addChildren()
82 ASSERT(!m_haveChildren);
84 m_haveChildren = true;
86 AXObjectCacheImpl* cache = toAXObjectCacheImpl(m_renderer->document().axObjectCache());
88 AXSliderThumb* thumb = static_cast<AXSliderThumb*>(cache->getOrCreate(SliderThumbRole));
89 thumb->setParent(this);
91 // Before actually adding the value indicator to the hierarchy,
92 // allow the platform to make a final decision about it.
93 if (thumb->accessibilityIsIgnored())
94 cache->remove(thumb->axObjectID());
96 m_children.append(thumb);
99 const AtomicString& AXSlider::getAttribute(const QualifiedName& attribute) const
101 return element()->getAttribute(attribute);
104 AXObject* AXSlider::elementAccessibilityHitTest(const IntPoint& point) const
106 if (m_children.size()) {
107 ASSERT(m_children.size() == 1);
108 if (m_children[0]->elementRect().contains(point))
109 return m_children[0].get();
112 return axObjectCache()->getOrCreate(m_renderer);
115 void AXSlider::setValue(const String& value)
117 HTMLInputElement* input = element();
119 if (input->value() == value)
122 input->setValue(value);
124 // Fire change event manually, as RenderSlider::setValueForPosition does.
125 input->dispatchFormControlChangeEvent();
128 HTMLInputElement* AXSlider::element() const
130 return toHTMLInputElement(m_renderer->node());
134 AXSliderThumb::AXSliderThumb()
138 PassRefPtr<AXSliderThumb> AXSliderThumb::create()
140 return adoptRef(new AXSliderThumb());
143 LayoutRect AXSliderThumb::elementRect() const
148 RenderObject* sliderRenderer = m_parent->renderer();
149 if (!sliderRenderer || !sliderRenderer->isSlider())
151 return toElement(sliderRenderer->node())->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderThumb())->boundingBox();
154 bool AXSliderThumb::computeAccessibilityIsIgnored() const
156 return accessibilityIsIgnoredByDefault();