Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: views/controls/menu/menu_item_view.h

Issue 6931039: Add MenuItemView API to add and remove items at a particular index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed another spurious OVERRIDE. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.
132 MenuItemView* AddMenuItemAt(int index,
133 int item_id,
134 const std::wstring& label,
135 const SkBitmap& icon,
136 Type type);
137
138 // Remove an item from the menu at a specified index. Either
139 // ChildrenChanged() or DeleteRemovedItems() should be called after
sky 2011/05/06 16:17:00 DeleteRemovedItems isn't public, so folks have to
140 // removing menu items.
141 void RemoveMenuItemAt(int index);
142
143 // Appends an item to this menu.
131 // item_id The id of the item, used to identify it in delegate callbacks 144 // 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 145 // or (if delegate is NULL) to identify the command associated
133 // with this item with the controller specified in the ctor. Note 146 // 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 147 // that this value should not be 0 as this has a special meaning
135 // ("NULL command, no item selected") 148 // ("NULL command, no item selected")
136 // label The text label shown. 149 // label The text label shown.
137 // type The type of item. 150 // type The type of item.
138 void AppendMenuItem(int item_id, 151 void AppendMenuItem(int item_id,
139 const std::wstring& label, 152 const std::wstring& label,
140 Type type) { 153 Type type) {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // Returns the various margins. 367 // Returns the various margins.
355 int GetTopMargin(); 368 int GetTopMargin();
356 int GetBottomMargin(); 369 int GetBottomMargin();
357 370
358 // Returns the preferred width (and padding) of any children. 371 // Returns the preferred width (and padding) of any children.
359 int GetChildPreferredWidth(); 372 int GetChildPreferredWidth();
360 373
361 // Calculates the preferred size. 374 // Calculates the preferred size.
362 gfx::Size CalculatePreferredSize(); 375 gfx::Size CalculatePreferredSize();
363 376
377 // Delete orphaned items removed from the menu.
378 void DeleteRemovedItems();
379
364 // The delegate. This is only valid for the root menu item. You shouldn't 380 // The delegate. This is only valid for the root menu item. You shouldn't
365 // use this directly, instead use GetDelegate() which walks the tree as 381 // use this directly, instead use GetDelegate() which walks the tree as
366 // as necessary. 382 // as necessary.
367 MenuDelegate* delegate_; 383 MenuDelegate* delegate_;
368 384
369 // Returns the controller for the run operation, or NULL if the menu isn't 385 // Returns the controller for the run operation, or NULL if the menu isn't
370 // showing. 386 // showing.
371 MenuController* controller_; 387 MenuController* controller_;
372 388
373 // Used to detect when Cancel was invoked. 389 // Used to detect when Cancel was invoked.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // Margins between the right of the item and the label. 432 // Margins between the right of the item and the label.
417 static int item_right_margin_; 433 static int item_right_margin_;
418 434
419 // Preferred height of menu items. Reset every time a menu is run. 435 // Preferred height of menu items. Reset every time a menu is run.
420 static int pref_menu_height_; 436 static int pref_menu_height_;
421 437
422 // Previously calculated preferred size to reduce GetStringWidth calls in 438 // Previously calculated preferred size to reduce GetStringWidth calls in
423 // GetPreferredSize. 439 // GetPreferredSize.
424 gfx::Size pref_size_; 440 gfx::Size pref_size_;
425 441
442 // Removed items to be deleted in ChildrenChanged().
443 std::vector<View*> removed_items_;
444
426 DISALLOW_COPY_AND_ASSIGN(MenuItemView); 445 DISALLOW_COPY_AND_ASSIGN(MenuItemView);
427 }; 446 };
428 447
429 } // namespace views 448 } // namespace views
430 449
431 #endif // VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ 450 #endif // VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698