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