RenderThemeGadget.h [plain text]
#pragma once
#include <gtk/gtk.h>
#if GTK_CHECK_VERSION(3, 20, 0)
#include "Color.h"
#include "IntSize.h"
#include <wtf/OptionSet.h>
#include <wtf/Vector.h>
#include <wtf/glib/GRefPtr.h>
#include <wtf/text/CString.h>
namespace WebCore {
class FloatRect;
class RenderThemeGadget {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(RenderThemeGadget);
public:
enum class Type {
Generic,
TextField,
Check,
Radio,
Arrow,
Icon,
Scrollbar
};
struct Info {
Type type;
const char* name;
GtkStateFlags state;
Vector<const char*> classList;
};
static std::unique_ptr<RenderThemeGadget> create(const Info&, RenderThemeGadget* parent = nullptr, const Vector<RenderThemeGadget::Info> siblings = Vector<RenderThemeGadget::Info>(), unsigned position = 0);
RenderThemeGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position);
virtual ~RenderThemeGadget();
virtual IntSize preferredSize() const;
virtual bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr);
virtual IntSize minimumSize() const;
void renderFocus(cairo_t*, const FloatRect&);
GtkBorder contentsBox() const;
Color color() const;
Color backgroundColor() const;
double opacity() const;
GtkStyleContext* context() const { return m_context.get(); }
protected:
GtkBorder marginBox() const;
GtkBorder borderBox() const;
GtkBorder paddingBox() const;
GRefPtr<GtkStyleContext> m_context;
};
class RenderThemeBoxGadget final : public RenderThemeGadget {
public:
RenderThemeBoxGadget(const RenderThemeGadget::Info&, GtkOrientation, const Vector<RenderThemeGadget::Info> children, RenderThemeGadget* parent = nullptr);
IntSize preferredSize() const override;
RenderThemeGadget* child(unsigned index) const { return m_children[index].get(); }
private:
Vector<std::unique_ptr<RenderThemeGadget>> m_children;
GtkOrientation m_orientation { GTK_ORIENTATION_HORIZONTAL };
};
class RenderThemeTextFieldGadget final : public RenderThemeGadget {
public:
RenderThemeTextFieldGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position);
IntSize minimumSize() const override;
};
class RenderThemeToggleGadget final : public RenderThemeGadget {
public:
RenderThemeToggleGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position);
bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr) override;
private:
RenderThemeGadget::Type m_type;
};
class RenderThemeArrowGadget final : public RenderThemeGadget {
public:
RenderThemeArrowGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position);
bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr) override;
};
class RenderThemeIconGadget final : public RenderThemeGadget {
public:
RenderThemeIconGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position);
bool render(cairo_t*, const FloatRect&, FloatRect* = nullptr) override;
IntSize minimumSize() const override;
void setIconName(const char* iconName) { m_iconName = iconName; }
void setIconSize(unsigned iconSize) { m_iconSize = iconSize; }
enum IconSizeGtk {
Menu = 16,
SmallToolbar = 18,
Button = 20,
LargeToolbar = 24,
DragAndDrop = 32,
Dialog = 48
};
private:
GtkIconSize gtkIconSizeForPixelSize(unsigned) const;
CString m_iconName;
unsigned m_iconSize { 0 };
};
class RenderThemeScrollbarGadget final : public RenderThemeGadget {
public:
RenderThemeScrollbarGadget(const Info&, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position);
enum class Steppers {
Backward = 1 << 0,
Forward = 1 << 1,
SecondaryBackward = 1 << 2,
SecondaryForward = 1 << 3
};
OptionSet<Steppers> steppers() const { return m_steppers; };
void renderStepper(cairo_t*, const FloatRect&, RenderThemeGadget*, GtkOrientation, Steppers);
private:
OptionSet<Steppers> m_steppers;
};
}
#endif // GTK_CHECK_VERSION(3, 20, 0)