Commit d8c664d2 authored by tfarina@chromium.org's avatar tfarina@chromium.org

views: Move the overridden methods of ProgressBar to private section.

R=sky@chromium.org

Review URL: http://codereview.chromium.org/8429014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108107 0039d316-1c4b-4281-b951-d872f2087c98
parent a4854818
...@@ -21,9 +21,6 @@ ...@@ -21,9 +21,6 @@
#include "views/border.h" #include "views/border.h"
#include "views/painter.h" #include "views/painter.h"
using std::max;
using std::min;
namespace { namespace {
// Corner radius for the progress bar's border. // Corner radius for the progress bar's border.
...@@ -143,12 +140,34 @@ ProgressBar::ProgressBar() ...@@ -143,12 +140,34 @@ ProgressBar::ProgressBar()
ProgressBar::~ProgressBar() { ProgressBar::~ProgressBar() {
} }
gfx::Size ProgressBar::GetPreferredSize() { void ProgressBar::SetDisplayRange(double min_display_value,
return gfx::Size(100, 16); double max_display_value) {
if (min_display_value != min_display_value_ ||
max_display_value != max_display_value_) {
DCHECK(min_display_value < max_display_value);
min_display_value_ = min_display_value;
max_display_value_ = max_display_value;
SchedulePaint();
}
} }
std::string ProgressBar::GetClassName() const { void ProgressBar::SetValue(double value) {
return kViewClassName; if (value != current_value_) {
current_value_ = value;
SchedulePaint();
}
}
void ProgressBar::SetTooltipText(const string16& tooltip_text) {
tooltip_text_ = tooltip_text;
}
bool ProgressBar::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
DCHECK(tooltip);
if (tooltip == NULL)
return false;
tooltip->assign(tooltip_text_);
return !tooltip_text_.empty();
} }
void ProgressBar::GetAccessibleState(ui::AccessibleViewState* state) { void ProgressBar::GetAccessibleState(ui::AccessibleViewState* state) {
...@@ -156,9 +175,17 @@ void ProgressBar::GetAccessibleState(ui::AccessibleViewState* state) { ...@@ -156,9 +175,17 @@ void ProgressBar::GetAccessibleState(ui::AccessibleViewState* state) {
state->state = ui::AccessibilityTypes::STATE_READONLY; state->state = ui::AccessibilityTypes::STATE_READONLY;
} }
gfx::Size ProgressBar::GetPreferredSize() {
return gfx::Size(100, 16);
}
std::string ProgressBar::GetClassName() const {
return kViewClassName;
}
void ProgressBar::OnPaint(gfx::Canvas* canvas) { void ProgressBar::OnPaint(gfx::Canvas* canvas) {
const double capped_value = const double capped_value = std::min(
min(max(current_value_, min_display_value_), max_display_value_); std::max(current_value_, min_display_value_), max_display_value_);
const double capped_fraction = const double capped_fraction =
(capped_value - min_display_value_) / (capped_value - min_display_value_) /
(max_display_value_ - min_display_value_); (max_display_value_ - min_display_value_);
...@@ -289,34 +316,4 @@ void ProgressBar::OnPaint(gfx::Canvas* canvas) { ...@@ -289,34 +316,4 @@ void ProgressBar::OnPaint(gfx::Canvas* canvas) {
#endif #endif
} }
bool ProgressBar::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
DCHECK(tooltip);
if (tooltip == NULL)
return false;
tooltip->assign(tooltip_text_);
return !tooltip_text_.empty();
}
void ProgressBar::SetDisplayRange(double min_display_value,
double max_display_value) {
if (min_display_value != min_display_value_ ||
max_display_value != max_display_value_) {
DCHECK(min_display_value < max_display_value);
min_display_value_ = min_display_value;
max_display_value_ = max_display_value;
SchedulePaint();
}
}
void ProgressBar::SetValue(double value) {
if (value != current_value_) {
current_value_ = value;
SchedulePaint();
}
}
void ProgressBar::SetTooltipText(const string16& tooltip_text) {
tooltip_text_ = tooltip_text;
}
} // namespace views } // namespace views
...@@ -6,26 +6,13 @@ ...@@ -6,26 +6,13 @@
#define VIEWS_CONTROLS_PROGRESS_BAR_H_ #define VIEWS_CONTROLS_PROGRESS_BAR_H_
#pragma once #pragma once
#include <string> #include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "views/view.h" #include "views/view.h"
namespace gfx {
class Canvas;
class Point;
class Size;
}
namespace views { namespace views {
///////////////////////////////////////////////////////////////////////////// // Progress bar is a control that indicates progress visually.
//
// ProgressBar class
//
// A progress bar is a control that indicates progress visually.
//
/////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT ProgressBar : public View { class VIEWS_EXPORT ProgressBar : public View {
public: public:
// The value range defaults to [0.0, 1.0]. // The value range defaults to [0.0, 1.0].
...@@ -34,32 +21,32 @@ class VIEWS_EXPORT ProgressBar : public View { ...@@ -34,32 +21,32 @@ class VIEWS_EXPORT ProgressBar : public View {
double current_value() const { return current_value_; } double current_value() const { return current_value_; }
// View implementation.
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual std::string GetClassName() const OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual bool GetTooltipText(const gfx::Point& p,
string16* tooltip) const OVERRIDE;
// Sets the inclusive range of values to be displayed. Values outside of the // Sets the inclusive range of values to be displayed. Values outside of the
// range will be capped when displayed. // range will be capped when displayed.
virtual void SetDisplayRange(double min_display_value, void SetDisplayRange(double min_display_value, double max_display_value);
double max_display_value);
// Sets the current value. Values outside of the range [min_display_value_, // Sets the current value. Values outside of the range [min_display_value_,
// max_display_value_] will be stored unmodified and capped for display. // max_display_value_] will be stored unmodified and capped for display.
virtual void SetValue(double value); void SetValue(double value);
// Sets the tooltip text. Default behavior for a progress bar is to show no // Sets the tooltip text. Default behavior for a progress bar is to show no
// tooltip on mouse hover. Calling this lets you set a custom tooltip. To // tooltip on mouse hover. Calling this lets you set a custom tooltip. To
// revert to default behavior, call this with an empty string. // revert to default behavior, call this with an empty string.
void SetTooltipText(const string16& tooltip_text); void SetTooltipText(const string16& tooltip_text);
// Overridden from View:
virtual bool GetTooltipText(const gfx::Point& p,
string16* tooltip) const OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
private: private:
static const char kViewClassName[]; static const char kViewClassName[];
// Overridden from View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual std::string GetClassName() const OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
// Inclusive range used when displaying values. // Inclusive range used when displaying values.
double min_display_value_; double min_display_value_;
double max_display_value_; double max_display_value_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment