Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3331)

Unified Diff: chrome/browser/views/tabs/browser_tab_strip_controller.cc

Issue 1001003: Allow dynamic switching in and out of sidetabs mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/views/tabs/browser_tab_strip_controller.cc
===================================================================
--- chrome/browser/views/tabs/browser_tab_strip_controller.cc (revision 41630)
+++ chrome/browser/views/tabs/browser_tab_strip_controller.cc (working copy)
@@ -5,8 +5,69 @@
#include "chrome/browser/views/tabs/browser_tab_strip_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_menu_model.h"
#include "chrome/browser/views/tabs/side_tab_strip.h"
+#include "views/controls/menu/menu_2.h"
+#include "views/widget/widget.h"
+class BrowserTabStripController::TabContextMenuContents
+ : public menus::SimpleMenuModel::Delegate {
+ public:
+ TabContextMenuContents(int tab_index, BrowserTabStripController* controller)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(model_(this)),
+ tab_index_(tab_index),
+ controller_(controller) {
+ Build();
+ }
+ virtual ~TabContextMenuContents() {
+ menu_->CancelMenu();
+ }
+
+ void RunMenuAt(const gfx::Point& point) {
+ menu_->RunMenuAt(point, views::Menu2::ALIGN_TOPLEFT);
+ }
+
+ // Overridden from menus::SimpleMenuModel::Delegate:
+ virtual bool IsCommandIdChecked(int command_id) const {
+ return controller_->IsCommandCheckedForTab(
+ static_cast<TabStripModel::ContextMenuCommand>(command_id),
+ tab_index_);
+ }
+ virtual bool IsCommandIdEnabled(int command_id) const {
+ return controller_->IsCommandEnabledForTab(
+ static_cast<TabStripModel::ContextMenuCommand>(command_id),
+ tab_index_);
+ }
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ menus::Accelerator* accelerator) {
+ return controller_->tabstrip_->GetWidget()->GetAccelerator(command_id,
+ accelerator);
+ }
+ virtual void ExecuteCommand(int command_id) {
+ controller_->ExecuteCommandForTab(
+ static_cast<TabStripModel::ContextMenuCommand>(command_id),
+ tab_index_);
+ }
+
+ private:
+ void Build() {
+ menu_.reset(new views::Menu2(&model_));
+ }
+
+ TabMenuModel model_;
+ scoped_ptr<views::Menu2> menu_;
+
+ // The index of the tab we are showing the context menu for.
+ int tab_index_;
+
+ // A pointer back to our hosting controller, for command state information.
+ BrowserTabStripController* controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents);
+};
+
+
////////////////////////////////////////////////////////////////////////////////
// BrowserTabStripController, public:
@@ -18,8 +79,42 @@
}
BrowserTabStripController::~BrowserTabStripController() {
+ model_->RemoveObserver(this);
}
+void BrowserTabStripController::InitFromModel() {
+ // Walk the model, calling our insertion observer method for each item within
+ // it.
+ for (int i = 0; i < model_->count(); ++i) {
+ TabInsertedAt(model_->GetTabContentsAt(i), i,
+ i == model_->selected_index());
+ }
+}
+
+bool BrowserTabStripController::IsCommandEnabledForTab(
+ TabStripModel::ContextMenuCommand command_id, int tab_index) const {
+ if (model_->ContainsIndex(tab_index))
+ return model_->IsContextMenuCommandEnabled(tab_index, command_id);
+ return false;
+}
+
+bool BrowserTabStripController::IsCommandCheckedForTab(
+ TabStripModel::ContextMenuCommand command_id, int tab_index) const {
+ // TODO(beng): move to TabStripModel, see note in IsTabPinned.
+ if (command_id == TabStripModel::CommandTogglePinned)
+ return false;
+
+ if (model_->ContainsIndex(tab_index))
+ return model_->IsContextMenuCommandChecked(tab_index, command_id);
+ return false;
+}
+
+void BrowserTabStripController::ExecuteCommandForTab(
+ TabStripModel::ContextMenuCommand command_id, int tab_index) {
+ if (model_->ContainsIndex(tab_index))
+ model_->ExecuteContextMenuCommand(tab_index, command_id);
+}
+
////////////////////////////////////////////////////////////////////////////////
// BrowserTabStripController, SideTabStripModel implementation:
@@ -53,6 +148,13 @@
model_->CloseTabContentsAt(index);
}
+void BrowserTabStripController::ShowContextMenu(int index,
+ const gfx::Point& p) {
+ if (!context_menu_contents_.get())
+ context_menu_contents_.reset(new TabContextMenuContents(index, this));
+ context_menu_contents_->RunMenuAt(p);
+}
+
////////////////////////////////////////////////////////////////////////////////
// BrowserTabStripController, TabStripModelObserver implementation:

Powered by Google App Engine
This is Rietveld 408576698