forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lock screen note background controller implementation
The controller shows a widget with a ink drop animation that fills the screen from the top right corner with black background. The controller will be in kShowing and kHiding state while the ink drop animation is in progress (during which time lock screen apps windows will be kept hidden). The lock screen action background widget will be shown only for views based lock screen UI. The web UI based lock screen provides its own implementation of the show animation, and it will use the stub background controller implementation. BUG=746596 Change-Id: I1e8ba562a8a5e854e4ba84b006da3c7748bab395 Reviewed-on: https://chromium-review.googlesource.com/709780 Reviewed-by: Jacob Dufault <jdufault@chromium.org> Reviewed-by: James Cook <jamescook@chromium.org> Commit-Queue: Toni Barzic <tbarzic@chromium.org> Cr-Commit-Position: refs/heads/master@{#508478}
- Loading branch information
Toni Barzic
authored and
Commit Bot
committed
Oct 12, 2017
1 parent
8eac88c
commit 2331400
Showing
19 changed files
with
918 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
ash/lock_screen_action/lock_screen_action_background_controller_impl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/lock_screen_action/lock_screen_action_background_controller_impl.h" | ||
|
||
#include "ash/lock_screen_action/lock_screen_action_background_view.h" | ||
#include "base/bind.h" | ||
#include "ui/aura/window.h" | ||
#include "ui/views/widget/widget.h" | ||
|
||
namespace ash { | ||
|
||
namespace { | ||
|
||
constexpr char kLockScreenActionBackgroundWidgetName[] = | ||
"LockScreenActionBackground"; | ||
|
||
} // namespace | ||
|
||
LockScreenActionBackgroundControllerImpl:: | ||
LockScreenActionBackgroundControllerImpl() | ||
: widget_observer_(this), weak_ptr_factory_(this) {} | ||
|
||
LockScreenActionBackgroundControllerImpl:: | ||
~LockScreenActionBackgroundControllerImpl() { | ||
if (background_widget_ && !background_widget_->IsClosed()) | ||
background_widget_->Close(); | ||
} | ||
|
||
bool LockScreenActionBackgroundControllerImpl::IsBackgroundWindow( | ||
aura::Window* window) const { | ||
return window->GetName() == kLockScreenActionBackgroundWidgetName; | ||
} | ||
|
||
bool LockScreenActionBackgroundControllerImpl::ShowBackground() { | ||
if (state() == LockScreenActionBackgroundState::kShown || | ||
state() == LockScreenActionBackgroundState::kShowing) { | ||
return false; | ||
} | ||
|
||
if (!parent_window_) | ||
return false; | ||
|
||
if (!background_widget_) | ||
background_widget_ = CreateWidget(); | ||
|
||
UpdateState(LockScreenActionBackgroundState::kShowing); | ||
|
||
background_widget_->Show(); | ||
|
||
contents_view_->AnimateShow(base::BindOnce( | ||
&LockScreenActionBackgroundControllerImpl::OnBackgroundShown, | ||
weak_ptr_factory_.GetWeakPtr())); | ||
|
||
return true; | ||
} | ||
|
||
bool LockScreenActionBackgroundControllerImpl::HideBackgroundImmediately() { | ||
if (state() == LockScreenActionBackgroundState::kHidden) | ||
return false; | ||
|
||
UpdateState(LockScreenActionBackgroundState::kHidden); | ||
|
||
background_widget_->Hide(); | ||
return true; | ||
} | ||
|
||
bool LockScreenActionBackgroundControllerImpl::HideBackground() { | ||
if (state() == LockScreenActionBackgroundState::kHidden || | ||
state() == LockScreenActionBackgroundState::kHiding) { | ||
return false; | ||
} | ||
|
||
DCHECK(background_widget_); | ||
|
||
UpdateState(LockScreenActionBackgroundState::kHiding); | ||
|
||
contents_view_->AnimateHide(base::BindOnce( | ||
&LockScreenActionBackgroundControllerImpl::OnBackgroundHidden, | ||
weak_ptr_factory_.GetWeakPtr())); | ||
|
||
return true; | ||
} | ||
|
||
void LockScreenActionBackgroundControllerImpl::OnWidgetDestroyed( | ||
views::Widget* widget) { | ||
if (widget != background_widget_) | ||
return; | ||
widget_observer_.Remove(widget); | ||
|
||
background_widget_ = nullptr; | ||
contents_view_ = nullptr; | ||
|
||
UpdateState(LockScreenActionBackgroundState::kHidden); | ||
} | ||
|
||
views::Widget* LockScreenActionBackgroundControllerImpl::CreateWidget() { | ||
// Passed to the widget as its delegate. | ||
contents_view_ = new LockScreenActionBackgroundView(); | ||
|
||
views::Widget::InitParams params( | ||
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | ||
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | ||
params.name = kLockScreenActionBackgroundWidgetName; | ||
params.parent = parent_window_; | ||
params.delegate = contents_view_; | ||
|
||
views::Widget* widget = new views::Widget(); | ||
widget->Init(params); | ||
widget->SetVisibilityChangedAnimationsEnabled(false); | ||
widget_observer_.Add(widget); | ||
|
||
return widget; | ||
} | ||
|
||
void LockScreenActionBackgroundControllerImpl::OnBackgroundShown() { | ||
if (state() != LockScreenActionBackgroundState::kShowing) | ||
return; | ||
|
||
UpdateState(LockScreenActionBackgroundState::kShown); | ||
} | ||
|
||
void LockScreenActionBackgroundControllerImpl::OnBackgroundHidden() { | ||
if (state() != LockScreenActionBackgroundState::kHiding) | ||
return; | ||
|
||
background_widget_->Hide(); | ||
|
||
UpdateState(LockScreenActionBackgroundState::kHidden); | ||
} | ||
|
||
} // namespace ash |
78 changes: 78 additions & 0 deletions
78
ash/lock_screen_action/lock_screen_action_background_controller_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_IMPL_H_ | ||
#define ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_IMPL_H_ | ||
|
||
#include "ash/ash_export.h" | ||
#include "ash/lock_screen_action/lock_screen_action_background_controller.h" | ||
#include "base/macros.h" | ||
#include "base/memory/weak_ptr.h" | ||
#include "base/scoped_observer.h" | ||
#include "ui/views/widget/widget_observer.h" | ||
|
||
namespace aura { | ||
class Window; | ||
} | ||
|
||
namespace views { | ||
class Widget; | ||
} | ||
|
||
namespace ash { | ||
|
||
class LockScreenActionBackgroundView; | ||
|
||
// The LockScreenActionBackgroundController implementation that shows lock | ||
// screen action background as a non activable window that is shown/hidden with | ||
// an ink drop animation that covers the whole window contents in black from the | ||
// top right window corner. | ||
class ASH_EXPORT LockScreenActionBackgroundControllerImpl | ||
: public LockScreenActionBackgroundController, | ||
public views::WidgetObserver { | ||
public: | ||
LockScreenActionBackgroundControllerImpl(); | ||
~LockScreenActionBackgroundControllerImpl() override; | ||
|
||
// LockScreenActionBackgroundController: | ||
bool IsBackgroundWindow(aura::Window* window) const override; | ||
bool ShowBackground() override; | ||
bool HideBackgroundImmediately() override; | ||
bool HideBackground() override; | ||
|
||
// views::WidgetObserver: | ||
void OnWidgetDestroyed(views::Widget* widget) override; | ||
|
||
private: | ||
friend class LockScreenActionBackgroundControllerImplTestApi; | ||
|
||
// Creates the widget to be used as the background widget. | ||
views::Widget* CreateWidget(); | ||
|
||
// Called when the background widget view is fully shown, i.e. when the ink | ||
// drop animation associated with showing the widget ends. | ||
void OnBackgroundShown(); | ||
|
||
// Called when the background widget view is fully hidden, i.e. when the ink | ||
// drop animation associated with hiding the widget ends. | ||
void OnBackgroundHidden(); | ||
|
||
// The background widget used (and created) by the controller to display the | ||
// lock screen action background. | ||
// The widget is owned by its native (aura) window - it will be deleted when | ||
// the window gets closed/destroyed. | ||
views::Widget* background_widget_ = nullptr; | ||
LockScreenActionBackgroundView* contents_view_ = nullptr; | ||
|
||
ScopedObserver<views::Widget, views::WidgetObserver> widget_observer_; | ||
|
||
base::WeakPtrFactory<LockScreenActionBackgroundControllerImpl> | ||
weak_ptr_factory_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(LockScreenActionBackgroundControllerImpl); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_IMPL_H_ |
45 changes: 45 additions & 0 deletions
45
ash/lock_screen_action/lock_screen_action_background_controller_impl_test_api.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_IMPL_TEST_API_H_ | ||
#define ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_IMPL_TEST_API_H_ | ||
|
||
#include "ash/ash_export.h" | ||
#include "ash/lock_screen_action/lock_screen_action_background_controller_impl.h" | ||
#include "base/macros.h" | ||
|
||
namespace views { | ||
class Widget; | ||
} | ||
|
||
namespace ash { | ||
|
||
class LockScreenActionBackgroundControllerImpl; | ||
class LockScreenActionBackgroundView; | ||
|
||
// Class that provides access to LockScreenActionBackgroundControllerImpl | ||
// implementation details in tests. | ||
class ASH_EXPORT LockScreenActionBackgroundControllerImplTestApi { | ||
public: | ||
explicit LockScreenActionBackgroundControllerImplTestApi( | ||
LockScreenActionBackgroundControllerImpl* controller) | ||
: controller_(controller) {} | ||
|
||
~LockScreenActionBackgroundControllerImplTestApi() = default; | ||
|
||
views::Widget* GetWidget() { return controller_->background_widget_; } | ||
|
||
LockScreenActionBackgroundView* GetContentsView() { | ||
return controller_->contents_view_; | ||
} | ||
|
||
private: | ||
LockScreenActionBackgroundControllerImpl* controller_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(LockScreenActionBackgroundControllerImplTestApi); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_IMPL_TEST_API_H_ |
Oops, something went wrong.