privacy_container_view.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/app_list/views/privacy_container_view.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "ash/app_list/app_list_view_delegate.h"
  8. #include "ash/app_list/model/search/search_result.h"
  9. #include "ash/app_list/views/suggested_content_info_view.h"
  10. #include "ash/public/cpp/app_list/app_list_config.h"
  11. #include "ash/public/cpp/app_list/app_list_types.h"
  12. #include "ui/views/layout/box_layout.h"
  13. namespace ash {
  14. PrivacyContainerView::PrivacyContainerView(AppListViewDelegate* view_delegate)
  15. : SearchResultContainerView(view_delegate) {
  16. // |ShouldShowSuggestedContentInfo()| cannot change from false to true in the
  17. // middle of a session.
  18. if (view_delegate->ShouldShowSuggestedContentInfo()) {
  19. suggested_content_info_view_ = AddChildView(
  20. std::make_unique<SuggestedContentInfoView>(view_delegate, this));
  21. }
  22. auto metadata = std::make_unique<SearchResultMetadata>();
  23. metadata->id = "PrivacyInfoResult";
  24. metadata->result_type = AppListSearchResultType::kInternalPrivacyInfo;
  25. result_.SetMetadata(std::move(metadata));
  26. // This container simply wraps around PrivacyInfoView.
  27. SetLayoutManager(std::make_unique<views::BoxLayout>(
  28. views::BoxLayout::Orientation::kVertical, gfx::Insets(), 0));
  29. }
  30. PrivacyContainerView::~PrivacyContainerView() = default;
  31. SearchResultBaseView* PrivacyContainerView::GetResultViewAt(size_t index) {
  32. if (index != 0) {
  33. // There is only one result.
  34. return nullptr;
  35. }
  36. if (suggested_content_info_view_ &&
  37. suggested_content_info_view_->GetVisible()) {
  38. return suggested_content_info_view_;
  39. }
  40. return nullptr;
  41. }
  42. int PrivacyContainerView::DoUpdate() {
  43. const bool should_show_suggested_content =
  44. view_delegate()->ShouldShowSuggestedContentInfo();
  45. if (suggested_content_info_view_) {
  46. const bool has_result = suggested_content_info_view_->result();
  47. if (has_result != should_show_suggested_content) {
  48. suggested_content_info_view_->SetResult(
  49. should_show_suggested_content ? &result_ : nullptr);
  50. }
  51. suggested_content_info_view_->SetVisible(should_show_suggested_content);
  52. }
  53. return should_show_suggested_content ? 1 : 0;
  54. }
  55. } // namespace ash