blob: 9061eb9c6665a5d77e3b7c3dec8679619ef2fc7b [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
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100134 virtual bool supportsClosedCaptioning() const { return true; }
135
136private:
137 virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const OVERRIDE;
138
139 IntRect inflateRect(const IntRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const;
140
141 FloatRect convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect&) const;
142
143 // Get the control size based off the font. Used by some of the controls (like buttons).
144 NSControlSize controlSizeForFont(RenderStyle*) const;
145 NSControlSize controlSizeForSystemFont(RenderStyle*) const;
146 void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f);
147 void setSizeFromFont(RenderStyle*, const IntSize* sizes) const;
148 IntSize sizeForFont(RenderStyle*, const IntSize* sizes) const;
149 IntSize sizeForSystemFont(RenderStyle*, const IntSize* sizes) const;
150 void setFontFromControlSize(StyleResolver*, RenderStyle*, NSControlSize) const;
151
152 void updateCheckedState(NSCell*, const RenderObject*);
153 void updateEnabledState(NSCell*, const RenderObject*);
154 void updateFocusedState(NSCell*, const RenderObject*);
155 void updatePressedState(NSCell*, const RenderObject*);
156
157 // Helpers for adjusting appearance and for painting
158
159 void setPopupButtonCellState(const RenderObject*, const IntRect&);
160 const IntSize* popupButtonSizes() const;
161 const int* popupButtonMargins() const;
162 const int* popupButtonPadding(NSControlSize) const;
163 void paintMenuListButtonGradients(RenderObject*, const PaintInfo&, const IntRect&);
164 const IntSize* menuListSizes() const;
165
166 const IntSize* searchFieldSizes() const;
167 const IntSize* cancelButtonSizes() const;
168 const IntSize* resultsButtonSizes() const;
169 void setSearchCellState(RenderObject*, const IntRect&);
170 void setSearchFieldSize(RenderStyle*) const;
171
172 NSPopUpButtonCell* popupButton() const;
173 NSSearchFieldCell* search() const;
174 NSMenu* searchMenuTemplate() const;
175 NSSliderCell* sliderThumbHorizontal() const;
176 NSSliderCell* sliderThumbVertical() const;
177 NSTextFieldCell* textField() const;
178
179 NSLevelIndicatorStyle levelIndicatorStyleFor(ControlPart) const;
180 NSLevelIndicatorCell* levelIndicatorFor(const RenderMeter*) const;
181
182 int minimumProgressBarHeight(RenderStyle*) const;
183 const IntSize* progressBarSizes() const;
184 const int* progressBarMargins(NSControlSize) const;
185
186protected:
187 virtual void adjustMediaSliderThumbSize(RenderStyle*) const;
188 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
189 virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&);
190 virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
191 virtual String extraMediaControlsStyleSheet();
192 virtual String extraFullScreenStyleSheet();
193
194 virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
195 virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&);
196 virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
197 virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
198 virtual bool usesMediaControlStatusDisplay() { return false; }
199 virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return true; }
200 virtual bool usesVerticalVolumeSlider() const { return false; }
201 virtual String formatMediaControlsTime(float time) const;
202 virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
203 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
204 virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&);
205
206 // Controls color values returned from platformFocusRingColor(). systemColor() will be used when false.
207 bool usesTestModeFocusRingColor() const;
208 // A view associated to the contained document. Subclasses may not have such a view and return a fake.
209 NSView* documentViewFor(RenderObject*) const;
210
211private:
212 virtual Color disabledTextColor(const Color& textColor, const Color&) const OVERRIDE { return textColor; }
213 virtual void updateActiveState(NSCell*, const RenderObject*);
214 virtual String extraDefaultStyleSheet();
215#if ENABLE(DATALIST_ELEMENT)
216 virtual LayoutUnit sliderTickSnappingThreshold() const OVERRIDE;
217#endif
218#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
219 virtual bool supportsCalendarPicker(const AtomicString& type) const OVERRIDE;
220#endif
221 virtual bool shouldShowPlaceholderWhenFocused() const OVERRIDE;
222
223 mutable RetainPtr<NSPopUpButtonCell> m_popupButton;
224 mutable RetainPtr<NSSearchFieldCell> m_search;
225 mutable RetainPtr<NSMenu> m_searchMenuTemplate;
226 mutable RetainPtr<NSSliderCell> m_sliderThumbHorizontal;
227 mutable RetainPtr<NSSliderCell> m_sliderThumbVertical;
228 mutable RetainPtr<NSLevelIndicatorCell> m_levelIndicator;
229 mutable RetainPtr<NSTextFieldCell> m_textField;
230
231 bool m_isSliderThumbHorizontalPressed;
232 bool m_isSliderThumbVerticalPressed;
233
234 mutable HashMap<int, RGBA32> m_systemColorCache;
235
236 RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
237};
238
239} // namespace WebCore
240
241#endif // RenderThemeChromiumMac_h