[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_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 9 | #include "base/basictypes.h" |
| 10 | #include "base/compiler_specific.h" |
[email protected] | 5025f86 | 2011-11-30 23:35:20 | [diff] [blame] | 11 | #include "ui/views/view.h" |
[email protected] | 45647af | 2011-12-01 16:09:33 | [diff] [blame] | 12 | #include "ui/views/views_export.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 14 | namespace views { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | |
| 16 | class ScrollBar; |
| 17 | |
| 18 | ///////////////////////////////////////////////////////////////////////////// |
| 19 | // |
| 20 | // ScrollBarController |
| 21 | // |
| 22 | // ScrollBarController defines the method that should be implemented to |
| 23 | // receive notification from a scrollbar |
| 24 | // |
| 25 | ///////////////////////////////////////////////////////////////////////////// |
[email protected] | 5036f18 | 2011-08-05 20:58:29 | [diff] [blame] | 26 | class VIEWS_EXPORT ScrollBarController { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | public: |
| 28 | |
| 29 | // Invoked by the scrollbar when the scrolling position changes |
| 30 | // This method typically implements the actual scrolling. |
| 31 | // |
| 32 | // The provided position is expressed in pixels. It is the new X or Y |
| 33 | // position which is in the GetMinPosition() / GetMaxPosition range. |
| 34 | virtual void ScrollToPosition(ScrollBar* source, int position) = 0; |
| 35 | |
| 36 | // Returns the amount to scroll. The amount to scroll may be requested in |
| 37 | // two different amounts. If is_page is true the 'page scroll' amount is |
| 38 | // requested. The page scroll amount typically corresponds to the |
| 39 | // visual size of the view. If is_page is false, the 'line scroll' amount |
| 40 | // is being requested. The line scroll amount typically corresponds to the |
| 41 | // size of one row/column. |
| 42 | // |
| 43 | // The return value should always be positive. A value <= 0 results in |
| 44 | // scrolling by a fixed amount. |
| 45 | virtual int GetScrollIncrement(ScrollBar* source, |
| 46 | bool is_page, |
| 47 | bool is_positive) = 0; |
| 48 | }; |
| 49 | |
| 50 | ///////////////////////////////////////////////////////////////////////////// |
| 51 | // |
| 52 | // ScrollBar |
| 53 | // |
| 54 | // A View subclass to wrap to implement a ScrollBar. Our current windows |
| 55 | // version simply wraps a native windows scrollbar. |
| 56 | // |
| 57 | // A scrollbar is either horizontal or vertical |
| 58 | // |
| 59 | ///////////////////////////////////////////////////////////////////////////// |
[email protected] | 5036f18 | 2011-08-05 20:58:29 | [diff] [blame] | 60 | class VIEWS_EXPORT ScrollBar : public View { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | public: |
| 62 | virtual ~ScrollBar(); |
| 63 | |
[email protected] | 70d38b0 | 2010-04-09 04:00:49 | [diff] [blame] | 64 | // Overridden from View: |
[email protected] | 79e549f | 2011-03-14 06:56:33 | [diff] [blame] | 65 | virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
[email protected] | 70d38b0 | 2010-04-09 04:00:49 | [diff] [blame] | 66 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 67 | // Returns whether this scrollbar is horizontal. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | bool IsHorizontal() const; |
| 69 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 70 | void set_controller(ScrollBarController* controller) { |
| 71 | controller_ = controller; |
| 72 | } |
| 73 | ScrollBarController* controller() const { return controller_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 74 | |
| 75 | // Update the scrollbar appearance given a viewport size, content size and |
| 76 | // current position |
| 77 | virtual void Update(int viewport_size, int content_size, int current_pos); |
| 78 | |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 79 | // Returns the max and min positions. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | int GetMaxPosition() const; |
| 81 | int GetMinPosition() const; |
| 82 | |
| 83 | // Returns the position of the scrollbar. |
| 84 | virtual int GetPosition() const = 0; |
| 85 | |
| 86 | // Get the width or height of this scrollbar, for use in layout calculations. |
| 87 | // For a vertical scrollbar, this is the width of the scrollbar, likewise it |
| 88 | // is the height for a horizontal scrollbar. |
| 89 | virtual int GetLayoutSize() const = 0; |
| 90 | |
| 91 | protected: |
| 92 | // Create new scrollbar, either horizontal or vertical. These are protected |
| 93 | // since you need to be creating either a NativeScrollBar or a |
| 94 | // BitmapScrollBar. |
[email protected] | 3c4fc69 | 2012-05-04 17:02:46 | [diff] [blame^] | 95 | explicit ScrollBar(bool is_horiz); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | |
| 97 | private: |
| 98 | const bool is_horiz_; |
| 99 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | ScrollBarController* controller_; |
| 101 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | int max_pos_; |
[email protected] | f96721b | 2011-09-23 14:51:45 | [diff] [blame] | 103 | |
| 104 | DISALLOW_COPY_AND_ASSIGN(ScrollBar); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | }; |
| 106 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 107 | } // namespace views |
| 108 | |
[email protected] | ac3e9f2 | 2011-11-27 18:38:51 | [diff] [blame] | 109 | #endif // UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_ |