OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_CONTROLS_PROGRESS_BAR_H_ | 5 #ifndef UI_VIEWS_CONTROLS_PROGRESS_BAR_H_ |
6 #define UI_VIEWS_CONTROLS_PROGRESS_BAR_H_ | 6 #define UI_VIEWS_CONTROLS_PROGRESS_BAR_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "ui/gfx/animation/animation_delegate.h" | |
10 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
11 | 12 |
13 namespace gfx { | |
14 class LinearAnimation; | |
15 } | |
16 | |
12 namespace views { | 17 namespace views { |
13 | 18 |
14 // Progress bar is a control that indicates progress visually. | 19 // Progress bar is a control that indicates progress visually. |
15 class VIEWS_EXPORT ProgressBar : public View { | 20 class VIEWS_EXPORT ProgressBar : public View, public gfx::AnimationDelegate { |
16 public: | 21 public: |
17 // The value range defaults to [0.0, 1.0]. | 22 // The preferred height parameter makes it easier to use a ProgressBar with |
18 ProgressBar(); | 23 // layout managers that size to preferred size. |
24 explicit ProgressBar(int preferred_height = 5); | |
19 ~ProgressBar() override; | 25 ~ProgressBar() override; |
20 | 26 |
27 // Overridden from View: | |
28 void GetAccessibleState(ui::AXViewState* state) override; | |
29 gfx::Size GetPreferredSize() const override; | |
30 const char* GetClassName() const override; | |
31 void OnPaint(gfx::Canvas* canvas) override; | |
32 | |
21 double current_value() const { return current_value_; } | 33 double current_value() const { return current_value_; } |
22 | 34 |
23 // Gets a normalized current value in [0.0, 1.0] range based on current value | 35 // Sets the current value. Values outside of the display range of 0.0-1.0 will |
24 // range and the min/max display value range. | 36 // be displayed with an infinite loading animation. |
25 double GetNormalizedValue() const; | |
26 | |
27 // Sets the inclusive range of values to be displayed. Values outside of the | |
28 // range will be capped when displayed. | |
29 void SetDisplayRange(double min_display_value, double max_display_value); | |
30 | |
31 // Sets the current value. Values outside of the range [min_display_value_, | |
32 // max_display_value_] will be stored unmodified and capped for display. | |
33 void SetValue(double value); | 37 void SetValue(double value); |
34 | 38 |
35 // Sets the tooltip text. Default behavior for a progress bar is to show no | 39 protected: |
36 // tooltip on mouse hover. Calling this lets you set a custom tooltip. To | 40 // The color of the progress portion. |
37 // revert to default behavior, call this with an empty string. | 41 SkColor GetForegroundColor() const; |
38 void SetTooltipText(const base::string16& tooltip_text); | 42 // The color of the portion that displays potential progress. |
43 SkColor GetBackgroundColor() const; | |
39 | 44 |
40 // Overridden from View: | 45 int preferred_height() const { return preferred_height_; } |
41 bool GetTooltipText(const gfx::Point& p, | |
42 base::string16* tooltip) const override; | |
43 void GetAccessibleState(ui::AXViewState* state) override; | |
44 | 46 |
45 private: | 47 private: |
46 static const char kViewClassName[]; | 48 static const char kViewClassName[]; |
47 | 49 |
48 // Overridden from View: | 50 // gfx::AnimationDelegate: |
49 gfx::Size GetPreferredSize() const override; | 51 void AnimationProgressed(const gfx::Animation* animation) override; |
50 const char* GetClassName() const override; | 52 void AnimationEnded(const gfx::Animation* animation) override; |
51 void OnPaint(gfx::Canvas* canvas) override; | |
52 | 53 |
53 // Inclusive range used when displaying values. | 54 bool IsIndeterminate(); |
54 double min_display_value_; | 55 void OnPaintIndeterminate(gfx::Canvas* canvas); |
55 double max_display_value_; | |
56 | 56 |
57 // Current value. May be outside of [min_display_value_, max_display_value_]. | 57 // Current progress to display, should be in the range 0.0 to 1.0. |
58 double current_value_; | 58 double current_value_ = 0.0; |
59 | 59 |
60 // Tooltip text. | 60 // In DP, the preferred height of this progress bar. |
61 base::string16 tooltip_text_; | 61 int preferred_height_; |
sky
2016/09/13 19:22:15
const
Evan Stade
2016/09/13 22:01:24
Done.
| |
62 | |
63 std::unique_ptr<gfx::LinearAnimation> indeterminate_bar_animation_; | |
62 | 64 |
63 DISALLOW_COPY_AND_ASSIGN(ProgressBar); | 65 DISALLOW_COPY_AND_ASSIGN(ProgressBar); |
64 }; | 66 }; |
65 | 67 |
66 } // namespace views | 68 } // namespace views |
67 | 69 |
68 #endif // UI_VIEWS_CONTROLS_PROGRESS_BAR_H_ | 70 #endif // UI_VIEWS_CONTROLS_PROGRESS_BAR_H_ |
OLD | NEW |