2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #include "platform/LengthBox.h"
30 #include "platform/LengthSize.h"
31 #include "platform/PlatformExport.h"
32 #include "platform/ThemeTypes.h"
33 #include "platform/fonts/FontDescription.h"
34 #include "platform/geometry/IntRect.h"
35 #include "platform/graphics/Color.h"
36 #include "wtf/Forward.h"
40 class GraphicsContext
;
43 // Unlike other platform classes, Theme does extensively use virtual functions. This design allows a platform to switch between multiple themes at runtime.
44 class PLATFORM_EXPORT Theme
{
49 // A method to obtain the baseline position adjustment for a "leaf" control. This will only be used if a baseline
50 // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
51 // controls that need to do this. The adjustment is an offset that adds to the baseline, e.g., marginTop() + height() + |offset|.
52 // The offset is not zoomed.
53 virtual int baselinePositionAdjustment(ControlPart
) const { return 0; }
55 // A method asking if the control changes its appearance when the window is inactive.
56 virtual bool controlHasInactiveAppearance(ControlPart
) const { return false; }
58 // General methods for whether or not any of the controls in the theme change appearance when the window is inactive or
60 virtual bool controlsCanHaveInactiveAppearance() const { return false; }
61 virtual bool controlsCanHaveHoveredAppearance() const { return false; }
63 // Used by LayoutTheme::isControlStyled to figure out if the native look and feel should be turned off.
64 virtual bool controlDrawsBorder(ControlPart
) const { return true; }
65 virtual bool controlDrawsBackground(ControlPart
) const { return true; }
66 virtual bool controlDrawsFocusOutline(ControlPart
) const { return true; }
68 // Methods for obtaining platform-specific colors.
69 virtual Color
selectionColor(ControlPart
, ControlState
, SelectionPart
) const { return Color(); }
70 virtual Color
textSearchHighlightColor() const { return Color(); }
72 // CSS system colors and fonts
73 virtual Color
systemColor(ThemeColor
) const { return Color(); }
75 // How fast the caret blinks in text fields.
76 virtual double caretBlinkInterval() const { return 0.5; }
78 // Methods used to adjust the ComputedStyles of controls.
80 // The font description result should have a zoomed font size.
81 virtual FontDescription
controlFont(ControlPart
, const FontDescription
& fontDescription
, float /*zoomFactor*/) const { return fontDescription
; }
83 // The size here is in zoomed coordinates already. If a new size is returned, it also needs to be in zoomed coordinates.
84 virtual LengthSize
controlSize(ControlPart
, const FontDescription
&, const LengthSize
& zoomedSize
, float /*zoomFactor*/) const { return zoomedSize
; }
86 // Returns the minimum size for a control in zoomed coordinates.
87 virtual LengthSize
minimumControlSize(ControlPart
, const FontDescription
&, float /*zoomFactor*/) const { return LengthSize(Length(0, Fixed
), Length(0, Fixed
)); }
89 // Allows the theme to modify the existing padding/border.
90 virtual LengthBox
controlPadding(ControlPart
, const FontDescription
&, const LengthBox
& zoomedBox
, float zoomFactor
) const;
91 virtual LengthBox
controlBorder(ControlPart
, const FontDescription
&, const LengthBox
& zoomedBox
, float zoomFactor
) const;
93 // Whether or not whitespace: pre should be forced on always.
94 virtual bool controlRequiresPreWhiteSpace(ControlPart
) const { return false; }
96 // Method for painting a control. The rect is in zoomed coordinates.
97 virtual void paint(ControlPart
, ControlStates
, GraphicsContext
*, const IntRect
& /*zoomedRect*/, float /*zoomFactor*/, ScrollableArea
*) const { }
99 // Add visual overflow (e.g., the check on an OS X checkbox). The rect passed in is in zoomed coordinates so
100 // the inflation should take that into account and make sure the inflation amount is also scaled by the zoomFactor.
101 virtual void addVisualOverflow(ControlPart
, ControlStates
, float zoomFactor
, IntRect
& borderBox
) const { }
104 mutable Color m_activeSelectionColor
;
105 mutable Color m_inactiveSelectionColor
;
108 PLATFORM_EXPORT Theme
* platformTheme();