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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_change_registrar.h"
11 #include "chrome/browser/ui/tabs/hover_tab_selector.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
14 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
19 struct TabRendererData
;
26 class ListSelectionModel
;
29 // An implementation of TabStripController that sources data from the
30 // WebContentses in a TabStripModel.
31 class BrowserTabStripController
: public TabStripController
,
32 public TabStripModelObserver
{
34 BrowserTabStripController(Browser
* browser
, TabStripModel
* model
);
35 ~BrowserTabStripController() override
;
37 void InitFromModel(TabStrip
* tabstrip
);
39 TabStripModel
* model() const { return model_
; }
41 bool IsCommandEnabledForTab(TabStripModel::ContextMenuCommand command_id
,
43 void ExecuteCommandForTab(TabStripModel::ContextMenuCommand command_id
,
45 bool IsTabPinned(Tab
* tab
) const;
47 // TabStripController implementation:
48 const ui::ListSelectionModel
& GetSelectionModel() override
;
49 int GetCount() const override
;
50 bool IsValidIndex(int model_index
) const override
;
51 bool IsActiveTab(int model_index
) const override
;
52 int GetActiveIndex() const override
;
53 bool IsTabSelected(int model_index
) const override
;
54 bool IsTabPinned(int model_index
) const override
;
55 bool IsNewTabPage(int model_index
) const override
;
56 void SelectTab(int model_index
) override
;
57 void ExtendSelectionTo(int model_index
) override
;
58 void ToggleSelected(int model_index
) override
;
59 void AddSelectionFromAnchorTo(int model_index
) override
;
60 void CloseTab(int model_index
, CloseTabSource source
) override
;
61 void ToggleTabAudioMute(int model_index
) override
;
62 void ShowContextMenuForTab(Tab
* tab
,
64 ui::MenuSourceType source_type
) override
;
65 void UpdateLoadingAnimations() override
;
66 int HasAvailableDragActions() const override
;
67 void OnDropIndexUpdate(int index
, bool drop_before
) override
;
68 void PerformDrop(bool drop_before
, int index
, const GURL
& url
) override
;
69 bool IsCompatibleWith(TabStrip
* other
) const override
;
70 void CreateNewTab() override
;
71 void CreateNewTabWithLocation(const base::string16
& loc
) override
;
72 bool IsIncognito() override
;
73 void StackedLayoutMaybeChanged() override
;
74 void OnStartedDraggingTabs() override
;
75 void OnStoppedDraggingTabs() override
;
76 void CheckFileSupported(const GURL
& url
) override
;
78 // TabStripModelObserver implementation:
79 void TabInsertedAt(content::WebContents
* contents
,
81 bool is_active
) override
;
82 void TabDetachedAt(content::WebContents
* contents
, int model_index
) override
;
83 void TabSelectionChanged(TabStripModel
* tab_strip_model
,
84 const ui::ListSelectionModel
& old_model
) override
;
85 void TabMoved(content::WebContents
* contents
,
87 int to_model_index
) override
;
88 void TabChangedAt(content::WebContents
* contents
,
90 TabChangeType change_type
) override
;
91 void TabReplacedAt(TabStripModel
* tab_strip_model
,
92 content::WebContents
* old_contents
,
93 content::WebContents
* new_contents
,
94 int model_index
) override
;
95 void TabPinnedStateChanged(content::WebContents
* contents
,
96 int model_index
) override
;
97 void TabBlockedStateChanged(content::WebContents
* contents
,
98 int model_index
) override
;
101 // The context in which SetTabRendererDataFromModel is being called.
107 // Sets the TabRendererData from the TabStripModel.
108 virtual void SetTabRendererDataFromModel(content::WebContents
* contents
,
110 TabRendererData
* data
,
111 TabStatus tab_status
);
113 Profile
* profile() const { return model_
->profile(); }
115 const TabStrip
* tabstrip() const { return tabstrip_
; }
117 const Browser
* browser() const { return browser_
; }
120 class TabContextMenuContents
;
122 // Invokes tabstrip_->SetTabData.
123 void SetTabDataAt(content::WebContents
* web_contents
, int model_index
);
125 void StartHighlightTabsForCommand(
126 TabStripModel::ContextMenuCommand command_id
,
128 void StopHighlightTabsForCommand(
129 TabStripModel::ContextMenuCommand command_id
,
133 void AddTab(content::WebContents
* contents
, int index
, bool is_active
);
135 // Resets the tabstrips stacked layout (true or false) from prefs.
136 void UpdateStackedLayout();
138 // Notifies the tabstrip whether |url| is supported once a MIME type request
140 void OnFindURLMimeTypeCompleted(const GURL
& url
,
141 const std::string
& mime_type
);
143 TabStripModel
* model_
;
147 // Non-owning pointer to the browser which is using this controller.
150 // If non-NULL it means we're showing a menu for the tab.
151 scoped_ptr
<TabContextMenuContents
> context_menu_contents_
;
153 // Helper for performing tab selection as a result of dragging over a tab.
154 HoverTabSelector hover_tab_selector_
;
156 // Forces the tabs to use the regular (non-immersive) style and the
157 // top-of-window views to be revealed when the user is dragging |tabstrip|'s
159 scoped_ptr
<ImmersiveRevealedLock
> immersive_reveal_lock_
;
161 PrefChangeRegistrar local_pref_registrar_
;
163 base::WeakPtrFactory
<BrowserTabStripController
> weak_ptr_factory_
;
165 DISALLOW_COPY_AND_ASSIGN(BrowserTabStripController
);
168 #endif // CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_