Paint state transition for overlay 9 patch scrollbars
[chromium-blink-merge.git] / ui / app_list / views / app_list_item_view.h
bloba55102bc1bc444506a4bb1de34a0107ed8b5c06c
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/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"
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 virtual ~AppListItemView();
44 void SetIconSize(const gfx::Size& size);
46 void Prerender();
48 void CancelContextMenu();
50 gfx::ImageSkia GetDragImage();
51 void OnDragEnded();
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.
62 void OnSyncDragEnd();
64 // Returns the icon bounds relative to AppListItemView.
65 const gfx::Rect& GetIconBounds() const;
67 // Sets UI state to dragging state.
68 void SetDragUIState();
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);
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
81 // Get icon from |item_| and schedule background processing.
82 void UpdateIcon();
84 // Update the tooltip text from |item_|.
85 void UpdateTooltip();
87 void SetUIState(UIState state);
89 // Sets |touch_dragging_| flag and updates UI.
90 void SetTouchDragging(bool touch_dragging);
92 // Invoked when |mouse_drag_timer_| fires to show dragging UI.
93 void OnMouseDragTimer();
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();
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;
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;
112 // views::ContextMenuController overrides:
113 virtual void ShowContextMenuForView(views::View* source,
114 const gfx::Point& point,
115 ui::MenuSourceType source_type) OVERRIDE;
117 // views::CustomButton overrides:
118 virtual void StateChanged() OVERRIDE;
119 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE;
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;
128 // ui::EventHandler overrides:
129 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
131 AppListItem* item_; // Owned by AppListModel.
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.
138 scoped_ptr<views::MenuRunner> context_menu_runner_;
140 gfx::Size icon_size_;
141 gfx::ShadowValues icon_shadows_;
143 UIState ui_state_;
145 // True if scroll gestures should contribute to dragging.
146 bool touch_dragging_;
148 // A timer to defer showing drag UI when mouse is pressed.
149 base::OneShotTimer<AppListItemView> mouse_drag_timer_;
151 DISALLOW_COPY_AND_ASSIGN(AppListItemView);
154 } // namespace app_list
156 #endif // UI_APP_LIST_VIEWS_APP_LIST_ITEM_VIEW_H_