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 #include "ui/message_center/quiet_mode_bubble.h"
7 #include "grit/ui_strings.h"
8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/insets.h"
11 #include "ui/message_center/notification_list.h"
12 #include "ui/views/border.h"
13 #include "ui/views/bubble/bubble_delegate.h"
14 #include "ui/views/controls/button/text_button.h"
15 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/view.h"
17 #include "ui/views/widget/widget.h"
21 const int kButtonVerticalMargin
= 10;
22 const int kButtonHorizontalMargin
= 20;
23 const SkColor kButtonNormalBackgroundColor
= SK_ColorWHITE
;
24 const SkColor kButtonHoveredBackgroundColor
= SkColorSetRGB(0xf5, 0xf5, 0xf5);
26 class QuietModeButton
: public views::TextButton
{
28 QuietModeButton(views::ButtonListener
* listener
, int message_id
)
29 : views::TextButton(listener
, l10n_util::GetStringUTF16(message_id
)) {
30 set_border(views::Border::CreateEmptyBorder(
31 kButtonVerticalMargin
, kButtonHorizontalMargin
,
32 kButtonVerticalMargin
, kButtonHorizontalMargin
));
33 set_alignment(views::TextButtonBase::ALIGN_LEFT
);
34 set_background(views::Background::CreateSolidBackground(
35 kButtonNormalBackgroundColor
));
39 virtual void StateChanged() OVERRIDE
{
40 set_background(views::Background::CreateSolidBackground(
41 (state() == views::CustomButton::STATE_HOVERED
) ?
42 kButtonHoveredBackgroundColor
: kButtonNormalBackgroundColor
));
48 namespace message_center
{
50 QuietModeBubble::QuietModeBubble(views::View
* anchor_view
,
51 gfx::NativeView parent_window
,
52 NotificationList
* notification_list
)
53 : notification_list_(notification_list
) {
54 DCHECK(notification_list_
);
55 bubble_
= new views::BubbleDelegateView(
56 anchor_view
, views::BubbleBorder::BOTTOM_RIGHT
);
57 bubble_
->set_notify_enter_exit_on_child(true);
58 bubble_
->SetPaintToLayer(true);
59 bubble_
->SetFillsBoundsOpaquely(true);
60 bubble_
->set_parent_window(parent_window
);
61 bubble_
->set_margins(gfx::Insets());
62 InitializeBubbleContents();
63 views::BubbleDelegateView::CreateBubble(bubble_
);
67 QuietModeBubble::~QuietModeBubble() {
71 void QuietModeBubble::Close() {
73 bubble_
->GetWidget()->Close();
76 quiet_mode_1hour_
= NULL
;
77 quiet_mode_1day_
= NULL
;
81 views::Widget
* QuietModeBubble::GetBubbleWidget() {
82 return bubble_
? bubble_
->GetWidget() : NULL
;
85 void QuietModeBubble::InitializeBubbleContents() {
86 views::View
* contents_view
= bubble_
->GetContentsView();
87 contents_view
->SetLayoutManager(
88 new views::BoxLayout(views::BoxLayout::kVertical
, 0, 0, 1));
89 // TODO(mukai): Determine the actual UI to denote "enter/exit" quiet mode.
90 quiet_mode_
= new QuietModeButton(
91 this, (notification_list_
->quiet_mode()) ?
92 IDS_MESSAGE_CENTER_QUIET_MODE_EXIT
: IDS_MESSAGE_CENTER_QUIET_MODE
);
93 contents_view
->AddChildView(quiet_mode_
);
94 quiet_mode_1hour_
= new QuietModeButton(
95 this, IDS_MESSAGE_CENTER_QUIET_MODE_1HOUR
);
96 contents_view
->AddChildView(quiet_mode_1hour_
);
97 quiet_mode_1day_
= new QuietModeButton(
98 this, IDS_MESSAGE_CENTER_QUIET_MODE_1DAY
);
99 contents_view
->AddChildView(quiet_mode_1day_
);
102 void QuietModeBubble::ButtonPressed(views::Button
* sender
,
103 const ui::Event
& event
) {
104 DCHECK(sender
== quiet_mode_
||
105 sender
== quiet_mode_1hour_
|| sender
== quiet_mode_1day_
);
106 if (sender
== quiet_mode_
) {
107 notification_list_
->SetQuietMode(!notification_list_
->quiet_mode());
108 LOG(INFO
) << notification_list_
->quiet_mode();
110 base::TimeDelta expires_in
= (sender
== quiet_mode_1day_
) ?
111 base::TimeDelta::FromDays(1) : base::TimeDelta::FromHours(1);
112 notification_list_
->EnterQuietModeWithExpire(expires_in
);
117 } // namespace message_center