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 TabMiniStateChanged(content::WebContents
* contents
,
98 int model_index
) override
;
99 void TabBlockedStateChanged(content::WebContents
* contents
,
100 int model_index
) override
;
103 // The context in which SetTabRendererDataFromModel is being called.
109 // Sets the TabRendererData from the TabStripModel.
110 virtual void SetTabRendererDataFromModel(content::WebContents
* contents
,
112 TabRendererData
* data
,
113 TabStatus tab_status
);
115 Profile
* profile() const { return model_
->profile(); }
117 const TabStrip
* tabstrip() const { return tabstrip_
; }
119 const Browser
* browser() const { return browser_
; }
122 class TabContextMenuContents
;
124 // Invokes tabstrip_->SetTabData.
125 void SetTabDataAt(content::WebContents
* web_contents
, int model_index
);
127 void StartHighlightTabsForCommand(
128 TabStripModel::ContextMenuCommand command_id
,
130 void StopHighlightTabsForCommand(
131 TabStripModel::ContextMenuCommand command_id
,
135 void AddTab(content::WebContents
* contents
, int index
, bool is_active
);
137 // Resets the tabstrips stacked layout (true or false) from prefs.
138 void UpdateStackedLayout();
140 // Notifies the tabstrip whether |url| is supported once a MIME type request
142 void OnFindURLMimeTypeCompleted(const GURL
& url
,
143 const std::string
& mime_type
);
145 TabStripModel
* model_
;
149 // Non-owning pointer to the browser which is using this controller.
152 // If non-NULL it means we're showing a menu for the tab.
153 scoped_ptr
<TabContextMenuContents
> context_menu_contents_
;
155 // Helper for performing tab selection as a result of dragging over a tab.
156 HoverTabSelector hover_tab_selector_
;
158 // Forces the tabs to use the regular (non-immersive) style and the
159 // top-of-window views to be revealed when the user is dragging |tabstrip|'s
161 scoped_ptr
<ImmersiveRevealedLock
> immersive_reveal_lock_
;
163 PrefChangeRegistrar local_pref_registrar_
;
165 base::WeakPtrFactory
<BrowserTabStripController
> weak_ptr_factory_
;
167 DISALLOW_COPY_AND_ASSIGN(BrowserTabStripController
);
170 #endif // CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_