blob: 551115328c9f98ba5fc38f1b2a43679d8830cce8 [file] [log] [blame]
// Copyright 2014 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.
#include <memory>
#include "ash/app_list/model/search/search_result_observer.h"
#include "base/macros.h"
#include "ui/app_list/app_list_export.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/button.h"
namespace views {
class ImageView;
class MenuRunner;
class Label;
} // namespace views
namespace app_list {
class AppListViewDelegate;
class SearchResult;
class SearchResultContainerView;
class PaginationModel;
// A tile view that displays a search result. It hosts view for search result
// that has SearchResult::DisplayType DISPLAY_TILE or DISPLAY_RECOMMENDATION.
class APP_LIST_EXPORT SearchResultTileItemView
: public views::Button,
public views::ButtonListener,
public views::ContextMenuController,
public SearchResultObserver {
SearchResultTileItemView(SearchResultContainerView* result_container,
AppListViewDelegate* view_delegate,
PaginationModel* pagination_model);
~SearchResultTileItemView() override;
SearchResult* result() { return item_; }
void SetSearchResult(SearchResult* item);
// Informs the SearchResultTileItemView of its parent's background color. The
// controls within the SearchResultTileItemView will adapt to suit the given
// color.
void SetParentBackgroundColor(SkColor color);
// Records the context menu user journey time.
void OnContextMenuClosed(const base::TimeTicks& open_time);
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Overridden from views::Button:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
bool OnKeyPressed(const ui::KeyEvent& event) override;
void OnFocus() override;
void OnBlur() override;
void StateChanged(ButtonState old_state) override;
void PaintButtonContents(gfx::Canvas* canvas) override;
// Overridden from SearchResultObserver:
void OnIconChanged() override;
void OnBadgeIconChanged() override;
void OnRatingChanged() override;
void OnFormattedPriceChanged() override;
void OnResultDestroying() override;
// views::ContextMenuController overrides:
void ShowContextMenuForView(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
void SetIcon(const gfx::ImageSkia& icon);
void SetBadgeIcon(const gfx::ImageSkia& badge_icon);
void SetTitle(const base::string16& title);
void SetRating(float rating);
void SetPrice(const base::string16& price);
// Whether the tile view is a suggested app.
bool IsSuggestedAppTile() const;
// Records an app being launched.
void LogAppLaunch() const;
void UpdateBackgroundColor();
// Overridden from views::View:
void Layout() override;
const char* GetClassName() const override;
gfx::Size CalculatePreferredSize() const override;
bool GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const override;
SearchResultContainerView* const result_container_; // Parent view
AppListViewDelegate* const view_delegate_; // Owned by AppListView.
PaginationModel* const pagination_model_; // Owned by AppsGridView.
// Owned by the model provided by the AppListViewDelegate.
SearchResult* item_ = nullptr;
views::ImageView* icon_ = nullptr; // Owned by views hierarchy.
views::ImageView* badge_ = nullptr; // Owned by views hierarchy.
views::Label* title_ = nullptr; // Owned by views hierarchy.
views::Label* rating_ = nullptr; // Owned by views hierarchy.
views::Label* price_ = nullptr; // Owned by views hierarchy.
views::ImageView* rating_star_ = nullptr; // Owned by views hierarchy.
SkColor parent_background_color_ = SK_ColorTRANSPARENT;
std::unique_ptr<views::MenuRunner> context_menu_runner_;
const bool is_play_store_app_search_enabled_;
base::WeakPtrFactory<SearchResultTileItemView> weak_ptr_factory_;
} // namespace app_list