123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- // Copyright (c) 2012 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #ifndef ASH_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_
- #define ASH_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_
- #include <memory>
- #include <vector>
- #include "ash/app_list/model/search/search_result.h"
- #include "ash/app_list/views/search_result_actions_view_delegate.h"
- #include "ash/app_list/views/search_result_base_view.h"
- #include "ash/ash_export.h"
- #include "base/compiler_specific.h"
- #include "base/memory/weak_ptr.h"
- namespace views {
- class FlexLayoutView;
- class ImageView;
- class Label;
- } // namespace views
- namespace ash {
- namespace test {
- class SearchResultListViewTest;
- class SearchResultViewWidgetTest;
- } // namespace test
- class AppListViewDelegate;
- class MaskedImageView;
- class SearchResult;
- class SearchResultListView;
- class SearchResultPageDialogController;
- // Search result view uses `views::FlexLayout` to show results in different
- // configurations.
- // +---------------------------------------------------------------+
- // |`text_container_` |
- // | +----------------------+ +----------------------------------+ |
- // | |`big_title_container_'| |`body_text_container_` | |
- // | | | | +------------------------------+ | |
- // | | | | |`title_and_details_container_`| | |
- // | | | | +------------------------------+ | |
- // | | | | +------------------------------+ | |
- // | | | | |`keyboard_shortcut_container_`| | |
- // | | | | +------------------------------+ | |
- // | +----------------------+ +----------------------------------+ |
- // +---------------------------------------------------------------+
- //
- // +-------------------------------------------------------------------------+
- // |`big_title_container_` |
- // | +--------------------------------+ +----------------------------------+ |
- // | |'big_title_main_text_container_'| |`big_title_superscript_container_`| |
- // | +--------------------------------+ +----------------------------------+ |
- // +-------------------------------------------------------------------------+
- //
- // The `title_and_details_container_` has two possible layouts depending on
- // `view_type_` and whether `keyboard_shortcut_container_` has results
- //
- // Layout used when the view_type_ == SearchResultViewType::kDefault OR
- // `has_keyboard_shortcut_contents_` is set.
- //
- // +--------------------------------------------------------------------+
- // |`title_and_details_container_` |
- // | +------------------+ +------------------+ +--------------------+ |
- // | |'title_container_'| |`separator_label_`| |`details_container_`| |
- // | +------------------+ +------------------+ +--------------------+ |
- // +--------------------------------------------------------------------+
- //
- // layout used when view type is SearchResultViewType::kAnswerCard or
- // SearchResultViewType::kClassic.
- // +-------------------------------+
- // |`title_and_details_container_` |
- // | +------------------+ |
- // | |'title_container_'| |
- // | +------------------+ |
- // | +--------------------+ |
- // | |'details_container_'| |
- // | +--------------------+ |
- // +-------------------------------+
- class ASH_EXPORT SearchResultView : public SearchResultBaseView,
- public SearchResultActionsViewDelegate {
- public:
- class LabelAndTag {
- public:
- LabelAndTag(views::Label* label, SearchResult::Tags tags);
- LabelAndTag(const LabelAndTag& other);
- LabelAndTag& operator=(const LabelAndTag& other);
- ~LabelAndTag();
- views::Label* GetLabel() const { return label_; }
- SearchResult::Tags GetTags() const { return tags_; }
- private:
- views::Label* label_; // Owned by views hierarchy.
- SearchResult::Tags tags_;
- };
- enum class SearchResultViewType {
- // The default vew type used for the majority of search results.
- kDefault,
- // The classic view type continues support for pre-BubbleView launcher's
- // search UI.
- kClassic,
- // Inline Answer views are used to directly answer questions posed by the
- // search query.
- kAnswerCard,
- };
- enum class LabelType {
- kBigTitle,
- kBigTitleSuperscript,
- kTitle,
- kDetails,
- kKeyboardShortcut,
- };
- // Internal class name.
- static const char kViewClassName[];
- SearchResultView(SearchResultListView* list_view,
- AppListViewDelegate* view_delegate,
- SearchResultPageDialogController* dialog_controller,
- SearchResultViewType view_type);
- SearchResultView(const SearchResultView&) = delete;
- SearchResultView& operator=(const SearchResultView&) = delete;
- ~SearchResultView() override;
- // Sets/gets SearchResult displayed by this view.
- void OnResultChanged() override;
- void SetSearchResultViewType(SearchResultViewType type);
- void ClearBigTitleContainer();
- SearchResultViewType view_type() { return view_type_; }
- views::LayoutOrientation TitleAndDetailsOrientationForTest();
- // Calculates the width of the `title_container_` and 'details_container_'
- // for SearchResultView's custom eliding behavior.
- // total_width is the total width allocated to `title_and_details_container_`
- static int GetTargetTitleWidth(int total_width,
- int separator_width,
- int target_details_width);
- static int GetMinimumDetailsWidth(int total_width,
- int details_width,
- int details_no_elide_width);
- // Set flex layout weights for title and details containers to support custom
- // eliding behavior.
- static void SetFlexBehaviorForTextContents(
- int total_width,
- int separator_width,
- int non_elided_details_width,
- views::FlexLayoutView* title_container,
- views::FlexLayoutView* details_container);
- private:
- friend class test::SearchResultListViewTest;
- friend class SearchResultListView;
- friend class SearchResultViewWidgetTest;
- void set_multi_line_label_height_for_test(int height) {
- multi_line_label_height_ = height;
- }
- int PreferredHeight() const;
- int PrimaryTextHeight() const;
- int SecondaryTextHeight() const;
- int ActionButtonRightMargin() const;
- std::vector<LabelAndTag> SetupContainerViewForTextVector(
- views::FlexLayoutView* parent,
- const std::vector<SearchResult::TextItem>& text_vector,
- LabelType label_type,
- bool has_keyboard_shortcut_contents,
- bool is_multi_line);
- void UpdateBadgeIcon();
- void UpdateBigTitleContainer();
- void UpdateBigTitleSuperscriptContainer();
- void UpdateTitleContainer();
- void UpdateDetailsContainer();
- void UpdateKeyboardShortcutContainer();
- void UpdateRating();
- void StyleLabel(views::Label* label,
- bool is_title_label,
- const SearchResult::Tags& tags);
- void StyleBigTitleContainer();
- void StyleBigTitleSuperscriptContainer();
- void StyleTitleContainer();
- void StyleDetailsContainer();
- void StyleKeyboardShortcutContainer();
- // Callback for query suggstion removal confirmation.
- void OnQueryRemovalAccepted(bool accepted);
- // Called when the result selection controller selects a new result.
- void OnSelectedResultChanged();
- // views::View overrides:
- const char* GetClassName() const override;
- gfx::Size CalculatePreferredSize() const override;
- void Layout() override;
- bool OnKeyPressed(const ui::KeyEvent& event) override;
- void PaintButtonContents(gfx::Canvas* canvas) override;
- void OnMouseEntered(const ui::MouseEvent& event) override;
- void OnMouseExited(const ui::MouseEvent& event) override;
- void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
- void VisibilityChanged(View* starting_from, bool is_visible) override;
- void OnThemeChanged() override;
- // ui::EventHandler overrides:
- void OnGestureEvent(ui::GestureEvent* event) override;
- // SearchResultObserver overrides:
- void OnMetadataChanged() override;
- void OnButtonPressed(const ui::Event& event);
- void SetIconImage(const gfx::ImageSkia& source,
- views::ImageView* const icon,
- const gfx::Size& size);
- // SearchResultActionsViewDelegate overrides:
- void OnSearchResultActionActivated(size_t index) override;
- bool IsSearchResultHoveredOrSelected() override;
- // Parent list view. Owned by views hierarchy.
- SearchResultListView* const list_view_;
- AppListViewDelegate* const view_delegate_;
- SearchResultPageDialogController* const dialog_controller_;
- MaskedImageView* icon_ = nullptr; // Owned by views hierarchy.
- views::ImageView* badge_icon_ = nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* text_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* big_title_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* big_title_main_text_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* big_title_superscript_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* body_text_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* title_and_details_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* title_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* details_container_ =
- nullptr; // Owned by views hierarchy.
- views::FlexLayoutView* keyboard_shortcut_container_ =
- nullptr; // Owned by views hierarchy.
- std::vector<LabelAndTag> big_title_label_tags_; // Owned by views hierarchy.
- std::vector<LabelAndTag>
- big_title_superscript_label_tags_; // Owned by views hierarchy.
- std::vector<LabelAndTag> title_label_tags_; // Owned by views hierarchy.
- std::vector<LabelAndTag> details_label_tags_; // Owned by views hierarchy.
- std::vector<LabelAndTag>
- keyboard_shortcut_container_tags_; // Owned by views hierarchy.
- views::Label* result_text_separator_label_ =
- nullptr; // Owned by views hierarchy.
- views::Label* rating_separator_label_ = nullptr; // Owned by views hierarchy.
- views::Label* rating_ = nullptr; // Owned by views hierarchy.
- views::ImageView* rating_star_ = nullptr; // Owned by views hierarchy.
- // Whether the removal confirmation dialog is invoked by long press touch.
- bool confirm_remove_by_long_press_ = false;
- // Separator label is shown for `kDefault` when details text is not empty,
- bool should_show_result_text_separator_label_ = false;
- // Used to override `title_and_details_container_` layout when
- // `keyboard_shortcut_container_` is populated.
- bool has_keyboard_shortcut_contents_ = false;
- SearchResultViewType view_type_;
- // Search result view can have one non-elided label. Cache the its for flex
- // layout weight calculations.
- int non_elided_details_label_width_ = 0;
- // Search result view can have one multi-line label. Cache its height for
- // calculating PreferredHeight() and SecondaryTextHeight().
- int multi_line_label_height_ = 0;
- base::WeakPtrFactory<SearchResultView> weak_ptr_factory_{this};
- };
- } // namespace ash
- #endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_VIEW_H_
|