legacy_remove_query_confirmation_dialog.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2019 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/app_list/views/legacy_remove_query_confirmation_dialog.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "ash/app_list/views/search_box_view.h"
  8. #include "ash/strings/grit/ash_strings.h"
  9. #include "base/bind.h"
  10. #include "ui/base/l10n/l10n_util.h"
  11. #include "ui/strings/grit/ui_strings.h"
  12. #include "ui/views/controls/label.h"
  13. #include "ui/views/focus/focus_manager.h"
  14. #include "ui/views/layout/box_layout.h"
  15. #include "ui/views/layout/layout_provider.h"
  16. namespace ash {
  17. namespace {
  18. constexpr int kDialogWidth = 320;
  19. } // namespace
  20. LegacyRemoveQueryConfirmationDialog::LegacyRemoveQueryConfirmationDialog(
  21. RemovalConfirmationCallback confirm_callback,
  22. const std::u16string& result_title)
  23. : confirm_callback_(std::move(confirm_callback)) {
  24. SetModalType(ui::MODAL_TYPE_WINDOW);
  25. SetTitle(l10n_util::GetStringUTF16(IDS_REMOVE_ZERO_STATE_SUGGESTION_TITLE));
  26. SetShowCloseButton(false);
  27. SetButtonLabel(ui::DIALOG_BUTTON_OK,
  28. l10n_util::GetStringUTF16(IDS_REMOVE_SUGGESTION_BUTTON_LABEL));
  29. SetButtonLabel(ui::DIALOG_BUTTON_CANCEL,
  30. l10n_util::GetStringUTF16(IDS_APP_CANCEL));
  31. auto run_callback = [](LegacyRemoveQueryConfirmationDialog* dialog,
  32. bool accept) {
  33. std::move(dialog->confirm_callback_).Run(accept);
  34. };
  35. SetAcceptCallback(base::BindOnce(run_callback, base::Unretained(this), true));
  36. SetCancelCallback(
  37. base::BindOnce(run_callback, base::Unretained(this), false));
  38. const views::LayoutProvider* provider = views::LayoutProvider::Get();
  39. SetLayoutManager(std::make_unique<views::BoxLayout>(
  40. views::BoxLayout::Orientation::kVertical,
  41. provider->GetDialogInsetsForContentType(views::DialogContentType::kText,
  42. views::DialogContentType::kText),
  43. provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
  44. auto* label =
  45. AddChildView(std::make_unique<views::Label>(l10n_util::GetStringFUTF16(
  46. IDS_REMOVE_ZERO_STATE_SUGGESTION_DETAILS, result_title)));
  47. label->SetMultiLine(true);
  48. label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  49. label->SetAllowCharacterBreak(true);
  50. }
  51. LegacyRemoveQueryConfirmationDialog::~LegacyRemoveQueryConfirmationDialog() =
  52. default;
  53. const char* LegacyRemoveQueryConfirmationDialog::GetClassName() const {
  54. return "LegacyRemoveQueryConfirmationDialog";
  55. }
  56. gfx::Size LegacyRemoveQueryConfirmationDialog::CalculatePreferredSize() const {
  57. const int default_width = kDialogWidth;
  58. return gfx::Size(default_width, GetHeightForWidth(default_width));
  59. }
  60. } // namespace ash