Commit 1498c75d authored by Yulun Wu's avatar Yulun Wu Committed by Commit Bot

Refactor in app to home nudge logic.

Moving logic out of shelf_layout_manager and into a separate controller class.

Tests for this behavior are in shelf_drag_handle_unittest.cc: will be refactored into
in_app_to_home_nudge_controller_unittest.cc in a follow up CL.

Bug: 1062690
Change-Id: Icb44ddcec0a89be131132723d4db0735a4e50825
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2152953Reviewed-by: default avatarYulun Wu <yulunwu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Yulun Wu <yulunwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760131}
parent 4e56b141
......@@ -641,6 +641,8 @@ component("ash") {
"shelf/hotseat_transition_animator.h",
"shelf/hotseat_widget.cc",
"shelf/hotseat_widget.h",
"shelf/in_app_to_home_nudge_controller.cc",
"shelf/in_app_to_home_nudge_controller.h",
"shelf/login_shelf_gesture_controller.cc",
"shelf/login_shelf_gesture_controller.h",
"shelf/login_shelf_view.cc",
......
// Copyright 2020 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/shelf/in_app_to_home_nudge_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
namespace ash {
InAppToHomeNudgeController::InAppToHomeNudgeController(
ShelfWidget* shelf_widget)
: shelf_widget_(shelf_widget) {}
InAppToHomeNudgeController::~InAppToHomeNudgeController() = default;
void InAppToHomeNudgeController::SetNudgeAllowedForCurrentShelf(
bool in_tablet_mode,
bool in_app_shelf) {
if (in_tablet_mode && in_app_shelf) {
if (contextual_tooltip::ShouldShowNudge(
Shell::Get()->session_controller()->GetLastActiveUserPrefService(),
contextual_tooltip::TooltipType::kInAppToHome,
/*recheck_delay*/ nullptr)) {
shelf_widget_->ScheduleShowDragHandleNudge();
} else if (!shelf_widget_->GetDragHandle()
->gesture_nudge_target_visibility()) {
// If the drag handle is not yet shown, HideDragHandleNudge() should
// cancel any scheduled show requests.
shelf_widget_->HideDragHandleNudge(
contextual_tooltip::DismissNudgeReason::kOther);
}
} else {
shelf_widget_->HideDragHandleNudge(
in_tablet_mode
? contextual_tooltip::DismissNudgeReason::kExitToHomeScreen
: contextual_tooltip::DismissNudgeReason::kSwitchToClamshell);
}
}
} // namespace ash
// Copyright 2020 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_SHELF_IN_APP_TO_HOME_NUDGE_CONTROLLER_H_
#define ASH_SHELF_IN_APP_TO_HOME_NUDGE_CONTROLLER_H_
#include "ash/ash_export.h"
namespace ash {
class ShelfWidget;
// Used by Chrome to notify shelf status changes and update in app to home
// gesture contextual nudge UI.
class ASH_EXPORT InAppToHomeNudgeController {
public:
explicit InAppToHomeNudgeController(ShelfWidget* shelf_widget);
InAppToHomeNudgeController(const InAppToHomeNudgeController&) = delete;
InAppToHomeNudgeController& operator=(const InAppToHomeNudgeController&) =
delete;
~InAppToHomeNudgeController();
// Sets whether the in app to home nudge can be shown for the current shelf
// state. If the nudge is allowed, controller may show the nudge if required.
// If the nudge is not allowed, the nudge will be hidden if currently visible.
void SetNudgeAllowedForCurrentShelf(bool in_tablet_mode, bool in_app_shelf);
private:
// pointer to the shelf widget that owns the drag handle anchoring the nudge.
ShelfWidget* const shelf_widget_;
};
} // namespace ash
#endif // ASH_SHELF_IN_APP_TO_HOME_NUDGE_CONTROLLER_H_
......@@ -30,6 +30,7 @@
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/home_to_overview_nudge_controller.h"
#include "ash/shelf/hotseat_widget.h"
#include "ash/shelf/in_app_to_home_nudge_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_metrics.h"
......@@ -612,23 +613,14 @@ void ShelfLayoutManager::UpdateContextualNudges() {
contextual_tooltip::SetDragHandleNudgeDisabledForHiddenShelf(!IsVisible());
if (in_app_shelf && in_tablet_mode) {
if (contextual_tooltip::ShouldShowNudge(
Shell::Get()->session_controller()->GetLastActiveUserPrefService(),
contextual_tooltip::TooltipType::kInAppToHome, nullptr)) {
shelf_widget_->ScheduleShowDragHandleNudge();
} else if (!shelf_widget_->GetDragHandle()
->gesture_nudge_target_visibility()) {
// If the drag handle is not yet shown, HideDragHandleNudge() should
// cancel any scheduled show requests.
shelf_widget_->HideDragHandleNudge(
contextual_tooltip::DismissNudgeReason::kOther);
}
} else {
shelf_widget_->HideDragHandleNudge(
in_tablet_mode
? contextual_tooltip::DismissNudgeReason::kExitToHomeScreen
: contextual_tooltip::DismissNudgeReason::kSwitchToClamshell);
if (in_app_shelf && in_tablet_mode && !in_app_to_home_nudge_controller_) {
in_app_to_home_nudge_controller_ =
std::make_unique<InAppToHomeNudgeController>(shelf_widget_);
}
if (in_app_to_home_nudge_controller_) {
in_app_to_home_nudge_controller_->SetNudgeAllowedForCurrentShelf(
in_tablet_mode, in_app_shelf);
}
// Create home to overview nudge controller if home to overview nudge is
......
......@@ -54,6 +54,7 @@ namespace ash {
enum class AnimationChangeType;
class DragWindowFromShelfController;
class HomeToOverviewNudgeController;
class InAppToHomeNudgeController;
class PanelLayoutManagerTest;
class PresentationTimeRecorder;
class Shelf;
......@@ -636,6 +637,9 @@ class ASH_EXPORT ShelfLayoutManager
std::unique_ptr<HomeToOverviewNudgeController>
home_to_overview_nudge_controller_;
// Controller for the visibility of the InAppToHome gesture contextual nudge.
std::unique_ptr<InAppToHomeNudgeController> in_app_to_home_nudge_controller_;
// Whether upward fling from shelf should be handled as potential gesture from
// overview to home. This is set when the swipe would otherwise be handled by
// |window_drag_controller_|, but the swipe cannot be associated with a window
......
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