| OLD | NEW |
| 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 "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "content/common/notification_service.h" | 13 #include "content/common/notification_service.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "views/controls/menu/menu_item_view.h" | 16 #include "views/controls/menu/menu_item_view.h" |
| 17 #include "views/controls/menu/menu_runner.h" |
| 17 #include "views/widget/widget.h" | 18 #include "views/widget/widget.h" |
| 18 | 19 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
| 20 // BookmarkContextMenu, public: | 21 // BookmarkContextMenu, public: |
| 21 | 22 |
| 22 BookmarkContextMenu::BookmarkContextMenu( | 23 BookmarkContextMenu::BookmarkContextMenu( |
| 23 views::Widget* parent_widget, | 24 views::Widget* parent_widget, |
| 24 Profile* profile, | 25 Profile* profile, |
| 25 PageNavigator* page_navigator, | 26 PageNavigator* page_navigator, |
| 26 const BookmarkNode* parent, | 27 const BookmarkNode* parent, |
| 27 const std::vector<const BookmarkNode*>& selection, | 28 const std::vector<const BookmarkNode*>& selection, |
| 28 bool close_on_remove) | 29 bool close_on_remove) |
| 29 : ALLOW_THIS_IN_INITIALIZER_LIST( | 30 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 30 controller_(new BookmarkContextMenuControllerViews(parent_widget, | 31 controller_(new BookmarkContextMenuControllerViews(parent_widget, |
| 31 this, profile, page_navigator, parent, selection))), | 32 this, profile, page_navigator, parent, selection))), |
| 32 parent_widget_(parent_widget), | 33 parent_widget_(parent_widget), |
| 33 ALLOW_THIS_IN_INITIALIZER_LIST(menu_(new views::MenuItemView(this))), | 34 ALLOW_THIS_IN_INITIALIZER_LIST(menu_(new views::MenuItemView(this))), |
| 35 menu_runner_(new views::MenuRunner(menu_)), |
| 34 parent_node_(parent), | 36 parent_node_(parent), |
| 35 observer_(NULL), | 37 observer_(NULL), |
| 36 close_on_remove_(close_on_remove) { | 38 close_on_remove_(close_on_remove) { |
| 37 controller_->BuildMenu(); | 39 controller_->BuildMenu(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 BookmarkContextMenu::~BookmarkContextMenu() { | 42 BookmarkContextMenu::~BookmarkContextMenu() { |
| 41 } | 43 } |
| 42 | 44 |
| 43 void BookmarkContextMenu::RunMenuAt(const gfx::Point& point) { | 45 void BookmarkContextMenu::RunMenuAt(const gfx::Point& point) { |
| 44 NotificationService::current()->Notify( | 46 NotificationService::current()->Notify( |
| 45 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, | 47 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, |
| 46 Source<BookmarkContextMenu>(this), | 48 Source<BookmarkContextMenu>(this), |
| 47 NotificationService::NoDetails()); | 49 NotificationService::NoDetails()); |
| 48 // width/height don't matter here. | 50 // width/height don't matter here. |
| 49 views::MenuItemView::AnchorPosition anchor = base::i18n::IsRTL() ? | 51 if (menu_runner_->RunMenuAt( |
| 50 views::MenuItemView::TOPRIGHT : views::MenuItemView::TOPLEFT; | 52 parent_widget_, NULL, gfx::Rect(point.x(), point.y(), 0, 0), |
| 51 menu_->RunMenuAt(parent_widget_, NULL, gfx::Rect(point.x(), point.y(), 0, 0), | 53 views::MenuItemView::TOPLEFT, |
| 52 anchor, true); | 54 (views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::IS_NESTED)) == |
| 55 views::MenuRunner::MENU_DELETED) |
| 56 return; |
| 53 } | 57 } |
| 54 | 58 |
| 55 //////////////////////////////////////////////////////////////////////////////// | 59 //////////////////////////////////////////////////////////////////////////////// |
| 56 // BookmarkContextMenu, views::MenuDelegate implementation: | 60 // BookmarkContextMenu, views::MenuDelegate implementation: |
| 57 | 61 |
| 58 void BookmarkContextMenu::ExecuteCommand(int command_id) { | 62 void BookmarkContextMenu::ExecuteCommand(int command_id) { |
| 59 controller_->ExecuteCommand(command_id); | 63 controller_->ExecuteCommand(command_id); |
| 60 } | 64 } |
| 61 | 65 |
| 62 bool BookmarkContextMenu::IsItemChecked(int command_id) const { | 66 bool BookmarkContextMenu::IsItemChecked(int command_id) const { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 void BookmarkContextMenu::WillRemoveBookmarks( | 101 void BookmarkContextMenu::WillRemoveBookmarks( |
| 98 const std::vector<const BookmarkNode*>& bookmarks) { | 102 const std::vector<const BookmarkNode*>& bookmarks) { |
| 99 if (observer_) | 103 if (observer_) |
| 100 observer_->WillRemoveBookmarks(bookmarks); | 104 observer_->WillRemoveBookmarks(bookmarks); |
| 101 } | 105 } |
| 102 | 106 |
| 103 void BookmarkContextMenu::DidRemoveBookmarks() { | 107 void BookmarkContextMenu::DidRemoveBookmarks() { |
| 104 if (observer_) | 108 if (observer_) |
| 105 observer_->DidRemoveBookmarks(); | 109 observer_->DidRemoveBookmarks(); |
| 106 } | 110 } |
| OLD | NEW |