summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-02 17:37:08 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-02 17:37:08 +0000
commit201f7bc0f6cd4a4a7ff5de43666d751242c974ef (patch)
tree1d08c6b724edbf465ca9b12d242dd8927e3cb86c /ash
parent2d93363dfc5c28d361c91ddcd74b71278140fcd4 (diff)
downloadchromium_src-201f7bc0f6cd4a4a7ff5de43666d751242c974ef.zip
chromium_src-201f7bc0f6cd4a4a7ff5de43666d751242c974ef.tar.gz
chromium_src-201f7bc0f6cd4a4a7ff5de43666d751242c974ef.tar.bz2
Refactor throbber_view.cc/h out of tray_views.cc/h.
BUG=174228 TBR=sky Review URL: https://chromiumcodereview.appspot.com/12378054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp2
-rw-r--r--ash/system/bluetooth/tray_bluetooth.cc1
-rw-r--r--ash/system/tray/special_popup_row.cc1
-rw-r--r--ash/system/tray/throbber_view.cc110
-rw-r--r--ash/system/tray/throbber_view.h65
-rw-r--r--ash/system/tray/tray_views.cc91
-rw-r--r--ash/system/tray/tray_views.h48
7 files changed, 179 insertions, 139 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index 5a36d0a..84172ad 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -257,6 +257,8 @@
'system/tray/system_tray_notifier.h',
'system/tray/test_system_tray_delegate.cc',
'system/tray/test_system_tray_delegate.h',
+ 'system/tray/throbber_view.cc',
+ 'system/tray/throbber_view.h',
'system/tray/tray_background_view.cc',
'system/tray/tray_background_view.h',
'system/tray/tray_bubble_wrapper.cc',
diff --git a/ash/system/bluetooth/tray_bluetooth.cc b/ash/system/bluetooth/tray_bluetooth.cc
index b12f0b2..61f834b 100644
--- a/ash/system/bluetooth/tray_bluetooth.cc
+++ b/ash/system/bluetooth/tray_bluetooth.cc
@@ -9,6 +9,7 @@
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
+#include "ash/system/tray/throbber_view.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_details_view.h"
#include "ash/system/tray/tray_item_more.h"
diff --git a/ash/system/tray/special_popup_row.cc b/ash/system/tray/special_popup_row.cc
index 43b27e8..29c697b 100644
--- a/ash/system/tray/special_popup_row.cc
+++ b/ash/system/tray/special_popup_row.cc
@@ -5,6 +5,7 @@
#include "ash/system/tray/special_popup_row.h"
#include "ash/system/tray/hover_highlight_view.h"
+#include "ash/system/tray/throbber_view.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_views.h"
#include "grit/ash_resources.h"
diff --git a/ash/system/tray/throbber_view.cc b/ash/system/tray/throbber_view.cc
new file mode 100644
index 0000000..89d4ed4
--- /dev/null
+++ b/ash/system/tray/throbber_view.cc
@@ -0,0 +1,110 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/tray/throbber_view.h"
+
+#include "ash/system/tray/tray_constants.h"
+#include "grit/ash_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/compositor/layer.h"
+#include "ui/compositor/scoped_layer_animation_settings.h"
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+// Time in ms per throbber frame.
+const int kThrobberFrameMs = 30;
+
+// Duration for showing/hiding animation in milliseconds.
+const int kThrobberAnimationDurationMs = 200;
+
+} // namespace
+
+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_->SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ IDR_AURA_CROS_DEFAULT_THROBBER).ToImageSkia());
+ 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);
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/system/tray/throbber_view.h b/ash/system/tray/throbber_view.h
new file mode 100644
index 0000000..4297df4
--- /dev/null
+++ b/ash/system/tray/throbber_view.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SYSTEM_TRAY_THROBBER_VIEW_H_
+#define ASH_SYSTEM_TRAY_THROBBER_VIEW_H_
+
+#include "ui/gfx/size.h"
+#include "ui/views/controls/throbber.h"
+#include "ui/views/view.h"
+
+namespace ash {
+namespace internal {
+
+// 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);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_SYSTEM_TRAY_THROBBER_VIEW_H_
diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc
index 22f0995..f680c2b 100644
--- a/ash/system/tray/tray_views.cc
+++ b/ash/system/tray/tray_views.cc
@@ -15,8 +15,6 @@
#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"
@@ -39,12 +37,6 @@ namespace {
const int kTrayPopupLabelButtonPaddingHorizontal = 16;
const int kTrayPopupLabelButtonPaddingVertical = 8;
-// Time in ms per throbber frame.
-const int kThrobberFrameMs = 30;
-
-// Duration for showing/hiding animation in milliseconds.
-const int kThrobberAnimationDurationMs = 200;
-
const int kBarImagesActive[] = {
IDR_SLIDER_ACTIVE_LEFT,
IDR_SLIDER_ACTIVE_CENTER,
@@ -359,89 +351,6 @@ 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_->SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
- IDR_AURA_CROS_DEFAULT_THROBBER).ToImageSkia());
- 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);
-}
-
void SetupLabelForTray(views::Label* label) {
// Making label_font static to avoid the time penalty of DeriveFont for
// all but the first call.
diff --git a/ash/system/tray/tray_views.h b/ash/system/tray/tray_views.h
index f59c4df..ea2596f 100644
--- a/ash/system/tray/tray_views.h
+++ b/ash/system/tray/tray_views.h
@@ -16,7 +16,6 @@
#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;
@@ -149,53 +148,6 @@ 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);
-};
-
// Sets up a Label properly for the tray (sets color, font etc.).
void SetupLabelForTray(views::Label* label);