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_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/timer/timer.h"
13 #include "ui/app_list/app_list_export.h"
14 #include "ui/app_list/app_list_item_observer.h"
15 #include "ui/app_list/views/cached_label.h"
16 #include "ui/views/context_menu_controller.h"
17 #include "ui/views/controls/button/custom_button.h"
31 class ProgressBarView;
33 class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
34 public views::ContextMenuController,
35 public AppListItemObserver {
37 // Internal class name.
38 static const char kViewClassName[];
40 AppListItemView(AppsGridView* apps_grid_view, AppListItem* item);
41 virtual ~AppListItemView();
45 void CancelContextMenu();
47 gfx::ImageSkia GetDragImage();
49 gfx::Point GetDragImageOffset();
51 void SetAsAttemptedFolderTarget(bool is_target_folder);
53 AppListItem* item() const { return item_; }
55 views::ImageView* icon() const { return icon_; }
57 const views::Label* title() const { return title_; }
59 // In a synchronous drag the item view isn't informed directly of the drag
60 // ending, so the runner of the drag should call this.
63 // Returns the icon bounds relative to AppListItemView.
64 const gfx::Rect& GetIconBounds() const;
66 // Sets UI state to dragging state.
67 void SetDragUIState();
69 // Returns the icon bounds for the given |target_bounds| as
70 // the assuming bounds of this view.
71 gfx::Rect GetIconBoundsForTargetViewBounds(const gfx::Rect& target_bounds);
75 UI_STATE_NORMAL, // Normal UI (icon + label)
76 UI_STATE_DRAGGING, // Dragging UI (scaled icon only)
77 UI_STATE_DROPPING_IN_FOLDER, // Folder dropping preview UI
80 // Get icon from |item_| and schedule background processing.
83 // Update the tooltip text from |item_|.
86 void SetUIState(UIState state);
88 // Sets |touch_dragging_| flag and updates UI.
89 void SetTouchDragging(bool touch_dragging);
91 // Invoked when |mouse_drag_timer_| fires to show dragging UI.
92 void OnMouseDragTimer();
94 // If the item is not in a folder, not highlighted, not being dragged, and not
95 // having something dropped onto it, enables subpixel AA for the title.
96 void SetTitleSubpixelAA();
98 // AppListItemObserver overrides:
99 virtual void ItemIconChanged() OVERRIDE;
100 virtual void ItemNameChanged() OVERRIDE;
101 virtual void ItemHighlightedChanged() OVERRIDE;
102 virtual void ItemIsInstallingChanged() OVERRIDE;
103 virtual void ItemPercentDownloadedChanged() OVERRIDE;
105 // views::View overrides:
106 virtual const char* GetClassName() const OVERRIDE;
107 virtual void Layout() OVERRIDE;
108 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE;
109 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
111 // views::ContextMenuController overrides:
112 virtual void ShowContextMenuForView(views::View* source,
113 const gfx::Point& point,
114 ui::MenuSourceType source_type) OVERRIDE;
116 // views::CustomButton overrides:
117 virtual void StateChanged() OVERRIDE;
118 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE;
120 // views::View overrides:
121 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
122 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
123 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
124 virtual void OnMouseCaptureLost() OVERRIDE;
125 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
127 // ui::EventHandler overrides:
128 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
130 AppListItem* item_; // Owned by AppListModel.
132 AppsGridView* apps_grid_view_; // Owned by views hierarchy.
133 views::ImageView* icon_; // Owned by views hierarchy.
134 CachedLabel* title_; // Owned by views hierarchy.
135 ProgressBarView* progress_bar_; // Owned by views hierarchy.
137 scoped_ptr<views::MenuRunner> context_menu_runner_;
141 // True if scroll gestures should contribute to dragging.
142 bool touch_dragging_;
144 // A timer to defer showing drag UI when mouse is pressed.
145 base::OneShotTimer<AppListItemView> mouse_drag_timer_;
147 DISALLOW_COPY_AND_ASSIGN(AppListItemView);
150 } // namespace app_list
152 #endif // UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_