| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/app_list/app_list_folder_item.h" | 5 #include "ui/app_list/app_list_folder_item.h" |
| 6 #include "ui/gfx/canvas.h" | 6 #include "ui/gfx/canvas.h" |
| 7 #include "ui/gfx/image/canvas_image_source.h" | 7 #include "ui/gfx/image/canvas_image_source.h" |
| 8 #include "ui/gfx/image/image_skia_operations.h" | 8 #include "ui/gfx/image/image_skia_operations.h" |
| 9 | 9 |
| 10 namespace app_list { | 10 namespace app_list { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const int kIconDimension = 48; | 14 const int kIconDimension = 48; |
| 15 const size_t kNumTopApps = 4; | 15 const size_t kNumTopApps = 4; |
| 16 const int kItemIconDimension = 16; | 16 const int kItemIconDimension = 16; |
| 17 | 17 |
| 18 // Generates the folder icon with the top 4 child item icons laid in 2x2 tile. | 18 // Genearats the folder icon with the top 4 child item icons laid in 2x2 tile. |
| 19 class FolderImageSource : public gfx::CanvasImageSource { | 19 class FolderImageSource : public gfx::CanvasImageSource { |
| 20 public: | 20 public: |
| 21 typedef std::vector<gfx::ImageSkia> Icons; | 21 typedef std::vector<gfx::ImageSkia> Icons; |
| 22 | 22 |
| 23 FolderImageSource(const Icons& icons, const gfx::Size& size) | 23 FolderImageSource(const Icons& icons, const gfx::Size& size) |
| 24 : gfx::CanvasImageSource(size, false), | 24 : gfx::CanvasImageSource(size, false), |
| 25 icons_(icons), | 25 icons_(icons), |
| 26 size_(size) { | 26 size_(size) { |
| 27 DCHECK(icons.size() <= kNumTopApps); | 27 DCHECK(icons.size() <= kNumTopApps); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual ~FolderImageSource() {} | 30 virtual ~FolderImageSource() {} |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 void DrawIcon(gfx::Canvas* canvas, | 33 void DrawIcon(gfx::Canvas* canvas, |
| 34 const gfx::ImageSkia& icon, | 34 const gfx::ImageSkia& icon, |
| 35 const gfx::Size icon_size, | 35 const gfx::Size icon_size, |
| 36 int x, int y) { | 36 int x, int y) { |
| 37 gfx::ImageSkia resized( | 37 gfx::ImageSkia resized( |
| 38 gfx::ImageSkiaOperations::CreateResizedImage( | 38 gfx::ImageSkiaOperations::CreateResizedImage( |
| 39 icon, skia::ImageOperations::RESIZE_BEST, icon_size)); | 39 icon, skia::ImageOperations::RESIZE_BEST, icon_size)); |
| 40 canvas->DrawImageInt(resized, 0, 0, resized.width(), resized.height(), | 40 canvas->DrawImageInt(resized, 0, 0, resized.width(), resized.height(), |
| 41 x, y, resized.width(), resized.height(), true); | 41 x, y, resized.width(), resized.height(), true); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // gfx::CanvasImageSource overrides: | 44 // gfx::CanvasImageSource overrides: |
| 45 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { | 45 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { |
| 46 // Draw folder circle. | 46 // Draw folder circle. |
| 47 gfx::Point center = gfx::Point(size().width() / 2 , size().height() / 2); | 47 gfx::Point center = gfx::Point(size().width() / 2 , size().height() / 2); |
| 48 const SkColor kCircleColor = SkColorSetRGB(0xE1, 0xE1, 0xE1); | 48 const SkColor kCirclColor = SkColorSetRGB(0xE1, 0xE1, 0xE1); |
| 49 SkPaint paint; | 49 SkPaint paint; |
| 50 paint.setStyle(SkPaint::kFill_Style); | 50 paint.setStyle(SkPaint::kFill_Style); |
| 51 paint.setAntiAlias(true); | 51 paint.setAntiAlias(true); |
| 52 paint.setColor(kCircleColor); | 52 paint.setColor(kCirclColor); |
| 53 canvas->DrawCircle(center, size().width() / 2, paint); | 53 canvas->DrawCircle(center, size().width() / 2, paint); |
| 54 | 54 |
| 55 if (icons_.size() == 0) | 55 if (icons_.size() == 0) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 // Tiled icon coordinates. | 58 // Tiled icon coordinates. |
| 59 const int delta_to_center = 1; | 59 const int delta_to_center = 1; |
| 60 const gfx::Size item_icon_size = | 60 const gfx::Size item_icon_size = |
| 61 gfx::Size(kItemIconDimension, kItemIconDimension); | 61 gfx::Size(kItemIconDimension, kItemIconDimension); |
| 62 int left_x = center.x() - item_icon_size.width() - delta_to_center; | 62 int left_x = center.x() - item_icon_size.width() - delta_to_center; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 SetIcon(icon, false); | 137 SetIcon(icon, false); |
| 138 } | 138 } |
| 139 | 139 |
| 140 std::string AppListFolderItem::GetSortOrder() const { | 140 std::string AppListFolderItem::GetSortOrder() const { |
| 141 // For now, put folders at the end of the list. | 141 // For now, put folders at the end of the list. |
| 142 // TODO(stevenjb): Implement synced app list ordering. | 142 // TODO(stevenjb): Implement synced app list ordering. |
| 143 return "zzzzzzzz"; | 143 return "zzzzzzzz"; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void AppListFolderItem::Activate(int event_flags) { | 146 void AppListFolderItem::Activate(int event_flags) { |
| 147 // Folder handling is implemented by the View, so do nothing. | 147 // TODO(stevenjb/jennyz): Implement. |
| 148 VLOG(1) << "AppListFolderItem::Activate"; |
| 148 } | 149 } |
| 149 | 150 |
| 150 // static | 151 // static |
| 151 const char AppListFolderItem::kAppType[] = "FolderItem"; | 152 const char AppListFolderItem::kAppType[] = "FolderItem"; |
| 152 | 153 |
| 153 const char* AppListFolderItem::GetAppType() const { | 154 const char* AppListFolderItem::GetAppType() const { |
| 154 return AppListFolderItem::kAppType; | 155 return AppListFolderItem::kAppType; |
| 155 } | 156 } |
| 156 | 157 |
| 157 ui::MenuModel* AppListFolderItem::GetContextMenuModel() { | 158 ui::MenuModel* AppListFolderItem::GetContextMenuModel() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 182 | 183 |
| 183 for (size_t i = 0; i < kNumTopApps && i < apps_->item_count(); ++i) { | 184 for (size_t i = 0; i < kNumTopApps && i < apps_->item_count(); ++i) { |
| 184 AppListItemModel* item = apps_->GetItemAt(i); | 185 AppListItemModel* item = apps_->GetItemAt(i); |
| 185 item->AddObserver(this); | 186 item->AddObserver(this); |
| 186 top_items_.push_back(item); | 187 top_items_.push_back(item); |
| 187 } | 188 } |
| 188 UpdateIcon(); | 189 UpdateIcon(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 } // namespace app_list | 192 } // namespace app_list |
| OLD | NEW |