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