| OLD | NEW |
| 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 "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro
ller.h" | 5 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro
ller.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
| 10 #include "chrome/browser/extensions/extension_action_manager.h" | 10 #include "chrome/browser/extensions/extension_action_manager.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // In the browser actions container's chevron menu, a menu item view's icon | 24 // In the browser actions container's chevron menu, a menu item view's icon |
| 25 // comes from BrowserActionView::GetIconWithBadge() (which comes from the | 25 // comes from BrowserActionView::GetIconWithBadge() (which comes from the |
| 26 // browser action button's icon) when the menu item view is created. But, the | 26 // browser action button's icon) when the menu item view is created. But, the |
| 27 // browser action button's icon may not be loaded in time because it is read | 27 // browser action button's icon may not be loaded in time because it is read |
| 28 // from file system in another thread. | 28 // from file system in another thread. |
| 29 // The IconUpdater will update the menu item view's icon when the browser | 29 // The IconUpdater will update the menu item view's icon when the browser |
| 30 // action button's icon has been updated. | 30 // action button's icon has been updated. |
| 31 class IconUpdater : public BrowserActionButton::IconObserver { | 31 class IconUpdater : public BrowserActionButton::IconObserver { |
| 32 public: | 32 public: |
| 33 IconUpdater(views::MenuItemView* menu_item_view, | 33 IconUpdater(views::MenuItemView* menu_item_view, BrowserActionButton* button) |
| 34 BrowserActionButton* button) | |
| 35 : menu_item_view_(menu_item_view), | 34 : menu_item_view_(menu_item_view), |
| 36 button_(button) { | 35 button_(button) { |
| 37 DCHECK(menu_item_view); | 36 DCHECK(menu_item_view); |
| 38 DCHECK(button); | 37 DCHECK(button); |
| 39 button->set_icon_observer(this); | 38 button->set_icon_observer(this); |
| 40 } | 39 } |
| 41 virtual ~IconUpdater() { | 40 virtual ~IconUpdater() { |
| 42 button_->set_icon_observer(NULL); | 41 button_->set_icon_observer(NULL); |
| 43 } | 42 } |
| 44 | 43 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // command. | 120 // command. |
| 122 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 121 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 123 } | 122 } |
| 124 return true; | 123 return true; |
| 125 } | 124 } |
| 126 | 125 |
| 127 void BrowserActionOverflowMenuController::CancelMenu() { | 126 void BrowserActionOverflowMenuController::CancelMenu() { |
| 128 menu_->Cancel(); | 127 menu_->Cancel(); |
| 129 } | 128 } |
| 130 | 129 |
| 130 void BrowserActionOverflowMenuController::NotifyBrowserActionViewsDeleting() { |
| 131 icon_updaters_.clear(); |
| 132 } |
| 133 |
| 131 bool BrowserActionOverflowMenuController::IsCommandEnabled(int id) const { | 134 bool BrowserActionOverflowMenuController::IsCommandEnabled(int id) const { |
| 132 BrowserActionView* view = (*views_)[start_index_ + id - 1]; | 135 BrowserActionView* view = (*views_)[start_index_ + id - 1]; |
| 133 return view->button()->IsEnabled(owner_->GetCurrentTabId()); | 136 return view->button()->IsEnabled(owner_->GetCurrentTabId()); |
| 134 } | 137 } |
| 135 | 138 |
| 136 void BrowserActionOverflowMenuController::ExecuteCommand(int id) { | 139 void BrowserActionOverflowMenuController::ExecuteCommand(int id) { |
| 137 BrowserActionView* view = (*views_)[start_index_ + id - 1]; | 140 BrowserActionView* view = (*views_)[start_index_ + id - 1]; |
| 138 owner_->OnBrowserActionExecuted(view->button()); | 141 owner_->OnBrowserActionExecuted(view->button()); |
| 139 } | 142 } |
| 140 | 143 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 264 |
| 262 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( | 265 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( |
| 263 int id, size_t* index) { | 266 int id, size_t* index) { |
| 264 // The index of the view being dragged (GetCommand gives a 1-based index into | 267 // The index of the view being dragged (GetCommand gives a 1-based index into |
| 265 // the overflow menu). | 268 // the overflow menu). |
| 266 size_t view_index = owner_->VisibleBrowserActions() + id - 1; | 269 size_t view_index = owner_->VisibleBrowserActions() + id - 1; |
| 267 if (index) | 270 if (index) |
| 268 *index = view_index; | 271 *index = view_index; |
| 269 return owner_->GetBrowserActionViewAt(view_index); | 272 return owner_->GetBrowserActionViewAt(view_index); |
| 270 } | 273 } |
| OLD | NEW |