1 // Copyright (c) 2011 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.
5 #ifndef UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_THUMB_H_
6 #define UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_THUMB_H_
8 #include "ui/gfx/geometry/size.h"
9 #include "ui/views/controls/button/custom_button.h"
10 #include "ui/views/controls/scrollbar/scroll_bar.h"
11 #include "ui/views/view.h"
21 ///////////////////////////////////////////////////////////////////////////////
25 // A view that acts as the thumb in the scroll bar track that the user can
26 // drag to scroll the associated contents view within the viewport.
28 ///////////////////////////////////////////////////////////////////////////////
29 class VIEWS_EXPORT BaseScrollBarThumb
: public View
{
31 explicit BaseScrollBarThumb(BaseScrollBar
* scroll_bar
);
32 ~BaseScrollBarThumb() override
;
34 // Sets the size (width or height) of the thumb to the specified value.
35 void SetSize(int size
);
37 // Retrieves the size (width or height) of the thumb.
40 // Sets the position of the thumb on the x or y axis.
41 void SetPosition(int position
);
43 // Gets the position of the thumb on the x or y axis.
44 int GetPosition() const;
47 gfx::Size
GetPreferredSize() const override
= 0;
51 void OnPaint(gfx::Canvas
* canvas
) override
= 0;
52 void OnMouseEntered(const ui::MouseEvent
& event
) override
;
53 void OnMouseExited(const ui::MouseEvent
& event
) override
;
54 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
55 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
56 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
57 void OnMouseCaptureLost() override
;
59 CustomButton::ButtonState
GetState() const;
60 // Update our state and schedule a repaint when the mouse moves over us.
61 void SetState(CustomButton::ButtonState state
);
63 BaseScrollBar
* scroll_bar() { return scroll_bar_
; }
66 // The BaseScrollBar that owns us.
67 BaseScrollBar
* scroll_bar_
;
69 int drag_start_position_
;
71 // The position of the mouse on the scroll axis relative to the top of this
72 // View when the drag started.
75 // The current state of the thumb button.
76 CustomButton::ButtonState state_
;
78 DISALLOW_COPY_AND_ASSIGN(BaseScrollBarThumb
);
83 #endif // UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_THUMB_H_