Home | History | Annotate | Download | only in platform
      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 "core/platform/LengthBox.h"
     30 #include "core/platform/LengthSize.h"
     31 #include "core/platform/ThemeTypes.h"
     32 #include "core/platform/graphics/Color.h"
     33 #include "core/platform/graphics/Font.h"
     34 #include "core/platform/graphics/IntRect.h"
     35 #include "wtf/Forward.h"
     36 
     37 namespace WebCore {
     38 
     39 class GraphicsContext;
     40 class ScrollView;
     41 
     42 // Unlike other platform classes, Theme does extensively use virtual functions.  This design allows a platform to switch between multiple themes at runtime.
     43 class Theme {
     44 public:
     45     Theme() { }
     46     virtual ~Theme() { }
     47 
     48     // A method to obtain the baseline position adjustment for a "leaf" control.  This will only be used if a baseline
     49     // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
     50     // controls that need to do this.  The adjustment is an offset that adds to the baseline, e.g., marginTop() + height() + |offset|.
     51     // The offset is not zoomed.
     52     virtual int baselinePositionAdjustment(ControlPart) const { return 0; }
     53 
     54     // A method asking if the control changes its appearance when the window is inactive.
     55     virtual bool controlHasInactiveAppearance(ControlPart) const { return false; }
     56 
     57     // General methods for whether or not any of the controls in the theme change appearance when the window is inactive or
     58     // when hovered over.
     59     virtual bool controlsCanHaveInactiveAppearance() const { return false; }
     60     virtual bool controlsCanHaveHoveredAppearance() const { return false; }
     61 
     62     // Used by RenderTheme::isControlStyled to figure out if the native look and feel should be turned off.
     63     virtual bool controlDrawsBorder(ControlPart) const { return true; }
     64     virtual bool controlDrawsBackground(ControlPart) const { return true; }
     65     virtual bool controlDrawsFocusOutline(ControlPart) const { return true; }
     66 
     67     // Methods for obtaining platform-specific colors.
     68     virtual Color selectionColor(ControlPart, ControlState, SelectionPart) const { return Color(); }
     69     virtual Color textSearchHighlightColor() const { return Color(); }
     70 
     71     // CSS system colors and fonts
     72     virtual Color systemColor(ThemeColor) const { return Color(); }
     73     virtual Font systemFont(ThemeFont, FontDescription&) const { return Font(); }
     74 
     75     // How fast the caret blinks in text fields.
     76     virtual double caretBlinkInterval() const { return 0.5; }
     77 
     78     // Notification when the theme has changed
     79     virtual void themeChanged() { }
     80 
     81     // Methods used to adjust the RenderStyles of controls.
     82 
     83     // The font description result should have a zoomed font size.
     84     virtual FontDescription controlFont(ControlPart, const Font& font, float /*zoomFactor*/) const { return font.fontDescription(); }
     85 
     86     // The size here is in zoomed coordinates already.  If a new size is returned, it also needs to be in zoomed coordinates.
     87     virtual LengthSize controlSize(ControlPart, const Font&, const LengthSize& zoomedSize, float /*zoomFactor*/) const { return zoomedSize; }
     88 
     89     // Returns the minimum size for a control in zoomed coordinates.
     90     virtual LengthSize minimumControlSize(ControlPart, const Font&, float /*zoomFactor*/) const { return LengthSize(Length(0, Fixed), Length(0, Fixed)); }
     91 
     92     // Allows the theme to modify the existing padding/border.
     93     virtual LengthBox controlPadding(ControlPart, const Font&, const LengthBox& zoomedBox, float zoomFactor) const;
     94     virtual LengthBox controlBorder(ControlPart, const Font&, const LengthBox& zoomedBox, float zoomFactor) const;
     95 
     96     // Whether or not whitespace: pre should be forced on always.
     97     virtual bool controlRequiresPreWhiteSpace(ControlPart) const { return false; }
     98 
     99     // Method for painting a control. The rect is in zoomed coordinates.
    100     virtual void paint(ControlPart, ControlStates, GraphicsContext*, const IntRect& /*zoomedRect*/, float /*zoomFactor*/, ScrollView*) const { }
    101 
    102     // Some controls may spill out of their containers (e.g., the check on an OS X checkbox).  When these controls repaint,
    103     // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
    104     // The rect passed in is in zoomed coordinates, so the inflation should take that into account and make sure the inflation
    105     // amount is also scaled by the zoomFactor.
    106     virtual void inflateControlPaintRect(ControlPart, ControlStates, IntRect& /*zoomedRect*/, float /*zoomFactor*/) const { }
    107 
    108     // This method is called once, from RenderTheme::adjustDefaultStyleSheet(), to let each platform adjust
    109     // the default CSS rules in html.css.
    110     static String defaultStyleSheet();
    111 
    112 private:
    113     mutable Color m_activeSelectionColor;
    114     mutable Color m_inactiveSelectionColor;
    115 };
    116 
    117 // Function to obtain the theme.  This is implemented in the platform-specific subclasses.
    118 Theme* platformTheme();
    119 
    120 } // namespace WebCore
    121 
    122 #endif // Theme_h
    123