OLD | NEW |
---|---|
(Empty) | |
1 #include "ui/message_center/quiet_mode_bubble.h" | |
miket_OOO
2012/11/21 01:18:21
License header missing!
Jun Mukai
2012/11/21 19:33:06
Done. Sorry...
| |
2 | |
3 #include "base/time.h" | |
4 #include "grit/ui_strings.h" | |
5 #include "third_party/skia/include/core/SkColor.h" | |
6 #include "ui/base/l10n/l10n_util.h" | |
7 #include "ui/gfx/insets.h" | |
8 #include "ui/message_center/notification_list.h" | |
9 #include "ui/views/border.h" | |
10 #include "ui/views/bubble/bubble_delegate.h" | |
11 #include "ui/views/controls/button/text_button.h" | |
12 #include "ui/views/layout/box_layout.h" | |
13 #include "ui/views/view.h" | |
14 #include "ui/views/widget/widget.h" | |
15 | |
16 namespace { | |
17 | |
18 const int kButtonVerticalMargin = 10; | |
19 const int kButtonHorizontalMargin = 20; | |
20 const SkColor kButtonNormalBackgroundColor = SK_ColorWHITE; | |
21 const SkColor kButtonHoveredBackgroundColor = SkColorSetRGB(0xf5, 0xf5, 0xf5); | |
22 | |
23 class QuietModeButton : public views::TextButton { | |
24 public: | |
25 QuietModeButton(views::ButtonListener* listener, int message_id) | |
26 : views::TextButton(listener, l10n_util::GetStringUTF16(message_id)) { | |
27 set_border(views::Border::CreateEmptyBorder( | |
28 kButtonVerticalMargin, kButtonHorizontalMargin, | |
29 kButtonVerticalMargin, kButtonHorizontalMargin)); | |
30 set_alignment(views::TextButtonBase::ALIGN_LEFT); | |
31 set_background(views::Background::CreateSolidBackground( | |
32 kButtonNormalBackgroundColor)); | |
33 } | |
34 | |
35 protected: | |
36 virtual void StateChanged() OVERRIDE { | |
37 set_background(views::Background::CreateSolidBackground( | |
38 (state() == views::CustomButton::STATE_HOVERED) ? | |
39 kButtonHoveredBackgroundColor : kButtonNormalBackgroundColor)); | |
40 } | |
41 }; | |
42 | |
43 } // namespace | |
44 | |
45 namespace message_center { | |
46 | |
47 QuietModeBubble::QuietModeBubble(views::View* anchor_view, | |
48 gfx::NativeView parent_window, | |
49 NotificationList* notification_list) | |
50 : notification_list_(notification_list) { | |
51 DCHECK(notification_list_); | |
52 bubble_ = new views::BubbleDelegateView( | |
53 anchor_view, views::BubbleBorder::BOTTOM_RIGHT); | |
54 bubble_->set_notify_enter_exit_on_child(true); | |
55 bubble_->SetPaintToLayer(true); | |
56 bubble_->SetFillsBoundsOpaquely(true); | |
57 bubble_->set_parent_window(parent_window); | |
58 bubble_->set_margins(gfx::Insets()); | |
59 InitializeBubbleContents(); | |
60 views::BubbleDelegateView::CreateBubble(bubble_); | |
61 bubble_->Show(); | |
62 } | |
63 | |
64 QuietModeBubble::~QuietModeBubble() { | |
65 Close(); | |
66 } | |
67 | |
68 void QuietModeBubble::Close() { | |
69 if (bubble_) { | |
70 bubble_->GetWidget()->Close(); | |
71 bubble_ = NULL; | |
72 quiet_mode_ = NULL; | |
73 quiet_mode_1hour_ = NULL; | |
74 quiet_mode_1day_ = NULL; | |
75 } | |
76 } | |
77 | |
78 void QuietModeBubble::InitializeBubbleContents() { | |
79 views::View* contents_view = bubble_->GetContentsView(); | |
80 contents_view->SetLayoutManager( | |
81 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | |
82 // TODO(mukai): Determine the actual UI to denote "enter/exit" quiet mode. | |
83 quiet_mode_ = new QuietModeButton( | |
84 this, (notification_list_->quiet_mode()) ? | |
85 IDS_MESSAGE_CENTER_QUIET_MODE_EXIT : IDS_MESSAGE_CENTER_QUIET_MODE); | |
86 contents_view->AddChildView(quiet_mode_); | |
87 quiet_mode_1hour_ = new QuietModeButton( | |
88 this, IDS_MESSAGE_CENTER_QUIET_MODE_1HOUR); | |
89 contents_view->AddChildView(quiet_mode_1hour_); | |
90 quiet_mode_1day_ = new QuietModeButton( | |
91 this, IDS_MESSAGE_CENTER_QUIET_MODE_1DAY); | |
92 contents_view->AddChildView(quiet_mode_1day_); | |
93 } | |
94 | |
95 void QuietModeBubble::ButtonPressed(views::Button* sender, | |
96 const ui::Event& event) { | |
97 DCHECK(sender == quiet_mode_ || | |
98 sender == quiet_mode_1hour_ || sender == quiet_mode_1day_); | |
99 if (sender == quiet_mode_) { | |
100 notification_list_->SetQuietMode(!notification_list_->quiet_mode()); | |
101 LOG(INFO) << notification_list_->quiet_mode(); | |
102 } else { | |
103 base::TimeDelta expires_in = (sender == quiet_mode_1day_) ? | |
104 base::TimeDelta::FromDays(1) : base::TimeDelta::FromHours(1); | |
105 notification_list_->EnterQuietModeWithExpire(expires_in); | |
106 } | |
107 Close(); | |
108 } | |
109 | |
110 } // namespace messge_center | |
miket_OOO
2012/11/21 01:18:21
spelling
Jun Mukai
2012/11/21 19:33:06
Done.
| |
OLD | NEW |