Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(781)

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller.cc

Issue 331343002: Misc. cleanup: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 for (size_t i = 0; i < drag_data_.size(); ++i) 789 for (size_t i = 0; i < drag_data_.size(); ++i)
790 tabs[i] = drag_data_[i].attached_tab; 790 tabs[i] = drag_data_[i].attached_tab;
791 791
792 bool did_layout = false; 792 bool did_layout = false;
793 // Update the model, moving the WebContents from one index to another. Do this 793 // Update the model, moving the WebContents from one index to another. Do this
794 // only if we have moved a minimum distance since the last reorder (to prevent 794 // only if we have moved a minimum distance since the last reorder (to prevent
795 // jitter) or if this the first move and the tabs are not consecutive. 795 // jitter) or if this the first move and the tabs are not consecutive.
796 if ((abs(point_in_screen.x() - last_move_screen_loc_) > threshold || 796 if ((abs(point_in_screen.x() - last_move_screen_loc_) > threshold ||
797 (initial_move_ && !AreTabsConsecutive()))) { 797 (initial_move_ && !AreTabsConsecutive()))) {
798 TabStripModel* attached_model = GetModel(attached_tabstrip_); 798 TabStripModel* attached_model = GetModel(attached_tabstrip_);
799 gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_point); 799 int to_index = GetInsertionIndexForDraggedBounds(
800 int to_index = GetInsertionIndexForDraggedBounds(bounds); 800 GetDraggedViewTabStripBounds(dragged_view_point));
Peter Kasting 2014/06/17 03:16:18 I didn't think the old code was bad, but while wor
801 bool do_move = true; 801 bool do_move = true;
802 // While dragging within a tabstrip the expectation is the insertion index 802 // While dragging within a tabstrip the expectation is the insertion index
803 // is based on the left edge of the tabs being dragged. OTOH when dragging 803 // is based on the left edge of the tabs being dragged. OTOH when dragging
804 // into a new tabstrip (attaching) the expectation is the insertion index is 804 // into a new tabstrip (attaching) the expectation is the insertion index is
805 // based on the cursor. This proves problematic as insertion may change the 805 // based on the cursor. This proves problematic as insertion may change the
806 // size of the tabs, resulting in the index calculated before the insert 806 // size of the tabs, resulting in the index calculated before the insert
807 // differing from the index calculated after the insert. To alleviate this 807 // differing from the index calculated after the insert. To alleviate this
808 // the index is chosen before insertion, and subsequently a new index is 808 // the index is chosen before insertion, and subsequently a new index is
809 // only used once the mouse moves enough such that the index changes based 809 // only used once the mouse moves enough such that the index changes based
810 // on the direction the mouse moved relative to |attach_x_| (smaller 810 // on the direction the mouse moved relative to |attach_x_| (smaller
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 997
998 // Figure out where to insert the tab based on the bounds of the dragged 998 // Figure out where to insert the tab based on the bounds of the dragged
999 // representation and the ideal bounds of the other Tabs already in the 999 // representation and the ideal bounds of the other Tabs already in the
1000 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are 1000 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are
1001 // changing due to animation). 1001 // changing due to animation).
1002 gfx::Point tab_strip_point(point_in_screen); 1002 gfx::Point tab_strip_point(point_in_screen);
1003 views::View::ConvertPointFromScreen(attached_tabstrip_, &tab_strip_point); 1003 views::View::ConvertPointFromScreen(attached_tabstrip_, &tab_strip_point);
1004 tab_strip_point.set_x( 1004 tab_strip_point.set_x(
1005 attached_tabstrip_->GetMirroredXInView(tab_strip_point.x())); 1005 attached_tabstrip_->GetMirroredXInView(tab_strip_point.x()));
1006 tab_strip_point.Offset(0, -mouse_offset_.y()); 1006 tab_strip_point.Offset(0, -mouse_offset_.y());
1007 gfx::Rect bounds = GetDraggedViewTabStripBounds(tab_strip_point); 1007 int index = GetInsertionIndexForDraggedBounds(
1008 int index = GetInsertionIndexForDraggedBounds(bounds); 1008 GetDraggedViewTabStripBounds(tab_strip_point));
1009 attach_index_ = index; 1009 attach_index_ = index;
1010 attach_x_ = tab_strip_point.x(); 1010 attach_x_ = tab_strip_point.x();
1011 base::AutoReset<bool> setter(&is_mutating_, true); 1011 base::AutoReset<bool> setter(&is_mutating_, true);
1012 for (size_t i = 0; i < drag_data_.size(); ++i) { 1012 for (size_t i = 0; i < drag_data_.size(); ++i) {
1013 int add_types = TabStripModel::ADD_NONE; 1013 int add_types = TabStripModel::ADD_NONE;
1014 if (attached_tabstrip_->touch_layout_.get()) { 1014 if (attached_tabstrip_->touch_layout_.get()) {
1015 // StackedTabStripLayout positions relative to the active tab, if we 1015 // StackedTabStripLayout positions relative to the active tab, if we
1016 // don't add the tab as active things bounce around. 1016 // don't add the tab as active things bounce around.
1017 DCHECK_EQ(1u, drag_data_.size()); 1017 DCHECK_EQ(1u, drag_data_.size());
1018 add_types |= TabStripModel::ADD_ACTIVE; 1018 add_types |= TabStripModel::ADD_ACTIVE;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 } else if (dragged_bounds.x() >= left_half.x() && 1259 } else if (dragged_bounds.x() >= left_half.x() &&
1260 dragged_bounds.x() < left_half.right()) { 1260 dragged_bounds.x() < left_half.right()) {
1261 return i; 1261 return i;
1262 } 1262 }
1263 } 1263 }
1264 return -1; 1264 return -1;
1265 } 1265 }
1266 1266
1267 int TabDragController::GetInsertionIndexForDraggedBounds( 1267 int TabDragController::GetInsertionIndexForDraggedBounds(
1268 const gfx::Rect& dragged_bounds) const { 1268 const gfx::Rect& dragged_bounds) const {
1269 // If the strip has no tabs, the only position to insert at is 0.
1270 const int tab_count = attached_tabstrip_->tab_count();
1271 if (!tab_count)
1272 return 0;
1273
1269 int index = -1; 1274 int index = -1;
1270 if (attached_tabstrip_->touch_layout_.get()) { 1275 if (attached_tabstrip_->touch_layout_.get()) {
1271 index = GetInsertionIndexForDraggedBoundsStacked(dragged_bounds); 1276 index = GetInsertionIndexForDraggedBoundsStacked(dragged_bounds);
1272 if (index != -1) { 1277 if (index != -1) {
1273 // Only move the tab to the left/right if the user actually moved the 1278 // Only move the tab to the left/right if the user actually moved the
1274 // mouse that way. This is necessary as tabs with stacked tabs 1279 // mouse that way. This is necessary as tabs with stacked tabs
1275 // before/after them have multiple drag positions. 1280 // before/after them have multiple drag positions.
1276 int active_index = attached_tabstrip_->touch_layout_->active_index(); 1281 int active_index = attached_tabstrip_->touch_layout_->active_index();
1277 if ((index < active_index && 1282 if ((index < active_index &&
1278 (mouse_move_direction_ & kMovedMouseLeft) == 0) || 1283 (mouse_move_direction_ & kMovedMouseLeft) == 0) ||
1279 (index > active_index && 1284 (index > active_index &&
1280 (mouse_move_direction_ & kMovedMouseRight) == 0)) { 1285 (mouse_move_direction_ & kMovedMouseRight) == 0)) {
1281 index = active_index; 1286 index = active_index;
1282 } 1287 }
1283 } 1288 }
1284 } else { 1289 } else {
1285 index = GetInsertionIndexFrom(dragged_bounds, 0, 1); 1290 index = GetInsertionIndexFrom(dragged_bounds, 0, 1);
1286 } 1291 }
1287 if (index == -1) { 1292 if (index == -1) {
1288 int tab_count = attached_tabstrip_->tab_count(); 1293 const int last_tab_right =
1289 int right_tab_x = tab_count == 0 ? 0 :
1290 attached_tabstrip_->ideal_bounds(tab_count - 1).right(); 1294 attached_tabstrip_->ideal_bounds(tab_count - 1).right();
1291 if (dragged_bounds.right() > right_tab_x) { 1295 index = (dragged_bounds.right() > last_tab_right) ? tab_count : 0;
Peter Kasting 2014/06/17 03:16:18 Note that this assumes attached_tabstrip_->tab_cou
sky 2014/06/17 15:42:42 Yes, they should be equal (with the exception of t
1292 index = GetModel(attached_tabstrip_)->count();
1293 } else {
1294 index = 0;
1295 }
1296 } 1296 }
1297 1297
1298 if (!drag_data_[0].attached_tab) { 1298 if (!drag_data_[0].attached_tab) {
1299 // If 'attached_tab' is NULL, it means we're in the process of attaching and 1299 // If 'attached_tab' is NULL, it means we're in the process of attaching and
1300 // don't need to constrain the index. 1300 // don't need to constrain the index.
1301 return index; 1301 return index;
1302 } 1302 }
1303 1303
1304 int max_index = GetModel(attached_tabstrip_)->count() - 1304 int max_index = GetModel(attached_tabstrip_)->count() -
1305 static_cast<int>(drag_data_.size()); 1305 static_cast<int>(drag_data_.size());
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 break; 1793 break;
1794 } 1794 }
1795 default: 1795 default:
1796 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. 1796 break; // Nothing to do for DETACH_ABOVE_OR_BELOW.
1797 } 1797 }
1798 1798
1799 // To account for the extra vertical on restored windows that is absent on 1799 // To account for the extra vertical on restored windows that is absent on
1800 // maximized windows, add an additional vertical offset extracted from the tab 1800 // maximized windows, add an additional vertical offset extracted from the tab
1801 // strip. 1801 // strip.
1802 if (source->GetWidget()->IsMaximized()) 1802 if (source->GetWidget()->IsMaximized())
1803 new_bounds.Offset(0, -source->button_v_offset()); 1803 new_bounds.Offset(0, -source->kNewTabButtonVerticalOffset);
1804 return new_bounds; 1804 return new_bounds;
1805 } 1805 }
1806 1806
1807 void TabDragController::AdjustBrowserAndTabBoundsForDrag( 1807 void TabDragController::AdjustBrowserAndTabBoundsForDrag(
1808 int last_tabstrip_width, 1808 int last_tabstrip_width,
1809 const gfx::Point& point_in_screen, 1809 const gfx::Point& point_in_screen,
1810 std::vector<gfx::Rect>* drag_bounds) { 1810 std::vector<gfx::Rect>* drag_bounds) {
1811 attached_tabstrip_->InvalidateLayout(); 1811 attached_tabstrip_->InvalidateLayout();
1812 attached_tabstrip_->DoLayout(); 1812 attached_tabstrip_->DoLayout();
1813 const int dragged_tabstrip_width = attached_tabstrip_->tab_area_width(); 1813 const int dragged_tabstrip_width = attached_tabstrip_->tab_area_width();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 it != browser_list->end(); ++it) { 1921 it != browser_list->end(); ++it) {
1922 if ((*it)->tab_strip_model()->empty()) 1922 if ((*it)->tab_strip_model()->empty())
1923 exclude.insert((*it)->window()->GetNativeWindow()); 1923 exclude.insert((*it)->window()->GetNativeWindow());
1924 } 1924 }
1925 #endif 1925 #endif
1926 return GetLocalProcessWindowAtPoint(host_desktop_type_, 1926 return GetLocalProcessWindowAtPoint(host_desktop_type_,
1927 screen_point, 1927 screen_point,
1928 exclude); 1928 exclude);
1929 1929
1930 } 1930 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698