Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/display/display_util.h" | 5 #include "ash/display/display_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/new_window_controller.h" | 10 #include "ash/common/new_window_controller.h" |
| 11 #include "ash/common/system/system_notifier.h" | 11 #include "ash/common/system/system_notifier.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/display/extended_mouse_warp_controller.h" | 13 #include "ash/display/extended_mouse_warp_controller.h" |
| 14 #include "ash/display/null_mouse_warp_controller.h" | 14 #include "ash/display/null_mouse_warp_controller.h" |
| 15 #include "ash/display/unified_mouse_warp_controller.h" | 15 #include "ash/display/unified_mouse_warp_controller.h" |
| 16 #include "ash/host/ash_window_tree_host.h" | 16 #include "ash/host/ash_window_tree_host.h" |
| 17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "grit/ash_resources.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "grit/ash_strings.h" | |
| 20 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
| 21 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | |
| 24 #include "ui/display/display.h" | 24 #include "ui/display/display.h" |
| 25 #include "ui/display/manager/display_manager.h" | 25 #include "ui/display/manager/display_manager.h" |
| 26 #include "ui/display/manager/managed_display_info.h" | 26 #include "ui/display/manager/managed_display_info.h" |
| 27 #include "ui/gfx/geometry/point.h" | 27 #include "ui/gfx/geometry/point.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 29 #include "ui/gfx/geometry/size_conversions.h" | 29 #include "ui/gfx/geometry/size_conversions.h" |
| 30 #include "ui/message_center/message_center.h" | 30 #include "ui/message_center/message_center.h" |
| 31 #include "ui/message_center/notification.h" | 31 #include "ui/message_center/notification.h" |
| 32 #include "ui/message_center/notification_delegate.h" | 32 #include "ui/message_center/notification_delegate.h" |
| 33 #include "ui/message_center/notification_list.h" | 33 #include "ui/message_center/notification_list.h" |
| 34 #include "ui/wm/core/coordinate_conversion.h" | 34 #include "ui/wm/core/coordinate_conversion.h" |
| 35 | 35 |
| 36 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 37 #include "ash/resources/vector_icons/vector_icons.h" | |
| 37 #include "base/sys_info.h" | 38 #include "base/sys_info.h" |
| 39 #include "ui/gfx/paint_vector_icon.h" | |
| 38 #endif | 40 #endif |
| 39 | 41 |
| 40 namespace ash { | 42 namespace ash { |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 const char kDisplayErrorNotificationId[] = "chrome://settings/display/error"; | 45 const char kDisplayErrorNotificationId[] = "chrome://settings/display/error"; |
| 44 | 46 |
| 47 #if defined(OS_CHROMEOS) | |
| 48 // TODO(glevin): These are for new MD vector icons, but are using pre-MD color | |
| 49 // scheme. When we switch to all MD icons for notifications, these should be | |
| 50 // updated to use MD color scheme. | |
| 51 const SkColor kDisplayIconColor = SkColorSetRGB(0xBD, 0xBD, 0xBD); | |
| 52 const SkColor kFeedbackIconColor = SkColorSetRGB(0x96, 0x96, 0x98); | |
| 53 #endif | |
| 54 | |
| 45 // A notification delegate that will start the feedback app when the notication | 55 // A notification delegate that will start the feedback app when the notication |
| 46 // is clicked. | 56 // is clicked. |
| 47 class DisplayErrorNotificationDelegate | 57 class DisplayErrorNotificationDelegate |
| 48 : public message_center::NotificationDelegate { | 58 : public message_center::NotificationDelegate { |
| 49 public: | 59 public: |
| 50 DisplayErrorNotificationDelegate() = default; | 60 DisplayErrorNotificationDelegate() = default; |
| 51 | 61 |
| 52 // message_center::NotificationDelegate: | 62 // message_center::NotificationDelegate: |
| 53 bool HasClickedListener() override { return true; } | 63 void ButtonClick(int index) override { |
| 54 | 64 DCHECK_EQ(0, index); |
| 55 void Click() override { | |
| 56 WmShell::Get()->new_window_controller()->OpenFeedbackPage(); | 65 WmShell::Get()->new_window_controller()->OpenFeedbackPage(); |
| 57 } | 66 } |
| 58 | 67 |
| 59 private: | 68 private: |
| 60 // Private destructor since NotificationDelegate is ref-counted. | 69 // Private destructor since NotificationDelegate is ref-counted. |
| 61 ~DisplayErrorNotificationDelegate() override = default; | 70 ~DisplayErrorNotificationDelegate() override = default; |
| 62 | 71 |
| 63 DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate); | 72 DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate); |
| 64 }; | 73 }; |
| 65 | 74 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 new_point_in_screen = point_in_native; | 165 new_point_in_screen = point_in_native; |
| 157 host->ConvertScreenInPixelsToDIP(&new_point_in_screen); | 166 host->ConvertScreenInPixelsToDIP(&new_point_in_screen); |
| 158 ::wm::ConvertPointToScreen(host->window(), &new_point_in_screen); | 167 ::wm::ConvertPointToScreen(host->window(), &new_point_in_screen); |
| 159 } | 168 } |
| 160 aura::Env::GetInstance()->set_last_mouse_location(new_point_in_screen); | 169 aura::Env::GetInstance()->set_last_mouse_location(new_point_in_screen); |
| 161 } | 170 } |
| 162 } | 171 } |
| 163 | 172 |
| 164 | 173 |
| 165 #if defined(OS_CHROMEOS) | 174 #if defined(OS_CHROMEOS) |
| 166 void ShowDisplayErrorNotification(int message_id) { | 175 void ShowDisplayErrorNotification(base::string16& message, |
| 176 bool allow_feedback) { | |
| 167 // Always remove the notification to make sure the notification appears | 177 // Always remove the notification to make sure the notification appears |
| 168 // as a popup in any situation. | 178 // as a popup in any situation. |
| 169 message_center::MessageCenter::Get()->RemoveNotification( | 179 message_center::MessageCenter::Get()->RemoveNotification( |
| 170 kDisplayErrorNotificationId, false /* by_user */); | 180 kDisplayErrorNotificationId, false /* by_user */); |
| 171 | 181 |
| 172 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 182 message_center::RichNotificationData optional_field; |
|
Evan Stade
2016/12/12 23:44:17
nit: this variable name strikes me as a little odd
Greg Levin
2016/12/13 01:48:59
I was just going for consistency by copying some e
Evan Stade
2016/12/13 01:56:13
data is fine. |RichNotificationDetails| would be m
| |
| 183 if (allow_feedback) { | |
| 184 message_center::ButtonInfo send_button( | |
| 185 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_SEND_FEEDBACK)); | |
| 186 send_button.icon = gfx::Image( | |
| 187 CreateVectorIcon(kNotificationFeedbackButtonIcon, kFeedbackIconColor)); | |
| 188 optional_field.buttons.push_back(send_button); | |
| 189 } | |
| 190 | |
| 173 std::unique_ptr<message_center::Notification> notification( | 191 std::unique_ptr<message_center::Notification> notification( |
| 174 new message_center::Notification( | 192 new message_center::Notification( |
| 175 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, | 193 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, |
| 176 base::string16(), // title | 194 base::string16(), // title |
| 177 l10n_util::GetStringUTF16(message_id), | 195 message, gfx::Image(CreateVectorIcon(kNotificationDisplayErrorIcon, |
| 178 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 196 kDisplayIconColor)), |
| 179 base::string16(), // display_source | 197 base::string16(), // display_source |
| 180 GURL(), message_center::NotifierId( | 198 GURL(), message_center::NotifierId( |
| 181 message_center::NotifierId::SYSTEM_COMPONENT, | 199 message_center::NotifierId::SYSTEM_COMPONENT, |
| 182 system_notifier::kNotifierDisplayError), | 200 system_notifier::kNotifierDisplayError), |
| 183 message_center::RichNotificationData(), | 201 optional_field, new DisplayErrorNotificationDelegate)); |
| 184 new DisplayErrorNotificationDelegate)); | |
| 185 message_center::MessageCenter::Get()->AddNotification( | 202 message_center::MessageCenter::Get()->AddNotification( |
| 186 std::move(notification)); | 203 std::move(notification)); |
| 187 } | 204 } |
| 188 #endif | 205 #endif |
| 189 | 206 |
| 190 base::string16 GetDisplayErrorNotificationMessageForTest() { | 207 base::string16 GetDisplayErrorNotificationMessageForTest() { |
| 191 message_center::NotificationList::Notifications notifications = | 208 message_center::NotificationList::Notifications notifications = |
| 192 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 209 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 193 for (auto* const notification : notifications) { | 210 for (auto* const notification : notifications) { |
| 194 if (notification->id() == kDisplayErrorNotificationId) | 211 if (notification->id() == kDisplayErrorNotificationId) |
| 195 return notification->message(); | 212 return notification->message(); |
| 196 } | 213 } |
| 197 return base::string16(); | 214 return base::string16(); |
| 198 } | 215 } |
| 199 | 216 |
| 200 } // namespace ash | 217 } // namespace ash |
| OLD | NEW |