2 * This file is part of the theme implementation for form controls in WebCore.
4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
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.
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.
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.
24 #ifndef RenderThemeMac_h
25 #define RenderThemeMac_h
27 #import "RenderTheme.h"
28 #import <wtf/RetainPtr.h>
29 #import <wtf/HashMap.h>
31 #if ENABLE(SERVICE_CONTROLS)
32 OBJC_CLASS NSServicesRolloverButtonCell;
35 OBJC_CLASS WebCoreRenderThemeNotificationObserver;
41 struct AttachmentLayout;
43 class RenderThemeMac final : public RenderTheme {
45 static PassRefPtr<RenderTheme> create();
47 // A method asking if the control changes its tint when the window has focus or not.
48 virtual bool controlSupportsTints(const RenderObject&) const override;
50 // A general method asking if any control tinting is supported at all.
51 virtual bool supportsControlTints() const override { return true; }
53 virtual void adjustRepaintRect(const RenderObject&, FloatRect&) override;
55 virtual bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer&, const Color& backgroundColor) const override;
57 virtual Color platformActiveSelectionBackgroundColor() const override;
58 virtual Color platformInactiveSelectionBackgroundColor() const override;
59 virtual Color platformActiveListBoxSelectionBackgroundColor() const override;
60 virtual Color platformActiveListBoxSelectionForegroundColor() const override;
61 virtual Color platformInactiveListBoxSelectionBackgroundColor() const override;
62 virtual Color platformInactiveListBoxSelectionForegroundColor() const override;
63 virtual Color platformFocusRingColor() const override;
64 virtual int platformFocusRingMaxWidth() const override;
66 virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) override { return SmallScrollbar; }
68 virtual void platformColorsDidChange() override;
70 virtual int minimumMenuListSize(RenderStyle&) const override;
72 virtual void adjustSliderThumbSize(RenderStyle&, Element*) const override;
74 #if ENABLE(DATALIST_ELEMENT)
75 virtual IntSize sliderTickSize() const override;
76 virtual int sliderTickOffsetFromTrackCenter() const override;
79 virtual int popupInternalPaddingLeft(RenderStyle&) const override;
80 virtual int popupInternalPaddingRight(RenderStyle&) const override;
81 virtual int popupInternalPaddingTop(RenderStyle&) const override;
82 virtual int popupInternalPaddingBottom(RenderStyle&) const override;
83 virtual PopupMenuStyle::PopupMenuSize popupMenuSize(const RenderStyle&, IntRect&) const override;
85 virtual bool popsMenuByArrowKeys() const override { return true; }
87 #if ENABLE(METER_ELEMENT)
88 virtual IntSize meterSizeForBounds(const RenderMeter&, const IntRect&) const override;
89 virtual bool paintMeter(const RenderObject&, const PaintInfo&, const IntRect&) override;
90 virtual bool supportsMeter(ControlPart) const override;
93 // Returns the repeat interval of the animation for the progress bar.
94 virtual double animationRepeatIntervalForProgressBar(RenderProgress&) const override;
95 // Returns the duration of the animation for the progress bar.
96 virtual double animationDurationForProgressBar(RenderProgress&) const override;
97 virtual IntRect progressBarRectForBounds(const RenderObject&, const IntRect&) const override;
99 virtual Color systemColor(CSSValueID) const override;
100 // Controls color values returned from platformFocusRingColor(). systemColor() will be used when false.
101 bool usesTestModeFocusRingColor() const;
102 // A view associated to the contained document.
103 NSView* documentViewFor(const RenderObject&) const;
105 virtual bool defaultButtonHasAnimation() const override;
109 virtual ~RenderThemeMac();
112 virtual void updateCachedSystemFontDescription(CSSValueID, FontDescription&) const override;
116 virtual String mediaControlsStyleSheet() override;
117 virtual String mediaControlsScript() override;
120 #if ENABLE(SERVICE_CONTROLS)
121 virtual String imageControlsStyleSheet() const override;
124 virtual bool supportsSelectionForegroundColors() const override { return false; }
126 virtual bool paintTextField(const RenderObject&, const PaintInfo&, const FloatRect&) override;
127 virtual void adjustTextFieldStyle(StyleResolver&, RenderStyle&, Element*) const override;
129 virtual bool paintTextArea(const RenderObject&, const PaintInfo&, const FloatRect&) override;
130 virtual void adjustTextAreaStyle(StyleResolver&, RenderStyle&, Element*) const override;
132 virtual bool paintMenuList(const RenderObject&, const PaintInfo&, const FloatRect&) override;
133 virtual void adjustMenuListStyle(StyleResolver&, RenderStyle&, Element*) const override;
135 virtual bool paintMenuListButtonDecorations(const RenderObject&, const PaintInfo&, const FloatRect&) override;
136 virtual void adjustMenuListButtonStyle(StyleResolver&, RenderStyle&, Element*) const override;
138 virtual void adjustProgressBarStyle(StyleResolver&, RenderStyle&, Element*) const override;
139 virtual bool paintProgressBar(const RenderObject&, const PaintInfo&, const IntRect&) override;
141 virtual bool paintSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) override;
142 virtual void adjustSliderTrackStyle(StyleResolver&, RenderStyle&, Element*) const override;
144 virtual bool paintSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) override;
145 virtual void adjustSliderThumbStyle(StyleResolver&, RenderStyle&, Element*) const override;
147 virtual bool paintSearchField(const RenderObject&, const PaintInfo&, const IntRect&) override;
148 virtual void adjustSearchFieldStyle(StyleResolver&, RenderStyle&, Element*) const override;
150 virtual void adjustSearchFieldCancelButtonStyle(StyleResolver&, RenderStyle&, Element*) const override;
151 virtual bool paintSearchFieldCancelButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
153 virtual void adjustSearchFieldDecorationPartStyle(StyleResolver&, RenderStyle&, Element*) const override;
154 virtual bool paintSearchFieldDecorationPart(const RenderObject&, const PaintInfo&, const IntRect&) override;
156 virtual void adjustSearchFieldResultsDecorationPartStyle(StyleResolver&, RenderStyle&, Element*) const override;
157 virtual bool paintSearchFieldResultsDecorationPart(const RenderObject&, const PaintInfo&, const IntRect&) override;
159 virtual void adjustSearchFieldResultsButtonStyle(StyleResolver&, RenderStyle&, Element*) const override;
160 virtual bool paintSearchFieldResultsButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
163 virtual bool supportsClosedCaptioning() const override { return true; }
166 virtual bool shouldShowPlaceholderWhenFocused() const override;
167 virtual bool shouldHaveCapsLockIndicator(HTMLInputElement&) const override;
169 virtual bool paintSnapshottedPluginOverlay(const RenderObject&, const PaintInfo&, const IntRect&) override;
171 #if ENABLE(ATTACHMENT_ELEMENT)
172 virtual LayoutSize attachmentIntrinsicSize(const RenderAttachment&) const override;
173 virtual int attachmentBaseline(const RenderAttachment&) const override;
174 virtual bool paintAttachment(const RenderObject&, const PaintInfo&, const IntRect&) override;
178 virtual String fileListNameForWidth(const FileList*, const FontCascade&, int width, bool multipleFilesAllowed) const override;
180 FloatRect convertToPaintingRect(const RenderObject& inputRenderer, const RenderObject& partRenderer, const FloatRect& inputRect, const IntRect&) const;
182 // Get the control size based off the font. Used by some of the controls (like buttons).
183 NSControlSize controlSizeForFont(RenderStyle&) const;
184 NSControlSize controlSizeForSystemFont(RenderStyle&) const;
185 NSControlSize controlSizeForCell(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f) const;
186 void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f);
187 void setSizeFromFont(RenderStyle&, const IntSize* sizes) const;
188 IntSize sizeForFont(RenderStyle&, const IntSize* sizes) const;
189 IntSize sizeForSystemFont(RenderStyle&, const IntSize* sizes) const;
190 void setFontFromControlSize(StyleResolver&, RenderStyle&, NSControlSize) const;
192 void updateCheckedState(NSCell*, const RenderObject&);
193 void updateEnabledState(NSCell*, const RenderObject&);
194 void updateFocusedState(NSCell*, const RenderObject&);
195 void updatePressedState(NSCell*, const RenderObject&);
197 // Helpers for adjusting appearance and for painting
199 void setPopupButtonCellState(const RenderObject&, const IntSize&);
200 const IntSize* popupButtonSizes() const;
201 const int* popupButtonMargins() const;
202 const int* popupButtonPadding(NSControlSize) const;
203 void paintMenuListButtonGradients(const RenderObject&, const PaintInfo&, const IntRect&);
204 const IntSize* menuListSizes() const;
206 const IntSize* searchFieldSizes() const;
207 const IntSize* cancelButtonSizes() const;
208 const IntSize* resultsButtonSizes() const;
209 void setSearchCellState(const RenderObject&, const IntRect&);
210 void setSearchFieldSize(RenderStyle&) const;
212 NSPopUpButtonCell *popupButton() const;
213 NSSearchFieldCell *search() const;
214 NSMenu *searchMenuTemplate() const;
215 NSSliderCell *sliderThumbHorizontal() const;
216 NSSliderCell *sliderThumbVertical() const;
217 NSTextFieldCell *textField() const;
219 #if ENABLE(METER_ELEMENT)
220 NSLevelIndicatorStyle levelIndicatorStyleFor(ControlPart) const;
221 NSLevelIndicatorCell *levelIndicatorFor(const RenderMeter&) const;
224 int minimumProgressBarHeight(RenderStyle&) const;
225 const IntSize* progressBarSizes() const;
226 const int* progressBarMargins(NSControlSize) const;
228 #if ENABLE(SERVICE_CONTROLS)
229 virtual bool paintImageControlsButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
230 virtual IntSize imageControlsButtonSize(const RenderObject&) const override;
231 virtual IntSize imageControlsButtonPositionOffset() const override;
233 NSServicesRolloverButtonCell *servicesRolloverButtonCell() const;
236 #if ENABLE(ATTACHMENT_ELEMENT)
237 void paintAttachmentLabelBackground(const RenderAttachment&, GraphicsContext&, AttachmentLayout&) const;
238 void paintAttachmentLabel(const RenderAttachment&, GraphicsContext&, AttachmentLayout&, bool useSelectedStyle) const;
241 mutable RetainPtr<NSPopUpButtonCell> m_popupButton;
242 mutable RetainPtr<NSSearchFieldCell> m_search;
243 mutable RetainPtr<NSMenu> m_searchMenuTemplate;
244 mutable RetainPtr<NSSliderCell> m_sliderThumbHorizontal;
245 mutable RetainPtr<NSSliderCell> m_sliderThumbVertical;
246 mutable RetainPtr<NSLevelIndicatorCell> m_levelIndicator;
247 mutable RetainPtr<NSTextFieldCell> m_textField;
248 #if ENABLE(SERVICE_CONTROLS)
249 mutable RetainPtr<NSServicesRolloverButtonCell> m_servicesRolloverButton;
252 bool m_isSliderThumbHorizontalPressed;
253 bool m_isSliderThumbVerticalPressed;
255 mutable HashMap<int, RGBA32> m_systemColorCache;
257 RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
259 String m_mediaControlsScript;
260 String m_mediaControlsStyleSheet;
263 } // namespace WebCore
265 #endif // RenderThemeMac_h
267 #endif // !PLATFORM(IOS)