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
|
// 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 "app/gfx/canvas.h"
#include "base/command_line.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 "chrome/common/pref_service.h"
namespace {
const int kVerticalTabSpacing = 2;
const int kTabStripWidth = 127;
}
////////////////////////////////////////////////////////////////////////////////
// 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));
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, BaseTabStrip implementation:
int SideTabStrip::GetPreferredHeight() {
return 0;
}
void SideTabStrip::SetBackgroundOffset(const gfx::Point& offset) {
}
bool SideTabStrip::IsPositionInWindowCaption(const gfx::Point& point) {
return true;
}
void SideTabStrip::SetDraggedTabBounds(int tab_index,
const gfx::Rect& tab_bounds) {
}
bool SideTabStrip::IsDragSessionActive() const {
return false;
}
void SideTabStrip::UpdateLoadingAnimations() {
}
bool SideTabStrip::IsAnimating() const {
return false;
}
TabStrip* SideTabStrip::AsTabStrip() {
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, views::View overrides:
void SideTabStrip::Layout() {
int y = 0;
for (int c = GetChildViewCount(), i = 0; i < c; ++i) {
views::View* child = GetChildViewAt(i);
child->SetBounds(0, y, width(), child->GetPreferredSize().height());
y = child->bounds().bottom() + kVerticalTabSpacing;
}
}
void SideTabStrip::Paint(gfx::Canvas* canvas) {
// canvas->FillRectInt(SK_ColorGREEN, 0, 0, width(), height());
}
gfx::Size SideTabStrip::GetPreferredSize() {
return gfx::Size(kTabStripWidth, 0);
}
////////////////////////////////////////////////////////////////////////////////
// SideTabStrip, private:
int SideTabStrip::GetIndexOfSideTab(SideTab* tab) const {
return GetChildIndex(tab);
}
|