OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
6 | 6 |
7 #import "base/mac/mac_util.h" | 7 #import "base/mac/mac_util.h" |
8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
9 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 9 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
10 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 10 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // When you finally leave the strip, we treat that as the origin. | 207 // When you finally leave the strip, we treat that as the origin. |
208 dragOrigin_.x = thisPoint.x; | 208 dragOrigin_.x = thisPoint.x; |
209 } else { | 209 } else { |
210 // Still dragging within the tab strip, wait for the next drag event. | 210 // Still dragging within the tab strip, wait for the next drag event. |
211 return; | 211 return; |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 // Do not start dragging until the user has "torn" the tab off by | 215 // Do not start dragging until the user has "torn" the tab off by |
216 // moving more than 3 pixels. | 216 // moving more than 3 pixels. |
217 NSDate* targetDwellDate = nil; // The date this target was first chosen. | |
218 | |
219 NSPoint thisPoint = [NSEvent mouseLocation]; | 217 NSPoint thisPoint = [NSEvent mouseLocation]; |
220 | 218 |
221 // Iterate over possible targets checking for the one the mouse is in. | 219 // Iterate over possible targets checking for the one the mouse is in. |
222 // If the tab is just in the frame, bring the window forward to make it | 220 // If the tab is just in the frame, bring the window forward to make it |
223 // easier to drop something there. If it's in the tab strip, set the new | 221 // easier to drop something there. If it's in the tab strip, set the new |
224 // target so that it pops into that window. We can't cache this because we | 222 // target so that it pops into that window. We can't cache this because we |
225 // need the z-order to be correct. | 223 // need the z-order to be correct. |
226 NSArray* targets = [self dropTargetsForController:draggedController_]; | 224 NSArray* targets = [self dropTargetsForController:draggedController_]; |
227 TabWindowController* newTarget = nil; | 225 TabWindowController* newTarget = nil; |
228 for (TabWindowController* target in targets) { | 226 for (TabWindowController* target in targets) { |
229 NSRect windowFrame = [[target window] frame]; | 227 NSRect windowFrame = [[target window] frame]; |
230 if (NSPointInRect(thisPoint, windowFrame)) { | 228 if (NSPointInRect(thisPoint, windowFrame)) { |
231 [[target window] orderFront:self]; | 229 [[target window] orderFront:self]; |
232 NSRect tabStripFrame = [[target tabStripView] frame]; | 230 NSRect tabStripFrame = [[target tabStripView] frame]; |
233 tabStripFrame.origin = [[target window] | 231 tabStripFrame.origin = [[target window] |
234 convertBaseToScreen:tabStripFrame.origin]; | 232 convertBaseToScreen:tabStripFrame.origin]; |
235 if (NSPointInRect(thisPoint, tabStripFrame)) { | 233 if (NSPointInRect(thisPoint, tabStripFrame)) { |
236 newTarget = target; | 234 newTarget = target; |
237 } | 235 } |
238 break; | 236 break; |
239 } | 237 } |
240 } | 238 } |
241 | 239 |
242 // If we're now targeting a new window, re-layout the tabs in the old | 240 // If we're now targeting a new window, re-layout the tabs in the old |
243 // target and reset how long we've been hovering over this new one. | 241 // target and reset how long we've been hovering over this new one. |
244 if (targetController_ != newTarget) { | 242 if (targetController_ != newTarget) { |
245 targetDwellDate = [NSDate date]; | |
246 [targetController_ removePlaceholder]; | 243 [targetController_ removePlaceholder]; |
247 targetController_ = newTarget; | 244 targetController_ = newTarget; |
248 if (!newTarget) { | 245 if (!newTarget) { |
249 tearTime_ = [NSDate timeIntervalSinceReferenceDate]; | 246 tearTime_ = [NSDate timeIntervalSinceReferenceDate]; |
250 tearOrigin_ = [dragWindow_ frame].origin; | 247 tearOrigin_ = [dragWindow_ frame].origin; |
251 } | 248 } |
252 } | 249 } |
253 | 250 |
254 // Create or identify the dragged controller. | 251 // Create or identify the dragged controller. |
255 if (!draggedController_) { | 252 if (!draggedController_) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 NSRect sourceFrame = [dragWindow_ frame]; | 344 NSRect sourceFrame = [dragWindow_ frame]; |
348 origin.y = NSMinY(targetFrame) + | 345 origin.y = NSMinY(targetFrame) + |
349 (NSHeight(targetFrame) - NSHeight(sourceFrame)); | 346 (NSHeight(targetFrame) - NSHeight(sourceFrame)); |
350 } | 347 } |
351 [dragWindow_ setFrameOrigin:NSMakePoint(origin.x, origin.y)]; | 348 [dragWindow_ setFrameOrigin:NSMakePoint(origin.x, origin.y)]; |
352 | 349 |
353 // If we're not hovering over any window, make the window fully | 350 // If we're not hovering over any window, make the window fully |
354 // opaque. Otherwise, find where the tab might be dropped and insert | 351 // opaque. Otherwise, find where the tab might be dropped and insert |
355 // a placeholder so it appears like it's part of that window. | 352 // a placeholder so it appears like it's part of that window. |
356 if (targetController_) { | 353 if (targetController_) { |
357 if (![[targetController_ window] isKeyWindow]) { | 354 if (![[targetController_ window] isKeyWindow]) |
358 // && ([targetDwellDate timeIntervalSinceNow] < -REQUIRED_DWELL)) { | |
359 [[targetController_ window] orderFront:nil]; | 355 [[targetController_ window] orderFront:nil]; |
360 targetDwellDate = nil; | |
361 } | |
362 | 356 |
363 // Compute where placeholder should go and insert it into the | 357 // Compute where placeholder should go and insert it into the |
364 // destination tab strip. | 358 // destination tab strip. |
365 TabView* draggedTabView = (TabView*)[draggedController_ activeTabView]; | 359 TabView* draggedTabView = (TabView*)[draggedController_ activeTabView]; |
366 NSRect tabFrame = [draggedTabView frame]; | 360 NSRect tabFrame = [draggedTabView frame]; |
367 tabFrame.origin = [dragWindow_ convertBaseToScreen:tabFrame.origin]; | 361 tabFrame.origin = [dragWindow_ convertBaseToScreen:tabFrame.origin]; |
368 tabFrame.origin = [[targetController_ window] | 362 tabFrame.origin = [[targetController_ window] |
369 convertScreenToBase:tabFrame.origin]; | 363 convertScreenToBase:tabFrame.origin]; |
370 tabFrame = [[targetController_ tabStripView] | 364 tabFrame = [[targetController_ tabStripView] |
371 convertRect:tabFrame fromView:nil]; | 365 convertRect:tabFrame fromView:nil]; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 NOTREACHED(); | 555 NOTREACHED(); |
562 } | 556 } |
563 } | 557 } |
564 if (useCache) { | 558 if (useCache) { |
565 workspaceIDCache_[windowID] = workspace; | 559 workspaceIDCache_[windowID] = workspace; |
566 } | 560 } |
567 return workspace; | 561 return workspace; |
568 } | 562 } |
569 | 563 |
570 @end | 564 @end |
OLD | NEW |