OSDN Git Service

Merge WebKit at r78450: Initial merge by git.
[android-x86/external-webkit.git] / Source / WebCore / rendering / RenderThemeMac.h
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, bool isHorizontal) 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
166     virtual bool shouldRenderMediaControlPart(ControlPart, Element*);
167     virtual bool usesMediaControlStatusDisplay();
168     virtual void adjustMediaSliderThumbSize(RenderObject*) const;
169     virtual IntPoint volumeSliderOffsetFromMuteButton(Node*, const IntSize&) const;
170 #endif
171     
172     virtual bool shouldShowPlaceholderWhenFocused() const;
173
174 private:
175
176     IntRect inflateRect(const IntRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const;
177
178     FloatRect convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect& r) const;
179     
180     // Get the control size based off the font.  Used by some of the controls (like buttons).
181     NSControlSize controlSizeForFont(RenderStyle*) const;
182     NSControlSize controlSizeForSystemFont(RenderStyle*) const;
183     void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f);
184     void setSizeFromFont(RenderStyle*, const IntSize* sizes) const;
185     IntSize sizeForFont(RenderStyle*, const IntSize* sizes) const;
186     IntSize sizeForSystemFont(RenderStyle*, const IntSize* sizes) const;
187     void setFontFromControlSize(CSSStyleSelector*, RenderStyle*, NSControlSize) const;
188
189     void updateCheckedState(NSCell*, const RenderObject*);
190     void updateEnabledState(NSCell*, const RenderObject*);
191     void updateFocusedState(NSCell*, const RenderObject*);
192     void updatePressedState(NSCell*, const RenderObject*);
193     // An optional hook for subclasses to update the control tint of NSCell.
194     virtual void updateActiveState(NSCell*, const RenderObject*) {}
195
196     // Helpers for adjusting appearance and for painting
197
198     void setPopupButtonCellState(const RenderObject*, const IntRect&);
199     const IntSize* popupButtonSizes() const;
200     const int* popupButtonMargins() const;
201     const int* popupButtonPadding(NSControlSize) const;
202     void paintMenuListButtonGradients(RenderObject*, const PaintInfo&, const IntRect&);
203     const IntSize* menuListSizes() const;
204
205     const IntSize* searchFieldSizes() const;
206     const IntSize* cancelButtonSizes() const;
207     const IntSize* resultsButtonSizes() const;
208     void setSearchCellState(RenderObject*, const IntRect&);
209     void setSearchFieldSize(RenderStyle*) const;
210     
211     NSPopUpButtonCell* popupButton() const;
212     NSSearchFieldCell* search() const;
213     NSMenu* searchMenuTemplate() const;
214     NSSliderCell* sliderThumbHorizontal() const;
215     NSSliderCell* sliderThumbVertical() const;
216
217 #if ENABLE(METER_TAG)
218     NSLevelIndicatorStyle levelIndicatorStyleFor(ControlPart) const;
219     NSLevelIndicatorCell* levelIndicatorFor(const RenderMeter*) const;
220 #endif
221
222 private:
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
230     bool m_isSliderThumbHorizontalPressed;
231     bool m_isSliderThumbVerticalPressed;
232
233     mutable HashMap<int, RGBA32> m_systemColorCache;
234
235     RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
236 };
237
238 } // namespace WebCore
239
240 #endif // RenderThemeMac_h