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
151
152
153
154
155
|
// Copyright (c) 2010 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.
#include "chrome/browser/views/tabs/side_tab_strip.h"
#include "base/command_line.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/view_ids.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "gfx/canvas.h"
namespace {
const int kVerticalTabSpacing = 2;
const int kTabStripWidth = 140;
const int kTabStripInset = 3;
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, public:
SideTabStrip::SideTabStrip() {
SetID(VIEW_ID_TAB_STRIP);
}
SideTabStrip::~SideTabStrip() {
}
void SideTabStrip::SetModel(SideTabStripModel* model) {
model_.reset(model);
}
// static
bool SideTabStrip::Available() {
return CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableVerticalTabs);
}
// static
bool SideTabStrip::Visible(Profile* profile) {
return Available() &&
profile->GetPrefs()->GetBoolean(prefs::kUseVerticalTabs);
}
void SideTabStrip::AddTabAt(int index) {
SideTab* tab = new SideTab(this);
AddChildView(tab);
Layout();
}
void SideTabStrip::RemoveTabAt(int index) {
View* v = GetChildViewAt(index);
RemoveChildView(v);
delete v;
Layout();
}
void SideTabStrip::SelectTabAt(int index) {
GetChildViewAt(index)->SchedulePaint();
}
void SideTabStrip::UpdateTabAt(int index) {
GetChildViewAt(index)->SchedulePaint();
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, SideTabModel implementation:
string16 SideTabStrip::GetTitle(SideTab* tab) const {
return model_->GetTitle(GetIndexOfSideTab(tab));
}
SkBitmap SideTabStrip::GetIcon(SideTab* tab) const {
return model_->GetIcon(GetIndexOfSideTab(tab));
}
bool SideTabStrip::IsSelected(SideTab* tab) const {
return model_->IsSelected(GetIndexOfSideTab(tab));
}
void SideTabStrip::SelectTab(SideTab* tab) {
model_->SelectTab(GetIndexOfSideTab(tab));
}
void SideTabStrip::CloseTab(SideTab* tab) {
model_->CloseTab(GetIndexOfSideTab(tab));
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, BaseTabStrip implementation:
int SideTabStrip::GetPreferredHeight() {
return 0;
}
void SideTabStrip::SetBackgroundOffset(const gfx::Point& offset) {
}
bool SideTabStrip::IsPositionInWindowCaption(const gfx::Point& point) {
return GetViewForPoint(point) == this;
}
void SideTabStrip::SetDraggedTabBounds(int tab_index,
const gfx::Rect& tab_bounds) {
}
bool SideTabStrip::IsDragSessionActive() const {
return false;
}
void SideTabStrip::UpdateLoadingAnimations() {
int count = GetChildViewCount();
for (int i = 0; i < count; ++i)
GetSideTabAt(i)->SetNetworkState(model_->GetNetworkState(i));
}
bool SideTabStrip::IsAnimating() const {
return false;
}
TabStrip* SideTabStrip::AsTabStrip() {
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, views::View overrides:
void SideTabStrip::Layout() {
gfx::Rect layout_rect = GetLocalBounds(false);
layout_rect.Inset(kTabStripInset, kTabStripInset);
int y = layout_rect.y();
for (int c = GetChildViewCount(), i = 0; i < c; ++i) {
views::View* child = GetChildViewAt(i);
child->SetBounds(layout_rect.x(), y, layout_rect.width(),
child->GetPreferredSize().height());
y = child->bounds().bottom() + kVerticalTabSpacing;
}
}
gfx::Size SideTabStrip::GetPreferredSize() {
return gfx::Size(kTabStripWidth, 0);
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, private:
int SideTabStrip::GetIndexOfSideTab(SideTab* tab) const {
return GetChildIndex(tab);
}
SideTab* SideTabStrip::GetSideTabAt(int index) const {
return static_cast<SideTab*>(GetChildViewAt(index));
}
|