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/gtk/tabs/dragged_tab_controller_gtk.h" | 5 #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "chrome/browser/gtk/browser_window_gtk.h" | 10 #include "chrome/browser/gtk/browser_window_gtk.h" |
11 #include "chrome/browser/gtk/gtk_util.h" | 11 #include "chrome/browser/gtk/gtk_util.h" |
12 #include "chrome/browser/gtk/tabs/dragged_tab_gtk.h" | 12 #include "chrome/browser/gtk/tabs/dragged_tab_gtk.h" |
13 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" | 13 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
14 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/tab_contents_wrapper.h" |
16 #include "chrome/browser/tabs/tab_strip_model.h" | 17 #include "chrome/browser/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Delay, in ms, during dragging before we bring a window to front. | 23 // Delay, in ms, during dragging before we bring a window to front. |
23 const int kBringToFrontDelay = 750; | 24 const int kBringToFrontDelay = 750; |
24 | 25 |
25 // Used to determine how far a tab must obscure another tab in order to swap | 26 // Used to determine how far a tab must obscure another tab in order to swap |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 bool DraggedTabControllerGtk::EndDrag(bool canceled) { | 87 bool DraggedTabControllerGtk::EndDrag(bool canceled) { |
87 return EndDragImpl(canceled ? CANCELED : NORMAL); | 88 return EndDragImpl(canceled ? CANCELED : NORMAL); |
88 } | 89 } |
89 | 90 |
90 TabGtk* DraggedTabControllerGtk::GetDragSourceTabForContents( | 91 TabGtk* DraggedTabControllerGtk::GetDragSourceTabForContents( |
91 TabContents* contents) const { | 92 TabContents* contents) const { |
92 if (attached_tabstrip_ == source_tabstrip_) | 93 if (attached_tabstrip_ == source_tabstrip_) |
93 return contents == dragged_contents_ ? source_tab_ : NULL; | 94 return contents == dragged_contents_->tab_contents() ? source_tab_ : NULL; |
94 return NULL; | 95 return NULL; |
95 } | 96 } |
96 | 97 |
97 bool DraggedTabControllerGtk::IsDragSourceTab(const TabGtk* tab) const { | 98 bool DraggedTabControllerGtk::IsDragSourceTab(const TabGtk* tab) const { |
98 return source_tab_ == tab; | 99 return source_tab_ == tab; |
99 } | 100 } |
100 | 101 |
101 bool DraggedTabControllerGtk::IsTabDetached(const TabGtk* tab) const { | 102 bool DraggedTabControllerGtk::IsTabDetached(const TabGtk* tab) const { |
102 if (!IsDragSourceTab(tab)) | 103 if (!IsDragSourceTab(tab)) |
103 return false; | 104 return false; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // Ignored. | 189 // Ignored. |
189 } | 190 } |
190 | 191 |
191 //////////////////////////////////////////////////////////////////////////////// | 192 //////////////////////////////////////////////////////////////////////////////// |
192 // DraggedTabControllerGtk, NotificationObserver implementation: | 193 // DraggedTabControllerGtk, NotificationObserver implementation: |
193 | 194 |
194 void DraggedTabControllerGtk::Observe(NotificationType type, | 195 void DraggedTabControllerGtk::Observe(NotificationType type, |
195 const NotificationSource& source, | 196 const NotificationSource& source, |
196 const NotificationDetails& details) { | 197 const NotificationDetails& details) { |
197 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); | 198 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); |
198 DCHECK(Source<TabContents>(source).ptr() == dragged_contents_); | 199 DCHECK(Source<TabContentsWrapper>(source).ptr() == dragged_contents_); |
199 EndDragImpl(TAB_DESTROYED); | 200 EndDragImpl(TAB_DESTROYED); |
200 } | 201 } |
201 | 202 |
202 void DraggedTabControllerGtk::InitWindowCreatePoint() { | 203 void DraggedTabControllerGtk::InitWindowCreatePoint() { |
203 window_create_point_.SetPoint(mouse_offset_.x(), mouse_offset_.y()); | 204 window_create_point_.SetPoint(mouse_offset_.x(), mouse_offset_.y()); |
204 } | 205 } |
205 | 206 |
206 gfx::Point DraggedTabControllerGtk::GetWindowCreatePoint() const { | 207 gfx::Point DraggedTabControllerGtk::GetWindowCreatePoint() const { |
207 gfx::Point cursor_point = GetCursorScreenPoint(); | 208 gfx::Point cursor_point = GetCursorScreenPoint(); |
208 return gfx::Point(cursor_point.x() - window_create_point_.x(), | 209 return gfx::Point(cursor_point.x() - window_create_point_.x(), |
209 cursor_point.y() - window_create_point_.y()); | 210 cursor_point.y() - window_create_point_.y()); |
210 } | 211 } |
211 | 212 |
212 void DraggedTabControllerGtk::SetDraggedContents(TabContents* new_contents) { | 213 void DraggedTabControllerGtk::SetDraggedContents( |
| 214 TabContentsWrapper* new_contents) { |
213 if (dragged_contents_) { | 215 if (dragged_contents_) { |
214 registrar_.Remove(this, | 216 registrar_.Remove(this, |
215 NotificationType::TAB_CONTENTS_DESTROYED, | 217 NotificationType::TAB_CONTENTS_DESTROYED, |
216 Source<TabContents>(dragged_contents_)); | 218 Source<TabContentsWrapper>(dragged_contents_)); |
217 if (original_delegate_) | 219 if (original_delegate_) |
218 dragged_contents_->set_delegate(original_delegate_); | 220 dragged_contents_->set_delegate(original_delegate_); |
219 } | 221 } |
220 original_delegate_ = NULL; | 222 original_delegate_ = NULL; |
221 dragged_contents_ = new_contents; | 223 dragged_contents_ = new_contents; |
222 if (dragged_contents_) { | 224 if (dragged_contents_) { |
223 registrar_.Add(this, | 225 registrar_.Add(this, |
224 NotificationType::TAB_CONTENTS_DESTROYED, | 226 NotificationType::TAB_CONTENTS_DESTROYED, |
225 Source<TabContents>(dragged_contents_)); | 227 Source<TabContentsWrapper>(dragged_contents_)); |
226 | 228 |
227 // We need to be the delegate so we receive messages about stuff, | 229 // We need to be the delegate so we receive messages about stuff, |
228 // otherwise our dragged_contents() may be replaced and subsequently | 230 // otherwise our dragged_contents() may be replaced and subsequently |
229 // collected/destroyed while the drag is in process, leading to | 231 // collected/destroyed while the drag is in process, leading to |
230 // nasty crashes. | 232 // nasty crashes. |
231 original_delegate_ = dragged_contents_->delegate(); | 233 original_delegate_ = dragged_contents_->delegate(); |
232 dragged_contents_->set_delegate(this); | 234 dragged_contents_->set_delegate(this); |
233 } | 235 } |
234 } | 236 } |
235 | 237 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 if (!tab) { | 375 if (!tab) { |
374 // There is no tab in |attached_tabstrip| that corresponds to the dragged | 376 // There is no tab in |attached_tabstrip| that corresponds to the dragged |
375 // TabContents. We must now create one. | 377 // TabContents. We must now create one. |
376 | 378 |
377 // Remove ourselves as the delegate now that the dragged TabContents is | 379 // Remove ourselves as the delegate now that the dragged TabContents is |
378 // being inserted back into a Browser. | 380 // being inserted back into a Browser. |
379 dragged_contents_->set_delegate(NULL); | 381 dragged_contents_->set_delegate(NULL); |
380 original_delegate_ = NULL; | 382 original_delegate_ = NULL; |
381 | 383 |
382 // Return the TabContents' to normalcy. | 384 // Return the TabContents' to normalcy. |
383 dragged_contents_->set_capturing_contents(false); | 385 dragged_contents_->tab_contents()->set_capturing_contents(false); |
384 | 386 |
385 // We need to ask the tabstrip we're attached to ensure that the ideal | 387 // We need to ask the tabstrip we're attached to ensure that the ideal |
386 // bounds for all its tabs are correctly generated, because the calculation | 388 // bounds for all its tabs are correctly generated, because the calculation |
387 // in GetInsertionIndexForDraggedBounds needs them to be to figure out the | 389 // in GetInsertionIndexForDraggedBounds needs them to be to figure out the |
388 // appropriate insertion index. | 390 // appropriate insertion index. |
389 attached_tabstrip_->GenerateIdealBounds(); | 391 attached_tabstrip_->GenerateIdealBounds(); |
390 | 392 |
391 // Inserting counts as a move. We don't want the tabs to jitter when the | 393 // Inserting counts as a move. We don't want the tabs to jitter when the |
392 // user moves the tab immediately after attaching it. | 394 // user moves the tab immediately after attaching it. |
393 last_move_screen_x_ = screen_point.x(); | 395 last_move_screen_x_ = screen_point.x(); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 new_browser->window()->Show(); | 680 new_browser->window()->Show(); |
679 CleanUpHiddenFrame(); | 681 CleanUpHiddenFrame(); |
680 } | 682 } |
681 | 683 |
682 return destroy_immediately; | 684 return destroy_immediately; |
683 } | 685 } |
684 | 686 |
685 void DraggedTabControllerGtk::EnsureDraggedTab() { | 687 void DraggedTabControllerGtk::EnsureDraggedTab() { |
686 if (!dragged_tab_.get()) { | 688 if (!dragged_tab_.get()) { |
687 gfx::Rect rect; | 689 gfx::Rect rect; |
688 dragged_contents_->GetContainerBounds(&rect); | 690 dragged_contents_->tab_contents()->GetContainerBounds(&rect); |
689 | 691 |
690 dragged_tab_.reset(new DraggedTabGtk(dragged_contents_, mouse_offset_, | 692 dragged_tab_.reset(new DraggedTabGtk(dragged_contents_->tab_contents(), |
691 rect.size(), mini_)); | 693 mouse_offset_, rect.size(), mini_)); |
692 } | 694 } |
693 } | 695 } |
694 | 696 |
695 gfx::Point DraggedTabControllerGtk::GetCursorScreenPoint() const { | 697 gfx::Point DraggedTabControllerGtk::GetCursorScreenPoint() const { |
696 // Get default display and screen. | 698 // Get default display and screen. |
697 GdkDisplay* display = gdk_display_get_default(); | 699 GdkDisplay* display = gdk_display_get_default(); |
698 | 700 |
699 // Get cursor position. | 701 // Get cursor position. |
700 int x, y; | 702 int x, y; |
701 gdk_display_get_pointer(display, NULL, &x, &y, NULL); | 703 gdk_display_get_pointer(display, NULL, &x, &y, NULL); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 gfx::NativeView dragged_tab = dragged_tab_->widget(); | 778 gfx::NativeView dragged_tab = dragged_tab_->widget(); |
777 dock_windows_.insert(dragged_tab); | 779 dock_windows_.insert(dragged_tab); |
778 window = DockInfo::GetLocalProcessWindowAtPoint(GetCursorScreenPoint(), | 780 window = DockInfo::GetLocalProcessWindowAtPoint(GetCursorScreenPoint(), |
779 dock_windows_); | 781 dock_windows_); |
780 dock_windows_.erase(dragged_tab); | 782 dock_windows_.erase(dragged_tab); |
781 } | 783 } |
782 | 784 |
783 if (window) | 785 if (window) |
784 gtk_window_present(GTK_WINDOW(window)); | 786 gtk_window_present(GTK_WINDOW(window)); |
785 } | 787 } |
OLD | NEW |