OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/renderer_context_menu/views/toolkit_delegate_views.h" | 5 #include "components/renderer_context_menu/views/toolkit_delegate_views.h" |
6 | 6 |
7 #include "ui/gfx/geometry/rect.h" | 7 #include "ui/gfx/geometry/rect.h" |
| 8 #include "ui/gfx/image/image.h" |
8 #include "ui/views/controls/menu/menu_item_view.h" | 9 #include "ui/views/controls/menu/menu_item_view.h" |
9 #include "ui/views/controls/menu/menu_model_adapter.h" | 10 #include "ui/views/controls/menu/menu_model_adapter.h" |
10 #include "ui/views/controls/menu/menu_runner.h" | 11 #include "ui/views/controls/menu/menu_runner.h" |
11 | 12 |
12 ToolkitDelegateViews::ToolkitDelegateViews() : menu_view_(NULL) {} | 13 ToolkitDelegateViews::ToolkitDelegateViews() : menu_view_(NULL) {} |
13 | 14 |
14 ToolkitDelegateViews::~ToolkitDelegateViews() {} | 15 ToolkitDelegateViews::~ToolkitDelegateViews() {} |
15 | 16 |
16 void ToolkitDelegateViews::RunMenuAt(views::Widget* parent, | 17 void ToolkitDelegateViews::RunMenuAt(views::Widget* parent, |
17 const gfx::Point& point, | 18 const gfx::Point& point, |
(...skipping 16 matching lines...) Expand all Loading... |
34 } | 35 } |
35 | 36 |
36 void ToolkitDelegateViews::Cancel() { | 37 void ToolkitDelegateViews::Cancel() { |
37 DCHECK(menu_runner_.get()); | 38 DCHECK(menu_runner_.get()); |
38 menu_runner_->Cancel(); | 39 menu_runner_->Cancel(); |
39 } | 40 } |
40 | 41 |
41 void ToolkitDelegateViews::UpdateMenuItem(int command_id, | 42 void ToolkitDelegateViews::UpdateMenuItem(int command_id, |
42 bool enabled, | 43 bool enabled, |
43 bool hidden, | 44 bool hidden, |
44 const base::string16& title) { | 45 const base::string16& title, |
| 46 gfx::Image* icon) { |
45 views::MenuItemView* item = menu_view_->GetMenuItemByID(command_id); | 47 views::MenuItemView* item = menu_view_->GetMenuItemByID(command_id); |
46 if (!item) | 48 if (!item) |
47 return; | 49 return; |
48 | 50 |
49 item->SetEnabled(enabled); | 51 item->SetEnabled(enabled); |
50 item->SetTitle(title); | 52 item->SetTitle(title); |
51 item->SetVisible(!hidden); | 53 item->SetVisible(!hidden); |
| 54 if (icon) |
| 55 item->SetIcon(*icon->ToImageSkia()); |
52 | 56 |
53 views::MenuItemView* parent = item->GetParentMenuItem(); | 57 views::MenuItemView* parent = item->GetParentMenuItem(); |
54 if (!parent) | 58 if (!parent) |
55 return; | 59 return; |
56 | 60 |
57 parent->ChildrenChanged(); | 61 parent->ChildrenChanged(); |
58 } | 62 } |
59 | |
OLD | NEW |