summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-05 23:33:22 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-05 23:33:22 +0000
commit44180814943246404dde6562559ff2bf05f7ec18 (patch)
treed5576ef5b381d4bfe3d93817e21b5706aee2e3b6 /ash
parente6fe29bbfa0e3b86e17a0b71bb940c1d3e4ffeda (diff)
downloadchromium_src-44180814943246404dde6562559ff2bf05f7ec18.zip
chromium_src-44180814943246404dde6562559ff2bf05f7ec18.tar.gz
chromium_src-44180814943246404dde6562559ff2bf05f7ec18.tar.bz2
Add spinner UI to show bluetooth is discovering devices. For M26, I used the default image from Throbber. We may polish the UI with better asset in M27.
Add an interactive_ flag in Throbber to allow it become non-interactive so that the tooltip will show up when user hover the mouse on the Throbber who is the child view of ThrobberView class. BUG=171676 Review URL: https://codereview.chromium.org/12180027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/system/bluetooth/tray_bluetooth.cc13
-rw-r--r--ash/system/tray/tray_views.cc98
-rw-r--r--ash/system/tray/tray_views.h49
3 files changed, 159 insertions, 1 deletions
diff --git a/ash/system/bluetooth/tray_bluetooth.cc b/ash/system/bluetooth/tray_bluetooth.cc
index 021eea4..842a7be 100644
--- a/ash/system/bluetooth/tray_bluetooth.cc
+++ b/ash/system/bluetooth/tray_bluetooth.cc
@@ -103,8 +103,12 @@ class BluetoothDetailedView : public TrayDetailsView,
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->system_tray_delegate();
bool bluetooth_enabled = delegate->GetBluetoothEnabled();
- if (!bluetooth_discovering_ && bluetooth_enabled)
+ if (!bluetooth_discovering_ && bluetooth_enabled) {
delegate->BluetoothStartDiscovering();
+ throbber_->Start();
+ } else if(!bluetooth_enabled) {
+ throbber_->Stop();
+ }
bluetooth_discovering_ = bluetooth_enabled;
}
@@ -114,6 +118,7 @@ class BluetoothDetailedView : public TrayDetailsView,
if (bluetooth_discovering_) {
bluetooth_discovering_ = false;
delegate->BluetoothStopDiscovering();
+ throbber_->Stop();
}
}
@@ -140,6 +145,11 @@ class BluetoothDetailedView : public TrayDetailsView,
if (login_ == user::LOGGED_IN_LOCKED)
return;
+ throbber_ = new ThrobberView;
+ throbber_->SetTooltipText(
+ l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING));
+ footer()->AddThrobber(throbber_);
+
// Do not allow toggling bluetooth in the lock screen.
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->system_tray_delegate();
@@ -322,6 +332,7 @@ class BluetoothDetailedView : public TrayDetailsView,
std::map<views::View*, std::string> device_map_;
views::View* add_device_;
+ ThrobberView* throbber_;
TrayPopupHeaderButton* toggle_bluetooth_;
HoverHighlightView* enable_bluetooth_;
BluetoothDeviceList connected_devices_;
diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc
index 86d9f05..2e6e7c5 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);
diff --git a/ash/system/tray/tray_views.h b/ash/system/tray/tray_views.h
index 4e7588d..6db419c 100644
--- a/ash/system/tray/tray_views.h
+++ b/ash/system/tray/tray_views.h
@@ -16,6 +16,7 @@
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/slider.h"
+#include "ui/views/controls/throbber.h"
#include "ui/views/view.h"
typedef unsigned int SkColor;
@@ -271,6 +272,53 @@ class TrayBarButtonWithTitle : public views::CustomButton {
DISALLOW_COPY_AND_ASSIGN(TrayBarButtonWithTitle);
};
+// A SmoothedThrobber with tooltip.
+class SystemTrayThrobber : public views::SmoothedThrobber {
+ public:
+ SystemTrayThrobber(int frame_delay_ms);
+ virtual ~SystemTrayThrobber();
+
+ void SetTooltipText(const string16& tooltip_text);
+
+ // Overriden from views::View.
+ virtual bool GetTooltipText(
+ const gfx::Point& p, string16* tooltip) const OVERRIDE;
+
+ private:
+ // The current tooltip text.
+ string16 tooltip_text_;
+
+ DISALLOW_COPY_AND_ASSIGN(SystemTrayThrobber);
+};
+
+// A View containing a SystemTrayThrobber with animation for starting/stopping.
+class ThrobberView : public views::View {
+ public:
+ ThrobberView();
+ virtual ~ThrobberView();
+
+ void Start();
+ void Stop();
+ void SetTooltipText(const string16& tooltip_text);
+
+ // Overriden from views::View.
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void Layout() OVERRIDE;
+ virtual bool GetTooltipText(
+ const gfx::Point& p, string16* tooltip) const OVERRIDE;
+
+ private:
+ // Schedules animation for starting/stopping throbber.
+ void ScheduleAnimation(bool start_throbber);
+
+ SystemTrayThrobber* throbber_;
+
+ // The current tooltip text.
+ string16 tooltip_text_;
+
+ DISALLOW_COPY_AND_ASSIGN(ThrobberView);
+};
+
// The 'special' looking row in the uber-tray popups. This is usually the bottom
// row in the popups, and has a fixed height.
class SpecialPopupRow : public views::View {
@@ -282,6 +330,7 @@ class SpecialPopupRow : public views::View {
void SetContent(views::View* view);
void AddButton(TrayPopupHeaderButton* button);
+ void AddThrobber(ThrobberView* throbber);
views::View* content() const { return content_; }