| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_view.h" | 5 #include "ui/message_center/views/message_view.h" |
| 6 | 6 |
| 7 #include "grit/ui_resources.h" | 7 #include "grit/ui_resources.h" |
| 8 #include "grit/ui_strings.h" | 8 #include "grit/ui_strings.h" |
| 9 #include "ui/base/accessibility/accessible_view_state.h" | 9 #include "ui/base/accessibility/accessible_view_state.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/compositor/scoped_layer_animation_settings.h" | 13 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/shadow_value.h" | |
| 16 #include "ui/gfx/skia_util.h" | |
| 17 #include "ui/message_center/message_center.h" | 15 #include "ui/message_center/message_center.h" |
| 18 #include "ui/message_center/message_center_style.h" | 16 #include "ui/message_center/message_center_style.h" |
| 19 #include "ui/message_center/message_center_tray.h" | 17 #include "ui/message_center/message_center_tray.h" |
| 20 #include "ui/message_center/message_center_util.h" | 18 #include "ui/message_center/message_center_util.h" |
| 21 #include "ui/views/context_menu_controller.h" | 19 #include "ui/views/context_menu_controller.h" |
| 22 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
| 23 #include "ui/views/controls/menu/menu_runner.h" | 21 #include "ui/views/controls/menu/menu_runner.h" |
| 24 #include "ui/views/controls/scroll_view.h" | 22 #include "ui/views/controls/scroll_view.h" |
| 23 #include "ui/views/shadow_border.h" |
| 25 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 const int kCloseIconTopPadding = 5; | 28 const int kCloseIconTopPadding = 5; |
| 30 const int kCloseIconRightPadding = 5; | 29 const int kCloseIconRightPadding = 5; |
| 31 const int kExpandIconBottomPadding = 8; | 30 const int kExpandIconBottomPadding = 8; |
| 32 const int kExpandIconRightPadding = 11; | 31 const int kExpandIconRightPadding = 11; |
| 33 | 32 |
| 34 const int kShadowOffset = 1; | 33 const int kShadowOffset = 1; |
| 35 const int kShadowBlur = 4; | 34 const int kShadowBlur = 4; |
| 36 | 35 |
| 37 const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); | |
| 38 | |
| 39 // Menu constants | 36 // Menu constants |
| 40 const int kTogglePermissionCommand = 0; | 37 const int kTogglePermissionCommand = 0; |
| 41 const int kToggleExtensionCommand = 1; | 38 const int kToggleExtensionCommand = 1; |
| 42 const int kShowSettingsCommand = 2; | 39 const int kShowSettingsCommand = 2; |
| 43 | 40 |
| 44 // ControlButtons are ImageButtons whose image can be padded within the button. | 41 // ControlButtons are ImageButtons whose image can be padded within the button. |
| 45 // This allows the creation of buttons like the notification close and expand | 42 // This allows the creation of buttons like the notification close and expand |
| 46 // buttons whose clickable areas extends beyond their image areas | 43 // buttons whose clickable areas extends beyond their image areas |
| 47 // (<http://crbug.com/168822>) without the need to create and maintain | 44 // (<http://crbug.com/168822>) without the need to create and maintain |
| 48 // corresponding resource images with alpha padding. In the future, this class | 45 // corresponding resource images with alpha padding. In the future, this class |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 offset.set_x(bounds.width() - image.width()); // Right align. | 155 offset.set_x(bounds.width() - image.width()); // Right align. |
| 159 | 156 |
| 160 if (padding_.top() == 0 && padding_.bottom() == 0) | 157 if (padding_.top() == 0 && padding_.bottom() == 0) |
| 161 offset.set_y((bounds.height() - image.height()) / 2); // Middle align. | 158 offset.set_y((bounds.height() - image.height()) / 2); // Middle align. |
| 162 else if (padding_.bottom() > 0) | 159 else if (padding_.bottom() > 0) |
| 163 offset.set_y(bounds.height() - image.height()); // Bottom align. | 160 offset.set_y(bounds.height() - image.height()); // Bottom align. |
| 164 | 161 |
| 165 return bounds.origin() + offset; | 162 return bounds.origin() + offset; |
| 166 } | 163 } |
| 167 | 164 |
| 168 // A border to provide the shadow for each card. | |
| 169 // Current shadow should look like css box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3) | |
| 170 class ShadowBorder : public views::Border { | |
| 171 public: | |
| 172 ShadowBorder() : views::Border() {} | |
| 173 virtual ~ShadowBorder() {} | |
| 174 | |
| 175 protected: | |
| 176 // Overridden from views::Border: | |
| 177 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; | |
| 178 virtual gfx::Insets GetInsets() const OVERRIDE; | |
| 179 | |
| 180 DISALLOW_COPY_AND_ASSIGN(ShadowBorder); | |
| 181 }; | |
| 182 | |
| 183 void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) { | |
| 184 SkPaint paint; | |
| 185 std::vector<gfx::ShadowValue> shadows; | |
| 186 shadows.push_back(gfx::ShadowValue(gfx::Point(), kShadowBlur, | |
| 187 message_center::kShadowColor)); | |
| 188 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows); | |
| 189 paint.setLooper(looper.get()); | |
| 190 paint.setColor(kTransparentColor); | |
| 191 paint.setStrokeJoin(SkPaint::kRound_Join); | |
| 192 gfx::Rect bounds(view.size()); | |
| 193 bounds.Inset(gfx::Insets(kShadowBlur / 2, kShadowBlur / 2, | |
| 194 kShadowBlur / 2, kShadowBlur / 2)); | |
| 195 canvas->DrawRect(bounds, paint); | |
| 196 } | |
| 197 | |
| 198 gfx::Insets ShadowBorder::GetInsets() const { | |
| 199 return message_center::MessageView::GetShadowInsets(); | |
| 200 } | |
| 201 | |
| 202 // A dropdown menu for notifications. | 165 // A dropdown menu for notifications. |
| 203 class MenuModel : public ui::SimpleMenuModel, | 166 class MenuModel : public ui::SimpleMenuModel, |
| 204 public ui::SimpleMenuModel::Delegate { | 167 public ui::SimpleMenuModel::Delegate { |
| 205 public: | 168 public: |
| 206 MenuModel(message_center::MessageCenter* message_center, | 169 MenuModel(message_center::MessageCenter* message_center, |
| 207 message_center::MessageCenterTray* tray, | 170 message_center::MessageCenterTray* tray, |
| 208 const std::string& notification_id, | 171 const std::string& notification_id, |
| 209 const string16& display_source, | 172 const string16& display_source, |
| 210 const std::string& extension_id); | 173 const std::string& extension_id); |
| 211 virtual ~MenuModel(); | 174 virtual ~MenuModel(); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 357 |
| 395 // static | 358 // static |
| 396 gfx::Insets MessageView::GetShadowInsets() { | 359 gfx::Insets MessageView::GetShadowInsets() { |
| 397 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, | 360 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, |
| 398 kShadowBlur / 2, | 361 kShadowBlur / 2, |
| 399 kShadowBlur / 2 + kShadowOffset, | 362 kShadowBlur / 2 + kShadowOffset, |
| 400 kShadowBlur / 2); | 363 kShadowBlur / 2); |
| 401 } | 364 } |
| 402 | 365 |
| 403 void MessageView::CreateShadowBorder() { | 366 void MessageView::CreateShadowBorder() { |
| 404 set_border(new ShadowBorder()); | 367 set_border(new views::ShadowBorder(kShadowBlur, |
| 368 message_center::kShadowColor, |
| 369 kShadowOffset, // Vertical offset. |
| 370 0)); // Horizontal offset. |
| 405 } | 371 } |
| 406 | 372 |
| 407 bool MessageView::IsCloseButtonFocused() { | 373 bool MessageView::IsCloseButtonFocused() { |
| 408 views::FocusManager* focus_manager = GetFocusManager(); | 374 views::FocusManager* focus_manager = GetFocusManager(); |
| 409 return focus_manager && focus_manager->GetFocusedView() == close_button(); | 375 return focus_manager && focus_manager->GetFocusedView() == close_button(); |
| 410 } | 376 } |
| 411 | 377 |
| 412 void MessageView::RequestFocusOnCloseButton() { | 378 void MessageView::RequestFocusOnCloseButton() { |
| 413 close_button_->RequestFocus(); | 379 close_button_->RequestFocus(); |
| 414 } | 380 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 is_expanded_ = true; | 453 is_expanded_ = true; |
| 488 message_center_->ExpandNotification(notification_id_); | 454 message_center_->ExpandNotification(notification_id_); |
| 489 } | 455 } |
| 490 } | 456 } |
| 491 | 457 |
| 492 void MessageView::OnSlideOut() { | 458 void MessageView::OnSlideOut() { |
| 493 message_center_->RemoveNotification(notification_id_, true); // By user. | 459 message_center_->RemoveNotification(notification_id_, true); // By user. |
| 494 } | 460 } |
| 495 | 461 |
| 496 } // namespace message_center | 462 } // namespace message_center |
| OLD | NEW |