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

Side by Side Diff: chrome/browser/views/tabs/dragged_tab_controller.cc

Issue 2124003: More TabStrip refactoring. (Closed)
Patch Set: Merge with trunk Created 10 years, 7 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/tabs/dragged_tab_controller.h" 5 #include "chrome/browser/views/tabs/dragged_tab_controller.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <set> 8 #include <set>
9 9
10 #include "app/animation.h" 10 #include "app/animation.h"
11 #include "app/slide_animation.h" 11 #include "app/slide_animation.h"
12 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
13 #include "app/resource_bundle.h" 13 #include "app/resource_bundle.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
16 #include "base/keyboard_codes.h" 16 #include "base/keyboard_codes.h"
17 #include "chrome/browser/browser_window.h" 17 #include "chrome/browser/browser_window.h"
18 #include "chrome/browser/extensions/extension_function_dispatcher.h" 18 #include "chrome/browser/extensions/extension_function_dispatcher.h"
19 #include "chrome/browser/tab_contents/tab_contents.h" 19 #include "chrome/browser/tab_contents/tab_contents.h"
20 #include "chrome/browser/tabs/tab_strip_model.h" 20 #include "chrome/browser/tabs/tab_strip_model.h"
21 #include "chrome/browser/metrics/user_metrics.h" 21 #include "chrome/browser/metrics/user_metrics.h"
22 #include "chrome/browser/views/frame/browser_view.h" 22 #include "chrome/browser/views/frame/browser_view.h"
23 #include "chrome/browser/views/tabs/base_tab_renderer.h"
24 #include "chrome/browser/views/tabs/base_tab_strip.h"
23 #include "chrome/browser/views/tabs/browser_tab_strip_controller.h" 25 #include "chrome/browser/views/tabs/browser_tab_strip_controller.h"
24 #include "chrome/browser/views/tabs/dragged_tab_view.h" 26 #include "chrome/browser/views/tabs/dragged_tab_view.h"
25 #include "chrome/browser/views/tabs/native_view_photobooth.h" 27 #include "chrome/browser/views/tabs/native_view_photobooth.h"
26 #include "chrome/browser/views/tabs/tab.h"
27 #include "chrome/browser/views/tabs/tab_strip.h" 28 #include "chrome/browser/views/tabs/tab_strip.h"
28 #include "chrome/common/notification_service.h" 29 #include "chrome/common/notification_service.h"
29 #include "gfx/canvas.h" 30 #include "gfx/canvas.h"
30 #include "grit/theme_resources.h" 31 #include "grit/theme_resources.h"
31 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
32 #include "views/event.h" 33 #include "views/event.h"
33 #include "views/widget/root_view.h" 34 #include "views/widget/root_view.h"
34 #include "views/widget/widget.h" 35 #include "views/widget/widget.h"
35 #include "views/window/window.h" 36 #include "views/window/window.h"
36 37
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 SkPaint paint; 172 SkPaint paint;
172 paint.setAlpha(128); 173 paint.setAlpha(128);
173 canvas->DrawBitmapInt(image, x, y, paint); 174 canvas->DrawBitmapInt(image, x, y, paint);
174 } 175 }
175 176
176 DockInfo::Type type_; 177 DockInfo::Type type_;
177 178
178 DISALLOW_COPY_AND_ASSIGN(DockView); 179 DISALLOW_COPY_AND_ASSIGN(DockView);
179 }; 180 };
180 181
181 gfx::Point ConvertScreenPointToTabStripPoint(TabStrip* tabstrip, 182 gfx::Point ConvertScreenPointToTabStripPoint(BaseTabStrip* tabstrip,
182 const gfx::Point& screen_point) { 183 const gfx::Point& screen_point) {
183 gfx::Point tabstrip_topleft; 184 gfx::Point tabstrip_topleft;
184 views::View::ConvertPointToScreen(tabstrip, &tabstrip_topleft); 185 views::View::ConvertPointToScreen(tabstrip, &tabstrip_topleft);
185 return gfx::Point(screen_point.x() - tabstrip_topleft.x(), 186 return gfx::Point(screen_point.x() - tabstrip_topleft.x(),
186 screen_point.y() - tabstrip_topleft.y()); 187 screen_point.y() - tabstrip_topleft.y());
187 } 188 }
188 189
189 } // namespace 190 } // namespace
190 191
191 /////////////////////////////////////////////////////////////////////////////// 192 ///////////////////////////////////////////////////////////////////////////////
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // Have we been hidden? 305 // Have we been hidden?
305 bool hidden_; 306 bool hidden_;
306 307
307 // Value of DockInfo::in_enable_area. 308 // Value of DockInfo::in_enable_area.
308 bool in_enable_area_; 309 bool in_enable_area_;
309 }; 310 };
310 311
311 /////////////////////////////////////////////////////////////////////////////// 312 ///////////////////////////////////////////////////////////////////////////////
312 // DraggedTabController, public: 313 // DraggedTabController, public:
313 314
314 DraggedTabController::DraggedTabController(Tab* source_tab, 315 DraggedTabController::DraggedTabController(BaseTabRenderer* source_tab,
315 TabStrip* source_tabstrip) 316 BaseTabStrip* source_tabstrip)
316 : dragged_contents_(NULL), 317 : dragged_contents_(NULL),
317 original_delegate_(NULL), 318 original_delegate_(NULL),
318 source_tabstrip_(source_tabstrip), 319 source_tabstrip_(source_tabstrip),
319 source_model_index_(source_tabstrip->GetModelIndexOfTab(source_tab)), 320 source_model_index_(source_tabstrip->GetModelIndexOfBaseTab(source_tab)),
320 attached_tabstrip_(NULL), 321 attached_tabstrip_(NULL),
321 attached_tab_(NULL), 322 attached_tab_(NULL),
322 offset_to_width_ratio_(0), 323 offset_to_width_ratio_(0),
323 old_focused_view_(NULL), 324 old_focused_view_(NULL),
324 in_destructor_(false), 325 in_destructor_(false),
325 last_move_screen_x_(0), 326 last_move_screen_x_(0),
326 mini_(source_tab->data().mini), 327 mini_(source_tab->data().mini),
327 pinned_(source_tabstrip->IsTabPinned(source_tab)), 328 pinned_(source_tabstrip->IsTabPinned(source_tab)),
328 started_drag_(false) { 329 started_drag_(false) {
329 SetDraggedContents( 330 SetDraggedContents(
330 GetModel(source_tabstrip_)->GetTabContentsAt(source_model_index_)); 331 GetModel(source_tabstrip_)->GetTabContentsAt(source_model_index_));
331 // Listen for Esc key presses. 332 // Listen for Esc key presses.
332 MessageLoopForUI::current()->AddObserver(this); 333 MessageLoopForUI::current()->AddObserver(this);
333 } 334 }
334 335
335 DraggedTabController::~DraggedTabController() { 336 DraggedTabController::~DraggedTabController() {
336 in_destructor_ = true; 337 in_destructor_ = true;
337 MessageLoopForUI::current()->RemoveObserver(this); 338 MessageLoopForUI::current()->RemoveObserver(this);
338 // Need to delete the view here manually _before_ we reset the dragged 339 // Need to delete the view here manually _before_ we reset the dragged
339 // contents to NULL, otherwise if the view is animating to its destination 340 // contents to NULL, otherwise if the view is animating to its destination
340 // bounds, it won't be able to clean up properly since its cleanup routine 341 // bounds, it won't be able to clean up properly since its cleanup routine
341 // uses GetIndexForDraggedContents, which will be invalid. 342 // uses GetIndexForDraggedContents, which will be invalid.
342 view_.reset(NULL); 343 view_.reset(NULL);
343 SetDraggedContents(NULL); // This removes our observer. 344 SetDraggedContents(NULL); // This removes our observer.
344 } 345 }
345 346
346 void DraggedTabController::CaptureDragInfo(Tab* tab, 347 void DraggedTabController::CaptureDragInfo(views::View* tab,
347 const gfx::Point& mouse_offset) { 348 const gfx::Point& mouse_offset) {
348 if (tab->width() > 0) { 349 if (tab->width() > 0) {
349 offset_to_width_ratio_ = static_cast<float>(mouse_offset.x()) / 350 offset_to_width_ratio_ = static_cast<float>(mouse_offset.x()) /
350 static_cast<float>(tab->width()); 351 static_cast<float>(tab->width());
351 } 352 }
352 start_screen_point_ = GetCursorScreenPoint(); 353 start_screen_point_ = GetCursorScreenPoint();
353 mouse_offset_ = mouse_offset; 354 mouse_offset_ = mouse_offset;
354 InitWindowCreatePoint(); 355 InitWindowCreatePoint();
355 } 356 }
356 357
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // DraggedTabController, private: 499 // DraggedTabController, private:
499 500
500 void DraggedTabController::InitWindowCreatePoint() { 501 void DraggedTabController::InitWindowCreatePoint() {
501 // window_create_point_ is only used in CompleteDrag() (through 502 // window_create_point_ is only used in CompleteDrag() (through
502 // GetWindowCreatePoint() to get the start point of the docked window) when 503 // GetWindowCreatePoint() to get the start point of the docked window) when
503 // the attached_tabstrip_ is NULL and all the window's related bound 504 // the attached_tabstrip_ is NULL and all the window's related bound
504 // information are obtained from source_tabstrip_. So, we need to get the 505 // information are obtained from source_tabstrip_. So, we need to get the
505 // first_tab based on source_tabstrip_, not attached_tabstrip_. Otherwise, 506 // first_tab based on source_tabstrip_, not attached_tabstrip_. Otherwise,
506 // the window_create_point_ is not in the correct coordinate system. Please 507 // the window_create_point_ is not in the correct coordinate system. Please
507 // refer to http://crbug.com/6223 comment #15 for detailed information. 508 // refer to http://crbug.com/6223 comment #15 for detailed information.
508 Tab* first_tab = source_tabstrip_->GetTabAtTabDataIndex(0); 509 views::View* first_tab = source_tabstrip_->base_tab_at_tab_index(0);
509 views::View::ConvertPointToWidget(first_tab, &first_source_tab_point_); 510 views::View::ConvertPointToWidget(first_tab, &first_source_tab_point_);
510 UpdateWindowCreatePoint(); 511 UpdateWindowCreatePoint();
511 } 512 }
512 513
513 void DraggedTabController::UpdateWindowCreatePoint() { 514 void DraggedTabController::UpdateWindowCreatePoint() {
514 // See comments in InitWindowCreatePoint for details on this. 515 // See comments in InitWindowCreatePoint for details on this.
515 window_create_point_ = first_source_tab_point_; 516 window_create_point_ = first_source_tab_point_;
516 window_create_point_.Offset(mouse_offset_.x(), mouse_offset_.y()); 517 window_create_point_.Offset(mouse_offset_.x(), mouse_offset_.y());
517 } 518 }
518 519
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // windows are open, the coordinates of |source_tab_| are way off in 613 // windows are open, the coordinates of |source_tab_| are way off in
613 // hyperspace since the window was moved there instead of being closed so 614 // hyperspace since the window was moved there instead of being closed so
614 // that we'd keep receiving events. And our ConvertPointToScreen methods 615 // that we'd keep receiving events. And our ConvertPointToScreen methods
615 // aren't really multi-screen aware. So really it's just safer to get the 616 // aren't really multi-screen aware. So really it's just safer to get the
616 // actual position of the mouse cursor directly from Windows here, which is 617 // actual position of the mouse cursor directly from Windows here, which is
617 // guaranteed to be correct regardless of monitor config. 618 // guaranteed to be correct regardless of monitor config.
618 gfx::Point screen_point = GetCursorScreenPoint(); 619 gfx::Point screen_point = GetCursorScreenPoint();
619 620
620 #if defined(OS_CHROMEOS) 621 #if defined(OS_CHROMEOS)
621 // We don't allow detaching in chrome os. 622 // We don't allow detaching in chrome os.
622 TabStrip* target_tabstrip = source_tabstrip_; 623 BaseTabStrip* target_tabstrip = source_tabstrip_;
623 #else 624 #else
624 // Determine whether or not we have dragged over a compatible TabStrip in 625 // Determine whether or not we have dragged over a compatible TabStrip in
625 // another browser window. If we have, we should attach to it and start 626 // another browser window. If we have, we should attach to it and start
626 // dragging within it. 627 // dragging within it.
627 TabStrip* target_tabstrip = GetTabStripForPoint(screen_point); 628 BaseTabStrip* target_tabstrip = GetTabStripForPoint(screen_point);
628 #endif 629 #endif
629 if (target_tabstrip != attached_tabstrip_) { 630 if (target_tabstrip != attached_tabstrip_) {
630 // Make sure we're fully detached from whatever TabStrip we're attached to 631 // Make sure we're fully detached from whatever TabStrip we're attached to
631 // (if any). 632 // (if any).
632 if (attached_tabstrip_) 633 if (attached_tabstrip_)
633 Detach(); 634 Detach();
634 if (target_tabstrip) 635 if (target_tabstrip)
635 Attach(target_tabstrip, screen_point); 636 Attach(target_tabstrip, screen_point);
636 } 637 }
637 if (!target_tabstrip) { 638 if (!target_tabstrip) {
638 bring_to_front_timer_.Start( 639 bring_to_front_timer_.Start(
639 base::TimeDelta::FromMilliseconds(kBringToFrontDelay), this, 640 base::TimeDelta::FromMilliseconds(kBringToFrontDelay), this,
640 &DraggedTabController::BringWindowUnderMouseToFront); 641 &DraggedTabController::BringWindowUnderMouseToFront);
641 } 642 }
642 643
643 UpdateDockInfo(screen_point); 644 UpdateDockInfo(screen_point);
644 645
645 if (attached_tabstrip_) 646 if (attached_tabstrip_)
646 MoveAttachedTab(screen_point); 647 MoveAttachedTab(screen_point);
647 else 648 else
648 MoveDetachedTab(screen_point); 649 MoveDetachedTab(screen_point);
649 } 650 }
650 651
651 void DraggedTabController::MoveAttachedTab(const gfx::Point& screen_point) { 652 void DraggedTabController::MoveAttachedTab(const gfx::Point& screen_point) {
652 DCHECK(attached_tabstrip_); 653 DCHECK(attached_tabstrip_);
653 DCHECK(!view_.get()); 654 DCHECK(!view_.get());
654 655
655 gfx::Point dragged_view_point = GetAttachedTabDragPoint(screen_point); 656 gfx::Point dragged_view_point = GetAttachedTabDragPoint(screen_point);
656
657 TabStripModel* attached_model = GetModel(attached_tabstrip_); 657 TabStripModel* attached_model = GetModel(attached_tabstrip_);
658 int from_index = attached_model->GetIndexOfTabContents(dragged_contents_); 658 int from_index = attached_model->GetIndexOfTabContents(dragged_contents_);
659 659
660 if (attached_tabstrip_->type() == BaseTabStrip::HORIZONTAL_TAB_STRIP) {
661 MoveAttachedTabHorizontalTabStrip(screen_point, attached_model,
662 dragged_view_point, from_index);
663 } else {
664 MoveAttachedTabVerticalTabStrip(screen_point, attached_model,
665 dragged_view_point, from_index);
666 }
667 attached_tab_->SchedulePaint();
668 attached_tab_->SetX(dragged_view_point.x());
669 attached_tab_->SetY(dragged_view_point.y());
670 attached_tab_->SchedulePaint();
671 }
672
673 void DraggedTabController::MoveAttachedTabHorizontalTabStrip(
674 const gfx::Point& screen_point,
675 TabStripModel* model,
676 const gfx::Point& dragged_view_point,
677 int from_index) {
678 TabStrip* tab_strip = static_cast<TabStrip*>(attached_tabstrip_);
660 // Determine the horizontal move threshold. This is dependent on the width 679 // Determine the horizontal move threshold. This is dependent on the width
661 // of tabs. The smaller the tabs compared to the standard size, the smaller 680 // of tabs. The smaller the tabs compared to the standard size, the smaller
662 // the threshold. 681 // the threshold.
663 double unselected, selected; 682 double unselected, selected;
664 attached_tabstrip_->GetCurrentTabWidths(&unselected, &selected); 683 tab_strip->GetCurrentTabWidths(&unselected, &selected);
665 double ratio = unselected / Tab::GetStandardSize().width(); 684 double ratio = unselected / Tab::GetStandardSize().width();
666 int threshold = static_cast<int>(ratio * kHorizontalMoveThreshold); 685 int threshold = static_cast<int>(ratio * kHorizontalMoveThreshold);
667 686
668 // Update the model, moving the TabContents from one index to another. Do this 687 // Update the model, moving the TabContents from one index to another. Do this
669 // only if we have moved a minimum distance since the last reorder (to prevent 688 // only if we have moved a minimum distance since the last reorder (to prevent
670 // jitter). 689 // jitter).
671 if (abs(screen_point.x() - last_move_screen_x_) > threshold) { 690 if (abs(screen_point.x() - last_move_screen_x_) > threshold) {
672 gfx::Point dragged_view_screen_point(dragged_view_point); 691 gfx::Point dragged_view_screen_point(dragged_view_point);
673 views::View::ConvertPointToScreen(attached_tabstrip_, 692 views::View::ConvertPointToScreen(tab_strip, &dragged_view_screen_point);
674 &dragged_view_screen_point);
675 gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_screen_point); 693 gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_screen_point);
676 int to_index = GetInsertionIndexForDraggedBounds(bounds, true); 694 int to_index = GetInsertionIndexForDraggedBounds(bounds, true);
677 to_index = NormalizeIndexToAttachedTabStrip(to_index); 695 to_index = NormalizeIndexToAttachedTabStrip(to_index);
678 if (from_index != to_index) { 696 if (from_index != to_index) {
679 last_move_screen_x_ = screen_point.x(); 697 last_move_screen_x_ = screen_point.x();
680 attached_model->MoveTabContentsAt(from_index, to_index, true); 698 model->MoveTabContentsAt(from_index, to_index, true);
681 } 699 }
682 } 700 }
683 attached_tab_->SchedulePaint(); 701 }
684 attached_tab_->SetX(dragged_view_point.x()); 702
685 attached_tab_->SetY(dragged_view_point.y()); 703 void DraggedTabController::MoveAttachedTabVerticalTabStrip(
686 attached_tab_->SchedulePaint(); 704 const gfx::Point& screen_point,
705 TabStripModel* model,
706 const gfx::Point& dragged_view_point,
707 int from_index) {
708 // TODO(sky): implement me.
687 } 709 }
688 710
689 void DraggedTabController::MoveDetachedTab(const gfx::Point& screen_point) { 711 void DraggedTabController::MoveDetachedTab(const gfx::Point& screen_point) {
690 DCHECK(!attached_tabstrip_); 712 DCHECK(!attached_tabstrip_);
691 DCHECK(view_.get()); 713 DCHECK(view_.get());
692 714
693 int x = screen_point.x() - mouse_offset_.x(); 715 int x = screen_point.x() - mouse_offset_.x();
694 int y = screen_point.y() - mouse_offset_.y(); 716 int y = screen_point.y() - mouse_offset_.y();
695 717
696 // Move the View. There are no changes to the model if we're detached. 718 // Move the View. There are no changes to the model if we're detached.
(...skipping 14 matching lines...) Expand all
711 return dock_info_; 733 return dock_info_;
712 } 734 }
713 735
714 gfx::NativeView dragged_hwnd = view_->GetWidget()->GetNativeView(); 736 gfx::NativeView dragged_hwnd = view_->GetWidget()->GetNativeView();
715 dock_windows_.insert(dragged_hwnd); 737 dock_windows_.insert(dragged_hwnd);
716 DockInfo info = DockInfo::GetDockInfoAtPoint(screen_point, dock_windows_); 738 DockInfo info = DockInfo::GetDockInfoAtPoint(screen_point, dock_windows_);
717 dock_windows_.erase(dragged_hwnd); 739 dock_windows_.erase(dragged_hwnd);
718 return info; 740 return info;
719 } 741 }
720 742
721 TabStrip* DraggedTabController::GetTabStripForPoint( 743 BaseTabStrip* DraggedTabController::GetTabStripForPoint(
722 const gfx::Point& screen_point) { 744 const gfx::Point& screen_point) {
723 gfx::NativeView dragged_view = NULL; 745 gfx::NativeView dragged_view = NULL;
724 if (view_.get()) { 746 if (view_.get()) {
725 dragged_view = view_->GetWidget()->GetNativeView(); 747 dragged_view = view_->GetWidget()->GetNativeView();
726 dock_windows_.insert(dragged_view); 748 dock_windows_.insert(dragged_view);
727 } 749 }
728 gfx::NativeWindow local_window = 750 gfx::NativeWindow local_window =
729 DockInfo::GetLocalProcessWindowAtPoint(screen_point, dock_windows_); 751 DockInfo::GetLocalProcessWindowAtPoint(screen_point, dock_windows_);
730 if (dragged_view) 752 if (dragged_view)
731 dock_windows_.erase(dragged_view); 753 dock_windows_.erase(dragged_view);
732 if (!local_window) 754 if (!local_window)
733 return NULL; 755 return NULL;
734 BrowserView* browser = 756 BrowserView* browser =
735 BrowserView::GetBrowserViewForNativeWindow(local_window); 757 BrowserView::GetBrowserViewForNativeWindow(local_window);
736 // We don't allow drops on windows that don't have tabstrips. 758 // We don't allow drops on windows that don't have tabstrips.
737 if (!browser || 759 if (!browser ||
738 !browser->browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)) 760 !browser->browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP))
739 return NULL; 761 return NULL;
740 762
741 TabStrip* other_tabstrip = browser->tabstrip()->AsTabStrip(); 763 BaseTabStrip* other_tabstrip = browser->tabstrip();
742 if (!other_tabstrip->controller()->IsCompatibleWith(source_tabstrip_)) 764 if (!other_tabstrip->controller()->IsCompatibleWith(source_tabstrip_))
743 return NULL; 765 return NULL;
744 return GetTabStripIfItContains(other_tabstrip, screen_point); 766 return GetTabStripIfItContains(other_tabstrip, screen_point);
745 } 767 }
746 768
747 TabStrip* DraggedTabController::GetTabStripIfItContains( 769 BaseTabStrip* DraggedTabController::GetTabStripIfItContains(
748 TabStrip* tabstrip, const gfx::Point& screen_point) const { 770 BaseTabStrip* tabstrip, const gfx::Point& screen_point) const {
771 // TODO(sky): this likely needs to be adjusted for vertical tabs.
749 static const int kVerticalDetachMagnetism = 15; 772 static const int kVerticalDetachMagnetism = 15;
750 // Make sure the specified screen point is actually within the bounds of the 773 // Make sure the specified screen point is actually within the bounds of the
751 // specified tabstrip... 774 // specified tabstrip...
752 gfx::Rect tabstrip_bounds = GetViewScreenBounds(tabstrip); 775 gfx::Rect tabstrip_bounds = GetViewScreenBounds(tabstrip);
753 if (screen_point.x() < tabstrip_bounds.right() && 776 if (screen_point.x() < tabstrip_bounds.right() &&
754 screen_point.x() >= tabstrip_bounds.x()) { 777 screen_point.x() >= tabstrip_bounds.x()) {
755 // TODO(beng): make this be relative to the start position of the mouse for 778 // TODO(beng): make this be relative to the start position of the mouse for
756 // the source TabStrip. 779 // the source TabStrip.
757 int upper_threshold = tabstrip_bounds.bottom() + kVerticalDetachMagnetism; 780 int upper_threshold = tabstrip_bounds.bottom() + kVerticalDetachMagnetism;
758 int lower_threshold = tabstrip_bounds.y() - kVerticalDetachMagnetism; 781 int lower_threshold = tabstrip_bounds.y() - kVerticalDetachMagnetism;
759 if (screen_point.y() >= lower_threshold && 782 if (screen_point.y() >= lower_threshold &&
760 screen_point.y() <= upper_threshold) { 783 screen_point.y() <= upper_threshold) {
761 return tabstrip; 784 return tabstrip;
762 } 785 }
763 } 786 }
764 return NULL; 787 return NULL;
765 } 788 }
766 789
767 void DraggedTabController::Attach(TabStrip* attached_tabstrip, 790 void DraggedTabController::Attach(BaseTabStrip* attached_tabstrip,
768 const gfx::Point& screen_point) { 791 const gfx::Point& screen_point) {
769 DCHECK(!attached_tabstrip_); // We should already have detached by the time 792 DCHECK(!attached_tabstrip_); // We should already have detached by the time
770 // we get here. 793 // we get here.
771 DCHECK(!attached_tab_); // Similarly there should be no attached tab. 794 DCHECK(!attached_tab_); // Similarly there should be no attached tab.
772 795
773 attached_tabstrip_ = attached_tabstrip; 796 attached_tabstrip_ = attached_tabstrip;
774 797
775 // We don't need the photo-booth while we're attached. 798 // We don't need the photo-booth while we're attached.
776 photobooth_.reset(NULL); 799 photobooth_.reset(NULL);
777 800
778 // And we don't need the dragged view. 801 // And we don't need the dragged view.
779 view_.reset(); 802 view_.reset();
780 803
781 Tab* tab = GetTabMatchingDraggedContents(attached_tabstrip_); 804 BaseTabRenderer* tab = GetTabMatchingDraggedContents(attached_tabstrip_);
782 805
783 if (!tab) { 806 if (!tab) {
784 // There is no Tab in |attached_tabstrip| that corresponds to the dragged 807 // There is no Tab in |attached_tabstrip| that corresponds to the dragged
785 // TabContents. We must now create one. 808 // TabContents. We must now create one.
786 809
787 // Remove ourselves as the delegate now that the dragged TabContents is 810 // Remove ourselves as the delegate now that the dragged TabContents is
788 // being inserted back into a Browser. 811 // being inserted back into a Browser.
789 dragged_contents_->set_delegate(NULL); 812 dragged_contents_->set_delegate(NULL);
790 original_delegate_ = NULL; 813 original_delegate_ = NULL;
791 814
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 // mirroring transformation flag) which effectively means that even though 894 // mirroring transformation flag) which effectively means that even though
872 // the tabs are rendered from right to left, the code performs the 895 // the tabs are rendered from right to left, the code performs the
873 // calculation as if the tabs are laid out from left to right. Mirroring the 896 // calculation as if the tabs are laid out from left to right. Mirroring the
874 // dragged bounds adjusts the coordinates of the tab we are dragging so that 897 // dragged bounds adjusts the coordinates of the tab we are dragging so that
875 // it uses the same orientation used by the tabs on the tab strip. 898 // it uses the same orientation used by the tabs on the tab strip.
876 gfx::Rect adjusted_bounds(dragged_bounds); 899 gfx::Rect adjusted_bounds(dragged_bounds);
877 adjusted_bounds.set_x( 900 adjusted_bounds.set_x(
878 attached_tabstrip_->MirroredLeftPointForRect(adjusted_bounds)); 901 attached_tabstrip_->MirroredLeftPointForRect(adjusted_bounds));
879 902
880 int index = -1; 903 int index = -1;
881 for (int i = 0; i < attached_tabstrip_->GetTabCount(); ++i) { 904 for (int i = 0; i < attached_tabstrip_->tab_count(); ++i) {
882 gfx::Rect ideal_bounds = attached_tabstrip_->GetIdealBounds(i); 905 const gfx::Rect& ideal_bounds = attached_tabstrip_->ideal_bounds(i);
883 gfx::Rect left_half = ideal_bounds; 906 gfx::Rect left_half = ideal_bounds;
884 left_half.set_width(left_half.width() / 2); 907 left_half.set_width(left_half.width() / 2);
885 gfx::Rect right_half = ideal_bounds; 908 gfx::Rect right_half = ideal_bounds;
886 right_half.set_width(ideal_bounds.width() - left_half.width()); 909 right_half.set_width(ideal_bounds.width() - left_half.width());
887 right_half.set_x(left_half.right()); 910 right_half.set_x(left_half.right());
888 right_tab_x = right_half.right(); 911 right_tab_x = right_half.right();
889 if (adjusted_bounds.x() >= right_half.x() && 912 if (adjusted_bounds.x() >= right_half.x() &&
890 adjusted_bounds.x() < right_half.right()) { 913 adjusted_bounds.x() < right_half.right()) {
891 index = i + 1; 914 index = i + 1;
892 break; 915 break;
(...skipping 19 matching lines...) Expand all
912 } 935 }
913 936
914 gfx::Rect DraggedTabController::GetDraggedViewTabStripBounds( 937 gfx::Rect DraggedTabController::GetDraggedViewTabStripBounds(
915 const gfx::Point& screen_point) { 938 const gfx::Point& screen_point) {
916 gfx::Point client_point = 939 gfx::Point client_point =
917 ConvertScreenPointToTabStripPoint(attached_tabstrip_, screen_point); 940 ConvertScreenPointToTabStripPoint(attached_tabstrip_, screen_point);
918 if (attached_tab_) { 941 if (attached_tab_) {
919 return gfx::Rect(client_point.x(), client_point.y(), 942 return gfx::Rect(client_point.x(), client_point.y(),
920 attached_tab_->width(), attached_tab_->height()); 943 attached_tab_->width(), attached_tab_->height());
921 } 944 }
922 // attached_tab_ is NULL when inserting into a new tabstrip. 945 if (attached_tabstrip_->type() == BaseTabStrip::HORIZONTAL_TAB_STRIP) {
923 double sel_width, unselected_width; 946 // attached_tab_ is NULL when inserting into a new tabstrip.
924 attached_tabstrip_->GetCurrentTabWidths(&sel_width, &unselected_width); 947 double sel_width, unselected_width;
948 static_cast<TabStrip*>(attached_tabstrip_)->GetCurrentTabWidths(
949 &sel_width, &unselected_width);
950 return gfx::Rect(client_point.x(), client_point.y(),
951 static_cast<int>(sel_width),
952 Tab::GetStandardSize().height());
953 }
925 // TODO(sky): this needs to adjust based on orientation of the tab strip. 954 // TODO(sky): this needs to adjust based on orientation of the tab strip.
926 return gfx::Rect(client_point.x(), client_point.y(), 955 return gfx::Rect(client_point.x(), client_point.y(),
927 static_cast<int>(sel_width), 956 0, Tab::GetStandardSize().height());
928 Tab::GetStandardSize().height());
929 } 957 }
930 958
931 gfx::Point DraggedTabController::GetAttachedTabDragPoint( 959 gfx::Point DraggedTabController::GetAttachedTabDragPoint(
932 const gfx::Point& screen_point) { 960 const gfx::Point& screen_point) {
933 DCHECK(attached_tabstrip_); // The tab must be attached. 961 DCHECK(attached_tabstrip_); // The tab must be attached.
934 962
935 int x = screen_point.x() - mouse_offset_.x(); 963 int x = screen_point.x() - mouse_offset_.x();
936 int y = screen_point.y() - mouse_offset_.y(); 964 int y = screen_point.y() - mouse_offset_.y();
937 965
938 gfx::Point tab_loc(x, y); 966 gfx::Point tab_loc(x, y);
939 views::View::ConvertPointToView(NULL, attached_tabstrip_, &tab_loc); 967 views::View::ConvertPointToView(NULL, attached_tabstrip_, &tab_loc);
940 968
941 x = tab_loc.x(); 969 x = tab_loc.x();
942 y = tab_loc.y(); 970 y = tab_loc.y();
943 971
944 const gfx::Size& tab_size = attached_tab_->bounds().size(); 972 const gfx::Size& tab_size = attached_tab_->bounds().size();
945 973
946 int max_x = attached_tabstrip_->bounds().right() - tab_size.width(); 974 int max_x = attached_tabstrip_->bounds().right() - tab_size.width();
947 // TODO(sky): this needs to adjust based on orientation of the tab strip. 975 // TODO(sky): this needs to adjust based on orientation of the tab strip.
948 x = std::min(std::max(x, 0), max_x); 976 x = std::min(std::max(x, 0), max_x);
949 y = 0; 977 y = 0;
950 return gfx::Point(x, y); 978 return gfx::Point(x, y);
951 } 979 }
952 980
953 Tab* DraggedTabController::GetTabMatchingDraggedContents( 981 BaseTabRenderer* DraggedTabController::GetTabMatchingDraggedContents(
954 TabStrip* tabstrip) const { 982 BaseTabStrip* tabstrip) const {
955 int model_index = GetModel(tabstrip)->GetIndexOfTabContents(dragged_contents_) ; 983 int model_index =
984 GetModel(tabstrip)->GetIndexOfTabContents(dragged_contents_);
956 return model_index == TabStripModel::kNoTab ? 985 return model_index == TabStripModel::kNoTab ?
957 NULL : tabstrip->GetTabAtModelIndex(model_index); 986 NULL : tabstrip->GetBaseTabAtModelIndex(model_index);
958 } 987 }
959 988
960 void DraggedTabController::EndDragImpl(EndDragType type) { 989 void DraggedTabController::EndDragImpl(EndDragType type) {
961 // WARNING: this may be invoked multiple times. In particular, if deletion 990 // WARNING: this may be invoked multiple times. In particular, if deletion
962 // occurs after a delay (as it does when the tab is released in the original 991 // occurs after a delay (as it does when the tab is released in the original
963 // tab strip) and the navigation controller/tab contents is deleted before 992 // tab strip) and the navigation controller/tab contents is deleted before
964 // the animation finishes, this is invoked twice. The second time through 993 // the animation finishes, this is invoked twice. The second time through
965 // type == TAB_DESTROYED. 994 // type == TAB_DESTROYED.
966 995
967 bring_to_front_timer_.Stop(); 996 bring_to_front_timer_.Stop();
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 #else 1277 #else
1249 NOTIMPLEMENTED(); 1278 NOTIMPLEMENTED();
1250 #endif 1279 #endif
1251 } 1280 }
1252 } 1281 }
1253 1282
1254 TabStripModel* DraggedTabController::GetModel(BaseTabStrip* tabstrip) const { 1283 TabStripModel* DraggedTabController::GetModel(BaseTabStrip* tabstrip) const {
1255 return static_cast<BrowserTabStripController*>(tabstrip->controller())-> 1284 return static_cast<BrowserTabStripController*>(tabstrip->controller())->
1256 model(); 1285 model();
1257 } 1286 }
OLDNEW
« no previous file with comments | « chrome/browser/views/tabs/dragged_tab_controller.h ('k') | chrome/browser/views/tabs/side_tab_strip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698