OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/views/tabs/side_tab_strip.h" | 5 #include "chrome/browser/views/tabs/side_tab_strip.h" |
6 | 6 |
7 #include "chrome/browser/views/tabs/side_tab.h" | 7 #include "chrome/browser/views/tabs/side_tab.h" |
8 #include "chrome/browser/view_ids.h" | 8 #include "chrome/browser/view_ids.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 const int kVerticalTabSpacing = 2; | 11 const int kVerticalTabSpacing = 2; |
12 const int kTabStripWidth = 140; | 12 const int kTabStripWidth = 140; |
13 const int kTabStripInset = 3; | 13 const int kTabStripInset = 3; |
14 } | 14 } |
15 | 15 |
16 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
17 // SideTabStrip, public: | 17 // SideTabStrip, public: |
18 | 18 |
19 SideTabStrip::SideTabStrip(TabStripController* controller) | 19 SideTabStrip::SideTabStrip(TabStripController* controller) |
20 : BaseTabStrip(controller) { | 20 : BaseTabStrip(controller, BaseTabStrip::VERTICAL_TAB_STRIP) { |
21 SetID(VIEW_ID_TAB_STRIP); | 21 SetID(VIEW_ID_TAB_STRIP); |
22 } | 22 } |
23 | 23 |
24 SideTabStrip::~SideTabStrip() { | 24 SideTabStrip::~SideTabStrip() { |
| 25 DestroyDragController(); |
25 } | 26 } |
26 | 27 |
27 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
28 // SideTabStrip, BaseTabStrip implementation: | 29 // SideTabStrip, BaseTabStrip implementation: |
29 | 30 |
30 int SideTabStrip::GetPreferredHeight() { | 31 int SideTabStrip::GetPreferredHeight() { |
31 return 0; | 32 return 0; |
32 } | 33 } |
33 | 34 |
34 void SideTabStrip::SetBackgroundOffset(const gfx::Point& offset) { | 35 void SideTabStrip::SetBackgroundOffset(const gfx::Point& offset) { |
35 } | 36 } |
36 | 37 |
37 bool SideTabStrip::IsPositionInWindowCaption(const gfx::Point& point) { | 38 bool SideTabStrip::IsPositionInWindowCaption(const gfx::Point& point) { |
38 return GetViewForPoint(point) == this; | 39 return GetViewForPoint(point) == this; |
39 } | 40 } |
40 | 41 |
41 void SideTabStrip::SetDraggedTabBounds(int tab_index, | 42 void SideTabStrip::SetDraggedTabBounds(int tab_index, |
42 const gfx::Rect& tab_bounds) { | 43 const gfx::Rect& tab_bounds) { |
43 } | 44 } |
44 | 45 |
45 bool SideTabStrip::IsDragSessionActive() const { | |
46 return false; | |
47 } | |
48 | |
49 bool SideTabStrip::IsAnimating() const { | 46 bool SideTabStrip::IsAnimating() const { |
50 return false; | 47 return false; |
51 } | 48 } |
52 | 49 |
53 TabStrip* SideTabStrip::AsTabStrip() { | 50 TabStrip* SideTabStrip::AsTabStrip() { |
54 return NULL; | 51 return NULL; |
55 } | 52 } |
56 | 53 |
57 void SideTabStrip::StartHighlight(int model_index) { | 54 void SideTabStrip::StartHighlight(int model_index) { |
58 } | 55 } |
59 | 56 |
60 void SideTabStrip::StopAllHighlighting() { | 57 void SideTabStrip::StopAllHighlighting() { |
61 } | 58 } |
62 | 59 |
63 BaseTabRenderer* SideTabStrip::GetBaseTabAtModelIndex(int model_index) const { | 60 BaseTabRenderer* SideTabStrip::GetBaseTabAtModelIndex(int model_index) const { |
64 return static_cast<BaseTabRenderer*>(GetChildViewAt(model_index)); | 61 return static_cast<BaseTabRenderer*>(GetChildViewAt(model_index)); |
65 } | 62 } |
66 | 63 |
67 BaseTabRenderer* SideTabStrip::GetBaseTabAtTabIndex(int tab_index) const { | |
68 return static_cast<BaseTabRenderer*>(GetChildViewAt(tab_index)); | |
69 } | |
70 | |
71 int SideTabStrip::GetTabCount() const { | |
72 return GetChildViewCount(); | |
73 } | |
74 | |
75 BaseTabRenderer* SideTabStrip::CreateTabForDragging() { | 64 BaseTabRenderer* SideTabStrip::CreateTabForDragging() { |
76 return new SideTab(NULL); | 65 return new SideTab(NULL); |
77 } | 66 } |
78 | 67 |
79 int SideTabStrip::GetModelIndexOfBaseTab(const BaseTabRenderer* tab) const { | |
80 return GetChildIndex(tab); | |
81 } | |
82 | |
83 void SideTabStrip::AddTabAt(int model_index, | |
84 bool foreground, | |
85 const TabRendererData& data) { | |
86 SideTab* tab = new SideTab(this); | |
87 AddChildView(tab); | |
88 Layout(); | |
89 } | |
90 | |
91 void SideTabStrip::RemoveTabAt(int index, bool initiated_close) { | 68 void SideTabStrip::RemoveTabAt(int index, bool initiated_close) { |
92 View* v = GetChildViewAt(index); | 69 View* v = GetChildViewAt(index); |
93 RemoveChildView(v); | 70 RemoveChildView(v); |
94 delete v; | 71 delete v; |
95 Layout(); | 72 Layout(); |
96 } | 73 } |
97 | 74 |
98 void SideTabStrip::SelectTabAt(int old_model_index, int new_model_index) { | 75 void SideTabStrip::SelectTabAt(int old_model_index, int new_model_index) { |
99 GetChildViewAt(new_model_index)->SchedulePaint(); | 76 GetChildViewAt(new_model_index)->SchedulePaint(); |
100 } | 77 } |
101 | 78 |
102 void SideTabStrip::MoveTab(int from_model_index, int to_model_index) { | |
103 } | |
104 | |
105 void SideTabStrip::TabTitleChangedNotLoading(int model_index) { | 79 void SideTabStrip::TabTitleChangedNotLoading(int model_index) { |
106 } | 80 } |
107 | 81 |
108 void SideTabStrip::SetTabData(int model_index, const TabRendererData& data) { | 82 void SideTabStrip::SetTabData(int model_index, const TabRendererData& data) { |
109 } | 83 BaseTabRenderer* tab = GetBaseTabAtModelIndex(model_index); |
110 | 84 tab->SetData(data); |
111 void SideTabStrip::MaybeStartDrag(BaseTabRenderer* tab, | 85 tab->SchedulePaint(); |
112 const views::MouseEvent& event) { | |
113 } | |
114 | |
115 void SideTabStrip::ContinueDrag(const views::MouseEvent& event) { | |
116 } | |
117 | |
118 bool SideTabStrip::EndDrag(bool canceled) { | |
119 return false; | |
120 } | |
121 | |
122 //////////////////////////////////////////////////////////////////////////////// | |
123 // SideTabStrip, views::View overrides: | |
124 | |
125 void SideTabStrip::Layout() { | |
126 gfx::Rect layout_rect = GetLocalBounds(false); | |
127 layout_rect.Inset(kTabStripInset, kTabStripInset); | |
128 int y = layout_rect.y(); | |
129 for (int c = GetChildViewCount(), i = 0; i < c; ++i) { | |
130 views::View* child = GetChildViewAt(i); | |
131 child->SetBounds(layout_rect.x(), y, layout_rect.width(), | |
132 child->GetPreferredSize().height()); | |
133 y = child->bounds().bottom() + kVerticalTabSpacing; | |
134 } | |
135 } | 86 } |
136 | 87 |
137 gfx::Size SideTabStrip::GetPreferredSize() { | 88 gfx::Size SideTabStrip::GetPreferredSize() { |
138 return gfx::Size(kTabStripWidth, 0); | 89 return gfx::Size(kTabStripWidth, 0); |
139 } | 90 } |
| 91 |
| 92 BaseTabRenderer* SideTabStrip::CreateTab() { |
| 93 return new SideTab(this); |
| 94 } |
| 95 |
| 96 void SideTabStrip::GenerateIdealBounds() { |
| 97 gfx::Rect layout_rect = GetLocalBounds(false); |
| 98 layout_rect.Inset(kTabStripInset, kTabStripInset); |
| 99 |
| 100 int y = layout_rect.y(); |
| 101 for (int i = 0; i < tab_count(); ++i) { |
| 102 BaseTabRenderer* tab = base_tab_at_tab_index(i); |
| 103 if (!tab->closing()) { |
| 104 gfx::Rect bounds = gfx::Rect(layout_rect.x(), y, layout_rect.width(), |
| 105 tab->GetPreferredSize().height()); |
| 106 set_ideal_bounds(i, bounds); |
| 107 y = bounds.bottom() + kVerticalTabSpacing; |
| 108 } |
| 109 } |
| 110 } |
| 111 |
| 112 void SideTabStrip::StartInsertTabAnimation(int model_index, bool foreground) { |
| 113 Layout(); |
| 114 } |
| 115 |
| 116 void SideTabStrip::StartMoveTabAnimation() { |
| 117 Layout(); |
| 118 } |
| 119 |
| 120 void SideTabStrip::StopAnimating(bool layout) { |
| 121 } |
OLD | NEW |