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