1/*
2 * Copyright (C) 2008-2017 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#pragma once
27
28#include "ThemeTypes.h"
29#include <wtf/Forward.h>
30
31namespace WebCore {
32
33class ControlStates;
34class FloatRect;
35class FontCascade;
36class FontCascadeDescription;
37class GraphicsContext;
38class LengthBox;
39class ScrollView;
40
41struct LengthSize;
42
43class Theme {
44public:
45 static Theme& singleton();
46
47 // A function to obtain the baseline position adjustment for a "leaf" control. This will be used if a baseline
48 // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
49 // controls that need to do this. The adjustment is an offset that adds to the baseline, e.g., marginTop() + height() + |offset|.
50 // The offset is not zoomed.
51 virtual int baselinePositionAdjustment(ControlPart) const;
52
53 // The font description result should have a zoomed font size.
54 virtual Optional<FontCascadeDescription> controlFont(ControlPart, const FontCascade&, float zoomFactor) const;
55
56 // The size here is in zoomed coordinates already. If a new size is returned, it also needs to be in zoomed coordinates.
57 virtual LengthSize controlSize(ControlPart, const FontCascade&, const LengthSize& zoomedSize, float zoomFactor) const;
58
59 // Returns the minimum size for a control in zoomed coordinates.
60 virtual LengthSize minimumControlSize(ControlPart, const FontCascade&, float zoomFactor) const;
61
62 // Allows the theme to modify the existing padding/border.
63 virtual LengthBox controlPadding(ControlPart, const FontCascade&, const LengthBox& zoomedBox, float zoomFactor) const;
64 virtual LengthBox controlBorder(ControlPart, const FontCascade&, const LengthBox& zoomedBox, float zoomFactor) const;
65
66 // Whether or not whitespace: pre should be forced on always.
67 virtual bool controlRequiresPreWhiteSpace(ControlPart) const;
68
69 // Method for painting a control. The rect is in zoomed coordinates.
70 virtual void paint(ControlPart, ControlStates&, GraphicsContext&, const FloatRect& zoomedRect, float zoomFactor, ScrollView*, float deviceScaleFactor, float pageScaleFactor, bool useSystemAppearance, bool useDarkAppearance);
71
72 // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint,
73 // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
74 // The rect passed in is in zoomed coordinates, so the inflation should take that into account and make sure the inflation
75 // amount is also scaled by the zoomFactor.
76 virtual void inflateControlPaintRect(ControlPart, const ControlStates&, FloatRect& zoomedRect, float zoomFactor) const;
77
78 virtual void drawNamedImage(const String&, GraphicsContext&, const FloatRect&) const;
79
80 virtual bool userPrefersReducedMotion() const;
81
82protected:
83 Theme() = default;
84 virtual ~Theme() = default;
85
86private:
87 Theme(const Theme&) = delete;
88 void operator=(const Theme&) = delete;
89};
90
91} // namespace WebCore
92