Theme.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2008 Apple Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef Theme_h
  26. #define Theme_h
  27. #include "Color.h"
  28. #include "Font.h"
  29. #include "IntRect.h"
  30. #include "LengthBox.h"
  31. #include "LengthSize.h"
  32. #include "ThemeTypes.h"
  33. #include <wtf/Forward.h>
  34. namespace WebCore {
  35. class GraphicsContext;
  36. class ScrollView;
  37. // Unlike other platform classes, Theme does extensively use virtual functions. This design allows a platform to switch between multiple themes at runtime.
  38. class Theme {
  39. public:
  40. Theme() { }
  41. virtual ~Theme() { }
  42. // A method to obtain the baseline position adjustment for a "leaf" control. This will only be used if a baseline
  43. // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
  44. // controls that need to do this. The adjustment is an offset that adds to the baseline, e.g., marginTop() + height() + |offset|.
  45. // The offset is not zoomed.
  46. virtual int baselinePositionAdjustment(ControlPart) const { return 0; }
  47. // A method asking if the control changes its appearance when the window is inactive.
  48. virtual bool controlHasInactiveAppearance(ControlPart) const { return false; }
  49. // General methods for whether or not any of the controls in the theme change appearance when the window is inactive or
  50. // when hovered over.
  51. virtual bool controlsCanHaveInactiveAppearance() const { return false; }
  52. virtual bool controlsCanHaveHoveredAppearance() const { return false; }
  53. // Used by RenderTheme::isControlStyled to figure out if the native look and feel should be turned off.
  54. virtual bool controlDrawsBorder(ControlPart) const { return true; }
  55. virtual bool controlDrawsBackground(ControlPart) const { return true; }
  56. virtual bool controlDrawsFocusOutline(ControlPart) const { return true; }
  57. // Methods for obtaining platform-specific colors.
  58. virtual Color selectionColor(ControlPart, ControlState, SelectionPart) const { return Color(); }
  59. virtual Color textSearchHighlightColor() const { return Color(); }
  60. // CSS system colors and fonts
  61. virtual Color systemColor(ThemeColor) const { return Color(); }
  62. virtual Font systemFont(ThemeFont, FontDescription&) const { return Font(); }
  63. // How fast the caret blinks in text fields.
  64. virtual double caretBlinkInterval() const { return 0.5; }
  65. // Notification when the theme has changed
  66. virtual void themeChanged() { }
  67. // Methods used to adjust the RenderStyles of controls.
  68. // The font description result should have a zoomed font size.
  69. virtual FontDescription controlFont(ControlPart, const Font& font, float /*zoomFactor*/) const { return font.fontDescription(); }
  70. // The size here is in zoomed coordinates already. If a new size is returned, it also needs to be in zoomed coordinates.
  71. virtual LengthSize controlSize(ControlPart, const Font&, const LengthSize& zoomedSize, float /*zoomFactor*/) const { return zoomedSize; }
  72. // Returns the minimum size for a control in zoomed coordinates.
  73. virtual LengthSize minimumControlSize(ControlPart, const Font&, float /*zoomFactor*/) const { return LengthSize(Length(0, Fixed), Length(0, Fixed)); }
  74. // Allows the theme to modify the existing padding/border.
  75. virtual LengthBox controlPadding(ControlPart, const Font&, const LengthBox& zoomedBox, float zoomFactor) const;
  76. virtual LengthBox controlBorder(ControlPart, const Font&, const LengthBox& zoomedBox, float zoomFactor) const;
  77. // Whether or not whitespace: pre should be forced on always.
  78. virtual bool controlRequiresPreWhiteSpace(ControlPart) const { return false; }
  79. // Method for painting a control. The rect is in zoomed coordinates.
  80. virtual void paint(ControlPart, ControlStates, GraphicsContext*, const IntRect& /*zoomedRect*/, float /*zoomFactor*/, ScrollView*) const { }
  81. // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint,
  82. // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
  83. // The rect passed in is in zoomed coordinates, so the inflation should take that into account and make sure the inflation
  84. // amount is also scaled by the zoomFactor.
  85. virtual void inflateControlPaintRect(ControlPart, ControlStates, IntRect& /*zoomedRect*/, float /*zoomFactor*/) const { }
  86. // This method is called once, from RenderTheme::adjustDefaultStyleSheet(), to let each platform adjust
  87. // the default CSS rules in html.css.
  88. static String defaultStyleSheet();
  89. private:
  90. mutable Color m_activeSelectionColor;
  91. mutable Color m_inactiveSelectionColor;
  92. };
  93. // Function to obtain the theme. This is implemented in the platform-specific subclasses.
  94. Theme* platformTheme();
  95. } // namespace WebCore
  96. #endif // Theme_h