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

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

Issue 291093005: Removes --enable-stacked-tab-strip flag (Stacked Tabs) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removes --enable-stacked-tab-strip flag (removed stale header) Created 6 years, 6 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) 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_tabstrip.h" 23 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/browser/ui/tabs/tab_menu_model.h" 24 #include "chrome/browser/ui/tabs/tab_menu_model.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
27 #include "chrome/browser/ui/tabs/tab_utils.h" 27 #include "chrome/browser/ui/tabs/tab_utils.h"
28 #include "chrome/browser/ui/views/frame/browser_view.h" 28 #include "chrome/browser/ui/views/frame/browser_view.h"
29 #include "chrome/browser/ui/views/tabs/tab.h" 29 #include "chrome/browser/ui/views/tabs/tab.h"
30 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" 30 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h"
31 #include "chrome/browser/ui/views/tabs/tab_strip.h" 31 #include "chrome/browser/ui/views/tabs/tab_strip.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
34 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
35 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/plugin_service.h" 36 #include "content/public/browser/plugin_service.h"
38 #include "content/public/browser/user_metrics.h" 37 #include "content/public/browser/user_metrics.h"
39 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
40 #include "content/public/common/webplugininfo.h" 39 #include "content/public/common/webplugininfo.h"
41 #include "ipc/ipc_message.h" 40 #include "ipc/ipc_message.h"
42 #include "net/base/filename_util.h" 41 #include "net/base/filename_util.h"
43 #include "ui/base/models/list_selection_model.h" 42 #include "ui/base/models/list_selection_model.h"
44 #include "ui/gfx/image/image.h" 43 #include "ui/gfx/image/image.h"
45 #include "ui/views/controls/menu/menu_runner.h" 44 #include "ui/views/controls/menu/menu_runner.h"
46 #include "ui/views/widget/widget.h" 45 #include "ui/views/widget/widget.h"
47 46
48 using base::UserMetricsAction; 47 using base::UserMetricsAction;
49 using content::WebContents; 48 using content::WebContents;
50 49
51 namespace { 50 namespace {
52 51
53 TabRendererData::NetworkState TabContentsNetworkState( 52 TabRendererData::NetworkState TabContentsNetworkState(
54 WebContents* contents) { 53 WebContents* contents) {
55 if (!contents || !contents->IsLoadingToDifferentDocument()) 54 if (!contents || !contents->IsLoadingToDifferentDocument())
56 return TabRendererData::NETWORK_STATE_NONE; 55 return TabRendererData::NETWORK_STATE_NONE;
57 if (contents->IsWaitingForResponse()) 56 if (contents->IsWaitingForResponse())
58 return TabRendererData::NETWORK_STATE_WAITING; 57 return TabRendererData::NETWORK_STATE_WAITING;
59 return TabRendererData::NETWORK_STATE_LOADING; 58 return TabRendererData::NETWORK_STATE_LOADING;
60 } 59 }
61 60
62 TabStripLayoutType DetermineTabStripLayout( 61 bool DetermineTabStripLayoutStacked(
63 PrefService* prefs, 62 PrefService* prefs,
64 chrome::HostDesktopType host_desktop_type, 63 chrome::HostDesktopType host_desktop_type,
65 bool* adjust_layout) { 64 bool* adjust_layout) {
66 *adjust_layout = false; 65 *adjust_layout = false;
67 if (CommandLine::ForCurrentProcess()->HasSwitch(
68 switches::kEnableStackedTabStrip)) {
69 return TAB_STRIP_LAYOUT_STACKED;
70 }
71 // For ash, always allow entering stacked mode. 66 // For ash, always allow entering stacked mode.
72 if (host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH) 67 if (host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH)
73 return TAB_STRIP_LAYOUT_SHRINK; 68 return false;
74 *adjust_layout = true; 69 *adjust_layout = true;
75 switch (prefs->GetInteger(prefs::kTabStripLayoutType)) { 70 return prefs->GetBoolean(prefs::kTabStripStackedLayout);
76 case TAB_STRIP_LAYOUT_STACKED:
77 return TAB_STRIP_LAYOUT_STACKED;
78 default:
79 return TAB_STRIP_LAYOUT_SHRINK;
80 }
81 } 71 }
82 72
83 // Get the MIME type of the file pointed to by the url, based on the file's 73 // Get the MIME type of the file pointed to by the url, based on the file's
84 // extension. Must be called on a thread that allows IO. 74 // extension. Must be called on a thread that allows IO.
85 std::string FindURLMimeType(const GURL& url) { 75 std::string FindURLMimeType(const GURL& url) {
86 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 76 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
87 base::FilePath full_path; 77 base::FilePath full_path;
88 net::FileURLToFilePath(url, &full_path); 78 net::FileURLToFilePath(url, &full_path);
89 79
90 // Get the MIME type based on the filename. 80 // Get the MIME type based on the filename.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 TabStripModel* model) 184 TabStripModel* model)
195 : model_(model), 185 : model_(model),
196 tabstrip_(NULL), 186 tabstrip_(NULL),
197 browser_(browser), 187 browser_(browser),
198 hover_tab_selector_(model), 188 hover_tab_selector_(model),
199 weak_ptr_factory_(this) { 189 weak_ptr_factory_(this) {
200 model_->AddObserver(this); 190 model_->AddObserver(this);
201 191
202 local_pref_registrar_.Init(g_browser_process->local_state()); 192 local_pref_registrar_.Init(g_browser_process->local_state());
203 local_pref_registrar_.Add( 193 local_pref_registrar_.Add(
204 prefs::kTabStripLayoutType, 194 prefs::kTabStripStackedLayout,
205 base::Bind(&BrowserTabStripController::UpdateLayoutType, 195 base::Bind(&BrowserTabStripController::UpdateStackedLayout,
206 base::Unretained(this))); 196 base::Unretained(this)));
207 } 197 }
208 198
209 BrowserTabStripController::~BrowserTabStripController() { 199 BrowserTabStripController::~BrowserTabStripController() {
210 // When we get here the TabStrip is being deleted. We need to explicitly 200 // When we get here the TabStrip is being deleted. We need to explicitly
211 // cancel the menu, otherwise it may try to invoke something on the tabstrip 201 // cancel the menu, otherwise it may try to invoke something on the tabstrip
212 // from its destructor. 202 // from its destructor.
213 if (context_menu_contents_.get()) 203 if (context_menu_contents_.get())
214 context_menu_contents_->Cancel(); 204 context_menu_contents_->Cancel();
215 205
216 model_->RemoveObserver(this); 206 model_->RemoveObserver(this);
217 } 207 }
218 208
219 void BrowserTabStripController::InitFromModel(TabStrip* tabstrip) { 209 void BrowserTabStripController::InitFromModel(TabStrip* tabstrip) {
220 tabstrip_ = tabstrip; 210 tabstrip_ = tabstrip;
221 211
222 UpdateLayoutType(); 212 UpdateStackedLayout();
223 213
224 // Walk the model, calling our insertion observer method for each item within 214 // Walk the model, calling our insertion observer method for each item within
225 // it. 215 // it.
226 for (int i = 0; i < model_->count(); ++i) 216 for (int i = 0; i < model_->count(); ++i)
227 AddTab(model_->GetWebContentsAt(i), i, model_->active_index() == i); 217 AddTab(model_->GetWebContentsAt(i), i, model_->active_index() == i);
228 } 218 }
229 219
230 bool BrowserTabStripController::IsCommandEnabledForTab( 220 bool BrowserTabStripController::IsCommandEnabledForTab(
231 TabStripModel::ContextMenuCommand command_id, 221 TabStripModel::ContextMenuCommand command_id,
232 Tab* tab) const { 222 Tab* tab) const {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 AutocompleteClassifierFactory::GetForProfile(profile())->Classify( 373 AutocompleteClassifierFactory::GetForProfile(profile())->Classify(
384 location, false, false, AutocompleteInput::BLANK, &match, NULL); 374 location, false, false, AutocompleteInput::BLANK, &match, NULL);
385 if (match.destination_url.is_valid()) 375 if (match.destination_url.is_valid())
386 model_->delegate()->AddTabAt(match.destination_url, -1, true); 376 model_->delegate()->AddTabAt(match.destination_url, -1, true);
387 } 377 }
388 378
389 bool BrowserTabStripController::IsIncognito() { 379 bool BrowserTabStripController::IsIncognito() {
390 return browser_->profile()->IsOffTheRecord(); 380 return browser_->profile()->IsOffTheRecord();
391 } 381 }
392 382
393 void BrowserTabStripController::LayoutTypeMaybeChanged() { 383 void BrowserTabStripController::StackedLayoutMaybeChanged() {
394 bool adjust_layout = false; 384 bool adjust_layout = false;
395 TabStripLayoutType layout_type = 385 bool stacked_layout =
396 DetermineTabStripLayout(g_browser_process->local_state(), 386 DetermineTabStripLayoutStacked(g_browser_process->local_state(),
397 browser_->host_desktop_type(), &adjust_layout); 387 browser_->host_desktop_type(),
398 if (!adjust_layout || layout_type == tabstrip_->layout_type()) 388 &adjust_layout);
389 if (!adjust_layout || stacked_layout == tabstrip_->stacked_layout())
399 return; 390 return;
400 391
401 g_browser_process->local_state()->SetInteger( 392 g_browser_process->local_state()->SetBoolean(prefs::kTabStripStackedLayout,
402 prefs::kTabStripLayoutType, 393 tabstrip_->stacked_layout());
403 static_cast<int>(tabstrip_->layout_type()));
404 } 394 }
405 395
406 void BrowserTabStripController::OnStartedDraggingTabs() { 396 void BrowserTabStripController::OnStartedDraggingTabs() {
407 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); 397 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
408 if (browser_view && !immersive_reveal_lock_.get()) { 398 if (browser_view && !immersive_reveal_lock_.get()) {
409 // The top-of-window views should be revealed while the user is dragging 399 // The top-of-window views should be revealed while the user is dragging
410 // tabs in immersive fullscreen. The top-of-window views may not be already 400 // tabs in immersive fullscreen. The top-of-window views may not be already
411 // revealed if the user is attempting to attach a tab to a tabstrip 401 // revealed if the user is attempting to attach a tab to a tabstrip
412 // belonging to an immersive fullscreen window. 402 // belonging to an immersive fullscreen window.
413 immersive_reveal_lock_.reset( 403 immersive_reveal_lock_.reset(
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 int index, 551 int index,
562 bool is_active) { 552 bool is_active) {
563 // Cancel any pending tab transition. 553 // Cancel any pending tab transition.
564 hover_tab_selector_.CancelTabTransition(); 554 hover_tab_selector_.CancelTabTransition();
565 555
566 TabRendererData data; 556 TabRendererData data;
567 SetTabRendererDataFromModel(contents, index, &data, NEW_TAB); 557 SetTabRendererDataFromModel(contents, index, &data, NEW_TAB);
568 tabstrip_->AddTabAt(index, data, is_active); 558 tabstrip_->AddTabAt(index, data, is_active);
569 } 559 }
570 560
571 void BrowserTabStripController::UpdateLayoutType() { 561 void BrowserTabStripController::UpdateStackedLayout() {
572 bool adjust_layout = false; 562 bool adjust_layout = false;
573 TabStripLayoutType layout_type = 563 bool stacked_layout =
574 DetermineTabStripLayout(g_browser_process->local_state(), 564 DetermineTabStripLayoutStacked(g_browser_process->local_state(),
575 browser_->host_desktop_type(), &adjust_layout); 565 browser_->host_desktop_type(),
576 tabstrip_->SetLayoutType(layout_type, adjust_layout); 566 &adjust_layout);
567 tabstrip_->set_adjust_layout(adjust_layout);
568 tabstrip_->SetStackedLayout(stacked_layout);
577 } 569 }
578 570
579 void BrowserTabStripController::OnFindURLMimeTypeCompleted( 571 void BrowserTabStripController::OnFindURLMimeTypeCompleted(
580 const GURL& url, 572 const GURL& url,
581 const std::string& mime_type) { 573 const std::string& mime_type) {
582 // Check whether the mime type, if given, is known to be supported or whether 574 // Check whether the mime type, if given, is known to be supported or whether
583 // there is a plugin that supports the mime type (e.g. PDF). 575 // there is a plugin that supports the mime type (e.g. PDF).
584 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not 576 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not
585 // to do disk access. 577 // to do disk access.
586 content::WebPluginInfo plugin; 578 content::WebPluginInfo plugin;
587 tabstrip_->FileSupported( 579 tabstrip_->FileSupported(
588 url, 580 url,
589 mime_type.empty() || 581 mime_type.empty() ||
590 net::IsSupportedMimeType(mime_type) || 582 net::IsSupportedMimeType(mime_type) ||
591 content::PluginService::GetInstance()->GetPluginInfo( 583 content::PluginService::GetInstance()->GetPluginInfo(
592 -1, // process ID 584 -1, // process ID
593 MSG_ROUTING_NONE, // routing ID 585 MSG_ROUTING_NONE, // routing ID
594 model_->profile()->GetResourceContext(), 586 model_->profile()->GetResourceContext(),
595 url, GURL(), mime_type, false, 587 url, GURL(), mime_type, false,
596 NULL, &plugin, NULL)); 588 NULL, &plugin, NULL));
597 } 589 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698