ScrollbarTheme.h 8.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (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 26 27 28
 */

#ifndef ScrollbarTheme_h
#define ScrollbarTheme_h

29
#include "platform/PlatformExport.h"
30
#include "platform/geometry/IntRect.h"
31
#include "platform/graphics/paint/DisplayItem.h"
32
#include "platform/scroll/ScrollTypes.h"
33
#include "platform/scroll/Scrollbar.h"
34
#include "public/platform/WebScrollbarButtonsPlacement.h"
35

36
namespace blink {
37

38
class CullRect;
39
class GraphicsContext;
40
class WebMouseEvent;
41

42
class PLATFORM_EXPORT ScrollbarTheme {
Blink Reformat's avatar
Blink Reformat committed
43 44 45 46 47 48 49 50 51 52
  WTF_MAKE_NONCOPYABLE(ScrollbarTheme);
  USING_FAST_MALLOC(ScrollbarTheme);

 public:
  ScrollbarTheme() {}
  virtual ~ScrollbarTheme() {}

  // If true, then scrollbars with this theme will be painted every time
  // Scrollbar::setNeedsPaintInvalidation is called. If false, then only parts
  // which are explicitly invalidated will be repainted.
Blink Reformat's avatar
Blink Reformat committed
53
  virtual bool ShouldRepaintAllPartsOnInvalidation() const { return true; }
Blink Reformat's avatar
Blink Reformat committed
54

Blink Reformat's avatar
Blink Reformat committed
55
  virtual void UpdateEnabledState(const ScrollbarThemeClient&) {}
Blink Reformat's avatar
Blink Reformat committed
56

Blink Reformat's avatar
Blink Reformat committed
57
  virtual bool Paint(const Scrollbar&, GraphicsContext&, const CullRect&);
Blink Reformat's avatar
Blink Reformat committed
58

Blink Reformat's avatar
Blink Reformat committed
59
  virtual ScrollbarPart HitTest(const ScrollbarThemeClient&, const IntPoint&);
Blink Reformat's avatar
Blink Reformat committed
60

61
  // This returns a fixed value regardless of device-scale-factor.
62 63
  // This returns thickness when scrollbar is painted.  i.e. It's not 0 even in
  // overlay scrollbar mode.
64
  // See also Scrollbar::scrollbarThickness().
Blink Reformat's avatar
Blink Reformat committed
65
  virtual int ScrollbarThickness(ScrollbarControlSize = kRegularScrollbar) {
Blink Reformat's avatar
Blink Reformat committed
66 67
    return 0;
  }
Blink Reformat's avatar
Blink Reformat committed
68
  virtual int ScrollbarMargin() const { return 0; }
Blink Reformat's avatar
Blink Reformat committed
69

Blink Reformat's avatar
Blink Reformat committed
70 71
  virtual WebScrollbarButtonsPlacement ButtonsPlacement() const {
    return kWebScrollbarButtonsPlacementSingle;
Blink Reformat's avatar
Blink Reformat committed
72 73
  }

Blink Reformat's avatar
Blink Reformat committed
74 75 76
  virtual bool SupportsControlTints() const { return false; }
  virtual bool UsesOverlayScrollbars() const { return false; }
  virtual void UpdateScrollbarOverlayColorTheme(const ScrollbarThemeClient&) {}
Blink Reformat's avatar
Blink Reformat committed
77

78 79 80 81 82
  // If true, scrollbars that become invisible (i.e. overlay scrollbars that
  // fade out) should be marked as disabled. This option exists since Mac and
  // Aura overlays implement the fade out differently, with Mac painting code
  // fading out the scrollbars. Aura scrollbars require disabling the scrollbar
  // to prevent painting it.
Blink Reformat's avatar
Blink Reformat committed
83
  virtual bool ShouldDisableInvisibleScrollbars() const { return true; }
84

Blink Reformat's avatar
Blink Reformat committed
85 86
  virtual bool InvalidateOnMouseEnterExit() { return false; }
  virtual bool InvalidateOnWindowActiveChange() const { return false; }
Blink Reformat's avatar
Blink Reformat committed
87 88 89

  // Returns parts of the scrollbar which must be repainted following a change
  // in the thumb position, given scroll positions before and after.
Blink Reformat's avatar
Blink Reformat committed
90
  virtual ScrollbarPart InvalidateOnThumbPositionChange(
Blink Reformat's avatar
Blink Reformat committed
91
      const ScrollbarThemeClient&,
Blink Reformat's avatar
Blink Reformat committed
92 93 94
      float old_position,
      float new_position) const {
    return kAllParts;
Blink Reformat's avatar
Blink Reformat committed
95 96
  }

Blink Reformat's avatar
Blink Reformat committed
97
  virtual void PaintScrollCorner(GraphicsContext&,
Blink Reformat's avatar
Blink Reformat committed
98
                                 const DisplayItemClient&,
Blink Reformat's avatar
Blink Reformat committed
99 100
                                 const IntRect& corner_rect);
  virtual void PaintTickmarks(GraphicsContext&,
Blink Reformat's avatar
Blink Reformat committed
101
                              const Scrollbar&,
102
                              const IntRect&);
Blink Reformat's avatar
Blink Reformat committed
103

Blink Reformat's avatar
Blink Reformat committed
104
  virtual bool ShouldCenterOnThumb(const ScrollbarThemeClient&,
105
                                   const WebMouseEvent&);
Blink Reformat's avatar
Blink Reformat committed
106
  virtual bool ShouldSnapBackToDragOrigin(const ScrollbarThemeClient&,
107
                                          const WebMouseEvent&);
Blink Reformat's avatar
Blink Reformat committed
108
  virtual bool ShouldDragDocumentInsteadOfThumb(const ScrollbarThemeClient&,
109
                                                const WebMouseEvent&) {
Blink Reformat's avatar
Blink Reformat committed
110 111 112 113
    return false;
  }

  // The position of the thumb relative to the track.
Blink Reformat's avatar
Blink Reformat committed
114 115
  int ThumbPosition(const ScrollbarThemeClient& scrollbar) {
    return ThumbPosition(scrollbar, scrollbar.CurrentPos());
Blink Reformat's avatar
Blink Reformat committed
116
  }
Blink Reformat's avatar
Blink Reformat committed
117 118
  virtual double OverlayScrollbarFadeOutDelaySeconds() const;
  virtual double OverlayScrollbarFadeOutDurationSeconds() const;
119 120
  // The position the thumb would have, relative to the track, at the specified
  // scroll position.
Blink Reformat's avatar
Blink Reformat committed
121
  virtual int ThumbPosition(const ScrollbarThemeClient&, float scroll_position);
Blink Reformat's avatar
Blink Reformat committed
122
  // The length of the thumb along the axis of the scrollbar.
Blink Reformat's avatar
Blink Reformat committed
123
  virtual int ThumbLength(const ScrollbarThemeClient&);
Blink Reformat's avatar
Blink Reformat committed
124
  // The position of the track relative to the scrollbar.
Blink Reformat's avatar
Blink Reformat committed
125
  virtual int TrackPosition(const ScrollbarThemeClient&);
Blink Reformat's avatar
Blink Reformat committed
126
  // The length of the track along the axis of the scrollbar.
Blink Reformat's avatar
Blink Reformat committed
127
  virtual int TrackLength(const ScrollbarThemeClient&);
Blink Reformat's avatar
Blink Reformat committed
128
  // The opacity to be applied to the thumb.
Blink Reformat's avatar
Blink Reformat committed
129
  virtual float ThumbOpacity(const ScrollbarThemeClient&) const { return 1.0f; }
Blink Reformat's avatar
Blink Reformat committed
130

Blink Reformat's avatar
Blink Reformat committed
131 132
  virtual bool HasButtons(const ScrollbarThemeClient&) = 0;
  virtual bool HasThumb(const ScrollbarThemeClient&) = 0;
Blink Reformat's avatar
Blink Reformat committed
133

Blink Reformat's avatar
Blink Reformat committed
134
  virtual IntRect BackButtonRect(const ScrollbarThemeClient&,
Blink Reformat's avatar
Blink Reformat committed
135 136
                                 ScrollbarPart,
                                 bool painting = false) = 0;
Blink Reformat's avatar
Blink Reformat committed
137
  virtual IntRect ForwardButtonRect(const ScrollbarThemeClient&,
Blink Reformat's avatar
Blink Reformat committed
138 139
                                    ScrollbarPart,
                                    bool painting = false) = 0;
Blink Reformat's avatar
Blink Reformat committed
140
  virtual IntRect TrackRect(const ScrollbarThemeClient&,
Blink Reformat's avatar
Blink Reformat committed
141
                            bool painting = false) = 0;
Blink Reformat's avatar
Blink Reformat committed
142 143
  virtual IntRect ThumbRect(const ScrollbarThemeClient&);
  virtual int ThumbThickness(const ScrollbarThemeClient&);
Blink Reformat's avatar
Blink Reformat committed
144

Blink Reformat's avatar
Blink Reformat committed
145
  virtual int MinimumThumbLength(const ScrollbarThemeClient&) = 0;
Blink Reformat's avatar
Blink Reformat committed
146

Blink Reformat's avatar
Blink Reformat committed
147
  virtual void SplitTrack(const ScrollbarThemeClient&,
Blink Reformat's avatar
Blink Reformat committed
148
                          const IntRect& track,
Blink Reformat's avatar
Blink Reformat committed
149
                          IntRect& start_track,
Blink Reformat's avatar
Blink Reformat committed
150
                          IntRect& thumb,
Blink Reformat's avatar
Blink Reformat committed
151
                          IntRect& end_track);
Blink Reformat's avatar
Blink Reformat committed
152

Blink Reformat's avatar
Blink Reformat committed
153 154
  virtual void PaintScrollbarBackground(GraphicsContext&, const Scrollbar&) {}
  virtual void PaintTrackBackground(GraphicsContext&,
Blink Reformat's avatar
Blink Reformat committed
155 156
                                    const Scrollbar&,
                                    const IntRect&) {}
Blink Reformat's avatar
Blink Reformat committed
157
  virtual void PaintTrackPiece(GraphicsContext&,
Blink Reformat's avatar
Blink Reformat committed
158 159 160
                               const Scrollbar&,
                               const IntRect&,
                               ScrollbarPart) {}
Blink Reformat's avatar
Blink Reformat committed
161
  virtual void PaintButton(GraphicsContext&,
Blink Reformat's avatar
Blink Reformat committed
162 163 164
                           const Scrollbar&,
                           const IntRect&,
                           ScrollbarPart) {}
Blink Reformat's avatar
Blink Reformat committed
165
  virtual void PaintThumb(GraphicsContext&, const Scrollbar&, const IntRect&) {}
Blink Reformat's avatar
Blink Reformat committed
166

Blink Reformat's avatar
Blink Reformat committed
167
  virtual int MaxOverlapBetweenPages() {
Blink Reformat's avatar
Blink Reformat committed
168 169 170
    return std::numeric_limits<int>::max();
  }

Blink Reformat's avatar
Blink Reformat committed
171 172
  virtual double InitialAutoscrollTimerDelay() { return 0.25; }
  virtual double AutoscrollTimerDelay() { return 0.05; }
Blink Reformat's avatar
Blink Reformat committed
173

Blink Reformat's avatar
Blink Reformat committed
174
  virtual IntRect ConstrainTrackRectToTrackPieces(const ScrollbarThemeClient&,
Blink Reformat's avatar
Blink Reformat committed
175 176 177 178
                                                  const IntRect& rect) {
    return rect;
  }

Blink Reformat's avatar
Blink Reformat committed
179 180
  virtual void RegisterScrollbar(ScrollbarThemeClient&) {}
  virtual void UnregisterScrollbar(ScrollbarThemeClient&) {}
Blink Reformat's avatar
Blink Reformat committed
181

Blink Reformat's avatar
Blink Reformat committed
182
  virtual bool IsMockTheme() const { return false; }
Blink Reformat's avatar
Blink Reformat committed
183

Blink Reformat's avatar
Blink Reformat committed
184
  virtual bool UsesNinePatchThumbResource() const { return false; }
185 186 187 188 189

  // For a nine-patch scrollbar, this defines the painting canvas size which the
  // painting code will use to paint the scrollbar into. The actual scrollbar
  // dimensions will be ignored for purposes of painting since the resource can
  // be then resized without a repaint.
Blink Reformat's avatar
Blink Reformat committed
190
  virtual IntSize NinePatchThumbCanvasSize(const ScrollbarThemeClient&) const {
191 192 193 194 195 196
    NOTREACHED();
    return IntSize();
  }

  // For a nine-patch resource, the aperture defines the center patch that will
  // be stretched out.
Blink Reformat's avatar
Blink Reformat committed
197
  virtual IntRect NinePatchThumbAperture(const ScrollbarThemeClient&) const {
198 199 200 201
    NOTREACHED();
    return IntRect();
  }

Blink Reformat's avatar
Blink Reformat committed
202
  static ScrollbarTheme& GetTheme();
Blink Reformat's avatar
Blink Reformat committed
203

Blink Reformat's avatar
Blink Reformat committed
204 205
  static void SetMockScrollbarsEnabled(bool flag);
  static bool MockScrollbarsEnabled();
Blink Reformat's avatar
Blink Reformat committed
206 207

 protected:
Blink Reformat's avatar
Blink Reformat committed
208 209 210
  virtual int TickmarkBorderWidth() { return 0; }
  static DisplayItem::Type ButtonPartToDisplayItemType(ScrollbarPart);
  static DisplayItem::Type TrackPiecePartToDisplayItemType(ScrollbarPart);
Blink Reformat's avatar
Blink Reformat committed
211 212 213

 private:
  static ScrollbarTheme&
Blink Reformat's avatar
Blink Reformat committed
214 215
  NativeTheme();  // Must be implemented to return the correct theme subclass.
  static bool g_mock_scrollbars_enabled_;
216 217
};

Blink Reformat's avatar
Blink Reformat committed
218
}  // namespace blink
219
#endif