| 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 "ash/system/web_notification/web_notification_view.h" | 5 #include "ash/system/web_notification/web_notification_view.h" |
| 6 | 6 |
| 7 #include "ash/system/tray/tray_constants.h" | 7 #include "ash/system/tray/tray_constants.h" |
| 8 #include "ash/system/tray/tray_views.h" | 8 #include "ash/system/tray/tray_views.h" |
| 9 #include "ash/system/web_notification/web_notification.h" | 9 #include "ash/system/web_notification/web_notification.h" |
| 10 #include "ash/system/web_notification/web_notification_tray.h" | 10 #include "ash/system/web_notification/web_notification_tray.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 if (!event.IsScrollGestureEvent()) | 239 if (!event.IsScrollGestureEvent()) |
| 240 return ui::ER_UNHANDLED; | 240 return ui::ER_UNHANDLED; |
| 241 | 241 |
| 242 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 242 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
| 243 gesture_scroll_amount_ = 0.f; | 243 gesture_scroll_amount_ = 0.f; |
| 244 } else if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { | 244 } else if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
| 245 // The scroll-update events include the incremental scroll amount. | 245 // The scroll-update events include the incremental scroll amount. |
| 246 gesture_scroll_amount_ += event.details().scroll_x(); | 246 gesture_scroll_amount_ += event.details().scroll_x(); |
| 247 | 247 |
| 248 ui::Transform transform; | 248 gfx::Transform transform; |
| 249 transform.SetTranslateX(gesture_scroll_amount_); | 249 transform.SetTranslateX(gesture_scroll_amount_); |
| 250 layer()->SetTransform(transform); | 250 layer()->SetTransform(transform); |
| 251 layer()->SetOpacity( | 251 layer()->SetOpacity( |
| 252 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f)); | 252 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f)); |
| 253 | 253 |
| 254 } else if (event.type() == ui::ET_GESTURE_SCROLL_END) { | 254 } else if (event.type() == ui::ET_GESTURE_SCROLL_END) { |
| 255 const float kScrollRatioForClosingNotification = 0.5f; | 255 const float kScrollRatioForClosingNotification = 0.5f; |
| 256 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width(); | 256 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width(); |
| 257 if (scrolled_ratio >= kScrollRatioForClosingNotification) | 257 if (scrolled_ratio >= kScrollRatioForClosingNotification) |
| 258 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT); | 258 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 views::MenuItemView::TOPRIGHT, | 291 views::MenuItemView::TOPRIGHT, |
| 292 views::MenuRunner::HAS_MNEMONICS)); | 292 views::MenuRunner::HAS_MNEMONICS)); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void WebNotificationView::RestoreVisualState() { | 295 void WebNotificationView::RestoreVisualState() { |
| 296 // Restore the layer state. | 296 // Restore the layer state. |
| 297 const int kSwipeRestoreDurationMS = 150; | 297 const int kSwipeRestoreDurationMS = 150; |
| 298 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); | 298 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| 299 settings.SetTransitionDuration( | 299 settings.SetTransitionDuration( |
| 300 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); | 300 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); |
| 301 layer()->SetTransform(ui::Transform()); | 301 layer()->SetTransform(gfx::Transform()); |
| 302 layer()->SetOpacity(1.f); | 302 layer()->SetOpacity(1.f); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void WebNotificationView::SlideOutAndClose(SlideDirection direction) { | 305 void WebNotificationView::SlideOutAndClose(SlideDirection direction) { |
| 306 const int kSwipeOutTotalDurationMS = 150; | 306 const int kSwipeOutTotalDurationMS = 150; |
| 307 int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity(); | 307 int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity(); |
| 308 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); | 308 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| 309 settings.SetTransitionDuration( | 309 settings.SetTransitionDuration( |
| 310 base::TimeDelta::FromMilliseconds(swipe_out_duration)); | 310 base::TimeDelta::FromMilliseconds(swipe_out_duration)); |
| 311 settings.AddObserver(this); | 311 settings.AddObserver(this); |
| 312 | 312 |
| 313 ui::Transform transform; | 313 gfx::Transform transform; |
| 314 transform.SetTranslateX(direction == SLIDE_LEFT ? -width() : width()); | 314 transform.SetTranslateX(direction == SLIDE_LEFT ? -width() : width()); |
| 315 layer()->SetTransform(transform); | 315 layer()->SetTransform(transform); |
| 316 layer()->SetOpacity(0.f); | 316 layer()->SetOpacity(0.f); |
| 317 } | 317 } |
| 318 | 318 |
| 319 } // namespace message_center | 319 } // namespace message_center |
| 320 | 320 |
| 321 } // namespace ash | 321 } // namespace ash |
| OLD | NEW |