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

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

Issue 10827022: Fix coordinates in tab detach &drag code and multi window resizer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 5 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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/callback.h" 10 #include "base/callback.h"
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 const std::vector<BaseTab*>& tabs, 386 const std::vector<BaseTab*>& tabs,
387 const gfx::Point& mouse_offset, 387 const gfx::Point& mouse_offset,
388 int source_tab_offset, 388 int source_tab_offset,
389 const TabStripSelectionModel& initial_selection_model, 389 const TabStripSelectionModel& initial_selection_model,
390 DetachBehavior detach_behavior, 390 DetachBehavior detach_behavior,
391 MoveBehavior move_behavior) { 391 MoveBehavior move_behavior) {
392 DCHECK(!tabs.empty()); 392 DCHECK(!tabs.empty());
393 DCHECK(std::find(tabs.begin(), tabs.end(), source_tab) != tabs.end()); 393 DCHECK(std::find(tabs.begin(), tabs.end(), source_tab) != tabs.end());
394 source_tabstrip_ = source_tabstrip; 394 source_tabstrip_ = source_tabstrip;
395 source_tab_offset_ = source_tab_offset; 395 source_tab_offset_ = source_tab_offset;
396 start_screen_point_ = gfx::Point(source_tab_offset, mouse_offset.y()); 396 start_point_in_screen_ = gfx::Point(source_tab_offset, mouse_offset.y());
397 views::View::ConvertPointToScreen(source_tab, &start_screen_point_); 397 views::View::ConvertPointToScreen(source_tab, &start_point_in_screen_);
398 mouse_offset_ = mouse_offset; 398 mouse_offset_ = mouse_offset;
399 detach_behavior_ = detach_behavior; 399 detach_behavior_ = detach_behavior;
400 move_behavior_ = move_behavior; 400 move_behavior_ = move_behavior;
401 last_screen_point_ = start_screen_point_; 401 last_point_in_screen_ = start_point_in_screen_;
402 last_move_screen_loc_ = start_screen_point_.x(); 402 last_move_screen_loc_ = start_point_in_screen_.x();
403 initial_tab_positions_ = source_tabstrip->GetTabXCoordinates(); 403 initial_tab_positions_ = source_tabstrip->GetTabXCoordinates();
404 if (detach_into_browser_) 404 if (detach_into_browser_)
405 GetModel(source_tabstrip_)->AddObserver(this); 405 GetModel(source_tabstrip_)->AddObserver(this);
406 406
407 drag_data_.resize(tabs.size()); 407 drag_data_.resize(tabs.size());
408 for (size_t i = 0; i < tabs.size(); ++i) 408 for (size_t i = 0; i < tabs.size(); ++i)
409 InitTabDragData(tabs[i], &(drag_data_[i])); 409 InitTabDragData(tabs[i], &(drag_data_[i]));
410 source_tab_index_ = 410 source_tab_index_ =
411 std::find(tabs.begin(), tabs.end(), source_tab) - tabs.begin(); 411 std::find(tabs.begin(), tabs.end(), source_tab) - tabs.begin();
412 412
(...skipping 19 matching lines...) Expand all
432 return instance_ && instance_->active(); 432 return instance_ && instance_->active();
433 } 433 }
434 434
435 void TabDragController::SetMoveBehavior(MoveBehavior behavior) { 435 void TabDragController::SetMoveBehavior(MoveBehavior behavior) {
436 if (started_drag()) 436 if (started_drag())
437 return; 437 return;
438 438
439 move_behavior_ = behavior; 439 move_behavior_ = behavior;
440 } 440 }
441 441
442 void TabDragController::Drag(const gfx::Point& screen_point) { 442 void TabDragController::Drag(const gfx::Point& point_in_screen) {
443 #if defined(OS_WIN) && !defined(USE_AURA) 443 #if defined(OS_WIN) && !defined(USE_AURA)
444 // Windows coordinates are 16 bit values. When we hide the frame we move it to 444 // Windows coordinates are 16 bit values. When we hide the frame we move it to
445 // the max x/y coordinate. If the distance between the hidden frame and the 445 // the max x/y coordinate. If the distance between the hidden frame and the
446 // current mouse coordinate is greater than 32k then the coordinate passed to 446 // current mouse coordinate is greater than 32k then the coordinate passed to
447 // the mouse handler wraps and we drag to the wrong place. For this reason we 447 // the mouse handler wraps and we drag to the wrong place. For this reason we
448 // ignore the coordinates and use the actual cursor position. 448 // ignore the coordinates and use the actual cursor position.
449 // NOTE: this works for touch too as dragging with touch updates the mouse 449 // NOTE: this works for touch too as dragging with touch updates the mouse
450 // position. 450 // position.
451 gfx::Point real_screen_point(GetCursorScreenPoint()); 451 gfx::Point real_point_in_screen(GetCursorScreenPoint());
452 #else 452 #else
453 gfx::Point real_screen_point(screen_point); 453 gfx::Point real_point_in_screen(point_in_screen);
454 #endif 454 #endif
455 bring_to_front_timer_.Stop(); 455 bring_to_front_timer_.Stop();
456 move_stacked_timer_.Stop(); 456 move_stacked_timer_.Stop();
457 457
458 if (waiting_for_run_loop_to_exit_) 458 if (waiting_for_run_loop_to_exit_)
459 return; 459 return;
460 460
461 if (!started_drag_) { 461 if (!started_drag_) {
462 if (!CanStartDrag(real_screen_point)) 462 if (!CanStartDrag(real_point_in_screen))
463 return; // User hasn't dragged far enough yet. 463 return; // User hasn't dragged far enough yet.
464 464
465 started_drag_ = true; 465 started_drag_ = true;
466 SaveFocus(); 466 SaveFocus();
467 Attach(source_tabstrip_, gfx::Point()); 467 Attach(source_tabstrip_, gfx::Point());
468 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == 468 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) ==
469 GetModel(source_tabstrip_)->count()) { 469 GetModel(source_tabstrip_)->count()) {
470 RunMoveLoop(); // Runs a nested loop, returning when done. 470 RunMoveLoop(); // Runs a nested loop, returning when done.
471 return; 471 return;
472 } 472 }
473 } 473 }
474 474
475 ContinueDragging(real_screen_point); 475 ContinueDragging(real_point_in_screen);
476 } 476 }
477 477
478 void TabDragController::EndDrag(bool canceled) { 478 void TabDragController::EndDrag(bool canceled) {
479 EndDragImpl(canceled && source_tabstrip_ ? CANCELED : NORMAL); 479 EndDragImpl(canceled && source_tabstrip_ ? CANCELED : NORMAL);
480 } 480 }
481 481
482 void TabDragController::InitTabDragData(BaseTab* tab, 482 void TabDragController::InitTabDragData(BaseTab* tab,
483 TabDragData* drag_data) { 483 TabDragData* drag_data) {
484 drag_data->source_model_index = 484 drag_data->source_model_index =
485 source_tabstrip_->GetModelIndexOfBaseTab(tab); 485 source_tabstrip_->GetModelIndexOfBaseTab(tab);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 create_point.set_x(work_area.right()); 661 create_point.set_x(work_area.right());
662 if (create_point.y() < work_area.y()) 662 if (create_point.y() < work_area.y())
663 create_point.set_y(work_area.y()); 663 create_point.set_y(work_area.y());
664 else if (create_point.y() > work_area.bottom()) 664 else if (create_point.y() > work_area.bottom())
665 create_point.set_y(work_area.bottom()); 665 create_point.set_y(work_area.bottom());
666 } 666 }
667 return gfx::Point(create_point.x() - window_create_point_.x(), 667 return gfx::Point(create_point.x() - window_create_point_.x(),
668 create_point.y() - window_create_point_.y()); 668 create_point.y() - window_create_point_.y());
669 } 669 }
670 670
671 void TabDragController::UpdateDockInfo(const gfx::Point& screen_point) { 671 void TabDragController::UpdateDockInfo(const gfx::Point& point_in_screen) {
672 // Update the DockInfo for the current mouse coordinates. 672 // Update the DockInfo for the current mouse coordinates.
673 DockInfo dock_info = GetDockInfoAtPoint(screen_point); 673 DockInfo dock_info = GetDockInfoAtPoint(point_in_screen);
674 if (!dock_info.equals(dock_info_)) { 674 if (!dock_info.equals(dock_info_)) {
675 // DockInfo for current position differs. 675 // DockInfo for current position differs.
676 if (dock_info_.type() != DockInfo::NONE && 676 if (dock_info_.type() != DockInfo::NONE &&
677 !dock_controllers_.empty()) { 677 !dock_controllers_.empty()) {
678 // Hide old visual indicator. 678 // Hide old visual indicator.
679 dock_controllers_.back()->Hide(); 679 dock_controllers_.back()->Hide();
680 } 680 }
681 dock_info_ = dock_info; 681 dock_info_ = dock_info;
682 if (dock_info_.type() != DockInfo::NONE) { 682 if (dock_info_.type() != DockInfo::NONE) {
683 // Show new docking position. 683 // Show new docking position.
(...skipping 19 matching lines...) Expand all
703 old_focused_view_ = source_tabstrip_->GetFocusManager()->GetFocusedView(); 703 old_focused_view_ = source_tabstrip_->GetFocusManager()->GetFocusedView();
704 source_tabstrip_->GetFocusManager()->SetFocusedView(source_tabstrip_); 704 source_tabstrip_->GetFocusManager()->SetFocusedView(source_tabstrip_);
705 } 705 }
706 706
707 void TabDragController::RestoreFocus() { 707 void TabDragController::RestoreFocus() {
708 if (old_focused_view_ && attached_tabstrip_ == source_tabstrip_) 708 if (old_focused_view_ && attached_tabstrip_ == source_tabstrip_)
709 old_focused_view_->GetFocusManager()->SetFocusedView(old_focused_view_); 709 old_focused_view_->GetFocusManager()->SetFocusedView(old_focused_view_);
710 old_focused_view_ = NULL; 710 old_focused_view_ = NULL;
711 } 711 }
712 712
713 bool TabDragController::CanStartDrag(const gfx::Point& screen_point) const { 713 bool TabDragController::CanStartDrag(const gfx::Point& point_in_screen) const {
714 // Determine if the mouse has moved beyond a minimum elasticity distance in 714 // Determine if the mouse has moved beyond a minimum elasticity distance in
715 // any direction from the starting point. 715 // any direction from the starting point.
716 static const int kMinimumDragDistance = 10; 716 static const int kMinimumDragDistance = 10;
717 int x_offset = abs(screen_point.x() - start_screen_point_.x()); 717 int x_offset = abs(point_in_screen.x() - start_point_in_screen_.x());
718 int y_offset = abs(screen_point.y() - start_screen_point_.y()); 718 int y_offset = abs(point_in_screen.y() - start_point_in_screen_.y());
719 return sqrt(pow(static_cast<float>(x_offset), 2) + 719 return sqrt(pow(static_cast<float>(x_offset), 2) +
720 pow(static_cast<float>(y_offset), 2)) > kMinimumDragDistance; 720 pow(static_cast<float>(y_offset), 2)) > kMinimumDragDistance;
721 } 721 }
722 722
723 void TabDragController::ContinueDragging(const gfx::Point& screen_point) { 723 void TabDragController::ContinueDragging(const gfx::Point& point_in_screen) {
724 DCHECK(!detach_into_browser_ || attached_tabstrip_); 724 DCHECK(!detach_into_browser_ || attached_tabstrip_);
725 725
726 TabStrip* target_tabstrip = detach_behavior_ == DETACHABLE ? 726 TabStrip* target_tabstrip = detach_behavior_ == DETACHABLE ?
727 GetTabStripForPoint(screen_point) : source_tabstrip_; 727 GetTabStripForPoint(point_in_screen) : source_tabstrip_;
728 bool tab_strip_changed = (target_tabstrip != attached_tabstrip_); 728 bool tab_strip_changed = (target_tabstrip != attached_tabstrip_);
729 729
730 if (attached_tabstrip_) { 730 if (attached_tabstrip_) {
731 int move_delta = screen_point.x() - last_screen_point_.x(); 731 int move_delta = point_in_screen.x() - last_point_in_screen_.x();
732 if (move_delta > 0) 732 if (move_delta > 0)
733 mouse_move_direction_ |= kMovedMouseRight; 733 mouse_move_direction_ |= kMovedMouseRight;
734 else if (move_delta < 0) 734 else if (move_delta < 0)
735 mouse_move_direction_ |= kMovedMouseLeft; 735 mouse_move_direction_ |= kMovedMouseLeft;
736 } 736 }
737 last_screen_point_ = screen_point; 737 last_point_in_screen_ = point_in_screen;
738 738
739 if (tab_strip_changed) { 739 if (tab_strip_changed) {
740 if (detach_into_browser_ && 740 if (detach_into_browser_ &&
741 DragBrowserToNewTabStrip(target_tabstrip, screen_point) == 741 DragBrowserToNewTabStrip(target_tabstrip, point_in_screen) ==
742 DRAG_BROWSER_RESULT_STOP) { 742 DRAG_BROWSER_RESULT_STOP) {
743 return; 743 return;
744 } else if (!detach_into_browser_) { 744 } else if (!detach_into_browser_) {
745 if (attached_tabstrip_) 745 if (attached_tabstrip_)
746 Detach(RELEASE_CAPTURE); 746 Detach(RELEASE_CAPTURE);
747 if (target_tabstrip) 747 if (target_tabstrip)
748 Attach(target_tabstrip, screen_point); 748 Attach(target_tabstrip, point_in_screen);
749 } 749 }
750 } 750 }
751 if (view_.get() || is_dragging_window_) { 751 if (view_.get() || is_dragging_window_) {
752 static_cast<base::Timer*>(&bring_to_front_timer_)->Start(FROM_HERE, 752 static_cast<base::Timer*>(&bring_to_front_timer_)->Start(FROM_HERE,
753 base::TimeDelta::FromMilliseconds(kBringToFrontDelay), 753 base::TimeDelta::FromMilliseconds(kBringToFrontDelay),
754 base::Bind(&TabDragController::BringWindowUnderPointToFront, 754 base::Bind(&TabDragController::BringWindowUnderPointToFront,
755 base::Unretained(this), screen_point)); 755 base::Unretained(this), point_in_screen));
756 } 756 }
757 757
758 UpdateDockInfo(screen_point); 758 UpdateDockInfo(point_in_screen);
759 759
760 if (!is_dragging_window_) { 760 if (!is_dragging_window_) {
761 if (attached_tabstrip_) { 761 if (attached_tabstrip_) {
762 if (move_only()) { 762 if (move_only()) {
763 DragActiveTabStacked(screen_point); 763 DragActiveTabStacked(point_in_screen);
764 } else { 764 } else {
765 MoveAttached(screen_point); 765 MoveAttached(point_in_screen);
766 if (tab_strip_changed) { 766 if (tab_strip_changed) {
767 // Move the corresponding window to the front. We do this after the 767 // Move the corresponding window to the front. We do this after the
768 // move as on windows activate triggers a synchronous paint. 768 // move as on windows activate triggers a synchronous paint.
769 attached_tabstrip_->GetWidget()->Activate(); 769 attached_tabstrip_->GetWidget()->Activate();
770 } 770 }
771 } 771 }
772 } else { 772 } else {
773 MoveDetached(screen_point); 773 MoveDetached(point_in_screen);
774 } 774 }
775 } 775 }
776 } 776 }
777 777
778 TabDragController::DragBrowserResultType 778 TabDragController::DragBrowserResultType
779 TabDragController::DragBrowserToNewTabStrip( 779 TabDragController::DragBrowserToNewTabStrip(
780 TabStrip* target_tabstrip, 780 TabStrip* target_tabstrip,
781 const gfx::Point& screen_point) { 781 const gfx::Point& point_in_screen) {
782 if (!target_tabstrip) { 782 if (!target_tabstrip) {
783 DetachIntoNewBrowserAndRunMoveLoop(screen_point); 783 DetachIntoNewBrowserAndRunMoveLoop(point_in_screen);
784 return DRAG_BROWSER_RESULT_STOP; 784 return DRAG_BROWSER_RESULT_STOP;
785 } 785 }
786 if (is_dragging_window_) { 786 if (is_dragging_window_) {
787 #if defined(USE_ASH) 787 #if defined(USE_ASH)
788 // ReleaseCapture() is going to result in calling back to us (because it 788 // ReleaseCapture() is going to result in calling back to us (because it
789 // results in a move). That'll cause all sorts of problems. Reset the 789 // results in a move). That'll cause all sorts of problems. Reset the
790 // observer so we don't get notified and process the event. 790 // observer so we don't get notified and process the event.
791 move_loop_widget_->RemoveObserver(this); 791 move_loop_widget_->RemoveObserver(this);
792 move_loop_widget_ = NULL; 792 move_loop_widget_ = NULL;
793 #endif 793 #endif
(...skipping 18 matching lines...) Expand all
812 browser_widget->EndMoveLoop(); 812 browser_widget->EndMoveLoop();
813 813
814 // Ideally we would always swap the tabs now, but on windows it seems that 814 // Ideally we would always swap the tabs now, but on windows it seems that
815 // running the move loop implicitly activates the window when done, leading 815 // running the move loop implicitly activates the window when done, leading
816 // to all sorts of flicker. So, on windows, instead we process the move 816 // to all sorts of flicker. So, on windows, instead we process the move
817 // after the loop completes. But on chromeos, we can do tab swapping now to 817 // after the loop completes. But on chromeos, we can do tab swapping now to
818 // avoid the tab flashing issue(crbug.com/116329). 818 // avoid the tab flashing issue(crbug.com/116329).
819 #if defined(USE_ASH) 819 #if defined(USE_ASH)
820 is_dragging_window_ = false; 820 is_dragging_window_ = false;
821 Detach(DONT_RELEASE_CAPTURE); 821 Detach(DONT_RELEASE_CAPTURE);
822 Attach(target_tabstrip, screen_point); 822 Attach(target_tabstrip, point_in_screen);
823 // Move the tabs into position. 823 // Move the tabs into position.
824 MoveAttached(screen_point); 824 MoveAttached(point_in_screen);
825 attached_tabstrip_->GetWidget()->Activate(); 825 attached_tabstrip_->GetWidget()->Activate();
826 #else 826 #else
827 tab_strip_to_attach_to_after_exit_ = target_tabstrip; 827 tab_strip_to_attach_to_after_exit_ = target_tabstrip;
828 #endif 828 #endif
829 829
830 waiting_for_run_loop_to_exit_ = true; 830 waiting_for_run_loop_to_exit_ = true;
831 end_run_loop_behavior_ = END_RUN_LOOP_CONTINUE_DRAGGING; 831 end_run_loop_behavior_ = END_RUN_LOOP_CONTINUE_DRAGGING;
832 return DRAG_BROWSER_RESULT_STOP; 832 return DRAG_BROWSER_RESULT_STOP;
833 } 833 }
834 Detach(DONT_RELEASE_CAPTURE); 834 Detach(DONT_RELEASE_CAPTURE);
835 Attach(target_tabstrip, screen_point); 835 Attach(target_tabstrip, point_in_screen);
836 return DRAG_BROWSER_RESULT_CONTINUE; 836 return DRAG_BROWSER_RESULT_CONTINUE;
837 } 837 }
838 838
839 void TabDragController::DragActiveTabStacked( 839 void TabDragController::DragActiveTabStacked(
840 const gfx::Point& screen_point) { 840 const gfx::Point& point_in_screen) {
841 if (attached_tabstrip_->tab_count() != 841 if (attached_tabstrip_->tab_count() !=
842 static_cast<int>(initial_tab_positions_.size())) 842 static_cast<int>(initial_tab_positions_.size()))
843 return; // TODO: should cancel drag if this happens. 843 return; // TODO: should cancel drag if this happens.
844 844
845 int delta = screen_point.x() - start_screen_point_.x(); 845 int delta = point_in_screen.x() - start_point_in_screen_.x();
846 attached_tabstrip_->DragActiveTab(initial_tab_positions_, delta); 846 attached_tabstrip_->DragActiveTab(initial_tab_positions_, delta);
847 } 847 }
848 848
849 void TabDragController::MoveAttachedToNextStackedIndex( 849 void TabDragController::MoveAttachedToNextStackedIndex(
850 const gfx::Point& screen_point) { 850 const gfx::Point& point_in_screen) {
851 int index = attached_tabstrip_->touch_layout_->active_index(); 851 int index = attached_tabstrip_->touch_layout_->active_index();
852 if (index + 1 >= attached_tabstrip_->tab_count()) 852 if (index + 1 >= attached_tabstrip_->tab_count())
853 return; 853 return;
854 854
855 GetModel(attached_tabstrip_)->MoveSelectedTabsTo(index + 1); 855 GetModel(attached_tabstrip_)->MoveSelectedTabsTo(index + 1);
856 StartMoveStackedTimerIfNecessary(screen_point, kMoveAttachedSubsequentDelay); 856 StartMoveStackedTimerIfNecessary(point_in_screen,
857 kMoveAttachedSubsequentDelay);
857 } 858 }
858 859
859 void TabDragController::MoveAttachedToPreviousStackedIndex( 860 void TabDragController::MoveAttachedToPreviousStackedIndex(
860 const gfx::Point& screen_point) { 861 const gfx::Point& point_in_screen) {
861 int index = attached_tabstrip_->touch_layout_->active_index(); 862 int index = attached_tabstrip_->touch_layout_->active_index();
862 if (index <= attached_tabstrip_->GetMiniTabCount()) 863 if (index <= attached_tabstrip_->GetMiniTabCount())
863 return; 864 return;
864 865
865 GetModel(attached_tabstrip_)->MoveSelectedTabsTo(index - 1); 866 GetModel(attached_tabstrip_)->MoveSelectedTabsTo(index - 1);
866 StartMoveStackedTimerIfNecessary(screen_point, kMoveAttachedSubsequentDelay); 867 StartMoveStackedTimerIfNecessary(point_in_screen,
868 kMoveAttachedSubsequentDelay);
867 } 869 }
868 870
869 void TabDragController::MoveAttached(const gfx::Point& screen_point) { 871 void TabDragController::MoveAttached(const gfx::Point& point_in_screen) {
870 DCHECK(attached_tabstrip_); 872 DCHECK(attached_tabstrip_);
871 DCHECK(!view_.get()); 873 DCHECK(!view_.get());
872 DCHECK(!is_dragging_window_); 874 DCHECK(!is_dragging_window_);
873 875
874 gfx::Point dragged_view_point = GetAttachedDragPoint(screen_point); 876 gfx::Point dragged_view_point = GetAttachedDragPoint(point_in_screen);
875 877
876 // Determine the horizontal move threshold. This is dependent on the width 878 // Determine the horizontal move threshold. This is dependent on the width
877 // of tabs. The smaller the tabs compared to the standard size, the smaller 879 // of tabs. The smaller the tabs compared to the standard size, the smaller
878 // the threshold. 880 // the threshold.
879 int threshold = kHorizontalMoveThreshold; 881 int threshold = kHorizontalMoveThreshold;
880 if (!attached_tabstrip_->touch_layout_.get()) { 882 if (!attached_tabstrip_->touch_layout_.get()) {
881 double unselected, selected; 883 double unselected, selected;
882 attached_tabstrip_->GetCurrentTabWidths(&unselected, &selected); 884 attached_tabstrip_->GetCurrentTabWidths(&unselected, &selected);
883 double ratio = unselected / Tab::GetStandardSize().width(); 885 double ratio = unselected / Tab::GetStandardSize().width();
884 threshold = static_cast<int>(ratio * kHorizontalMoveThreshold); 886 threshold = static_cast<int>(ratio * kHorizontalMoveThreshold);
885 } 887 }
886 // else case: touch tabs never shrink. 888 // else case: touch tabs never shrink.
887 889
888 std::vector<BaseTab*> tabs(drag_data_.size()); 890 std::vector<BaseTab*> tabs(drag_data_.size());
889 for (size_t i = 0; i < drag_data_.size(); ++i) 891 for (size_t i = 0; i < drag_data_.size(); ++i)
890 tabs[i] = drag_data_[i].attached_tab; 892 tabs[i] = drag_data_[i].attached_tab;
891 893
892 bool did_layout = false; 894 bool did_layout = false;
893 // Update the model, moving the WebContents from one index to another. Do this 895 // Update the model, moving the WebContents from one index to another. Do this
894 // only if we have moved a minimum distance since the last reorder (to prevent 896 // only if we have moved a minimum distance since the last reorder (to prevent
895 // jitter) or if this the first move and the tabs are not consecutive. 897 // jitter) or if this the first move and the tabs are not consecutive.
896 if ((abs(screen_point.x() - last_move_screen_loc_) > threshold || 898 if ((abs(point_in_screen.x() - last_move_screen_loc_) > threshold ||
897 (initial_move_ && !AreTabsConsecutive()))) { 899 (initial_move_ && !AreTabsConsecutive()))) {
898 TabStripModel* attached_model = GetModel(attached_tabstrip_); 900 TabStripModel* attached_model = GetModel(attached_tabstrip_);
899 gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_point); 901 gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_point);
900 int to_index = GetInsertionIndexForDraggedBounds(bounds); 902 int to_index = GetInsertionIndexForDraggedBounds(bounds);
901 TabContents* last_contents = drag_data_[drag_data_.size() - 1].contents; 903 TabContents* last_contents = drag_data_[drag_data_.size() - 1].contents;
902 int index_of_last_item = 904 int index_of_last_item =
903 attached_model->GetIndexOfTabContents(last_contents); 905 attached_model->GetIndexOfTabContents(last_contents);
904 if (initial_move_) { 906 if (initial_move_) {
905 // TabStrip determines if the tabs needs to be animated based on model 907 // TabStrip determines if the tabs needs to be animated based on model
906 // position. This means we need to invoke LayoutDraggedTabsAt before 908 // position. This means we need to invoke LayoutDraggedTabsAt before
907 // changing the model. 909 // changing the model.
908 attached_tabstrip_->LayoutDraggedTabsAt( 910 attached_tabstrip_->LayoutDraggedTabsAt(
909 tabs, source_tab_drag_data()->attached_tab, dragged_view_point, 911 tabs, source_tab_drag_data()->attached_tab, dragged_view_point,
910 initial_move_); 912 initial_move_);
911 did_layout = true; 913 did_layout = true;
912 } 914 }
913 attached_model->MoveSelectedTabsTo(to_index); 915 attached_model->MoveSelectedTabsTo(to_index);
914 916
915 // Move may do nothing in certain situations (such as when dragging pinned 917 // Move may do nothing in certain situations (such as when dragging pinned
916 // tabs). Make sure the tabstrip actually changed before updating 918 // tabs). Make sure the tabstrip actually changed before updating
917 // last_move_screen_loc_. 919 // last_move_screen_loc_.
918 if (index_of_last_item != 920 if (index_of_last_item !=
919 attached_model->GetIndexOfTabContents(last_contents)) { 921 attached_model->GetIndexOfTabContents(last_contents)) {
920 last_move_screen_loc_ = screen_point.x(); 922 last_move_screen_loc_ = point_in_screen.x();
921 } 923 }
922 } 924 }
923 925
924 if (!did_layout) { 926 if (!did_layout) {
925 attached_tabstrip_->LayoutDraggedTabsAt( 927 attached_tabstrip_->LayoutDraggedTabsAt(
926 tabs, source_tab_drag_data()->attached_tab, dragged_view_point, 928 tabs, source_tab_drag_data()->attached_tab, dragged_view_point,
927 initial_move_); 929 initial_move_);
928 } 930 }
929 931
930 StartMoveStackedTimerIfNecessary(screen_point, kMoveAttachedInitialDelay); 932 StartMoveStackedTimerIfNecessary(point_in_screen, kMoveAttachedInitialDelay);
931 933
932 initial_move_ = false; 934 initial_move_ = false;
933 } 935 }
934 936
935 void TabDragController::MoveDetached(const gfx::Point& screen_point) { 937 void TabDragController::MoveDetached(const gfx::Point& point_in_screen) {
936 DCHECK(!attached_tabstrip_); 938 DCHECK(!attached_tabstrip_);
937 DCHECK(view_.get()); 939 DCHECK(view_.get());
938 DCHECK(!is_dragging_window_); 940 DCHECK(!is_dragging_window_);
939 941
940 // Move the View. There are no changes to the model if we're detached. 942 // Move the View. There are no changes to the model if we're detached.
941 view_->MoveTo(screen_point); 943 view_->MoveTo(point_in_screen);
942 } 944 }
943 945
944 void TabDragController::StartMoveStackedTimerIfNecessary( 946 void TabDragController::StartMoveStackedTimerIfNecessary(
945 const gfx::Point& screen_point, 947 const gfx::Point& point_in_screen,
946 int delay_ms) { 948 int delay_ms) {
947 DCHECK(attached_tabstrip_); 949 DCHECK(attached_tabstrip_);
948 950
949 TouchTabStripLayout* touch_layout = attached_tabstrip_->touch_layout_.get(); 951 TouchTabStripLayout* touch_layout = attached_tabstrip_->touch_layout_.get();
950 if (!touch_layout) 952 if (!touch_layout)
951 return; 953 return;
952 954
953 gfx::Point dragged_view_point = GetAttachedDragPoint(screen_point); 955 gfx::Point dragged_view_point = GetAttachedDragPoint(point_in_screen);
954 gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_point); 956 gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_point);
955 int index = touch_layout->active_index(); 957 int index = touch_layout->active_index();
956 if (ShouldDragToNextStackedTab(bounds, index)) { 958 if (ShouldDragToNextStackedTab(bounds, index)) {
957 static_cast<base::Timer*>(&move_stacked_timer_)->Start( 959 static_cast<base::Timer*>(&move_stacked_timer_)->Start(
958 FROM_HERE, 960 FROM_HERE,
959 base::TimeDelta::FromMilliseconds(delay_ms), 961 base::TimeDelta::FromMilliseconds(delay_ms),
960 base::Bind(&TabDragController::MoveAttachedToNextStackedIndex, 962 base::Bind(&TabDragController::MoveAttachedToNextStackedIndex,
961 base::Unretained(this), screen_point)); 963 base::Unretained(this), point_in_screen));
962 } else if (ShouldDragToPreviousStackedTab(bounds, index)) { 964 } else if (ShouldDragToPreviousStackedTab(bounds, index)) {
963 static_cast<base::Timer*>(&move_stacked_timer_)->Start( 965 static_cast<base::Timer*>(&move_stacked_timer_)->Start(
964 FROM_HERE, 966 FROM_HERE,
965 base::TimeDelta::FromMilliseconds(delay_ms), 967 base::TimeDelta::FromMilliseconds(delay_ms),
966 base::Bind(&TabDragController::MoveAttachedToPreviousStackedIndex, 968 base::Bind(&TabDragController::MoveAttachedToPreviousStackedIndex,
967 base::Unretained(this), screen_point)); 969 base::Unretained(this), point_in_screen));
968 } 970 }
969 } 971 }
970 972
971 TabDragController::DetachPosition TabDragController::GetDetachPosition( 973 TabDragController::DetachPosition TabDragController::GetDetachPosition(
972 const gfx::Point& screen_point) { 974 const gfx::Point& point_in_screen) {
973 DCHECK(attached_tabstrip_); 975 DCHECK(attached_tabstrip_);
974 gfx::Point attached_point(screen_point); 976 gfx::Point attached_point(point_in_screen);
975 views::View::ConvertPointToView(NULL, attached_tabstrip_, &attached_point); 977 views::View::ConvertPointToView(NULL, attached_tabstrip_, &attached_point);
976 if (attached_point.x() < 0) 978 if (attached_point.x() < 0)
977 return DETACH_BEFORE; 979 return DETACH_BEFORE;
978 if (attached_point.x() >= attached_tabstrip_->width()) 980 if (attached_point.x() >= attached_tabstrip_->width())
979 return DETACH_AFTER; 981 return DETACH_AFTER;
980 return DETACH_ABOVE_OR_BELOW; 982 return DETACH_ABOVE_OR_BELOW;
981 } 983 }
982 984
983 DockInfo TabDragController::GetDockInfoAtPoint(const gfx::Point& screen_point) { 985 DockInfo TabDragController::GetDockInfoAtPoint(
986 const gfx::Point& point_in_screen) {
984 // TODO: add support for dock info when |detach_into_browser_| is true. 987 // TODO: add support for dock info when |detach_into_browser_| is true.
985 if (attached_tabstrip_ || detach_into_browser_) { 988 if (attached_tabstrip_ || detach_into_browser_) {
986 // If the mouse is over a tab strip, don't offer a dock position. 989 // If the mouse is over a tab strip, don't offer a dock position.
987 return DockInfo(); 990 return DockInfo();
988 } 991 }
989 992
990 if (dock_info_.IsValidForPoint(screen_point)) { 993 if (dock_info_.IsValidForPoint(point_in_screen)) {
991 // It's possible any given screen coordinate has multiple docking 994 // It's possible any given screen coordinate has multiple docking
992 // positions. Check the current info first to avoid having the docking 995 // positions. Check the current info first to avoid having the docking
993 // position bounce around. 996 // position bounce around.
994 return dock_info_; 997 return dock_info_;
995 } 998 }
996 999
997 gfx::NativeView dragged_view = view_->GetWidget()->GetNativeView(); 1000 gfx::NativeView dragged_view = view_->GetWidget()->GetNativeView();
998 dock_windows_.insert(dragged_view); 1001 dock_windows_.insert(dragged_view);
999 DockInfo info = DockInfo::GetDockInfoAtPoint(screen_point, dock_windows_); 1002 DockInfo info = DockInfo::GetDockInfoAtPoint(point_in_screen, dock_windows_);
1000 dock_windows_.erase(dragged_view); 1003 dock_windows_.erase(dragged_view);
1001 return info; 1004 return info;
1002 } 1005 }
1003 1006
1004 TabStrip* TabDragController::GetTabStripForPoint( 1007 TabStrip* TabDragController::GetTabStripForPoint(
1005 const gfx::Point& screen_point) { 1008 const gfx::Point& point_in_screen) {
1006 gfx::NativeView dragged_view = NULL; 1009 gfx::NativeView dragged_view = NULL;
1007 if (view_.get()) 1010 if (view_.get())
1008 dragged_view = view_->GetWidget()->GetNativeView(); 1011 dragged_view = view_->GetWidget()->GetNativeView();
1009 else if (is_dragging_window_) 1012 else if (is_dragging_window_)
1010 dragged_view = attached_tabstrip_->GetWidget()->GetNativeView(); 1013 dragged_view = attached_tabstrip_->GetWidget()->GetNativeView();
1011 if (dragged_view) 1014 if (dragged_view)
1012 dock_windows_.insert(dragged_view); 1015 dock_windows_.insert(dragged_view);
1013 gfx::NativeWindow local_window = 1016 gfx::NativeWindow local_window =
1014 DockInfo::GetLocalProcessWindowAtPoint(screen_point, dock_windows_); 1017 DockInfo::GetLocalProcessWindowAtPoint(point_in_screen, dock_windows_);
1015 if (dragged_view) 1018 if (dragged_view)
1016 dock_windows_.erase(dragged_view); 1019 dock_windows_.erase(dragged_view);
1017 TabStrip* tab_strip = GetTabStripForWindow(local_window); 1020 TabStrip* tab_strip = GetTabStripForWindow(local_window);
1018 if (tab_strip && DoesTabStripContain(tab_strip, screen_point)) 1021 if (tab_strip && DoesTabStripContain(tab_strip, point_in_screen))
1019 return tab_strip; 1022 return tab_strip;
1020 return is_dragging_window_ ? attached_tabstrip_ : NULL; 1023 return is_dragging_window_ ? attached_tabstrip_ : NULL;
1021 } 1024 }
1022 1025
1023 TabStrip* TabDragController::GetTabStripForWindow(gfx::NativeWindow window) { 1026 TabStrip* TabDragController::GetTabStripForWindow(gfx::NativeWindow window) {
1024 if (!window) 1027 if (!window)
1025 return NULL; 1028 return NULL;
1026 BrowserView* browser_view = 1029 BrowserView* browser_view =
1027 BrowserView::GetBrowserViewForNativeWindow(window); 1030 BrowserView::GetBrowserViewForNativeWindow(window);
1028 // We don't allow drops on windows that don't have tabstrips. 1031 // We don't allow drops on windows that don't have tabstrips.
1029 if (!browser_view || 1032 if (!browser_view ||
1030 !browser_view->browser()->SupportsWindowFeature( 1033 !browser_view->browser()->SupportsWindowFeature(
1031 Browser::FEATURE_TABSTRIP)) 1034 Browser::FEATURE_TABSTRIP))
1032 return NULL; 1035 return NULL;
1033 1036
1034 TabStrip* other_tabstrip = browser_view->tabstrip(); 1037 TabStrip* other_tabstrip = browser_view->tabstrip();
1035 TabStrip* tab_strip = 1038 TabStrip* tab_strip =
1036 attached_tabstrip_ ? attached_tabstrip_ : source_tabstrip_; 1039 attached_tabstrip_ ? attached_tabstrip_ : source_tabstrip_;
1037 DCHECK(tab_strip); 1040 DCHECK(tab_strip);
1038 1041
1039 return other_tabstrip->controller()->IsCompatibleWith(tab_strip) ? 1042 return other_tabstrip->controller()->IsCompatibleWith(tab_strip) ?
1040 other_tabstrip : NULL; 1043 other_tabstrip : NULL;
1041 } 1044 }
1042 1045
1043 bool TabDragController::DoesTabStripContain( 1046 bool TabDragController::DoesTabStripContain(
1044 TabStrip* tabstrip, 1047 TabStrip* tabstrip,
1045 const gfx::Point& screen_point) const { 1048 const gfx::Point& point_in_screen) const {
1046 static const int kVerticalDetachMagnetism = 15; 1049 static const int kVerticalDetachMagnetism = 15;
1047 // Make sure the specified screen point is actually within the bounds of the 1050 // Make sure the specified screen point is actually within the bounds of the
1048 // specified tabstrip... 1051 // specified tabstrip...
1049 gfx::Rect tabstrip_bounds = GetViewScreenBounds(tabstrip); 1052 gfx::Rect tabstrip_bounds = GetViewScreenBounds(tabstrip);
1050 if (screen_point.x() < tabstrip_bounds.right() && 1053 if (point_in_screen.x() < tabstrip_bounds.right() &&
1051 screen_point.x() >= tabstrip_bounds.x()) { 1054 point_in_screen.x() >= tabstrip_bounds.x()) {
1052 // TODO(beng): make this be relative to the start position of the mouse 1055 // TODO(beng): make this be relative to the start position of the mouse
1053 // for the source TabStrip. 1056 // for the source TabStrip.
1054 int upper_threshold = tabstrip_bounds.bottom() + kVerticalDetachMagnetism; 1057 int upper_threshold = tabstrip_bounds.bottom() + kVerticalDetachMagnetism;
1055 int lower_threshold = tabstrip_bounds.y() - kVerticalDetachMagnetism; 1058 int lower_threshold = tabstrip_bounds.y() - kVerticalDetachMagnetism;
1056 return screen_point.y() >= lower_threshold && 1059 return point_in_screen.y() >= lower_threshold &&
1057 screen_point.y() <= upper_threshold; 1060 point_in_screen.y() <= upper_threshold;
1058 } 1061 }
1059 return false; 1062 return false;
1060 } 1063 }
1061 1064
1062 void TabDragController::Attach(TabStrip* attached_tabstrip, 1065 void TabDragController::Attach(TabStrip* attached_tabstrip,
1063 const gfx::Point& screen_point) { 1066 const gfx::Point& point_in_screen) {
1064 DCHECK(!attached_tabstrip_); // We should already have detached by the time 1067 DCHECK(!attached_tabstrip_); // We should already have detached by the time
1065 // we get here. 1068 // we get here.
1066 1069
1067 attached_tabstrip_ = attached_tabstrip; 1070 attached_tabstrip_ = attached_tabstrip;
1068 1071
1069 // And we don't need the dragged view. 1072 // And we don't need the dragged view.
1070 view_.reset(); 1073 view_.reset();
1071 1074
1072 std::vector<BaseTab*> tabs = 1075 std::vector<BaseTab*> tabs =
1073 GetTabsMatchingDraggedContents(attached_tabstrip_); 1076 GetTabsMatchingDraggedContents(attached_tabstrip_);
(...skipping 11 matching lines...) Expand all
1085 drag_data_[i].contents->web_contents()->SetDelegate(NULL); 1088 drag_data_[i].contents->web_contents()->SetDelegate(NULL);
1086 drag_data_[i].original_delegate = NULL; 1089 drag_data_[i].original_delegate = NULL;
1087 } 1090 }
1088 1091
1089 // Return the WebContents to normalcy. 1092 // Return the WebContents to normalcy.
1090 source_dragged_contents()->web_contents()->SetCapturingContents(false); 1093 source_dragged_contents()->web_contents()->SetCapturingContents(false);
1091 } 1094 }
1092 1095
1093 // Inserting counts as a move. We don't want the tabs to jitter when the 1096 // Inserting counts as a move. We don't want the tabs to jitter when the
1094 // user moves the tab immediately after attaching it. 1097 // user moves the tab immediately after attaching it.
1095 last_move_screen_loc_ = screen_point.x(); 1098 last_move_screen_loc_ = point_in_screen.x();
1096 1099
1097 // Figure out where to insert the tab based on the bounds of the dragged 1100 // Figure out where to insert the tab based on the bounds of the dragged
1098 // representation and the ideal bounds of the other Tabs already in the 1101 // representation and the ideal bounds of the other Tabs already in the
1099 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are 1102 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are
1100 // changing due to animation). 1103 // changing due to animation).
1101 gfx::Point tab_strip_point(screen_point); 1104 gfx::Point tab_strip_point(point_in_screen);
1102 views::View::ConvertPointToView(NULL, attached_tabstrip_, &tab_strip_point); 1105 views::View::ConvertPointToView(NULL, attached_tabstrip_, &tab_strip_point);
1103 tab_strip_point.set_x( 1106 tab_strip_point.set_x(
1104 attached_tabstrip_->GetMirroredXInView(tab_strip_point.x())); 1107 attached_tabstrip_->GetMirroredXInView(tab_strip_point.x()));
1105 tab_strip_point.Offset(-mouse_offset_.x(), -mouse_offset_.y()); 1108 tab_strip_point.Offset(-mouse_offset_.x(), -mouse_offset_.y());
1106 gfx::Rect bounds = GetDraggedViewTabStripBounds(tab_strip_point); 1109 gfx::Rect bounds = GetDraggedViewTabStripBounds(tab_strip_point);
1107 int index = GetInsertionIndexForDraggedBounds(bounds); 1110 int index = GetInsertionIndexForDraggedBounds(bounds);
1108 for (size_t i = 0; i < drag_data_.size(); ++i) { 1111 for (size_t i = 0; i < drag_data_.size(); ++i) {
1109 int add_types = TabStripModel::ADD_NONE; 1112 int add_types = TabStripModel::ADD_NONE;
1110 if (attached_tabstrip_->touch_layout_.get()) { 1113 if (attached_tabstrip_->touch_layout_.get()) {
1111 // TouchTabStripLayout positions relative to the active tab, if we don't 1114 // TouchTabStripLayout positions relative to the active tab, if we don't
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 1227
1225 // Create the dragged view. 1228 // Create the dragged view.
1226 if (!detach_into_browser_) 1229 if (!detach_into_browser_)
1227 CreateDraggedView(tab_data, drag_bounds); 1230 CreateDraggedView(tab_data, drag_bounds);
1228 1231
1229 attached_tabstrip_->DraggedTabsDetached(); 1232 attached_tabstrip_->DraggedTabsDetached();
1230 attached_tabstrip_ = NULL; 1233 attached_tabstrip_ = NULL;
1231 } 1234 }
1232 1235
1233 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( 1236 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop(
1234 const gfx::Point& screen_point) { 1237 const gfx::Point& point_in_screen) {
1235 if (GetModel(attached_tabstrip_)->count() == 1238 if (GetModel(attached_tabstrip_)->count() ==
1236 static_cast<int>(drag_data_.size())) { 1239 static_cast<int>(drag_data_.size())) {
1237 // All the tabs in a browser are being dragged but all the tabs weren't 1240 // All the tabs in a browser are being dragged but all the tabs weren't
1238 // initially being dragged. For this to happen the user would have to 1241 // initially being dragged. For this to happen the user would have to
1239 // start dragging a set of tabs, the other tabs close, then detach. 1242 // start dragging a set of tabs, the other tabs close, then detach.
1240 RunMoveLoop(); 1243 RunMoveLoop();
1241 return; 1244 return;
1242 } 1245 }
1243 1246
1244 // Create a new browser to house the dragged tabs and have the OS run a move 1247 // Create a new browser to house the dragged tabs and have the OS run a move
1245 // loop. 1248 // loop.
1246 1249
1247 gfx::Point attached_point = GetAttachedDragPoint(screen_point); 1250 gfx::Point attached_point = GetAttachedDragPoint(point_in_screen);
1248 1251
1249 // Calculate the bounds for the tabs from the attached_tab_strip. We do this 1252 // Calculate the bounds for the tabs from the attached_tab_strip. We do this
1250 // so that the tabs don't change size when detached. 1253 // so that the tabs don't change size when detached.
1251 std::vector<gfx::Rect> drag_bounds = 1254 std::vector<gfx::Rect> drag_bounds =
1252 CalculateBoundsForDraggedTabs(attached_point.x()); 1255 CalculateBoundsForDraggedTabs(attached_point.x());
1253 1256
1254 Browser* browser = CreateBrowserForDrag( 1257 Browser* browser = CreateBrowserForDrag(
1255 attached_tabstrip_, screen_point, &drag_bounds); 1258 attached_tabstrip_, point_in_screen, &drag_bounds);
1256 Detach(DONT_RELEASE_CAPTURE); 1259 Detach(DONT_RELEASE_CAPTURE);
1257 BrowserView* dragged_browser_view = 1260 BrowserView* dragged_browser_view =
1258 BrowserView::GetBrowserViewForBrowser(browser); 1261 BrowserView::GetBrowserViewForBrowser(browser);
1259 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( 1262 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled(
1260 false); 1263 false);
1261 Attach(dragged_browser_view->tabstrip(), gfx::Point()); 1264 Attach(dragged_browser_view->tabstrip(), gfx::Point());
1262 // TODO: come up with a cleaner way to do this. 1265 // TODO: come up with a cleaner way to do this.
1263 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); 1266 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds);
1264 1267
1265 browser->window()->Show(); 1268 browser->window()->Show();
(...skipping 28 matching lines...) Expand all
1294 // Under chromeos we immediately set the |move_loop_widget_| to NULL. 1297 // Under chromeos we immediately set the |move_loop_widget_| to NULL.
1295 if (move_loop_widget_) { 1298 if (move_loop_widget_) {
1296 move_loop_widget_->RemoveObserver(this); 1299 move_loop_widget_->RemoveObserver(this);
1297 move_loop_widget_ = NULL; 1300 move_loop_widget_ = NULL;
1298 } 1301 }
1299 is_dragging_window_ = false; 1302 is_dragging_window_ = false;
1300 waiting_for_run_loop_to_exit_ = false; 1303 waiting_for_run_loop_to_exit_ = false;
1301 if (end_run_loop_behavior_ == END_RUN_LOOP_CONTINUE_DRAGGING) { 1304 if (end_run_loop_behavior_ == END_RUN_LOOP_CONTINUE_DRAGGING) {
1302 end_run_loop_behavior_ = END_RUN_LOOP_STOP_DRAGGING; 1305 end_run_loop_behavior_ = END_RUN_LOOP_STOP_DRAGGING;
1303 if (tab_strip_to_attach_to_after_exit_) { 1306 if (tab_strip_to_attach_to_after_exit_) {
1304 gfx::Point screen_point(GetCursorScreenPoint()); 1307 gfx::Point point_in_screen(GetCursorScreenPoint());
1305 Detach(DONT_RELEASE_CAPTURE); 1308 Detach(DONT_RELEASE_CAPTURE);
1306 Attach(tab_strip_to_attach_to_after_exit_, screen_point); 1309 Attach(tab_strip_to_attach_to_after_exit_, point_in_screen);
1307 // Move the tabs into position. 1310 // Move the tabs into position.
1308 MoveAttached(screen_point); 1311 MoveAttached(point_in_screen);
1309 attached_tabstrip_->GetWidget()->Activate(); 1312 attached_tabstrip_->GetWidget()->Activate();
1310 tab_strip_to_attach_to_after_exit_ = NULL; 1313 tab_strip_to_attach_to_after_exit_ = NULL;
1311 } 1314 }
1312 DCHECK(attached_tabstrip_); 1315 DCHECK(attached_tabstrip_);
1313 attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_); 1316 attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_);
1314 } else if (active_) { 1317 } else if (active_) {
1315 EndDrag(result == views::Widget::MOVE_LOOP_CANCELED); 1318 EndDrag(result == views::Widget::MOVE_LOOP_CANCELED);
1316 } 1319 }
1317 } 1320 }
1318 1321
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 } 1449 }
1447 1450
1448 double sel_width, unselected_width; 1451 double sel_width, unselected_width;
1449 attached_tabstrip_->GetCurrentTabWidths(&sel_width, &unselected_width); 1452 attached_tabstrip_->GetCurrentTabWidths(&sel_width, &unselected_width);
1450 return gfx::Rect(tab_strip_point.x(), tab_strip_point.y(), 1453 return gfx::Rect(tab_strip_point.x(), tab_strip_point.y(),
1451 static_cast<int>(sel_width), 1454 static_cast<int>(sel_width),
1452 Tab::GetStandardSize().height()); 1455 Tab::GetStandardSize().height());
1453 } 1456 }
1454 1457
1455 gfx::Point TabDragController::GetAttachedDragPoint( 1458 gfx::Point TabDragController::GetAttachedDragPoint(
1456 const gfx::Point& screen_point) { 1459 const gfx::Point& point_in_screen) {
1457 DCHECK(attached_tabstrip_); // The tab must be attached. 1460 DCHECK(attached_tabstrip_); // The tab must be attached.
1458 1461
1459 gfx::Point tab_loc(screen_point); 1462 gfx::Point tab_loc(point_in_screen);
1460 views::View::ConvertPointToView(NULL, attached_tabstrip_, &tab_loc); 1463 views::View::ConvertPointToView(NULL, attached_tabstrip_, &tab_loc);
1461 int x = 1464 int x =
1462 attached_tabstrip_->GetMirroredXInView(tab_loc.x()) - mouse_offset_.x(); 1465 attached_tabstrip_->GetMirroredXInView(tab_loc.x()) - mouse_offset_.x();
1463 1466
1464 // TODO: consider caching this. 1467 // TODO: consider caching this.
1465 std::vector<BaseTab*> attached_tabs; 1468 std::vector<BaseTab*> attached_tabs;
1466 for (size_t i = 0; i < drag_data_.size(); ++i) 1469 for (size_t i = 0; i < drag_data_.size(); ++i)
1467 attached_tabs.push_back(drag_data_[i].attached_tab); 1470 attached_tabs.push_back(drag_data_[i].attached_tab);
1468 int size = attached_tabstrip_->GetSizeNeededForTabs(attached_tabs); 1471 int size = attached_tabstrip_->GetSizeNeededForTabs(attached_tabs);
1469 int max_x = attached_tabstrip_->width() - size; 1472 int max_x = attached_tabstrip_->width() - size;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 break; 1690 break;
1688 1691
1689 default: 1692 default:
1690 NOTREACHED(); 1693 NOTREACHED();
1691 break; 1694 break;
1692 } 1695 }
1693 } 1696 }
1694 // Compel the model to construct a new window for the detached WebContents. 1697 // Compel the model to construct a new window for the detached WebContents.
1695 views::Widget* widget = source_tabstrip_->GetWidget(); 1698 views::Widget* widget = source_tabstrip_->GetWidget();
1696 gfx::Rect window_bounds(widget->GetRestoredBounds()); 1699 gfx::Rect window_bounds(widget->GetRestoredBounds());
1697 window_bounds.set_origin(GetWindowCreatePoint(last_screen_point_)); 1700 window_bounds.set_origin(GetWindowCreatePoint(last_point_in_screen_));
1698 // When modifying the following if statement, please make sure not to 1701 // When modifying the following if statement, please make sure not to
1699 // introduce issue listed in http://crbug.com/6223 comment #11. 1702 // introduce issue listed in http://crbug.com/6223 comment #11.
1700 bool rtl_ui = base::i18n::IsRTL(); 1703 bool rtl_ui = base::i18n::IsRTL();
1701 bool has_dock_position = (dock_info_.type() != DockInfo::NONE); 1704 bool has_dock_position = (dock_info_.type() != DockInfo::NONE);
1702 if (rtl_ui && has_dock_position) { 1705 if (rtl_ui && has_dock_position) {
1703 // Mirror X axis so the docked tab is aligned using the mouse click as 1706 // Mirror X axis so the docked tab is aligned using the mouse click as
1704 // the top-right corner. 1707 // the top-right corner.
1705 window_bounds.set_x(window_bounds.x() - window_bounds.width()); 1708 window_bounds.set_x(window_bounds.x() - window_bounds.width());
1706 } 1709 }
1707 Browser* new_browser = 1710 Browser* new_browser =
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 std::vector<DockDisplayer*>::iterator i = 1819 std::vector<DockDisplayer*>::iterator i =
1817 std::find(dock_controllers_.begin(), dock_controllers_.end(), 1820 std::find(dock_controllers_.begin(), dock_controllers_.end(),
1818 controller); 1821 controller);
1819 if (i != dock_controllers_.end()) 1822 if (i != dock_controllers_.end())
1820 dock_controllers_.erase(i); 1823 dock_controllers_.erase(i);
1821 else 1824 else
1822 NOTREACHED(); 1825 NOTREACHED();
1823 } 1826 }
1824 1827
1825 void TabDragController::BringWindowUnderPointToFront( 1828 void TabDragController::BringWindowUnderPointToFront(
1826 const gfx::Point& screen_point) { 1829 const gfx::Point& point_in_screen) {
1827 // If we're going to dock to another window, bring it to the front. 1830 // If we're going to dock to another window, bring it to the front.
1828 gfx::NativeWindow window = dock_info_.window(); 1831 gfx::NativeWindow window = dock_info_.window();
1829 if (!window) { 1832 if (!window) {
1830 views::View* dragged_view; 1833 views::View* dragged_view;
1831 if (view_.get()) 1834 if (view_.get())
1832 dragged_view = view_.get(); 1835 dragged_view = view_.get();
1833 else 1836 else
1834 dragged_view = attached_tabstrip_; 1837 dragged_view = attached_tabstrip_;
1835 gfx::NativeView dragged_native_view = 1838 gfx::NativeView dragged_native_view =
1836 dragged_view->GetWidget()->GetNativeView(); 1839 dragged_view->GetWidget()->GetNativeView();
1837 dock_windows_.insert(dragged_native_view); 1840 dock_windows_.insert(dragged_native_view);
1838 window = 1841 window =
1839 DockInfo::GetLocalProcessWindowAtPoint(screen_point, dock_windows_); 1842 DockInfo::GetLocalProcessWindowAtPoint(point_in_screen, dock_windows_);
1840 dock_windows_.erase(dragged_native_view); 1843 dock_windows_.erase(dragged_native_view);
1841 } 1844 }
1842 if (window) { 1845 if (window) {
1843 views::Widget* widget_window = views::Widget::GetWidgetForNativeView( 1846 views::Widget* widget_window = views::Widget::GetWidgetForNativeView(
1844 window); 1847 window);
1845 if (widget_window) 1848 if (widget_window)
1846 widget_window->StackAtTop(); 1849 widget_window->StackAtTop();
1847 else 1850 else
1848 return; 1851 return;
1849 1852
(...skipping 21 matching lines...) Expand all
1871 if (drag_data_[i - 1].source_model_index + 1 != 1874 if (drag_data_[i - 1].source_model_index + 1 !=
1872 drag_data_[i].source_model_index) { 1875 drag_data_[i].source_model_index) {
1873 return false; 1876 return false;
1874 } 1877 }
1875 } 1878 }
1876 return true; 1879 return true;
1877 } 1880 }
1878 1881
1879 Browser* TabDragController::CreateBrowserForDrag( 1882 Browser* TabDragController::CreateBrowserForDrag(
1880 TabStrip* source, 1883 TabStrip* source,
1881 const gfx::Point& screen_point, 1884 const gfx::Point& point_in_screen,
1882 std::vector<gfx::Rect>* drag_bounds) { 1885 std::vector<gfx::Rect>* drag_bounds) {
1883 Browser* browser = new Browser( 1886 Browser* browser = new Browser(
1884 Browser::CreateParams(drag_data_[0].contents->profile())); 1887 Browser::CreateParams(drag_data_[0].contents->profile()));
1885 gfx::Point center(0, source->height() / 2); 1888 gfx::Point center(0, source->height() / 2);
1886 views::View::ConvertPointToWidget(source, &center); 1889 views::View::ConvertPointToWidget(source, &center);
1887 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen()); 1890 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen());
1888 new_bounds.set_y(screen_point.y() - center.y()); 1891 new_bounds.set_y(point_in_screen.y() - center.y());
1889 switch (GetDetachPosition(screen_point)) { 1892 switch (GetDetachPosition(point_in_screen)) {
1890 case DETACH_BEFORE: 1893 case DETACH_BEFORE:
1891 new_bounds.set_x(screen_point.x() - center.x()); 1894 new_bounds.set_x(point_in_screen.x() - center.x());
1892 new_bounds.Offset(-mouse_offset_.x(), 0); 1895 new_bounds.Offset(-mouse_offset_.x(), 0);
1893 break; 1896 break;
1894 1897
1895 case DETACH_AFTER: { 1898 case DETACH_AFTER: {
1896 gfx::Point right_edge(source->width(), 0); 1899 gfx::Point right_edge(source->width(), 0);
1897 views::View::ConvertPointToWidget(source, &right_edge); 1900 views::View::ConvertPointToWidget(source, &right_edge);
1898 new_bounds.set_x(screen_point.x() - right_edge.x()); 1901 new_bounds.set_x(point_in_screen.x() - right_edge.x());
1899 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); 1902 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0);
1900 int delta = (*drag_bounds)[0].x(); 1903 int delta = (*drag_bounds)[0].x();
1901 for (size_t i = 0; i < drag_bounds->size(); ++i) 1904 for (size_t i = 0; i < drag_bounds->size(); ++i)
1902 (*drag_bounds)[i].Offset(-delta, 0); 1905 (*drag_bounds)[i].Offset(-delta, 0);
1903 break; 1906 break;
1904 } 1907 }
1905 1908
1906 default: 1909 default:
1907 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. 1910 break; // Nothing to do for DETACH_ABOVE_OR_BELOW.
1908 } 1911 }
(...skipping 13 matching lines...) Expand all
1922 gfx::Point touch_point; 1925 gfx::Point touch_point;
1923 bool got_touch_point = widget_window->GetRootWindow()-> 1926 bool got_touch_point = widget_window->GetRootWindow()->
1924 gesture_recognizer()->GetLastTouchPointForTarget(widget_window, 1927 gesture_recognizer()->GetLastTouchPointForTarget(widget_window,
1925 &touch_point); 1928 &touch_point);
1926 DCHECK(got_touch_point); 1929 DCHECK(got_touch_point);
1927 return touch_point; 1930 return touch_point;
1928 } 1931 }
1929 #endif 1932 #endif
1930 return gfx::Screen::GetCursorScreenPoint(); 1933 return gfx::Screen::GetCursorScreenPoint();
1931 } 1934 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698