/platform/external/webkit/WebCore/accessibility/AccessibilitySlider.cpp

https://github.com/aharish/totoro-gb-opensource-update2 · C++ · 162 lines · 101 code · 32 blank · 29 comment · 7 complexity · d7dbf097286a01458764fe73c2d80173 MD5 · raw file

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