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

Unified Diff: ash/system/tray/tray_views.cc

Issue 12180027: Add spinner UI to show bluetooth is discovering devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a subclass of SmoothedThrobber and override GetTooltipText to show tooltip on throbber. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/tray/tray_views.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/tray/tray_views.cc
diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc
index 86d9f0514284f77ab558be1ab25f705eb472b59d..2e6e7c5b579cb49bcd854c67a7e085f311c66257 100644
--- a/ash/system/tray/tray_views.cc
+++ b/ash/system/tray/tray_views.cc
@@ -14,6 +14,8 @@
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/events/event.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/compositor/layer.h"
+#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
@@ -40,6 +42,12 @@ const int kSpecialPopupRowHeight = 55;
const int kTrayPopupLabelButtonPaddingHorizontal = 16;
const int kTrayPopupLabelButtonPaddingVertical = 8;
+// Time in ms per throbber frame.
+const int kThrobberFrameMs = 50;
+
+// Duration for showing/hiding animation in milliseconds.
+const int kThrobberAnimationDurationMs = 200;
+
const int kBarImagesActive[] = {
IDR_SLIDER_ACTIVE_LEFT,
IDR_SLIDER_ACTIVE_CENTER,
@@ -611,6 +619,87 @@ void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
image_->Update(control_on);
}
+SystemTrayThrobber::SystemTrayThrobber(int frame_delay_ms)
+ : views::SmoothedThrobber(frame_delay_ms) {
+}
+
+SystemTrayThrobber::~SystemTrayThrobber() {
+}
+
+void SystemTrayThrobber::SetTooltipText(const string16& tooltip_text) {
+ tooltip_text_ = tooltip_text;
+}
+
+bool SystemTrayThrobber::GetTooltipText(const gfx::Point& p,
+ string16* tooltip) const {
+ if (tooltip_text_.empty())
+ return false;
+
+ *tooltip = tooltip_text_;
+ return true;
+}
+
+ThrobberView::ThrobberView() {
+ throbber_ = new SystemTrayThrobber(kThrobberFrameMs);
+ throbber_->set_stop_delay_ms(kThrobberAnimationDurationMs);
+ AddChildView(throbber_);
+
+ SetPaintToLayer(true);
+ layer()->SetFillsBoundsOpaquely(false);
+ layer()->SetOpacity(0.0);
+}
+
+ThrobberView::~ThrobberView() {
+}
+
+gfx::Size ThrobberView::GetPreferredSize() {
+ return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight);
+}
+
+void ThrobberView::Layout() {
+ View* child = child_at(0);
+ gfx::Size ps = child->GetPreferredSize();
+ child->SetBounds((width() - ps.width()) / 2,
+ (height() - ps.height()) / 2,
+ ps.width(), ps.height());
+ SizeToPreferredSize();
+}
+
+bool ThrobberView::GetTooltipText(const gfx::Point& p,
+ string16* tooltip) const {
+ if (tooltip_text_.empty())
+ return false;
+
+ *tooltip = tooltip_text_;
+ return true;
+}
+
+void ThrobberView::Start() {
+ ScheduleAnimation(true);
+ throbber_->Start();
+}
+
+void ThrobberView::Stop() {
+ ScheduleAnimation(false);
+ throbber_->Stop();
+}
+
+void ThrobberView::SetTooltipText(const string16& tooltip_text) {
+ tooltip_text_ = tooltip_text;
+ throbber_->SetTooltipText(tooltip_text);
+}
+
+void ThrobberView::ScheduleAnimation(bool start_throbber) {
+ // Stop any previous animation.
+ layer()->GetAnimator()->StopAnimating();
+
+ ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
+ animation.SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs));
+
+ layer()->SetOpacity(start_throbber ? 1.0 : 0.0);
+}
+
////////////////////////////////////////////////////////////////////////////////
// SpecialPopupRow
@@ -669,6 +758,15 @@ void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) {
button_container_->AddChildView(button);
}
+void SpecialPopupRow::AddThrobber(ThrobberView* throbber) {
+ if (!button_container_) {
+ button_container_ = CreatePopupHeaderButtonsContainer();
+ AddChildView(button_container_);
+ }
+
+ button_container_->AddChildView(throbber);
+}
+
gfx::Size SpecialPopupRow::GetPreferredSize() {
gfx::Size size = views::View::GetPreferredSize();
size.set_height(kSpecialPopupRowHeight);
« no previous file with comments | « ash/system/tray/tray_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698