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 "chrome/browser/chromeos/ui/idle_app_name_notification_view.h" | 5 #include "chrome/browser/chromeos/ui/idle_app_name_notification_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Color of the text of the warning message. | 45 // Color of the text of the warning message. |
46 const SkColor kErrorTextColor = SK_ColorRED; | 46 const SkColor kErrorTextColor = SK_ColorRED; |
47 | 47 |
48 // Color of the window background. | 48 // Color of the window background. |
49 const SkColor kWindowBackgroundColor = SK_ColorWHITE; | 49 const SkColor kWindowBackgroundColor = SK_ColorWHITE; |
50 | 50 |
51 // Radius of the rounded corners of the window. | 51 // Radius of the rounded corners of the window. |
52 const int kWindowCornerRadius = 4; | 52 const int kWindowCornerRadius = 4; |
53 | 53 |
54 // Creates and shows the message widget for |view| with |animation_time_ms|. | 54 // Creates and shows the message widget for |view| with |animation_time_ms|. |
55 void CreateAndShowWidgetWithContent(views::WidgetDelegate* delegate, | 55 void CreateAndShowWidget(views::WidgetDelegateView* delegate, |
56 views::View* view, | 56 int animation_time_ms) { |
57 int animation_time_ms) { | |
58 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); | 57 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); |
59 gfx::Size rs = root_window->bounds().size(); | 58 gfx::Size rs = root_window->bounds().size(); |
60 gfx::Size ps = view->GetPreferredSize(); | 59 gfx::Size ps = delegate->GetPreferredSize(); |
61 gfx::Rect bounds((rs.width() - ps.width()) / 2, | 60 gfx::Rect bounds((rs.width() - ps.width()) / 2, |
62 -ps.height(), | 61 -ps.height(), |
63 ps.width(), | 62 ps.width(), |
64 ps.height()); | 63 ps.height()); |
65 views::Widget::InitParams params; | 64 views::Widget::InitParams params; |
66 params.type = views::Widget::InitParams::TYPE_POPUP; | 65 params.type = views::Widget::InitParams::TYPE_POPUP; |
67 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 66 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
68 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; | 67 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; |
69 params.accept_events = false; | 68 params.accept_events = false; |
70 params.keep_on_top = true; | 69 params.keep_on_top = true; |
71 params.remove_standard_frame = true; | 70 params.remove_standard_frame = true; |
72 params.delegate = delegate; | 71 params.delegate = delegate; |
73 params.bounds = bounds; | 72 params.bounds = bounds; |
74 params.parent = ash::Shell::GetContainer( | 73 params.parent = ash::Shell::GetContainer( |
75 root_window, ash::kShellWindowId_SettingBubbleContainer); | 74 root_window, ash::kShellWindowId_SettingBubbleContainer); |
76 views::Widget* widget = new views::Widget; | 75 views::Widget* widget = new views::Widget; |
77 widget->Init(params); | 76 widget->Init(params); |
78 widget->SetContentsView(view); | |
79 gfx::NativeView native_view = widget->GetNativeView(); | 77 gfx::NativeView native_view = widget->GetNativeView(); |
80 native_view->SetName("KioskIdleAppNameNotification"); | 78 native_view->SetName("KioskIdleAppNameNotification"); |
81 | 79 |
82 // Note: We cannot use the Window show/hide animations since they are disabled | 80 // Note: We cannot use the Window show/hide animations since they are disabled |
83 // for kiosk by command line. | 81 // for kiosk by command line. |
84 ui::LayerAnimator* animator = new ui::LayerAnimator( | 82 ui::LayerAnimator* animator = new ui::LayerAnimator( |
85 base::TimeDelta::FromMilliseconds(animation_time_ms)); | 83 base::TimeDelta::FromMilliseconds(animation_time_ms)); |
86 native_view->layer()->SetAnimator(animator); | 84 native_view->layer()->SetAnimator(animator); |
87 widget->Show(); | 85 widget->Show(); |
88 | 86 |
89 // We don't care about the show animation since it is off screen, so stop the | 87 // We don't care about the show animation since it is off screen, so stop the |
90 // started animation and move the message into view. | 88 // started animation and move the message into view. |
91 animator->StopAnimating(); | 89 animator->StopAnimating(); |
92 bounds.set_y((rs.height() - ps.height()) / 20); | 90 bounds.set_y((rs.height() - ps.height()) / 20); |
93 widget->SetBounds(bounds); | 91 widget->SetBounds(bounds); |
94 | 92 |
95 // Allow to use the message for spoken feedback. | 93 // Allow to use the message for spoken feedback. |
96 view->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 94 delegate->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
97 } | 95 } |
98 | 96 |
99 } // namespace | 97 } // namespace |
100 | 98 |
101 // The class which implements the content view for the message. | 99 // The class which implements the content view for the message. |
102 class IdleAppNameNotificationDelegateView | 100 class IdleAppNameNotificationDelegateView |
103 : public views::WidgetDelegateView, | 101 : public views::WidgetDelegateView, |
104 public ui::ImplicitAnimationObserver { | 102 public ui::ImplicitAnimationObserver { |
105 public: | 103 public: |
106 // An idle message which will get shown from the caller and hides itself after | 104 // An idle message which will get shown from the caller and hides itself after |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 error = true; | 258 error = true; |
261 app_name = l10n_util::GetStringUTF16( | 259 app_name = l10n_util::GetStringUTF16( |
262 IDS_IDLE_APP_NAME_UNKNOWN_APPLICATION_NOTIFICATION); | 260 IDS_IDLE_APP_NAME_UNKNOWN_APPLICATION_NOTIFICATION); |
263 } | 261 } |
264 | 262 |
265 view_ = new IdleAppNameNotificationDelegateView( | 263 view_ = new IdleAppNameNotificationDelegateView( |
266 this, | 264 this, |
267 app_name, | 265 app_name, |
268 error, | 266 error, |
269 message_visibility_time_in_ms + animation_time_ms); | 267 message_visibility_time_in_ms + animation_time_ms); |
270 CreateAndShowWidgetWithContent(view_, view_, animation_time_ms); | 268 CreateAndShowWidget(view_, animation_time_ms); |
271 } | 269 } |
272 | 270 |
273 } // namespace chromeos | 271 } // namespace chromeos |
OLD | NEW |