Home | History | Annotate | Download | only in rendering
      1 /*
      2  * This file is part of the theme implementation for form controls in WebCore.
      3  *
      4  * Copyright (C) 2005, 2006, 2007, 2008 Apple Computer, Inc.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  *
     21  */
     22 
     23 #ifndef RenderTheme_h
     24 #define RenderTheme_h
     25 
     26 #if USE(NEW_THEME)
     27 #include "Theme.h"
     28 #else
     29 #include "ThemeTypes.h"
     30 #endif
     31 #include "RenderObject.h"
     32 #include "RenderTheme.h"
     33 #include "ScrollTypes.h"
     34 #include <wtf/PassRefPtr.h>
     35 #include <wtf/RefCounted.h>
     36 
     37 namespace WebCore {
     38 
     39 class Element;
     40 class PopupMenu;
     41 class RenderMenuList;
     42 class CSSStyleSheet;
     43 
     44 class RenderTheme : public RefCounted<RenderTheme> {
     45 protected:
     46     RenderTheme();
     47 
     48 public:
     49     virtual ~RenderTheme() { }
     50 
     51     // This function is to be implemented in your platform-specific theme implementation to hand back the
     52     // appropriate platform theme. When the theme is needed in non-page dependent code, a default theme is
     53     // used as fallback, which is returned for a nulled page, so the platform code needs to account for this.
     54     static PassRefPtr<RenderTheme> themeForPage(Page* page);
     55 
     56     // When the theme is needed in non-page dependent code, the defaultTheme() is used as fallback.
     57     static inline PassRefPtr<RenderTheme> defaultTheme()
     58     {
     59         return themeForPage(0);
     60     };
     61 
     62     // This method is called whenever style has been computed for an element and the appearance
     63     // property has been set to a value other than "none".  The theme should map in all of the appropriate
     64     // metrics and defaults given the contents of the style.  This includes sophisticated operations like
     65     // selection of control size based off the font, the disabling of appearance when certain other properties like
     66     // "border" are set, or if the appearance is not supported by the theme.
     67     void adjustStyle(CSSStyleSelector*, RenderStyle*, Element*,  bool UAHasAppearance,
     68                      const BorderData&, const FillLayer&, const Color& backgroundColor);
     69 
     70     // This method is called to paint the widget as a background of the RenderObject.  A widget's foreground, e.g., the
     71     // text of a button, is always rendered by the engine itself.  The boolean return value indicates
     72     // whether the CSS border/background should also be painted.
     73     bool paint(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
     74     bool paintBorderOnly(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
     75     bool paintDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
     76 
     77     // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
     78     // RenderThemeMac.cpp for Mac OS X.
     79 
     80     // These methods return the theme's extra style sheets rules, to let each platform
     81     // adjust the default CSS rules in html.css, quirks.css, or mediaControls.css
     82     virtual String extraDefaultStyleSheet() { return String(); }
     83     virtual String extraQuirksStyleSheet() { return String(); }
     84 #if ENABLE(VIDEO)
     85     virtual String extraMediaControlsStyleSheet() { return String(); };
     86 #endif
     87 
     88     // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
     89     // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
     90     // controls that need to do this.
     91     virtual int baselinePosition(const RenderObject*) const;
     92 
     93     // A method for asking if a control is a container or not.  Leaf controls have to have some special behavior (like
     94     // the baseline position API above).
     95     bool isControlContainer(ControlPart) const;
     96 
     97     // A method asking if the control changes its tint when the window has focus or not.
     98     virtual bool controlSupportsTints(const RenderObject*) const { return false; }
     99 
    100     // Whether or not the control has been styled enough by the author to disable the native appearance.
    101     virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
    102 
    103     // A general method asking if any control tinting is supported at all.
    104     virtual bool supportsControlTints() const { return false; }
    105 
    106     // Some controls may spill out of their containers (e.g., the check on an OS X checkbox).  When these controls repaint,
    107     // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
    108     virtual void adjustRepaintRect(const RenderObject*, IntRect&);
    109 
    110     // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
    111     // or a control becomes disabled.
    112     virtual bool stateChanged(RenderObject*, ControlState) const;
    113 
    114     // This method is called whenever the theme changes on the system in order to flush cached resources from the
    115     // old theme.
    116     virtual void themeChanged() { }
    117 
    118     // A method asking if the theme is able to draw the focus ring.
    119     virtual bool supportsFocusRing(const RenderStyle*) const;
    120 
    121     // A method asking if the theme's controls actually care about redrawing when hovered.
    122     virtual bool supportsHover(const RenderStyle*) const { return false; }
    123 
    124     // Text selection colors.
    125     Color activeSelectionBackgroundColor() const;
    126     Color inactiveSelectionBackgroundColor() const;
    127     Color activeSelectionForegroundColor() const;
    128     Color inactiveSelectionForegroundColor() const;
    129 
    130     // List box selection colors
    131     Color activeListBoxSelectionBackgroundColor() const;
    132     Color activeListBoxSelectionForegroundColor() const;
    133     Color inactiveListBoxSelectionBackgroundColor() const;
    134     Color inactiveListBoxSelectionForegroundColor() const;
    135 
    136     // Highlighting colors for TextMatches.
    137     virtual Color platformActiveTextSearchHighlightColor() const;
    138     virtual Color platformInactiveTextSearchHighlightColor() const;
    139 
    140     static Color focusRingColor();
    141     virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
    142     static void setCustomFocusRingColor(const Color&);
    143 
    144     virtual void platformColorsDidChange();
    145 
    146     virtual double caretBlinkInterval() const { return 0.5; }
    147 
    148     // System fonts and colors for CSS.
    149     virtual void systemFont(int cssValueId, FontDescription&) const = 0;
    150     virtual Color systemColor(int cssValueId) const;
    151 
    152     virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
    153 
    154     virtual void adjustSliderThumbSize(RenderObject*) const;
    155 
    156     virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
    157     virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
    158     virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
    159     virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
    160     virtual bool popupOptionSupportsTextIndent() const { return false; }
    161 
    162     virtual int buttonInternalPaddingLeft() const { return 0; }
    163     virtual int buttonInternalPaddingRight() const { return 0; }
    164     virtual int buttonInternalPaddingTop() const { return 0; }
    165     virtual int buttonInternalPaddingBottom() const { return 0; }
    166 
    167     virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
    168 
    169     // Method for painting the caps lock indicator
    170     virtual bool paintCapsLockIndicator(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return 0; };
    171 
    172 #if ENABLE(VIDEO)
    173     // Media controls
    174     virtual bool hitTestMediaControlPart(RenderObject*, const IntPoint& absPoint);
    175     virtual bool shouldRenderMediaControlPart(ControlPart, Element*);
    176     virtual double mediaControlsFadeInDuration() { return 0.1; }
    177     virtual double mediaControlsFadeOutDuration() { return 0.3; }
    178     virtual String formatMediaControlsTime(float time) const;
    179     virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
    180     virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
    181 #endif
    182 
    183 protected:
    184     // The platform selection color.
    185     virtual Color platformActiveSelectionBackgroundColor() const;
    186     virtual Color platformInactiveSelectionBackgroundColor() const;
    187     virtual Color platformActiveSelectionForegroundColor() const;
    188     virtual Color platformInactiveSelectionForegroundColor() const;
    189 
    190     virtual Color platformActiveListBoxSelectionBackgroundColor() const;
    191     virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
    192     virtual Color platformActiveListBoxSelectionForegroundColor() const;
    193     virtual Color platformInactiveListBoxSelectionForegroundColor() const;
    194 
    195     virtual bool supportsSelectionForegroundColors() const { return true; }
    196     virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
    197 
    198 #if !USE(NEW_THEME)
    199     // Methods for each appearance value.
    200     virtual void adjustCheckboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    201     virtual bool paintCheckbox(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    202     virtual void setCheckboxSize(RenderStyle*) const { }
    203 
    204     virtual void adjustRadioStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    205     virtual bool paintRadio(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    206     virtual void setRadioSize(RenderStyle*) const { }
    207 
    208     virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    209     virtual bool paintButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    210     virtual void setButtonSize(RenderStyle*) const { }
    211 
    212     virtual void adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    213     virtual bool paintInnerSpinButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    214     virtual void adjustOuterSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    215     virtual bool paintOuterSpinButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    216 #endif
    217 
    218     virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    219     virtual bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    220 
    221     virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    222     virtual bool paintTextArea(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    223 
    224 #ifdef ANDROID_LISTBOX_USES_MENU_LIST
    225     virtual void adjustListboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const {}
    226 #endif
    227     virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    228     virtual bool paintMenuList(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    229 
    230     virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    231     virtual bool paintMenuListButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    232 
    233     virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    234     virtual bool paintSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    235 
    236     virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    237     virtual bool paintSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    238 
    239     virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    240     virtual bool paintSearchField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    241 
    242     virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    243     virtual bool paintSearchFieldCancelButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    244 
    245     virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    246     virtual bool paintSearchFieldDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    247 
    248     virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    249     virtual bool paintSearchFieldResultsDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    250 
    251     virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    252     virtual bool paintSearchFieldResultsButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    253 
    254     virtual bool paintMediaFullscreenButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    255     virtual bool paintMediaPlayButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    256     virtual bool paintMediaMuteButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    257     virtual bool paintMediaSeekBackButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    258     virtual bool paintMediaSeekForwardButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    259     virtual bool paintMediaSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    260     virtual bool paintMediaSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    261     virtual bool paintMediaVolumeSliderContainer(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    262     virtual bool paintMediaVolumeSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    263     virtual bool paintMediaVolumeSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    264     virtual bool paintMediaRewindButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    265     virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    266     virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    267     virtual bool paintMediaControlsBackground(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    268     virtual bool paintMediaCurrentTime(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    269     virtual bool paintMediaTimeRemaining(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
    270 
    271 public:
    272     // Methods for state querying
    273     ControlStates controlStatesForRenderer(const RenderObject* o) const;
    274     bool isActive(const RenderObject*) const;
    275     bool isChecked(const RenderObject*) const;
    276     bool isIndeterminate(const RenderObject*) const;
    277     bool isEnabled(const RenderObject*) const;
    278     bool isFocused(const RenderObject*) const;
    279     bool isPressed(const RenderObject*) const;
    280     bool isHovered(const RenderObject*) const;
    281     bool isReadOnlyControl(const RenderObject*) const;
    282     bool isDefault(const RenderObject*) const;
    283 
    284 private:
    285     mutable Color m_activeSelectionBackgroundColor;
    286     mutable Color m_inactiveSelectionBackgroundColor;
    287     mutable Color m_activeSelectionForegroundColor;
    288     mutable Color m_inactiveSelectionForegroundColor;
    289 
    290     mutable Color m_activeListBoxSelectionBackgroundColor;
    291     mutable Color m_inactiveListBoxSelectionBackgroundColor;
    292     mutable Color m_activeListBoxSelectionForegroundColor;
    293     mutable Color m_inactiveListBoxSelectionForegroundColor;
    294 
    295 #if USE(NEW_THEME)
    296     Theme* m_theme; // The platform-specific theme.
    297 #endif
    298 };
    299 
    300 } // namespace WebCore
    301 
    302 #endif // RenderTheme_h
    303