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, 2009, 2010 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 "ScrollTypes.h"
     33 #include <wtf/PassRefPtr.h>
     34 #include <wtf/RefCounted.h>
     35 
     36 namespace WebCore {
     37 
     38 class Element;
     39 class PopupMenu;
     40 class RenderMenuList;
     41 #if ENABLE(METER_TAG)
     42 class RenderMeter;
     43 #endif
     44 #if ENABLE(PROGRESS_TAG)
     45 class RenderProgress;
     46 #endif
     47 class CSSStyleSheet;
     48 
     49 class RenderTheme : public RefCounted<RenderTheme> {
     50 protected:
     51     RenderTheme();
     52 
     53 public:
     54     virtual ~RenderTheme() { }
     55 
     56     // This function is to be implemented in your platform-specific theme implementation to hand back the
     57     // appropriate platform theme. When the theme is needed in non-page dependent code, a default theme is
     58     // used as fallback, which is returned for a nulled page, so the platform code needs to account for this.
     59     static PassRefPtr<RenderTheme> themeForPage(Page* page);
     60 
     61     // When the theme is needed in non-page dependent code, the defaultTheme() is used as fallback.
     62     static inline PassRefPtr<RenderTheme> defaultTheme()
     63     {
     64         return themeForPage(0);
     65     };
     66 
     67     // This method is called whenever style has been computed for an element and the appearance
     68     // property has been set to a value other than "none".  The theme should map in all of the appropriate
     69     // metrics and defaults given the contents of the style.  This includes sophisticated operations like
     70     // selection of control size based off the font, the disabling of appearance when certain other properties like
     71     // "border" are set, or if the appearance is not supported by the theme.
     72     void adjustStyle(CSSStyleSelector*, RenderStyle*, Element*,  bool UAHasAppearance,
     73                      const BorderData&, const FillLayer&, const Color& backgroundColor);
     74 
     75     // This method is called to paint the widget as a background of the RenderObject.  A widget's foreground, e.g., the
     76     // text of a button, is always rendered by the engine itself.  The boolean return value indicates
     77     // whether the CSS border/background should also be painted.
     78     bool paint(RenderObject*, const PaintInfo&, const IntRect&);
     79     bool paintBorderOnly(RenderObject*, const PaintInfo&, const IntRect&);
     80     bool paintDecorations(RenderObject*, const PaintInfo&, const IntRect&);
     81 
     82     // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
     83     // RenderThemeMac.cpp for Mac OS X.
     84 
     85     // These methods return the theme's extra style sheets rules, to let each platform
     86     // adjust the default CSS rules in html.css, quirks.css, or mediaControls.css
     87     virtual String extraDefaultStyleSheet() { return String(); }
     88     virtual String extraQuirksStyleSheet() { return String(); }
     89 #if ENABLE(VIDEO)
     90     virtual String extraMediaControlsStyleSheet() { return String(); };
     91 #if ENABLE(FULLSCREEN_API)
     92     virtual String extraFullScreenStyleSheet() { return String(); };
     93 #endif
     94 #endif
     95 
     96     // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
     97     // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
     98     // controls that need to do this.
     99     virtual int baselinePosition(const RenderObject*) const;
    100 
    101     // A method for asking if a control is a container or not.  Leaf controls have to have some special behavior (like
    102     // the baseline position API above).
    103     bool isControlContainer(ControlPart) const;
    104 
    105     // A method asking if the control changes its tint when the window has focus or not.
    106     virtual bool controlSupportsTints(const RenderObject*) const { return false; }
    107 
    108     // Whether or not the control has been styled enough by the author to disable the native appearance.
    109     virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
    110 
    111     // A general method asking if any control tinting is supported at all.
    112     virtual bool supportsControlTints() const { return false; }
    113 
    114     // Some controls may spill out of their containers (e.g., the check on an OS X checkbox).  When these controls repaint,
    115     // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
    116     virtual void adjustRepaintRect(const RenderObject*, IntRect&);
    117 
    118     // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
    119     // or a control becomes disabled.
    120     virtual bool stateChanged(RenderObject*, ControlState) const;
    121 
    122     // This method is called whenever the theme changes on the system in order to flush cached resources from the
    123     // old theme.
    124     virtual void themeChanged() { }
    125 
    126     // A method asking if the theme is able to draw the focus ring.
    127     virtual bool supportsFocusRing(const RenderStyle*) const;
    128 
    129     // A method asking if the theme's controls actually care about redrawing when hovered.
    130     virtual bool supportsHover(const RenderStyle*) const { return false; }
    131 
    132     // Text selection colors.
    133     Color activeSelectionBackgroundColor() const;
    134     Color inactiveSelectionBackgroundColor() const;
    135     Color activeSelectionForegroundColor() const;
    136     Color inactiveSelectionForegroundColor() const;
    137 
    138     // List box selection colors
    139     Color activeListBoxSelectionBackgroundColor() const;
    140     Color activeListBoxSelectionForegroundColor() const;
    141     Color inactiveListBoxSelectionBackgroundColor() const;
    142     Color inactiveListBoxSelectionForegroundColor() const;
    143 
    144     // Highlighting colors for TextMatches.
    145     virtual Color platformActiveTextSearchHighlightColor() const;
    146     virtual Color platformInactiveTextSearchHighlightColor() const;
    147 
    148     static Color focusRingColor();
    149     virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
    150     static void setCustomFocusRingColor(const Color&);
    151 
    152     virtual void platformColorsDidChange();
    153 
    154     virtual double caretBlinkInterval() const { return 0.5; }
    155 
    156     // System fonts and colors for CSS.
    157     virtual void systemFont(int cssValueId, FontDescription&) const = 0;
    158     virtual Color systemColor(int cssValueId) const;
    159 
    160     virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
    161 
    162     virtual void adjustSliderThumbSize(RenderObject*) const;
    163 
    164     virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
    165     virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
    166     virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
    167     virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
    168     virtual bool popupOptionSupportsTextIndent() const { return false; }
    169 
    170     virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
    171 
    172     // Method for painting the caps lock indicator
    173     virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) { return 0; };
    174 
    175 #if ENABLE(PROGRESS_TAG)
    176     // Returns the repeat interval of the animation for the progress bar.
    177     virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
    178     // Returns the duration of the animation for the progress bar.
    179     virtual double animationDurationForProgressBar(RenderProgress*) const;
    180 #endif
    181 
    182 #if ENABLE(VIDEO)
    183     // Media controls
    184     virtual bool supportsClosedCaptioning() const { return false; }
    185     virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return false; }
    186     virtual bool usesMediaControlStatusDisplay() { return false; }
    187     virtual bool usesMediaControlVolumeSlider() const { return true; }
    188     virtual double mediaControlsFadeInDuration() { return 0.1; }
    189     virtual double mediaControlsFadeOutDuration() { return 0.3; }
    190     virtual String formatMediaControlsTime(float time) const;
    191     virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
    192     virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
    193 
    194     // Returns the media volume slider container's offset from the mute button.
    195     virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const;
    196 #endif
    197 
    198 #if ENABLE(METER_TAG)
    199     virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const;
    200     virtual bool supportsMeter(ControlPart) const;
    201 #endif
    202 
    203     virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
    204 
    205 protected:
    206     // The platform selection color.
    207     virtual Color platformActiveSelectionBackgroundColor() const;
    208     virtual Color platformInactiveSelectionBackgroundColor() const;
    209     virtual Color platformActiveSelectionForegroundColor() const;
    210     virtual Color platformInactiveSelectionForegroundColor() const;
    211 
    212     virtual Color platformActiveListBoxSelectionBackgroundColor() const;
    213     virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
    214     virtual Color platformActiveListBoxSelectionForegroundColor() const;
    215     virtual Color platformInactiveListBoxSelectionForegroundColor() const;
    216 
    217     virtual bool supportsSelectionForegroundColors() const { return true; }
    218     virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
    219 
    220 #if !USE(NEW_THEME)
    221     // Methods for each appearance value.
    222     virtual void adjustCheckboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    223     virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    224     virtual void setCheckboxSize(RenderStyle*) const { }
    225 
    226     virtual void adjustRadioStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    227     virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    228     virtual void setRadioSize(RenderStyle*) const { }
    229 
    230     virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    231     virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    232     virtual void setButtonSize(RenderStyle*) const { }
    233 
    234     virtual void adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    235     virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    236     virtual void adjustOuterSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    237     virtual bool paintOuterSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    238 #endif
    239 
    240     virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    241     virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    242 
    243     virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    244     virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    245 
    246 #if ENABLE(NO_LISTBOX_RENDERING)
    247     virtual void adjustListboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const {}
    248 #endif
    249     virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    250     virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    251 
    252     virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    253     virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    254 
    255 #if ENABLE(METER_TAG)
    256     virtual void adjustMeterStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    257     virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
    258 #endif
    259 
    260 #if ENABLE(PROGRESS_TAG)
    261     virtual void adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    262     virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    263 #endif
    264 
    265 #if ENABLE(INPUT_SPEECH)
    266     virtual void adjustInputFieldSpeechButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    267     virtual bool paintInputFieldSpeechButton(RenderObject*, const PaintInfo&, const IntRect&);
    268 #endif
    269 
    270     virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    271     virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    272 
    273     virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    274     virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    275 
    276     virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    277     virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    278 
    279     virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    280     virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    281 
    282     virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    283     virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    284 
    285     virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    286     virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    287 
    288     virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
    289     virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    290 
    291     virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    292     virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    293     virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    294     virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    295     virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    296     virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    297     virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    298     virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    299     virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    300     virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    301     virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    302     virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    303     virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    304     virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    305     virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    306     virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
    307 
    308 public:
    309     // Methods for state querying
    310     ControlStates controlStatesForRenderer(const RenderObject* o) const;
    311     bool isActive(const RenderObject*) const;
    312     bool isChecked(const RenderObject*) const;
    313     bool isIndeterminate(const RenderObject*) const;
    314     bool isEnabled(const RenderObject*) const;
    315     bool isFocused(const RenderObject*) const;
    316     bool isPressed(const RenderObject*) const;
    317     bool isSpinUpButtonPartPressed(const RenderObject*) const;
    318     bool isHovered(const RenderObject*) const;
    319     bool isSpinUpButtonPartHovered(const RenderObject*) const;
    320     bool isReadOnlyControl(const RenderObject*) const;
    321     bool isDefault(const RenderObject*) const;
    322 
    323 private:
    324     mutable Color m_activeSelectionBackgroundColor;
    325     mutable Color m_inactiveSelectionBackgroundColor;
    326     mutable Color m_activeSelectionForegroundColor;
    327     mutable Color m_inactiveSelectionForegroundColor;
    328 
    329     mutable Color m_activeListBoxSelectionBackgroundColor;
    330     mutable Color m_inactiveListBoxSelectionBackgroundColor;
    331     mutable Color m_activeListBoxSelectionForegroundColor;
    332     mutable Color m_inactiveListBoxSelectionForegroundColor;
    333 
    334 #if USE(NEW_THEME)
    335     Theme* m_theme; // The platform-specific theme.
    336 #endif
    337 };
    338 
    339 } // namespace WebCore
    340 
    341 #endif // RenderTheme_h
    342