RenderThemeMac.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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, 2011, 2012 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. #ifndef RenderThemeMac_h
  23. #define RenderThemeMac_h
  24. #import "RenderTheme.h"
  25. #import <wtf/RetainPtr.h>
  26. #import <wtf/HashMap.h>
  27. OBJC_CLASS WebCoreRenderThemeNotificationObserver;
  28. namespace WebCore {
  29. class RenderProgress;
  30. class RenderStyle;
  31. class RenderThemeMac : public RenderTheme {
  32. public:
  33. static PassRefPtr<RenderTheme> create();
  34. // A method asking if the control changes its tint when the window has focus or not.
  35. virtual bool controlSupportsTints(const RenderObject*) const;
  36. // A general method asking if any control tinting is supported at all.
  37. virtual bool supportsControlTints() const { return true; }
  38. virtual void adjustRepaintRect(const RenderObject*, IntRect&) OVERRIDE;
  39. virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
  40. virtual Color platformActiveSelectionBackgroundColor() const;
  41. virtual Color platformInactiveSelectionBackgroundColor() const;
  42. virtual Color platformActiveListBoxSelectionBackgroundColor() const;
  43. virtual Color platformActiveListBoxSelectionForegroundColor() const;
  44. virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
  45. virtual Color platformInactiveListBoxSelectionForegroundColor() const;
  46. virtual Color platformFocusRingColor() const;
  47. virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return SmallScrollbar; }
  48. virtual void platformColorsDidChange();
  49. // System fonts.
  50. virtual void systemFont(int cssValueId, FontDescription&) const;
  51. virtual int minimumMenuListSize(RenderStyle*) const;
  52. virtual void adjustSliderThumbSize(RenderStyle*, Element*) const;
  53. #if ENABLE(DATALIST_ELEMENT)
  54. virtual IntSize sliderTickSize() const OVERRIDE;
  55. virtual int sliderTickOffsetFromTrackCenter() const OVERRIDE;
  56. #endif
  57. virtual int popupInternalPaddingLeft(RenderStyle*) const;
  58. virtual int popupInternalPaddingRight(RenderStyle*) const;
  59. virtual int popupInternalPaddingTop(RenderStyle*) const;
  60. virtual int popupInternalPaddingBottom(RenderStyle*) const;
  61. virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) OVERRIDE;
  62. virtual bool popsMenuByArrowKeys() const OVERRIDE { return true; }
  63. #if ENABLE(METER_ELEMENT)
  64. virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const OVERRIDE;
  65. virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
  66. virtual bool supportsMeter(ControlPart) const;
  67. #endif
  68. #if ENABLE(PROGRESS_ELEMENT)
  69. // Returns the repeat interval of the animation for the progress bar.
  70. virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
  71. // Returns the duration of the animation for the progress bar.
  72. virtual double animationDurationForProgressBar(RenderProgress*) const;
  73. #endif
  74. virtual Color systemColor(int cssValueId) const;
  75. // Controls color values returned from platformFocusRingColor(). systemColor() will be used when false.
  76. virtual bool usesTestModeFocusRingColor() const;
  77. // A view associated to the contained document. Subclasses may not have such a view and return a fake.
  78. NSView* documentViewFor(RenderObject*) const;
  79. protected:
  80. RenderThemeMac();
  81. virtual ~RenderThemeMac();
  82. #if ENABLE(VIDEO)
  83. virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
  84. virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
  85. virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&);
  86. virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&);
  87. virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&);
  88. virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
  89. virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
  90. virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&);
  91. virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&);
  92. virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&);
  93. virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&);
  94. virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&);
  95. virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&);
  96. virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
  97. virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
  98. virtual bool paintMediaFullScreenVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) OVERRIDE;
  99. virtual bool paintMediaFullScreenVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) OVERRIDE;
  100. // Media controls
  101. virtual String extraMediaControlsStyleSheet();
  102. #if ENABLE(FULLSCREEN_API)
  103. virtual String extraFullScreenStyleSheet();
  104. #endif
  105. virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const;
  106. virtual bool usesMediaControlStatusDisplay();
  107. virtual bool usesMediaControlVolumeSlider() const;
  108. virtual void adjustMediaSliderThumbSize(RenderStyle*) const;
  109. virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const OVERRIDE;
  110. #endif
  111. virtual bool supportsSelectionForegroundColors() const { return false; }
  112. virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&);
  113. virtual void adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
  114. virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&);
  115. virtual void adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const;
  116. virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&);
  117. virtual void adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const;
  118. virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&);
  119. virtual void adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
  120. #if ENABLE(PROGRESS_ELEMENT)
  121. virtual void adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const;
  122. virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&);
  123. #endif
  124. virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
  125. virtual void adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const;
  126. virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
  127. virtual void adjustSliderThumbStyle(StyleResolver*, RenderStyle*, Element*) const;
  128. virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&);
  129. virtual void adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
  130. virtual void adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
  131. virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&);
  132. virtual void adjustSearchFieldDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
  133. virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&);
  134. virtual void adjustSearchFieldResultsDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
  135. virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&);
  136. virtual void adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
  137. virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&);
  138. #if ENABLE(VIDEO)
  139. virtual bool supportsClosedCaptioning() const { return true; }
  140. #endif
  141. virtual bool shouldShowPlaceholderWhenFocused() const;
  142. virtual bool paintSnapshottedPluginOverlay(RenderObject*, const PaintInfo&, const IntRect&);
  143. private:
  144. virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const OVERRIDE;
  145. IntRect inflateRect(const IntRect&, const IntSize&, const int* margins, float zoomLevel = 1.0f) const;
  146. FloatRect convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect&) const;
  147. // Get the control size based off the font. Used by some of the controls (like buttons).
  148. NSControlSize controlSizeForFont(RenderStyle*) const;
  149. NSControlSize controlSizeForSystemFont(RenderStyle*) const;
  150. void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f);
  151. void setSizeFromFont(RenderStyle*, const IntSize* sizes) const;
  152. IntSize sizeForFont(RenderStyle*, const IntSize* sizes) const;
  153. IntSize sizeForSystemFont(RenderStyle*, const IntSize* sizes) const;
  154. void setFontFromControlSize(StyleResolver*, RenderStyle*, NSControlSize) const;
  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. // An optional hook for subclasses to update the control tint of NSCell.
  160. virtual void updateActiveState(NSCell*, const RenderObject*) { }
  161. // Helpers for adjusting appearance and for painting
  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. 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. NSPopUpButtonCell* popupButton() const;
  174. NSSearchFieldCell* search() const;
  175. NSMenu* searchMenuTemplate() const;
  176. NSSliderCell* sliderThumbHorizontal() const;
  177. NSSliderCell* sliderThumbVertical() const;
  178. NSTextFieldCell* textField() const;
  179. #if ENABLE(METER_ELEMENT)
  180. NSLevelIndicatorStyle levelIndicatorStyleFor(ControlPart) const;
  181. NSLevelIndicatorCell* levelIndicatorFor(const RenderMeter*) const;
  182. #endif
  183. #if ENABLE(PROGRESS_ELEMENT)
  184. int minimumProgressBarHeight(RenderStyle*) const;
  185. const IntSize* progressBarSizes() const;
  186. const int* progressBarMargins(NSControlSize) const;
  187. #endif
  188. private:
  189. mutable RetainPtr<NSPopUpButtonCell> m_popupButton;
  190. mutable RetainPtr<NSSearchFieldCell> m_search;
  191. mutable RetainPtr<NSMenu> m_searchMenuTemplate;
  192. mutable RetainPtr<NSSliderCell> m_sliderThumbHorizontal;
  193. mutable RetainPtr<NSSliderCell> m_sliderThumbVertical;
  194. mutable RetainPtr<NSLevelIndicatorCell> m_levelIndicator;
  195. mutable RetainPtr<NSTextFieldCell> m_textField;
  196. bool m_isSliderThumbHorizontalPressed;
  197. bool m_isSliderThumbVerticalPressed;
  198. mutable HashMap<int, RGBA32> m_systemColorCache;
  199. RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
  200. };
  201. } // namespace WebCore
  202. #endif // RenderThemeMac_h