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/gfx/shadow_value.h"
17 #include "ui/views/context_menu_controller.h"
18 #include "ui/views/controls/button/custom_button.h"
32 class ProgressBarView
;
34 class APP_LIST_EXPORT AppListItemView
: public views::CustomButton
,
35 public views::ContextMenuController
,
36 public AppListItemObserver
{
38 // Internal class name.
39 static const char kViewClassName
[];
41 AppListItemView(AppsGridView
* apps_grid_view
, AppListItem
* item
);
42 virtual ~AppListItemView();
44 void SetIconSize(const gfx::Size
& size
);
48 void CancelContextMenu();
50 gfx::ImageSkia
GetDragImage();
52 gfx::Point
GetDragImageOffset();
54 void SetAsAttemptedFolderTarget(bool is_target_folder
);
56 AppListItem
* item() const { return item_
; }
58 const views::Label
* title() const { return title_
; }
60 // In a synchronous drag the item view isn't informed directly of the drag
61 // ending, so the runner of the drag should call this.
64 // Returns the icon bounds relative to AppListItemView.
65 const gfx::Rect
& GetIconBounds() const;
69 UI_STATE_NORMAL
, // Normal UI (icon + label)
70 UI_STATE_DRAGGING
, // Dragging UI (scaled icon only)
71 UI_STATE_DROPPING_IN_FOLDER
, // Folder dropping preview UI
74 // Get icon from |item_| and schedule background processing.
77 // Update the tooltip text from |item_|.
80 void SetUIState(UIState state
);
82 // Sets |touch_dragging_| flag and updates UI.
83 void SetTouchDragging(bool touch_dragging
);
85 // Invoked when |mouse_drag_timer_| fires to show dragging UI.
86 void OnMouseDragTimer();
88 // AppListItemObserver overrides:
89 virtual void ItemIconChanged() OVERRIDE
;
90 virtual void ItemTitleChanged() OVERRIDE
;
91 virtual void ItemHighlightedChanged() OVERRIDE
;
92 virtual void ItemIsInstallingChanged() OVERRIDE
;
93 virtual void ItemPercentDownloadedChanged() OVERRIDE
;
95 // views::View overrides:
96 virtual const char* GetClassName() const OVERRIDE
;
97 virtual void Layout() OVERRIDE
;
98 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
99 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
101 // views::ContextMenuController overrides:
102 virtual void ShowContextMenuForView(views::View
* source
,
103 const gfx::Point
& point
,
104 ui::MenuSourceType source_type
) OVERRIDE
;
106 // views::CustomButton overrides:
107 virtual void StateChanged() OVERRIDE
;
108 virtual bool ShouldEnterPushedState(const ui::Event
& event
) OVERRIDE
;
110 // views::View overrides:
111 virtual bool OnKeyPressed(const ui::KeyEvent
& event
) OVERRIDE
;
112 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
;
113 virtual void OnMouseReleased(const ui::MouseEvent
& event
) OVERRIDE
;
114 virtual void OnMouseCaptureLost() OVERRIDE
;
115 virtual bool OnMouseDragged(const ui::MouseEvent
& event
) OVERRIDE
;
117 // ui::EventHandler overrides:
118 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
120 AppListItem
* item_
; // Owned by AppListModel.
122 AppsGridView
* apps_grid_view_
; // Owned by views hierarchy.
123 views::ImageView
* icon_
; // Owned by views hierarchy.
124 CachedLabel
* title_
; // Owned by views hierarchy.
125 ProgressBarView
* progress_bar_
; // Owned by views hierarchy.
127 scoped_ptr
<views::MenuRunner
> context_menu_runner_
;
129 gfx::Size icon_size_
;
130 gfx::ShadowValues icon_shadows_
;
134 // True if scroll gestures should contribute to dragging.
135 bool touch_dragging_
;
137 // A timer to defer showing drag UI when mouse is pressed.
138 base::OneShotTimer
<AppListItemView
> mouse_drag_timer_
;
140 DISALLOW_COPY_AND_ASSIGN(AppListItemView
);
143 } // namespace app_list
145 #endif // UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_