search_result_suggestion_chip_view.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2018 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. #ifndef ASH_APP_LIST_VIEWS_SEARCH_RESULT_SUGGESTION_CHIP_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_SEARCH_RESULT_SUGGESTION_CHIP_VIEW_H_
  6. #include <memory>
  7. #include "ash/app_list/views/search_result_base_view.h"
  8. #include "ash/ash_export.h"
  9. namespace views {
  10. class BoxLayout;
  11. class ImageView;
  12. class Label;
  13. } // namespace views
  14. namespace ash {
  15. class AppListViewDelegate;
  16. // A chip view that displays a search result.
  17. class ASH_EXPORT SearchResultSuggestionChipView : public SearchResultBaseView {
  18. public:
  19. explicit SearchResultSuggestionChipView(AppListViewDelegate* view_delegate);
  20. SearchResultSuggestionChipView(const SearchResultSuggestionChipView&) =
  21. delete;
  22. SearchResultSuggestionChipView& operator=(
  23. const SearchResultSuggestionChipView&) = delete;
  24. ~SearchResultSuggestionChipView() override;
  25. // Enables background blur for folder icon if |enabled| is true.
  26. void SetBackgroundBlurEnabled(bool enabled);
  27. void OnResultChanged() override;
  28. // SearchResultObserver:
  29. void OnMetadataChanged() override;
  30. // views::View:
  31. const char* GetClassName() const override;
  32. void ChildVisibilityChanged(views::View* child) override;
  33. void OnPaintBackground(gfx::Canvas* canvas) override;
  34. void OnFocus() override;
  35. void OnBlur() override;
  36. bool OnKeyPressed(const ui::KeyEvent& event) override;
  37. void OnThemeChanged() override;
  38. // ui::LayerOwner:
  39. std::unique_ptr<ui::Layer> RecreateLayer() override;
  40. void SetIcon(const gfx::ImageSkia& icon);
  41. void SetText(const std::u16string& text);
  42. const std::u16string& GetText() const;
  43. private:
  44. // Updates the suggestion chip view's title and icon.
  45. void UpdateSuggestionChipView();
  46. void InitLayout();
  47. void OnButtonPressed(const ui::Event& event);
  48. // Sets rounded corners for the layer with |corner_radius| to clip the chip.
  49. void SetRoundedCornersForLayer(float corner_radius);
  50. // The color of the enabled focus ring. Stored so we can swap between this and
  51. // transparent.
  52. const ui::ColorId focus_ring_color_;
  53. AppListViewDelegate* const view_delegate_; // Owned by AppListView.
  54. views::ImageView* icon_view_ = nullptr; // Owned by view hierarchy.
  55. views::Label* text_view_ = nullptr; // Owned by view hierarchy.
  56. views::BoxLayout* layout_manager_; // Owned by view hierarchy.
  57. base::WeakPtrFactory<SearchResultSuggestionChipView> weak_ptr_factory_{this};
  58. };
  59. } // namespace ash
  60. #endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_SUGGESTION_CHIP_VIEW_H_