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, 2012 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 "platform/Theme.h" 28 #else 29 #include "platform/ThemeTypes.h" 30 #endif 31 #include "core/rendering/RenderObject.h" 32 #include "core/rendering/style/CachedUAStyle.h" 33 #include "platform/scroll/ScrollTypes.h" 34 #include "wtf/PassRefPtr.h" 35 #include "wtf/RefCounted.h" 36 #include "wtf/text/WTFString.h" 37 38 namespace WebCore { 39 40 class CSSStyleSheet; 41 class Element; 42 class FileList; 43 class HTMLInputElement; 44 class PopupMenu; 45 class RenderMenuList; 46 class RenderMeter; 47 class RenderProgress; 48 49 50 class RenderTheme : public RefCounted<RenderTheme> { 51 protected: 52 RenderTheme(); 53 54 public: 55 virtual ~RenderTheme() { } 56 57 // This function is to be implemented in your platform-specific theme implementation to hand back the 58 // appropriate platform theme. 59 static RenderTheme& theme(); 60 61 static void setSizeIfAuto(RenderStyle*, const IntSize&); 62 63 // This method is called whenever style has been computed for an element and the appearance 64 // property has been set to a value other than "none". The theme should map in all of the appropriate 65 // metrics and defaults given the contents of the style. This includes sophisticated operations like 66 // selection of control size based off the font, the disabling of appearance when certain other properties like 67 // "border" are set, or if the appearance is not supported by the theme. 68 void adjustStyle(RenderStyle*, Element*, const CachedUAStyle&); 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 PaintInfo&, const IntRect&); 74 bool paintBorderOnly(RenderObject*, const PaintInfo&, const IntRect&); 75 bool paintDecorations(RenderObject*, const 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(); 83 virtual String extraQuirksStyleSheet() { return String(); } 84 virtual String extraMediaControlsStyleSheet() { return String(); } 85 virtual String extraFullScreenStyleSheet() { return String(); } 86 87 // A method to obtain the baseline position for a "leaf" control. This will only be used if a baseline 88 // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of 89 // controls that need to do this. 90 virtual int baselinePosition(const RenderObject*) const; 91 92 // A method for asking if a control is a container or not. Leaf controls have to have some special behavior (like 93 // the baseline position API above). 94 bool isControlContainer(ControlPart) const; 95 96 // A method asking if the control changes its tint when the window has focus or not. 97 virtual bool controlSupportsTints(const RenderObject*) const { return false; } 98 99 // Whether or not the control has been styled enough by the author to disable the native appearance. 100 virtual bool isControlStyled(const RenderStyle*, const CachedUAStyle&) const; 101 102 // A general method asking if any control tinting is supported at all. 103 virtual bool supportsControlTints() const { return false; } 104 105 // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint, 106 // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control. 107 virtual void adjustRepaintRect(const RenderObject*, IntRect&); 108 109 // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed 110 // or a control becomes disabled. 111 virtual bool stateChanged(RenderObject*, ControlState) const; 112 113 bool shouldDrawDefaultFocusRing(RenderObject*) const; 114 115 // A method asking if the theme's controls actually care about redrawing when hovered. 116 virtual bool supportsHover(const RenderStyle*) const { return false; } 117 118 // A method asking if the platform is able to show datalist suggestions for a given input type. 119 virtual bool supportsDataListUI(const AtomicString&) const; 120 121 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 122 // A method asking if the platform is able to show a calendar picker for a given input type. 123 virtual bool supportsCalendarPicker(const AtomicString&) const; 124 #endif 125 126 // Text selection colors. 127 Color activeSelectionBackgroundColor() const; 128 Color inactiveSelectionBackgroundColor() const; 129 Color activeSelectionForegroundColor() const; 130 Color inactiveSelectionForegroundColor() const; 131 132 // List box selection colors 133 Color activeListBoxSelectionBackgroundColor() const; 134 Color activeListBoxSelectionForegroundColor() const; 135 Color inactiveListBoxSelectionBackgroundColor() const; 136 Color inactiveListBoxSelectionForegroundColor() const; 137 138 // Highlighting colors for TextMatches. 139 virtual Color platformActiveTextSearchHighlightColor() const; 140 virtual Color platformInactiveTextSearchHighlightColor() const; 141 142 static Color focusRingColor(); 143 virtual Color platformFocusRingColor() const { return Color(0, 0, 0); } 144 static void setCustomFocusRingColor(const Color&); 145 static Color tapHighlightColor(); 146 virtual Color platformTapHighlightColor() const { return RenderTheme::defaultTapHighlightColor; } 147 virtual void platformColorsDidChange(); 148 149 virtual double caretBlinkInterval() const { return 0.5; } 150 151 // System fonts and colors for CSS. 152 virtual void systemFont(CSSValueID, FontDescription&) const = 0; 153 virtual Color systemColor(CSSValueID) const; 154 155 virtual int minimumMenuListSize(RenderStyle*) const { return 0; } 156 157 virtual void adjustSliderThumbSize(RenderStyle*, Element*) const; 158 159 virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; } 160 virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; } 161 virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; } 162 virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; } 163 virtual bool popupOptionSupportsTextIndent() const { return false; } 164 165 virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; } 166 167 // Method for painting the caps lock indicator 168 virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) { return 0; }; 169 170 // Returns the repeat interval of the animation for the progress bar. 171 virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const; 172 // Returns the duration of the animation for the progress bar. 173 virtual double animationDurationForProgressBar(RenderProgress*) const; 174 175 // Media controls 176 virtual bool supportsClosedCaptioning() const { return false; } 177 virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return false; } 178 virtual bool usesVerticalVolumeSlider() const { return true; } 179 virtual String formatMediaControlsTime(float time) const; 180 virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const; 181 182 virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const; 183 virtual bool supportsMeter(ControlPart) const; 184 185 // Returns size of one slider tick mark for a horizontal track. 186 // For vertical tracks we rotate it and use it. i.e. Width is always length along the track. 187 virtual IntSize sliderTickSize() const = 0; 188 // Returns the distance of slider tick origin from the slider track center. 189 virtual int sliderTickOffsetFromTrackCenter() const = 0; 190 void paintSliderTicks(RenderObject*, const PaintInfo&, const IntRect&); 191 192 virtual bool shouldShowPlaceholderWhenFocused() const { return false; } 193 virtual bool shouldHaveSpinButton(HTMLInputElement*) const; 194 195 // Functions for <select> elements. 196 virtual bool delegatesMenuListRendering() const { return false; } 197 virtual bool popsMenuByArrowKeys() const { return false; } 198 virtual bool popsMenuBySpaceOrReturn() const { return false; } 199 200 virtual String fileListNameForWidth(Locale&, const FileList*, const Font&, int width) const; 201 202 virtual bool shouldOpenPickerWithF4Key() const; 203 204 protected: 205 // The platform selection color. 206 virtual Color platformActiveSelectionBackgroundColor() const; 207 virtual Color platformInactiveSelectionBackgroundColor() const; 208 virtual Color platformActiveSelectionForegroundColor() const; 209 virtual Color platformInactiveSelectionForegroundColor() const; 210 211 virtual Color platformActiveListBoxSelectionBackgroundColor() const; 212 virtual Color platformInactiveListBoxSelectionBackgroundColor() const; 213 virtual Color platformActiveListBoxSelectionForegroundColor() const; 214 virtual Color platformInactiveListBoxSelectionForegroundColor() const; 215 216 // A method asking if the theme is able to draw the focus ring. 217 virtual bool supportsFocusRing(const RenderStyle*) const; 218 virtual bool supportsSelectionForegroundColors() const { return true; } 219 virtual bool supportsListBoxSelectionForegroundColors() const { return true; } 220 221 #if !USE(NEW_THEME) 222 // Methods for each appearance value. 223 virtual void adjustCheckboxStyle(RenderStyle*, Element*) const; 224 virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 225 virtual void setCheckboxSize(RenderStyle*) const { } 226 227 virtual void adjustRadioStyle(RenderStyle*, Element*) const; 228 virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 229 virtual void setRadioSize(RenderStyle*) const { } 230 231 virtual void adjustButtonStyle(RenderStyle*, Element*) const; 232 virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 233 234 virtual void adjustInnerSpinButtonStyle(RenderStyle*, Element*) const; 235 virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 236 #endif 237 238 virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 239 240 virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 241 242 virtual void adjustMenuListStyle(RenderStyle*, Element*) const; 243 virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 244 245 virtual void adjustMenuListButtonStyle(RenderStyle*, Element*) const; 246 virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 247 248 virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&); 249 250 virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 251 252 #if ENABLE(INPUT_SPEECH) 253 virtual void adjustInputFieldSpeechButtonStyle(RenderStyle*, Element*) const; 254 virtual bool paintInputFieldSpeechButton(RenderObject*, const PaintInfo&, const IntRect&); 255 #endif 256 257 virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 258 259 virtual void adjustSliderThumbStyle(RenderStyle*, Element*) const; 260 virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 261 262 virtual void adjustSearchFieldStyle(RenderStyle*, Element*) const; 263 virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 264 265 virtual void adjustSearchFieldCancelButtonStyle(RenderStyle*, Element*) const; 266 virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 267 268 virtual void adjustSearchFieldDecorationStyle(RenderStyle*, Element*) const; 269 virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 270 271 virtual void adjustSearchFieldResultsDecorationStyle(RenderStyle*, Element*) const; 272 virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 273 274 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 275 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 276 virtual bool paintMediaOverlayPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 277 virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 278 virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 279 virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 280 virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 281 virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 282 virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 283 virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 284 virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 285 virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 286 virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 287 virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 288 virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 289 virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 290 virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 291 virtual bool paintMediaFullScreenVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 292 virtual bool paintMediaFullScreenVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; } 293 294 virtual bool shouldUseFallbackTheme(RenderStyle*) const; 295 void adjustStyleUsingFallbackTheme(RenderStyle*, Element*); 296 bool paintUsingFallbackTheme(RenderObject*, const PaintInfo&, const IntRect&); 297 void adjustCheckboxStyleUsingFallbackTheme(RenderStyle*, Element*) const; 298 bool paintCheckboxUsingFallbackTheme(RenderObject*, const PaintInfo&, const IntRect&); 299 void adjustRadioStyleUsingFallbackTheme(RenderStyle*, Element*) const; 300 bool paintRadioUsingFallbackTheme(RenderObject*, const PaintInfo&, const IntRect&); 301 302 public: 303 // Methods for state querying 304 ControlStates controlStatesForRenderer(const RenderObject* o) const; 305 bool isActive(const RenderObject*) const; 306 bool isChecked(const RenderObject*) const; 307 bool isIndeterminate(const RenderObject*) const; 308 bool isEnabled(const RenderObject*) const; 309 bool isFocused(const RenderObject*) const; 310 bool isPressed(const RenderObject*) const; 311 bool isSpinUpButtonPartPressed(const RenderObject*) const; 312 bool isHovered(const RenderObject*) const; 313 bool isSpinUpButtonPartHovered(const RenderObject*) const; 314 bool isReadOnlyControl(const RenderObject*) const; 315 316 private: 317 mutable Color m_activeSelectionBackgroundColor; 318 mutable Color m_inactiveSelectionBackgroundColor; 319 mutable Color m_activeSelectionForegroundColor; 320 mutable Color m_inactiveSelectionForegroundColor; 321 322 mutable Color m_activeListBoxSelectionBackgroundColor; 323 mutable Color m_inactiveListBoxSelectionBackgroundColor; 324 mutable Color m_activeListBoxSelectionForegroundColor; 325 mutable Color m_inactiveListBoxSelectionForegroundColor; 326 327 // This color is expected to be drawn on a semi-transparent overlay, 328 // making it more transparent than its alpha value indicates. 329 static const RGBA32 defaultTapHighlightColor = 0x66000000; 330 331 #if USE(NEW_THEME) 332 Theme* m_platformTheme; // The platform-specific theme. 333 #endif 334 }; 335 336 } // namespace WebCore 337 338 #endif // RenderTheme_h 339