blob: b34f4ede0b67796362c70e6779fabbce7ff9e578 [file] [log] [blame]
[email protected]3c4fc692012-05-04 17:02:461// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]ac3e9f22011-11-27 18:38:515#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_
6#define UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
[email protected]f96721b2011-09-23 14:51:459#include "base/basictypes.h"
10#include "base/compiler_specific.h"
[email protected]5025f862011-11-30 23:35:2011#include "ui/views/view.h"
[email protected]45647af2011-12-01 16:09:3312#include "ui/views/views_export.h"
initial.commit09911bf2008-07-26 23:55:2913
[email protected]c2dacc92008-10-16 23:51:3814namespace views {
initial.commit09911bf2008-07-26 23:55:2915
16class 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]5036f182011-08-05 20:58:2926class VIEWS_EXPORT ScrollBarController {
initial.commit09911bf2008-07-26 23:55:2927 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]5036f182011-08-05 20:58:2960class VIEWS_EXPORT ScrollBar : public View {
initial.commit09911bf2008-07-26 23:55:2961 public:
62 virtual ~ScrollBar();
63
[email protected]70d38b02010-04-09 04:00:4964 // Overridden from View:
[email protected]79e549f2011-03-14 06:56:3365 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
[email protected]70d38b02010-04-09 04:00:4966
[email protected]f96721b2011-09-23 14:51:4567 // Returns whether this scrollbar is horizontal.
initial.commit09911bf2008-07-26 23:55:2968 bool IsHorizontal() const;
69
[email protected]f96721b2011-09-23 14:51:4570 void set_controller(ScrollBarController* controller) {
71 controller_ = controller;
72 }
73 ScrollBarController* controller() const { return controller_; }
initial.commit09911bf2008-07-26 23:55:2974
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]f96721b2011-09-23 14:51:4579 // Returns the max and min positions.
initial.commit09911bf2008-07-26 23:55:2980 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
[email protected]964e09d52012-05-24 15:17:3994 // ImageScrollBar.
[email protected]3c4fc692012-05-04 17:02:4695 explicit ScrollBar(bool is_horiz);
initial.commit09911bf2008-07-26 23:55:2996
97 private:
98 const bool is_horiz_;
99
initial.commit09911bf2008-07-26 23:55:29100 ScrollBarController* controller_;
101
initial.commit09911bf2008-07-26 23:55:29102 int max_pos_;
[email protected]f96721b2011-09-23 14:51:45103
104 DISALLOW_COPY_AND_ASSIGN(ScrollBar);
initial.commit09911bf2008-07-26 23:55:29105};
106
[email protected]c2dacc92008-10-16 23:51:38107} // namespace views
108
[email protected]ac3e9f22011-11-27 18:38:51109#endif // UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_