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#include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" 6 7#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 8 9LauncherApplicationMenuItemModel::LauncherApplicationMenuItemModel( 10 ChromeLauncherAppMenuItems item_list) 11 : ash::ShelfMenuModel(this), 12 launcher_items_(item_list.Pass()) { 13 Build(); 14} 15 16LauncherApplicationMenuItemModel::~LauncherApplicationMenuItemModel() { 17} 18 19bool LauncherApplicationMenuItemModel::IsCommandActive(int command_id) const { 20 DCHECK(command_id >= 0); 21 DCHECK(static_cast<size_t>(command_id) < launcher_items_.size()); 22 return launcher_items_[command_id]->IsActive(); 23} 24 25bool LauncherApplicationMenuItemModel::IsCommandIdChecked( 26 int command_id) const { 27 return false; 28} 29 30bool LauncherApplicationMenuItemModel::IsCommandIdEnabled( 31 int command_id) const { 32 DCHECK(command_id < static_cast<int>(launcher_items_.size())); 33 return launcher_items_[command_id]->IsEnabled(); 34} 35 36bool LauncherApplicationMenuItemModel::GetAcceleratorForCommandId( 37 int command_id, 38 ui::Accelerator* accelerator) { 39 return false; 40} 41 42void LauncherApplicationMenuItemModel::ExecuteCommand(int command_id, 43 int event_flags) { 44 DCHECK(command_id < static_cast<int>(launcher_items_.size())); 45 launcher_items_[command_id]->Execute(event_flags); 46} 47 48void LauncherApplicationMenuItemModel::Build() { 49 AddSeparator(ui::SPACING_SEPARATOR); 50 for (size_t i = 0; i < launcher_items_.size(); i++) { 51 ChromeLauncherAppMenuItem* item = launcher_items_[i]; 52 53 // Check for a separator requirement in front of this item. 54 if (item->HasLeadingSeparator()) 55 AddSeparator(ui::SPACING_SEPARATOR); 56 57 // The first item is the context menu, the others are the running apps. 58 AddItem(i, item->title()); 59 60 if (!item->icon().IsEmpty()) 61 SetIcon(GetIndexOfCommandId(i), item->icon()); 62 } 63 RemoveTrailingSeparators(); 64 65 // Adding final spacing (if the menu is not empty) to conform the menu to our 66 // style. 67 if (launcher_items_.size()) 68 AddSeparator(ui::SPACING_SEPARATOR); 69} 70 71