1/*
2 * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#pragma once
33
34#include "HTMLDivElement.h"
35#include "RenderBlockFlow.h"
36#include <wtf/Forward.h>
37
38namespace WebCore {
39
40class HTMLInputElement;
41class TouchEvent;
42
43class SliderThumbElement final : public HTMLDivElement {
44 WTF_MAKE_ISO_ALLOCATED(SliderThumbElement);
45public:
46 static Ref<SliderThumbElement> create(Document&);
47
48 void setPositionFromValue();
49 void dragFrom(const LayoutPoint&);
50 RefPtr<HTMLInputElement> hostInput() const;
51 void setPositionFromPoint(const LayoutPoint&);
52
53#if ENABLE(IOS_TOUCH_EVENTS)
54 void handleTouchEvent(TouchEvent&);
55#endif
56
57 void hostDisabledStateChanged();
58
59private:
60 SliderThumbElement(Document&);
61
62 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
63
64 Ref<Element> cloneElementWithoutAttributesAndChildren(Document&) final;
65 bool isDisabledFormControl() const final;
66 bool matchesReadWritePseudoClass() const final;
67 RefPtr<Element> focusDelegate() final;
68
69#if !PLATFORM(IOS_FAMILY)
70 void defaultEventHandler(Event&) final;
71 bool willRespondToMouseMoveEvents() final;
72 bool willRespondToMouseClickEvents() final;
73#endif
74
75#if ENABLE(IOS_TOUCH_EVENTS)
76 void didAttachRenderers() final;
77#endif
78 void willDetachRenderers() final;
79
80 Optional<ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final;
81 const AtomicString& shadowPseudoId() const final;
82
83 void startDragging();
84 void stopDragging();
85
86#if ENABLE(IOS_TOUCH_EVENTS)
87 unsigned exclusiveTouchIdentifier() const;
88 void setExclusiveTouchIdentifier(unsigned);
89 void clearExclusiveTouchIdentifier();
90
91 void handleTouchStart(TouchEvent&);
92 void handleTouchMove(TouchEvent&);
93 void handleTouchEndAndCancel(TouchEvent&);
94
95 bool shouldAcceptTouchEvents();
96 void registerForTouchEvents();
97 void unregisterForTouchEvents();
98#endif
99
100 AtomicString m_shadowPseudoId;
101 bool m_inDragMode { false };
102
103#if ENABLE(IOS_TOUCH_EVENTS)
104 // FIXME: Currently it is safe to use 0, but this may need to change
105 // if touch identifiers change in the future and can be 0.
106 static const unsigned NoIdentifier = 0;
107 unsigned m_exclusiveTouchIdentifier { NoIdentifier };
108 bool m_isRegisteredAsTouchEventListener { false };
109#endif
110};
111
112inline Ref<SliderThumbElement> SliderThumbElement::create(Document& document)
113{
114 return adoptRef(*new SliderThumbElement(document));
115}
116
117// --------------------------------
118
119class RenderSliderThumb final : public RenderBlockFlow {
120 WTF_MAKE_ISO_ALLOCATED(RenderSliderThumb);
121public:
122 RenderSliderThumb(SliderThumbElement&, RenderStyle&&);
123 void updateAppearance(const RenderStyle* parentStyle);
124
125private:
126 bool isSliderThumb() const final;
127};
128
129// --------------------------------
130
131class SliderContainerElement final : public HTMLDivElement {
132 WTF_MAKE_ISO_ALLOCATED(SliderContainerElement);
133public:
134 static Ref<SliderContainerElement> create(Document&);
135
136private:
137 SliderContainerElement(Document&);
138 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
139 Optional<ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final;
140 const AtomicString& shadowPseudoId() const final;
141 bool isSliderContainerElement() const final { return true; }
142
143 AtomicString m_shadowPseudoId;
144};
145
146} // namespace WebCore
147
148SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SliderContainerElement)
149 static bool isType(const WebCore::Element& element) { return element.isSliderContainerElement(); }
150 static bool isType(const WebCore::Node& node) { return is<WebCore::Element>(node) && isType(downcast<WebCore::Element>(node)); }
151SPECIALIZE_TYPE_TRAITS_END()
152