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

Unified Diff: ui/message_center/views/notification_view.cc

Issue 1447933002: Implement an indeterminate progress-bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failure Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/views/notification_view.cc
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index 76b7827614857c9bc70cc7febf930f0f3d8a3b3d..1bb5392ecc49de53a429c94ce0758a1690e475a5 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -26,6 +26,7 @@
#include "ui/message_center/views/constants.h"
#include "ui/message_center/views/message_center_controller.h"
#include "ui/message_center/views/notification_button.h"
+#include "ui/message_center/views/notification_progress_bar.h"
#include "ui/message_center/views/padded_button.h"
#include "ui/message_center/views/proportional_image_view.h"
#include "ui/native_theme/native_theme.h"
@@ -48,8 +49,6 @@
namespace {
// Dimensions.
-const int kProgressBarWidth = message_center::kNotificationWidth -
- message_center::kTextLeftPadding - message_center::kTextRightPadding;
const int kProgressBarBottomPadding = 0;
// static
@@ -157,67 +156,6 @@ void ItemView::SetVisible(bool visible) {
child_at(i)->SetVisible(visible);
}
-// NotificationProgressBar /////////////////////////////////////////////////////
-
-class NotificationProgressBar : public views::ProgressBar {
- public:
- NotificationProgressBar();
- ~NotificationProgressBar() override;
-
- private:
- // Overriden from View
- gfx::Size GetPreferredSize() const override;
- void OnPaint(gfx::Canvas* canvas) override;
-
- DISALLOW_COPY_AND_ASSIGN(NotificationProgressBar);
-};
-
-NotificationProgressBar::NotificationProgressBar() {
-}
-
-NotificationProgressBar::~NotificationProgressBar() {
-}
-
-gfx::Size NotificationProgressBar::GetPreferredSize() const {
- gfx::Size pref_size(kProgressBarWidth, message_center::kProgressBarThickness);
- gfx::Insets insets = GetInsets();
- pref_size.Enlarge(insets.width(), insets.height());
- return pref_size;
-}
-
-void NotificationProgressBar::OnPaint(gfx::Canvas* canvas) {
- gfx::Rect content_bounds = GetContentsBounds();
-
- // Draw background.
- SkPath background_path;
- background_path.addRoundRect(gfx::RectToSkRect(content_bounds),
- message_center::kProgressBarCornerRadius,
- message_center::kProgressBarCornerRadius);
- SkPaint background_paint;
- background_paint.setStyle(SkPaint::kFill_Style);
- background_paint.setFlags(SkPaint::kAntiAlias_Flag);
- background_paint.setColor(message_center::kProgressBarBackgroundColor);
- canvas->DrawPath(background_path, background_paint);
-
- // Draw slice.
- const int slice_width =
- static_cast<int>(content_bounds.width() * GetNormalizedValue() + 0.5);
- if (slice_width < 1)
- return;
-
- gfx::Rect slice_bounds = content_bounds;
- slice_bounds.set_width(slice_width);
- SkPath slice_path;
- slice_path.addRoundRect(gfx::RectToSkRect(slice_bounds),
- message_center::kProgressBarCornerRadius,
- message_center::kProgressBarCornerRadius);
- SkPaint slice_paint;
- slice_paint.setStyle(SkPaint::kFill_Style);
- slice_paint.setFlags(SkPaint::kAntiAlias_Flag);
- slice_paint.setColor(message_center::kProgressBarSliceColor);
- canvas->DrawPath(slice_path, slice_paint);
-}
-
} // namespace
namespace message_center {
@@ -663,14 +601,27 @@ void NotificationView::CreateOrUpdateProgressBarView(
DCHECK(top_view_ != NULL);
+ bool is_indeterminate = (notification.progress() < 0);
+ if (progress_bar_view_ &&
+ progress_bar_view_->is_indeterminate() != is_indeterminate) {
+ delete progress_bar_view_;
+ progress_bar_view_ = NULL;
+ }
+
if (!progress_bar_view_) {
- progress_bar_view_ = new NotificationProgressBar();
+ if (!is_indeterminate)
+ progress_bar_view_ = new NotificationProgressBar();
+ else
+ progress_bar_view_ = new NotificationIndeterminateProgressBar();
+
progress_bar_view_->SetBorder(MakeProgressBarBorder(
message_center::kProgressBarTopPadding, kProgressBarBottomPadding));
top_view_->AddChildView(progress_bar_view_);
}
- progress_bar_view_->SetValue(notification.progress() / 100.0);
+ if (!is_indeterminate)
+ progress_bar_view_->SetValue(notification.progress() / 100.0);
+
progress_bar_view_->SetVisible(!notification.items().size());
}
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698