Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / app_list_menu.cc
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
3 // found in the LICENSE file.
4
5 #include "ui/app_list/app_list_menu.h"
6
7 #include "grit/ui_resources.h"
8 #include "grit/ui_strings.h"
9 #include "ui/app_list/app_list_view_delegate.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/models/menu_separator_types.h"
12 #include "ui/base/resource/resource_bundle.h"
13
14 namespace app_list {
15
16 AppListMenu::AppListMenu(AppListViewDelegate* delegate)
17     : menu_model_(this),
18       delegate_(delegate),
19       users_(delegate->GetUsers()) {
20   InitMenu();
21 }
22
23 AppListMenu::~AppListMenu() {}
24
25 void AppListMenu::InitMenu() {
26   // User selector menu section. We don't show the user selector if there is
27   // only 1 user.
28   if (users_.size() > 1) {
29     for (size_t i = 0; i < users_.size(); ++i) {
30 #if defined(OS_MACOSX)
31       menu_model_.AddRadioItem(SELECT_PROFILE + i,
32                                users_[i].email.empty() ? users_[i].name
33                                                        : users_[i].email,
34                                0 /* group_id */);
35 #elif defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
36       menu_model_.AddItem(SELECT_PROFILE + i, users_[i].name);
37       int menu_index = menu_model_.GetIndexOfCommandId(SELECT_PROFILE + i);
38       menu_model_.SetSublabel(menu_index, users_[i].email);
39       // Use custom check mark.
40       if (users_[i].active) {
41         ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
42         menu_model_.SetIcon(menu_index, gfx::Image(*rb.GetImageSkiaNamed(
43             IDR_APP_LIST_USER_INDICATOR)));
44       }
45 #endif
46     }
47     menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
48   }
49
50   menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16(
51       IDS_APP_LIST_OPEN_SETTINGS));
52
53   menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16(
54       IDS_APP_LIST_HELP));
55
56   menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16(
57       IDS_APP_LIST_OPEN_FEEDBACK));
58 }
59
60 bool AppListMenu::IsCommandIdChecked(int command_id) const {
61 #if defined(OS_MACOSX)
62   DCHECK_LT(static_cast<unsigned>(command_id) - SELECT_PROFILE, users_.size());
63   return users_[command_id - SELECT_PROFILE].active;
64 #else
65   return false;
66 #endif
67 }
68
69 bool AppListMenu::IsCommandIdEnabled(int command_id) const {
70   if (command_id >= SELECT_PROFILE &&
71       command_id < SELECT_PROFILE + static_cast<int>(users_.size())) {
72     return !users_[command_id - SELECT_PROFILE].signin_required;
73   }
74   return true;
75 }
76
77 bool AppListMenu::GetAcceleratorForCommandId(int command_id,
78                                              ui::Accelerator* accelerator) {
79   return false;
80 }
81
82 void AppListMenu::ExecuteCommand(int command_id, int event_flags) {
83   if (command_id >= SELECT_PROFILE) {
84     delegate_->ShowForProfileByPath(
85         users_[command_id - SELECT_PROFILE].profile_path);
86     return;
87   }
88   switch (command_id) {
89     case SHOW_SETTINGS:
90       delegate_->OpenSettings();
91       break;
92     case SHOW_HELP:
93       delegate_->OpenHelp();
94       break;
95     case SHOW_FEEDBACK:
96       delegate_->OpenFeedback();
97       break;
98     default:
99       NOTREACHED();
100   }
101 }
102
103 }  // namespace app_list