Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / app_list / views / app_list_item_view.h
blob95ca4f3df83aa3fa24f854ed687f0d3fb06acbe1
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/views/context_menu_controller.h"
18 #include "ui/views/controls/button/custom_button.h"
20 class SkBitmap;
22 namespace views {
23 class ImageView;
24 class Label;
25 class MenuRunner;
28 namespace app_list {
30 class AppListItem;
31 class AppsGridView;
32 class ProgressBarView;
34 class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
35 public views::ContextMenuController,
36 public AppListItemObserver {
37 public:
38 // Internal class name.
39 static const char kViewClassName[];
41 AppListItemView(AppsGridView* apps_grid_view, AppListItem* item);
42 ~AppListItemView() override;
44 // Set the icon of this image, adding a drop shadow if |has_shadow|.
45 void SetIcon(const gfx::ImageSkia& icon, bool has_shadow);
47 void SetItemName(const base::string16& display_name,
48 const base::string16& full_name);
49 void SetItemIsInstalling(bool is_installing);
50 bool is_highlighted() { return is_highlighted_; } // for unit test
51 void SetItemIsHighlighted(bool is_highlighted);
52 void SetItemPercentDownloaded(int percent_downloaded);
54 void Prerender();
56 void CancelContextMenu();
58 gfx::ImageSkia GetDragImage();
59 void OnDragEnded();
60 gfx::Point GetDragImageOffset();
62 void SetAsAttemptedFolderTarget(bool is_target_folder);
64 AppListItem* item() const { return item_weak_; }
66 views::ImageView* icon() const { return icon_; }
68 const views::Label* title() const { return title_; }
70 // In a synchronous drag the item view isn't informed directly of the drag
71 // ending, so the runner of the drag should call this.
72 void OnSyncDragEnd();
74 // Returns the icon bounds relative to AppListItemView.
75 const gfx::Rect& GetIconBounds() const;
77 // Sets UI state to dragging state.
78 void SetDragUIState();
80 // Returns the icon bounds for the given |target_bounds| as
81 // the assuming bounds of this view.
82 gfx::Rect GetIconBoundsForTargetViewBounds(const gfx::Rect& target_bounds);
84 // If the item is not in a folder, not highlighted, not being dragged, and not
85 // having something dropped onto it, enables subpixel AA for the title.
86 void SetTitleSubpixelAA();
88 // views::CustomButton overrides:
89 void OnGestureEvent(ui::GestureEvent* event) override;
91 // views::View overrides:
92 bool GetTooltipText(const gfx::Point& p,
93 base::string16* tooltip) const override;
95 private:
96 enum UIState {
97 UI_STATE_NORMAL, // Normal UI (icon + label)
98 UI_STATE_DRAGGING, // Dragging UI (scaled icon only)
99 UI_STATE_DROPPING_IN_FOLDER, // Folder dropping preview UI
102 // Get icon from |item_| and schedule background processing.
103 void UpdateIcon();
105 // Update the tooltip text from |item_|.
106 void UpdateTooltip();
108 void SetUIState(UIState state);
110 // Sets |touch_dragging_| flag and updates UI.
111 void SetTouchDragging(bool touch_dragging);
113 // Invoked when |mouse_drag_timer_| fires to show dragging UI.
114 void OnMouseDragTimer();
116 // views::View overrides:
117 const char* GetClassName() const override;
118 void Layout() override;
119 void OnPaint(gfx::Canvas* canvas) override;
121 // views::ContextMenuController overrides:
122 void ShowContextMenuForView(views::View* source,
123 const gfx::Point& point,
124 ui::MenuSourceType source_type) override;
126 // views::CustomButton overrides:
127 void StateChanged() override;
128 bool ShouldEnterPushedState(const ui::Event& event) override;
130 // views::View overrides:
131 bool OnKeyPressed(const ui::KeyEvent& event) override;
132 bool OnMousePressed(const ui::MouseEvent& event) override;
133 void OnMouseReleased(const ui::MouseEvent& event) override;
134 void OnMouseCaptureLost() override;
135 bool OnMouseDragged(const ui::MouseEvent& event) override;
137 // AppListItemObserver overrides:
138 void ItemIconChanged() override;
139 void ItemNameChanged() override;
140 void ItemIsInstallingChanged() override;
141 void ItemPercentDownloadedChanged() override;
142 void ItemBeingDestroyed() override;
144 const bool is_folder_;
145 const bool is_in_folder_;
147 AppListItem* item_weak_; // Owned by AppListModel. Can be NULL.
149 AppsGridView* apps_grid_view_; // Parent view, owns this.
150 views::ImageView* icon_; // Strongly typed child view.
151 CachedLabel* title_; // Strongly typed child view.
152 ProgressBarView* progress_bar_; // Strongly typed child view.
154 scoped_ptr<views::MenuRunner> context_menu_runner_;
156 UIState ui_state_;
158 // True if scroll gestures should contribute to dragging.
159 bool touch_dragging_;
161 bool is_installing_;
162 bool is_highlighted_;
164 base::string16 tooltip_text_;
166 // A timer to defer showing drag UI when mouse is pressed.
167 base::OneShotTimer<AppListItemView> mouse_drag_timer_;
169 DISALLOW_COPY_AND_ASSIGN(AppListItemView);
172 } // namespace app_list
174 #endif // UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_