15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2008 Apple Inc. All Rights Reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef ScrollbarTheme_h
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ScrollbarTheme_h
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
29a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/PlatformExport.h"
301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/IntRect.h"
311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/scroll/ScrollTypes.h"
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
355d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)class GraphicsContext;
365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class PlatformMouseEvent;
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class ScrollbarThemeClient;
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class ScrollView;
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
40a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class PLATFORM_EXPORT ScrollbarTheme {
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTF_MAKE_NONCOPYABLE(ScrollbarTheme); WTF_MAKE_FAST_ALLOCATED;
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ScrollbarTheme() { }
443c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual ~ScrollbarTheme() { }
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
463c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void updateEnabledState(ScrollbarThemeClient*) { }
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
483c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual bool paint(ScrollbarThemeClient*, GraphicsContext*, const IntRect& damageRect);
493c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual ScrollbarPart hitTest(ScrollbarThemeClient*, const IntPoint&);
5002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar) { return 0; }
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual ScrollbarButtonsPlacement buttonsPlacement() const { return ScrollbarButtonsSingle; }
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual bool supportsControlTints() const { return false; }
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual bool usesOverlayScrollbars() const { return false; }
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual void updateScrollbarOverlayStyle(ScrollbarThemeClient*) { }
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual bool invalidateOnMouseEnterExit() { return false; }
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void invalidateParts(ScrollbarThemeClient* scrollbar, ScrollbarControlPartMask mask)
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (mask & BackButtonStartPart)
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            invalidatePart(scrollbar, BackButtonStartPart);
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (mask & ForwardButtonStartPart)
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            invalidatePart(scrollbar, ForwardButtonStartPart);
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (mask & BackTrackPart)
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            invalidatePart(scrollbar, BackTrackPart);
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (mask & ThumbPart)
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            invalidatePart(scrollbar, ThumbPart);
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (mask & ForwardTrackPart)
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            invalidatePart(scrollbar, ForwardTrackPart);
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (mask & BackButtonEndPart)
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            invalidatePart(scrollbar, BackButtonEndPart);
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (mask & ForwardButtonEndPart)
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            invalidatePart(scrollbar, ForwardButtonEndPart);
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
793c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void invalidatePart(ScrollbarThemeClient*, ScrollbarPart);
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual void paintTickmarks(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { }
8419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    virtual void paintOverhangBackground(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&);
8519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    virtual void paintOverhangShadows(GraphicsContext*, const IntSize&, const IntRect&, const IntRect&, const IntRect&) { }
86c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)
87d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    virtual bool shouldCenterOnThumb(ScrollbarThemeClient*, const PlatformMouseEvent&);
88d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    virtual bool shouldSnapBackToDragOrigin(ScrollbarThemeClient*, const PlatformMouseEvent&);
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual bool shouldDragDocumentInsteadOfThumb(ScrollbarThemeClient*, const PlatformMouseEvent&) { return false; }
903c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
913c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    // The position of the thumb relative to the track.
923c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual int thumbPosition(ScrollbarThemeClient*);
933c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    // The length of the thumb along the axis of the scrollbar.
943c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual int thumbLength(ScrollbarThemeClient*);
953c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    // The position of the track relative to the scrollbar.
963c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual int trackPosition(ScrollbarThemeClient*);
973c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    // The length of the track along the axis of the scrollbar.
983c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual int trackLength(ScrollbarThemeClient*);
993c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1003c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual bool hasButtons(ScrollbarThemeClient*) = 0;
1013c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual bool hasThumb(ScrollbarThemeClient*) = 0;
1023c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1033c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual IntRect backButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false) = 0;
1043c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false) = 0;
1053c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false) = 0;
1063c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual IntRect thumbRect(ScrollbarThemeClient*);
1079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)    virtual int thumbThickness(ScrollbarThemeClient*);
1083c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1093c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual int minimumThumbLength(ScrollbarThemeClient*);
1103c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1113c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void splitTrack(ScrollbarThemeClient*, const IntRect& track, IntRect& startTrack, IntRect& thumb, IntRect& endTrack);
1123c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1133c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*) { }
1143c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { }
1153c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void paintTrackPiece(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart) { }
1163c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void paintButton(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart) { }
1173c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual void paintThumb(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { }
1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual int maxOverlapBetweenPages() { return std::numeric_limits<int>::max(); }
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual double initialAutoscrollTimerDelay() { return 0.25; }
1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual double autoscrollTimerDelay() { return 0.05; }
1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1243c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    virtual IntRect constrainTrackRectToTrackPieces(ScrollbarThemeClient*, const IntRect& rect) { return rect; }
1253c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual void registerScrollbar(ScrollbarThemeClient*) { }
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual void unregisterScrollbar(ScrollbarThemeClient*) { }
1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual bool isMockTheme() const { return false; }
1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    static ScrollbarTheme* theme();
1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static void setMockScrollbarsEnabled(bool flag);
1341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static bool mockScrollbarsEnabled();
1351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    static ScrollbarTheme* nativeTheme(); // Must be implemented to return the correct theme subclass.
1381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static bool gMockScrollbarsEnabled;
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
143