Commit bb3fde80 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

ash: get rid of LockScreenWidgetDelegate

This class is no longer needed because of the new WidgetDelegate
setters.

This change:
1) Replaces LockScreenWidgetDelegate with a plain WidgetDelegate
2) Refactors LockScreen::Show() to pass the contents view directly
   into the Widget factory method, in aid of (1)

Bug: 1075649
Change-Id: I5a89cbd822ad22aef62a76f6ea8afb70f6431d08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2458450
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814873}
parent 10f01c23
...@@ -67,6 +67,27 @@ LockScreen::~LockScreen() { ...@@ -67,6 +67,27 @@ LockScreen::~LockScreen() {
ui::Clipboard::SetClipboardForCurrentThread(std::move(saved_clipboard_)); ui::Clipboard::SetClipboardForCurrentThread(std::move(saved_clipboard_));
} }
std::unique_ptr<views::View> LockScreen::MakeContentsView() {
auto initial_note_action_state =
Shell::Get()->tray_action()->GetLockScreenNoteState();
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kShowLoginDevOverlay)) {
auto debug_view =
std::make_unique<LockDebugView>(initial_note_action_state, type_);
contents_view_ = debug_view->lock();
return debug_view;
}
auto detachable_base_model =
LoginDetachableBaseModel::Create(Shell::Get()->detachable_base_handler());
auto view = std::make_unique<LockContentsView>(
initial_note_action_state, type_,
Shell::Get()->login_screen_controller()->data_dispatcher(),
std::move(detachable_base_model));
contents_view_ = view.get();
return view;
}
// static // static
LockScreen* LockScreen::Get() { LockScreen* LockScreen::Get() {
CHECK(instance_); CHECK(instance_);
...@@ -86,28 +107,11 @@ void LockScreen::Show(ScreenType type) { ...@@ -86,28 +107,11 @@ void LockScreen::Show(ScreenType type) {
parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(), parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_LockScreenContainer); kShellWindowId_LockScreenContainer);
} }
instance_->widget_ = CreateLockScreenWidget(parent); instance_->widget_ =
CreateLockScreenWidget(parent, instance_->MakeContentsView());
instance_->widget_->SetBounds( instance_->widget_->SetBounds(
display::Screen::GetScreen()->GetPrimaryDisplay().bounds()); display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
auto initial_note_action_state =
Shell::Get()->tray_action()->GetLockScreenNoteState();
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kShowLoginDevOverlay)) {
auto debug_view =
std::make_unique<LockDebugView>(initial_note_action_state, type);
instance_->contents_view_ = debug_view->lock();
instance_->widget_->SetContentsView(std::move(debug_view));
} else {
auto detachable_base_model = LoginDetachableBaseModel::Create(
Shell::Get()->detachable_base_handler());
instance_->contents_view_ =
instance_->widget_->SetContentsView(std::make_unique<LockContentsView>(
initial_note_action_state, type,
Shell::Get()->login_screen_controller()->data_dispatcher(),
std::move(detachable_base_model)));
}
// Postpone showing the screen after the animation of the first wallpaper // Postpone showing the screen after the animation of the first wallpaper
// completes, to make the transition smooth. The callback will be dispatched // completes, to make the transition smooth. The callback will be dispatched
// immediately if the animation is already complete (e.g. kLock). // immediately if the animation is already complete (e.g. kLock).
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
namespace views { namespace views {
class View;
class Widget; class Widget;
} }
...@@ -81,6 +82,8 @@ class ASH_EXPORT LockScreen : public TrayActionObserver, ...@@ -81,6 +82,8 @@ class ASH_EXPORT LockScreen : public TrayActionObserver,
explicit LockScreen(ScreenType type); explicit LockScreen(ScreenType type);
~LockScreen() override; ~LockScreen() override;
std::unique_ptr<views::View> MakeContentsView();
// Shows the lock screen widget, unless the global instance was already // Shows the lock screen widget, unless the global instance was already
// destroyed. Called after the first wallpaper becomes ready. // destroyed. Called after the first wallpaper becomes ready.
static void ShowWidgetUponWallpaperReady(); static void ShowWidgetUponWallpaperReady();
......
...@@ -9,38 +9,20 @@ ...@@ -9,38 +9,20 @@
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
namespace ash { namespace ash {
namespace {
class LockScreenWidgetDelegate : public views::WidgetDelegate { std::unique_ptr<views::Widget> CreateLockScreenWidget(
public: aura::Window* parent,
explicit LockScreenWidgetDelegate(views::Widget* widget) : widget_(widget) { std::unique_ptr<views::View> contents_view) {
SetOwnedByWidget(true);
DCHECK(widget_);
}
~LockScreenWidgetDelegate() override = default;
// views::WidgetDelegate:
views::View* GetInitiallyFocusedView() override {
return widget_->GetContentsView();
}
views::Widget* GetWidget() override { return widget_; }
const views::Widget* GetWidget() const override { return widget_; }
private:
views::Widget* widget_;
DISALLOW_COPY_AND_ASSIGN(LockScreenWidgetDelegate);
};
} // namespace
std::unique_ptr<views::Widget> CreateLockScreenWidget(aura::Window* parent) {
std::unique_ptr<views::Widget> widget = std::make_unique<views::Widget>(); std::unique_ptr<views::Widget> widget = std::make_unique<views::Widget>();
views::Widget::InitParams params( views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
// Owned by Widget.
params.delegate = new LockScreenWidgetDelegate(widget.get()); params.delegate = new views::WidgetDelegate();
params.delegate->SetOwnedByWidget(true);
params.delegate->SetContentsView(std::move(contents_view));
params.delegate->SetInitiallyFocusedView(params.delegate->GetContentsView());
params.show_state = ui::SHOW_STATE_FULLSCREEN; params.show_state = ui::SHOW_STATE_FULLSCREEN;
params.opacity = views::Widget::InitParams::WindowOpacity::kTranslucent; params.opacity = views::Widget::InitParams::WindowOpacity::kTranslucent;
params.parent = parent; params.parent = parent;
......
...@@ -14,6 +14,7 @@ class Window; ...@@ -14,6 +14,7 @@ class Window;
} }
namespace views { namespace views {
class View;
class Widget; class Widget;
} }
...@@ -24,7 +25,8 @@ namespace ash { ...@@ -24,7 +25,8 @@ namespace ash {
// should only be supplied if called from ash, otherwise use null to get the // should only be supplied if called from ash, otherwise use null to get the
// right container. // right container.
ASH_PUBLIC_EXPORT std::unique_ptr<views::Widget> CreateLockScreenWidget( ASH_PUBLIC_EXPORT std::unique_ptr<views::Widget> CreateLockScreenWidget(
aura::Window* parent = nullptr); aura::Window* parent,
std::unique_ptr<views::View> contents_view);
} // namespace ash } // namespace ash
......
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