Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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/views/message_center_button_bar.h" | |
| 6 | |
| 7 #include "grit/ui_resources.h" | |
| 8 #include "grit/ui_strings.h" | |
| 9 #include "ui/base/l10n/l10n_util.h" | |
| 10 #include "ui/base/models/simple_menu_model.h" | |
| 11 #include "ui/base/resource/resource_bundle.h" | |
| 12 #include "ui/gfx/canvas.h" | |
| 13 #include "ui/gfx/text_constants.h" | |
| 14 #include "ui/message_center/message_center.h" | |
| 15 #include "ui/message_center/message_center_style.h" | |
| 16 #include "ui/message_center/notifier_settings.h" | |
| 17 #include "ui/message_center/views/message_center_view.h" | |
| 18 #include "ui/views/controls/button/button.h" | |
| 19 #include "ui/views/controls/button/image_button.h" | |
| 20 #include "ui/views/controls/button/label_button.h" | |
| 21 #include "ui/views/controls/button/menu_button.h" | |
| 22 #include "ui/views/controls/button/menu_button_listener.h" | |
| 23 #include "ui/views/controls/label.h" | |
| 24 #include "ui/views/controls/menu/menu_runner.h" | |
| 25 #include "ui/views/layout/box_layout.h" | |
| 26 #include "ui/views/layout/grid_layout.h" | |
| 27 | |
| 28 namespace message_center { | |
| 29 | |
| 30 namespace { | |
| 31 const int kButtonSize = 40; | |
| 32 const int kChevronMargin = 4; | |
| 33 const int kFooterLeftMargin = 17; | |
| 34 const int kFooterRightMargin = 14; | |
| 35 } // namespace | |
| 36 | |
| 37 // NotificationCenterButton //////////////////////////////////////////////////// | |
| 38 //////////////////////////////////////////////////////////////////////////////// | |
| 39 class NotificationCenterButton : public views::ToggleImageButton { | |
| 40 public: | |
| 41 NotificationCenterButton(views::ButtonListener* listener, | |
| 42 int normal_id, | |
| 43 int hover_id, | |
| 44 int pressed_id, | |
| 45 int text_id); | |
| 46 | |
| 47 protected: | |
| 48 // Overridden from views::View: | |
| 49 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 50 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; | |
| 51 | |
| 52 private: | |
| 53 DISALLOW_COPY_AND_ASSIGN(NotificationCenterButton); | |
| 54 }; | |
| 55 | |
| 56 NotificationCenterButton::NotificationCenterButton( | |
| 57 views::ButtonListener* listener, | |
| 58 int normal_id, | |
| 59 int hover_id, | |
| 60 int pressed_id, | |
| 61 int text_id) | |
| 62 : views::ToggleImageButton(listener) { | |
| 63 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 64 SetImage(STATE_NORMAL, resource_bundle.GetImageSkiaNamed(normal_id)); | |
| 65 SetImage(STATE_HOVERED, resource_bundle.GetImageSkiaNamed(hover_id)); | |
| 66 SetImage(STATE_PRESSED, resource_bundle.GetImageSkiaNamed(pressed_id)); | |
| 67 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
| 68 views::ImageButton::ALIGN_MIDDLE); | |
| 69 SetTooltipText(resource_bundle.GetLocalizedString(text_id)); | |
| 70 set_focusable(true); | |
| 71 set_request_focus_on_press(false); | |
| 72 } | |
| 73 | |
| 74 gfx::Size NotificationCenterButton::GetPreferredSize() { | |
| 75 return gfx::Size(kButtonSize, kButtonSize); | |
| 76 } | |
| 77 | |
| 78 void NotificationCenterButton::OnPaintFocusBorder(gfx::Canvas* canvas) { | |
| 79 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) { | |
| 80 canvas->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3), | |
| 81 kFocusBorderColor); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 // MessageCenterButtonBar ///////////////////////////////////////////////////// | |
| 86 /////////////////////////////////////////////////////////////////////////////// | |
| 87 MessageCenterButtonBar::MessageCenterButtonBar( | |
| 88 MessageCenterView* message_center_view, | |
| 89 MessageCenter* message_center, | |
| 90 NotifierSettingsProvider* notifier_settings_provider, | |
| 91 bool settings_initially_visible) | |
| 92 : message_center_view_(message_center_view), | |
| 93 message_center_(message_center), | |
| 94 close_all_button_(NULL) { | |
|
jianli
2013/08/05 20:48:03
bit: better to also initialize quiet_mode_button_
dewittj
2013/08/05 22:42:28
Done.
| |
| 95 if (get_use_acceleration_when_possible()) | |
| 96 SetPaintToLayer(true); | |
| 97 set_background( | |
| 98 views::Background::CreateSolidBackground(kMessageCenterBackgroundColor)); | |
| 99 | |
| 100 views::Label* notification_label = new views::Label( | |
| 101 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_FOOTER_TITLE)); | |
| 102 notification_label->SetAutoColorReadabilityEnabled(false); | |
| 103 notification_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 104 notification_label->SetEnabledColor(kRegularTextColor); | |
| 105 AddChildView(notification_label); | |
| 106 | |
| 107 views::View* button_container = new views::View; | |
| 108 button_container->SetLayoutManager( | |
| 109 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 110 quiet_mode_button_ = new NotificationCenterButton( | |
| 111 this, | |
| 112 IDR_NOTIFICATION_DO_NOT_DISTURB, | |
| 113 IDR_NOTIFICATION_DO_NOT_DISTURB_HOVER, | |
| 114 IDR_NOTIFICATION_DO_NOT_DISTURB_PRESSED, | |
| 115 IDS_MESSAGE_CENTER_QUIET_MODE_BUTTON_TOOLTIP); | |
| 116 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 117 quiet_mode_button_->SetToggledImage( | |
| 118 views::Button::STATE_NORMAL, | |
| 119 resource_bundle.GetImageSkiaNamed( | |
| 120 IDR_NOTIFICATION_DO_NOT_DISTURB_PRESSED)); | |
| 121 quiet_mode_button_->SetToggledImage( | |
| 122 views::Button::STATE_HOVERED, | |
| 123 resource_bundle.GetImageSkiaNamed( | |
| 124 IDR_NOTIFICATION_DO_NOT_DISTURB_PRESSED)); | |
| 125 quiet_mode_button_->SetToggledImage( | |
| 126 views::Button::STATE_PRESSED, | |
| 127 resource_bundle.GetImageSkiaNamed( | |
| 128 IDR_NOTIFICATION_DO_NOT_DISTURB_PRESSED)); | |
| 129 quiet_mode_button_->SetToggled(message_center->IsQuietMode()); | |
| 130 button_container->AddChildView(quiet_mode_button_); | |
| 131 | |
| 132 close_all_button_ = | |
| 133 new NotificationCenterButton(this, | |
| 134 IDR_NOTIFICATION_CLEAR_ALL, | |
| 135 IDR_NOTIFICATION_CLEAR_ALL_HOVER, | |
| 136 IDR_NOTIFICATION_CLEAR_ALL_PRESSED, | |
| 137 IDS_MESSAGE_CENTER_CLEAR_ALL); | |
| 138 button_container->AddChildView(close_all_button_); | |
| 139 settings_button_ = | |
| 140 new NotificationCenterButton(this, | |
| 141 IDR_NOTIFICATION_SETTINGS, | |
| 142 IDR_NOTIFICATION_SETTINGS_HOVER, | |
| 143 IDR_NOTIFICATION_SETTINGS_PRESSED, | |
| 144 IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL); | |
| 145 button_container->AddChildView(settings_button_); | |
| 146 | |
| 147 gfx::ImageSkia* settings_image = | |
| 148 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 149 IDR_NOTIFICATION_SETTINGS); | |
| 150 int image_margin = std::max(0, (kButtonSize - settings_image->width()) / 2); | |
| 151 views::GridLayout* layout = new views::GridLayout(this); | |
| 152 SetLayoutManager(layout); | |
| 153 layout->SetInsets( | |
| 154 0, kFooterLeftMargin, 0, std::max(0, kFooterRightMargin - image_margin)); | |
| 155 views::ColumnSet* column = layout->AddColumnSet(0); | |
| 156 column->AddColumn(views::GridLayout::FILL, | |
| 157 views::GridLayout::FILL, | |
| 158 1.0f, | |
| 159 views::GridLayout::USE_PREF, | |
| 160 0, | |
| 161 0); | |
| 162 column->AddColumn(views::GridLayout::LEADING, | |
| 163 views::GridLayout::FILL, | |
| 164 0, | |
| 165 views::GridLayout::USE_PREF, | |
| 166 0, | |
| 167 0); | |
| 168 layout->StartRow(0, 0); | |
| 169 layout->AddView(notification_label); | |
| 170 layout->AddView(button_container); | |
| 171 } | |
| 172 | |
| 173 MessageCenterButtonBar::~MessageCenterButtonBar() {} | |
| 174 | |
| 175 void MessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) { | |
| 176 if (close_all_button_) | |
| 177 close_all_button_->SetEnabled(enabled); | |
| 178 settings_button_->SetEnabled(enabled); | |
| 179 quiet_mode_button_->SetEnabled(enabled); | |
| 180 } | |
| 181 | |
| 182 void MessageCenterButtonBar::SetCloseAllVisible(bool visible) { | |
| 183 if (close_all_button_) | |
| 184 close_all_button_->SetVisible(visible); | |
| 185 } | |
| 186 | |
| 187 void MessageCenterButtonBar::ChildVisibilityChanged(views::View* child) { | |
| 188 InvalidateLayout(); | |
| 189 } | |
| 190 | |
| 191 void MessageCenterButtonBar::ButtonPressed(views::Button* sender, | |
| 192 const ui::Event& event) { | |
| 193 if (sender == close_all_button()) { | |
|
jianli
2013/08/05 20:48:03
nit: close_all_button_
dewittj
2013/08/05 22:42:28
Done.
| |
| 194 message_center_view()->ClearAllNotifications(); | |
| 195 } else if (sender == settings_button_) { | |
| 196 MessageCenterView* center_view = message_center_view(); | |
| 197 center_view->SetSettingsVisible(!center_view->settings_visible()); | |
| 198 } else if (sender == quiet_mode_button_) { | |
| 199 if (message_center()->IsQuietMode()) | |
| 200 message_center()->SetQuietMode(false); | |
| 201 else | |
| 202 message_center()->EnterQuietModeWithExpire(base::TimeDelta::FromDays(1)); | |
| 203 quiet_mode_button_->SetToggled(message_center()->IsQuietMode()); | |
| 204 } else { | |
| 205 NOTREACHED(); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 } // namespace message_center | |
| OLD | NEW |