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/tabs/browser_tab_strip_controller.h" | 5 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/browser/extensions/extension_tab_helper.h" | 9 #include "chrome/browser/extensions/extension_tab_helper.h" |
10 #include "chrome/browser/favicon/favicon_tab_helper.h" | 10 #include "chrome/browser/favicon/favicon_tab_helper.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/tabs/tab_strip_model.h" | 12 #include "chrome/browser/tabs/tab_strip_model.h" |
13 #include "chrome/browser/tabs/tab_strip_selection_model.h" | 13 #include "chrome/browser/tabs/tab_strip_selection_model.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
16 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 16 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
17 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" | 17 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" |
18 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 18 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "content/browser/renderer_host/render_view_host.h" | 21 #include "content/browser/renderer_host/render_view_host.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
23 #include "content/browser/user_metrics.h" | 23 #include "content/browser/user_metrics.h" |
24 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
25 #include "views/controls/menu/menu_item_view.h" | 25 #include "views/controls/menu/menu_item_view.h" |
26 #include "views/controls/menu/menu_model_adapter.h" | 26 #include "views/controls/menu/menu_model_adapter.h" |
| 27 #include "views/controls/menu/menu_runner.h" |
27 #include "views/widget/widget.h" | 28 #include "views/widget/widget.h" |
28 | 29 |
29 static TabRendererData::NetworkState TabContentsNetworkState( | 30 static TabRendererData::NetworkState TabContentsNetworkState( |
30 TabContents* contents) { | 31 TabContents* contents) { |
31 if (!contents || !contents->IsLoading()) | 32 if (!contents || !contents->IsLoading()) |
32 return TabRendererData::NETWORK_STATE_NONE; | 33 return TabRendererData::NETWORK_STATE_NONE; |
33 if (contents->waiting_for_response()) | 34 if (contents->waiting_for_response()) |
34 return TabRendererData::NETWORK_STATE_WAITING; | 35 return TabRendererData::NETWORK_STATE_WAITING; |
35 return TabRendererData::NETWORK_STATE_LOADING; | 36 return TabRendererData::NETWORK_STATE_LOADING; |
36 } | 37 } |
37 | 38 |
38 class BrowserTabStripController::TabContextMenuContents | 39 class BrowserTabStripController::TabContextMenuContents |
39 : public ui::SimpleMenuModel::Delegate { | 40 : public ui::SimpleMenuModel::Delegate { |
40 public: | 41 public: |
41 TabContextMenuContents(BaseTab* tab, | 42 TabContextMenuContents(BaseTab* tab, |
42 BrowserTabStripController* controller) | 43 BrowserTabStripController* controller) |
43 : ALLOW_THIS_IN_INITIALIZER_LIST( | 44 : tab_(tab), |
44 model_(this, | |
45 controller->model_, | |
46 controller->tabstrip_->GetModelIndexOfBaseTab(tab))), | |
47 menu_model_adapter_(&model_), | |
48 menu_(&menu_model_adapter_), | |
49 tab_(tab), | |
50 controller_(controller), | 45 controller_(controller), |
51 last_command_(TabStripModel::CommandFirst) { | 46 last_command_(TabStripModel::CommandFirst) { |
52 menu_model_adapter_.BuildMenu(&menu_); | 47 model_.reset(new TabMenuModel( |
| 48 this, controller->model_, |
| 49 controller->tabstrip_->GetModelIndexOfBaseTab(tab))); |
| 50 menu_model_adapter_.reset(new views::MenuModelAdapter(model_.get())); |
| 51 menu_runner_.reset( |
| 52 new views::MenuRunner(menu_model_adapter_->CreateMenu())); |
53 } | 53 } |
| 54 |
54 virtual ~TabContextMenuContents() { | 55 virtual ~TabContextMenuContents() { |
55 menu_.Cancel(); | |
56 if (controller_) | 56 if (controller_) |
57 controller_->tabstrip_->StopAllHighlighting(); | 57 controller_->tabstrip_->StopAllHighlighting(); |
58 } | 58 } |
59 | 59 |
60 void Cancel() { | 60 void Cancel() { |
61 controller_ = NULL; | 61 controller_ = NULL; |
62 } | 62 } |
63 | 63 |
64 void RunMenuAt(const gfx::Point& point) { | 64 void RunMenuAt(const gfx::Point& point) { |
65 menu_.RunMenuAt(tab_->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 65 if (menu_runner_->RunMenuAt( |
66 views::MenuItemView::TOPLEFT, true); | 66 tab_->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
67 // We could be gone now. Assume |this| is junk! | 67 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
| 68 views::MenuRunner::MENU_DELETED) |
| 69 return; |
68 } | 70 } |
69 | 71 |
70 // Overridden from ui::SimpleMenuModel::Delegate: | 72 // Overridden from ui::SimpleMenuModel::Delegate: |
71 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { | 73 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { |
72 return controller_->IsCommandCheckedForTab( | 74 return controller_->IsCommandCheckedForTab( |
73 static_cast<TabStripModel::ContextMenuCommand>(command_id), | 75 static_cast<TabStripModel::ContextMenuCommand>(command_id), |
74 tab_); | 76 tab_); |
75 } | 77 } |
76 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { | 78 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { |
77 return controller_->IsCommandEnabledForTab( | 79 return controller_->IsCommandEnabledForTab( |
(...skipping 24 matching lines...) Expand all Loading... |
102 static_cast<TabStripModel::ContextMenuCommand>(command_id), | 104 static_cast<TabStripModel::ContextMenuCommand>(command_id), |
103 tab_); | 105 tab_); |
104 } | 106 } |
105 | 107 |
106 virtual void MenuClosed(ui::SimpleMenuModel* /*source*/) OVERRIDE { | 108 virtual void MenuClosed(ui::SimpleMenuModel* /*source*/) OVERRIDE { |
107 if (controller_) | 109 if (controller_) |
108 controller_->tabstrip_->StopAllHighlighting(); | 110 controller_->tabstrip_->StopAllHighlighting(); |
109 } | 111 } |
110 | 112 |
111 private: | 113 private: |
112 TabMenuModel model_; | 114 scoped_ptr<TabMenuModel> model_; |
113 views::MenuModelAdapter menu_model_adapter_; | 115 scoped_ptr<views::MenuModelAdapter> menu_model_adapter_; |
114 views::MenuItemView menu_; | 116 scoped_ptr<views::MenuRunner> menu_runner_; |
115 | 117 |
116 // The tab we're showing a menu for. | 118 // The tab we're showing a menu for. |
117 BaseTab* tab_; | 119 BaseTab* tab_; |
118 | 120 |
119 // A pointer back to our hosting controller, for command state information. | 121 // A pointer back to our hosting controller, for command state information. |
120 BrowserTabStripController* controller_; | 122 BrowserTabStripController* controller_; |
121 | 123 |
122 // The last command that was selected, so that we can start/stop highlighting | 124 // The last command that was selected, so that we can start/stop highlighting |
123 // appropriately as the user moves through the menu. | 125 // appropriately as the user moves through the menu. |
124 TabStripModel::ContextMenuCommand last_command_; | 126 TabStripModel::ContextMenuCommand last_command_; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 476 |
475 void BrowserTabStripController::StopHighlightTabsForCommand( | 477 void BrowserTabStripController::StopHighlightTabsForCommand( |
476 TabStripModel::ContextMenuCommand command_id, | 478 TabStripModel::ContextMenuCommand command_id, |
477 BaseTab* tab) { | 479 BaseTab* tab) { |
478 if (command_id == TabStripModel::CommandCloseTabsToRight || | 480 if (command_id == TabStripModel::CommandCloseTabsToRight || |
479 command_id == TabStripModel::CommandCloseOtherTabs) { | 481 command_id == TabStripModel::CommandCloseOtherTabs) { |
480 // Just tell all Tabs to stop pulsing - it's safe. | 482 // Just tell all Tabs to stop pulsing - it's safe. |
481 tabstrip_->StopAllHighlighting(); | 483 tabstrip_->StopAllHighlighting(); |
482 } | 484 } |
483 } | 485 } |
OLD | NEW |