1 | /* |
2 | * Copyright (C) 2016 Igalia S.L. |
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 | #pragma once |
27 | |
28 | #include <gtk/gtk.h> |
29 | |
30 | #if GTK_CHECK_VERSION(3, 20, 0) |
31 | |
32 | #include "Color.h" |
33 | #include "IntSize.h" |
34 | #include <wtf/OptionSet.h> |
35 | #include <wtf/Vector.h> |
36 | #include <wtf/glib/GRefPtr.h> |
37 | #include <wtf/text/CString.h> |
38 | |
39 | namespace WebCore { |
40 | class FloatRect; |
41 | |
42 | class RenderThemeGadget { |
43 | WTF_MAKE_FAST_ALLOCATED; |
44 | WTF_MAKE_NONCOPYABLE(RenderThemeGadget); |
45 | public: |
46 | enum class Type { |
47 | Generic, |
48 | TextField, |
49 | Check, |
50 | Radio, |
51 | Arrow, |
52 | Icon, |
53 | Scrollbar, |
54 | Button |
55 | }; |
56 | |
57 | struct Info { |
58 | Type type; |
59 | const char* name; |
60 | Vector<const char*> classList; |
61 | }; |
62 | |
63 | static std::unique_ptr<RenderThemeGadget> create(const Info&, RenderThemeGadget* parent = nullptr, const Vector<RenderThemeGadget::Info> siblings = Vector<RenderThemeGadget::Info>(), unsigned position = 0); |
64 | RenderThemeGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position); |
65 | virtual ~RenderThemeGadget(); |
66 | |
67 | virtual IntSize preferredSize() const; |
68 | virtual bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr); |
69 | virtual IntSize minimumSize() const; |
70 | |
71 | void renderFocus(cairo_t*, const FloatRect&); |
72 | |
73 | GtkBorder contentsBox() const; |
74 | Color color() const; |
75 | Color backgroundColor() const; |
76 | double opacity() const; |
77 | |
78 | GtkStyleContext* context() const { return m_context.get(); } |
79 | |
80 | GtkStateFlags state() const; |
81 | void setState(GtkStateFlags); |
82 | |
83 | protected: |
84 | GtkBorder marginBox() const; |
85 | GtkBorder borderBox() const; |
86 | GtkBorder paddingBox() const; |
87 | |
88 | GRefPtr<GtkStyleContext> m_context; |
89 | }; |
90 | |
91 | class RenderThemeBoxGadget final : public RenderThemeGadget { |
92 | public: |
93 | RenderThemeBoxGadget(const RenderThemeGadget::Info&, GtkOrientation, const Vector<RenderThemeGadget::Info> children, RenderThemeGadget* parent = nullptr); |
94 | |
95 | IntSize preferredSize() const override; |
96 | |
97 | RenderThemeGadget* child(unsigned index) const { return m_children[index].get(); } |
98 | |
99 | private: |
100 | Vector<std::unique_ptr<RenderThemeGadget>> m_children; |
101 | GtkOrientation m_orientation { GTK_ORIENTATION_HORIZONTAL }; |
102 | }; |
103 | |
104 | class RenderThemeTextFieldGadget final : public RenderThemeGadget { |
105 | public: |
106 | RenderThemeTextFieldGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position); |
107 | |
108 | IntSize minimumSize() const override; |
109 | }; |
110 | |
111 | class RenderThemeToggleGadget final : public RenderThemeGadget { |
112 | public: |
113 | RenderThemeToggleGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position); |
114 | |
115 | bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr) override; |
116 | |
117 | private: |
118 | RenderThemeGadget::Type m_type; |
119 | }; |
120 | |
121 | class RenderThemeArrowGadget final : public RenderThemeGadget { |
122 | public: |
123 | RenderThemeArrowGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position); |
124 | |
125 | bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr) override; |
126 | }; |
127 | |
128 | class RenderThemeIconGadget final : public RenderThemeGadget { |
129 | public: |
130 | RenderThemeIconGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position); |
131 | |
132 | bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr) override; |
133 | IntSize minimumSize() const override; |
134 | |
135 | void setIconName(const char* iconName) { m_iconName = iconName; } |
136 | void setIconSize(unsigned iconSize) { m_iconSize = iconSize; } |
137 | |
138 | // Defined in GTK+ (gtk/gtkiconfactory.c). |
139 | enum IconSizeGtk { |
140 | = 16, |
141 | SmallToolbar = 18, |
142 | Button = 20, |
143 | LargeToolbar = 24, |
144 | DragAndDrop = 32, |
145 | Dialog = 48 |
146 | }; |
147 | |
148 | private: |
149 | GtkIconSize gtkIconSizeForPixelSize(unsigned) const; |
150 | |
151 | CString m_iconName; |
152 | unsigned m_iconSize { 0 }; |
153 | }; |
154 | |
155 | class RenderThemeScrollbarGadget final : public RenderThemeGadget { |
156 | public: |
157 | RenderThemeScrollbarGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position); |
158 | |
159 | enum class Steppers { |
160 | Backward = 1 << 0, |
161 | Forward = 1 << 1, |
162 | SecondaryBackward = 1 << 2, |
163 | SecondaryForward = 1 << 3 |
164 | }; |
165 | OptionSet<Steppers> steppers() const { return m_steppers; }; |
166 | |
167 | void renderStepper(cairo_t*, const FloatRect&, RenderThemeGadget*, GtkOrientation, Steppers); |
168 | |
169 | private: |
170 | OptionSet<Steppers> m_steppers; |
171 | }; |
172 | |
173 | class RenderThemeButtonGadget final : public RenderThemeGadget { |
174 | public: |
175 | RenderThemeButtonGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position); |
176 | |
177 | IntSize minimumSize() const override; |
178 | }; |
179 | |
180 | } // namespace WebCore |
181 | |
182 | #endif // GTK_CHECK_VERSION(3, 20, 0) |
183 | |