| 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/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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 controller_(controller), | 94 controller_(controller), |
| 95 last_command_(TabStripModel::CommandFirst) { | 95 last_command_(TabStripModel::CommandFirst) { |
| 96 model_.reset(new TabMenuModel( | 96 model_.reset(new TabMenuModel( |
| 97 this, controller->model_, | 97 this, controller->model_, |
| 98 controller->tabstrip_->GetModelIndexOfTab(tab))); | 98 controller->tabstrip_->GetModelIndexOfTab(tab))); |
| 99 menu_runner_.reset(new views::MenuRunner( | 99 menu_runner_.reset(new views::MenuRunner( |
| 100 model_.get(), | 100 model_.get(), |
| 101 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); | 101 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 virtual ~TabContextMenuContents() { | 104 ~TabContextMenuContents() override { |
| 105 if (controller_) | 105 if (controller_) |
| 106 controller_->tabstrip_->StopAllHighlighting(); | 106 controller_->tabstrip_->StopAllHighlighting(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void Cancel() { | 109 void Cancel() { |
| 110 controller_ = NULL; | 110 controller_ = NULL; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void RunMenuAt(const gfx::Point& point, ui::MenuSourceType source_type) { | 113 void RunMenuAt(const gfx::Point& point, ui::MenuSourceType source_type) { |
| 114 if (menu_runner_->RunMenuAt(tab_->GetWidget(), | 114 if (menu_runner_->RunMenuAt(tab_->GetWidget(), |
| 115 NULL, | 115 NULL, |
| 116 gfx::Rect(point, gfx::Size()), | 116 gfx::Rect(point, gfx::Size()), |
| 117 views::MENU_ANCHOR_TOPLEFT, | 117 views::MENU_ANCHOR_TOPLEFT, |
| 118 source_type) == | 118 source_type) == |
| 119 views::MenuRunner::MENU_DELETED) { | 119 views::MenuRunner::MENU_DELETED) { |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Overridden from ui::SimpleMenuModel::Delegate: | 124 // Overridden from ui::SimpleMenuModel::Delegate: |
| 125 virtual bool IsCommandIdChecked(int command_id) const override { | 125 bool IsCommandIdChecked(int command_id) const override { return false; } |
| 126 return false; | 126 bool IsCommandIdEnabled(int command_id) const override { |
| 127 } | |
| 128 virtual bool IsCommandIdEnabled(int command_id) const override { | |
| 129 return controller_->IsCommandEnabledForTab( | 127 return controller_->IsCommandEnabledForTab( |
| 130 static_cast<TabStripModel::ContextMenuCommand>(command_id), | 128 static_cast<TabStripModel::ContextMenuCommand>(command_id), |
| 131 tab_); | 129 tab_); |
| 132 } | 130 } |
| 133 virtual bool GetAcceleratorForCommandId( | 131 bool GetAcceleratorForCommandId(int command_id, |
| 134 int command_id, | 132 ui::Accelerator* accelerator) override { |
| 135 ui::Accelerator* accelerator) override { | |
| 136 int browser_cmd; | 133 int browser_cmd; |
| 137 return TabStripModel::ContextMenuCommandToBrowserCommand(command_id, | 134 return TabStripModel::ContextMenuCommandToBrowserCommand(command_id, |
| 138 &browser_cmd) ? | 135 &browser_cmd) ? |
| 139 controller_->tabstrip_->GetWidget()->GetAccelerator(browser_cmd, | 136 controller_->tabstrip_->GetWidget()->GetAccelerator(browser_cmd, |
| 140 accelerator) : | 137 accelerator) : |
| 141 false; | 138 false; |
| 142 } | 139 } |
| 143 virtual void CommandIdHighlighted(int command_id) override { | 140 void CommandIdHighlighted(int command_id) override { |
| 144 controller_->StopHighlightTabsForCommand(last_command_, tab_); | 141 controller_->StopHighlightTabsForCommand(last_command_, tab_); |
| 145 last_command_ = static_cast<TabStripModel::ContextMenuCommand>(command_id); | 142 last_command_ = static_cast<TabStripModel::ContextMenuCommand>(command_id); |
| 146 controller_->StartHighlightTabsForCommand(last_command_, tab_); | 143 controller_->StartHighlightTabsForCommand(last_command_, tab_); |
| 147 } | 144 } |
| 148 virtual void ExecuteCommand(int command_id, int event_flags) override { | 145 void ExecuteCommand(int command_id, int event_flags) override { |
| 149 // Executing the command destroys |this|, and can also end up destroying | 146 // Executing the command destroys |this|, and can also end up destroying |
| 150 // |controller_|. So stop the highlights before executing the command. | 147 // |controller_|. So stop the highlights before executing the command. |
| 151 controller_->tabstrip_->StopAllHighlighting(); | 148 controller_->tabstrip_->StopAllHighlighting(); |
| 152 controller_->ExecuteCommandForTab( | 149 controller_->ExecuteCommandForTab( |
| 153 static_cast<TabStripModel::ContextMenuCommand>(command_id), | 150 static_cast<TabStripModel::ContextMenuCommand>(command_id), |
| 154 tab_); | 151 tab_); |
| 155 } | 152 } |
| 156 | 153 |
| 157 virtual void MenuClosed(ui::SimpleMenuModel* /*source*/) override { | 154 void MenuClosed(ui::SimpleMenuModel* /*source*/) override { |
| 158 if (controller_) | 155 if (controller_) |
| 159 controller_->tabstrip_->StopAllHighlighting(); | 156 controller_->tabstrip_->StopAllHighlighting(); |
| 160 } | 157 } |
| 161 | 158 |
| 162 private: | 159 private: |
| 163 scoped_ptr<TabMenuModel> model_; | 160 scoped_ptr<TabMenuModel> model_; |
| 164 scoped_ptr<views::MenuRunner> menu_runner_; | 161 scoped_ptr<views::MenuRunner> menu_runner_; |
| 165 | 162 |
| 166 // The tab we're showing a menu for. | 163 // The tab we're showing a menu for. |
| 167 Tab* tab_; | 164 Tab* tab_; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 url, | 581 url, |
| 585 mime_type.empty() || | 582 mime_type.empty() || |
| 586 net::IsSupportedMimeType(mime_type) || | 583 net::IsSupportedMimeType(mime_type) || |
| 587 content::PluginService::GetInstance()->GetPluginInfo( | 584 content::PluginService::GetInstance()->GetPluginInfo( |
| 588 -1, // process ID | 585 -1, // process ID |
| 589 MSG_ROUTING_NONE, // routing ID | 586 MSG_ROUTING_NONE, // routing ID |
| 590 model_->profile()->GetResourceContext(), | 587 model_->profile()->GetResourceContext(), |
| 591 url, GURL(), mime_type, false, | 588 url, GURL(), mime_type, false, |
| 592 NULL, &plugin, NULL)); | 589 NULL, &plugin, NULL)); |
| 593 } | 590 } |
| OLD | NEW |