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

Side by Side Diff: chrome/browser/views/tabs/browser_tab_strip_controller.cc

Issue 1141005: Revert r42156, r42157, r42160. Allow dynamic switching in and out of sidetabs... (Closed) Base URL: svn://chrome-svn/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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/tabs/browser_tab_strip_controller.h" 5 #include "chrome/browser/views/tabs/browser_tab_strip_controller.h"
6 6
7 #include "chrome/browser/tab_contents/tab_contents.h" 7 #include "chrome/browser/tab_contents/tab_contents.h"
8 #include "chrome/browser/tab_menu_model.h"
9 #include "chrome/browser/views/tabs/side_tab_strip.h" 8 #include "chrome/browser/views/tabs/side_tab_strip.h"
10 #include "views/controls/menu/menu_2.h"
11 #include "views/widget/widget.h"
12
13 class BrowserTabStripController::TabContextMenuContents
14 : public menus::SimpleMenuModel::Delegate {
15 public:
16 TabContextMenuContents(int tab_index, BrowserTabStripController* controller)
17 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(this)),
18 tab_index_(tab_index),
19 controller_(controller) {
20 Build();
21 }
22 virtual ~TabContextMenuContents() {
23 menu_->CancelMenu();
24 }
25
26 void RunMenuAt(const gfx::Point& point) {
27 menu_->RunMenuAt(point, views::Menu2::ALIGN_TOPLEFT);
28 }
29
30 // Overridden from menus::SimpleMenuModel::Delegate:
31 virtual bool IsCommandIdChecked(int command_id) const {
32 return controller_->IsCommandCheckedForTab(
33 static_cast<TabStripModel::ContextMenuCommand>(command_id),
34 tab_index_);
35 }
36 virtual bool IsCommandIdEnabled(int command_id) const {
37 return controller_->IsCommandEnabledForTab(
38 static_cast<TabStripModel::ContextMenuCommand>(command_id),
39 tab_index_);
40 }
41 virtual bool GetAcceleratorForCommandId(
42 int command_id,
43 menus::Accelerator* accelerator) {
44 return controller_->tabstrip_->GetWidget()->GetAccelerator(command_id,
45 accelerator);
46 }
47 virtual void ExecuteCommand(int command_id) {
48 controller_->ExecuteCommandForTab(
49 static_cast<TabStripModel::ContextMenuCommand>(command_id),
50 tab_index_);
51 }
52
53 private:
54 void Build() {
55 menu_.reset(new views::Menu2(&model_));
56 }
57
58 TabMenuModel model_;
59 scoped_ptr<views::Menu2> menu_;
60
61 // The index of the tab we are showing the context menu for.
62 int tab_index_;
63
64 // A pointer back to our hosting controller, for command state information.
65 BrowserTabStripController* controller_;
66
67 DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents);
68 };
69
70 9
71 //////////////////////////////////////////////////////////////////////////////// 10 ////////////////////////////////////////////////////////////////////////////////
72 // BrowserTabStripController, public: 11 // BrowserTabStripController, public:
73 12
74 BrowserTabStripController::BrowserTabStripController(TabStripModel* model, 13 BrowserTabStripController::BrowserTabStripController(TabStripModel* model,
75 SideTabStrip* tabstrip) 14 SideTabStrip* tabstrip)
76 : model_(model), 15 : model_(model),
77 tabstrip_(tabstrip) { 16 tabstrip_(tabstrip) {
78 model_->AddObserver(this); 17 model_->AddObserver(this);
79 } 18 }
80 19
81 BrowserTabStripController::~BrowserTabStripController() { 20 BrowserTabStripController::~BrowserTabStripController() {
82 model_->RemoveObserver(this);
83 }
84
85 void BrowserTabStripController::InitFromModel() {
86 // Walk the model, calling our insertion observer method for each item within
87 // it.
88 for (int i = 0; i < model_->count(); ++i) {
89 TabInsertedAt(model_->GetTabContentsAt(i), i,
90 i == model_->selected_index());
91 }
92 }
93
94 bool BrowserTabStripController::IsCommandEnabledForTab(
95 TabStripModel::ContextMenuCommand command_id, int tab_index) const {
96 if (model_->ContainsIndex(tab_index))
97 return model_->IsContextMenuCommandEnabled(tab_index, command_id);
98 return false;
99 }
100
101 bool BrowserTabStripController::IsCommandCheckedForTab(
102 TabStripModel::ContextMenuCommand command_id, int tab_index) const {
103 // TODO(beng): move to TabStripModel, see note in IsTabPinned.
104 if (command_id == TabStripModel::CommandTogglePinned)
105 return false;
106
107 if (model_->ContainsIndex(tab_index))
108 return model_->IsContextMenuCommandChecked(tab_index, command_id);
109 return false;
110 }
111
112 void BrowserTabStripController::ExecuteCommandForTab(
113 TabStripModel::ContextMenuCommand command_id, int tab_index) {
114 if (model_->ContainsIndex(tab_index))
115 model_->ExecuteContextMenuCommand(tab_index, command_id);
116 } 21 }
117 22
118 //////////////////////////////////////////////////////////////////////////////// 23 ////////////////////////////////////////////////////////////////////////////////
119 // BrowserTabStripController, SideTabStripModel implementation: 24 // BrowserTabStripController, SideTabStripModel implementation:
120 25
121 SkBitmap BrowserTabStripController::GetIcon(int index) const { 26 SkBitmap BrowserTabStripController::GetIcon(int index) const {
122 return model_->GetTabContentsAt(index)->GetFavIcon(); 27 return model_->GetTabContentsAt(index)->GetFavIcon();
123 } 28 }
124 29
125 string16 BrowserTabStripController::GetTitle(int index) const { 30 string16 BrowserTabStripController::GetTitle(int index) const {
(...skipping 15 matching lines...) Expand all
141 } 46 }
142 47
143 void BrowserTabStripController::SelectTab(int index) { 48 void BrowserTabStripController::SelectTab(int index) {
144 model_->SelectTabContentsAt(index, true); 49 model_->SelectTabContentsAt(index, true);
145 } 50 }
146 51
147 void BrowserTabStripController::CloseTab(int index) { 52 void BrowserTabStripController::CloseTab(int index) {
148 model_->CloseTabContentsAt(index); 53 model_->CloseTabContentsAt(index);
149 } 54 }
150 55
151 void BrowserTabStripController::ShowContextMenu(int index,
152 const gfx::Point& p) {
153 if (!context_menu_contents_.get())
154 context_menu_contents_.reset(new TabContextMenuContents(index, this));
155 context_menu_contents_->RunMenuAt(p);
156 }
157
158 //////////////////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////////////////
159 // BrowserTabStripController, TabStripModelObserver implementation: 57 // BrowserTabStripController, TabStripModelObserver implementation:
160 58
161 void BrowserTabStripController::TabInsertedAt(TabContents* contents, int index, 59 void BrowserTabStripController::TabInsertedAt(TabContents* contents, int index,
162 bool foreground) { 60 bool foreground) {
163 tabstrip_->AddTabAt(index); 61 tabstrip_->AddTabAt(index);
164 } 62 }
165 63
166 void BrowserTabStripController::TabDetachedAt(TabContents* contents, 64 void BrowserTabStripController::TabDetachedAt(TabContents* contents,
167 int index) { 65 int index) {
(...skipping 21 matching lines...) Expand all
189 } 87 }
190 88
191 void BrowserTabStripController::TabPinnedStateChanged(TabContents* contents, 89 void BrowserTabStripController::TabPinnedStateChanged(TabContents* contents,
192 int index) { 90 int index) {
193 } 91 }
194 92
195 void BrowserTabStripController::TabBlockedStateChanged(TabContents* contents, 93 void BrowserTabStripController::TabBlockedStateChanged(TabContents* contents,
196 int index) { 94 int index) {
197 } 95 }
198 96
OLDNEW
« no previous file with comments | « chrome/browser/views/tabs/browser_tab_strip_controller.h ('k') | chrome/browser/views/tabs/side_tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698