| 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_drag_controller.h" | 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "ash/accelerators/accelerator_commands.h" | 10 #include "ash/accelerators/accelerator_commands.h" |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 end_run_loop_behavior_ = END_RUN_LOOP_CONTINUE_DRAGGING; | 609 end_run_loop_behavior_ = END_RUN_LOOP_CONTINUE_DRAGGING; |
| 610 return DRAG_BROWSER_RESULT_STOP; | 610 return DRAG_BROWSER_RESULT_STOP; |
| 611 } | 611 } |
| 612 Detach(DONT_RELEASE_CAPTURE); | 612 Detach(DONT_RELEASE_CAPTURE); |
| 613 Attach(target_tabstrip, point_in_screen); | 613 Attach(target_tabstrip, point_in_screen); |
| 614 return DRAG_BROWSER_RESULT_CONTINUE; | 614 return DRAG_BROWSER_RESULT_CONTINUE; |
| 615 } | 615 } |
| 616 | 616 |
| 617 void TabDragController::DragActiveTabStacked( | 617 void TabDragController::DragActiveTabStacked( |
| 618 const gfx::Point& point_in_screen) { | 618 const gfx::Point& point_in_screen) { |
| 619 if (attached_tabstrip_->tab_count() != | 619 if (attached_tabstrip_->GetTabCount() != |
| 620 static_cast<int>(initial_tab_positions_.size())) | 620 static_cast<int>(initial_tab_positions_.size())) |
| 621 return; // TODO: should cancel drag if this happens. | 621 return; // TODO: should cancel drag if this happens. |
| 622 | 622 |
| 623 int delta = point_in_screen.x() - start_point_in_screen_.x(); | 623 int delta = point_in_screen.x() - start_point_in_screen_.x(); |
| 624 attached_tabstrip_->DragActiveTab(initial_tab_positions_, delta); | 624 attached_tabstrip_->DragActiveTab(initial_tab_positions_, delta); |
| 625 } | 625 } |
| 626 | 626 |
| 627 void TabDragController::MoveAttachedToNextStackedIndex( | 627 void TabDragController::MoveAttachedToNextStackedIndex( |
| 628 const gfx::Point& point_in_screen) { | 628 const gfx::Point& point_in_screen) { |
| 629 int index = attached_tabstrip_->touch_layout_->active_index(); | 629 int index = attached_tabstrip_->touch_layout_->active_index(); |
| 630 if (index + 1 >= attached_tabstrip_->tab_count()) | 630 if (index + 1 >= attached_tabstrip_->GetTabCount()) |
| 631 return; | 631 return; |
| 632 | 632 |
| 633 GetModel(attached_tabstrip_)->MoveSelectedTabsTo(index + 1); | 633 GetModel(attached_tabstrip_)->MoveSelectedTabsTo(index + 1); |
| 634 StartMoveStackedTimerIfNecessary(point_in_screen, | 634 StartMoveStackedTimerIfNecessary(point_in_screen, |
| 635 kMoveAttachedSubsequentDelay); | 635 kMoveAttachedSubsequentDelay); |
| 636 } | 636 } |
| 637 | 637 |
| 638 void TabDragController::MoveAttachedToPreviousStackedIndex( | 638 void TabDragController::MoveAttachedToPreviousStackedIndex( |
| 639 const gfx::Point& point_in_screen) { | 639 const gfx::Point& point_in_screen) { |
| 640 int index = attached_tabstrip_->touch_layout_->active_index(); | 640 int index = attached_tabstrip_->touch_layout_->active_index(); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 DCHECK(attached_tabstrip_); | 1092 DCHECK(attached_tabstrip_); |
| 1093 attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_); | 1093 attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_); |
| 1094 } else if (active_) { | 1094 } else if (active_) { |
| 1095 EndDrag(result == views::Widget::MOVE_LOOP_CANCELED ? | 1095 EndDrag(result == views::Widget::MOVE_LOOP_CANCELED ? |
| 1096 END_DRAG_CANCEL : END_DRAG_COMPLETE); | 1096 END_DRAG_CANCEL : END_DRAG_COMPLETE); |
| 1097 } | 1097 } |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 int TabDragController::GetInsertionIndexFrom(const gfx::Rect& dragged_bounds, | 1100 int TabDragController::GetInsertionIndexFrom(const gfx::Rect& dragged_bounds, |
| 1101 int start) const { | 1101 int start) const { |
| 1102 const int last_tab = attached_tabstrip_->tab_count() - 1; | 1102 const int last_tab = attached_tabstrip_->GetTabCount() - 1; |
| 1103 // Make the actual "drag insertion point" be just after the leading edge of | 1103 // Make the actual "drag insertion point" be just after the leading edge of |
| 1104 // the first dragged tab. This is closer to where the user thinks of the tab | 1104 // the first dragged tab. This is closer to where the user thinks of the tab |
| 1105 // as "starting" than just dragged_bounds.x(), especially with narrow tabs. | 1105 // as "starting" than just dragged_bounds.x(), especially with narrow tabs. |
| 1106 const int dragged_x = dragged_bounds.x() + Tab::leading_width_for_drag(); | 1106 const int dragged_x = dragged_bounds.x() + Tab::leading_width_for_drag(); |
| 1107 if (start < 0 || start > last_tab || | 1107 if (start < 0 || start > last_tab || |
| 1108 dragged_x < attached_tabstrip_->ideal_bounds(start).x()) | 1108 dragged_x < attached_tabstrip_->ideal_bounds(start).x()) |
| 1109 return -1; | 1109 return -1; |
| 1110 | 1110 |
| 1111 for (int i = start; i <= last_tab; ++i) { | 1111 for (int i = start; i <= last_tab; ++i) { |
| 1112 const gfx::Rect& ideal_bounds = attached_tabstrip_->ideal_bounds(i); | 1112 const gfx::Rect& ideal_bounds = attached_tabstrip_->ideal_bounds(i); |
| 1113 if (dragged_x < (ideal_bounds.x() + (ideal_bounds.width() / 2))) | 1113 if (dragged_x < (ideal_bounds.x() + (ideal_bounds.width() / 2))) |
| 1114 return i; | 1114 return i; |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 return (dragged_x < attached_tabstrip_->ideal_bounds(last_tab).right()) ? | 1117 return (dragged_x < attached_tabstrip_->ideal_bounds(last_tab).right()) ? |
| 1118 (last_tab + 1) : -1; | 1118 (last_tab + 1) : -1; |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 int TabDragController::GetInsertionIndexFromReversed( | 1121 int TabDragController::GetInsertionIndexFromReversed( |
| 1122 const gfx::Rect& dragged_bounds, | 1122 const gfx::Rect& dragged_bounds, |
| 1123 int start) const { | 1123 int start) const { |
| 1124 // Make the actual "drag insertion point" be just after the leading edge of | 1124 // Make the actual "drag insertion point" be just after the leading edge of |
| 1125 // the first dragged tab. This is closer to where the user thinks of the tab | 1125 // the first dragged tab. This is closer to where the user thinks of the tab |
| 1126 // as "starting" than just dragged_bounds.x(), especially with narrow tabs. | 1126 // as "starting" than just dragged_bounds.x(), especially with narrow tabs. |
| 1127 const int dragged_x = dragged_bounds.x() + Tab::leading_width_for_drag(); | 1127 const int dragged_x = dragged_bounds.x() + Tab::leading_width_for_drag(); |
| 1128 if (start < 0 || start >= attached_tabstrip_->tab_count() || | 1128 if (start < 0 || start >= attached_tabstrip_->GetTabCount() || |
| 1129 dragged_x >= attached_tabstrip_->ideal_bounds(start).right()) | 1129 dragged_x >= attached_tabstrip_->ideal_bounds(start).right()) |
| 1130 return -1; | 1130 return -1; |
| 1131 | 1131 |
| 1132 for (int i = start; i >= 0; --i) { | 1132 for (int i = start; i >= 0; --i) { |
| 1133 const gfx::Rect& ideal_bounds = attached_tabstrip_->ideal_bounds(i); | 1133 const gfx::Rect& ideal_bounds = attached_tabstrip_->ideal_bounds(i); |
| 1134 if (dragged_x >= (ideal_bounds.x() + (ideal_bounds.width() / 2))) | 1134 if (dragged_x >= (ideal_bounds.x() + (ideal_bounds.width() / 2))) |
| 1135 return i + 1; | 1135 return i + 1; |
| 1136 } | 1136 } |
| 1137 | 1137 |
| 1138 return (dragged_x >= attached_tabstrip_->ideal_bounds(0).x()) ? 0 : -1; | 1138 return (dragged_x >= attached_tabstrip_->ideal_bounds(0).x()) ? 0 : -1; |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 int TabDragController::GetInsertionIndexForDraggedBounds( | 1141 int TabDragController::GetInsertionIndexForDraggedBounds( |
| 1142 const gfx::Rect& dragged_bounds) const { | 1142 const gfx::Rect& dragged_bounds) const { |
| 1143 // If the strip has no tabs, the only position to insert at is 0. | 1143 // If the strip has no tabs, the only position to insert at is 0. |
| 1144 const int tab_count = attached_tabstrip_->tab_count(); | 1144 const int tab_count = attached_tabstrip_->GetTabCount(); |
| 1145 if (!tab_count) | 1145 if (!tab_count) |
| 1146 return 0; | 1146 return 0; |
| 1147 | 1147 |
| 1148 int index = -1; | 1148 int index = -1; |
| 1149 if (attached_tabstrip_->touch_layout_.get()) { | 1149 if (attached_tabstrip_->touch_layout_.get()) { |
| 1150 index = GetInsertionIndexForDraggedBoundsStacked(dragged_bounds); | 1150 index = GetInsertionIndexForDraggedBoundsStacked(dragged_bounds); |
| 1151 if (index != -1) { | 1151 if (index != -1) { |
| 1152 // Only move the tab to the left/right if the user actually moved the | 1152 // Only move the tab to the left/right if the user actually moved the |
| 1153 // mouse that way. This is necessary as tabs with stacked tabs | 1153 // mouse that way. This is necessary as tabs with stacked tabs |
| 1154 // before/after them have multiple drag positions. | 1154 // before/after them have multiple drag positions. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1179 0, last_insertion_point - static_cast<int>(drag_data_.size())); | 1179 0, last_insertion_point - static_cast<int>(drag_data_.size())); |
| 1180 } | 1180 } |
| 1181 | 1181 |
| 1182 // Ensure the first dragged tab always stays in the visible index range. | 1182 // Ensure the first dragged tab always stays in the visible index range. |
| 1183 return std::min(index, last_insertion_point); | 1183 return std::min(index, last_insertion_point); |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 bool TabDragController::ShouldDragToNextStackedTab( | 1186 bool TabDragController::ShouldDragToNextStackedTab( |
| 1187 const gfx::Rect& dragged_bounds, | 1187 const gfx::Rect& dragged_bounds, |
| 1188 int index) const { | 1188 int index) const { |
| 1189 if (index + 1 >= attached_tabstrip_->tab_count() || | 1189 if (index + 1 >= attached_tabstrip_->GetTabCount() || |
| 1190 !attached_tabstrip_->touch_layout_->IsStacked(index + 1) || | 1190 !attached_tabstrip_->touch_layout_->IsStacked(index + 1) || |
| 1191 (mouse_move_direction_ & kMovedMouseRight) == 0) | 1191 (mouse_move_direction_ & kMovedMouseRight) == 0) |
| 1192 return false; | 1192 return false; |
| 1193 | 1193 |
| 1194 int active_x = attached_tabstrip_->ideal_bounds(index).x(); | 1194 int active_x = attached_tabstrip_->ideal_bounds(index).x(); |
| 1195 int next_x = attached_tabstrip_->ideal_bounds(index + 1).x(); | 1195 int next_x = attached_tabstrip_->ideal_bounds(index + 1).x(); |
| 1196 int mid_x = std::min(next_x - kStackedDistance, | 1196 int mid_x = std::min(next_x - kStackedDistance, |
| 1197 active_x + (next_x - active_x) / 4); | 1197 active_x + (next_x - active_x) / 4); |
| 1198 // TODO(pkasting): Should this add Tab::leading_width_for_drag() as | 1198 // TODO(pkasting): Should this add Tab::leading_width_for_drag() as |
| 1199 // GetInsertionIndexFrom() does? | 1199 // GetInsertionIndexFrom() does? |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1226 int index = GetInsertionIndexFromReversed(dragged_bounds, active_index); | 1226 int index = GetInsertionIndexFromReversed(dragged_bounds, active_index); |
| 1227 if (index != active_index) | 1227 if (index != active_index) |
| 1228 return index; | 1228 return index; |
| 1229 if (index == -1) | 1229 if (index == -1) |
| 1230 return GetInsertionIndexFrom(dragged_bounds, active_index + 1); | 1230 return GetInsertionIndexFrom(dragged_bounds, active_index + 1); |
| 1231 | 1231 |
| 1232 // The position to drag to corresponds to the active tab. If the next/previous | 1232 // The position to drag to corresponds to the active tab. If the next/previous |
| 1233 // tab is stacked, then shorten the distance used to determine insertion | 1233 // tab is stacked, then shorten the distance used to determine insertion |
| 1234 // bounds. We do this as GetInsertionIndexFrom() uses the bounds of the | 1234 // bounds. We do this as GetInsertionIndexFrom() uses the bounds of the |
| 1235 // tabs. When tabs are stacked the next/previous tab is on top of the tab. | 1235 // tabs. When tabs are stacked the next/previous tab is on top of the tab. |
| 1236 if (active_index + 1 < attached_tabstrip_->tab_count() && | 1236 if (active_index + 1 < attached_tabstrip_->GetTabCount() && |
| 1237 touch_layout->IsStacked(active_index + 1)) { | 1237 touch_layout->IsStacked(active_index + 1)) { |
| 1238 index = GetInsertionIndexFrom(dragged_bounds, active_index + 1); | 1238 index = GetInsertionIndexFrom(dragged_bounds, active_index + 1); |
| 1239 if (index == -1 && ShouldDragToNextStackedTab(dragged_bounds, active_index)) | 1239 if (index == -1 && ShouldDragToNextStackedTab(dragged_bounds, active_index)) |
| 1240 index = active_index + 1; | 1240 index = active_index + 1; |
| 1241 else if (index == -1) | 1241 else if (index == -1) |
| 1242 index = active_index; | 1242 index = active_index; |
| 1243 } else if (ShouldDragToPreviousStackedTab(dragged_bounds, active_index)) { | 1243 } else if (ShouldDragToPreviousStackedTab(dragged_bounds, active_index)) { |
| 1244 index = active_index - 1; | 1244 index = active_index - 1; |
| 1245 } | 1245 } |
| 1246 return index; | 1246 return index; |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 it != browser_list->end(); ++it) { | 1760 it != browser_list->end(); ++it) { |
| 1761 if ((*it)->tab_strip_model()->empty()) | 1761 if ((*it)->tab_strip_model()->empty()) |
| 1762 exclude.insert((*it)->window()->GetNativeWindow()); | 1762 exclude.insert((*it)->window()->GetNativeWindow()); |
| 1763 } | 1763 } |
| 1764 #endif | 1764 #endif |
| 1765 return GetLocalProcessWindowAtPoint(host_desktop_type_, | 1765 return GetLocalProcessWindowAtPoint(host_desktop_type_, |
| 1766 screen_point, | 1766 screen_point, |
| 1767 exclude); | 1767 exclude); |
| 1768 | 1768 |
| 1769 } | 1769 } |
| OLD | NEW |