Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2004, 2006 Apple Computer, 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 COMPUTER, 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 COMPUTER, 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 Scrollbar_h
     27 #define Scrollbar_h
     28 
     29 #include "core/platform/ScrollTypes.h"
     30 #include "core/platform/ScrollbarThemeClient.h"
     31 #include "core/platform/Timer.h"
     32 #include "core/platform/Widget.h"
     33 #include "wtf/MathExtras.h"
     34 #include "wtf/PassRefPtr.h"
     35 
     36 namespace WebCore {
     37 
     38 class GraphicsContext;
     39 class IntRect;
     40 class PlatformGestureEvent;
     41 class PlatformMouseEvent;
     42 class ScrollableArea;
     43 class ScrollbarTheme;
     44 
     45 class Scrollbar : public Widget,
     46                   public ScrollbarThemeClient {
     47 
     48 public:
     49     // Must be implemented by platforms that can't simply use the Scrollbar base class.  Right now the only platform that is not using the base class is GTK.
     50     static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollableArea*, ScrollbarOrientation orientation, ScrollbarControlSize size);
     51 
     52     virtual ~Scrollbar();
     53 
     54     // ScrollbarThemeClient implementation.
     55     virtual int x() const { return Widget::x(); }
     56     virtual int y() const { return Widget::y(); }
     57     virtual int width() const { return Widget::width(); }
     58     virtual int height() const { return Widget::height(); }
     59     virtual IntSize size() const { return Widget::size(); }
     60     virtual IntPoint location() const { return Widget::location(); }
     61 
     62     virtual ScrollView* parent() const { return Widget::parent(); }
     63     virtual ScrollView* root() const { return Widget::root(); }
     64 
     65     virtual void setFrameRect(const IntRect&);
     66     virtual IntRect frameRect() const { return Widget::frameRect(); }
     67 
     68     virtual void invalidate() { Widget::invalidate(); }
     69     virtual void invalidateRect(const IntRect&);
     70 
     71     virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const;
     72     virtual void getTickmarks(Vector<IntRect>&) const;
     73     virtual bool isScrollableAreaActive() const;
     74     virtual bool isScrollViewScrollbar() const;
     75 
     76     virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) { return Widget::convertFromContainingWindow(windowPoint); }
     77 
     78     virtual bool isCustomScrollbar() const { return false; }
     79     virtual ScrollbarOrientation orientation() const { return m_orientation; }
     80 
     81     virtual int value() const { return lroundf(m_currentPos); }
     82     virtual float currentPos() const { return m_currentPos; }
     83     virtual int visibleSize() const { return m_visibleSize; }
     84     virtual int totalSize() const { return m_totalSize; }
     85     virtual int maximum() const { return m_totalSize - m_visibleSize; }
     86     virtual ScrollbarControlSize controlSize() const { return m_controlSize; }
     87 
     88     virtual ScrollbarPart pressedPart() const { return m_pressedPart; }
     89     virtual ScrollbarPart hoveredPart() const { return m_hoveredPart; }
     90 
     91     virtual void styleChanged() { }
     92 
     93     virtual bool enabled() const { return m_enabled; }
     94     virtual void setEnabled(bool);
     95 
     96     // Called by the ScrollableArea when the scroll offset changes.
     97     void offsetDidChange();
     98 
     99     void disconnectFromScrollableArea() { m_scrollableArea = 0; }
    100     ScrollableArea* scrollableArea() const { return m_scrollableArea; }
    101 
    102     int pressedPos() const { return m_pressedPos; }
    103 
    104     virtual void setHoveredPart(ScrollbarPart);
    105     virtual void setPressedPart(ScrollbarPart);
    106 
    107     void setProportion(int visibleSize, int totalSize);
    108     void setPressedPos(int p) { m_pressedPos = p; }
    109 
    110     virtual void paint(GraphicsContext*, const IntRect& damageRect);
    111 
    112     virtual bool isOverlayScrollbar() const;
    113     bool shouldParticipateInHitTesting();
    114 
    115     bool isWindowActive() const;
    116 
    117     bool gestureEvent(const PlatformGestureEvent&);
    118 
    119     // These methods are used for platform scrollbars to give :hover feedback.  They will not get called
    120     // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start
    121     // grabbing all events in that case anyway.
    122     void mouseMoved(const PlatformMouseEvent&);
    123     void mouseEntered();
    124     void mouseExited();
    125 
    126     // Used by some platform scrollbars to know when they've been released from capture.
    127     void mouseUp(const PlatformMouseEvent&);
    128     void mouseDown(const PlatformMouseEvent&);
    129 
    130     ScrollbarTheme* theme() const { return m_theme; }
    131 
    132     virtual void setParent(ScrollView*);
    133 
    134     bool suppressInvalidation() const { return m_suppressInvalidation; }
    135     void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
    136 
    137     virtual IntRect convertToContainingView(const IntRect&) const;
    138     virtual IntRect convertFromContainingView(const IntRect&) const;
    139 
    140     virtual IntPoint convertToContainingView(const IntPoint&) const;
    141     virtual IntPoint convertFromContainingView(const IntPoint&) const;
    142 
    143     void moveThumb(int pos, bool draggingDocument = false);
    144 
    145     virtual bool isAlphaLocked() const { return m_isAlphaLocked; }
    146     virtual void setIsAlphaLocked(bool flag) { m_isAlphaLocked = flag; }
    147 
    148 protected:
    149     Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
    150 
    151     void updateThumb();
    152     virtual void updateThumbPosition();
    153     virtual void updateThumbProportion();
    154 
    155     void autoscrollTimerFired(Timer<Scrollbar>*);
    156     void startTimerIfNeeded(double delay);
    157     void stopTimerIfNeeded();
    158     void autoscrollPressedPart(double delay);
    159     ScrollDirection pressedPartScrollDirection();
    160     ScrollGranularity pressedPartScrollGranularity();
    161 
    162     ScrollableArea* m_scrollableArea;
    163     ScrollbarOrientation m_orientation;
    164     ScrollbarControlSize m_controlSize;
    165     ScrollbarTheme* m_theme;
    166 
    167     int m_visibleSize;
    168     int m_totalSize;
    169     float m_currentPos;
    170     float m_dragOrigin;
    171 
    172     ScrollbarPart m_hoveredPart;
    173     ScrollbarPart m_pressedPart;
    174     int m_pressedPos;
    175     float m_scrollPos;
    176     bool m_draggingDocument;
    177     int m_documentDragPos;
    178 
    179     bool m_enabled;
    180 
    181     Timer<Scrollbar> m_scrollTimer;
    182     bool m_overlapsResizer;
    183 
    184     bool m_suppressInvalidation;
    185 
    186     bool m_isAlphaLocked;
    187 
    188 private:
    189     virtual bool isScrollbar() const { return true; }
    190     virtual AXObjectCache* existingAXObjectCache() const;
    191 
    192     float scrollableAreaCurrentPos() const;
    193 };
    194 
    195 } // namespace WebCore
    196 
    197 #endif // Scrollbar_h
    198