Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2008, 2011 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 ScrollableArea_h
     27 #define ScrollableArea_h
     28 
     29 #include "IntRect.h"
     30 #include "Scrollbar.h"
     31 #include <wtf/Vector.h>
     32 
     33 namespace WebCore {
     34 
     35 class FloatPoint;
     36 class GraphicsContext;
     37 class PlatformGestureEvent;
     38 class PlatformWheelEvent;
     39 class ScrollAnimator;
     40 #if USE(ACCELERATED_COMPOSITING)
     41 class GraphicsLayer;
     42 #endif
     43 
     44 class ScrollableArea {
     45 public:
     46     ScrollableArea();
     47     virtual ~ScrollableArea();
     48 
     49     bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
     50     void scrollToOffsetWithoutAnimation(const FloatPoint&);
     51     void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset);
     52     void scrollToXOffsetWithoutAnimation(float x);
     53     void scrollToYOffsetWithoutAnimation(float x);
     54 
     55     void handleWheelEvent(PlatformWheelEvent&);
     56 #if ENABLE(GESTURE_EVENTS)
     57     void handleGestureEvent(const PlatformGestureEvent&);
     58 #endif
     59 
     60     // Functions for controlling if you can scroll past the end of the document.
     61     bool constrainsScrollingToContentEdge() const { return m_constrainsScrollingToContentEdge; }
     62     void setConstrainsScrollingToContentEdge(bool constrainsScrollingToContentEdge) { m_constrainsScrollingToContentEdge = constrainsScrollingToContentEdge; }
     63 
     64     void setVerticalScrollElasticity(ScrollElasticity scrollElasticity) { m_verticalScrollElasticity = scrollElasticity; }
     65     ScrollElasticity verticalScrollElasticity() const { return m_verticalScrollElasticity; }
     66 
     67     void setHorizontalScrollElasticity(ScrollElasticity scrollElasticity) { m_horizontalScrollElasticity = scrollElasticity; }
     68     ScrollElasticity horizontalScrollElasticity() const { return m_horizontalScrollElasticity; }
     69 
     70     bool inLiveResize() const { return m_inLiveResize; }
     71     void willStartLiveResize();
     72     void willEndLiveResize();
     73 
     74     void didAddVerticalScrollbar(Scrollbar*);
     75     void willRemoveVerticalScrollbar(Scrollbar*);
     76     void didAddHorizontalScrollbar(Scrollbar*);
     77     void willRemoveHorizontalScrollbar(Scrollbar*);
     78 
     79     bool hasOverlayScrollbars() const;
     80 
     81     ScrollAnimator* scrollAnimator() const { return m_scrollAnimator.get(); }
     82     const IntPoint& scrollOrigin() const { return m_scrollOrigin; }
     83 
     84     virtual bool isActive() const = 0;
     85     virtual int scrollSize(ScrollbarOrientation) const = 0;
     86     virtual int scrollPosition(Scrollbar*) const = 0;
     87     void invalidateScrollbar(Scrollbar*, const IntRect&);
     88     virtual bool isScrollCornerVisible() const = 0;
     89     virtual IntRect scrollCornerRect() const = 0;
     90     void invalidateScrollCorner();
     91     virtual void getTickmarks(Vector<IntRect>&) const { }
     92 
     93     // This function should be overriden by subclasses to perform the actual
     94     // scroll of the content.
     95     virtual void setScrollOffset(const IntPoint&) = 0;
     96 
     97     // Convert points and rects between the scrollbar and its containing view.
     98     // The client needs to implement these in order to be aware of layout effects
     99     // like CSS transforms.
    100     virtual IntRect convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntRect& scrollbarRect) const
    101     {
    102         return scrollbar->Widget::convertToContainingView(scrollbarRect);
    103     }
    104     virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntRect& parentRect) const
    105     {
    106         return scrollbar->Widget::convertFromContainingView(parentRect);
    107     }
    108     virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntPoint& scrollbarPoint) const
    109     {
    110         return scrollbar->Widget::convertToContainingView(scrollbarPoint);
    111     }
    112     virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const
    113     {
    114         return scrollbar->Widget::convertFromContainingView(parentPoint);
    115     }
    116 
    117     virtual Scrollbar* horizontalScrollbar() const { return 0; }
    118     virtual Scrollbar* verticalScrollbar() const { return 0; }
    119 
    120     virtual IntPoint scrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
    121     virtual IntPoint minimumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
    122     virtual IntPoint maximumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
    123     virtual IntRect visibleContentRect(bool = false) const { ASSERT_NOT_REACHED(); return IntRect(); }
    124     virtual int visibleHeight() const { ASSERT_NOT_REACHED(); return 0; }
    125     virtual int visibleWidth() const { ASSERT_NOT_REACHED(); return 0; }
    126     virtual IntSize contentsSize() const { ASSERT_NOT_REACHED(); return IntSize(); }
    127     virtual IntSize overhangAmount() const { ASSERT_NOT_REACHED(); return IntSize(); }
    128     virtual IntPoint currentMousePosition() const { return IntPoint(); }
    129     virtual void didCompleteRubberBand(const IntSize&) const { ASSERT_NOT_REACHED(); }
    130     virtual bool shouldSuspendScrollAnimations() const { return true; }
    131     virtual void scrollbarStyleChanged() { }
    132 
    133     virtual void disconnectFromPage() { }
    134 
    135 private:
    136     // NOTE: Only called from the ScrollAnimator.
    137     friend class ScrollAnimator;
    138     void setScrollOffsetFromAnimation(const IntPoint&);
    139 
    140     OwnPtr<ScrollAnimator> m_scrollAnimator;
    141     bool m_constrainsScrollingToContentEdge;
    142 
    143     bool m_inLiveResize;
    144 
    145     ScrollElasticity m_verticalScrollElasticity;
    146     ScrollElasticity m_horizontalScrollElasticity;
    147 
    148 protected:
    149     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0;
    150     virtual void invalidateScrollCornerRect(const IntRect&) = 0;
    151 
    152 #if USE(ACCELERATED_COMPOSITING)
    153     virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; }
    154     virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; }
    155     virtual GraphicsLayer* layerForScrollCorner() const { return 0; }
    156 #endif
    157 
    158     // There are 8 possible combinations of writing mode and direction. Scroll origin will be non-zero in the x or y axis
    159     // if there is any reversed direction or writing-mode. The combinations are:
    160     // writing-mode / direction     scrollOrigin.x() set    scrollOrigin.y() set
    161     // horizontal-tb / ltr          NO                      NO
    162     // horizontal-tb / rtl          YES                     NO
    163     // horizontal-bt / ltr          NO                      YES
    164     // horizontal-bt / rtl          YES                     YES
    165     // vertical-lr / ltr            NO                      NO
    166     // vertical-lr / rtl            NO                      YES
    167     // vertical-rl / ltr            YES                     NO
    168     // vertical-rl / rtl            YES                     YES
    169     IntPoint m_scrollOrigin;
    170 };
    171 
    172 } // namespace WebCore
    173 
    174 #endif // ScrollableArea_h
    175