| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/message_center/views/message_center_button_bar.h" | 5 #include "ui/message_center/views/message_center_button_bar.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "ui/base/models/simple_menu_model.h" | 9 #include "ui/base/models/simple_menu_model.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/text_constants.h" | 12 #include "ui/gfx/text_constants.h" |
| 13 #include "ui/message_center/message_center.h" | 13 #include "ui/message_center/message_center.h" |
| 14 #include "ui/message_center/message_center_style.h" | 14 #include "ui/message_center/message_center_style.h" |
| 15 #include "ui/message_center/message_center_tray.h" | 15 #include "ui/message_center/message_center_tray.h" |
| 16 #include "ui/message_center/notifier_settings.h" | 16 #include "ui/message_center/notifier_settings.h" |
| 17 #include "ui/message_center/views/message_center_view.h" | 17 #include "ui/message_center/views/message_center_view.h" |
| 18 #include "ui/resources/grit/ui_resources.h" | 18 #include "ui/resources/grit/ui_resources.h" |
| 19 #include "ui/strings/grit/ui_strings.h" | 19 #include "ui/strings/grit/ui_strings.h" |
| 20 #include "ui/views/border.h" |
| 20 #include "ui/views/controls/button/button.h" | 21 #include "ui/views/controls/button/button.h" |
| 21 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
| 22 #include "ui/views/controls/button/label_button.h" | 23 #include "ui/views/controls/button/label_button.h" |
| 23 #include "ui/views/controls/button/menu_button.h" | 24 #include "ui/views/controls/button/menu_button.h" |
| 24 #include "ui/views/controls/button/menu_button_listener.h" | 25 #include "ui/views/controls/button/menu_button_listener.h" |
| 25 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
| 26 #include "ui/views/controls/menu/menu_runner.h" | 27 #include "ui/views/controls/menu/menu_runner.h" |
| 27 #include "ui/views/layout/box_layout.h" | 28 #include "ui/views/layout/box_layout.h" |
| 28 #include "ui/views/layout/grid_layout.h" | 29 #include "ui/views/layout/grid_layout.h" |
| 29 #include "ui/views/painter.h" | 30 #include "ui/views/painter.h" |
| 30 | 31 |
| 31 namespace message_center { | 32 namespace message_center { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 const int kButtonSize = 40; | 35 constexpr int kButtonSize = 40; |
| 35 const int kLeftPaddingWidthForNonArrows = 16; | |
| 36 const int kFooterTopMargin = 6; | |
| 37 const int kFooterBottomMargin = 3; | |
| 38 const int kFooterLeftMargin = 4; | |
| 39 const int kFooterRightMargin = 14; | |
| 40 } // namespace | 36 } // namespace |
| 41 | 37 |
| 42 // NotificationCenterButton //////////////////////////////////////////////////// | 38 // NotificationCenterButton //////////////////////////////////////////////////// |
| 43 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
| 44 class NotificationCenterButton : public views::ToggleImageButton { | 40 class NotificationCenterButton : public views::ToggleImageButton { |
| 45 public: | 41 public: |
| 46 NotificationCenterButton(views::ButtonListener* listener, | 42 NotificationCenterButton(views::ButtonListener* listener, |
| 47 int normal_id, | 43 int normal_id, |
| 48 int hover_id, | 44 int hover_id, |
| 49 int pressed_id, | 45 int pressed_id, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 resource_bundle.GetImageSkiaNamed(IDR_NOTIFICATION_BUBBLE_CLOSE_PRESSED)); | 179 resource_bundle.GetImageSkiaNamed(IDR_NOTIFICATION_BUBBLE_CLOSE_PRESSED)); |
| 184 AddChildView(close_bubble_button_); | 180 AddChildView(close_bubble_button_); |
| 185 #endif | 181 #endif |
| 186 | 182 |
| 187 SetCloseAllButtonEnabled(!settings_initially_visible); | 183 SetCloseAllButtonEnabled(!settings_initially_visible); |
| 188 SetBackArrowVisible(settings_initially_visible); | 184 SetBackArrowVisible(settings_initially_visible); |
| 189 ViewVisibilityChanged(); | 185 ViewVisibilityChanged(); |
| 190 } | 186 } |
| 191 | 187 |
| 192 void MessageCenterButtonBar::ViewVisibilityChanged() { | 188 void MessageCenterButtonBar::ViewVisibilityChanged() { |
| 193 gfx::ImageSkia* settings_image = | |
| 194 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 195 IDR_NOTIFICATION_SETTINGS); | |
| 196 int image_margin = std::max(0, (kButtonSize - settings_image->width()) / 2); | |
| 197 views::GridLayout* layout = new views::GridLayout(this); | 189 views::GridLayout* layout = new views::GridLayout(this); |
| 198 SetLayoutManager(layout); | 190 SetLayoutManager(layout); |
| 199 layout->SetInsets(kFooterTopMargin, | |
| 200 kFooterLeftMargin, | |
| 201 kFooterBottomMargin, | |
| 202 std::max(0, kFooterRightMargin - image_margin)); | |
| 203 views::ColumnSet* column = layout->AddColumnSet(0); | 191 views::ColumnSet* column = layout->AddColumnSet(0); |
| 192 constexpr int kFooterLeftMargin = 4; |
| 193 column->AddPaddingColumn(0, kFooterLeftMargin); |
| 204 if (title_arrow_->visible()) { | 194 if (title_arrow_->visible()) { |
| 205 // Column for the left-arrow used to back out of settings. | 195 // Column for the left-arrow used to back out of settings. |
| 206 column->AddColumn(views::GridLayout::LEADING, | 196 column->AddColumn(views::GridLayout::LEADING, |
| 207 views::GridLayout::CENTER, | 197 views::GridLayout::CENTER, |
| 208 0.0f, | 198 0.0f, |
| 209 views::GridLayout::FIXED, | 199 views::GridLayout::FIXED, |
| 210 kButtonSize, | 200 kButtonSize, |
| 211 0); | 201 0); |
| 212 } else { | 202 } else { |
| 203 constexpr int kLeftPaddingWidthForNonArrows = 16; |
| 213 column->AddPaddingColumn(0.0f, kLeftPaddingWidthForNonArrows); | 204 column->AddPaddingColumn(0.0f, kLeftPaddingWidthForNonArrows); |
| 214 } | 205 } |
| 215 | 206 |
| 216 // Column for the label "Notifications". | 207 // Column for the label "Notifications". |
| 217 column->AddColumn(views::GridLayout::LEADING, | 208 column->AddColumn(views::GridLayout::LEADING, |
| 218 views::GridLayout::CENTER, | 209 views::GridLayout::CENTER, |
| 219 0.0f, | 210 0.0f, |
| 220 views::GridLayout::USE_PREF, | 211 views::GridLayout::USE_PREF, |
| 221 0, | 212 0, |
| 222 0); | 213 0); |
| 223 | 214 |
| 224 // Fills in the remaining space between "Notifications" and buttons. | 215 // Fills in the remaining space between "Notifications" and buttons. |
| 216 gfx::ImageSkia* settings_image = |
| 217 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 218 IDR_NOTIFICATION_SETTINGS); |
| 219 const int image_margin = |
| 220 std::max(0, (kButtonSize - settings_image->width()) / 2); |
| 225 column->AddPaddingColumn(1.0f, image_margin); | 221 column->AddPaddingColumn(1.0f, image_margin); |
| 226 | 222 |
| 227 // The button area column. | 223 // The button area column. |
| 228 column->AddColumn(views::GridLayout::LEADING, | 224 column->AddColumn(views::GridLayout::LEADING, |
| 229 views::GridLayout::CENTER, | 225 views::GridLayout::CENTER, |
| 230 0.0f, | 226 0.0f, |
| 231 views::GridLayout::USE_PREF, | 227 views::GridLayout::USE_PREF, |
| 232 0, | 228 0, |
| 233 0); | 229 0); |
| 234 | 230 |
| 235 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 231 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 236 // The close-bubble button. | 232 // The close-bubble button. |
| 237 column->AddColumn(views::GridLayout::LEADING, | 233 column->AddColumn(views::GridLayout::LEADING, |
| 238 views::GridLayout::LEADING, | 234 views::GridLayout::LEADING, |
| 239 0.0f, | 235 0.0f, |
| 240 views::GridLayout::USE_PREF, | 236 views::GridLayout::USE_PREF, |
| 241 0, | 237 0, |
| 242 0); | 238 0); |
| 243 #endif | 239 #endif |
| 240 constexpr int kFooterRightMargin = 14; |
| 241 const int right_margin = std::max(0, kFooterRightMargin - image_margin); |
| 242 column->AddPaddingColumn(0, right_margin); |
| 244 | 243 |
| 244 constexpr int kFooterTopMargin = 6; |
| 245 layout->AddPaddingRow(0, kFooterTopMargin); |
| 245 layout->StartRow(0, 0, kButtonSize); | 246 layout->StartRow(0, 0, kButtonSize); |
| 246 if (title_arrow_->visible()) | 247 if (title_arrow_->visible()) |
| 247 layout->AddView(title_arrow_); | 248 layout->AddView(title_arrow_); |
| 248 layout->AddView(notification_label_); | 249 layout->AddView(notification_label_); |
| 249 layout->AddView(button_container_); | 250 layout->AddView(button_container_); |
| 250 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 251 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 251 layout->AddView(close_bubble_button_); | 252 layout->AddView(close_bubble_button_); |
| 252 #endif | 253 #endif |
| 254 constexpr int kFooterBottomMargin = 3; |
| 255 layout->AddPaddingRow(0, kFooterBottomMargin); |
| 253 } | 256 } |
| 254 | 257 |
| 255 MessageCenterButtonBar::~MessageCenterButtonBar() {} | 258 MessageCenterButtonBar::~MessageCenterButtonBar() {} |
| 256 | 259 |
| 257 void MessageCenterButtonBar::SetSettingsAndQuietModeButtonsEnabled( | 260 void MessageCenterButtonBar::SetSettingsAndQuietModeButtonsEnabled( |
| 258 bool enabled) { | 261 bool enabled) { |
| 259 settings_button_->SetEnabled(enabled); | 262 settings_button_->SetEnabled(enabled); |
| 260 quiet_mode_button_->SetEnabled(enabled); | 263 quiet_mode_button_->SetEnabled(enabled); |
| 261 } | 264 } |
| 262 | 265 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 322 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 320 } else if (sender == close_bubble_button_) { | 323 } else if (sender == close_bubble_button_) { |
| 321 message_center_view()->tray()->HideMessageCenterBubble(); | 324 message_center_view()->tray()->HideMessageCenterBubble(); |
| 322 #endif | 325 #endif |
| 323 } else { | 326 } else { |
| 324 NOTREACHED(); | 327 NOTREACHED(); |
| 325 } | 328 } |
| 326 } | 329 } |
| 327 | 330 |
| 328 } // namespace message_center | 331 } // namespace message_center |
| OLD | NEW |