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

Side by Side Diff: ui/base/models/simple_menu_model.cc

Issue 6336014: Fix printing PDFs through right click on Mac and Linux. Looks like they both... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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/base/models/simple_menu_model.h ('k') | views/controls/menu/native_menu_win.cc » ('j') | 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) 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 #include "ui/base/models/simple_menu_model.h" 5 #include "ui/base/models/simple_menu_model.h"
6 6
7 #include "base/message_loop.h"
7 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
9 10
10 namespace ui { 11 namespace ui {
11 12
12 const int kSeparatorId = -1; 13 const int kSeparatorId = -1;
13 14
14 struct SimpleMenuModel::Item { 15 struct SimpleMenuModel::Item {
15 int command_id; 16 int command_id;
16 string16 label; 17 string16 label;
(...skipping 27 matching lines...) Expand all
44 45
45 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { 46 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) {
46 } 47 }
47 48
48 void SimpleMenuModel::Delegate::MenuClosed() { 49 void SimpleMenuModel::Delegate::MenuClosed() {
49 } 50 }
50 51
51 //////////////////////////////////////////////////////////////////////////////// 52 ////////////////////////////////////////////////////////////////////////////////
52 // SimpleMenuModel, public: 53 // SimpleMenuModel, public:
53 54
54 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) { 55 SimpleMenuModel::SimpleMenuModel(Delegate* delegate)
56 : delegate_(delegate),
57 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
55 } 58 }
56 59
57 SimpleMenuModel::~SimpleMenuModel() { 60 SimpleMenuModel::~SimpleMenuModel() {
58 } 61 }
59 62
60 void SimpleMenuModel::AddItem(int command_id, const string16& label) { 63 void SimpleMenuModel::AddItem(int command_id, const string16& label) {
61 Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL, NULL }; 64 Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL, NULL };
62 AppendItem(item); 65 AppendItem(item);
63 } 66 }
64 67
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 void SimpleMenuModel::ActivatedAt(int index) { 284 void SimpleMenuModel::ActivatedAt(int index) {
282 if (delegate_) 285 if (delegate_)
283 delegate_->ExecuteCommand(GetCommandIdAt(index)); 286 delegate_->ExecuteCommand(GetCommandIdAt(index));
284 } 287 }
285 288
286 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { 289 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const {
287 return items_.at(FlipIndex(index)).submenu; 290 return items_.at(FlipIndex(index)).submenu;
288 } 291 }
289 292
290 void SimpleMenuModel::MenuClosed() { 293 void SimpleMenuModel::MenuClosed() {
294 // Due to how menus work on the different platforms, ActivatedAt will be
295 // called after this. It's more convenient for the delegate to be called
296 // afterwards though, so post a task.
297 MessageLoop::current()->PostTask(
298 FROM_HERE,
299 method_factory_.NewRunnableMethod(&SimpleMenuModel::OnMenuClosed));
300 }
301
302 void SimpleMenuModel::OnMenuClosed() {
291 if (delegate_) 303 if (delegate_)
292 delegate_->MenuClosed(); 304 delegate_->MenuClosed();
293 } 305 }
294 306
295 int SimpleMenuModel::FlipIndex(int index) const { 307 int SimpleMenuModel::FlipIndex(int index) const {
296 return index; 308 return index;
297 } 309 }
298 310
299 //////////////////////////////////////////////////////////////////////////////// 311 ////////////////////////////////////////////////////////////////////////////////
300 // SimpleMenuModel, Private: 312 // SimpleMenuModel, Private:
(...skipping 12 matching lines...) Expand all
313 #ifndef NDEBUG 325 #ifndef NDEBUG
314 if (item.type == TYPE_SEPARATOR) { 326 if (item.type == TYPE_SEPARATOR) {
315 DCHECK_EQ(item.command_id, kSeparatorId); 327 DCHECK_EQ(item.command_id, kSeparatorId);
316 } else { 328 } else {
317 DCHECK_GE(item.command_id, 0); 329 DCHECK_GE(item.command_id, 0);
318 } 330 }
319 #endif // NDEBUG 331 #endif // NDEBUG
320 } 332 }
321 333
322 } // namespace ui 334 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/models/simple_menu_model.h ('k') | views/controls/menu/native_menu_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698