[email protected] | 3c4fc69 | 2012-05-04 17:02:46 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | ac3e9f2 | 2011-11-27 18:38:51 | [diff] [blame] | 5 | #ifndef UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_ |
| 6 | #define UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 8 | #include "base/basictypes.h" |
| 9 | #include "base/compiler_specific.h" |
[email protected] | 5025f86 | 2011-11-30 23:35:20 | [diff] [blame] | 10 | #include "ui/views/view.h" |
[email protected] | 45647af | 2011-12-01 16:09:33 | [diff] [blame] | 11 | #include "ui/views/views_export.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 13 | namespace views { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 | ///////////////////////////////////////////////////////////////////////////// |
[email protected] | 5036f18 | 2011-08-05 20:58:29 | [diff] [blame] | 25 | class VIEWS_EXPORT ScrollBarController { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 | ///////////////////////////////////////////////////////////////////////////// |
[email protected] | 5036f18 | 2011-08-05 20:58:29 | [diff] [blame] | 58 | class VIEWS_EXPORT ScrollBar : public View { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | public: |
| 60 | virtual ~ScrollBar(); |
| 61 | |
[email protected] | 70d38b0 | 2010-04-09 04:00:49 | [diff] [blame] | 62 | // Overridden from View: |
mostynb | 3b3d52b | 2014-10-09 10:54:27 | [diff] [blame^] | 63 | virtual void GetAccessibleState(ui::AXViewState* state) override; |
[email protected] | 70d38b0 | 2010-04-09 04:00:49 | [diff] [blame] | 64 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 65 | // Returns whether this scrollbar is horizontal. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | bool IsHorizontal() const; |
| 67 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 68 | void set_controller(ScrollBarController* controller) { |
| 69 | controller_ = controller; |
| 70 | } |
| 71 | ScrollBarController* controller() const { return controller_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 77 | // Returns the max and min positions. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 | |
[email protected] | 474d6fd0 | 2013-06-11 14:46:59 | [diff] [blame] | 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 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 |
[email protected] | 964e09d5 | 2012-05-24 15:17:39 | [diff] [blame] | 99 | // ImageScrollBar. |
[email protected] | 3c4fc69 | 2012-05-04 17:02:46 | [diff] [blame] | 100 | explicit ScrollBar(bool is_horiz); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 101 | |
| 102 | private: |
| 103 | const bool is_horiz_; |
| 104 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | ScrollBarController* controller_; |
| 106 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 107 | int max_pos_; |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 108 | |
| 109 | DISALLOW_COPY_AND_ASSIGN(ScrollBar); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 112 | } // namespace views |
| 113 | |
[email protected] | ac3e9f2 | 2011-11-27 18:38:51 | [diff] [blame] | 114 | #endif // UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_ |