bluetooth_disabled_view.cc 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/bluetooth_disabled_view.h"
  5. #include "ash/components/phonehub/url_constants.h"
  6. #include "ash/public/cpp/new_window_delegate.h"
  7. #include "ash/public/cpp/resources/grit/ash_public_unscaled_resources.h"
  8. #include "ash/root_window_controller.h"
  9. #include "ash/shell.h"
  10. #include "ash/strings/grit/ash_strings.h"
  11. #include "ash/style/ash_color_provider.h"
  12. #include "ash/style/pill_button.h"
  13. #include "ash/system/phonehub/phone_hub_interstitial_view.h"
  14. #include "ash/system/phonehub/phone_hub_metrics.h"
  15. #include "ash/system/phonehub/phone_hub_tray.h"
  16. #include "ash/system/phonehub/phone_hub_view_ids.h"
  17. #include "ash/system/phonehub/ui_constants.h"
  18. #include "ash/system/status_area_widget.h"
  19. #include "base/bind.h"
  20. #include "ui/base/l10n/l10n_util.h"
  21. #include "ui/base/metadata/metadata_impl_macros.h"
  22. #include "ui/base/resource/resource_bundle.h"
  23. #include "ui/chromeos/devicetype_utils.h"
  24. #include "ui/views/layout/fill_layout.h"
  25. namespace ash {
  26. using phone_hub_metrics::InterstitialScreenEvent;
  27. using phone_hub_metrics::Screen;
  28. BluetoothDisabledView::BluetoothDisabledView() {
  29. SetID(PhoneHubViewID::kBluetoothDisabledView);
  30. SetLayoutManager(std::make_unique<views::FillLayout>());
  31. auto* content_view = AddChildView(
  32. std::make_unique<PhoneHubInterstitialView>(/*show_progress=*/false));
  33. content_view->SetImage(
  34. ui::ResourceBundle::GetSharedInstance().GetThemedLottieImageNamed(
  35. IDR_PHONE_HUB_ERROR_STATE_IMAGE));
  36. content_view->SetTitle(l10n_util::GetStringUTF16(
  37. IDS_ASH_PHONE_HUB_BLUETOOTH_DISABLED_DIALOG_TITLE));
  38. content_view->SetDescription(l10n_util::GetStringFUTF16(
  39. IDS_ASH_PHONE_HUB_BLUETOOTH_DISABLED_DIALOG_DESCRIPTION,
  40. ui::GetChromeOSDeviceName()));
  41. // Add "Learn more" button.
  42. auto learn_more = std::make_unique<PillButton>(
  43. base::BindRepeating(&BluetoothDisabledView::LearnMoreButtonPressed,
  44. base::Unretained(this)),
  45. l10n_util::GetStringUTF16(
  46. IDS_ASH_PHONE_HUB_BLUETOOTH_DISABLED_DIALOG_LEARN_MORE_BUTTON),
  47. PillButton::Type::kIconlessFloating, /*icon=*/nullptr);
  48. learn_more->SetID(PhoneHubViewID::kBluetoothDisabledLearnMoreButton);
  49. content_view->AddButton(std::move(learn_more));
  50. LogInterstitialScreenEvent(InterstitialScreenEvent::kShown);
  51. }
  52. BluetoothDisabledView::~BluetoothDisabledView() = default;
  53. phone_hub_metrics::Screen BluetoothDisabledView::GetScreenForMetrics() const {
  54. return Screen::kBluetoothOrWifiDisabled;
  55. }
  56. void BluetoothDisabledView::LearnMoreButtonPressed() {
  57. LogInterstitialScreenEvent(InterstitialScreenEvent::kLearnMore);
  58. NewWindowDelegate::GetPrimary()->OpenUrl(
  59. GURL(phonehub::kPhoneHubLearnMoreLink),
  60. NewWindowDelegate::OpenUrlFrom::kUserInteraction,
  61. NewWindowDelegate::Disposition::kNewForegroundTab);
  62. }
  63. BEGIN_METADATA(BluetoothDisabledView, views::View)
  64. END_METADATA
  65. } // namespace ash