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 5 #ifndef ASH_APP_LIST_VIEWS_SEARCH_RESULT_SUGGESTION_CHIP_VIEW_H_ 6 #define ASH_APP_LIST_VIEWS_SEARCH_RESULT_SUGGESTION_CHIP_VIEW_H_ 7 8 #include <memory> 9 10 #include "ash/app_list/app_list_export.h" 11 #include "ash/app_list/views/search_result_base_view.h" 12 #include "base/macros.h" 13 14 namespace views { 15 class BoxLayout; 16 class ImageView; 17 class InkDrop; 18 class InkDropRipple; 19 class Label; 20 } // namespace views 21 22 namespace ash { 23 24 class AppListViewDelegate; 25 26 // A chip view that displays a search result. 27 class APP_LIST_EXPORT SearchResultSuggestionChipView 28 : public SearchResultBaseView { 29 public: 30 explicit SearchResultSuggestionChipView(AppListViewDelegate* view_delegate); 31 SearchResultSuggestionChipView(const SearchResultSuggestionChipView&) = 32 delete; 33 SearchResultSuggestionChipView& operator=( 34 const SearchResultSuggestionChipView&) = delete; 35 ~SearchResultSuggestionChipView() override; 36 37 // Enables background blur for folder icon if |enabled| is true. 38 void SetBackgroundBlurEnabled(bool enabled); 39 40 void OnResultChanged() override; 41 42 // SearchResultObserver: 43 void OnMetadataChanged() override; 44 45 // views::View: 46 const char* GetClassName() const override; 47 void ChildVisibilityChanged(views::View* child) override; 48 void OnPaintBackground(gfx::Canvas* canvas) override; 49 void OnFocus() override; 50 void OnBlur() override; 51 bool OnKeyPressed(const ui::KeyEvent& event) override; 52 53 // views::InkDropHost: 54 std::unique_ptr<views::InkDrop> CreateInkDrop() override; 55 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; 56 57 // ui::LayerOwner: 58 std::unique_ptr<ui::Layer> RecreateLayer() override; 59 60 void SetIcon(const gfx::ImageSkia& icon); 61 62 void SetText(const base::string16& text); 63 const base::string16& GetText() const; 64 65 private: 66 // Updates the suggestion chip view's title and icon. 67 void UpdateSuggestionChipView(); 68 69 void InitLayout(); 70 71 void OnButtonPressed(const ui::Event& event); 72 73 // Sets rounded corners for the layer with |corner_radius| to clip the chip. 74 void SetRoundedCornersForLayer(int corner_radius); 75 76 AppListViewDelegate* const view_delegate_; // Owned by AppListView. 77 78 views::ImageView* icon_view_ = nullptr; // Owned by view hierarchy. 79 views::Label* text_view_ = nullptr; // Owned by view hierarchy. 80 81 views::BoxLayout* layout_manager_; // Owned by view hierarchy. 82 83 base::WeakPtrFactory<SearchResultSuggestionChipView> weak_ptr_factory_{this}; 84 }; 85 86 } // namespace ash 87 88 #endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_SUGGESTION_CHIP_VIEW_H_ 89