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 ASH_APP_LIST_APP_LIST_ITEM_VIEW_H_ | |
6 #define ASH_APP_LIST_APP_LIST_ITEM_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include "ash/app_list/app_list_item_model_observer.h" | |
10 #include "ash/ash_export.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "ui/views/context_menu_controller.h" | |
15 #include "ui/views/controls/button/custom_button.h" | |
16 | |
17 class SkBitmap; | |
18 | |
19 namespace views { | |
20 class ImageView; | |
21 class MenuRunner; | |
22 } | |
23 | |
24 namespace ash { | |
25 | |
26 class AppListItemModel; | |
27 class AppListModelView; | |
28 class DropShadowLabel; | |
29 | |
30 class ASH_EXPORT AppListItemView : public views::CustomButton, | |
31 public views::ContextMenuController, | |
32 public AppListItemModelObserver { | |
33 public: | |
34 AppListItemView(AppListModelView* list_model_view, | |
35 AppListItemModel* model, | |
36 views::ButtonListener* listener); | |
37 virtual ~AppListItemView(); | |
38 | |
39 static gfx::Size GetPreferredSizeForIconSize(const gfx::Size& icon_size); | |
40 | |
41 // For testing. Testing calls this function to set minimum title width in | |
42 // pixels to get rid dependency on default font width. | |
43 static void SetMinTitleWidth(int width); | |
44 | |
45 void SetSelected(bool selected); | |
46 bool selected() const { | |
47 return selected_; | |
48 } | |
49 | |
50 void SetIconSize(const gfx::Size& size); | |
51 | |
52 AppListItemModel* model() const { | |
53 return model_; | |
54 } | |
55 | |
56 // Internal class name. | |
57 static const char kViewClassName[]; | |
58 | |
59 private: | |
60 class IconOperation; | |
61 | |
62 // Get icon from model and schedule background processing. | |
63 void UpdateIcon(); | |
64 | |
65 // Cancel pending icon operation and reply callback. | |
66 void CancelPendingIconOperation(); | |
67 | |
68 // Reply callback from background shadow generation. |op| is the finished | |
69 // operation and holds the result image. | |
70 void ApplyShadow(scoped_refptr<IconOperation> op); | |
71 | |
72 // AppListItemModelObserver overrides: | |
73 virtual void ItemIconChanged() OVERRIDE; | |
74 virtual void ItemTitleChanged() OVERRIDE; | |
75 virtual void ItemHighlightedChanged() OVERRIDE; | |
76 | |
77 // views::View overrides: | |
78 virtual std::string GetClassName() const OVERRIDE; | |
79 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
80 virtual void Layout() OVERRIDE; | |
81 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
82 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
83 | |
84 // views::ContextMenuController overrides: | |
85 virtual void ShowContextMenuForView(views::View* source, | |
86 const gfx::Point& point) OVERRIDE; | |
87 | |
88 // views::CustomButton overrides: | |
89 virtual void StateChanged() OVERRIDE; | |
90 | |
91 AppListItemModel* model_; | |
92 | |
93 AppListModelView* list_model_view_; | |
94 views::ImageView* icon_; | |
95 DropShadowLabel* title_; | |
96 | |
97 scoped_ptr<views::MenuRunner> context_menu_runner_; | |
98 | |
99 gfx::Size icon_size_; | |
100 bool selected_; | |
101 | |
102 scoped_refptr<IconOperation> icon_op_; | |
103 base::WeakPtrFactory<AppListItemView> apply_shadow_factory_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(AppListItemView); | |
106 }; | |
107 | |
108 } // namespace ash | |
109 | |
110 #endif // ASH_APP_LIST_APP_LIST_ITEM_VIEW_H_ | |
OLD | NEW |