Upstream version 7.36.149.0
[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/gfx/shadow_value.h"
17 #include "ui/views/context_menu_controller.h"
18 #include "ui/views/controls/button/custom_button.h"
19
20 class SkBitmap;
21
22 namespace views {
23 class ImageView;
24 class Label;
25 class MenuRunner;
26 }
27
28 namespace app_list {
29
30 class AppListItem;
31 class AppsGridView;
32 class ProgressBarView;
33
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[];
40
41   AppListItemView(AppsGridView* apps_grid_view, AppListItem* item);
42   virtual ~AppListItemView();
43
44   void SetIconSize(const gfx::Size& size);
45
46   void Prerender();
47
48   void CancelContextMenu();
49
50   gfx::ImageSkia GetDragImage();
51   void OnDragEnded();
52   gfx::Point GetDragImageOffset();
53
54   void SetAsAttemptedFolderTarget(bool is_target_folder);
55
56   AppListItem* item() const { return item_; }
57
58   const views::Label* title() const { return title_; }
59
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.
62   void OnSyncDragEnd();
63
64   // Returns the icon bounds relative to AppListItemView.
65   const gfx::Rect& GetIconBounds() const;
66
67   // Sets UI state to dragging state.
68   void SetDragUIState();
69
70   // Returns the icon bounds for the given |target_bounds| as
71   // the assuming bounds of this view.
72   gfx::Rect GetIconBoundsForTargetViewBounds(const gfx::Rect& target_bounds);
73
74  private:
75   enum UIState {
76     UI_STATE_NORMAL,    // Normal UI (icon + label)
77     UI_STATE_DRAGGING,  // Dragging UI (scaled icon only)
78     UI_STATE_DROPPING_IN_FOLDER,  // Folder dropping preview UI
79   };
80
81   // Get icon from |item_| and schedule background processing.
82   void UpdateIcon();
83
84   // Update the tooltip text from |item_|.
85   void UpdateTooltip();
86
87   void SetUIState(UIState state);
88
89   // Sets |touch_dragging_| flag and updates UI.
90   void SetTouchDragging(bool touch_dragging);
91
92   // Invoked when |mouse_drag_timer_| fires to show dragging UI.
93   void OnMouseDragTimer();
94
95   // If the item is not in a folder, not highlighted, not being dragged, and not
96   // having something dropped onto it, enables subpixel AA for the title.
97   void SetTitleSubpixelAA();
98
99   // AppListItemObserver overrides:
100   virtual void ItemIconChanged() OVERRIDE;
101   virtual void ItemNameChanged() OVERRIDE;
102   virtual void ItemHighlightedChanged() OVERRIDE;
103   virtual void ItemIsInstallingChanged() OVERRIDE;
104   virtual void ItemPercentDownloadedChanged() OVERRIDE;
105
106   // views::View overrides:
107   virtual const char* GetClassName() const OVERRIDE;
108   virtual void Layout() OVERRIDE;
109   virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE;
110   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
111
112   // views::ContextMenuController overrides:
113   virtual void ShowContextMenuForView(views::View* source,
114                                       const gfx::Point& point,
115                                       ui::MenuSourceType source_type) OVERRIDE;
116
117   // views::CustomButton overrides:
118   virtual void StateChanged() OVERRIDE;
119   virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE;
120
121   // views::View overrides:
122   virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
123   virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
124   virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
125   virtual void OnMouseCaptureLost() OVERRIDE;
126   virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
127
128   // ui::EventHandler overrides:
129   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
130
131   AppListItem* item_;  // Owned by AppListModel.
132
133   AppsGridView* apps_grid_view_;  // Owned by views hierarchy.
134   views::ImageView* icon_;  // Owned by views hierarchy.
135   CachedLabel* title_;  // Owned by views hierarchy.
136   ProgressBarView* progress_bar_;  // Owned by views hierarchy.
137
138   scoped_ptr<views::MenuRunner> context_menu_runner_;
139
140   gfx::Size icon_size_;
141   gfx::ShadowValues icon_shadows_;
142
143   UIState ui_state_;
144
145   // True if scroll gestures should contribute to dragging.
146   bool touch_dragging_;
147
148   // A timer to defer showing drag UI when mouse is pressed.
149   base::OneShotTimer<AppListItemView> mouse_drag_timer_;
150
151   DISALLOW_COPY_AND_ASSIGN(AppListItemView);
152 };
153
154 }  // namespace app_list
155
156 #endif  // UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_