| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/tabs/tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 newtab_button_(NULL), | 669 newtab_button_(NULL), |
| 670 current_inactive_width_(Tab::GetStandardSize().width()), | 670 current_inactive_width_(Tab::GetStandardSize().width()), |
| 671 current_active_width_(Tab::GetStandardSize().width()), | 671 current_active_width_(Tab::GetStandardSize().width()), |
| 672 available_width_for_tabs_(-1), | 672 available_width_for_tabs_(-1), |
| 673 in_tab_close_(false), | 673 in_tab_close_(false), |
| 674 animation_container_(new gfx::AnimationContainer()), | 674 animation_container_(new gfx::AnimationContainer()), |
| 675 bounds_animator_(this), | 675 bounds_animator_(this), |
| 676 stacked_layout_(false), | 676 stacked_layout_(false), |
| 677 adjust_layout_(false), | 677 adjust_layout_(false), |
| 678 reset_to_shrink_on_exit_(false), | 678 reset_to_shrink_on_exit_(false), |
| 679 mouse_move_count_(0), | 679 mouse_move_count_(0) { |
| 680 immersive_style_(false) { | |
| 681 Init(); | 680 Init(); |
| 682 SetEventTargeter( | 681 SetEventTargeter( |
| 683 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 682 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 684 } | 683 } |
| 685 | 684 |
| 686 TabStrip::~TabStrip() { | 685 TabStrip::~TabStrip() { |
| 687 FOR_EACH_OBSERVER(TabStripObserver, observers_, | 686 FOR_EACH_OBSERVER(TabStripObserver, observers_, |
| 688 TabStripDeleted(this)); | 687 TabStripDeleted(this)); |
| 689 | 688 |
| 690 // The animations may reference the tabs. Shut down the animation before we | 689 // The animations may reference the tabs. Shut down the animation before we |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 732 |
| 734 for (int i = 0; i < tab_count(); ++i) | 733 for (int i = 0; i < tab_count(); ++i) |
| 735 tab_at(i)->HideCloseButtonForInactiveTabsChanged(); | 734 tab_at(i)->HideCloseButtonForInactiveTabsChanged(); |
| 736 } | 735 } |
| 737 | 736 |
| 738 gfx::Rect TabStrip::GetNewTabButtonBounds() { | 737 gfx::Rect TabStrip::GetNewTabButtonBounds() { |
| 739 return newtab_button_->bounds(); | 738 return newtab_button_->bounds(); |
| 740 } | 739 } |
| 741 | 740 |
| 742 bool TabStrip::SizeTabButtonToTopOfTabStrip() { | 741 bool TabStrip::SizeTabButtonToTopOfTabStrip() { |
| 743 // Extend the button to the screen edge in maximized and immersive fullscreen. | 742 // Extend the button to the screen edge in maximized mode. |
| 744 views::Widget* widget = GetWidget(); | 743 views::Widget* widget = GetWidget(); |
| 745 return browser_defaults::kSizeTabButtonToTopOfTabStrip || | 744 return browser_defaults::kSizeTabButtonToTopOfTabStrip || |
| 746 (widget && (widget->IsMaximized() || widget->IsFullscreen())); | 745 (widget && (widget->IsMaximized() || widget->IsFullscreen())); |
| 747 } | 746 } |
| 748 | 747 |
| 749 void TabStrip::StartHighlight(int model_index) { | 748 void TabStrip::StartHighlight(int model_index) { |
| 750 tab_at(model_index)->StartPulse(); | 749 tab_at(model_index)->StartPulse(); |
| 751 } | 750 } |
| 752 | 751 |
| 753 void TabStrip::StopAllHighlighting() { | 752 void TabStrip::StopAllHighlighting() { |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 // processed for them. | 1093 // processed for them. |
| 1095 return false; | 1094 return false; |
| 1096 } | 1095 } |
| 1097 | 1096 |
| 1098 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { | 1097 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { |
| 1099 for (int i = 0; i < tab_count(); ++i) | 1098 for (int i = 0; i < tab_count(); ++i) |
| 1100 tab_at(i)->set_background_offset(offset); | 1099 tab_at(i)->set_background_offset(offset); |
| 1101 newtab_button_->set_background_offset(offset); | 1100 newtab_button_->set_background_offset(offset); |
| 1102 } | 1101 } |
| 1103 | 1102 |
| 1104 void TabStrip::SetImmersiveStyle(bool enable) { | |
| 1105 if (immersive_style_ == enable) | |
| 1106 return; | |
| 1107 immersive_style_ = enable; | |
| 1108 } | |
| 1109 | |
| 1110 SkAlpha TabStrip::GetInactiveAlpha(bool for_new_tab_button) const { | 1103 SkAlpha TabStrip::GetInactiveAlpha(bool for_new_tab_button) const { |
| 1111 #if defined(USE_ASH) | 1104 #if defined(USE_ASH) |
| 1112 static const SkAlpha kInactiveTabAlphaAsh = 230; | 1105 static const SkAlpha kInactiveTabAlphaAsh = 230; |
| 1113 const SkAlpha base_alpha = kInactiveTabAlphaAsh; | 1106 const SkAlpha base_alpha = kInactiveTabAlphaAsh; |
| 1114 #else | 1107 #else |
| 1115 static const SkAlpha kInactiveTabAlphaGlass = 200; | 1108 static const SkAlpha kInactiveTabAlphaGlass = 200; |
| 1116 static const SkAlpha kInactiveTabAlphaOpaque = 255; | 1109 static const SkAlpha kInactiveTabAlphaOpaque = 255; |
| 1117 const SkAlpha base_alpha = GetWidget()->ShouldWindowContentsBeTransparent() ? | 1110 const SkAlpha base_alpha = GetWidget()->ShouldWindowContentsBeTransparent() ? |
| 1118 kInactiveTabAlphaGlass : kInactiveTabAlphaOpaque; | 1111 kInactiveTabAlphaGlass : kInactiveTabAlphaOpaque; |
| 1119 #endif // USE_ASH | 1112 #endif // USE_ASH |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 const ui::ListSelectionModel& original_selection) { | 1234 const ui::ListSelectionModel& original_selection) { |
| 1242 // Don't accidentally start any drag operations during animations if the | 1235 // Don't accidentally start any drag operations during animations if the |
| 1243 // mouse is down... during an animation tabs are being resized automatically, | 1236 // mouse is down... during an animation tabs are being resized automatically, |
| 1244 // so the View system can misinterpret this easily if the mouse is down that | 1237 // so the View system can misinterpret this easily if the mouse is down that |
| 1245 // the user is dragging. | 1238 // the user is dragging. |
| 1246 if (IsAnimating() || tab->closing() || | 1239 if (IsAnimating() || tab->closing() || |
| 1247 controller_->HasAvailableDragActions() == 0) { | 1240 controller_->HasAvailableDragActions() == 0) { |
| 1248 return; | 1241 return; |
| 1249 } | 1242 } |
| 1250 | 1243 |
| 1251 // Do not do any dragging of tabs when using the super short immersive style. | |
| 1252 if (IsImmersiveStyle()) | |
| 1253 return; | |
| 1254 | |
| 1255 int model_index = GetModelIndexOfTab(tab); | 1244 int model_index = GetModelIndexOfTab(tab); |
| 1256 if (!IsValidModelIndex(model_index)) { | 1245 if (!IsValidModelIndex(model_index)) { |
| 1257 CHECK(false); | 1246 CHECK(false); |
| 1258 return; | 1247 return; |
| 1259 } | 1248 } |
| 1260 Tabs tabs; | 1249 Tabs tabs; |
| 1261 int size_to_selected = 0; | 1250 int size_to_selected = 0; |
| 1262 int x = tab->GetMirroredXInView(event.x()); | 1251 int x = tab->GetMirroredXInView(event.x()); |
| 1263 int y = event.y(); | 1252 int y = event.y(); |
| 1264 // Build the set of selected tabs to drag and calculate the offset from the | 1253 // Build the set of selected tabs to drag and calculate the offset from the |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 current_x) { | 1373 current_x) { |
| 1385 *clip = border_callback.Run(tab_at(index - 1)->size()); | 1374 *clip = border_callback.Run(tab_at(index - 1)->size()); |
| 1386 clip->offset(SkIntToScalar(previous_x - current_x), 0); | 1375 clip->offset(SkIntToScalar(previous_x - current_x), 0); |
| 1387 } | 1376 } |
| 1388 } | 1377 } |
| 1389 return true; | 1378 return true; |
| 1390 } | 1379 } |
| 1391 | 1380 |
| 1392 bool TabStrip::CanPaintThrobberToLayer() const { | 1381 bool TabStrip::CanPaintThrobberToLayer() const { |
| 1393 // Disable layer-painting of throbbers if dragging, if any tab animation is in | 1382 // Disable layer-painting of throbbers if dragging, if any tab animation is in |
| 1394 // progress, or if stacked tabs are enabled. Also disable in fullscreen: when | 1383 // progress, or if stacked tabs are enabled. Also disable in fullscreen. |
| 1395 // "immersive" the tab strip could be sliding in or out while transitioning to | |
| 1396 // or away from |immersive_style_| and, for other modes, there's no tab strip. | |
| 1397 const bool dragging = drag_controller_ && drag_controller_->started_drag(); | 1384 const bool dragging = drag_controller_ && drag_controller_->started_drag(); |
| 1398 const views::Widget* widget = GetWidget(); | 1385 const views::Widget* widget = GetWidget(); |
| 1399 return widget && !touch_layout_ && !dragging && !IsAnimating() && | 1386 return widget && !touch_layout_ && !dragging && !IsAnimating() && |
| 1400 !widget->IsFullscreen(); | 1387 !widget->IsFullscreen(); |
| 1401 } | 1388 } |
| 1402 | 1389 |
| 1403 bool TabStrip::IsImmersiveStyle() const { | |
| 1404 return immersive_style_; | |
| 1405 } | |
| 1406 | |
| 1407 SkColor TabStrip::GetToolbarTopSeparatorColor() const { | 1390 SkColor TabStrip::GetToolbarTopSeparatorColor() const { |
| 1408 return controller_->GetToolbarTopSeparatorColor(); | 1391 return controller_->GetToolbarTopSeparatorColor(); |
| 1409 } | 1392 } |
| 1410 | 1393 |
| 1411 int TabStrip::GetBackgroundResourceId(bool* custom_image) const { | 1394 int TabStrip::GetBackgroundResourceId(bool* custom_image) const { |
| 1412 const ui::ThemeProvider* tp = GetThemeProvider(); | 1395 const ui::ThemeProvider* tp = GetThemeProvider(); |
| 1413 | 1396 |
| 1414 if (GetWidget()->ShouldWindowContentsBeTransparent()) { | 1397 if (GetWidget()->ShouldWindowContentsBeTransparent()) { |
| 1415 const int kBackgroundIdGlass = IDR_THEME_TAB_BACKGROUND_V; | 1398 const int kBackgroundIdGlass = IDR_THEME_TAB_BACKGROUND_V; |
| 1416 *custom_image = tp->HasCustomImage(kBackgroundIdGlass); | 1399 *custom_image = tp->HasCustomImage(kBackgroundIdGlass); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 needed_tab_width -= (tab_count() - 1) * tab_overlap; | 1571 needed_tab_width -= (tab_count() - 1) * tab_overlap; |
| 1589 | 1572 |
| 1590 // Don't let the tabstrip shrink smaller than is necessary to show one tab, | 1573 // Don't let the tabstrip shrink smaller than is necessary to show one tab, |
| 1591 // and don't force it to be larger than is necessary to show 20 tabs. | 1574 // and don't force it to be larger than is necessary to show 20 tabs. |
| 1592 const int largest_min_tab_width = | 1575 const int largest_min_tab_width = |
| 1593 min_selected_width + 19 * (min_unselected_width - tab_overlap); | 1576 min_selected_width + 19 * (min_unselected_width - tab_overlap); |
| 1594 needed_tab_width = std::min( | 1577 needed_tab_width = std::min( |
| 1595 std::max(needed_tab_width, min_selected_width), largest_min_tab_width); | 1578 std::max(needed_tab_width, min_selected_width), largest_min_tab_width); |
| 1596 } | 1579 } |
| 1597 return gfx::Size(needed_tab_width + GetNewTabButtonWidth(), | 1580 return gfx::Size(needed_tab_width + GetNewTabButtonWidth(), |
| 1598 immersive_style_ ? Tab::GetImmersiveHeight() | 1581 Tab::GetMinimumInactiveSize().height()); |
| 1599 : Tab::GetMinimumInactiveSize().height()); | |
| 1600 } | 1582 } |
| 1601 | 1583 |
| 1602 void TabStrip::OnDragEntered(const DropTargetEvent& event) { | 1584 void TabStrip::OnDragEntered(const DropTargetEvent& event) { |
| 1603 // Force animations to stop, otherwise it makes the index calculation tricky. | 1585 // Force animations to stop, otherwise it makes the index calculation tricky. |
| 1604 StopAnimating(true); | 1586 StopAnimating(true); |
| 1605 | 1587 |
| 1606 UpdateDropIndex(event); | 1588 UpdateDropIndex(event); |
| 1607 | 1589 |
| 1608 GURL url; | 1590 GURL url; |
| 1609 base::string16 title; | 1591 base::string16 title; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 if (view) | 1671 if (view) |
| 1690 return view; | 1672 return view; |
| 1691 } | 1673 } |
| 1692 Tab* tab = FindTabForEvent(point); | 1674 Tab* tab = FindTabForEvent(point); |
| 1693 if (tab) | 1675 if (tab) |
| 1694 return ConvertPointToViewAndGetTooltipHandler(this, tab, point); | 1676 return ConvertPointToViewAndGetTooltipHandler(this, tab, point); |
| 1695 } | 1677 } |
| 1696 return this; | 1678 return this; |
| 1697 } | 1679 } |
| 1698 | 1680 |
| 1699 // static | |
| 1700 int TabStrip::GetImmersiveHeight() { | |
| 1701 return Tab::GetImmersiveHeight(); | |
| 1702 } | |
| 1703 | |
| 1704 /////////////////////////////////////////////////////////////////////////////// | 1681 /////////////////////////////////////////////////////////////////////////////// |
| 1705 // TabStrip, private: | 1682 // TabStrip, private: |
| 1706 | 1683 |
| 1707 void TabStrip::Init() { | 1684 void TabStrip::Init() { |
| 1708 set_id(VIEW_ID_TAB_STRIP); | 1685 set_id(VIEW_ID_TAB_STRIP); |
| 1709 // So we get enter/exit on children to switch stacked layout on and off. | 1686 // So we get enter/exit on children to switch stacked layout on and off. |
| 1710 set_notify_enter_exit_on_child(true); | 1687 set_notify_enter_exit_on_child(true); |
| 1711 | 1688 |
| 1712 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON)); | 1689 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON)); |
| 1713 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset()); | 1690 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset()); |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2888 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 2865 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
| 2889 if (view) | 2866 if (view) |
| 2890 return view; | 2867 return view; |
| 2891 } | 2868 } |
| 2892 Tab* tab = FindTabForEvent(point); | 2869 Tab* tab = FindTabForEvent(point); |
| 2893 if (tab) | 2870 if (tab) |
| 2894 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2871 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
| 2895 } | 2872 } |
| 2896 return this; | 2873 return this; |
| 2897 } | 2874 } |
| OLD | NEW |