OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 5 #ifndef VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
6 #define VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 6 #define VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
10 | 11 |
11 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
12 #include <windows.h> | 13 #include <windows.h> |
13 #endif | 14 #endif |
14 | 15 |
15 // TODO(avi): remove when not needed | 16 // TODO(avi): remove when not needed |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "views/view.h" | 19 #include "views/view.h" |
19 | 20 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 const gfx::Rect& bounds, | 121 const gfx::Rect& bounds, |
121 AnchorPosition anchor, | 122 AnchorPosition anchor, |
122 bool has_mnemonics); | 123 bool has_mnemonics); |
123 void RunMenuForDropAt(gfx::NativeWindow parent, | 124 void RunMenuForDropAt(gfx::NativeWindow parent, |
124 const gfx::Rect& bounds, | 125 const gfx::Rect& bounds, |
125 AnchorPosition anchor); | 126 AnchorPosition anchor); |
126 | 127 |
127 // Hides and cancels the menu. This does nothing if the menu is not open. | 128 // Hides and cancels the menu. This does nothing if the menu is not open. |
128 void Cancel(); | 129 void Cancel(); |
129 | 130 |
130 // Adds an item to this menu. | 131 // Add an item to the menu at a specified index. ChildrenChanged() should |
| 132 // called after adding menu items if the menu may be active. |
| 133 MenuItemView* AddMenuItemAt(int index, |
| 134 int item_id, |
| 135 const std::wstring& label, |
| 136 const SkBitmap& icon, |
| 137 Type type); |
| 138 |
| 139 // Remove an item from the menu at a specified index. |
| 140 // ChildrenChanged() should be called after removing menu items (whether |
| 141 // the menu may be active or not). |
| 142 void RemoveMenuItemAt(int index); |
| 143 |
| 144 // Appends an item to this menu. |
131 // item_id The id of the item, used to identify it in delegate callbacks | 145 // item_id The id of the item, used to identify it in delegate callbacks |
132 // or (if delegate is NULL) to identify the command associated | 146 // or (if delegate is NULL) to identify the command associated |
133 // with this item with the controller specified in the ctor. Note | 147 // with this item with the controller specified in the ctor. Note |
134 // that this value should not be 0 as this has a special meaning | 148 // that this value should not be 0 as this has a special meaning |
135 // ("NULL command, no item selected") | 149 // ("NULL command, no item selected") |
136 // label The text label shown. | 150 // label The text label shown. |
137 // type The type of item. | 151 // type The type of item. |
138 void AppendMenuItem(int item_id, | 152 void AppendMenuItem(int item_id, |
139 const std::wstring& label, | 153 const std::wstring& label, |
140 Type type) { | 154 Type type) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 // Margins between the right of the item and the label. | 430 // Margins between the right of the item and the label. |
417 static int item_right_margin_; | 431 static int item_right_margin_; |
418 | 432 |
419 // Preferred height of menu items. Reset every time a menu is run. | 433 // Preferred height of menu items. Reset every time a menu is run. |
420 static int pref_menu_height_; | 434 static int pref_menu_height_; |
421 | 435 |
422 // Previously calculated preferred size to reduce GetStringWidth calls in | 436 // Previously calculated preferred size to reduce GetStringWidth calls in |
423 // GetPreferredSize. | 437 // GetPreferredSize. |
424 gfx::Size pref_size_; | 438 gfx::Size pref_size_; |
425 | 439 |
| 440 // Removed items to be deleted in ChildrenChanged(). |
| 441 std::vector<View*> removed_items_; |
| 442 |
426 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 443 DISALLOW_COPY_AND_ASSIGN(MenuItemView); |
427 }; | 444 }; |
428 | 445 |
429 } // namespace views | 446 } // namespace views |
430 | 447 |
431 #endif // VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 448 #endif // VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
OLD | NEW |