Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / app_list / views / app_list_item_view.h
blobc434371e1ff74e38da3b670db72801cf59ed3263
1 // Copyright (c) 2012 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.
5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_
6 #define UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "base/timer/timer.h"
14 #include "ui/app_list/app_list_export.h"
15 #include "ui/app_list/app_list_item_observer.h"
16 #include "ui/app_list/views/cached_label.h"
17 #include "ui/app_list/views/image_shadow_animator.h"
18 #include "ui/views/context_menu_controller.h"
19 #include "ui/views/controls/button/custom_button.h"
21 class SkBitmap;
23 namespace views {
24 class ImageView;
25 class Label;
26 class MenuRunner;
29 namespace app_list {
31 class AppListItem;
32 class AppsGridView;
33 class ProgressBarView;
35 class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
36 public views::ContextMenuController,
37 public AppListItemObserver,
38 public ImageShadowAnimator::Delegate {
39 public:
40 // Internal class name.
41 static const char kViewClassName[];
43 AppListItemView(AppsGridView* apps_grid_view, AppListItem* item);
44 ~AppListItemView() override;
46 // Set the icon of this image, adding a drop shadow if |has_shadow|.
47 void SetIcon(const gfx::ImageSkia& icon);
49 void SetItemName(const base::string16& display_name,
50 const base::string16& full_name);
51 void SetItemIsInstalling(bool is_installing);
52 bool is_highlighted() { return is_highlighted_; } // for unit test
53 void SetItemIsHighlighted(bool is_highlighted);
54 void SetItemPercentDownloaded(int percent_downloaded);
56 void Prerender();
58 void CancelContextMenu();
60 gfx::ImageSkia GetDragImage();
61 void OnDragEnded();
62 gfx::Point GetDragImageOffset();
64 void SetAsAttemptedFolderTarget(bool is_target_folder);
66 AppListItem* item() const { return item_weak_; }
68 views::ImageView* icon() const { return icon_; }
70 const views::Label* title() const { return title_; }
72 // In a synchronous drag the item view isn't informed directly of the drag
73 // ending, so the runner of the drag should call this.
74 void OnSyncDragEnd();
76 // Returns the icon bounds relative to AppListItemView.
77 const gfx::Rect& GetIconBounds() const;
79 // Sets UI state to dragging state.
80 void SetDragUIState();
82 // Returns the icon bounds for the given |target_bounds| as
83 // the assuming bounds of this view.
84 gfx::Rect GetIconBoundsForTargetViewBounds(const gfx::Rect& target_bounds);
86 // If the item is not in a folder, not highlighted, not being dragged, and not
87 // having something dropped onto it, enables subpixel AA for the title.
88 void SetTitleSubpixelAA();
90 // views::CustomButton overrides:
91 void OnGestureEvent(ui::GestureEvent* event) override;
93 // views::View overrides:
94 bool GetTooltipText(const gfx::Point& p,
95 base::string16* tooltip) const override;
97 // ImageShadowAnimator::Delegate overrides:
98 void ImageShadowAnimationProgressed(ImageShadowAnimator* animator) override;
100 private:
101 enum UIState {
102 UI_STATE_NORMAL, // Normal UI (icon + label)
103 UI_STATE_DRAGGING, // Dragging UI (scaled icon only)
104 UI_STATE_DROPPING_IN_FOLDER, // Folder dropping preview UI
107 // Get icon from |item_| and schedule background processing.
108 void UpdateIcon();
110 // Update the tooltip text from |item_|.
111 void UpdateTooltip();
113 void SetUIState(UIState state);
115 // Sets |touch_dragging_| flag and updates UI.
116 void SetTouchDragging(bool touch_dragging);
118 // Invoked when |mouse_drag_timer_| fires to show dragging UI.
119 void OnMouseDragTimer();
121 // views::View overrides:
122 const char* GetClassName() const override;
123 void Layout() override;
124 void OnPaint(gfx::Canvas* canvas) override;
126 // views::ContextMenuController overrides:
127 void ShowContextMenuForView(views::View* source,
128 const gfx::Point& point,
129 ui::MenuSourceType source_type) override;
131 // views::CustomButton overrides:
132 void StateChanged() override;
133 bool ShouldEnterPushedState(const ui::Event& event) override;
135 // views::View overrides:
136 bool OnKeyPressed(const ui::KeyEvent& event) override;
137 bool OnMousePressed(const ui::MouseEvent& event) override;
138 void OnMouseReleased(const ui::MouseEvent& event) override;
139 void OnMouseCaptureLost() override;
140 bool OnMouseDragged(const ui::MouseEvent& event) override;
142 // AppListItemObserver overrides:
143 void ItemIconChanged() override;
144 void ItemNameChanged() override;
145 void ItemIsInstallingChanged() override;
146 void ItemPercentDownloadedChanged() override;
147 void ItemBeingDestroyed() override;
149 const bool is_folder_;
150 const bool is_in_folder_;
152 AppListItem* item_weak_; // Owned by AppListModel. Can be NULL.
154 AppsGridView* apps_grid_view_; // Parent view, owns this.
155 views::ImageView* icon_; // Strongly typed child view.
156 CachedLabel* title_; // Strongly typed child view.
157 ProgressBarView* progress_bar_; // Strongly typed child view.
159 scoped_ptr<views::MenuRunner> context_menu_runner_;
161 UIState ui_state_;
163 // True if scroll gestures should contribute to dragging.
164 bool touch_dragging_;
166 ImageShadowAnimator shadow_animator_;
168 bool is_installing_;
169 bool is_highlighted_;
171 base::string16 tooltip_text_;
173 // A timer to defer showing drag UI when mouse is pressed.
174 base::OneShotTimer<AppListItemView> mouse_drag_timer_;
176 DISALLOW_COPY_AND_ASSIGN(AppListItemView);
179 } // namespace app_list
181 #endif // UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_