| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/tab_strip.h" | 5 #include "chrome/browser/views/tabs/tab_strip.h" |
| 6 | 6 |
| 7 #include "base/gfx/size.h" | 7 #include "base/gfx/size.h" |
| 8 #include "chrome/app/theme/theme_resources.h" | 8 #include "chrome/app/theme/theme_resources.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/tab_contents.h" | 10 #include "chrome/browser/tab_contents.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // Figure out the desired start and end widths for the specified pre- and | 190 // Figure out the desired start and end widths for the specified pre- and |
| 191 // post- animation tab counts. | 191 // post- animation tab counts. |
| 192 void GenerateStartAndEndWidths(int start_tab_count, int end_tab_count) { | 192 void GenerateStartAndEndWidths(int start_tab_count, int end_tab_count) { |
| 193 tabstrip_->GetDesiredTabWidths(start_tab_count, &start_unselected_width_, | 193 tabstrip_->GetDesiredTabWidths(start_tab_count, &start_unselected_width_, |
| 194 &start_selected_width_); | 194 &start_selected_width_); |
| 195 double standard_tab_width = | 195 double standard_tab_width = |
| 196 static_cast<double>(TabRenderer::GetStandardSize().width()); | 196 static_cast<double>(TabRenderer::GetStandardSize().width()); |
| 197 if (start_tab_count < end_tab_count && | 197 if (start_tab_count < end_tab_count && |
| 198 start_unselected_width_ < standard_tab_width) { | 198 start_unselected_width_ < standard_tab_width) { |
| 199 double minimum_tab_width = | 199 double minimum_tab_width = |
| 200 static_cast<double>(TabRenderer::GetMinimumSize().width()); | 200 static_cast<double>(TabRenderer::GetMinimumUnselectedSize().width()); |
| 201 start_unselected_width_ -= minimum_tab_width / start_tab_count; | 201 start_unselected_width_ -= minimum_tab_width / start_tab_count; |
| 202 } | 202 } |
| 203 tabstrip_->GenerateIdealBounds(); | 203 tabstrip_->GenerateIdealBounds(); |
| 204 tabstrip_->GetDesiredTabWidths(end_tab_count, | 204 tabstrip_->GetDesiredTabWidths(end_tab_count, |
| 205 &end_unselected_width_, | 205 &end_unselected_width_, |
| 206 &end_selected_width_); | 206 &end_selected_width_); |
| 207 } | 207 } |
| 208 | 208 |
| 209 TabStrip* tabstrip_; | 209 TabStrip* tabstrip_; |
| 210 SlideAnimation animation_; | 210 SlideAnimation animation_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 240 virtual ~InsertTabAnimation() {} | 240 virtual ~InsertTabAnimation() {} |
| 241 | 241 |
| 242 protected: | 242 protected: |
| 243 // Overridden from TabStrip::TabAnimation: | 243 // Overridden from TabStrip::TabAnimation: |
| 244 virtual double GetWidthForTab(int index) const { | 244 virtual double GetWidthForTab(int index) const { |
| 245 if (index == index_) { | 245 if (index == index_) { |
| 246 bool is_selected = tabstrip_->model()->selected_index() == index; | 246 bool is_selected = tabstrip_->model()->selected_index() == index; |
| 247 double target_width = | 247 double target_width = |
| 248 is_selected ? end_unselected_width_ : end_selected_width_; | 248 is_selected ? end_unselected_width_ : end_selected_width_; |
| 249 double start_width = is_selected ? Tab::GetMinimumSelectedSize().width() : | 249 double start_width = is_selected ? Tab::GetMinimumSelectedSize().width() : |
| 250 Tab::GetMinimumSize().width(); | 250 Tab::GetMinimumUnselectedSize().width(); |
| 251 double delta = target_width - start_width; | 251 double delta = target_width - start_width; |
| 252 if (delta > 0) | 252 if (delta > 0) |
| 253 return start_width + (delta * animation_.GetCurrentValue()); | 253 return start_width + (delta * animation_.GetCurrentValue()); |
| 254 return start_width; | 254 return start_width; |
| 255 } | 255 } |
| 256 if (tabstrip_->GetTabAt(index)->IsSelected()) { | 256 if (tabstrip_->GetTabAt(index)->IsSelected()) { |
| 257 double delta = end_selected_width_ - start_selected_width_; | 257 double delta = end_selected_width_ - start_selected_width_; |
| 258 return start_selected_width_ + (delta * animation_.GetCurrentValue()); | 258 return start_selected_width_ + (delta * animation_.GetCurrentValue()); |
| 259 } | 259 } |
| 260 double delta = end_unselected_width_ - start_unselected_width_; | 260 double delta = end_unselected_width_ - start_unselected_width_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 287 | 287 |
| 288 protected: | 288 protected: |
| 289 // Overridden from TabStrip::TabAnimation: | 289 // Overridden from TabStrip::TabAnimation: |
| 290 virtual double GetWidthForTab(int index) const { | 290 virtual double GetWidthForTab(int index) const { |
| 291 Tab* tab = tabstrip_->GetTabAt(index); | 291 Tab* tab = tabstrip_->GetTabAt(index); |
| 292 if (index == index_) { | 292 if (index == index_) { |
| 293 // The tab(s) being removed are gradually shrunken depending on the state | 293 // The tab(s) being removed are gradually shrunken depending on the state |
| 294 // of the animation. | 294 // of the animation. |
| 295 // Removed animated Tabs are never selected. | 295 // Removed animated Tabs are never selected. |
| 296 double start_width = start_unselected_width_; | 296 double start_width = start_unselected_width_; |
| 297 double target_width = Tab::GetMinimumSize().width() + kTabHOffset; | 297 double target_width = |
| 298 Tab::GetMinimumUnselectedSize().width() + kTabHOffset; |
| 298 double delta = start_width - target_width; | 299 double delta = start_width - target_width; |
| 299 return start_width - (delta * animation_.GetCurrentValue()); | 300 return start_width - (delta * animation_.GetCurrentValue()); |
| 300 } | 301 } |
| 301 if (tabstrip_->available_width_for_tabs_ != -1 && | 302 if (tabstrip_->available_width_for_tabs_ != -1 && |
| 302 index_ != tabstrip_->GetTabCount() - 1) { | 303 index_ != tabstrip_->GetTabCount() - 1) { |
| 303 return TabStrip::TabAnimation::GetWidthForTab(index); | 304 return TabStrip::TabAnimation::GetWidthForTab(index); |
| 304 } | 305 } |
| 305 // All other tabs are sized according to the start/end widths specified at | 306 // All other tabs are sized according to the start/end widths specified at |
| 306 // the start of the animation. | 307 // the start of the animation. |
| 307 if (tab->IsSelected()) { | 308 if (tab->IsSelected()) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // TODO(beng): remove this if it doesn't work to fix the TabSelectedAt bug. | 502 // TODO(beng): remove this if it doesn't work to fix the TabSelectedAt bug. |
| 502 drag_controller_.reset(NULL); | 503 drag_controller_.reset(NULL); |
| 503 | 504 |
| 504 // Make sure we unhook ourselves as a message loop observer so that we don't | 505 // Make sure we unhook ourselves as a message loop observer so that we don't |
| 505 // crash in the case where the user closes the window after closing a tab | 506 // crash in the case where the user closes the window after closing a tab |
| 506 // but before moving the mouse. | 507 // but before moving the mouse. |
| 507 RemoveMessageLoopObserver(); | 508 RemoveMessageLoopObserver(); |
| 508 } | 509 } |
| 509 | 510 |
| 510 int TabStrip::GetPreferredHeight() { | 511 int TabStrip::GetPreferredHeight() { |
| 511 CSize preferred_size; | 512 return GetPreferredSize().height(); |
| 512 GetPreferredSize(&preferred_size); | |
| 513 return preferred_size.cy; | |
| 514 } | 513 } |
| 515 | 514 |
| 516 bool TabStrip::HasAvailableDragActions() const { | 515 bool TabStrip::HasAvailableDragActions() const { |
| 517 return model_->delegate()->GetDragActions() != 0; | 516 return model_->delegate()->GetDragActions() != 0; |
| 518 } | 517 } |
| 519 | 518 |
| 520 void TabStrip::ShowApplicationMenu(const gfx::Point& p) { | 519 void TabStrip::ShowApplicationMenu(const gfx::Point& p) { |
| 521 TabStripModelDelegate* delegate = model_->delegate(); | 520 TabStripModelDelegate* delegate = model_->delegate(); |
| 522 if (delegate) | 521 if (delegate) |
| 523 delegate->ShowApplicationMenu(p); | 522 delegate->ShowApplicationMenu(p); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 for (int i = 0; i < tab_count; ++i) { | 668 for (int i = 0; i < tab_count; ++i) { |
| 670 const gfx::Rect& bounds = tab_data_.at(i).ideal_bounds; | 669 const gfx::Rect& bounds = tab_data_.at(i).ideal_bounds; |
| 671 GetTabAt(i)->SetBounds(bounds.x(), bounds.y(), bounds.width(), | 670 GetTabAt(i)->SetBounds(bounds.x(), bounds.y(), bounds.width(), |
| 672 bounds.height()); | 671 bounds.height()); |
| 673 tab_right = bounds.right() + kTabHOffset; | 672 tab_right = bounds.right() + kTabHOffset; |
| 674 } | 673 } |
| 675 LayoutNewTabButton(static_cast<double>(tab_right), current_unselected_width_); | 674 LayoutNewTabButton(static_cast<double>(tab_right), current_unselected_width_); |
| 676 SchedulePaint(); | 675 SchedulePaint(); |
| 677 } | 676 } |
| 678 | 677 |
| 679 void TabStrip::GetPreferredSize(CSize* preferred_size) { | 678 gfx::Size TabStrip::GetPreferredSize() { |
| 680 DCHECK(preferred_size); | 679 return gfx::Size(0, Tab::GetMinimumUnselectedSize().height()); |
| 681 preferred_size->cx = 0; | |
| 682 preferred_size->cy = Tab::GetMinimumSize().height(); | |
| 683 } | 680 } |
| 684 | 681 |
| 685 void TabStrip::OnDragEntered(const DropTargetEvent& event) { | 682 void TabStrip::OnDragEntered(const DropTargetEvent& event) { |
| 686 UpdateDropIndex(event); | 683 UpdateDropIndex(event); |
| 687 } | 684 } |
| 688 | 685 |
| 689 int TabStrip::OnDragUpdated(const DropTargetEvent& event) { | 686 int TabStrip::OnDragUpdated(const DropTargetEvent& event) { |
| 690 UpdateDropIndex(event); | 687 UpdateDropIndex(event); |
| 691 return GetDropEffect(event); | 688 return GetDropEffect(event); |
| 692 } | 689 } |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 | 1147 |
| 1151 void TabStrip::GetCurrentTabWidths(double* unselected_width, | 1148 void TabStrip::GetCurrentTabWidths(double* unselected_width, |
| 1152 double* selected_width) const { | 1149 double* selected_width) const { |
| 1153 *unselected_width = current_unselected_width_; | 1150 *unselected_width = current_unselected_width_; |
| 1154 *selected_width = current_selected_width_; | 1151 *selected_width = current_selected_width_; |
| 1155 } | 1152 } |
| 1156 | 1153 |
| 1157 void TabStrip::GetDesiredTabWidths(int tab_count, | 1154 void TabStrip::GetDesiredTabWidths(int tab_count, |
| 1158 double* unselected_width, | 1155 double* unselected_width, |
| 1159 double* selected_width) const { | 1156 double* selected_width) const { |
| 1160 const double min_unselected_width = Tab::GetMinimumSize().width(); | 1157 const double min_unselected_width = Tab::GetMinimumUnselectedSize().width(); |
| 1161 const double min_selected_width = Tab::GetMinimumSelectedSize().width(); | 1158 const double min_selected_width = Tab::GetMinimumSelectedSize().width(); |
| 1162 if (tab_count == 0) { | 1159 if (tab_count == 0) { |
| 1163 // Return immediately to avoid divide-by-zero below. | 1160 // Return immediately to avoid divide-by-zero below. |
| 1164 *unselected_width = min_unselected_width; | 1161 *unselected_width = min_unselected_width; |
| 1165 *selected_width = min_selected_width; | 1162 *selected_width = min_selected_width; |
| 1166 return; | 1163 return; |
| 1167 } | 1164 } |
| 1168 | 1165 |
| 1169 // Determine how much space we can actually allocate to tabs. | 1166 // Determine how much space we can actually allocate to tabs. |
| 1170 int available_width; | 1167 int available_width; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 return last_tab->x() + last_tab->width(); | 1563 return last_tab->x() + last_tab->width(); |
| 1567 } | 1564 } |
| 1568 | 1565 |
| 1569 bool TabStrip::IsPointInTab(Tab* tab, | 1566 bool TabStrip::IsPointInTab(Tab* tab, |
| 1570 const gfx::Point& point_in_tabstrip_coords) { | 1567 const gfx::Point& point_in_tabstrip_coords) { |
| 1571 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 1568 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
| 1572 View::ConvertPointToView(this, tab, &point_in_tab_coords); | 1569 View::ConvertPointToView(this, tab, &point_in_tab_coords); |
| 1573 return tab->HitTest(point_in_tab_coords); | 1570 return tab->HitTest(point_in_tab_coords); |
| 1574 } | 1571 } |
| 1575 | 1572 |
| OLD | NEW |