Chromium Code Reviews| 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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/wrench_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/view_ids.h" | |
| 18 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 19 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 19 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "content/public/browser/host_zoom_map.h" | 22 #include "content/public/browser/host_zoom_map.h" |
| 21 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 23 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 24 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 27 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 PopulateMenu(root_, model, &next_id); | 602 PopulateMenu(root_, model, &next_id); |
| 601 first_bookmark_command_id_ = next_id + 1; | 603 first_bookmark_command_id_ = next_id + 1; |
| 602 menu_runner_.reset(new views::MenuRunner(root_)); | 604 menu_runner_.reset(new views::MenuRunner(root_)); |
| 603 } | 605 } |
| 604 | 606 |
| 605 void WrenchMenu::RunMenu(views::MenuButton* host) { | 607 void WrenchMenu::RunMenu(views::MenuButton* host) { |
| 606 gfx::Point screen_loc; | 608 gfx::Point screen_loc; |
| 607 views::View::ConvertPointToScreen(host, &screen_loc); | 609 views::View::ConvertPointToScreen(host, &screen_loc); |
| 608 gfx::Rect bounds(screen_loc, host->size()); | 610 gfx::Rect bounds(screen_loc, host->size()); |
| 609 content::RecordAction(UserMetricsAction("ShowAppMenu")); | 611 content::RecordAction(UserMetricsAction("ShowAppMenu")); |
| 612 if (host->GetFocusManager()->GetFocusedView() == host) { | |
| 613 // If the app-menu has the focus, then move the focus to the content before | |
| 614 // showing the menu. | |
| 615 BrowserWindow* window = browser_->window(); | |
| 616 views::View* view = reinterpret_cast<BrowserView*>(window)-> | |
| 617 GetViewByID(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); | |
| 618 if (view) | |
| 619 view->GetFocusManager()->SetFocusedView(view); | |
| 620 } | |
|
sadrul
2012/02/23 14:51:24
An alternate option is to expose GetTabContentsCon
| |
| 610 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, | 621 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, |
| 611 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | 622 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
| 612 views::MenuRunner::MENU_DELETED) | 623 views::MenuRunner::MENU_DELETED) |
| 613 return; | 624 return; |
| 614 if (bookmark_menu_delegate_.get()) { | 625 if (bookmark_menu_delegate_.get()) { |
| 615 BookmarkModel* model = browser_->profile()->GetBookmarkModel(); | 626 BookmarkModel* model = browser_->profile()->GetBookmarkModel(); |
| 616 if (model) | 627 if (model) |
| 617 model->RemoveObserver(this); | 628 model->RemoveObserver(this); |
| 618 } | 629 } |
| 619 if (selected_menu_model_) | 630 if (selected_menu_model_) |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 bookmark_menu_delegate_.reset( | 906 bookmark_menu_delegate_.reset( |
| 896 new BookmarkMenuDelegate(browser_->profile(), | 907 new BookmarkMenuDelegate(browser_->profile(), |
| 897 NULL, | 908 NULL, |
| 898 parent, | 909 parent, |
| 899 first_bookmark_command_id_)); | 910 first_bookmark_command_id_)); |
| 900 bookmark_menu_delegate_->Init( | 911 bookmark_menu_delegate_->Init( |
| 901 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 912 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
| 902 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 913 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 903 bookmark_utils::LAUNCH_WRENCH_MENU); | 914 bookmark_utils::LAUNCH_WRENCH_MENU); |
| 904 } | 915 } |
| OLD | NEW |