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.
5 #include "ui/views/controls/menu/menu.h"
7 #include "base/i18n/rtl.h"
8 #include "ui/gfx/image/image_skia.h"
12 bool Menu::Delegate::IsItemChecked(int id
) const {
16 bool Menu::Delegate::IsItemDefault(int id
) const {
20 base::string16
Menu::Delegate::GetLabel(int id
) const {
21 return base::string16();
24 bool Menu::Delegate::GetAcceleratorInfo(int id
, ui::Accelerator
* accel
) {
28 const gfx::ImageSkia
& Menu::Delegate::GetIcon(int id
) const {
29 return GetEmptyIcon();
32 int Menu::Delegate::GetItemCount() const {
36 bool Menu::Delegate::IsItemSeparator(int id
) const {
40 bool Menu::Delegate::HasIcon(int id
) const {
44 bool Menu::Delegate::SupportsCommand(int id
) const {
48 bool Menu::Delegate::IsCommandEnabled(int id
) const {
52 bool Menu::Delegate::GetContextualLabel(int id
, base::string16
* out
) const {
56 bool Menu::Delegate::IsRightToLeftUILayout() const {
57 return base::i18n::IsRTL();
60 const gfx::ImageSkia
& Menu::Delegate::GetEmptyIcon() const {
61 static const gfx::ImageSkia
* empty_icon
= new gfx::ImageSkia();
65 Menu::Menu(Delegate
* delegate
, AnchorPoint anchor
)
66 : delegate_(delegate
),
70 Menu::Menu(Menu
* parent
)
71 : delegate_(parent
->delegate_
),
72 anchor_(parent
->anchor_
) {
78 void Menu::AppendMenuItem(int item_id
,
79 const base::string16
& label
,
81 AddMenuItem(-1, item_id
, label
, type
);
84 void Menu::AddMenuItem(int index
,
86 const base::string16
& label
,
88 if (type
== SEPARATOR
)
91 AddMenuItemInternal(index
, item_id
, label
, gfx::ImageSkia(), type
);
94 Menu
* Menu::AppendSubMenu(int item_id
, const base::string16
& label
) {
95 return AddSubMenu(-1, item_id
, label
);
98 Menu
* Menu::AddSubMenu(int index
, int item_id
, const base::string16
& label
) {
99 return AddSubMenuWithIcon(index
, item_id
, label
, gfx::ImageSkia());
102 Menu
* Menu::AppendSubMenuWithIcon(int item_id
,
103 const base::string16
& label
,
104 const gfx::ImageSkia
& icon
) {
105 return AddSubMenuWithIcon(-1, item_id
, label
, icon
);
108 void Menu::AppendMenuItemWithLabel(int item_id
, const base::string16
& label
) {
109 AddMenuItemWithLabel(-1, item_id
, label
);
112 void Menu::AddMenuItemWithLabel(int index
,
114 const base::string16
& label
) {
115 AddMenuItem(index
, item_id
, label
, Menu::NORMAL
);
118 void Menu::AppendDelegateMenuItem(int item_id
) {
119 AddDelegateMenuItem(-1, item_id
);
122 void Menu::AddDelegateMenuItem(int index
, int item_id
) {
123 AddMenuItem(index
, item_id
, base::string16(), Menu::NORMAL
);
126 void Menu::AppendSeparator() {
130 void Menu::AppendMenuItemWithIcon(int item_id
,
131 const base::string16
& label
,
132 const gfx::ImageSkia
& icon
) {
133 AddMenuItemWithIcon(-1, item_id
, label
, icon
);
136 void Menu::AddMenuItemWithIcon(int index
,
138 const base::string16
& label
,
139 const gfx::ImageSkia
& icon
) {
140 AddMenuItemInternal(index
, item_id
, label
, icon
, Menu::NORMAL
);
143 Menu::Menu() : delegate_(NULL
), anchor_(TOPLEFT
) {