Skip to content

Commit

Permalink
Add lock screen note background controller implementation
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 19 changed files with 918 additions and 35 deletions.
7 changes: 7 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ component("ash") {
"laser/laser_segment_utils.h",
"lock_screen_action/lock_screen_action_background_controller.cc",
"lock_screen_action/lock_screen_action_background_controller.h",
"lock_screen_action/lock_screen_action_background_controller_impl.cc",
"lock_screen_action/lock_screen_action_background_controller_impl.h",
"lock_screen_action/lock_screen_action_background_controller_stub.cc",
"lock_screen_action/lock_screen_action_background_controller_stub.h",
"lock_screen_action/lock_screen_action_background_observer.h",
"lock_screen_action/lock_screen_action_background_state.h",
"lock_screen_action/lock_screen_action_background_view.cc",
"lock_screen_action/lock_screen_action_background_view.h",
"login/lock_screen_apps_focus_observer.h",
"login/lock_screen_controller.cc",
"login/lock_screen_controller.h",
Expand Down Expand Up @@ -1254,6 +1258,7 @@ test("ash_unittests") {
"ime/ime_controller_unittest.cc",
"laser/laser_pointer_controller_unittest.cc",
"laser/laser_segment_utils_unittest.cc",
"lock_screen_action/lock_screen_action_background_controller_impl_unittest.cc",
"login/lock_screen_controller_unittest.cc",
"login/mock_lock_screen_client.cc",
"login/mock_lock_screen_client.h",
Expand Down Expand Up @@ -1611,6 +1616,8 @@ static_library("test_support_common") {
"keyboard/test_keyboard_ui.h",
"laser/laser_pointer_controller_test_api.cc",
"laser/laser_pointer_controller_test_api.h",
"lock_screen_action/lock_screen_action_background_controller_impl_test_api.h",
"lock_screen_action/lock_screen_action_background_view_test_api.h",
"lock_screen_action/test_lock_screen_action_background_controller.cc",
"lock_screen_action/test_lock_screen_action_background_controller.h",
"metrics/task_switch_time_tracker_test_api.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include "ash/lock_screen_action/lock_screen_action_background_controller.h"

#include "ash/lock_screen_action/lock_screen_action_background_controller_impl.h"
#include "ash/lock_screen_action/lock_screen_action_background_controller_stub.h"
#include "ash/lock_screen_action/lock_screen_action_background_observer.h"
#include "ash/public/cpp/ash_switches.h"
#include "base/callback.h"

namespace ash {
Expand All @@ -22,10 +24,12 @@ std::unique_ptr<LockScreenActionBackgroundController>
LockScreenActionBackgroundController::Create() {
if (g_testing_factory_callback)
return g_testing_factory_callback->Run();
// TODO(tbarzic): Add a proper LockScreenActionBackgroundController
// implementation to be used with views lock screen implementation.
// http://crbug.com/746596
return std::make_unique<LockScreenActionBackgroundControllerStub>();
// Web UI based lock screen implements its own background - use the stub
// lock action background controller implementation unless md-based lock UI
// is used.
if (!switches::IsUsingMdLogin())
return std::make_unique<LockScreenActionBackgroundControllerStub>();
return std::make_unique<LockScreenActionBackgroundControllerImpl>();
}

// static
Expand Down
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
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_
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_
Loading

0 comments on commit 2331400

Please sign in to comment.