Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / tabs / browser_tab_strip_controller.h
blob15d1621382d00309b9b7e79cd1edaaaff0ae0ed3
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"
16 class Browser;
17 class Tab;
18 class TabStrip;
19 struct TabRendererData;
21 namespace content {
22 class WebContents;
25 namespace ui {
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 {
33 public:
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,
42 Tab* tab) const;
43 void ExecuteCommandForTab(TabStripModel::ContextMenuCommand command_id,
44 Tab* tab);
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,
63 const gfx::Point& p,
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,
80 int model_index,
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,
86 int from_model_index,
87 int to_model_index) override;
88 void TabChangedAt(content::WebContents* contents,
89 int model_index,
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;
102 protected:
103 // The context in which SetTabRendererDataFromModel is being called.
104 enum TabStatus {
105 NEW_TAB,
106 EXISTING_TAB
109 // Sets the TabRendererData from the TabStripModel.
110 virtual void SetTabRendererDataFromModel(content::WebContents* contents,
111 int model_index,
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_; }
121 private:
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,
129 Tab* tab);
130 void StopHighlightTabsForCommand(
131 TabStripModel::ContextMenuCommand command_id,
132 Tab* tab);
134 // Adds a tab.
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
141 // has completed.
142 void OnFindURLMimeTypeCompleted(const GURL& url,
143 const std::string& mime_type);
145 TabStripModel* model_;
147 TabStrip* tabstrip_;
149 // Non-owning pointer to the browser which is using this controller.
150 Browser* browser_;
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
160 // tabs.
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_