summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 03:55:45 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 03:55:45 +0000
commit52aac9e4ff1d4181f1b980a29446fdf5036a185a (patch)
tree8d970acf8b45bf33f10d40e5298c33c313dcfa70 /app
parent4ce7e15da651c6221720e33dc8c500830d4b6b8a (diff)
downloadchromium_src-52aac9e4ff1d4181f1b980a29446fdf5036a185a.zip
chromium_src-52aac9e4ff1d4181f1b980a29446fdf5036a185a.tar.gz
chromium_src-52aac9e4ff1d4181f1b980a29446fdf5036a185a.tar.bz2
Add icons to SimpleMenuModel.
Also get rid of one of the MenuGtk constructors (now down to 2). Also, stamp out one more use of MenuGtk::Delegate as a controller class. BUG=31365 TEST=manual (in debug mode) + trybots Review URL: http://codereview.chromium.org/1915004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46434 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/menus/simple_menu_model.cc42
-rw-r--r--app/menus/simple_menu_model.h5
2 files changed, 33 insertions, 14 deletions
diff --git a/app/menus/simple_menu_model.cc b/app/menus/simple_menu_model.cc
index 7f01b97..f6de9ad 100644
--- a/app/menus/simple_menu_model.cc
+++ b/app/menus/simple_menu_model.cc
@@ -1,6 +1,6 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "app/menus/simple_menu_model.h"
@@ -18,7 +18,7 @@ SimpleMenuModel::~SimpleMenuModel() {
}
void SimpleMenuModel::AddItem(int command_id, const string16& label) {
- Item item = { command_id, label, TYPE_COMMAND, -1, NULL };
+ Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL };
items_.push_back(item);
}
@@ -27,12 +27,12 @@ void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) {
}
void SimpleMenuModel::AddSeparator() {
- Item item = { -1, string16(), TYPE_SEPARATOR, -1, NULL };
+ Item item = { -1, string16(), SkBitmap(), TYPE_SEPARATOR, -1, NULL };
items_.push_back(item);
}
void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) {
- Item item = { command_id, label, TYPE_CHECK, -1, NULL };
+ Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL };
items_.push_back(item);
}
@@ -42,7 +42,7 @@ void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) {
void SimpleMenuModel::AddRadioItem(int command_id, const string16& label,
int group_id) {
- Item item = { command_id, label, TYPE_RADIO, group_id, NULL };
+ Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL };
items_.push_back(item);
}
@@ -52,7 +52,7 @@ void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id,
}
void SimpleMenuModel::AddSubMenu(const string16& label, MenuModel* model) {
- Item item = { -1, label, TYPE_SUBMENU, -1, model };
+ Item item = { -1, label, SkBitmap(), TYPE_SUBMENU, -1, model };
items_.push_back(item);
}
@@ -62,7 +62,7 @@ void SimpleMenuModel::AddSubMenuWithStringId(int string_id, MenuModel* model) {
void SimpleMenuModel::InsertItemAt(
int index, int command_id, const string16& label) {
- Item item = { command_id, label, TYPE_COMMAND, -1, NULL };
+ Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL };
items_.insert(items_.begin() + FlipIndex(index), item);
}
@@ -72,13 +72,13 @@ void SimpleMenuModel::InsertItemWithStringIdAt(
}
void SimpleMenuModel::InsertSeparatorAt(int index) {
- Item item = { -1, string16(), TYPE_SEPARATOR, -1, NULL };
+ Item item = { -1, string16(), SkBitmap(), TYPE_SEPARATOR, -1, NULL };
items_.insert(items_.begin() + FlipIndex(index), item);
}
void SimpleMenuModel::InsertCheckItemAt(
int index, int command_id, const string16& label) {
- Item item = { command_id, label, TYPE_CHECK, -1, NULL };
+ Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL };
items_.insert(items_.begin() + FlipIndex(index), item);
}
@@ -90,7 +90,7 @@ void SimpleMenuModel::InsertCheckItemWithStringIdAt(
void SimpleMenuModel::InsertRadioItemAt(
int index, int command_id, const string16& label, int group_id) {
- Item item = { command_id, label, TYPE_RADIO, group_id, NULL };
+ Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL };
items_.insert(items_.begin() + FlipIndex(index), item);
}
@@ -102,7 +102,7 @@ void SimpleMenuModel::InsertRadioItemWithStringIdAt(
void SimpleMenuModel::InsertSubMenuAt(
int index, const string16& label, MenuModel* model) {
- Item item = { -1, label, TYPE_SUBMENU, -1, model };
+ Item item = { -1, label, SkBitmap(), TYPE_SUBMENU, -1, model };
items_.insert(items_.begin() + FlipIndex(index), item);
}
@@ -111,6 +111,10 @@ void SimpleMenuModel::InsertSubMenuWithStringIdAt(
InsertSubMenuAt(index, l10n_util::GetStringUTF16(string_id), model);
}
+void SimpleMenuModel::SetIcon(int index, const SkBitmap& icon) {
+ items_[index].icon = icon;
+}
+
int SimpleMenuModel::GetIndexOfCommandId(int command_id) {
std::vector<Item>::iterator itr;
for (itr = items_.begin(); itr != items_.end(); itr++) {
@@ -125,6 +129,12 @@ int SimpleMenuModel::GetIndexOfCommandId(int command_id) {
// SimpleMenuModel, MenuModel implementation:
bool SimpleMenuModel::HasIcons() const {
+ for (std::vector<Item>::const_iterator iter = items_.begin();
+ iter != items_.end(); ++iter) {
+ if (!iter->icon.isNull())
+ return true;
+ }
+
return false;
}
@@ -175,7 +185,11 @@ int SimpleMenuModel::GetGroupIdAt(int index) const {
}
bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const {
- return false;
+ if (items_[index].icon.isNull())
+ return false;
+
+ *icon = items_[index].icon;
+ return true;
}
bool SimpleMenuModel::IsEnabledAt(int index) const {
diff --git a/app/menus/simple_menu_model.h b/app/menus/simple_menu_model.h
index 59e741e..5307f12 100644
--- a/app/menus/simple_menu_model.h
+++ b/app/menus/simple_menu_model.h
@@ -9,6 +9,7 @@
#include "base/string16.h"
#include "app/menus/menu_model.h"
+#include "third_party/skia/include/core/SkBitmap.h"
namespace menus {
@@ -75,6 +76,9 @@ class SimpleMenuModel : public MenuModel {
void InsertSubMenuAt(int index, const string16& label, MenuModel* model);
void InsertSubMenuWithStringIdAt(int index, int string_id, MenuModel* model);
+ // Sets the icon for the item at |index|.
+ void SetIcon(int index, const SkBitmap& icon);
+
// Clears all items. Note that it does not free MenuModel of submenu.
void Clear() {
items_.clear();
@@ -115,6 +119,7 @@ class SimpleMenuModel : public MenuModel {
struct Item {
int command_id;
string16 label;
+ SkBitmap icon;
ItemType type;
int group_id;
MenuModel* submenu;