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 RenderThemeMac_h 24 #define RenderThemeMac_h 25 26 #import "RenderTheme.h" 27 #import <wtf/HashMap.h> 28 #import <wtf/RetainPtr.h> 29 30 class RenderProgress; 31 32 #ifdef __OBJC__ 33 @class WebCoreRenderThemeNotificationObserver; 34 #else 35 class WebCoreRenderThemeNotificationObserver; 36 #endif 37 38 namespace WebCore { 39 40 class RenderStyle; 41 42 class RenderThemeMac : public RenderTheme { 43 public: 44 static PassRefPtr<RenderTheme> create(); 45 46 // A method asking if the control changes its tint when the window has focus or not. 47 virtual bool controlSupportsTints(const RenderObject*) const; 48 49 // A general method asking if any control tinting is supported at all. 50 virtual bool supportsControlTints() const { return true; } 51 52 virtual void adjustRepaintRect(const RenderObject*, IntRect&); 53 54 virtual bool isControlStyled(const RenderStyle*, const BorderData&, 55 const FillLayer&, const Color& backgroundColor) const; 56 57 virtual Color platformActiveSelectionBackgroundColor() const; 58 virtual Color platformInactiveSelectionBackgroundColor() const; 59 virtual Color platformActiveListBoxSelectionBackgroundColor() const; 60 virtual Color platformActiveListBoxSelectionForegroundColor() const; 61 virtual Color platformInactiveListBoxSelectionBackgroundColor() const; 62 virtual Color platformInactiveListBoxSelectionForegroundColor() const; 63 virtual Color platformFocusRingColor() const; 64 65 virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return SmallScrollbar; } 66 67 virtual void platformColorsDidChange(); 68 69 // System fonts. 70 virtual void systemFont(int cssValueId, FontDescription&) const; 71 72 virtual int minimumMenuListSize(RenderStyle*) const; 73 74 virtual void adjustSliderThumbSize(RenderObject*) const; 75 76 virtual int popupInternalPaddingLeft(RenderStyle*) const; 77 virtual int popupInternalPaddingRight(RenderStyle*) const; 78 virtual int popupInternalPaddingTop(RenderStyle*) const; 79 virtual int popupInternalPaddingBottom(RenderStyle*) const; 80 81 virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&); 82 83 #if ENABLE(METER_TAG) 84 virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const; 85 virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&); 86 virtual bool supportsMeter(ControlPart) const; 87 #endif 88 89 #if ENABLE(PROGRESS_TAG) 90 // Returns the repeat interval of the animation for the progress bar. 91 virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const; 92 // Returns the duration of the animation for the progress bar. 93 virtual double animationDurationForProgressBar(RenderProgress*) const; 94 #endif 95 96 virtual Color systemColor(int cssValueId) const; 97 // Controls color values returned from platformFocusRingColor(). systemColor() will be used when false. 98 virtual bool usesTestModeFocusRingColor() const; 99 // A view associated to the contained document. Subclasses may not have such a view and return a fake. 100 virtual NSView* documentViewFor(RenderObject*) const; 101 protected: 102 RenderThemeMac(); 103 virtual ~RenderThemeMac(); 104 105 virtual bool supportsSelectionForegroundColors() const { return false; } 106 107 virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&); 108 virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 109 110 virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&); 111 virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 112 113 virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&); 114 virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 115 116 virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&); 117 virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 118 119 #if ENABLE(PROGRESS_TAG) 120 virtual void adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 121 virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&); 122 #endif 123 124 virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&); 125 virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 126 127 virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&); 128 virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 129 130 virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&); 131 virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 132 133 virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 134 virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&); 135 136 virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 137 virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&); 138 139 virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 140 virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&); 141 142 virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 143 virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&); 144 145 #if ENABLE(VIDEO) 146 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&); 147 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&); 148 virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&); 149 virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&); 150 virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&); 151 virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&); 152 virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&); 153 virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&); 154 virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&); 155 virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&); 156 virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&); 157 virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&); 158 virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&); 159 virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&); 160 virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&); 161 virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&); 162 163 // Media controls 164 virtual String extraMediaControlsStyleSheet(); 165 #if ENABLE(FULLSCREEN_API) 166 virtual String extraFullScreenStyleSheet(); 167 #endif 168 169 virtual bool supportsClosedCaptioning() const { return true; } 170 virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const; 171 virtual bool usesMediaControlStatusDisplay(); 172 virtual bool usesMediaControlVolumeSlider() const; 173 virtual void adjustMediaSliderThumbSize(RenderObject*) const; 174 virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const; 175 #endif 176 177 virtual bool shouldShowPlaceholderWhenFocused() const; 178 179 private: 180 181 IntRect inflateRect(const IntRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const; 182 183 FloatRect convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect& r) const; 184 185 // Get the control size based off the font. Used by some of the controls (like buttons). 186 NSControlSize controlSizeForFont(RenderStyle*) const; 187 NSControlSize controlSizeForSystemFont(RenderStyle*) const; 188 void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f); 189 void setSizeFromFont(RenderStyle*, const IntSize* sizes) const; 190 IntSize sizeForFont(RenderStyle*, const IntSize* sizes) const; 191 IntSize sizeForSystemFont(RenderStyle*, const IntSize* sizes) const; 192 void setFontFromControlSize(CSSStyleSelector*, RenderStyle*, NSControlSize) const; 193 194 void updateCheckedState(NSCell*, const RenderObject*); 195 void updateEnabledState(NSCell*, const RenderObject*); 196 void updateFocusedState(NSCell*, const RenderObject*); 197 void updatePressedState(NSCell*, const RenderObject*); 198 // An optional hook for subclasses to update the control tint of NSCell. 199 virtual void updateActiveState(NSCell*, const RenderObject*) {} 200 201 // Helpers for adjusting appearance and for painting 202 203 void setPopupButtonCellState(const RenderObject*, const IntRect&); 204 const IntSize* popupButtonSizes() const; 205 const int* popupButtonMargins() const; 206 const int* popupButtonPadding(NSControlSize) const; 207 void paintMenuListButtonGradients(RenderObject*, const PaintInfo&, const IntRect&); 208 const IntSize* menuListSizes() const; 209 210 const IntSize* searchFieldSizes() const; 211 const IntSize* cancelButtonSizes() const; 212 const IntSize* resultsButtonSizes() const; 213 void setSearchCellState(RenderObject*, const IntRect&); 214 void setSearchFieldSize(RenderStyle*) const; 215 216 NSPopUpButtonCell* popupButton() const; 217 NSSearchFieldCell* search() const; 218 NSMenu* searchMenuTemplate() const; 219 NSSliderCell* sliderThumbHorizontal() const; 220 NSSliderCell* sliderThumbVertical() const; 221 222 #if ENABLE(METER_TAG) 223 NSLevelIndicatorStyle levelIndicatorStyleFor(ControlPart) const; 224 NSLevelIndicatorCell* levelIndicatorFor(const RenderMeter*) const; 225 #endif 226 227 private: 228 mutable RetainPtr<NSPopUpButtonCell> m_popupButton; 229 mutable RetainPtr<NSSearchFieldCell> m_search; 230 mutable RetainPtr<NSMenu> m_searchMenuTemplate; 231 mutable RetainPtr<NSSliderCell> m_sliderThumbHorizontal; 232 mutable RetainPtr<NSSliderCell> m_sliderThumbVertical; 233 mutable RetainPtr<NSLevelIndicatorCell> m_levelIndicator; 234 235 bool m_isSliderThumbHorizontalPressed; 236 bool m_isSliderThumbVerticalPressed; 237 238 mutable HashMap<int, RGBA32> m_systemColorCache; 239 240 RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver; 241 }; 242 243 } // namespace WebCore 244 245 #endif // RenderThemeMac_h 246