| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 newtab_button_(NULL), | 587 newtab_button_(NULL), |
| 588 current_inactive_width_(Tab::GetStandardSize().width()), | 588 current_inactive_width_(Tab::GetStandardSize().width()), |
| 589 current_active_width_(Tab::GetStandardSize().width()), | 589 current_active_width_(Tab::GetStandardSize().width()), |
| 590 available_width_for_tabs_(-1), | 590 available_width_for_tabs_(-1), |
| 591 in_tab_close_(false), | 591 in_tab_close_(false), |
| 592 animation_container_(new gfx::AnimationContainer()), | 592 animation_container_(new gfx::AnimationContainer()), |
| 593 bounds_animator_(this), | 593 bounds_animator_(this), |
| 594 stacked_layout_(false), | 594 stacked_layout_(false), |
| 595 adjust_layout_(false), | 595 adjust_layout_(false), |
| 596 reset_to_shrink_on_exit_(false), | 596 reset_to_shrink_on_exit_(false), |
| 597 mouse_move_count_(0), | 597 mouse_move_count_(0) { |
| 598 immersive_style_(false) { | |
| 599 Init(); | 598 Init(); |
| 600 SetEventTargeter( | 599 SetEventTargeter( |
| 601 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 600 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 602 } | 601 } |
| 603 | 602 |
| 604 TabStrip::~TabStrip() { | 603 TabStrip::~TabStrip() { |
| 605 for (TabStripObserver& observer : observers_) | 604 for (TabStripObserver& observer : observers_) |
| 606 observer.TabStripDeleted(this); | 605 observer.TabStripDeleted(this); |
| 607 | 606 |
| 608 // The animations may reference the tabs. Shut down the animation before we | 607 // The animations may reference the tabs. Shut down the animation before we |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 // processed for them. | 1011 // processed for them. |
| 1013 return false; | 1012 return false; |
| 1014 } | 1013 } |
| 1015 | 1014 |
| 1016 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { | 1015 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { |
| 1017 for (int i = 0; i < tab_count(); ++i) | 1016 for (int i = 0; i < tab_count(); ++i) |
| 1018 tab_at(i)->set_background_offset(offset); | 1017 tab_at(i)->set_background_offset(offset); |
| 1019 newtab_button_->set_background_offset(offset); | 1018 newtab_button_->set_background_offset(offset); |
| 1020 } | 1019 } |
| 1021 | 1020 |
| 1022 void TabStrip::SetImmersiveStyle(bool enable) { | |
| 1023 if (immersive_style_ == enable) | |
| 1024 return; | |
| 1025 immersive_style_ = enable; | |
| 1026 } | |
| 1027 | |
| 1028 SkAlpha TabStrip::GetInactiveAlpha(bool for_new_tab_button) const { | 1021 SkAlpha TabStrip::GetInactiveAlpha(bool for_new_tab_button) const { |
| 1029 #if defined(USE_ASH) | 1022 #if defined(USE_ASH) |
| 1030 static const SkAlpha kInactiveTabAlphaAsh = 230; | 1023 static const SkAlpha kInactiveTabAlphaAsh = 230; |
| 1031 const SkAlpha base_alpha = kInactiveTabAlphaAsh; | 1024 const SkAlpha base_alpha = kInactiveTabAlphaAsh; |
| 1032 #else | 1025 #else |
| 1033 static const SkAlpha kInactiveTabAlphaGlass = 200; | 1026 static const SkAlpha kInactiveTabAlphaGlass = 200; |
| 1034 static const SkAlpha kInactiveTabAlphaOpaque = 255; | 1027 static const SkAlpha kInactiveTabAlphaOpaque = 255; |
| 1035 const SkAlpha base_alpha = GetWidget()->ShouldWindowContentsBeTransparent() ? | 1028 const SkAlpha base_alpha = GetWidget()->ShouldWindowContentsBeTransparent() ? |
| 1036 kInactiveTabAlphaGlass : kInactiveTabAlphaOpaque; | 1029 kInactiveTabAlphaGlass : kInactiveTabAlphaOpaque; |
| 1037 #endif // USE_ASH | 1030 #endif // USE_ASH |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 const ui::ListSelectionModel& original_selection) { | 1152 const ui::ListSelectionModel& original_selection) { |
| 1160 // Don't accidentally start any drag operations during animations if the | 1153 // Don't accidentally start any drag operations during animations if the |
| 1161 // mouse is down... during an animation tabs are being resized automatically, | 1154 // mouse is down... during an animation tabs are being resized automatically, |
| 1162 // so the View system can misinterpret this easily if the mouse is down that | 1155 // so the View system can misinterpret this easily if the mouse is down that |
| 1163 // the user is dragging. | 1156 // the user is dragging. |
| 1164 if (IsAnimating() || tab->closing() || | 1157 if (IsAnimating() || tab->closing() || |
| 1165 controller_->HasAvailableDragActions() == 0) { | 1158 controller_->HasAvailableDragActions() == 0) { |
| 1166 return; | 1159 return; |
| 1167 } | 1160 } |
| 1168 | 1161 |
| 1169 // Do not do any dragging of tabs when using the super short immersive style. | |
| 1170 if (IsImmersiveStyle()) | |
| 1171 return; | |
| 1172 | |
| 1173 int model_index = GetModelIndexOfTab(tab); | 1162 int model_index = GetModelIndexOfTab(tab); |
| 1174 if (!IsValidModelIndex(model_index)) { | 1163 if (!IsValidModelIndex(model_index)) { |
| 1175 CHECK(false); | 1164 CHECK(false); |
| 1176 return; | 1165 return; |
| 1177 } | 1166 } |
| 1178 Tabs tabs; | 1167 Tabs tabs; |
| 1179 int size_to_selected = 0; | 1168 int size_to_selected = 0; |
| 1180 int x = tab->GetMirroredXInView(event.x()); | 1169 int x = tab->GetMirroredXInView(event.x()); |
| 1181 int y = event.y(); | 1170 int y = event.y(); |
| 1182 // Build the set of selected tabs to drag and calculate the offset from the | 1171 // 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... |
| 1302 *clip = border_callback.Run(tab_at(index - 1)->size()); | 1291 *clip = border_callback.Run(tab_at(index - 1)->size()); |
| 1303 clip->offset(SkIntToScalar(previous_x - current_x), 0); | 1292 clip->offset(SkIntToScalar(previous_x - current_x), 0); |
| 1304 } | 1293 } |
| 1305 } | 1294 } |
| 1306 return true; | 1295 return true; |
| 1307 } | 1296 } |
| 1308 | 1297 |
| 1309 bool TabStrip::CanPaintThrobberToLayer() const { | 1298 bool TabStrip::CanPaintThrobberToLayer() const { |
| 1310 // Disable layer-painting of throbbers if dragging, if any tab animation is in | 1299 // Disable layer-painting of throbbers if dragging, if any tab animation is in |
| 1311 // progress, or if stacked tabs are enabled. Also disable in fullscreen: when | 1300 // progress, or if stacked tabs are enabled. Also disable in fullscreen: when |
| 1312 // "immersive" the tab strip could be sliding in or out while transitioning to | 1301 // "immersive" the tab strip could be sliding in or out; for other modes, |
| 1313 // or away from |immersive_style_| and, for other modes, there's no tab strip. | 1302 // there's no tab strip. |
| 1314 const bool dragging = drag_controller_ && drag_controller_->started_drag(); | 1303 const bool dragging = drag_controller_ && drag_controller_->started_drag(); |
| 1315 const views::Widget* widget = GetWidget(); | 1304 const views::Widget* widget = GetWidget(); |
| 1316 return widget && !touch_layout_ && !dragging && !IsAnimating() && | 1305 return widget && !touch_layout_ && !dragging && !IsAnimating() && |
| 1317 !widget->IsFullscreen(); | 1306 !widget->IsFullscreen(); |
| 1318 } | 1307 } |
| 1319 | 1308 |
| 1320 bool TabStrip::IsImmersiveStyle() const { | |
| 1321 return immersive_style_; | |
| 1322 } | |
| 1323 | |
| 1324 SkColor TabStrip::GetToolbarTopSeparatorColor() const { | 1309 SkColor TabStrip::GetToolbarTopSeparatorColor() const { |
| 1325 return controller_->GetToolbarTopSeparatorColor(); | 1310 return controller_->GetToolbarTopSeparatorColor(); |
| 1326 } | 1311 } |
| 1327 | 1312 |
| 1328 // Returns the accessible tab name for the tab. | 1313 // Returns the accessible tab name for the tab. |
| 1329 base::string16 TabStrip::GetAccessibleTabName(const Tab* tab) const { | 1314 base::string16 TabStrip::GetAccessibleTabName(const Tab* tab) const { |
| 1330 int model_index = GetModelIndexOfTab(tab); | 1315 int model_index = GetModelIndexOfTab(tab); |
| 1331 if (IsValidModelIndex(model_index)) | 1316 if (IsValidModelIndex(model_index)) |
| 1332 return controller_->GetAccessibleTabName(tab); | 1317 return controller_->GetAccessibleTabName(tab); |
| 1333 return base::string16(); | 1318 return base::string16(); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1509 needed_tab_width -= (tab_count() - 1) * Tab::kOverlap; | 1494 needed_tab_width -= (tab_count() - 1) * Tab::kOverlap; |
| 1510 | 1495 |
| 1511 // Don't let the tabstrip shrink smaller than is necessary to show one tab, | 1496 // Don't let the tabstrip shrink smaller than is necessary to show one tab, |
| 1512 // and don't force it to be larger than is necessary to show 20 tabs. | 1497 // and don't force it to be larger than is necessary to show 20 tabs. |
| 1513 const int largest_min_tab_width = | 1498 const int largest_min_tab_width = |
| 1514 min_selected_width + 19 * (min_unselected_width - Tab::kOverlap); | 1499 min_selected_width + 19 * (min_unselected_width - Tab::kOverlap); |
| 1515 needed_tab_width = std::min( | 1500 needed_tab_width = std::min( |
| 1516 std::max(needed_tab_width, min_selected_width), largest_min_tab_width); | 1501 std::max(needed_tab_width, min_selected_width), largest_min_tab_width); |
| 1517 } | 1502 } |
| 1518 return gfx::Size(needed_tab_width + GetNewTabButtonWidth(), | 1503 return gfx::Size(needed_tab_width + GetNewTabButtonWidth(), |
| 1519 immersive_style_ ? Tab::GetImmersiveHeight() | 1504 Tab::GetMinimumInactiveSize().height()); |
| 1520 : Tab::GetMinimumInactiveSize().height()); | |
| 1521 } | 1505 } |
| 1522 | 1506 |
| 1523 void TabStrip::OnDragEntered(const DropTargetEvent& event) { | 1507 void TabStrip::OnDragEntered(const DropTargetEvent& event) { |
| 1524 // Force animations to stop, otherwise it makes the index calculation tricky. | 1508 // Force animations to stop, otherwise it makes the index calculation tricky. |
| 1525 StopAnimating(true); | 1509 StopAnimating(true); |
| 1526 | 1510 |
| 1527 UpdateDropIndex(event); | 1511 UpdateDropIndex(event); |
| 1528 | 1512 |
| 1529 GURL url; | 1513 GURL url; |
| 1530 base::string16 title; | 1514 base::string16 title; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 if (view) | 1594 if (view) |
| 1611 return view; | 1595 return view; |
| 1612 } | 1596 } |
| 1613 Tab* tab = FindTabForEvent(point); | 1597 Tab* tab = FindTabForEvent(point); |
| 1614 if (tab) | 1598 if (tab) |
| 1615 return ConvertPointToViewAndGetTooltipHandler(this, tab, point); | 1599 return ConvertPointToViewAndGetTooltipHandler(this, tab, point); |
| 1616 } | 1600 } |
| 1617 return this; | 1601 return this; |
| 1618 } | 1602 } |
| 1619 | 1603 |
| 1620 // static | |
| 1621 int TabStrip::GetImmersiveHeight() { | |
| 1622 return Tab::GetImmersiveHeight(); | |
| 1623 } | |
| 1624 | |
| 1625 /////////////////////////////////////////////////////////////////////////////// | 1604 /////////////////////////////////////////////////////////////////////////////// |
| 1626 // TabStrip, private: | 1605 // TabStrip, private: |
| 1627 | 1606 |
| 1628 void TabStrip::Init() { | 1607 void TabStrip::Init() { |
| 1629 set_id(VIEW_ID_TAB_STRIP); | 1608 set_id(VIEW_ID_TAB_STRIP); |
| 1630 // So we get enter/exit on children to switch stacked layout on and off. | 1609 // So we get enter/exit on children to switch stacked layout on and off. |
| 1631 set_notify_enter_exit_on_child(true); | 1610 set_notify_enter_exit_on_child(true); |
| 1632 | 1611 |
| 1633 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON)); | 1612 newtab_button_bounds_.set_size(GetLayoutSize(NEW_TAB_BUTTON)); |
| 1634 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset()); | 1613 newtab_button_bounds_.Inset(0, 0, 0, -GetNewTabButtonTopOffset()); |
| (...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2803 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 2782 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
| 2804 if (view) | 2783 if (view) |
| 2805 return view; | 2784 return view; |
| 2806 } | 2785 } |
| 2807 Tab* tab = FindTabForEvent(point); | 2786 Tab* tab = FindTabForEvent(point); |
| 2808 if (tab) | 2787 if (tab) |
| 2809 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 2788 return ConvertPointToViewAndGetEventHandler(this, tab, point); |
| 2810 } | 2789 } |
| 2811 return this; | 2790 return this; |
| 2812 } | 2791 } |
| OLD | NEW |