1 /* 2 * Copyright (C) 2008 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 Theme_h 27 #define Theme_h 28 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" 37 38 namespace WebCore { 39 40 class GraphicsContext; 41 class ScrollView; 42 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 { 45 public: Theme()46 Theme() { } ~Theme()47 virtual ~Theme() { } 48 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. baselinePositionAdjustment(ControlPart)53 virtual int baselinePositionAdjustment(ControlPart) const { return 0; } 54 55 // A method asking if the control changes its appearance when the window is inactive. controlHasInactiveAppearance(ControlPart)56 virtual bool controlHasInactiveAppearance(ControlPart) const { return false; } 57 58 // General methods for whether or not any of the controls in the theme change appearance when the window is inactive or 59 // when hovered over. controlsCanHaveInactiveAppearance()60 virtual bool controlsCanHaveInactiveAppearance() const { return false; } controlsCanHaveHoveredAppearance()61 virtual bool controlsCanHaveHoveredAppearance() const { return false; } 62 63 // Used by RenderTheme::isControlStyled to figure out if the native look and feel should be turned off. controlDrawsBorder(ControlPart)64 virtual bool controlDrawsBorder(ControlPart) const { return true; } controlDrawsBackground(ControlPart)65 virtual bool controlDrawsBackground(ControlPart) const { return true; } controlDrawsFocusOutline(ControlPart)66 virtual bool controlDrawsFocusOutline(ControlPart) const { return true; } 67 68 // Methods for obtaining platform-specific colors. selectionColor(ControlPart,ControlState,SelectionPart)69 virtual Color selectionColor(ControlPart, ControlState, SelectionPart) const { return Color(); } textSearchHighlightColor()70 virtual Color textSearchHighlightColor() const { return Color(); } 71 72 // CSS system colors and fonts systemColor(ThemeColor)73 virtual Color systemColor(ThemeColor) const { return Color(); } 74 75 // How fast the caret blinks in text fields. caretBlinkInterval()76 virtual double caretBlinkInterval() const { return 0.5; } 77 78 // Methods used to adjust the RenderStyles of controls. 79 80 // The font description result should have a zoomed font size. controlFont(ControlPart,const FontDescription & fontDescription,float)81 virtual FontDescription controlFont(ControlPart, const FontDescription& fontDescription, float /*zoomFactor*/) const { return fontDescription; } 82 83 // The size here is in zoomed coordinates already. If a new size is returned, it also needs to be in zoomed coordinates. controlSize(ControlPart,const FontDescription &,const LengthSize & zoomedSize,float)84 virtual LengthSize controlSize(ControlPart, const FontDescription&, const LengthSize& zoomedSize, float /*zoomFactor*/) const { return zoomedSize; } 85 86 // Returns the minimum size for a control in zoomed coordinates. minimumControlSize(ControlPart,const FontDescription &,float)87 virtual LengthSize minimumControlSize(ControlPart, const FontDescription&, float /*zoomFactor*/) const { return LengthSize(Length(0, Fixed), Length(0, Fixed)); } 88 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; 92 93 // Whether or not whitespace: pre should be forced on always. controlRequiresPreWhiteSpace(ControlPart)94 virtual bool controlRequiresPreWhiteSpace(ControlPart) const { return false; } 95 96 // Method for painting a control. The rect is in zoomed coordinates. paint(ControlPart,ControlStates,GraphicsContext *,const IntRect &,float,ScrollView *)97 virtual void paint(ControlPart, ControlStates, GraphicsContext*, const IntRect& /*zoomedRect*/, float /*zoomFactor*/, ScrollView*) const { } 98 99 // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint, 100 // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control. 101 // The rect passed in is in zoomed coordinates, so the inflation should take that into account and make sure the inflation 102 // amount is also scaled by the zoomFactor. inflateControlPaintRect(ControlPart,ControlStates,IntRect &,float)103 virtual void inflateControlPaintRect(ControlPart, ControlStates, IntRect& /*zoomedRect*/, float /*zoomFactor*/) const { } 104 105 private: 106 mutable Color m_activeSelectionColor; 107 mutable Color m_inactiveSelectionColor; 108 }; 109 110 PLATFORM_EXPORT Theme* platformTheme(); 111 112 } // namespace WebCore 113 114 #endif // Theme_h 115