OLD | NEW |
| (Empty) |
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_APP_LIST_ITEM_VIEW_H_ | |
6 #define UI_APP_LIST_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.h" | |
13 #include "ui/app_list/app_list_export.h" | |
14 #include "ui/app_list/app_list_item_model_observer.h" | |
15 #include "ui/gfx/shadow_value.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 AppListItemModel; | |
30 class AppsGridView; | |
31 | |
32 class APP_LIST_EXPORT AppListItemView : public views::CustomButton, | |
33 public views::ContextMenuController, | |
34 public AppListItemModelObserver { | |
35 public: | |
36 // Internal class name. | |
37 static const char kViewClassName[]; | |
38 | |
39 AppListItemView(AppsGridView* apps_grid_view, AppListItemModel* model); | |
40 virtual ~AppListItemView(); | |
41 | |
42 void SetIconSize(const gfx::Size& size); | |
43 | |
44 AppListItemModel* model() const { return model_; } | |
45 | |
46 private: | |
47 enum UIState { | |
48 UI_STATE_NORMAL, // Normal UI (icon + label) | |
49 UI_STATE_DRAGGING, // Dragging UI (scaled icon only) | |
50 }; | |
51 | |
52 // Get icon from model and schedule background processing. | |
53 void UpdateIcon(); | |
54 | |
55 void SetUIState(UIState state); | |
56 | |
57 // Sets |touch_dragging_| flag and updates UI. | |
58 void SetTouchDragging(bool touch_dragging); | |
59 | |
60 // Invoked when |mouse_drag_timer_| fires to show dragging UI. | |
61 void OnMouseDragTimer(); | |
62 | |
63 // AppListItemModelObserver overrides: | |
64 virtual void ItemIconChanged() OVERRIDE; | |
65 virtual void ItemTitleChanged() OVERRIDE; | |
66 virtual void ItemHighlightedChanged() OVERRIDE; | |
67 | |
68 // views::View overrides: | |
69 virtual std::string GetClassName() const OVERRIDE; | |
70 virtual void Layout() OVERRIDE; | |
71 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
72 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
73 | |
74 // views::ContextMenuController overrides: | |
75 virtual void ShowContextMenuForView(views::View* source, | |
76 const gfx::Point& point) OVERRIDE; | |
77 | |
78 // views::CustomButton overrides: | |
79 virtual void StateChanged() OVERRIDE; | |
80 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE; | |
81 | |
82 // views::View overrides: | |
83 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | |
84 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | |
85 virtual void OnMouseCaptureLost() OVERRIDE; | |
86 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; | |
87 | |
88 // ui::EventHandler overrides: | |
89 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | |
90 | |
91 AppListItemModel* model_; // Owned by AppListModel::Apps. | |
92 | |
93 AppsGridView* apps_grid_view_; // Owned by views hierarchy. | |
94 views::ImageView* icon_; // Owned by views hierarchy. | |
95 views::Label* title_; // Owned by views hierarchy. | |
96 | |
97 scoped_ptr<views::MenuRunner> context_menu_runner_; | |
98 | |
99 gfx::Size icon_size_; | |
100 gfx::ShadowValues icon_shadows_; | |
101 | |
102 UIState ui_state_; | |
103 | |
104 // True if scroll gestures should contribute to dragging. | |
105 bool touch_dragging_; | |
106 | |
107 // A timer to defer showing drag UI when mouse is pressed. | |
108 base::OneShotTimer<AppListItemView> mouse_drag_timer_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(AppListItemView); | |
111 }; | |
112 | |
113 } // namespace app_list | |
114 | |
115 #endif // UI_APP_LIST_APP_LIST_ITEM_VIEW_H_ | |
OLD | NEW |