summaryrefslogtreecommitdiffstats
path: root/ash/system
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-05 22:36:49 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-05 22:36:49 +0000
commit72f05d6006238f840299aed5adde730558c1c10e (patch)
tree2924497c95348959701c70491013063233a5d4d8 /ash/system
parent919a8c3858bdca5d7e742f2800e8f98c25ba97eb (diff)
downloadchromium_src-72f05d6006238f840299aed5adde730558c1c10e.zip
chromium_src-72f05d6006238f840299aed5adde730558c1c10e.tar.gz
chromium_src-72f05d6006238f840299aed5adde730558c1c10e.tar.bz2
ash uber tray: Auto-close volume/brightness popups after a short delay.
BUG=110130,110131 TEST=none Review URL: https://chromiumcodereview.appspot.com/9599001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125018 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system')
-rw-r--r--ash/system/audio/tray_volume.cc3
-rw-r--r--ash/system/brightness/tray_brightness.cc3
-rw-r--r--ash/system/tray/system_tray.cc60
-rw-r--r--ash/system/tray/system_tray.h12
-rw-r--r--ash/system/tray/system_tray_item.cc4
-rw-r--r--ash/system/tray/system_tray_item.h6
-rw-r--r--ash/system/tray/tray_constants.cc11
-rw-r--r--ash/system/tray/tray_constants.h15
8 files changed, 94 insertions, 20 deletions
diff --git a/ash/system/audio/tray_volume.cc b/ash/system/audio/tray_volume.cc
index bbf37f2..3fa712e 100644
--- a/ash/system/audio/tray_volume.cc
+++ b/ash/system/audio/tray_volume.cc
@@ -6,6 +6,7 @@
#include "ash/shell.h"
#include "ash/system/tray/system_tray_delegate.h"
+#include "ash/system/tray/tray_constants.h"
#include "base/utf_string_conversions.h"
#include "grit/ui_resources.h"
#include "third_party/skia/include/core/SkCanvas.h"
@@ -179,7 +180,7 @@ void TrayVolume::OnVolumeChanged(float percent) {
return;
}
- PopupDetailedView();
+ PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds);
}
} // namespace internal
diff --git a/ash/system/brightness/tray_brightness.cc b/ash/system/brightness/tray_brightness.cc
index 698863c..52206c3 100644
--- a/ash/system/brightness/tray_brightness.cc
+++ b/ash/system/brightness/tray_brightness.cc
@@ -8,6 +8,7 @@
#include "ash/shell.h"
#include "ash/system/brightness/brightness_control_delegate.h"
#include "ash/system/tray/system_tray_delegate.h"
+#include "ash/system/tray/tray_constants.h"
#include "base/utf_string_conversions.h"
#include "grit/ui_resources.h"
#include "ui/base/resource/resource_bundle.h"
@@ -117,7 +118,7 @@ void TrayBrightness::OnBrightnessChanged(float percent, bool user_initiated) {
}
if (!user_initiated)
return;
- PopupDetailedView();
+ PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds);
}
} // namespace internal
diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc
index 89e421b..8862e81 100644
--- a/ash/system/tray/system_tray.cc
+++ b/ash/system/tray/system_tray.cc
@@ -12,6 +12,7 @@
#include "ash/system/user/login_status.h"
#include "ash/wm/shadow_types.h"
#include "base/logging.h"
+#include "base/timer.h"
#include "base/utf_string_conversions.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -24,7 +25,9 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/view.h"
-namespace {
+namespace ash {
+
+namespace internal {
const int kArrowHeight = 10;
const int kArrowWidth = 20;
@@ -150,10 +153,12 @@ class SystemTrayBubble : public views::BubbleDelegateView {
: views::BubbleDelegateView(tray, views::BubbleBorder::BOTTOM_RIGHT),
tray_(tray),
items_(items),
- detailed_(detailed) {
+ detailed_(detailed),
+ autoclose_delay_(0) {
set_margin(0);
set_parent_window(ash::Shell::GetInstance()->GetContainer(
ash::internal::kShellWindowId_SettingBubbleContainer));
+ set_notify_enter_exit_on_child(true);
}
virtual ~SystemTrayBubble() {
@@ -167,7 +172,21 @@ class SystemTrayBubble : public views::BubbleDelegateView {
}
}
+ void StartAutoCloseTimer(int seconds) {
+ autoclose_.Stop();
+ autoclose_delay_ = seconds;
+ if (autoclose_delay_) {
+ autoclose_.Start(FROM_HERE,
+ base::TimeDelta::FromSeconds(autoclose_delay_),
+ this, &SystemTrayBubble::AutoClose);
+ }
+ }
+
private:
+ void AutoClose() {
+ StartFade(false);
+ }
+
// Overridden from views::BubbleDelegateView.
virtual void Init() OVERRIDE {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
@@ -187,19 +206,34 @@ class SystemTrayBubble : public views::BubbleDelegateView {
}
}
+ virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE {
+ autoclose_.Stop();
+ }
+
+ virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE {
+ if (autoclose_delay_) {
+ autoclose_.Stop();
+ autoclose_.Start(FROM_HERE,
+ base::TimeDelta::FromSeconds(autoclose_delay_),
+ this, &SystemTrayBubble::AutoClose);
+ }
+ }
+
ash::SystemTray* tray_;
std::vector<ash::SystemTrayItem*> items_;
bool detailed_;
+ int autoclose_delay_;
+ base::OneShotTimer<SystemTrayBubble> autoclose_;
+
DISALLOW_COPY_AND_ASSIGN(SystemTrayBubble);
};
-} // namespace
-
-namespace ash {
+} // namespace internal
SystemTray::SystemTray()
: items_(),
+ bubble_(NULL),
popup_(NULL) {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
5, 0, 3));
@@ -232,14 +266,16 @@ void SystemTray::RemoveTrayItem(SystemTrayItem* item) {
NOTIMPLEMENTED();
}
-void SystemTray::ShowDetailedView(SystemTrayItem* item) {
+void SystemTray::ShowDetailedView(SystemTrayItem* item, int close_delay) {
if (popup_)
popup_->Close();
popup_ = NULL;
+ bubble_ = NULL;
std::vector<SystemTrayItem*> items;
items.push_back(item);
ShowItems(items, true);
+ bubble_->StartAutoCloseTimer(close_delay);
}
void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) {
@@ -265,14 +301,15 @@ void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) {
void SystemTray::ShowItems(std::vector<SystemTrayItem*>& items, bool detailed) {
CHECK(!popup_);
- SystemTrayBubble* bubble = new SystemTrayBubble(this, items, detailed);
- popup_ = views::BubbleDelegateView::CreateBubble(bubble);
- bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
+ CHECK(!bubble_);
+ bubble_ = new internal::SystemTrayBubble(this, items, detailed);
+ popup_ = views::BubbleDelegateView::CreateBubble(bubble_);
+ bubble_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
popup_->non_client_view()->frame_view()->set_background(NULL);
popup_->non_client_view()->frame_view()->set_border(
- new SystemTrayBubbleBorder(bubble));
+ new internal::SystemTrayBubbleBorder(bubble_));
popup_->AddObserver(this);
- bubble->Show();
+ bubble_->Show();
}
bool SystemTray::OnMousePressed(const views::MouseEvent& event) {
@@ -286,6 +323,7 @@ bool SystemTray::OnMousePressed(const views::MouseEvent& event) {
void SystemTray::OnWidgetClosing(views::Widget* widget) {
CHECK_EQ(popup_, widget);
popup_ = NULL;
+ bubble_ = NULL;
}
} // namespace ash
diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h
index 0fcd5e6..8bdd0d4 100644
--- a/ash/system/tray/system_tray.h
+++ b/ash/system/tray/system_tray.h
@@ -18,6 +18,10 @@ namespace ash {
class SystemTrayItem;
+namespace internal {
+class SystemTrayBubble;
+}
+
class ASH_EXPORT SystemTray : public views::View,
public views::Widget::Observer {
public:
@@ -30,8 +34,9 @@ class ASH_EXPORT SystemTray : public views::View,
// Removes an existing tray item.
void RemoveTrayItem(SystemTrayItem* item);
- // Shows details of a particular item.
- void ShowDetailedView(SystemTrayItem* item);
+ // Shows details of a particular item. If |close_delay| is non-zero, then the
+ // view is automatically closed after the specified time.
+ void ShowDetailedView(SystemTrayItem* item, int close_delay_in_seconds);
// Updates the items when the login status of the system changes.
void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
@@ -49,7 +54,8 @@ class ASH_EXPORT SystemTray : public views::View,
std::vector<SystemTrayItem*> items_;
- // The popup widget.
+ // The popup widget and the delegate.
+ internal::SystemTrayBubble* bubble_;
views::Widget* popup_;
DISALLOW_COPY_AND_ASSIGN(SystemTray);
diff --git a/ash/system/tray/system_tray_item.cc b/ash/system/tray/system_tray_item.cc
index d9e7875..3232f2bc 100644
--- a/ash/system/tray/system_tray_item.cc
+++ b/ash/system/tray/system_tray_item.cc
@@ -16,8 +16,8 @@ SystemTrayItem::SystemTrayItem() {
SystemTrayItem::~SystemTrayItem() {
}
-void SystemTrayItem::PopupDetailedView() {
- Shell::GetInstance()->tray()->ShowDetailedView(this);
+void SystemTrayItem::PopupDetailedView(int for_seconds) {
+ Shell::GetInstance()->tray()->ShowDetailedView(this, for_seconds);
}
} // namespace ash
diff --git a/ash/system/tray/system_tray_item.h b/ash/system/tray/system_tray_item.h
index c7d4ba6..e1c2b44 100644
--- a/ash/system/tray/system_tray_item.h
+++ b/ash/system/tray/system_tray_item.h
@@ -42,8 +42,10 @@ class ASH_EXPORT SystemTrayItem {
// Pops up the detailed view for this item. An item can request to show its
// detailed view using this function (e.g. from an observer callback when
- // something, e.g. volume, network availability etc. changes).
- void PopupDetailedView();
+ // something, e.g. volume, network availability etc. changes). If
+ // |for_seconds| is non-zero, then the popup is closed after the specified
+ // time.
+ void PopupDetailedView(int for_seconds);
private:
diff --git a/ash/system/tray/tray_constants.cc b/ash/system/tray/tray_constants.cc
new file mode 100644
index 0000000..21944ed
--- /dev/null
+++ b/ash/system/tray/tray_constants.cc
@@ -0,0 +1,11 @@
+// Copyright (c) 2012 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/tray_constants.h"
+
+namespace ash {
+
+const int kTrayPopupAutoCloseDelayInSeconds = 2;
+
+} // namespace ash
diff --git a/ash/system/tray/tray_constants.h b/ash/system/tray/tray_constants.h
new file mode 100644
index 0000000..dddcaa4
--- /dev/null
+++ b/ash/system/tray/tray_constants.h
@@ -0,0 +1,15 @@
+// Copyright (c) 2012 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_TRAY_CONSTANTS_H_
+#define ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_
+#pragma once
+
+namespace ash {
+
+extern const int kTrayPopupAutoCloseDelayInSeconds;
+
+} // namespace ash
+
+#endif // ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_