in_app_to_home_nudge_controller.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/shelf/in_app_to_home_nudge_controller.h"
  5. #include "ash/session/session_controller_impl.h"
  6. #include "ash/shelf/drag_handle.h"
  7. #include "ash/shelf/shelf_widget.h"
  8. #include "ash/shell.h"
  9. namespace ash {
  10. InAppToHomeNudgeController::InAppToHomeNudgeController(
  11. ShelfWidget* shelf_widget)
  12. : shelf_widget_(shelf_widget) {}
  13. InAppToHomeNudgeController::~InAppToHomeNudgeController() = default;
  14. void InAppToHomeNudgeController::SetNudgeAllowedForCurrentShelf(
  15. bool in_tablet_mode,
  16. bool in_app_shelf,
  17. bool shelf_controls_visible) {
  18. // HideDragHandleNudge should hide the in app to home nudge if shelf controls
  19. // are enabled. We need the in_tablet_mode check to prevent misreporting the
  20. // hide cause when exiting tablet mode.
  21. if (shelf_controls_visible && in_tablet_mode) {
  22. shelf_widget_->HideDragHandleNudge(
  23. contextual_tooltip::DismissNudgeReason::kOther);
  24. return;
  25. }
  26. if (in_tablet_mode && in_app_shelf) {
  27. if (contextual_tooltip::ShouldShowNudge(
  28. Shell::Get()->session_controller()->GetLastActiveUserPrefService(),
  29. contextual_tooltip::TooltipType::kInAppToHome,
  30. /*recheck_delay*/ nullptr)) {
  31. shelf_widget_->ScheduleShowDragHandleNudge();
  32. } else if (!shelf_widget_->GetDragHandle()
  33. ->gesture_nudge_target_visibility()) {
  34. // If the drag handle is not yet shown, HideDragHandleNudge() should
  35. // cancel any scheduled show requests.
  36. shelf_widget_->HideDragHandleNudge(
  37. contextual_tooltip::DismissNudgeReason::kOther);
  38. }
  39. } else {
  40. shelf_widget_->HideDragHandleNudge(
  41. in_tablet_mode
  42. ? contextual_tooltip::DismissNudgeReason::kExitToHomeScreen
  43. : contextual_tooltip::DismissNudgeReason::kSwitchToClamshell);
  44. }
  45. }
  46. } // namespace ash