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 "MouseEvent.h"
|
---|
32 | #include "Node.h"
|
---|
33 | #include "RenderLayer.h"
|
---|
34 | #include "RenderTheme.h"
|
---|
35 | #include "RenderView.h"
|
---|
36 | #include "ShadowRoot.h"
|
---|
37 | #include "SliderThumbElement.h"
|
---|
38 | #include "StepRange.h"
|
---|
39 | #include "StyleResolver.h"
|
---|
40 | #include <wtf/IsoMallocInlines.h>
|
---|
41 | #include <wtf/MathExtras.h>
|
---|
42 | #include <wtf/StackStats.h>
|
---|
43 |
|
---|
44 | namespace WebCore {
|
---|
45 |
|
---|
46 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSlider);
|
---|
47 |
|
---|
48 | const int RenderSlider::defaultTrackLength = 129;
|
---|
49 |
|
---|
50 | RenderSlider::RenderSlider(HTMLInputElement& element, RenderStyle&& style)
|
---|
51 | : RenderFlexibleBox(element, WTFMove(style))
|
---|
52 | {
|
---|
53 | // We assume RenderSlider works only with <input type=range>.
|
---|
54 | ASSERT(element.isRangeControl());
|
---|
55 | }
|
---|
56 |
|
---|
57 | RenderSlider::~RenderSlider() = default;
|
---|
58 |
|
---|
59 | HTMLInputElement& RenderSlider::element() const
|
---|
60 | {
|
---|
61 | return downcast<HTMLInputElement>(nodeForNonAnonymous());
|
---|
62 | }
|
---|
63 |
|
---|
64 | LayoutUnit RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode) const
|
---|
65 | {
|
---|
66 | // FIXME: Patch this function for writing-mode.
|
---|
67 | return height() + marginTop();
|
---|
68 | }
|
---|
69 |
|
---|
70 | void RenderSlider::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
|
---|
71 | {
|
---|
72 | if (shouldApplySizeContainment())
|
---|
73 | return;
|
---|
74 | maxLogicalWidth = defaultTrackLength * style().effectiveZoom();
|
---|
75 | if (!style().width().isPercentOrCalculated())
|
---|
76 | minLogicalWidth = maxLogicalWidth;
|
---|
77 | }
|
---|
78 |
|
---|
79 | void RenderSlider::computePreferredLogicalWidths()
|
---|
80 | {
|
---|
81 | m_minPreferredLogicalWidth = 0;
|
---|
82 | m_maxPreferredLogicalWidth = 0;
|
---|
83 |
|
---|
84 | if (style().width().isFixed() && style().width().value() > 0)
|
---|
85 | m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style().width());
|
---|
86 | else
|
---|
87 | computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
|
---|
88 |
|
---|
89 | RenderBox::computePreferredLogicalWidths(style().minWidth(), style().maxWidth(), horizontalBorderAndPaddingExtent());
|
---|
90 |
|
---|
91 | setPreferredLogicalWidthsDirty(false);
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool RenderSlider::inDragMode() const
|
---|
95 | {
|
---|
96 | return element().sliderThumbElement()->active();
|
---|
97 | }
|
---|
98 |
|
---|
99 | double RenderSlider::valueRatio() const
|
---|
100 | {
|
---|
101 | auto& element = this->element();
|
---|
102 |
|
---|
103 | auto min = element.minimum();
|
---|
104 | auto max = element.maximum();
|
---|
105 | auto value = element.valueAsNumber();
|
---|
106 |
|
---|
107 | if (max <= min)
|
---|
108 | return 0;
|
---|
109 | return (value - min) / (max - min);
|
---|
110 | }
|
---|
111 |
|
---|
112 | } // namespace WebCore
|
---|