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

Side by Side Diff: ui/views/controls/menu/menu_model_adapter.cc

Issue 423833002: Check if the delegate changed the visibility of child MenuItemViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added MenuModelAdapter::IsCommandVisible Created 6 years, 4 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
« no previous file with comments | « ui/views/controls/menu/menu_model_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "ui/views/controls/menu/menu_model_adapter.h" 5 #include "ui/views/controls/menu/menu_model_adapter.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/base/l10n/l10n_util.h" 8 #include "ui/base/l10n/l10n_util.h"
9 #include "ui/base/models/menu_model.h" 9 #include "ui/base/models/menu_model.h"
10 #include "ui/gfx/image/image.h" 10 #include "ui/gfx/image/image.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 bool MenuModelAdapter::IsCommandEnabled(int id) const { 198 bool MenuModelAdapter::IsCommandEnabled(int id) const {
199 ui::MenuModel* model = menu_model_; 199 ui::MenuModel* model = menu_model_;
200 int index = 0; 200 int index = 0;
201 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) 201 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index))
202 return model->IsEnabledAt(index); 202 return model->IsEnabledAt(index);
203 203
204 NOTREACHED(); 204 NOTREACHED();
205 return false; 205 return false;
206 } 206 }
207 207
208 bool MenuModelAdapter::IsCommandVisible(int id) const {
209 ui::MenuModel* model = menu_model_;
210 int index = 0;
211 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index))
212 return model->IsVisibleAt(index);
213
214 NOTREACHED();
215 return false;
216 }
217
208 bool MenuModelAdapter::IsItemChecked(int id) const { 218 bool MenuModelAdapter::IsItemChecked(int id) const {
209 ui::MenuModel* model = menu_model_; 219 ui::MenuModel* model = menu_model_;
210 int index = 0; 220 int index = 0;
211 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) 221 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index))
212 return model->IsItemCheckedAt(index); 222 return model->IsItemCheckedAt(index);
213 223
214 NOTREACHED(); 224 NOTREACHED();
215 return false; 225 return false;
216 } 226 }
217 227
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // MenuModelAdapter, private: 268 // MenuModelAdapter, private:
259 269
260 void MenuModelAdapter::BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model) { 270 void MenuModelAdapter::BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model) {
261 DCHECK(menu); 271 DCHECK(menu);
262 DCHECK(model); 272 DCHECK(model);
263 bool has_icons = model->HasIcons(); 273 bool has_icons = model->HasIcons();
264 const int item_count = model->GetItemCount(); 274 const int item_count = model->GetItemCount();
265 for (int i = 0; i < item_count; ++i) { 275 for (int i = 0; i < item_count; ++i) {
266 MenuItemView* item = AppendMenuItem(menu, model, i); 276 MenuItemView* item = AppendMenuItem(menu, model, i);
267 277
268 if (item)
269 item->SetVisible(model->IsVisibleAt(i));
270
271 if (model->GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) { 278 if (model->GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) {
272 DCHECK(item); 279 DCHECK(item);
273 DCHECK_EQ(MenuItemView::SUBMENU, item->GetType()); 280 DCHECK_EQ(MenuItemView::SUBMENU, item->GetType());
274 ui::MenuModel* submodel = model->GetSubmenuModelAt(i); 281 ui::MenuModel* submodel = model->GetSubmenuModelAt(i);
275 DCHECK(submodel); 282 DCHECK(submodel);
276 BuildMenuImpl(item, submodel); 283 BuildMenuImpl(item, submodel);
277 has_icons = has_icons || item->has_icons(); 284 has_icons = has_icons || item->has_icons();
278 285
279 menu_map_[item] = submodel; 286 menu_map_[item] = submodel;
280 } 287 }
281 } 288 }
282 289
283 menu->set_has_icons(has_icons); 290 menu->set_has_icons(has_icons);
284 } 291 }
285 292
286 } // namespace views 293 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_model_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698