Home | History | Annotate | Download | only in accessibility
      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 float AccessibilitySlider::valueForRange() const
    103 {
    104     return element()->value().toFloat();
    105 }
    106 
    107 float AccessibilitySlider::maxValueForRange() const
    108 {
    109     return getAttribute(maxAttr).toFloat();
    110 }
    111 
    112 float AccessibilitySlider::minValueForRange() const
    113 {
    114     return getAttribute(minAttr).toFloat();
    115 }
    116 
    117 void AccessibilitySlider::setValue(const String& value)
    118 {
    119     HTMLInputElement* input = element();
    120 
    121     if (input->value() == value)
    122         return;
    123 
    124     input->setValue(value);
    125 
    126     // Fire change event manually, as RenderSlider::setValueForPosition does.
    127     input->dispatchFormControlChangeEvent();
    128 }
    129 
    130 HTMLInputElement* AccessibilitySlider::element() const
    131 {
    132     return static_cast<HTMLInputElement*>(m_renderer->node());
    133 }
    134 
    135 
    136 AccessibilitySliderThumb::AccessibilitySliderThumb()
    137     : m_parentSlider(0)
    138 {
    139 }
    140 
    141 PassRefPtr<AccessibilitySliderThumb> AccessibilitySliderThumb::create()
    142 {
    143     return adoptRef(new AccessibilitySliderThumb());
    144 }
    145 
    146 IntRect AccessibilitySliderThumb::elementRect() const
    147 {
    148     if (!m_parentSlider->renderer())
    149         return IntRect();
    150 
    151     IntRect intRect = toRenderSlider(m_parentSlider->renderer())->thumbRect();
    152     FloatQuad floatQuad = m_parentSlider->renderer()->localToAbsoluteQuad(FloatRect(intRect));
    153 
    154     return floatQuad.enclosingBoundingBox();
    155 }
    156 
    157 IntSize AccessibilitySliderThumb::size() const
    158 {
    159     return elementRect().size();
    160 }
    161 
    162 } // namespace WebCore
    163