2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "RenderSlider.h"
24 #include "CSSPropertyNames.h"
25 #include "CSSStyleSelector.h"
28 #include "EventHandler.h"
29 #include "EventNames.h"
31 #include "HTMLInputElement.h"
32 #include "HTMLNames.h"
33 #include "HTMLParserIdioms.h"
34 #include "MediaControlElements.h"
35 #include "MouseEvent.h"
37 #include "RenderLayer.h"
38 #include "RenderTheme.h"
39 #include "RenderView.h"
40 #include "ShadowRoot.h"
41 #include "SliderThumbElement.h"
42 #include "StepRange.h"
43 #include <wtf/MathExtras.h>
49 static const int defaultTrackLength = 129;
51 RenderSlider::RenderSlider(HTMLInputElement* element)
52 : RenderBlock(element)
54 // We assume RenderSlider works only with <input type=range>.
55 ASSERT(element->isRangeControl());
58 RenderSlider::~RenderSlider()
62 int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode) const
64 // FIXME: Patch this function for writing-mode.
65 return height() + marginTop();
68 void RenderSlider::computePreferredLogicalWidths()
70 m_minPreferredLogicalWidth = 0;
71 m_maxPreferredLogicalWidth = 0;
73 if (style()->width().isFixed() && style()->width().value() > 0)
74 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeContentBoxLogicalWidth(style()->width().value());
76 m_maxPreferredLogicalWidth = defaultTrackLength * style()->effectiveZoom();
78 if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) {
79 m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value()));
80 m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value()));
81 } else if (style()->width().isPercent() || (style()->width().isAuto() && style()->height().isPercent()))
82 m_minPreferredLogicalWidth = 0;
84 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
86 if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
87 m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
88 m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
91 LayoutUnit toAdd = borderAndPaddingWidth();
92 m_minPreferredLogicalWidth += toAdd;
93 m_maxPreferredLogicalWidth += toAdd;
95 setPreferredLogicalWidthsDirty(false);
98 void RenderSlider::layout()
100 // FIXME: Find a way to cascade appearance.
101 // http://webkit.org/b/62535
102 RenderBox* thumbBox = sliderThumbElementOf(node())->renderBox();
103 if (thumbBox && thumbBox->isSliderThumb())
104 static_cast<RenderSliderThumb*>(thumbBox)->updateAppearance(style());
105 if (RenderObject* limiterRenderer = trackLimiterElementOf(node())->renderer()) {
106 if (limiterRenderer->isSliderThumb())
107 static_cast<RenderSliderThumb*>(limiterRenderer)->updateAppearance(style());
110 RenderBlock::layout();
114 LayoutUnit heightDiff = thumbBox->height() - contentHeight();
116 thumbBox->setY(thumbBox->y() - (heightDiff / 2));
119 bool RenderSlider::inDragMode() const
121 return sliderThumbElementOf(node())->active();
124 } // namespace WebCore