OLD | NEW |
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" |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 // Ignored. | 467 // Ignored. |
468 } | 468 } |
469 | 469 |
470 /////////////////////////////////////////////////////////////////////////////// | 470 /////////////////////////////////////////////////////////////////////////////// |
471 // DraggedTabController, NotificationObserver implementation: | 471 // DraggedTabController, NotificationObserver implementation: |
472 | 472 |
473 void DraggedTabController::Observe(NotificationType type, | 473 void DraggedTabController::Observe(NotificationType type, |
474 const NotificationSource& source, | 474 const NotificationSource& source, |
475 const NotificationDetails& details) { | 475 const NotificationDetails& details) { |
476 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); | 476 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); |
477 DCHECK(Source<TabContents>(source).ptr() == dragged_contents_); | 477 DCHECK(Source<TabContents>(source).ptr() == |
| 478 dragged_contents_->tab_contents()); |
478 EndDragImpl(TAB_DESTROYED); | 479 EndDragImpl(TAB_DESTROYED); |
479 } | 480 } |
480 | 481 |
481 /////////////////////////////////////////////////////////////////////////////// | 482 /////////////////////////////////////////////////////////////////////////////// |
482 // DraggedTabController, MessageLoop::Observer implementation: | 483 // DraggedTabController, MessageLoop::Observer implementation: |
483 | 484 |
484 #if defined(OS_WIN) | 485 #if defined(OS_WIN) |
485 void DraggedTabController::WillProcessMessage(const MSG& msg) { | 486 void DraggedTabController::WillProcessMessage(const MSG& msg) { |
486 } | 487 } |
487 | 488 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 } | 570 } |
570 } | 571 } |
571 } else if (dock_info_.type() != DockInfo::NONE && | 572 } else if (dock_info_.type() != DockInfo::NONE && |
572 !dock_controllers_.empty()) { | 573 !dock_controllers_.empty()) { |
573 // Current dock position is the same as last, update the controller's | 574 // Current dock position is the same as last, update the controller's |
574 // in_enable_area state as it may have changed. | 575 // in_enable_area state as it may have changed. |
575 dock_controllers_.back()->UpdateInEnabledArea(dock_info_.in_enable_area()); | 576 dock_controllers_.back()->UpdateInEnabledArea(dock_info_.in_enable_area()); |
576 } | 577 } |
577 } | 578 } |
578 | 579 |
579 void DraggedTabController::SetDraggedContents(TabContents* new_contents) { | 580 void DraggedTabController::SetDraggedContents( |
| 581 TabContentsWrapper* new_contents) { |
580 if (dragged_contents_) { | 582 if (dragged_contents_) { |
581 registrar_.Remove(this, | 583 registrar_.Remove(this, |
582 NotificationType::TAB_CONTENTS_DESTROYED, | 584 NotificationType::TAB_CONTENTS_DESTROYED, |
583 Source<TabContents>(dragged_contents_)); | 585 Source<TabContents>(dragged_contents_->tab_contents())); |
584 if (original_delegate_) | 586 if (original_delegate_) |
585 dragged_contents_->set_delegate(original_delegate_); | 587 dragged_contents_->set_delegate(original_delegate_); |
586 } | 588 } |
587 original_delegate_ = NULL; | 589 original_delegate_ = NULL; |
588 dragged_contents_ = new_contents; | 590 dragged_contents_ = new_contents; |
589 if (dragged_contents_) { | 591 if (dragged_contents_) { |
590 registrar_.Add(this, | 592 registrar_.Add(this, |
591 NotificationType::TAB_CONTENTS_DESTROYED, | 593 NotificationType::TAB_CONTENTS_DESTROYED, |
592 Source<TabContents>(dragged_contents_)); | 594 Source<TabContents>(dragged_contents_->tab_contents())); |
593 | 595 |
594 // We need to be the delegate so we receive messages about stuff, | 596 // We need to be the delegate so we receive messages about stuff, |
595 // otherwise our dragged_contents() may be replaced and subsequently | 597 // otherwise our dragged_contents() may be replaced and subsequently |
596 // collected/destroyed while the drag is in process, leading to | 598 // collected/destroyed while the drag is in process, leading to |
597 // nasty crashes. | 599 // nasty crashes. |
598 original_delegate_ = dragged_contents_->delegate(); | 600 original_delegate_ = dragged_contents_->delegate(); |
599 dragged_contents_->set_delegate(this); | 601 dragged_contents_->set_delegate(this); |
600 } | 602 } |
601 } | 603 } |
602 | 604 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 if (!tab) { | 827 if (!tab) { |
826 // There is no Tab in |attached_tabstrip| that corresponds to the dragged | 828 // There is no Tab in |attached_tabstrip| that corresponds to the dragged |
827 // TabContents. We must now create one. | 829 // TabContents. We must now create one. |
828 | 830 |
829 // Remove ourselves as the delegate now that the dragged TabContents is | 831 // Remove ourselves as the delegate now that the dragged TabContents is |
830 // being inserted back into a Browser. | 832 // being inserted back into a Browser. |
831 dragged_contents_->set_delegate(NULL); | 833 dragged_contents_->set_delegate(NULL); |
832 original_delegate_ = NULL; | 834 original_delegate_ = NULL; |
833 | 835 |
834 // Return the TabContents' to normalcy. | 836 // Return the TabContents' to normalcy. |
835 dragged_contents_->set_capturing_contents(false); | 837 dragged_contents_->tab_contents()->set_capturing_contents(false); |
836 | 838 |
837 // Inserting counts as a move. We don't want the tabs to jitter when the | 839 // Inserting counts as a move. We don't want the tabs to jitter when the |
838 // user moves the tab immediately after attaching it. | 840 // user moves the tab immediately after attaching it. |
839 last_move_screen_loc_ = MajorAxisValue(screen_point, attached_tabstrip); | 841 last_move_screen_loc_ = MajorAxisValue(screen_point, attached_tabstrip); |
840 | 842 |
841 // Figure out where to insert the tab based on the bounds of the dragged | 843 // Figure out where to insert the tab based on the bounds of the dragged |
842 // representation and the ideal bounds of the other Tabs already in the | 844 // representation and the ideal bounds of the other Tabs already in the |
843 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are | 845 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are |
844 // changing due to animation). | 846 // changing due to animation). |
845 gfx::Rect bounds = GetDraggedViewTabStripBounds(screen_point); | 847 gfx::Rect bounds = GetDraggedViewTabStripBounds(screen_point); |
(...skipping 18 matching lines...) Expand all Loading... |
864 static_cast<int>(tab->width()))); | 866 static_cast<int>(tab->width()))); |
865 } | 867 } |
866 | 868 |
867 // Move the corresponding window to the front. | 869 // Move the corresponding window to the front. |
868 attached_tabstrip_->GetWindow()->Activate(); | 870 attached_tabstrip_->GetWindow()->Activate(); |
869 } | 871 } |
870 | 872 |
871 void DraggedTabController::Detach() { | 873 void DraggedTabController::Detach() { |
872 // Prevent the TabContents' HWND from being hidden by any of the model | 874 // Prevent the TabContents' HWND from being hidden by any of the model |
873 // operations performed during the drag. | 875 // operations performed during the drag. |
874 dragged_contents_->set_capturing_contents(true); | 876 dragged_contents_->tab_contents()->set_capturing_contents(true); |
875 | 877 |
876 // Update the Model. | 878 // Update the Model. |
877 TabRendererData tab_data = attached_tab_->data(); | 879 TabRendererData tab_data = attached_tab_->data(); |
878 TabStripModel* attached_model = GetModel(attached_tabstrip_); | 880 TabStripModel* attached_model = GetModel(attached_tabstrip_); |
879 int index = attached_model->GetIndexOfTabContents(dragged_contents_); | 881 int index = attached_model->GetIndexOfTabContents(dragged_contents_); |
880 DCHECK(index != -1); | 882 DCHECK(index != -1); |
881 // Hide the tab so that the user doesn't see it animate closed. | 883 // Hide the tab so that the user doesn't see it animate closed. |
882 attached_tab_->SetVisible(false); | 884 attached_tab_->SetVisible(false); |
883 int attached_tab_width = attached_tab_->width(); | 885 int attached_tab_width = attached_tab_->width(); |
884 attached_model->DetachTabContentsAt(index); | 886 attached_model->DetachTabContentsAt(index); |
885 // Detaching may end up deleting the tab, drop references to it. | 887 // Detaching may end up deleting the tab, drop references to it. |
886 attached_tab_ = NULL; | 888 attached_tab_ = NULL; |
887 | 889 |
888 // If we've removed the last Tab from the TabStrip, hide the frame now. | 890 // If we've removed the last Tab from the TabStrip, hide the frame now. |
889 if (attached_model->empty()) | 891 if (attached_model->empty()) |
890 HideFrame(); | 892 HideFrame(); |
891 | 893 |
892 // Set up the photo booth to start capturing the contents of the dragged | 894 // Set up the photo booth to start capturing the contents of the dragged |
893 // TabContents. | 895 // TabContents. |
894 if (!photobooth_.get()) { | 896 if (!photobooth_.get()) { |
895 photobooth_.reset( | 897 photobooth_.reset(NativeViewPhotobooth::Create( |
896 NativeViewPhotobooth::Create(dragged_contents_->GetNativeView())); | 898 dragged_contents_->tab_contents()->GetNativeView())); |
897 } | 899 } |
898 | 900 |
899 // Create the dragged view. | 901 // Create the dragged view. |
900 EnsureDraggedView(tab_data); | 902 EnsureDraggedView(tab_data); |
901 view_->SetTabWidthAndUpdate(attached_tab_width, photobooth_.get()); | 903 view_->SetTabWidthAndUpdate(attached_tab_width, photobooth_.get()); |
902 | 904 |
903 // Detaching resets the delegate, but we still want to be the delegate. | 905 // Detaching resets the delegate, but we still want to be the delegate. |
904 dragged_contents_->set_delegate(this); | 906 dragged_contents_->set_delegate(this); |
905 | 907 |
906 attached_tabstrip_ = NULL; | 908 attached_tabstrip_ = NULL; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 pinned_); | 1222 pinned_); |
1221 new_browser->window()->Show(); | 1223 new_browser->window()->Show(); |
1222 } | 1224 } |
1223 | 1225 |
1224 CleanUpHiddenFrame(); | 1226 CleanUpHiddenFrame(); |
1225 } | 1227 } |
1226 | 1228 |
1227 void DraggedTabController::EnsureDraggedView(const TabRendererData& data) { | 1229 void DraggedTabController::EnsureDraggedView(const TabRendererData& data) { |
1228 if (!view_.get()) { | 1230 if (!view_.get()) { |
1229 gfx::Rect tab_bounds; | 1231 gfx::Rect tab_bounds; |
1230 dragged_contents_->GetContainerBounds(&tab_bounds); | 1232 dragged_contents_->tab_contents()->GetContainerBounds(&tab_bounds); |
1231 BaseTab* renderer = source_tabstrip_->CreateTabForDragging(); | 1233 BaseTab* renderer = source_tabstrip_->CreateTabForDragging(); |
1232 renderer->SetData(data); | 1234 renderer->SetData(data); |
1233 // DraggedTabView takes ownership of renderer. | 1235 // DraggedTabView takes ownership of renderer. |
1234 view_.reset(new DraggedTabView(renderer, mouse_offset_, | 1236 view_.reset(new DraggedTabView(renderer, mouse_offset_, |
1235 tab_bounds.size(), | 1237 tab_bounds.size(), |
1236 Tab::GetMinimumSelectedSize())); | 1238 Tab::GetMinimumSelectedSize())); |
1237 } | 1239 } |
1238 } | 1240 } |
1239 | 1241 |
1240 gfx::Point DraggedTabController::GetCursorScreenPoint() const { | 1242 gfx::Point DraggedTabController::GetCursorScreenPoint() const { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 #else | 1334 #else |
1333 NOTIMPLEMENTED(); | 1335 NOTIMPLEMENTED(); |
1334 #endif | 1336 #endif |
1335 } | 1337 } |
1336 } | 1338 } |
1337 | 1339 |
1338 TabStripModel* DraggedTabController::GetModel(BaseTabStrip* tabstrip) const { | 1340 TabStripModel* DraggedTabController::GetModel(BaseTabStrip* tabstrip) const { |
1339 return static_cast<BrowserTabStripController*>(tabstrip->controller())-> | 1341 return static_cast<BrowserTabStripController*>(tabstrip->controller())-> |
1340 model(); | 1342 model(); |
1341 } | 1343 } |
OLD | NEW |