diff options
author | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-22 00:48:07 +0000 |
---|---|---|
committer | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-22 00:48:07 +0000 |
commit | 851490a1a28496967ba8e386b6590637fa46e9f0 (patch) | |
tree | 82d9ade0d33519bfd9202462d7bf928c73a8fb58 /ui/message_center | |
parent | 77e9e4d9f3028c80dea47aed96e324b2fe762474 (diff) | |
download | chromium_src-851490a1a28496967ba8e386b6590637fa46e9f0.zip chromium_src-851490a1a28496967ba8e386b6590637fa46e9f0.tar.gz chromium_src-851490a1a28496967ba8e386b6590637fa46e9f0.tar.bz2 |
Add quiet mode settings bubble.
BUG=161096
Review URL: https://chromiumcodereview.appspot.com/11417103
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r-- | ui/message_center/message_center.gyp | 2 | ||||
-rw-r--r-- | ui/message_center/notification_list.h | 2 | ||||
-rw-r--r-- | ui/message_center/quiet_mode_bubble.cc | 114 | ||||
-rw-r--r-- | ui/message_center/quiet_mode_bubble.h | 56 |
4 files changed, 174 insertions, 0 deletions
diff --git a/ui/message_center/message_center.gyp b/ui/message_center/message_center.gyp index acd9aeb..22a9ce3 100644 --- a/ui/message_center/message_center.gyp +++ b/ui/message_center/message_center.gyp @@ -45,6 +45,8 @@ 'message_view_multiple.h', 'notification_list.cc', 'notification_list.h', + 'quiet_mode_bubble.cc', + 'quiet_mode_bubble.h', ], }, ], diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h index ce9c266..c06fa16 100644 --- a/ui/message_center/notification_list.h +++ b/ui/message_center/notification_list.h @@ -133,6 +133,8 @@ class MESSAGE_CENTER_EXPORT NotificationList { // Marks the popups returned by GetPopupNotifications() as shown. void MarkPopupsAsShown(); + bool quiet_mode() const { return quiet_mode_; } + // Sets the current quiet mode status to |quiet_mode|. The new status is not // expired. void SetQuietMode(bool quiet_mode); diff --git a/ui/message_center/quiet_mode_bubble.cc b/ui/message_center/quiet_mode_bubble.cc new file mode 100644 index 0000000..c876273 --- /dev/null +++ b/ui/message_center/quiet_mode_bubble.cc @@ -0,0 +1,114 @@ +// 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 "ui/message_center/quiet_mode_bubble.h" + +#include "base/time.h" +#include "grit/ui_strings.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/insets.h" +#include "ui/message_center/notification_list.h" +#include "ui/views/border.h" +#include "ui/views/bubble/bubble_delegate.h" +#include "ui/views/controls/button/text_button.h" +#include "ui/views/layout/box_layout.h" +#include "ui/views/view.h" +#include "ui/views/widget/widget.h" + +namespace { + +const int kButtonVerticalMargin = 10; +const int kButtonHorizontalMargin = 20; +const SkColor kButtonNormalBackgroundColor = SK_ColorWHITE; +const SkColor kButtonHoveredBackgroundColor = SkColorSetRGB(0xf5, 0xf5, 0xf5); + +class QuietModeButton : public views::TextButton { + public: + QuietModeButton(views::ButtonListener* listener, int message_id) + : views::TextButton(listener, l10n_util::GetStringUTF16(message_id)) { + set_border(views::Border::CreateEmptyBorder( + kButtonVerticalMargin, kButtonHorizontalMargin, + kButtonVerticalMargin, kButtonHorizontalMargin)); + set_alignment(views::TextButtonBase::ALIGN_LEFT); + set_background(views::Background::CreateSolidBackground( + kButtonNormalBackgroundColor)); + } + + protected: + virtual void StateChanged() OVERRIDE { + set_background(views::Background::CreateSolidBackground( + (state() == views::CustomButton::STATE_HOVERED) ? + kButtonHoveredBackgroundColor : kButtonNormalBackgroundColor)); + } +}; + +} // namespace + +namespace message_center { + +QuietModeBubble::QuietModeBubble(views::View* anchor_view, + gfx::NativeView parent_window, + NotificationList* notification_list) + : notification_list_(notification_list) { + DCHECK(notification_list_); + bubble_ = new views::BubbleDelegateView( + anchor_view, views::BubbleBorder::BOTTOM_RIGHT); + bubble_->set_notify_enter_exit_on_child(true); + bubble_->SetPaintToLayer(true); + bubble_->SetFillsBoundsOpaquely(true); + bubble_->set_parent_window(parent_window); + bubble_->set_margins(gfx::Insets()); + InitializeBubbleContents(); + views::BubbleDelegateView::CreateBubble(bubble_); + bubble_->Show(); +} + +QuietModeBubble::~QuietModeBubble() { + Close(); +} + +void QuietModeBubble::Close() { + if (bubble_) { + bubble_->GetWidget()->Close(); + bubble_ = NULL; + quiet_mode_ = NULL; + quiet_mode_1hour_ = NULL; + quiet_mode_1day_ = NULL; + } +} + +void QuietModeBubble::InitializeBubbleContents() { + views::View* contents_view = bubble_->GetContentsView(); + contents_view->SetLayoutManager( + new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); + // TODO(mukai): Determine the actual UI to denote "enter/exit" quiet mode. + quiet_mode_ = new QuietModeButton( + this, (notification_list_->quiet_mode()) ? + IDS_MESSAGE_CENTER_QUIET_MODE_EXIT : IDS_MESSAGE_CENTER_QUIET_MODE); + contents_view->AddChildView(quiet_mode_); + quiet_mode_1hour_ = new QuietModeButton( + this, IDS_MESSAGE_CENTER_QUIET_MODE_1HOUR); + contents_view->AddChildView(quiet_mode_1hour_); + quiet_mode_1day_ = new QuietModeButton( + this, IDS_MESSAGE_CENTER_QUIET_MODE_1DAY); + contents_view->AddChildView(quiet_mode_1day_); +} + +void QuietModeBubble::ButtonPressed(views::Button* sender, + const ui::Event& event) { + DCHECK(sender == quiet_mode_ || + sender == quiet_mode_1hour_ || sender == quiet_mode_1day_); + if (sender == quiet_mode_) { + notification_list_->SetQuietMode(!notification_list_->quiet_mode()); + LOG(INFO) << notification_list_->quiet_mode(); + } else { + base::TimeDelta expires_in = (sender == quiet_mode_1day_) ? + base::TimeDelta::FromDays(1) : base::TimeDelta::FromHours(1); + notification_list_->EnterQuietModeWithExpire(expires_in); + } + Close(); +} + +} // namespace message_center diff --git a/ui/message_center/quiet_mode_bubble.h b/ui/message_center/quiet_mode_bubble.h new file mode 100644 index 0000000..ef5a568 --- /dev/null +++ b/ui/message_center/quiet_mode_bubble.h @@ -0,0 +1,56 @@ +// 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 UI_MESSAGE_CENTER_QUIET_MODE_BUBBLE_H_ +#define UI_MESSAGE_CENTER_QUIET_MODE_BUBBLE_H_ + +#include "base/string16.h" +#include "ui/gfx/native_widget_types.h" +#include "ui/message_center/message_center_export.h" +#include "ui/views/controls/button/button.h" + +namespace views { +class BubbleDelegateView; +class View; +} + +namespace message_center { +class NotificationList; + +// The bubble for the quiet mode selection. Note that this isn't TrayBubbleView +// or MessageBubbleBase because its UI is slightly different. +class MESSAGE_CENTER_EXPORT QuietModeBubble : public views::ButtonListener { + public: + QuietModeBubble(views::View* anchor_view, + gfx::NativeView parent_window, + NotificationList* notification_list); + virtual ~QuietModeBubble(); + + // Close the quiet mode bubble. + void Close(); + + views::BubbleDelegateView* bubble() { return bubble_; } + + private: + // Initialize the contents of the bubble. + void InitializeBubbleContents(); + + // views::ButtonListener overrides: + virtual void ButtonPressed(views::Button* sender, + const ui::Event& event) OVERRIDE; + + NotificationList* notification_list_; + views::BubbleDelegateView* bubble_; + + // Buttons. Used in ButtonPressed() to check which button is pressed. + views::Button* quiet_mode_; + views::Button* quiet_mode_1hour_; + views::Button* quiet_mode_1day_; + + DISALLOW_COPY_AND_ASSIGN(QuietModeBubble); +}; + +} // namespace messge_center + +#endif // UI_MESSAGE_CENTER_QUIET_MODE_BUBBLE_H_ |