Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: ui/views/controls/progress_bar.h

Issue 2329633003: Implement progress bar spec (determinate and indeterminate). (Closed)
Patch Set: better example code Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
16 public: 21 public:
17 // The value range defaults to [0.0, 1.0]. 22 // The value range defaults to [0.0, 1.0].
18 ProgressBar(); 23 ProgressBar();
19 ~ProgressBar() override; 24 ~ProgressBar() override;
20 25
21 double current_value() const { return current_value_; } 26 double current_value() const { return current_value_; }
22 27
28 virtual bool is_indeterminate() = 0;
29
23 // Gets a normalized current value in [0.0, 1.0] range based on current value 30 // Gets a normalized current value in [0.0, 1.0] range based on current value
24 // range and the min/max display value range. 31 // range and the min/max display value range.
25 double GetNormalizedValue() const; 32 double GetNormalizedValue() const;
26 33
27 // Sets the inclusive range of values to be displayed. Values outside of the 34 // Sets the inclusive range of values to be displayed. Values outside of the
28 // range will be capped when displayed. 35 // range will be capped when displayed.
29 void SetDisplayRange(double min_display_value, double max_display_value); 36 void SetDisplayRange(double min_display_value, double max_display_value);
30 37
31 // Sets the current value. Values outside of the range [min_display_value_, 38 // Sets the current value. Values outside of the range [min_display_value_,
32 // max_display_value_] will be stored unmodified and capped for display. 39 // max_display_value_] will be stored unmodified and capped for display.
33 void SetValue(double value); 40 void SetValue(double value);
34 41
35 // Sets the tooltip text. Default behavior for a progress bar is to show no 42 // Sets the tooltip text. Default behavior for a progress bar is to show no
36 // tooltip on mouse hover. Calling this lets you set a custom tooltip. To 43 // tooltip on mouse hover. Calling this lets you set a custom tooltip. To
37 // revert to default behavior, call this with an empty string. 44 // revert to default behavior, call this with an empty string.
38 void SetTooltipText(const base::string16& tooltip_text); 45 void SetTooltipText(const base::string16& tooltip_text);
39 46
40 // Overridden from View: 47 // Overridden from View:
41 bool GetTooltipText(const gfx::Point& p, 48 bool GetTooltipText(const gfx::Point& p,
42 base::string16* tooltip) const override; 49 base::string16* tooltip) const override;
43 void GetAccessibleState(ui::AXViewState* state) override; 50 void GetAccessibleState(ui::AXViewState* state) override;
51 gfx::Size GetPreferredSize() const override;
52 const char* GetClassName() const override;
53 void OnPaint(gfx::Canvas* canvas) override = 0;
54
55 protected:
56 // The color of the progress portion.
57 SkColor GetForegroundColor() const;
58 // The color of the portion that displays potential progress.
59 SkColor GetBackgroundColor() const;
44 60
45 private: 61 private:
46 static const char kViewClassName[]; 62 static const char kViewClassName[];
47 63
48 // Overridden from View:
49 gfx::Size GetPreferredSize() const override;
50 const char* GetClassName() const override;
51 void OnPaint(gfx::Canvas* canvas) override;
52
53 // Inclusive range used when displaying values. 64 // Inclusive range used when displaying values.
54 double min_display_value_; 65 double min_display_value_;
55 double max_display_value_; 66 double max_display_value_;
56 67
57 // Current value. May be outside of [min_display_value_, max_display_value_]. 68 // Current value. May be outside of [min_display_value_, max_display_value_].
58 double current_value_; 69 double current_value_;
59 70
60 // Tooltip text. 71 // Tooltip text.
61 base::string16 tooltip_text_; 72 base::string16 tooltip_text_;
62 73
63 DISALLOW_COPY_AND_ASSIGN(ProgressBar); 74 DISALLOW_COPY_AND_ASSIGN(ProgressBar);
64 }; 75 };
65 76
77 class VIEWS_EXPORT DeterminateProgressBar : public ProgressBar {
tdanderson 2016/09/12 17:11:13 Class-level descriptions would be nice to include
Evan Stade 2016/09/13 02:05:14 Done.
78 public:
79 DeterminateProgressBar();
80 ~DeterminateProgressBar() override;
81
82 bool is_indeterminate() override;
83
84 private:
85 // Overriden from views::ProgressBar (originally from views::View)
86 void OnPaint(gfx::Canvas* canvas) override;
87
88 DISALLOW_COPY_AND_ASSIGN(DeterminateProgressBar);
89 };
90
91 class VIEWS_EXPORT IndeterminateProgressBar : public DeterminateProgressBar,
tdanderson 2016/09/12 17:11:13 I don't understand why you have chosen to have IPB
Evan Stade 2016/09/13 02:05:14 I don't understand either. Just a brain fart. I s
92 public gfx::AnimationDelegate {
93 public:
94 IndeterminateProgressBar();
95 ~IndeterminateProgressBar() override;
96
97 bool is_indeterminate() override;
98
99 private:
100 // Overriden from views::ProgressBar (originally from views::View)
101 void OnPaint(gfx::Canvas* canvas) override;
102
103 // Overriden from gfx::AnimationDelegate
104 void AnimationProgressed(const gfx::Animation* animation) override;
105 void AnimationEnded(const gfx::Animation* animation) override;
106
107 std::unique_ptr<gfx::LinearAnimation> indeterminate_bar_animation_;
108
109 DISALLOW_COPY_AND_ASSIGN(IndeterminateProgressBar);
110 };
111
66 } // namespace views 112 } // namespace views
67 113
68 #endif // UI_VIEWS_CONTROLS_PROGRESS_BAR_H_ 114 #endif // UI_VIEWS_CONTROLS_PROGRESS_BAR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698