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

Side by Side Diff: ui/message_center/quiet_mode_bubble.cc

Issue 11417103: Add quiet mode settings bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/message_center/quiet_mode_bubble.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/message_center/quiet_mode_bubble.h"
6
7 #include "base/time.h"
8 #include "grit/ui_strings.h"
9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/gfx/insets.h"
12 #include "ui/message_center/notification_list.h"
13 #include "ui/views/border.h"
14 #include "ui/views/bubble/bubble_delegate.h"
15 #include "ui/views/controls/button/text_button.h"
16 #include "ui/views/layout/box_layout.h"
17 #include "ui/views/view.h"
18 #include "ui/views/widget/widget.h"
19
20 namespace {
21
22 const int kButtonVerticalMargin = 10;
23 const int kButtonHorizontalMargin = 20;
24 const SkColor kButtonNormalBackgroundColor = SK_ColorWHITE;
25 const SkColor kButtonHoveredBackgroundColor = SkColorSetRGB(0xf5, 0xf5, 0xf5);
26
27 class QuietModeButton : public views::TextButton {
28 public:
29 QuietModeButton(views::ButtonListener* listener, int message_id)
30 : views::TextButton(listener, l10n_util::GetStringUTF16(message_id)) {
31 set_border(views::Border::CreateEmptyBorder(
32 kButtonVerticalMargin, kButtonHorizontalMargin,
33 kButtonVerticalMargin, kButtonHorizontalMargin));
34 set_alignment(views::TextButtonBase::ALIGN_LEFT);
35 set_background(views::Background::CreateSolidBackground(
36 kButtonNormalBackgroundColor));
37 }
38
39 protected:
40 virtual void StateChanged() OVERRIDE {
41 set_background(views::Background::CreateSolidBackground(
42 (state() == views::CustomButton::STATE_HOVERED) ?
43 kButtonHoveredBackgroundColor : kButtonNormalBackgroundColor));
44 }
45 };
46
47 } // namespace
48
49 namespace message_center {
50
51 QuietModeBubble::QuietModeBubble(views::View* anchor_view,
52 gfx::NativeView parent_window,
53 NotificationList* notification_list)
54 : notification_list_(notification_list) {
55 DCHECK(notification_list_);
56 bubble_ = new views::BubbleDelegateView(
57 anchor_view, views::BubbleBorder::BOTTOM_RIGHT);
58 bubble_->set_notify_enter_exit_on_child(true);
59 bubble_->SetPaintToLayer(true);
60 bubble_->SetFillsBoundsOpaquely(true);
61 bubble_->set_parent_window(parent_window);
62 bubble_->set_margins(gfx::Insets());
63 InitializeBubbleContents();
64 views::BubbleDelegateView::CreateBubble(bubble_);
65 bubble_->Show();
66 }
67
68 QuietModeBubble::~QuietModeBubble() {
69 Close();
70 }
71
72 void QuietModeBubble::Close() {
73 if (bubble_) {
74 bubble_->GetWidget()->Close();
75 bubble_ = NULL;
76 quiet_mode_ = NULL;
77 quiet_mode_1hour_ = NULL;
78 quiet_mode_1day_ = NULL;
79 }
80 }
81
82 void QuietModeBubble::InitializeBubbleContents() {
83 views::View* contents_view = bubble_->GetContentsView();
84 contents_view->SetLayoutManager(
85 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
86 // TODO(mukai): Determine the actual UI to denote "enter/exit" quiet mode.
87 quiet_mode_ = new QuietModeButton(
88 this, (notification_list_->quiet_mode()) ?
89 IDS_MESSAGE_CENTER_QUIET_MODE_EXIT : IDS_MESSAGE_CENTER_QUIET_MODE);
90 contents_view->AddChildView(quiet_mode_);
91 quiet_mode_1hour_ = new QuietModeButton(
92 this, IDS_MESSAGE_CENTER_QUIET_MODE_1HOUR);
93 contents_view->AddChildView(quiet_mode_1hour_);
94 quiet_mode_1day_ = new QuietModeButton(
95 this, IDS_MESSAGE_CENTER_QUIET_MODE_1DAY);
96 contents_view->AddChildView(quiet_mode_1day_);
97 }
98
99 void QuietModeBubble::ButtonPressed(views::Button* sender,
100 const ui::Event& event) {
101 DCHECK(sender == quiet_mode_ ||
102 sender == quiet_mode_1hour_ || sender == quiet_mode_1day_);
103 if (sender == quiet_mode_) {
104 notification_list_->SetQuietMode(!notification_list_->quiet_mode());
105 LOG(INFO) << notification_list_->quiet_mode();
106 } else {
107 base::TimeDelta expires_in = (sender == quiet_mode_1day_) ?
108 base::TimeDelta::FromDays(1) : base::TimeDelta::FromHours(1);
109 notification_list_->EnterQuietModeWithExpire(expires_in);
110 }
111 Close();
112 }
113
114 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/quiet_mode_bubble.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698