Commit 1e545ff9 authored by yoshiki iguchi's avatar yoshiki iguchi Committed by Commit Bot

Pass the status of sliding (sliding or not) to OnSlideChanged

This CL passes the status of sliding on OnSlideChanged handler so that
the handler in ArcNotificationContentView can hide the copied surface
at the timing of the sliding finished.

Bug: 897653
Test: manual
Change-Id: I8e76d54f59105b6101b1d2dfc10eb171272be611
Reviewed-on: https://chromium-review.googlesource.com/c/1295632
Commit-Queue: Yoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarTatsuhisa Yamaguchi <yamaguchi@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603003}
parent c093b2ba
...@@ -93,7 +93,7 @@ ui::Layer* NotificationMenuController::GetSlideOutLayer() { ...@@ -93,7 +93,7 @@ ui::Layer* NotificationMenuController::GetSlideOutLayer() {
: nullptr; : nullptr;
} }
void NotificationMenuController::OnSlideChanged() {} void NotificationMenuController::OnSlideChanged(bool in_progress) {}
void NotificationMenuController::OnSlideOut() { void NotificationMenuController::OnSlideOut() {
// Results in |this| being deleted if there are no more notifications to show. // Results in |this| being deleted if there are no more notifications to show.
......
...@@ -42,7 +42,7 @@ class APP_MENU_EXPORT NotificationMenuController ...@@ -42,7 +42,7 @@ class APP_MENU_EXPORT NotificationMenuController
// message_center::SlideOutController::Delegate overrides: // message_center::SlideOutController::Delegate overrides:
ui::Layer* GetSlideOutLayer() override; ui::Layer* GetSlideOutLayer() override;
void OnSlideChanged() override; void OnSlideChanged(bool in_progress) override;
void OnSlideOut() override; void OnSlideOut() override;
// NotificationMenuView::Delegate overrides: // NotificationMenuView::Delegate overrides:
......
...@@ -46,7 +46,7 @@ class MockNotificationMenuController ...@@ -46,7 +46,7 @@ class MockNotificationMenuController
return notification_menu_view_->GetSlideOutLayer(); return notification_menu_view_->GetSlideOutLayer();
} }
void OnSlideChanged() override {} void OnSlideChanged(bool in_progress) override {}
void OnSlideOut() override { slide_out_count_++; } void OnSlideOut() override { slide_out_count_++; }
......
...@@ -185,12 +185,9 @@ class ArcNotificationContentView::EventForwarder : public ui::EventHandler { ...@@ -185,12 +185,9 @@ class ArcNotificationContentView::EventForwarder : public ui::EventHandler {
DISALLOW_COPY_AND_ASSIGN(EventForwarder); DISALLOW_COPY_AND_ASSIGN(EventForwarder);
}; };
class ArcNotificationContentView::SlideHelper class ArcNotificationContentView::SlideHelper {
: public ui::LayerAnimationObserver {
public: public:
explicit SlideHelper(ArcNotificationContentView* owner) : owner_(owner) { explicit SlideHelper(ArcNotificationContentView* owner) : owner_(owner) {
GetSlideOutLayer()->GetAnimator()->AddObserver(this);
// Reset opacity to 1 to handle to case when the surface is sliding before // Reset opacity to 1 to handle to case when the surface is sliding before
// getting managed by this class, e.g. sliding in a popup before showing // getting managed by this class, e.g. sliding in a popup before showing
// in a message center view. // in a message center view.
...@@ -199,25 +196,25 @@ class ArcNotificationContentView::SlideHelper ...@@ -199,25 +196,25 @@ class ArcNotificationContentView::SlideHelper
owner_->surface_->GetWindow()->layer()->SetOpacity(1.0f); owner_->surface_->GetWindow()->layer()->SetOpacity(1.0f);
} }
} }
~SlideHelper() override { virtual ~SlideHelper() = default;
if (GetSlideOutLayer())
GetSlideOutLayer()->GetAnimator()->RemoveObserver(this); void Update(base::Optional<bool> slide_in_progress) {
} if (slide_in_progress.has_value())
slide_in_progress_ = slide_in_progress.value();
void Update() {
const bool has_animation = const bool has_animation =
GetSlideOutLayer()->GetAnimator()->is_animating(); GetSlideOutLayer()->GetAnimator()->is_animating();
const bool has_transform = !GetSlideOutLayer()->transform().IsIdentity(); const bool has_transform = !GetSlideOutLayer()->transform().IsIdentity();
const bool sliding = has_transform || has_animation; const bool moving = (slide_in_progress_ && has_transform) || has_animation;
if (sliding_ == sliding)
return;
sliding_ = sliding; if (moving_ == moving)
return;
moving_ = moving;
if (sliding_) if (moving_)
OnSlideStart(); owner_->ShowCopiedSurface();
else else
OnSlideEnd(); owner_->HideCopiedSurface();
} }
private: private:
...@@ -227,21 +224,9 @@ class ArcNotificationContentView::SlideHelper ...@@ -227,21 +224,9 @@ class ArcNotificationContentView::SlideHelper
return layer ? layer : owner_->GetWidget()->GetLayer(); return layer ? layer : owner_->GetWidget()->GetLayer();
} }
void OnSlideStart() { owner_->ShowCopiedSurface(); }
void OnSlideEnd() { owner_->HideCopiedSurface(); }
// ui::LayerAnimationObserver
void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) override {
Update();
}
void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) override {
Update();
}
void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {}
ArcNotificationContentView* const owner_; ArcNotificationContentView* const owner_;
bool sliding_ = false; bool slide_in_progress_ = false;
bool moving_ = false;
DISALLOW_COPY_AND_ASSIGN(SlideHelper); DISALLOW_COPY_AND_ASSIGN(SlideHelper);
}; };
...@@ -368,9 +353,9 @@ void ArcNotificationContentView::UpdateCornerRadius(int top_radius, ...@@ -368,9 +353,9 @@ void ArcNotificationContentView::UpdateCornerRadius(int top_radius,
UpdateMask(); UpdateMask();
} }
void ArcNotificationContentView::OnSlideChanged() { void ArcNotificationContentView::OnSlideChanged(bool in_progress) {
if (slide_helper_) if (slide_helper_)
slide_helper_->Update(); slide_helper_->Update(in_progress);
} }
void ArcNotificationContentView::OnContainerAnimationStarted() { void ArcNotificationContentView::OnContainerAnimationStarted() {
...@@ -508,7 +493,7 @@ void ArcNotificationContentView::AttachSurface() { ...@@ -508,7 +493,7 @@ void ArcNotificationContentView::AttachSurface() {
slide_helper_.reset(new SlideHelper(this)); slide_helper_.reset(new SlideHelper(this));
// Invokes Update() in case surface is attached during a slide. // Invokes Update() in case surface is attached during a slide.
slide_helper_->Update(); slide_helper_->Update(base::nullopt);
// (Re-)create the floating buttons after |surface_| is attached to a widget. // (Re-)create the floating buttons after |surface_| is attached to a widget.
MaybeCreateFloatingControlButtons(); MaybeCreateFloatingControlButtons();
......
...@@ -58,7 +58,7 @@ class ArcNotificationContentView ...@@ -58,7 +58,7 @@ class ArcNotificationContentView
message_center::NotificationControlButtonsView* GetControlButtonsView(); message_center::NotificationControlButtonsView* GetControlButtonsView();
void UpdateControlButtonsVisibility(); void UpdateControlButtonsVisibility();
void UpdateCornerRadius(int top_radius, int bottom_radius); void UpdateCornerRadius(int top_radius, int bottom_radius);
void OnSlideChanged(); void OnSlideChanged(bool in_progress);
void OnContainerAnimationStarted(); void OnContainerAnimationStarted();
void OnContainerAnimationEnded(); void OnContainerAnimationEnded();
void ActivateWidget(bool activate); void ActivateWidget(bool activate);
......
...@@ -161,9 +161,9 @@ void ArcNotificationView::OnContainerAnimationEnded() { ...@@ -161,9 +161,9 @@ void ArcNotificationView::OnContainerAnimationEnded() {
content_view_->OnContainerAnimationEnded(); content_view_->OnContainerAnimationEnded();
} }
void ArcNotificationView::OnSlideChanged() { void ArcNotificationView::OnSlideChanged(bool in_progress) {
MessageView::OnSlideChanged(); MessageView::OnSlideChanged(in_progress);
content_view_->OnSlideChanged(); content_view_->OnSlideChanged(in_progress);
} }
gfx::Size ArcNotificationView::CalculatePreferredSize() const { gfx::Size ArcNotificationView::CalculatePreferredSize() const {
......
...@@ -56,8 +56,8 @@ class ArcNotificationView : public message_center::MessageView, ...@@ -56,8 +56,8 @@ class ArcNotificationView : public message_center::MessageView,
void OnSnoozeButtonPressed(const ui::Event& event) override; void OnSnoozeButtonPressed(const ui::Event& event) override;
void UpdateCornerRadius(int top_radius, int bottom_radius) override; void UpdateCornerRadius(int top_radius, int bottom_radius) override;
// views::SlideOutController::Delegate: // message_center::SlideOutController::Delegate:
void OnSlideChanged() override; void OnSlideChanged(bool in_progress) override;
// Overridden from views::View: // Overridden from views::View:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
......
...@@ -313,7 +313,7 @@ ui::Layer* MessageView::GetSlideOutLayer() { ...@@ -313,7 +313,7 @@ ui::Layer* MessageView::GetSlideOutLayer() {
return is_nested_ ? layer() : GetWidget()->GetLayer(); return is_nested_ ? layer() : GetWidget()->GetLayer();
} }
void MessageView::OnSlideChanged() { void MessageView::OnSlideChanged(bool in_progress) {
for (auto* observer : slide_observers_) { for (auto* observer : slide_observers_) {
observer->OnSlideChanged(notification_id_); observer->OnSlideChanged(notification_id_);
} }
......
...@@ -126,7 +126,7 @@ class MESSAGE_CENTER_EXPORT MessageView : public views::InkDropHostView, ...@@ -126,7 +126,7 @@ class MESSAGE_CENTER_EXPORT MessageView : public views::InkDropHostView,
// message_center::SlideOutController::Delegate: // message_center::SlideOutController::Delegate:
ui::Layer* GetSlideOutLayer() override; ui::Layer* GetSlideOutLayer() override;
void OnSlideChanged() override; void OnSlideChanged(bool in_progress) override;
void OnSlideOut() override; void OnSlideOut() override;
// views::FocusChangeListener: // views::FocusChangeListener:
......
...@@ -49,7 +49,6 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) { ...@@ -49,7 +49,6 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) {
} }
CaptureControlOpenState(); CaptureControlOpenState();
RestoreVisualState(); RestoreVisualState();
delegate_->OnSlideChanged();
return; return;
} }
...@@ -70,6 +69,7 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) { ...@@ -70,6 +69,7 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) {
default: default:
NOTREACHED(); NOTREACHED();
} }
delegate_->OnSlideChanged(true);
} else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
// The scroll-update events include the incremental scroll amount. // The scroll-update events include the incremental scroll amount.
gesture_amount_ += event->details().scroll_x(); gesture_amount_ += event->details().scroll_x();
...@@ -102,6 +102,7 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) { ...@@ -102,6 +102,7 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) {
gfx::Transform transform; gfx::Transform transform;
transform.Translate(scroll_amount, 0.0); transform.Translate(scroll_amount, 0.0);
layer->SetTransform(transform); layer->SetTransform(transform);
delegate_->OnSlideChanged(true);
} else if (event->type() == ui::ET_GESTURE_SCROLL_END) { } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
float scrolled_ratio = fabsf(gesture_amount_) / width; float scrolled_ratio = fabsf(gesture_amount_) / width;
if (mode_ == SlideMode::FULL && if (mode_ == SlideMode::FULL &&
...@@ -114,7 +115,6 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) { ...@@ -114,7 +115,6 @@ void SlideOutController::OnGestureEvent(ui::GestureEvent* event) {
RestoreVisualState(); RestoreVisualState();
} }
delegate_->OnSlideChanged();
event->SetHandled(); event->SetHandled();
} }
...@@ -125,6 +125,7 @@ void SlideOutController::RestoreVisualState() { ...@@ -125,6 +125,7 @@ void SlideOutController::RestoreVisualState() {
ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
settings.SetTransitionDuration( settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS));
settings.AddObserver(this);
gfx::Transform transform; gfx::Transform transform;
switch (control_open_state_) { switch (control_open_state_) {
case SwipeControlOpenState::CLOSED: case SwipeControlOpenState::CLOSED:
...@@ -137,8 +138,20 @@ void SlideOutController::RestoreVisualState() { ...@@ -137,8 +138,20 @@ void SlideOutController::RestoreVisualState() {
transform.Translate(swipe_control_width_, 0); transform.Translate(swipe_control_width_, 0);
break; break;
} }
if (layer->transform() == transform && layer->opacity() == 1.f) {
// Here, nothing are changed and no animation starts. In this case, just
// calls OnSlideChanged(in_progress = false) to notify end of horizontal
// slide (including animations) to observers.
delegate_->OnSlideChanged(false);
return;
}
// In this case, animation starts. OnImplicitAnimationsCompleted will be
// called just after the animation finishes.
layer->SetTransform(transform); layer->SetTransform(transform);
layer->SetOpacity(1.f); layer->SetOpacity(1.f);
delegate_->OnSlideChanged(true);
} }
void SlideOutController::SlideOutAndClose(int direction) { void SlideOutController::SlideOutAndClose(int direction) {
...@@ -153,14 +166,22 @@ void SlideOutController::SlideOutAndClose(int direction) { ...@@ -153,14 +166,22 @@ void SlideOutController::SlideOutAndClose(int direction) {
gfx::Transform transform; gfx::Transform transform;
int width = layer->bounds().width(); int width = layer->bounds().width();
transform.Translate(direction < 0 ? -width : width, 0.0); transform.Translate(direction < 0 ? -width : width, 0.0);
// An animation starts. OnImplicitAnimationsCompleted will be called just
// after the animation finishes.
layer->SetTransform(transform); layer->SetTransform(transform);
layer->SetOpacity(0.f); layer->SetOpacity(0.f);
delegate_->OnSlideChanged(); delegate_->OnSlideChanged(true);
} }
void SlideOutController::OnImplicitAnimationsCompleted() { void SlideOutController::OnImplicitAnimationsCompleted() {
delegate_->OnSlideChanged(); delegate_->OnSlideChanged(false);
delegate_->OnSlideOut();
// Call Delegate::OnSlideOut() if this animation came from
// SlideOutAndClose().
ui::Layer* layer = delegate_->GetSlideOutLayer();
if (layer->opacity() == 0)
delegate_->OnSlideOut();
} }
void SlideOutController::SetSwipeControlWidth(int swipe_control_width) { void SlideOutController::SetSwipeControlWidth(int swipe_control_width) {
......
...@@ -31,7 +31,9 @@ class MESSAGE_CENTER_EXPORT SlideOutController ...@@ -31,7 +31,9 @@ class MESSAGE_CENTER_EXPORT SlideOutController
virtual ui::Layer* GetSlideOutLayer() = 0; virtual ui::Layer* GetSlideOutLayer() = 0;
// Called when a slide starts, ends, or is updated. // Called when a slide starts, ends, or is updated.
virtual void OnSlideChanged() = 0; // The argument is true if the slide starts or in progress, false if it
// ends.
virtual void OnSlideChanged(bool in_progress) = 0;
// Called when user intends to close the View by sliding it out. // Called when user intends to close the View by sliding it out.
virtual void OnSlideOut() = 0; virtual void OnSlideOut() = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment