Home | History | Annotate | Download | only in scrollbar
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_
      6 #define UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "ui/views/view.h"
     11 #include "ui/views/views_export.h"
     12 
     13 namespace views {
     14 
     15 class ScrollBar;
     16 
     17 /////////////////////////////////////////////////////////////////////////////
     18 //
     19 // ScrollBarController
     20 //
     21 // ScrollBarController defines the method that should be implemented to
     22 // receive notification from a scrollbar
     23 //
     24 /////////////////////////////////////////////////////////////////////////////
     25 class VIEWS_EXPORT ScrollBarController {
     26  public:
     27   // Invoked by the scrollbar when the scrolling position changes
     28   // This method typically implements the actual scrolling.
     29   //
     30   // The provided position is expressed in pixels. It is the new X or Y
     31   // position which is in the GetMinPosition() / GetMaxPosition range.
     32   virtual void ScrollToPosition(ScrollBar* source, int position) = 0;
     33 
     34   // Returns the amount to scroll. The amount to scroll may be requested in
     35   // two different amounts. If is_page is true the 'page scroll' amount is
     36   // requested. The page scroll amount typically corresponds to the
     37   // visual size of the view. If is_page is false, the 'line scroll' amount
     38   // is being requested. The line scroll amount typically corresponds to the
     39   // size of one row/column.
     40   //
     41   // The return value should always be positive. A value <= 0 results in
     42   // scrolling by a fixed amount.
     43   virtual int GetScrollIncrement(ScrollBar* source,
     44                                  bool is_page,
     45                                  bool is_positive) = 0;
     46 };
     47 
     48 /////////////////////////////////////////////////////////////////////////////
     49 //
     50 // ScrollBar
     51 //
     52 // A View subclass to wrap to implement a ScrollBar. Our current windows
     53 // version simply wraps a native windows scrollbar.
     54 //
     55 // A scrollbar is either horizontal or vertical
     56 //
     57 /////////////////////////////////////////////////////////////////////////////
     58 class VIEWS_EXPORT ScrollBar : public View {
     59  public:
     60   virtual ~ScrollBar();
     61 
     62   // Overridden from View:
     63   virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
     64 
     65   // Returns whether this scrollbar is horizontal.
     66   bool IsHorizontal() const;
     67 
     68   void set_controller(ScrollBarController* controller) {
     69      controller_ = controller;
     70   }
     71   ScrollBarController* controller() const { return controller_; }
     72 
     73   // Update the scrollbar appearance given a viewport size, content size and
     74   // current position
     75   virtual void Update(int viewport_size, int content_size, int current_pos);
     76 
     77   // Returns the max and min positions.
     78   int GetMaxPosition() const;
     79   int GetMinPosition() const;
     80 
     81   // Returns the position of the scrollbar.
     82   virtual int GetPosition() const = 0;
     83 
     84   // Get the width or height of this scrollbar, for use in layout calculations.
     85   // For a vertical scrollbar, this is the width of the scrollbar, likewise it
     86   // is the height for a horizontal scrollbar.
     87   virtual int GetLayoutSize() const = 0;
     88 
     89   // Get the width or height for this scrollbar which overlaps with the content.
     90   // Default is 0.
     91   virtual int GetContentOverlapSize() const;
     92 
     93   virtual void OnMouseEnteredScrollView(const ui::MouseEvent& event);
     94   virtual void OnMouseExitedScrollView(const ui::MouseEvent& event);
     95 
     96  protected:
     97   // Create new scrollbar, either horizontal or vertical. These are protected
     98   // since you need to be creating either a NativeScrollBar or a
     99   // ImageScrollBar.
    100   explicit ScrollBar(bool is_horiz);
    101 
    102  private:
    103   const bool is_horiz_;
    104 
    105   ScrollBarController* controller_;
    106 
    107   int max_pos_;
    108 
    109   DISALLOW_COPY_AND_ASSIGN(ScrollBar);
    110 };
    111 
    112 }  // namespace views
    113 
    114 #endif  // UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_
    115