• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the theme implementation for form controls in WebCore.
3  *
4  * Copyright (C) 2005 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 #ifdef __OBJC__
31 @class WebCoreRenderThemeNotificationObserver;
32 #else
33 class WebCoreRenderThemeNotificationObserver;
34 #endif
35 
36 namespace WebCore {
37 
38 class RenderStyle;
39 
40 class RenderThemeMac : public RenderTheme {
41 public:
42     static PassRefPtr<RenderTheme> create();
43 
44     // A method asking if the control changes its tint when the window has focus or not.
45     virtual bool controlSupportsTints(const RenderObject*) const;
46 
47     // A general method asking if any control tinting is supported at all.
supportsControlTints()48     virtual bool supportsControlTints() const { return true; }
49 
50     virtual void adjustRepaintRect(const RenderObject*, IntRect&);
51 
52     virtual bool isControlStyled(const RenderStyle*, const BorderData&,
53                                  const FillLayer&, const Color& backgroundColor) const;
54 
55     virtual Color platformActiveSelectionBackgroundColor() const;
56     virtual Color platformInactiveSelectionBackgroundColor() const;
57     virtual Color platformActiveListBoxSelectionBackgroundColor() const;
58     virtual Color platformActiveListBoxSelectionForegroundColor() const;
59     virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
60     virtual Color platformInactiveListBoxSelectionForegroundColor() const;
61     virtual Color platformFocusRingColor() const;
62 
scrollbarControlSizeForPart(ControlPart)63     virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return SmallScrollbar; }
64 
65     virtual void platformColorsDidChange();
66 
67     // System fonts.
68     virtual void systemFont(int cssValueId, FontDescription&) const;
69 
70     virtual int minimumMenuListSize(RenderStyle*) const;
71 
72     virtual void adjustSliderThumbSize(RenderObject*) const;
73 
74     virtual int popupInternalPaddingLeft(RenderStyle*) const;
75     virtual int popupInternalPaddingRight(RenderStyle*) const;
76     virtual int popupInternalPaddingTop(RenderStyle*) const;
77     virtual int popupInternalPaddingBottom(RenderStyle*) const;
78 
79     virtual bool paintCapsLockIndicator(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
80 
81     virtual Color systemColor(int cssValueId) const;
82 
83 protected:
supportsSelectionForegroundColors()84     virtual bool supportsSelectionForegroundColors() const { return false; }
85 
86     virtual bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
87     virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
88 
89     virtual bool paintTextArea(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
90     virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
91 
92     virtual bool paintMenuList(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
93     virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
94 
95     virtual bool paintMenuListButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
96     virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
97 
98     virtual bool paintSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
99     virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
100 
101     virtual bool paintSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
102     virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
103 
104     virtual bool paintSearchField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
105     virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
106 
107     virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
108     virtual bool paintSearchFieldCancelButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
109 
110     virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
111     virtual bool paintSearchFieldDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
112 
113     virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
114     virtual bool paintSearchFieldResultsDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
115 
116     virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
117     virtual bool paintSearchFieldResultsButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
118 
119 #if ENABLE(VIDEO)
120     virtual bool paintMediaFullscreenButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
121     virtual bool paintMediaPlayButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
122     virtual bool paintMediaMuteButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
123     virtual bool paintMediaSeekBackButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
124     virtual bool paintMediaSeekForwardButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
125     virtual bool paintMediaSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
126     virtual bool paintMediaSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
127     virtual bool paintMediaRewindButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
128     virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
129     virtual bool paintMediaControlsBackground(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
130     virtual bool paintMediaCurrentTime(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
131     virtual bool paintMediaTimeRemaining(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
132 
133     // Media controls
134     virtual String extraMediaControlsStyleSheet();
135 #endif
136 
137 private:
138     RenderThemeMac();
139     virtual ~RenderThemeMac();
140 
141     IntRect inflateRect(const IntRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const;
142 
143     FloatRect convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect& r) const;
144 
145     // Get the control size based off the font.  Used by some of the controls (like buttons).
146     NSControlSize controlSizeForFont(RenderStyle*) const;
147     NSControlSize controlSizeForSystemFont(RenderStyle*) const;
148     void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f);
149     void setSizeFromFont(RenderStyle*, const IntSize* sizes) const;
150     IntSize sizeForFont(RenderStyle*, const IntSize* sizes) const;
151     IntSize sizeForSystemFont(RenderStyle*, const IntSize* sizes) const;
152     void setFontFromControlSize(CSSStyleSelector*, RenderStyle*, NSControlSize) const;
153 
154     void updateCheckedState(NSCell*, const RenderObject*);
155     void updateEnabledState(NSCell*, const RenderObject*);
156     void updateFocusedState(NSCell*, const RenderObject*);
157     void updatePressedState(NSCell*, const RenderObject*);
158 
159     // Helpers for adjusting appearance and for painting
160 
161     void setPopupButtonCellState(const RenderObject*, const IntRect&);
162     const IntSize* popupButtonSizes() const;
163     const int* popupButtonMargins() const;
164     const int* popupButtonPadding(NSControlSize) const;
165     void paintMenuListButtonGradients(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
166     const IntSize* menuListSizes() const;
167 
168     const IntSize* searchFieldSizes() const;
169     const IntSize* cancelButtonSizes() const;
170     const IntSize* resultsButtonSizes() const;
171     void setSearchCellState(RenderObject*, const IntRect&);
172     void setSearchFieldSize(RenderStyle*) const;
173 
174     NSPopUpButtonCell* popupButton() const;
175     NSSearchFieldCell* search() const;
176     NSMenu* searchMenuTemplate() const;
177     NSSliderCell* sliderThumbHorizontal() const;
178     NSSliderCell* sliderThumbVertical() const;
179 
180 private:
181     mutable RetainPtr<NSPopUpButtonCell> m_popupButton;
182     mutable RetainPtr<NSSearchFieldCell> m_search;
183     mutable RetainPtr<NSMenu> m_searchMenuTemplate;
184     mutable RetainPtr<NSSliderCell> m_sliderThumbHorizontal;
185     mutable RetainPtr<NSSliderCell> m_sliderThumbVertical;
186 
187     bool m_isSliderThumbHorizontalPressed;
188     bool m_isSliderThumbVerticalPressed;
189 
190     mutable HashMap<int, RGBA32> m_systemColorCache;
191 
192     RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
193 };
194 
195 } // namespace WebCore
196 
197 #endif // RenderThemeMac_h
198