autozoom_toast_view.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2022 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/camera/autozoom_toast_view.h"
  5. #include "ash/resources/vector_icons/vector_icons.h"
  6. #include "ash/strings/grit/ash_strings.h"
  7. #include "ash/system/camera/autozoom_toast_controller.h"
  8. #include "ash/system/tray/tray_constants.h"
  9. #include "ash/system/unified/feature_pod_button.h"
  10. #include "ui/base/l10n/l10n_util.h"
  11. #include "ui/views/controls/button/button.h"
  12. #include "ui/views/controls/label.h"
  13. #include "ui/views/layout/box_layout.h"
  14. #include "ui/views/style/typography.h"
  15. namespace ash {
  16. AutozoomToastView::AutozoomToastView(AutozoomToastController* controller)
  17. : controller_(controller) {
  18. auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
  19. views::BoxLayout::Orientation::kHorizontal, kAutozoomToastInsets,
  20. kAutozoomToastSpacing));
  21. layout->set_cross_axis_alignment(
  22. views::BoxLayout::CrossAxisAlignment::kCenter);
  23. button_ = AddChildView(std::make_unique<FeaturePodIconButton>(
  24. FeaturePodIconButton::PressedCallback(),
  25. /*is_togglable=*/true));
  26. button_->SetVectorIcon(kUnifiedMenuAutozoomIcon);
  27. button_->SetToggled(false);
  28. button_->AddObserver(this);
  29. label_ = AddChildView(std::make_unique<views::Label>());
  30. label_->SetText(
  31. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUTOZOOM_TOAST_ON_STATE));
  32. label_->SetFontList(
  33. views::style::GetFont(views::style::TextContext::CONTEXT_DIALOG_TITLE,
  34. views::style::TextStyle::STYLE_PRIMARY));
  35. }
  36. AutozoomToastView::~AutozoomToastView() {
  37. button_->RemoveObserver(this);
  38. }
  39. void AutozoomToastView::SetAutozoomEnabled(bool enabled) {
  40. button_->SetToggled(enabled);
  41. button_->SetTooltipText(
  42. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUTOZOOM_TOAST_ON_STATE));
  43. InvalidateLayout();
  44. }
  45. std::u16string AutozoomToastView::GetAccessibleName() {
  46. return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUTOZOOM_TOAST_ON_STATE);
  47. }
  48. bool AutozoomToastView::IsButtonFocused() const {
  49. return button_->HasFocus();
  50. }
  51. void AutozoomToastView::OnViewFocused(views::View* observed_view) {
  52. DCHECK(observed_view == button_);
  53. controller_->StopAutocloseTimer();
  54. }
  55. void AutozoomToastView::OnViewBlurred(views::View* observed_view) {
  56. DCHECK(observed_view == button_);
  57. controller_->StartAutoCloseTimer();
  58. }
  59. } // namespace ash