1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
#pragma once
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/hover_tab_selector.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class BaseTab;
class Browser;
class TabStrip;
class TabStripSelectionModel;
struct TabRendererData;
// An implementation of TabStripController that sources data from the
// TabContentsWrappers in a TabStripModel.
class BrowserTabStripController : public TabStripController,
public TabStripModelObserver,
public content::NotificationObserver {
public:
BrowserTabStripController(Browser* browser, TabStripModel* model);
virtual ~BrowserTabStripController();
void InitFromModel(TabStrip* tabstrip);
TabStripModel* model() const { return model_; }
bool IsCommandEnabledForTab(TabStripModel::ContextMenuCommand command_id,
BaseTab* tab) const;
void ExecuteCommandForTab(TabStripModel::ContextMenuCommand command_id,
BaseTab* tab);
bool IsTabPinned(BaseTab* tab) const;
// TabStripController implementation:
virtual const TabStripSelectionModel& GetSelectionModel() OVERRIDE;
virtual int GetCount() const OVERRIDE;
virtual bool IsValidIndex(int model_index) const OVERRIDE;
virtual bool IsActiveTab(int model_index) const OVERRIDE;
virtual bool IsTabSelected(int model_index) const OVERRIDE;
virtual bool IsTabPinned(int model_index) const OVERRIDE;
virtual bool IsTabCloseable(int model_index) const OVERRIDE;
virtual bool IsNewTabPage(int model_index) const OVERRIDE;
virtual void SelectTab(int model_index) OVERRIDE;
virtual void ExtendSelectionTo(int model_index) OVERRIDE;
virtual void ToggleSelected(int model_index) OVERRIDE;
virtual void AddSelectionFromAnchorTo(int model_index) OVERRIDE;
virtual void CloseTab(int model_index) OVERRIDE;
virtual void ShowContextMenuForTab(BaseTab* tab,
const gfx::Point& p) OVERRIDE;
virtual void UpdateLoadingAnimations() OVERRIDE;
virtual int HasAvailableDragActions() const OVERRIDE;
virtual void OnDropIndexUpdate(int index, bool drop_before) OVERRIDE;
virtual void PerformDrop(bool drop_before,
int index,
const GURL& url) OVERRIDE;
virtual bool IsCompatibleWith(TabStrip* other) const OVERRIDE;
virtual void CreateNewTab() OVERRIDE;
virtual void ClickActiveTab(int index) OVERRIDE;
// TabStripModelObserver implementation:
virtual void TabInsertedAt(TabContentsWrapper* contents,
int model_index,
bool active) OVERRIDE;
virtual void TabDetachedAt(TabContentsWrapper* contents,
int model_index) OVERRIDE;
virtual void TabSelectionChanged(
TabStripModel* tab_strip_model,
const TabStripSelectionModel& old_model) OVERRIDE;
virtual void TabMoved(TabContentsWrapper* contents,
int from_model_index,
int to_model_index) OVERRIDE;
virtual void TabChangedAt(TabContentsWrapper* contents,
int model_index,
TabChangeType change_type) OVERRIDE;
virtual void TabReplacedAt(TabStripModel* tab_strip_model,
TabContentsWrapper* old_contents,
TabContentsWrapper* new_contents,
int model_index) OVERRIDE;
virtual void TabPinnedStateChanged(TabContentsWrapper* contents,
int model_index) OVERRIDE;
virtual void TabMiniStateChanged(TabContentsWrapper* contents,
int model_index) OVERRIDE;
virtual void TabBlockedStateChanged(TabContentsWrapper* contents,
int model_index) OVERRIDE;
// content::NotificationObserver implementation:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
protected:
// The context in which SetTabRendererDataFromModel is being called.
enum TabStatus {
NEW_TAB,
EXISTING_TAB
};
// Sets the TabRendererData from the TabStripModel.
virtual void SetTabRendererDataFromModel(TabContents* contents,
int model_index,
TabRendererData* data,
TabStatus tab_status);
Profile* profile() const { return model_->profile(); }
const TabStrip* tabstrip() const { return tabstrip_; }
const Browser* browser() const { return browser_; }
private:
class TabContextMenuContents;
// Invokes tabstrip_->SetTabData.
void SetTabDataAt(TabContentsWrapper* contents, int model_index);
void StartHighlightTabsForCommand(
TabStripModel::ContextMenuCommand command_id,
BaseTab* tab);
void StopHighlightTabsForCommand(
TabStripModel::ContextMenuCommand command_id,
BaseTab* tab);
TabStripModel* model_;
TabStrip* tabstrip_;
// Non-owning pointer to the browser which is using this controller.
Browser* browser_;
// If non-NULL it means we're showing a menu for the tab.
scoped_ptr<TabContextMenuContents> context_menu_contents_;
content::NotificationRegistrar notification_registrar_;
// Helper for performing tab selection as a result of dragging over a tab.
HoverTabSelector hover_tab_selector_;
DISALLOW_COPY_AND_ASSIGN(BrowserTabStripController);
};
#endif // CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
|