Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/tabs/tab_strip_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | |
| 8 | 9 |
| 9 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete.h" | 13 #include "chrome/browser/autocomplete/autocomplete.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 14 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 15 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/tabs/tab_strip_model_delegate.h" | 17 #include "chrome/browser/tabs/tab_strip_model_delegate.h" |
| 17 #include "chrome/browser/themes/theme_service.h" | 18 #include "chrome/browser/themes/theme_service.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_navigator.h" | 20 #include "chrome/browser/ui/browser_navigator.h" |
| 20 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 21 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 21 #include "chrome/browser/ui/gtk/custom_button.h" | 22 #include "chrome/browser/ui/gtk/custom_button.h" |
| 22 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 23 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 23 #include "chrome/browser/ui/gtk/gtk_util.h" | 24 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 24 #include "chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h" | 25 #include "chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h" |
| 26 #include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h" | |
| 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 26 #include "content/browser/tab_contents/tab_contents.h" | 28 #include "content/browser/tab_contents/tab_contents.h" |
| 27 #include "content/common/notification_service.h" | 29 #include "content/common/notification_service.h" |
| 28 #include "content/common/notification_type.h" | 30 #include "content/common/notification_type.h" |
| 29 #include "grit/app_resources.h" | 31 #include "grit/app_resources.h" |
| 30 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 31 #include "grit/theme_resources_standard.h" | 33 #include "grit/theme_resources_standard.h" |
| 32 #include "ui/base/animation/animation_delegate.h" | 34 #include "ui/base/animation/animation_delegate.h" |
| 33 #include "ui/base/animation/slide_animation.h" | 35 #include "ui/base/animation/slide_animation.h" |
| 34 #include "ui/base/dragdrop/gtk_dnd_util.h" | 36 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 static double GetCurrentTabWidth(TabStripGtk* tabstrip, | 163 static double GetCurrentTabWidth(TabStripGtk* tabstrip, |
| 162 TabStripGtk::TabAnimation* animation, | 164 TabStripGtk::TabAnimation* animation, |
| 163 int index) { | 165 int index) { |
| 164 TabGtk* tab = tabstrip->GetTabAt(index); | 166 TabGtk* tab = tabstrip->GetTabAt(index); |
| 165 double tab_width; | 167 double tab_width; |
| 166 if (tab->mini()) { | 168 if (tab->mini()) { |
| 167 tab_width = TabGtk::GetMiniWidth(); | 169 tab_width = TabGtk::GetMiniWidth(); |
| 168 } else { | 170 } else { |
| 169 double unselected, selected; | 171 double unselected, selected; |
| 170 tabstrip->GetCurrentTabWidths(&unselected, &selected); | 172 tabstrip->GetCurrentTabWidths(&unselected, &selected); |
| 171 tab_width = tab->IsSelected() ? selected : unselected; | 173 tab_width = tab->IsActive() ? selected : unselected; |
| 172 } | 174 } |
| 173 | 175 |
| 174 if (animation) { | 176 if (animation) { |
| 175 double specified_tab_width = animation->GetWidthForTab(index); | 177 double specified_tab_width = animation->GetWidthForTab(index); |
| 176 if (specified_tab_width != -1) | 178 if (specified_tab_width != -1) |
| 177 tab_width = specified_tab_width; | 179 tab_width = specified_tab_width; |
| 178 } | 180 } |
| 179 | 181 |
| 180 return tab_width; | 182 return tab_width; |
| 181 } | 183 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 double delta = target_width - start_width; | 297 double delta = target_width - start_width; |
| 296 if (delta > 0) | 298 if (delta > 0) |
| 297 return start_width + (delta * animation_.GetCurrentValue()); | 299 return start_width + (delta * animation_.GetCurrentValue()); |
| 298 | 300 |
| 299 return start_width; | 301 return start_width; |
| 300 } | 302 } |
| 301 | 303 |
| 302 if (tabstrip_->GetTabAt(index)->mini()) | 304 if (tabstrip_->GetTabAt(index)->mini()) |
| 303 return TabGtk::GetMiniWidth(); | 305 return TabGtk::GetMiniWidth(); |
| 304 | 306 |
| 305 if (tabstrip_->GetTabAt(index)->IsSelected()) { | 307 if (tabstrip_->GetTabAt(index)->IsActive()) { |
| 306 double delta = end_selected_width_ - start_selected_width_; | 308 double delta = end_selected_width_ - start_selected_width_; |
| 307 return start_selected_width_ + (delta * animation_.GetCurrentValue()); | 309 return start_selected_width_ + (delta * animation_.GetCurrentValue()); |
| 308 } | 310 } |
| 309 | 311 |
| 310 double delta = end_unselected_width_ - start_unselected_width_; | 312 double delta = end_unselected_width_ - start_unselected_width_; |
| 311 return start_unselected_width_ + (delta * animation_.GetCurrentValue()); | 313 return start_unselected_width_ + (delta * animation_.GetCurrentValue()); |
| 312 } | 314 } |
| 313 | 315 |
| 314 private: | 316 private: |
| 315 int index_; | 317 int index_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 if (tab->mini()) | 378 if (tab->mini()) |
| 377 return TabGtk::GetMiniWidth(); | 379 return TabGtk::GetMiniWidth(); |
| 378 | 380 |
| 379 if (tabstrip_->available_width_for_tabs_ != -1 && | 381 if (tabstrip_->available_width_for_tabs_ != -1 && |
| 380 index_ != tabstrip_->GetTabCount() - 1) { | 382 index_ != tabstrip_->GetTabCount() - 1) { |
| 381 return TabStripGtk::TabAnimation::GetWidthForTab(index); | 383 return TabStripGtk::TabAnimation::GetWidthForTab(index); |
| 382 } | 384 } |
| 383 | 385 |
| 384 // All other tabs are sized according to the start/end widths specified at | 386 // All other tabs are sized according to the start/end widths specified at |
| 385 // the start of the animation. | 387 // the start of the animation. |
| 386 if (tab->IsSelected()) { | 388 if (tab->IsActive()) { |
| 387 double delta = end_selected_width_ - start_selected_width_; | 389 double delta = end_selected_width_ - start_selected_width_; |
| 388 return start_selected_width_ + (delta * animation_.GetCurrentValue()); | 390 return start_selected_width_ + (delta * animation_.GetCurrentValue()); |
| 389 } | 391 } |
| 390 | 392 |
| 391 double delta = end_unselected_width_ - start_unselected_width_; | 393 double delta = end_unselected_width_ - start_unselected_width_; |
| 392 return start_unselected_width_ + (delta * animation_.GetCurrentValue()); | 394 return start_unselected_width_ + (delta * animation_.GetCurrentValue()); |
| 393 } | 395 } |
| 394 | 396 |
| 395 virtual void AnimationEnded(const ui::Animation* animation) { | 397 virtual void AnimationEnded(const ui::Animation* animation) { |
| 396 tabstrip_->RemoveTabAt(index_); | 398 tabstrip_->RemoveTabAt(index_); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 virtual int GetDuration() const { | 486 virtual int GetDuration() const { |
| 485 return kResizeLayoutAnimationDurationMs; | 487 return kResizeLayoutAnimationDurationMs; |
| 486 } | 488 } |
| 487 | 489 |
| 488 virtual double GetWidthForTab(int index) const { | 490 virtual double GetWidthForTab(int index) const { |
| 489 TabGtk* tab = tabstrip_->GetTabAt(index); | 491 TabGtk* tab = tabstrip_->GetTabAt(index); |
| 490 | 492 |
| 491 if (tab->mini()) | 493 if (tab->mini()) |
| 492 return TabGtk::GetMiniWidth(); | 494 return TabGtk::GetMiniWidth(); |
| 493 | 495 |
| 494 if (tab->IsSelected()) { | 496 if (tab->IsActive()) { |
| 495 return animation_.CurrentValueBetween(start_selected_width_, | 497 return animation_.CurrentValueBetween(start_selected_width_, |
| 496 end_selected_width_); | 498 end_selected_width_); |
| 497 } | 499 } |
| 498 | 500 |
| 499 return animation_.CurrentValueBetween(start_unselected_width_, | 501 return animation_.CurrentValueBetween(start_unselected_width_, |
| 500 end_unselected_width_); | 502 end_unselected_width_); |
| 501 } | 503 } |
| 502 | 504 |
| 503 private: | 505 private: |
| 504 // We need to start from the current widths of the Tabs as they were last | 506 // We need to start from the current widths of the Tabs as they were last |
| 505 // laid out, _not_ the last known good state, which is what'll be done if we | 507 // laid out, _not_ the last known good state, which is what'll be done if we |
| 506 // don't measure the Tab sizes here and just go with the default TabAnimation | 508 // don't measure the Tab sizes here and just go with the default TabAnimation |
| 507 // behavior... | 509 // behavior... |
| 508 void InitStartState() { | 510 void InitStartState() { |
| 509 for (int i = 0; i < tabstrip_->GetTabCount(); ++i) { | 511 for (int i = 0; i < tabstrip_->GetTabCount(); ++i) { |
| 510 TabGtk* current_tab = tabstrip_->GetTabAt(i); | 512 TabGtk* current_tab = tabstrip_->GetTabAt(i); |
| 511 if (!current_tab->mini()) { | 513 if (!current_tab->mini()) { |
| 512 if (current_tab->IsSelected()) { | 514 if (current_tab->IsActive()) { |
| 513 start_selected_width_ = current_tab->width(); | 515 start_selected_width_ = current_tab->width(); |
| 514 } else { | 516 } else { |
| 515 start_unselected_width_ = current_tab->width(); | 517 start_unselected_width_ = current_tab->width(); |
| 516 } | 518 } |
| 517 } | 519 } |
| 518 } | 520 } |
| 519 } | 521 } |
| 520 | 522 |
| 521 DISALLOW_COPY_AND_ASSIGN(ResizeLayoutAnimation); | 523 DISALLOW_COPY_AND_ASSIGN(ResizeLayoutAnimation); |
| 522 }; | 524 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 static_cast<double>(TabGtk::GetMiniWidth())); | 558 static_cast<double>(TabGtk::GetMiniWidth())); |
| 557 } else { | 559 } else { |
| 558 return animation_.CurrentValueBetween( | 560 return animation_.CurrentValueBetween( |
| 559 static_cast<double>(TabGtk::GetMiniWidth()), | 561 static_cast<double>(TabGtk::GetMiniWidth()), |
| 560 end_selected_width_); | 562 end_selected_width_); |
| 561 } | 563 } |
| 562 } else if (tab->mini()) { | 564 } else if (tab->mini()) { |
| 563 return TabGtk::GetMiniWidth(); | 565 return TabGtk::GetMiniWidth(); |
| 564 } | 566 } |
| 565 | 567 |
| 566 if (tab->IsSelected()) { | 568 if (tab->IsActive()) { |
| 567 return animation_.CurrentValueBetween(start_selected_width_, | 569 return animation_.CurrentValueBetween(start_selected_width_, |
| 568 end_selected_width_); | 570 end_selected_width_); |
| 569 } | 571 } |
| 570 | 572 |
| 571 return animation_.CurrentValueBetween(start_unselected_width_, | 573 return animation_.CurrentValueBetween(start_unselected_width_, |
| 572 end_unselected_width_); | 574 end_unselected_width_); |
| 573 } | 575 } |
| 574 | 576 |
| 575 private: | 577 private: |
| 576 // Index of the tab whose mini-state changed. | 578 // Index of the tab whose mini-state changed. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 | 656 |
| 655 virtual double GetWidthForTab(int index) const { | 657 virtual double GetWidthForTab(int index) const { |
| 656 TabGtk* tab = tabstrip_->GetTabAt(index); | 658 TabGtk* tab = tabstrip_->GetTabAt(index); |
| 657 | 659 |
| 658 if (index == to_index_) | 660 if (index == to_index_) |
| 659 return animation_.CurrentValueBetween(0, target_bounds_.width()); | 661 return animation_.CurrentValueBetween(0, target_bounds_.width()); |
| 660 | 662 |
| 661 if (tab->mini()) | 663 if (tab->mini()) |
| 662 return TabGtk::GetMiniWidth(); | 664 return TabGtk::GetMiniWidth(); |
| 663 | 665 |
| 664 if (tab->IsSelected()) { | 666 if (tab->IsActive()) { |
| 665 return animation_.CurrentValueBetween(start_selected_width_, | 667 return animation_.CurrentValueBetween(start_selected_width_, |
| 666 end_selected_width_); | 668 end_selected_width_); |
| 667 } | 669 } |
| 668 | 670 |
| 669 return animation_.CurrentValueBetween(start_unselected_width_, | 671 return animation_.CurrentValueBetween(start_unselected_width_, |
| 670 end_unselected_width_); | 672 end_unselected_width_); |
| 671 } | 673 } |
| 672 | 674 |
| 673 private: | 675 private: |
| 674 // The tab being moved. | 676 // The tab being moved. |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 | 1030 |
| 1029 GetTabAt(index)->SchedulePaint(); | 1031 GetTabAt(index)->SchedulePaint(); |
| 1030 | 1032 |
| 1031 int old_index = model_->GetIndexOfTabContents(old_contents); | 1033 int old_index = model_->GetIndexOfTabContents(old_contents); |
| 1032 if (old_index >= 0) { | 1034 if (old_index >= 0) { |
| 1033 GetTabAt(old_index)->SchedulePaint(); | 1035 GetTabAt(old_index)->SchedulePaint(); |
| 1034 GetTabAt(old_index)->StopMiniTabTitleAnimation(); | 1036 GetTabAt(old_index)->StopMiniTabTitleAnimation(); |
| 1035 } | 1037 } |
| 1036 } | 1038 } |
| 1037 | 1039 |
| 1040 void TabStripGtk::TabSelectionChanged( | |
|
sky
2011/06/01 20:56:04
Seems like you should only have to override one of
dpapad
2011/06/02 00:28:22
TabStripGtk::ActiveTabChanged() seems to me that i
| |
| 1041 const std::vector<int>& previously_selected, | |
| 1042 const std::vector<int>& currently_selected) { | |
| 1043 std::set<int> indices_affected; | |
| 1044 for (size_t i = 0; i < previously_selected.size(); i++) { | |
| 1045 if (previously_selected[i] != TabStripSelectionModel::kUnselectedIndex) | |
| 1046 indices_affected.insert(previously_selected[i]); | |
| 1047 } | |
| 1048 for (size_t i = 0; i < currently_selected.size(); i++) | |
|
sky
2011/06/01 20:56:04
Can this be indices_affected.insert(currently_sele
dpapad
2011/06/02 00:28:22
Done.
| |
| 1049 indices_affected.insert(currently_selected[i]); | |
| 1050 std::set<int>::iterator it; | |
| 1051 for (it = indices_affected.begin(); it != indices_affected.end(); ++it) | |
|
sky
2011/06/01 20:56:04
move definition of iterator into for loop.
dpapad
2011/06/02 00:28:22
Done.
| |
| 1052 GetTabAt(*it)->SchedulePaint(); | |
|
sky
2011/06/01 20:56:04
The indices passed to this method are from the mod
| |
| 1053 } | |
| 1054 | |
| 1038 void TabStripGtk::TabMoved(TabContentsWrapper* contents, | 1055 void TabStripGtk::TabMoved(TabContentsWrapper* contents, |
| 1039 int from_index, | 1056 int from_index, |
| 1040 int to_index) { | 1057 int to_index) { |
| 1041 gfx::Rect start_bounds = GetIdealBounds(from_index); | 1058 gfx::Rect start_bounds = GetIdealBounds(from_index); |
| 1042 TabGtk* tab = GetTabAt(from_index); | 1059 TabGtk* tab = GetTabAt(from_index); |
| 1043 tab_data_.erase(tab_data_.begin() + from_index); | 1060 tab_data_.erase(tab_data_.begin() + from_index); |
| 1044 TabData data = {tab, gfx::Rect()}; | 1061 TabData data = {tab, gfx::Rect()}; |
| 1045 tab->set_mini(model_->IsMiniTab(to_index)); | 1062 tab->set_mini(model_->IsMiniTab(to_index)); |
| 1046 tab->SetBlocked(model_->IsTabBlocked(to_index)); | 1063 tab->SetBlocked(model_->IsTabBlocked(to_index)); |
| 1047 tab_data_.insert(tab_data_.begin() + to_index, data); | 1064 tab_data_.insert(tab_data_.begin() + to_index, data); |
| 1048 GenerateIdealBounds(); | 1065 GenerateIdealBounds(); |
| 1049 StartMoveTabAnimation(from_index, to_index); | 1066 StartMoveTabAnimation(from_index, to_index); |
| 1050 } | 1067 } |
| 1051 | 1068 |
| 1052 void TabStripGtk::TabChangedAt(TabContentsWrapper* contents, int index, | 1069 void TabStripGtk::TabChangedAt(TabContentsWrapper* contents, int index, |
| 1053 TabChangeType change_type) { | 1070 TabChangeType change_type) { |
| 1054 // Index is in terms of the model. Need to make sure we adjust that index in | 1071 // Index is in terms of the model. Need to make sure we adjust that index in |
| 1055 // case we have an animation going. | 1072 // case we have an animation going. |
| 1056 TabGtk* tab = GetTabAtAdjustForAnimation(index); | 1073 TabGtk* tab = GetTabAtAdjustForAnimation(index); |
| 1057 if (change_type == TITLE_NOT_LOADING) { | 1074 if (change_type == TITLE_NOT_LOADING) { |
| 1058 if (tab->mini() && !tab->IsSelected()) | 1075 if (tab->mini() && !tab->IsActive()) |
| 1059 tab->StartMiniTabTitleAnimation(); | 1076 tab->StartMiniTabTitleAnimation(); |
| 1060 // We'll receive another notification of the change asynchronously. | 1077 // We'll receive another notification of the change asynchronously. |
| 1061 return; | 1078 return; |
| 1062 } | 1079 } |
| 1063 tab->UpdateData(contents->tab_contents(), | 1080 tab->UpdateData(contents->tab_contents(), |
| 1064 model_->IsAppTab(index), | 1081 model_->IsAppTab(index), |
| 1065 change_type == LOADING_ONLY); | 1082 change_type == LOADING_ONLY); |
| 1066 tab->UpdateFromModel(); | 1083 tab->UpdateFromModel(); |
| 1067 } | 1084 } |
| 1068 | 1085 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1090 } | 1107 } |
| 1091 | 1108 |
| 1092 void TabStripGtk::TabBlockedStateChanged(TabContentsWrapper* contents, | 1109 void TabStripGtk::TabBlockedStateChanged(TabContentsWrapper* contents, |
| 1093 int index) { | 1110 int index) { |
| 1094 GetTabAt(index)->SetBlocked(model_->IsTabBlocked(index)); | 1111 GetTabAt(index)->SetBlocked(model_->IsTabBlocked(index)); |
| 1095 } | 1112 } |
| 1096 | 1113 |
| 1097 //////////////////////////////////////////////////////////////////////////////// | 1114 //////////////////////////////////////////////////////////////////////////////// |
| 1098 // TabStripGtk, TabGtk::TabDelegate implementation: | 1115 // TabStripGtk, TabGtk::TabDelegate implementation: |
| 1099 | 1116 |
| 1100 bool TabStripGtk::IsTabSelected(const TabGtk* tab) const { | 1117 bool TabStripGtk::IsTabActive(const TabGtk* tab) const { |
| 1101 if (tab->closing()) | 1118 if (tab->closing()) |
| 1102 return false; | 1119 return false; |
| 1103 | 1120 |
| 1104 return GetIndexOfTab(tab) == model_->active_index(); | 1121 return GetIndexOfTab(tab) == model_->active_index(); |
| 1105 } | 1122 } |
| 1106 | 1123 |
| 1124 bool TabStripGtk::IsTabSelected(const TabGtk* tab) const { | |
| 1125 if (tab->closing()) | |
| 1126 return false; | |
| 1127 | |
| 1128 return model_->IsTabSelected(GetIndexOfTab(tab)); | |
| 1129 } | |
| 1130 | |
| 1107 bool TabStripGtk::IsTabDetached(const TabGtk* tab) const { | 1131 bool TabStripGtk::IsTabDetached(const TabGtk* tab) const { |
| 1108 if (drag_controller_.get()) | 1132 if (drag_controller_.get()) |
| 1109 return drag_controller_->IsTabDetached(tab); | 1133 return drag_controller_->IsTabDetached(tab); |
| 1110 return false; | 1134 return false; |
| 1111 } | 1135 } |
| 1112 | 1136 |
| 1113 void TabStripGtk::GetCurrentTabWidths(double* unselected_width, | 1137 void TabStripGtk::GetCurrentTabWidths(double* unselected_width, |
| 1114 double* selected_width) const { | 1138 double* selected_width) const { |
| 1115 *unselected_width = current_unselected_width_; | 1139 *unselected_width = current_unselected_width_; |
| 1116 *selected_width = current_selected_width_; | 1140 *selected_width = current_selected_width_; |
| 1117 } | 1141 } |
| 1118 | 1142 |
| 1119 bool TabStripGtk::IsTabPinned(const TabGtk* tab) const { | 1143 bool TabStripGtk::IsTabPinned(const TabGtk* tab) const { |
| 1120 if (tab->closing()) | 1144 if (tab->closing()) |
| 1121 return false; | 1145 return false; |
| 1122 | 1146 |
| 1123 return model_->IsTabPinned(GetIndexOfTab(tab)); | 1147 return model_->IsTabPinned(GetIndexOfTab(tab)); |
| 1124 } | 1148 } |
| 1125 | 1149 |
| 1126 void TabStripGtk::SelectTab(TabGtk* tab) { | 1150 void TabStripGtk::ActivateTab(TabGtk* tab) { |
| 1127 int index = GetIndexOfTab(tab); | 1151 int index = GetIndexOfTab(tab); |
| 1128 if (model_->ContainsIndex(index)) | 1152 if (model_->ContainsIndex(index)) |
| 1129 model_->ActivateTabAt(index, true); | 1153 model_->ActivateTabAt(index, true); |
| 1130 } | 1154 } |
| 1131 | 1155 |
| 1156 void TabStripGtk::ToggleTabSelection(TabGtk* tab) { | |
| 1157 int index = GetIndexOfTab(tab); | |
| 1158 model_->ToggleSelectionAt(index); | |
| 1159 } | |
| 1160 | |
| 1161 void TabStripGtk::ExtendTabSelection(TabGtk* tab) { | |
| 1162 int index = GetIndexOfTab(tab); | |
| 1163 if (model_->ContainsIndex(index)) | |
| 1164 model_->ExtendSelectionTo(index); | |
| 1165 } | |
| 1166 | |
| 1132 void TabStripGtk::CloseTab(TabGtk* tab) { | 1167 void TabStripGtk::CloseTab(TabGtk* tab) { |
| 1133 int tab_index = GetIndexOfTab(tab); | 1168 int tab_index = GetIndexOfTab(tab); |
| 1134 if (model_->ContainsIndex(tab_index)) { | 1169 if (model_->ContainsIndex(tab_index)) { |
| 1135 TabGtk* last_tab = GetTabAt(GetTabCount() - 1); | 1170 TabGtk* last_tab = GetTabAt(GetTabCount() - 1); |
| 1136 // Limit the width available to the TabStrip for laying out Tabs, so that | 1171 // Limit the width available to the TabStrip for laying out Tabs, so that |
| 1137 // Tabs are not resized until a later time (when the mouse pointer leaves | 1172 // Tabs are not resized until a later time (when the mouse pointer leaves |
| 1138 // the TabStrip). | 1173 // the TabStrip). |
| 1139 available_width_for_tabs_ = GetAvailableWidthForTabs(last_tab); | 1174 available_width_for_tabs_ = GetAvailableWidthForTabs(last_tab); |
| 1140 needs_resize_layout_ = true; | 1175 needs_resize_layout_ = true; |
| 1141 // We hook into the message loop in order to receive mouse move events when | 1176 // We hook into the message loop in order to receive mouse move events when |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1208 } | 1243 } |
| 1209 | 1244 |
| 1210 bool TabStripGtk::HasAvailableDragActions() const { | 1245 bool TabStripGtk::HasAvailableDragActions() const { |
| 1211 return model_->delegate()->GetDragActions() != 0; | 1246 return model_->delegate()->GetDragActions() != 0; |
| 1212 } | 1247 } |
| 1213 | 1248 |
| 1214 ui::ThemeProvider* TabStripGtk::GetThemeProvider() { | 1249 ui::ThemeProvider* TabStripGtk::GetThemeProvider() { |
| 1215 return theme_service_; | 1250 return theme_service_; |
| 1216 } | 1251 } |
| 1217 | 1252 |
| 1253 TabStripMenuController* TabStripGtk::GetTabStripMenuControllerForTab( | |
| 1254 TabGtk* tab) { | |
| 1255 return new TabStripMenuController(tab, model(), GetIndexOfTab(tab)); | |
| 1256 } | |
| 1257 | |
| 1218 /////////////////////////////////////////////////////////////////////////////// | 1258 /////////////////////////////////////////////////////////////////////////////// |
| 1219 // TabStripGtk, MessageLoop::Observer implementation: | 1259 // TabStripGtk, MessageLoop::Observer implementation: |
| 1220 | 1260 |
| 1221 void TabStripGtk::WillProcessEvent(GdkEvent* event) { | 1261 void TabStripGtk::WillProcessEvent(GdkEvent* event) { |
| 1222 // Nothing to do. | 1262 // Nothing to do. |
| 1223 } | 1263 } |
| 1224 | 1264 |
| 1225 void TabStripGtk::DidProcessEvent(GdkEvent* event) { | 1265 void TabStripGtk::DidProcessEvent(GdkEvent* event) { |
| 1226 switch (event->type) { | 1266 switch (event->type) { |
| 1227 case GDK_MOTION_NOTIFY: | 1267 case GDK_MOTION_NOTIFY: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1340 | 1380 |
| 1341 // NOTE: This currently assumes a tab's height doesn't differ based on | 1381 // NOTE: This currently assumes a tab's height doesn't differ based on |
| 1342 // selected state or the number of tabs in the strip! | 1382 // selected state or the number of tabs in the strip! |
| 1343 int tab_height = TabGtk::GetStandardSize().height(); | 1383 int tab_height = TabGtk::GetStandardSize().height(); |
| 1344 double tab_x = tab_start_x(); | 1384 double tab_x = tab_start_x(); |
| 1345 for (int i = 0; i < tab_count; ++i) { | 1385 for (int i = 0; i < tab_count; ++i) { |
| 1346 TabGtk* tab = GetTabAt(i); | 1386 TabGtk* tab = GetTabAt(i); |
| 1347 double tab_width = unselected; | 1387 double tab_width = unselected; |
| 1348 if (tab->mini()) | 1388 if (tab->mini()) |
| 1349 tab_width = TabGtk::GetMiniWidth(); | 1389 tab_width = TabGtk::GetMiniWidth(); |
| 1350 else if (tab->IsSelected()) | 1390 else if (tab->IsActive()) |
| 1351 tab_width = selected; | 1391 tab_width = selected; |
| 1352 double end_of_tab = tab_x + tab_width; | 1392 double end_of_tab = tab_x + tab_width; |
| 1353 int rounded_tab_x = Round(tab_x); | 1393 int rounded_tab_x = Round(tab_x); |
| 1354 gfx::Rect state(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, | 1394 gfx::Rect state(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, |
| 1355 tab_height); | 1395 tab_height); |
| 1356 tab_data_.at(i).ideal_bounds = state; | 1396 tab_data_.at(i).ideal_bounds = state; |
| 1357 tab_x = end_of_tab + GetTabHOffset(i + 1); | 1397 tab_x = end_of_tab + GetTabHOffset(i + 1); |
| 1358 } | 1398 } |
| 1359 } | 1399 } |
| 1360 | 1400 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1484 available_width_for_tabs_ = -1; | 1524 available_width_for_tabs_ = -1; |
| 1485 int mini_tab_count = GetMiniTabCount(); | 1525 int mini_tab_count = GetMiniTabCount(); |
| 1486 if (mini_tab_count == GetTabCount()) { | 1526 if (mini_tab_count == GetTabCount()) { |
| 1487 // Only mini tabs, we know the tab widths won't have changed (all mini-tabs | 1527 // Only mini tabs, we know the tab widths won't have changed (all mini-tabs |
| 1488 // have the same width), so there is nothing to do. | 1528 // have the same width), so there is nothing to do. |
| 1489 return false; | 1529 return false; |
| 1490 } | 1530 } |
| 1491 TabGtk* first_tab = GetTabAt(mini_tab_count); | 1531 TabGtk* first_tab = GetTabAt(mini_tab_count); |
| 1492 double unselected, selected; | 1532 double unselected, selected; |
| 1493 GetDesiredTabWidths(GetTabCount(), mini_tab_count, &unselected, &selected); | 1533 GetDesiredTabWidths(GetTabCount(), mini_tab_count, &unselected, &selected); |
| 1494 int w = Round(first_tab->IsSelected() ? selected : unselected); | 1534 int w = Round(first_tab->IsActive() ? selected : unselected); |
| 1495 | 1535 |
| 1496 // We only want to run the animation if we're not already at the desired | 1536 // We only want to run the animation if we're not already at the desired |
| 1497 // size. | 1537 // size. |
| 1498 if (abs(first_tab->width() - w) > 1) { | 1538 if (abs(first_tab->width() - w) > 1) { |
| 1499 StartResizeLayoutAnimation(); | 1539 StartResizeLayoutAnimation(); |
| 1500 return true; | 1540 return true; |
| 1501 } | 1541 } |
| 1502 | 1542 |
| 1503 return false; | 1543 return false; |
| 1504 } | 1544 } |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1913 newtab_button_->widget(), event); | 1953 newtab_button_->widget(), event); |
| 1914 | 1954 |
| 1915 // Paint the tabs in reverse order, so they stack to the left. | 1955 // Paint the tabs in reverse order, so they stack to the left. |
| 1916 TabGtk* selected_tab = NULL; | 1956 TabGtk* selected_tab = NULL; |
| 1917 int tab_count = GetTabCount(); | 1957 int tab_count = GetTabCount(); |
| 1918 for (int i = tab_count - 1; i >= 0; --i) { | 1958 for (int i = tab_count - 1; i >= 0; --i) { |
| 1919 TabGtk* tab = GetTabAt(i); | 1959 TabGtk* tab = GetTabAt(i); |
| 1920 // We must ask the _Tab's_ model, not ourselves, because in some situations | 1960 // We must ask the _Tab's_ model, not ourselves, because in some situations |
| 1921 // the model will be different to this object, e.g. when a Tab is being | 1961 // the model will be different to this object, e.g. when a Tab is being |
| 1922 // removed after its TabContents has been destroyed. | 1962 // removed after its TabContents has been destroyed. |
| 1923 if (!tab->IsSelected()) { | 1963 if (!tab->IsActive()) { |
| 1924 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip_.get()), | 1964 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip_.get()), |
| 1925 tab->widget(), event); | 1965 tab->widget(), event); |
| 1926 } else { | 1966 } else { |
| 1927 selected_tab = tab; | 1967 selected_tab = tab; |
| 1928 } | 1968 } |
| 1929 } | 1969 } |
| 1930 | 1970 |
| 1931 // Paint the selected tab last, so it overlaps all the others. | 1971 // Paint the selected tab last, so it overlaps all the others. |
| 1932 if (selected_tab) { | 1972 if (selected_tab) { |
| 1933 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip_.get()), | 1973 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip_.get()), |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2076 | 2116 |
| 2077 // Let the middle mouse button initiate clicks as well. | 2117 // Let the middle mouse button initiate clicks as well. |
| 2078 gtk_util::SetButtonTriggersNavigation(button->widget()); | 2118 gtk_util::SetButtonTriggersNavigation(button->widget()); |
| 2079 g_signal_connect(button->widget(), "clicked", | 2119 g_signal_connect(button->widget(), "clicked", |
| 2080 G_CALLBACK(OnNewTabClickedThunk), this); | 2120 G_CALLBACK(OnNewTabClickedThunk), this); |
| 2081 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 2121 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
| 2082 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); | 2122 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); |
| 2083 | 2123 |
| 2084 return button; | 2124 return button; |
| 2085 } | 2125 } |
| OLD | NEW |