phone_connected_view.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/system/phonehub/phone_connected_view.h"
  5. #include <memory>
  6. #include "ash/components/phonehub/multidevice_feature_access_manager.h"
  7. #include "ash/components/phonehub/phone_hub_manager.h"
  8. #include "ash/components/phonehub/user_action_recorder.h"
  9. #include "ash/constants/ash_features.h"
  10. #include "ash/style/ash_color_provider.h"
  11. #include "ash/system/phonehub/camera_roll_view.h"
  12. #include "ash/system/phonehub/multidevice_feature_opt_in_view.h"
  13. #include "ash/system/phonehub/phone_hub_recent_apps_view.h"
  14. #include "ash/system/phonehub/phone_hub_view_ids.h"
  15. #include "ash/system/phonehub/phone_status_view.h"
  16. #include "ash/system/phonehub/quick_actions_view.h"
  17. #include "ash/system/phonehub/task_continuation_view.h"
  18. #include "ash/system/phonehub/ui_constants.h"
  19. #include "ash/system/tray/tray_constants.h"
  20. #include "ui/base/resource/resource_bundle.h"
  21. #include "ui/compositor/layer.h"
  22. #include "ui/gfx/geometry/insets.h"
  23. #include "ui/gfx/paint_vector_icon.h"
  24. #include "ui/views/controls/image_view.h"
  25. #include "ui/views/controls/label.h"
  26. #include "ui/views/controls/separator.h"
  27. #include "ui/views/layout/box_layout.h"
  28. namespace ash {
  29. namespace {
  30. constexpr auto kDarkLightModeEnabledPadding =
  31. gfx::Insets::TLBR(0,
  32. kBubbleHorizontalSidePaddingDip,
  33. 16,
  34. kBubbleHorizontalSidePaddingDip);
  35. constexpr auto kDarkLightModeDisabledPadding =
  36. gfx::Insets::VH(0, kBubbleHorizontalSidePaddingDip);
  37. } // namespace
  38. PhoneConnectedView::PhoneConnectedView(
  39. phonehub::PhoneHubManager* phone_hub_manager) {
  40. SetID(PhoneHubViewID::kPhoneConnectedView);
  41. auto setup_layered_view = [](views::View* view) {
  42. // In dark light mode, we switch TrayBubbleView to use a textured layer
  43. // instead of solid color layer, so no need to create an extra layer here.
  44. if (features::IsDarkLightModeEnabled())
  45. return;
  46. view->SetPaintToLayer();
  47. view->layer()->SetFillsBoundsOpaquely(false);
  48. };
  49. auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
  50. views::BoxLayout::Orientation::kVertical,
  51. features::IsDarkLightModeEnabled() ? kDarkLightModeEnabledPadding
  52. : kDarkLightModeDisabledPadding));
  53. layout->SetDefaultFlex(1);
  54. AddChildView(std::make_unique<MultideviceFeatureOptInView>(
  55. phone_hub_manager->GetMultideviceFeatureAccessManager()));
  56. setup_layered_view(
  57. AddChildView(std::make_unique<QuickActionsView>(phone_hub_manager)));
  58. auto* phone_model = phone_hub_manager->GetPhoneModel();
  59. if (phone_model) {
  60. setup_layered_view(AddChildView(std::make_unique<TaskContinuationView>(
  61. phone_model, phone_hub_manager->GetUserActionRecorder())));
  62. }
  63. auto* camera_roll_manager = phone_hub_manager->GetCameraRollManager();
  64. if (features::IsPhoneHubCameraRollEnabled() && camera_roll_manager) {
  65. setup_layered_view(AddChildView(std::make_unique<CameraRollView>(
  66. camera_roll_manager, phone_hub_manager->GetUserActionRecorder())));
  67. }
  68. auto* recent_apps_handler =
  69. phone_hub_manager->GetRecentAppsInteractionHandler();
  70. if (features::IsEcheSWAEnabled() && recent_apps_handler) {
  71. setup_layered_view(AddChildView(
  72. std::make_unique<PhoneHubRecentAppsView>(recent_apps_handler)));
  73. }
  74. phone_hub_manager->GetUserActionRecorder()->RecordUiOpened();
  75. }
  76. PhoneConnectedView::~PhoneConnectedView() = default;
  77. void PhoneConnectedView::ChildPreferredSizeChanged(View* child) {
  78. // Resize the bubble when the child change its size.
  79. PreferredSizeChanged();
  80. }
  81. void PhoneConnectedView::ChildVisibilityChanged(View* child) {
  82. // Resize the bubble when the child change its visibility.
  83. PreferredSizeChanged();
  84. }
  85. const char* PhoneConnectedView::GetClassName() const {
  86. return "PhoneConnectedView";
  87. }
  88. phone_hub_metrics::Screen PhoneConnectedView::GetScreenForMetrics() const {
  89. return phone_hub_metrics::Screen::kPhoneConnected;
  90. }
  91. } // namespace ash