1/*
2 * Copyright (C) 2014-2018 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 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef ControlStates_h
27#define ControlStates_h
28
29#include <wtf/RetainPtr.h>
30#include <wtf/Seconds.h>
31
32#if PLATFORM(COCOA)
33#ifndef __OBJC__
34typedef struct objc_object *id;
35#endif
36#endif
37
38namespace WebCore {
39
40#if PLATFORM(COCOA)
41typedef id PlatformControlInstance;
42#endif
43
44class ControlStates {
45 WTF_MAKE_FAST_ALLOCATED;
46public:
47 enum {
48 HoverState = 1,
49 PressedState = 1 << 1,
50 FocusState = 1 << 2,
51 EnabledState = 1 << 3,
52 CheckedState = 1 << 4,
53 DefaultState = 1 << 5,
54 WindowInactiveState = 1 << 6,
55 IndeterminateState = 1 << 7,
56 SpinUpState = 1 << 8, // Sub-state for HoverState and PressedState.
57 PresentingState = 1 << 9,
58 AllStates = 0xffffffff
59 };
60
61 typedef unsigned States;
62
63 ControlStates(States states)
64 : m_states(states)
65 {
66 }
67
68 ControlStates()
69 : ControlStates(0)
70 {
71 }
72
73 States states() const { return m_states; }
74 void setStates(States newStates)
75 {
76 if (newStates == m_states)
77 return;
78 m_states = newStates;
79 m_isDirty = m_initialized;
80 m_initialized = true;
81 }
82
83 bool needsRepaint() const { return m_needsRepaint; }
84 void setNeedsRepaint(bool r) { m_needsRepaint = r; }
85
86 bool isDirty() const { return m_isDirty; }
87 void setDirty(bool d) { m_isDirty = d; }
88
89 Seconds timeSinceControlWasFocused() const { return m_timeSinceControlWasFocused; }
90 void setTimeSinceControlWasFocused(Seconds time) { m_timeSinceControlWasFocused = time; }
91
92#if PLATFORM(COCOA)
93 PlatformControlInstance platformControl() const { return m_controlInstance.get(); }
94 void setPlatformControl(PlatformControlInstance instance) { m_controlInstance = instance; }
95#endif
96
97private:
98 States m_states;
99 bool m_initialized { false };
100 bool m_needsRepaint { false };
101 bool m_isDirty { false };
102 Seconds m_timeSinceControlWasFocused { 0_s };
103#if PLATFORM(COCOA)
104 RetainPtr<PlatformControlInstance> m_controlInstance;
105#endif
106};
107
108}
109
110#endif
111