Commit 9d295fc1 authored by Aga Wronska's avatar Aga Wronska Committed by Commit Bot

child user: Show PIN keyboard on parent access view in tablet mode only

PIN keyboard should only be visible when device is in tablet mode.
Update view layout and add handling of gestures to move focus of access
code input.

Bug: 911326
Test: ParentAccessViewTest
Change-Id: I66ac5a039549312d1686875478ae6fa743082bd5
Reviewed-on: https://chromium-review.googlesource.com/c/1480824Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Commit-Queue: Aga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636080}
parent 51deb7a4
......@@ -151,6 +151,10 @@ void LoginBigUserView::RequestFocus() {
return auth_user_->RequestFocus();
}
void LoginBigUserView::ChildPreferredSizeChanged(views::View* child) {
parent()->Layout();
}
void LoginBigUserView::OnWallpaperBlurChanged() {
if (Shell::Get()->wallpaper_controller()->IsWallpaperBlurred()) {
SetPaintToLayer(ui::LayerType::LAYER_NOT_DRAWN);
......
......@@ -71,6 +71,7 @@ class ASH_EXPORT LoginBigUserView : public NonAccessibleView,
// views::View:
void RequestFocus() override;
void ChildPreferredSizeChanged(views::View* child) override;
// WallpaperControllerObserver:
void OnWallpaperBlurChanged() override;
......
......@@ -49,9 +49,10 @@ constexpr const char kParentAccessViewClassName[] = "ParentAccessView";
constexpr int kParentAccessCodePinLength = 6;
constexpr int kParentAccessViewWidthDp = 340;
constexpr int kParentAccessViewHeightDp = 560;
constexpr int kParentAccessViewHeightDp = 340;
constexpr int kParentAccessViewTabletModeHeightDp = 580;
constexpr int kParentAccessViewRoundedCornerRadiusDp = 8;
constexpr int kParentAccessViewVerticalInsetDp = 36;
constexpr int kParentAccessViewVerticalInsetDp = 16;
constexpr int kParentAccessViewHorizontalInsetDp = 26;
constexpr int kLockIconSizeDp = 24;
......@@ -77,6 +78,12 @@ constexpr SkColor kTextColor = SK_ColorWHITE;
constexpr SkColor kErrorColor = SkColorSetARGB(0xFF, 0xF2, 0x8B, 0x82);
constexpr SkColor kArrowButtonColor = SkColorSetARGB(0x57, 0xFF, 0xFF, 0xFF);
bool IsTabletMode() {
return Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled();
}
} // namespace
// Digital access code input view for variable length of input codes.
......@@ -198,6 +205,38 @@ class ParentAccessView::AccessCodeInput : public views::View,
return true;
}
bool HandleMouseEvent(views::Textfield* sender,
const ui::MouseEvent& mouse_event) override {
if (!mouse_event.IsOnlyLeftMouseButton())
return false;
// Move focus to the field that was selected with mouse input.
for (size_t i = 0; i < input_fields_.size(); ++i) {
if (input_fields_[i] == sender) {
active_input_index_ = i;
break;
}
}
return true;
}
bool HandleGestureEvent(views::Textfield* sender,
const ui::GestureEvent& gesture_event) override {
if (gesture_event.details().type() != ui::EventType::ET_GESTURE_TAP)
return false;
// Move focus to the field that was selected with gesture.
for (size_t i = 0; i < input_fields_.size(); ++i) {
if (input_fields_[i] == sender) {
active_input_index_ = i;
break;
}
}
return true;
}
private:
// Moves focus to the previous input field if it exists.
void FocusPreviousField() {
......@@ -279,13 +318,11 @@ ParentAccessView::ParentAccessView(const AccountId& account_id,
gfx::Insets(kParentAccessViewVerticalInsetDp,
kParentAccessViewHorizontalInsetDp),
0);
layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
SetLayoutManager(std::move(layout));
views::BoxLayout* main_layout = SetLayoutManager(std::move(layout));
SetPreferredSize(
gfx::Size(kParentAccessViewWidthDp, kParentAccessViewHeightDp));
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
......@@ -375,6 +412,12 @@ ParentAccessView::ParentAccessView(const AccountId& account_id,
pin_keyboard_view_->OnPasswordTextChanged(false);
AddChildView(pin_keyboard_view_);
// Vertical spacer to consume height remaining in the view after all children
// are accounted for.
auto* vertical_spacer = new NonAccessibleView();
AddChildView(vertical_spacer);
main_layout->SetFlexForView(vertical_spacer, 1);
// Footer view contains help text button aligned to its start, submit
// button aligned to its end and spacer view in between.
auto* footer = new NonAccessibleView();
......@@ -405,6 +448,11 @@ ParentAccessView::ParentAccessView(const AccountId& account_id,
gfx::Size(kArrowButtonSizeDp, kArrowButtonSizeDp));
submit_button_->SetEnabled(false);
footer->AddChildView(submit_button_);
// Pin keyboard is only shown in tablet mode.
pin_keyboard_view_->SetVisible(IsTabletMode());
tablet_mode_observer_.Add(Shell::Get()->tablet_mode_controller());
}
ParentAccessView::~ParentAccessView() = default;
......@@ -428,6 +476,17 @@ void ParentAccessView::RequestFocus() {
access_code_view_->RequestFocus();
}
void ParentAccessView::Layout() {
NonAccessibleView::Layout();
SizeToPreferredSize();
}
gfx::Size ParentAccessView::CalculatePreferredSize() const {
return gfx::Size(kParentAccessViewWidthDp,
IsTabletMode() ? kParentAccessViewTabletModeHeightDp
: kParentAccessViewHeightDp);
}
void ParentAccessView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == back_button_) {
......@@ -440,6 +499,27 @@ void ParentAccessView::ButtonPressed(views::Button* sender,
}
}
void ParentAccessView::OnTabletModeStarted() {
VLOG(1) << "Showing PIN keyboard in ParentAccessView";
pin_keyboard_view_->SetVisible(true);
// This will trigger ChildPreferredSizeChanged in parent view and Layout() in
// view. As the result whole hierarchy will go through re-layout.
PreferredSizeChanged();
}
void ParentAccessView::OnTabletModeEnded() {
VLOG(1) << "Hiding PIN keyboard in ParentAccessView";
DCHECK(pin_keyboard_view_);
pin_keyboard_view_->SetVisible(false);
// This will trigger ChildPreferredSizeChanged in parent view and Layout() in
// view. As the result whole hierarchy will go through re-layout.
PreferredSizeChanged();
}
void ParentAccessView::OnTabletControllerDestroyed() {
tablet_mode_observer_.RemoveAll();
}
void ParentAccessView::SubmitCode() {
base::Optional<std::string> code = access_code_view_->GetCode();
DCHECK(code.has_value());
......
......@@ -9,10 +9,13 @@
#include "ash/ash_export.h"
#include "ash/login/ui/non_accessible_view.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/scoped_observer.h"
#include "components/account_id/account_id.h"
#include "ui/views/controls/button/button.h"
......@@ -29,7 +32,8 @@ class LoginPinView;
// The view that allows for input of parent access code to authorize certain
// actions on child's device.
class ASH_EXPORT ParentAccessView : public NonAccessibleView,
public views::ButtonListener {
public views::ButtonListener,
public TabletModeObserver {
public:
// ParentAccessView state.
enum class State {
......@@ -76,10 +80,17 @@ class ASH_EXPORT ParentAccessView : public NonAccessibleView,
// views::View:
void OnPaint(gfx::Canvas* canvas) override;
void RequestFocus() override;
void Layout() override;
gfx::Size CalculatePreferredSize() const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
void OnTabletControllerDestroyed() override;
private:
class AccessCodeInput;
......@@ -113,6 +124,9 @@ class ASH_EXPORT ParentAccessView : public NonAccessibleView,
views::LabelButton* help_button_ = nullptr;
ArrowButtonView* submit_button_ = nullptr;
ScopedObserver<TabletModeController, TabletModeObserver>
tablet_mode_observer_{this};
base::WeakPtrFactory<ParentAccessView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ParentAccessView);
......
......@@ -12,6 +12,8 @@
#include "ash/login/ui/login_button.h"
#include "ash/login/ui/login_pin_view.h"
#include "ash/login/ui/login_test_base.h"
#include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/optional.h"
......@@ -177,6 +179,8 @@ TEST_F(ParentAccessViewTest, Backspace) {
// Tests input with virtual pin keyboard.
TEST_F(ParentAccessViewTest, PinKeyboard) {
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
ParentAccessView::TestApi test_api(view_);
LoginPinView::TestApi test_pin_keyboard(test_api.pin_keyboard_view());
EXPECT_FALSE(test_api.submit_button()->enabled());
......@@ -195,6 +199,19 @@ TEST_F(ParentAccessViewTest, PinKeyboard) {
EXPECT_EQ(1, successful_validation_);
}
// Tests that pin keyboard visibility changes upon tablet mode changes.
TEST_F(ParentAccessViewTest, PinKeyboardVisibilityChange) {
ParentAccessView::TestApi test_api(view_);
LoginPinView::TestApi test_pin_keyboard(test_api.pin_keyboard_view());
EXPECT_FALSE(test_api.pin_keyboard_view()->visible());
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
EXPECT_TRUE(test_api.pin_keyboard_view()->visible());
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false);
EXPECT_FALSE(test_api.pin_keyboard_view()->visible());
}
// Tests that error state is shown and cleared when neccesary.
TEST_F(ParentAccessViewTest, ErrorState) {
ParentAccessView::TestApi test_api(view_);
......
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