blob: 1f55e4f02896fe72f3244baee0c26f736b8cf6b8 [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * This file is part of the theme implementation for form controls in WebCore.
3 *
4 * Copyright (C) 2005 Apple Computer, Inc.
5 * Copyright (C) 2008, 2009 Google, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef RenderThemeChromiumMac_h
25#define RenderThemeChromiumMac_h
26
27#import "core/rendering/RenderTheme.h"
28#import "core/rendering/RenderThemeChromiumCommon.h"
29
30#import <wtf/HashMap.h>
31#import <wtf/RetainPtr.h>
32
33OBJC_CLASS WebCoreRenderThemeNotificationObserver;
34
35namespace WebCore {
36
37class RenderThemeChromiumMac : public RenderTheme {
38public:
39 static PassRefPtr<RenderTheme> create();
40
41 virtual bool supportsDataListUI(const AtomicString& type) const OVERRIDE;
42
43 // A method asking if the control changes its tint when the window has focus or not.
44 virtual bool controlSupportsTints(const RenderObject*) const;
45
46 // A general method asking if any control tinting is supported at all.
47 virtual bool supportsControlTints() const { return true; }
48
49 virtual void adjustRepaintRect(const RenderObject*, IntRect&) OVERRIDE;
50
51 virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
52
53 virtual Color platformActiveSelectionBackgroundColor() const;
54 virtual Color platformInactiveSelectionBackgroundColor() const;
55 virtual Color platformActiveListBoxSelectionBackgroundColor() const;
56 virtual Color platformActiveListBoxSelectionForegroundColor() const;
57 virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
58 virtual Color platformInactiveListBoxSelectionForegroundColor() const;
59 virtual Color platformFocusRingColor() const;
60
61 virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return SmallScrollbar; }
62
63 virtual void platformColorsDidChange();
64
65 // System fonts.
66 virtual void systemFont(int cssValueId, FontDescription&) const;
67
68 virtual int minimumMenuListSize(RenderStyle*) const;
69
70 virtual void adjustSliderThumbSize(RenderStyle*, Element*) const;
71
72#if ENABLE(DATALIST_ELEMENT)
73 virtual IntSize sliderTickSize() const OVERRIDE;
74 virtual int sliderTickOffsetFromTrackCenter() const OVERRIDE;
75#endif
76
77 virtual int popupInternalPaddingLeft(RenderStyle*) const;
78 virtual int popupInternalPaddingRight(RenderStyle*) const;
79 virtual int popupInternalPaddingTop(RenderStyle*) const;
80 virtual int popupInternalPaddingBottom(RenderStyle*) const;
81
82 virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) OVERRIDE;
83
84 virtual bool popsMenuByArrowKeys() const OVERRIDE { return true; }
85
86 virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const OVERRIDE;
87 virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
88 virtual bool supportsMeter(ControlPart) const;
89
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
95 virtual Color systemColor(int cssValueId) const;
96
97protected:
98 RenderThemeChromiumMac();
99 virtual ~RenderThemeChromiumMac();
100
101 virtual bool supportsSelectionForegroundColors() const { return false; }
102
103 virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&);
104 virtual void adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
105
106 virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&);
107 virtual void adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const;
108
109 virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&);
110 virtual void adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const;
111
112 virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&);
113 virtual void adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
114
115 virtual void adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const;
116 virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&);
117
118 virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
119
120 virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
121
122 virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&);
123 virtual void adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
124
125 virtual void adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
126 virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&);
127
128 virtual void adjustSearchFieldDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
129 virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&);
130
131 virtual void adjustSearchFieldResultsDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
132 virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&);
133
134 virtual void adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
135 virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&);
136
137 virtual bool supportsClosedCaptioning() const { return true; }
138
139private:
140 virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const OVERRIDE;
141
142 IntRect inflateRect(const IntRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const;
143
144 FloatRect convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect&) const;
145
146 // Get the control size based off the font. Used by some of the controls (like buttons).
147 NSControlSize controlSizeForFont(RenderStyle*) const;
148 NSControlSize controlSizeForSystemFont(RenderStyle*) const;
149 void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f);
150 void setSizeFromFont(RenderStyle*, const IntSize* sizes) const;
151 IntSize sizeForFont(RenderStyle*, const IntSize* sizes) const;
152 IntSize sizeForSystemFont(RenderStyle*, const IntSize* sizes) const;
153 void setFontFromControlSize(StyleResolver*, RenderStyle*, NSControlSize) const;
154
155 void updateCheckedState(NSCell*, const RenderObject*);
156 void updateEnabledState(NSCell*, const RenderObject*);
157 void updateFocusedState(NSCell*, const RenderObject*);
158 void updatePressedState(NSCell*, const RenderObject*);
159
160 // Helpers for adjusting appearance and for painting
161
162 void setPopupButtonCellState(const RenderObject*, const IntRect&);
163 const IntSize* popupButtonSizes() const;
164 const int* popupButtonMargins() const;
165 const int* popupButtonPadding(NSControlSize) const;
166 void paintMenuListButtonGradients(RenderObject*, const PaintInfo&, const IntRect&);
167 const IntSize* menuListSizes() const;
168
169 const IntSize* searchFieldSizes() const;
170 const IntSize* cancelButtonSizes() const;
171 const IntSize* resultsButtonSizes() const;
172 void setSearchCellState(RenderObject*, const IntRect&);
173 void setSearchFieldSize(RenderStyle*) const;
174
175 NSPopUpButtonCell* popupButton() const;
176 NSSearchFieldCell* search() const;
177 NSMenu* searchMenuTemplate() const;
178 NSSliderCell* sliderThumbHorizontal() const;
179 NSSliderCell* sliderThumbVertical() const;
180 NSTextFieldCell* textField() const;
181
182 NSLevelIndicatorStyle levelIndicatorStyleFor(ControlPart) const;
183 NSLevelIndicatorCell* levelIndicatorFor(const RenderMeter*) const;
184
185 int minimumProgressBarHeight(RenderStyle*) const;
186 const IntSize* progressBarSizes() const;
187 const int* progressBarMargins(NSControlSize) const;
188
189protected:
190 virtual void adjustMediaSliderThumbSize(RenderStyle*) const;
191 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
192 virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&);
193 virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
194 virtual String extraMediaControlsStyleSheet();
195 virtual String extraFullScreenStyleSheet();
196
197 virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
198 virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&);
199 virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
200 virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
201 virtual bool usesMediaControlStatusDisplay() { return false; }
202 virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return true; }
203 virtual bool usesVerticalVolumeSlider() const { return false; }
204 virtual String formatMediaControlsTime(float time) const;
205 virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
206 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
207 virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&);
208
209 // Controls color values returned from platformFocusRingColor(). systemColor() will be used when false.
210 bool usesTestModeFocusRingColor() const;
211 // A view associated to the contained document. Subclasses may not have such a view and return a fake.
212 NSView* documentViewFor(RenderObject*) const;
213
214private:
215 virtual Color disabledTextColor(const Color& textColor, const Color&) const OVERRIDE { return textColor; }
216 virtual void updateActiveState(NSCell*, const RenderObject*);
217 virtual String extraDefaultStyleSheet();
218#if ENABLE(DATALIST_ELEMENT)
219 virtual LayoutUnit sliderTickSnappingThreshold() const OVERRIDE;
220#endif
221#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
222 virtual bool supportsCalendarPicker(const AtomicString& type) const OVERRIDE;
223#endif
224 virtual bool shouldShowPlaceholderWhenFocused() const OVERRIDE;
225
226 mutable RetainPtr<NSPopUpButtonCell> m_popupButton;
227 mutable RetainPtr<NSSearchFieldCell> m_search;
228 mutable RetainPtr<NSMenu> m_searchMenuTemplate;
229 mutable RetainPtr<NSSliderCell> m_sliderThumbHorizontal;
230 mutable RetainPtr<NSSliderCell> m_sliderThumbVertical;
231 mutable RetainPtr<NSLevelIndicatorCell> m_levelIndicator;
232 mutable RetainPtr<NSTextFieldCell> m_textField;
233
234 bool m_isSliderThumbHorizontalPressed;
235 bool m_isSliderThumbVerticalPressed;
236
237 mutable HashMap<int, RGBA32> m_systemColorCache;
238
239 RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
240};
241
242} // namespace WebCore
243
244#endif // RenderThemeChromiumMac_h