1/*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 *
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.
8 *
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.
13 *
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.
18 *
19 */
20
21#include "config.h"
22#include "RenderSlider.h"
23
24#include "CSSPropertyNames.h"
25#include "Document.h"
26#include "Event.h"
27#include "Frame.h"
28#include "HTMLInputElement.h"
29#include "HTMLNames.h"
30#include "HTMLParserIdioms.h"
31#include "MediaControlElements.h"
32#include "MouseEvent.h"
33#include "Node.h"
34#include "RenderLayer.h"
35#include "RenderTheme.h"
36#include "RenderView.h"
37#include "ShadowRoot.h"
38#include "SliderThumbElement.h"
39#include "StepRange.h"
40#include "StyleResolver.h"
41#include <wtf/IsoMallocInlines.h>
42#include <wtf/MathExtras.h>
43#include <wtf/StackStats.h>
44
45namespace WebCore {
46
47WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSlider);
48
49const int RenderSlider::defaultTrackLength = 129;
50
51RenderSlider::RenderSlider(HTMLInputElement& element, RenderStyle&& style)
52 : RenderFlexibleBox(element, WTFMove(style))
53{
54 // We assume RenderSlider works only with <input type=range>.
55 ASSERT(element.isRangeControl());
56}
57
58RenderSlider::~RenderSlider() = default;
59
60HTMLInputElement& RenderSlider::element() const
61{
62 return downcast<HTMLInputElement>(nodeForNonAnonymous());
63}
64
65int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode) const
66{
67 // FIXME: Patch this function for writing-mode.
68 return height() + marginTop();
69}
70
71void RenderSlider::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
72{
73 maxLogicalWidth = defaultTrackLength * style().effectiveZoom();
74 if (!style().width().isPercentOrCalculated())
75 minLogicalWidth = maxLogicalWidth;
76}
77
78void RenderSlider::computePreferredLogicalWidths()
79{
80 m_minPreferredLogicalWidth = 0;
81 m_maxPreferredLogicalWidth = 0;
82
83 if (style().width().isFixed() && style().width().value() > 0)
84 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style().width().value());
85 else
86 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
87
88 if (style().minWidth().isFixed() && style().minWidth().value() > 0) {
89 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().minWidth().value()));
90 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().minWidth().value()));
91 }
92
93 if (style().maxWidth().isFixed()) {
94 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value()));
95 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value()));
96 }
97
98 LayoutUnit toAdd = horizontalBorderAndPaddingExtent();
99 m_minPreferredLogicalWidth += toAdd;
100 m_maxPreferredLogicalWidth += toAdd;
101
102 setPreferredLogicalWidthsDirty(false);
103}
104
105void RenderSlider::layout()
106{
107 StackStats::LayoutCheckPoint layoutCheckPoint;
108
109 // FIXME: Find a way to cascade appearance. http://webkit.org/b/62535
110 RenderBox* thumbBox = element().sliderThumbElement()->renderBox();
111 if (thumbBox && thumbBox->isSliderThumb())
112 static_cast<RenderSliderThumb*>(thumbBox)->updateAppearance(&style());
113
114 RenderFlexibleBox::layout();
115}
116
117bool RenderSlider::inDragMode() const
118{
119 return element().sliderThumbElement()->active();
120}
121
122} // namespace WebCore
123