blob: 2a711d6d5d4084d5e10124e40045454546c80123 [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_
initial.commit09911bf2008-07-26 23:55:297
[email protected]f96721b2011-09-23 14:51:458#include "base/basictypes.h"
9#include "base/compiler_specific.h"
[email protected]5025f862011-11-30 23:35:2010#include "ui/views/view.h"
[email protected]45647af2011-12-01 16:09:3311#include "ui/views/views_export.h"
initial.commit09911bf2008-07-26 23:55:2912
[email protected]c2dacc92008-10-16 23:51:3813namespace views {
initial.commit09911bf2008-07-26 23:55:2914
15class 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]5036f182011-08-05 20:58:2925class VIEWS_EXPORT ScrollBarController {
initial.commit09911bf2008-07-26 23:55:2926 public:
initial.commit09911bf2008-07-26 23:55:2927 // 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]5036f182011-08-05 20:58:2958class VIEWS_EXPORT ScrollBar : public View {
initial.commit09911bf2008-07-26 23:55:2959 public:
60 virtual ~ScrollBar();
61
[email protected]70d38b02010-04-09 04:00:4962 // Overridden from View:
mostynb3b3d52b2014-10-09 10:54:2763 virtual void GetAccessibleState(ui::AXViewState* state) override;
[email protected]70d38b02010-04-09 04:00:4964
[email protected]f96721b2011-09-23 14:51:4565 // Returns whether this scrollbar is horizontal.
initial.commit09911bf2008-07-26 23:55:2966 bool IsHorizontal() const;
67
[email protected]f96721b2011-09-23 14:51:4568 void set_controller(ScrollBarController* controller) {
69 controller_ = controller;
70 }
71 ScrollBarController* controller() const { return controller_; }
initial.commit09911bf2008-07-26 23:55:2972
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]f96721b2011-09-23 14:51:4577 // Returns the max and min positions.
initial.commit09911bf2008-07-26 23:55:2978 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]474d6fd02013-06-11 14:46:5989 // 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.commit09911bf2008-07-26 23:55:2996 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]964e09d52012-05-24 15:17:3999 // ImageScrollBar.
[email protected]3c4fc692012-05-04 17:02:46100 explicit ScrollBar(bool is_horiz);
initial.commit09911bf2008-07-26 23:55:29101
102 private:
103 const bool is_horiz_;
104
initial.commit09911bf2008-07-26 23:55:29105 ScrollBarController* controller_;
106
initial.commit09911bf2008-07-26 23:55:29107 int max_pos_;
[email protected]f96721b2011-09-23 14:51:45108
109 DISALLOW_COPY_AND_ASSIGN(ScrollBar);
initial.commit09911bf2008-07-26 23:55:29110};
111
[email protected]c2dacc92008-10-16 23:51:38112} // namespace views
113
[email protected]ac3e9f22011-11-27 18:38:51114#endif // UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_H_