65467b5c88ae41a8302cd07327941e08c507d5ac
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / app_list_item_view.h
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.
4
5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_
6 #define UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_
7
8 #include <string>
9
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"
18
19 class SkBitmap;
20
21 namespace views {
22 class ImageView;
23 class Label;
24 class MenuRunner;
25 }
26
27 namespace app_list {
28
29 class AppListItem;
30 class AppsGridView;
31 class ProgressBarView;
32
33 class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
34                                         public views::ContextMenuController,
35                                         public AppListItemObserver {
36  public:
37   // Internal class name.
38   static const char kViewClassName[];
39
40   AppListItemView(AppsGridView* apps_grid_view, AppListItem* item);
41   virtual ~AppListItemView();
42
43   void Prerender();
44
45   void CancelContextMenu();
46
47   gfx::ImageSkia GetDragImage();
48   void OnDragEnded();
49   gfx::Point GetDragImageOffset();
50
51   void SetAsAttemptedFolderTarget(bool is_target_folder);
52
53   AppListItem* item() const { return item_; }
54
55   views::ImageView* icon() const { return icon_; }
56
57   const views::Label* title() const { return title_; }
58
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.
61   void OnSyncDragEnd();
62
63   // Returns the icon bounds relative to AppListItemView.
64   const gfx::Rect& GetIconBounds() const;
65
66   // Sets UI state to dragging state.
67   void SetDragUIState();
68
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);
72
73  private:
74   enum UIState {
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
78   };
79
80   // Get icon from |item_| and schedule background processing.
81   void UpdateIcon();
82
83   // Update the tooltip text from |item_|.
84   void UpdateTooltip();
85
86   void SetUIState(UIState state);
87
88   // Sets |touch_dragging_| flag and updates UI.
89   void SetTouchDragging(bool touch_dragging);
90
91   // Invoked when |mouse_drag_timer_| fires to show dragging UI.
92   void OnMouseDragTimer();
93
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();
97
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;
104
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;
110
111   // views::ContextMenuController overrides:
112   virtual void ShowContextMenuForView(views::View* source,
113                                       const gfx::Point& point,
114                                       ui::MenuSourceType source_type) OVERRIDE;
115
116   // views::CustomButton overrides:
117   virtual void StateChanged() OVERRIDE;
118   virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE;
119
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;
126
127   // ui::EventHandler overrides:
128   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
129
130   AppListItem* item_;  // Owned by AppListModel.
131
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.
136
137   scoped_ptr<views::MenuRunner> context_menu_runner_;
138
139   UIState ui_state_;
140
141   // True if scroll gestures should contribute to dragging.
142   bool touch_dragging_;
143
144   // A timer to defer showing drag UI when mouse is pressed.
145   base::OneShotTimer<AppListItemView> mouse_drag_timer_;
146
147   DISALLOW_COPY_AND_ASSIGN(AppListItemView);
148 };
149
150 }  // namespace app_list
151
152 #endif  // UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_