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 26 #ifndef ScrollbarTheme_h 27 #define ScrollbarTheme_h 28 29 #include "core/platform/ScrollTypes.h" 30 #include "core/platform/graphics/GraphicsContext.h" 31 #include "core/platform/graphics/IntRect.h" 32 33 namespace WebCore { 34 35 class PlatformMouseEvent; 36 class ScrollbarThemeClient; 37 class ScrollView; 38 39 #if ENABLE(RUBBER_BANDING) 40 class GraphicsLayer; 41 #endif 42 43 class ScrollbarTheme { 44 WTF_MAKE_NONCOPYABLE(ScrollbarTheme); WTF_MAKE_FAST_ALLOCATED; 45 public: 46 ScrollbarTheme() { } 47 virtual ~ScrollbarTheme() { } 48 49 virtual void updateEnabledState(ScrollbarThemeClient*) { } 50 51 virtual bool paint(ScrollbarThemeClient*, GraphicsContext*, const IntRect& damageRect); 52 virtual ScrollbarPart hitTest(ScrollbarThemeClient*, const IntPoint&); 53 54 virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar) { return 0; } 55 56 virtual ScrollbarButtonsPlacement buttonsPlacement() const { return ScrollbarButtonsSingle; } 57 58 virtual bool supportsControlTints() const { return false; } 59 virtual bool usesOverlayScrollbars() const { return false; } 60 virtual void updateScrollbarOverlayStyle(ScrollbarThemeClient*) { } 61 62 virtual void themeChanged() { } 63 64 virtual bool invalidateOnMouseEnterExit() { return false; } 65 66 void invalidateParts(ScrollbarThemeClient* scrollbar, ScrollbarControlPartMask mask) 67 { 68 if (mask & BackButtonStartPart) 69 invalidatePart(scrollbar, BackButtonStartPart); 70 if (mask & ForwardButtonStartPart) 71 invalidatePart(scrollbar, ForwardButtonStartPart); 72 if (mask & BackTrackPart) 73 invalidatePart(scrollbar, BackTrackPart); 74 if (mask & ThumbPart) 75 invalidatePart(scrollbar, ThumbPart); 76 if (mask & ForwardTrackPart) 77 invalidatePart(scrollbar, ForwardTrackPart); 78 if (mask & BackButtonEndPart) 79 invalidatePart(scrollbar, BackButtonEndPart); 80 if (mask & ForwardButtonEndPart) 81 invalidatePart(scrollbar, ForwardButtonEndPart); 82 } 83 84 virtual void invalidatePart(ScrollbarThemeClient*, ScrollbarPart); 85 86 virtual void paintScrollCorner(ScrollView*, GraphicsContext*, const IntRect& cornerRect); 87 88 virtual void paintTickmarks(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { } 89 virtual void paintOverhangAreas(ScrollView*, GraphicsContext*, const IntRect&, const IntRect&, const IntRect&); 90 91 virtual bool shouldCenterOnThumb(ScrollbarThemeClient*, const PlatformMouseEvent&) { return false; } 92 virtual bool shouldSnapBackToDragOrigin(ScrollbarThemeClient*, const PlatformMouseEvent&) { return false; } 93 virtual bool shouldDragDocumentInsteadOfThumb(ScrollbarThemeClient*, const PlatformMouseEvent&) { return false; } 94 95 // The position of the thumb relative to the track. 96 virtual int thumbPosition(ScrollbarThemeClient*); 97 // The length of the thumb along the axis of the scrollbar. 98 virtual int thumbLength(ScrollbarThemeClient*); 99 // The position of the track relative to the scrollbar. 100 virtual int trackPosition(ScrollbarThemeClient*); 101 // The length of the track along the axis of the scrollbar. 102 virtual int trackLength(ScrollbarThemeClient*); 103 104 virtual bool hasButtons(ScrollbarThemeClient*) = 0; 105 virtual bool hasThumb(ScrollbarThemeClient*) = 0; 106 107 virtual IntRect backButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false) = 0; 108 virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false) = 0; 109 virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false) = 0; 110 virtual IntRect thumbRect(ScrollbarThemeClient*); 111 112 virtual int minimumThumbLength(ScrollbarThemeClient*); 113 114 virtual void splitTrack(ScrollbarThemeClient*, const IntRect& track, IntRect& startTrack, IntRect& thumb, IntRect& endTrack); 115 116 virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*) { } 117 virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { } 118 virtual void paintTrackPiece(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart) { } 119 virtual void paintButton(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart) { } 120 virtual void paintThumb(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { } 121 122 virtual int maxOverlapBetweenPages() { return std::numeric_limits<int>::max(); } 123 124 virtual double initialAutoscrollTimerDelay() { return 0.25; } 125 virtual double autoscrollTimerDelay() { return 0.05; } 126 127 virtual IntRect constrainTrackRectToTrackPieces(ScrollbarThemeClient*, const IntRect& rect) { return rect; } 128 129 virtual void registerScrollbar(ScrollbarThemeClient*) { } 130 virtual void unregisterScrollbar(ScrollbarThemeClient*) { } 131 132 virtual bool isMockTheme() const { return false; } 133 134 static ScrollbarTheme* theme(); 135 136 private: 137 static ScrollbarTheme* nativeTheme(); // Must be implemented to return the correct theme subclass. 138 }; 139 140 } 141 #endif 142