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 #import "chrome/browser/cocoa/tab_view.h" | 5 #import "chrome/browser/cocoa/tab_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/nsimage_cache_mac.h" | 8 #include "base/nsimage_cache_mac.h" |
9 #include "chrome/browser/browser_theme_provider.h" | 9 #include "chrome/browser/browser_theme_provider.h" |
10 #import "chrome/browser/cocoa/tab_controller.h" | 10 #import "chrome/browser/cocoa/tab_controller.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // controller. | 277 // controller. |
278 scoped_nsobject<TabController> controller([controller_ retain]); | 278 scoped_nsobject<TabController> controller([controller_ retain]); |
279 | 279 |
280 // Because we move views between windows, we need to handle the event loop | 280 // Because we move views between windows, we need to handle the event loop |
281 // ourselves. Ideally we should use the standard event loop. | 281 // ourselves. Ideally we should use the standard event loop. |
282 while (1) { | 282 while (1) { |
283 theEvent = | 283 theEvent = |
284 [NSApp nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask | 284 [NSApp nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask |
285 untilDate:[NSDate distantFuture] | 285 untilDate:[NSDate distantFuture] |
286 inMode:NSDefaultRunLoopMode dequeue:YES]; | 286 inMode:NSDefaultRunLoopMode dequeue:YES]; |
287 NSPoint thisPoint = [NSEvent mouseLocation]; | |
288 | |
289 NSEventType type = [theEvent type]; | 287 NSEventType type = [theEvent type]; |
290 if (type == NSLeftMouseDragged) { | 288 if (type == NSLeftMouseDragged) { |
291 [self mouseDragged:theEvent]; | 289 [self mouseDragged:theEvent]; |
292 } else if (type == NSLeftMouseUp) { | 290 } else if (type == NSLeftMouseUp) { |
293 NSPoint upLocation = [theEvent locationInWindow]; | 291 NSPoint upLocation = [theEvent locationInWindow]; |
294 CGFloat dx = upLocation.x - downLocation.x; | 292 CGFloat dx = upLocation.x - downLocation.x; |
295 CGFloat dy = upLocation.y - downLocation.y; | 293 CGFloat dy = upLocation.y - downLocation.y; |
296 | 294 |
297 // During rapid tab closure (mashing tab close buttons), we may get hit | 295 // During rapid tab closure (mashing tab close buttons), we may get hit |
298 // with a mouse down. As long as the mouse up is over the close button, | 296 // with a mouse down. As long as the mouse up is over the close button, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 [sourceWindow_ setFrameOrigin:NSMakePoint(origin.x, origin.y)]; | 330 [sourceWindow_ setFrameOrigin:NSMakePoint(origin.x, origin.y)]; |
333 } // else do nothing. | 331 } // else do nothing. |
334 return; | 332 return; |
335 } | 333 } |
336 | 334 |
337 // First, go through the magnetic drag cycle. We break out of this if | 335 // First, go through the magnetic drag cycle. We break out of this if |
338 // "stretchiness" ever exceeds a set amount. | 336 // "stretchiness" ever exceeds a set amount. |
339 tabWasDragged_ = YES; | 337 tabWasDragged_ = YES; |
340 | 338 |
341 if (draggingWithinTabStrip_) { | 339 if (draggingWithinTabStrip_) { |
342 NSRect frame = [self frame]; | |
343 NSPoint thisPoint = [NSEvent mouseLocation]; | 340 NSPoint thisPoint = [NSEvent mouseLocation]; |
344 CGFloat stretchiness = thisPoint.y - dragOrigin_.y; | 341 CGFloat stretchiness = thisPoint.y - dragOrigin_.y; |
345 stretchiness = copysign(sqrtf(fabs(stretchiness))/sqrtf(kTearDistance), | 342 stretchiness = copysign(sqrtf(fabs(stretchiness))/sqrtf(kTearDistance), |
346 stretchiness) / 2.0; | 343 stretchiness) / 2.0; |
347 CGFloat offset = thisPoint.x - dragOrigin_.x; | 344 CGFloat offset = thisPoint.x - dragOrigin_.x; |
348 if (fabsf(offset) > 100) stretchiness = 0; | 345 if (fabsf(offset) > 100) stretchiness = 0; |
349 [sourceController_ insertPlaceholderForTab:self | 346 [sourceController_ insertPlaceholderForTab:self |
350 frame:NSOffsetRect(sourceTabFrame_, | 347 frame:NSOffsetRect(sourceTabFrame_, |
351 offset, 0) | 348 offset, 0) |
352 yStretchiness:stretchiness]; | 349 yStretchiness:stretchiness]; |
353 // Check that we haven't pulled the tab too far to start a drag. This | 350 // Check that we haven't pulled the tab too far to start a drag. This |
354 // can include either pulling it too far down, or off the side of the tab | 351 // can include either pulling it too far down, or off the side of the tab |
355 // strip that would cause it to no longer be fully visible. | 352 // strip that would cause it to no longer be fully visible. |
356 BOOL stillVisible = [sourceController_ isTabFullyVisible:self]; | 353 BOOL stillVisible = [sourceController_ isTabFullyVisible:self]; |
357 CGFloat tearForce = fabs(thisPoint.y - dragOrigin_.y); | 354 CGFloat tearForce = fabs(thisPoint.y - dragOrigin_.y); |
358 if ([sourceController_ tabTearingAllowed] && | 355 if ([sourceController_ tabTearingAllowed] && |
359 (tearForce > kTearDistance || !stillVisible)) { | 356 (tearForce > kTearDistance || !stillVisible)) { |
360 draggingWithinTabStrip_ = NO; | 357 draggingWithinTabStrip_ = NO; |
361 // When you finally leave the strip, we treat that as the origin. | 358 // When you finally leave the strip, we treat that as the origin. |
362 dragOrigin_.x = thisPoint.x; | 359 dragOrigin_.x = thisPoint.x; |
363 } else { | 360 } else { |
364 // Still dragging within the tab strip, wait for the next drag event. | 361 // Still dragging within the tab strip, wait for the next drag event. |
365 return; | 362 return; |
366 } | 363 } |
367 } | 364 } |
368 | 365 |
369 NSPoint lastPoint = | |
370 [[theEvent window] convertBaseToScreen:[theEvent locationInWindow]]; | |
371 | |
372 // Do not start dragging until the user has "torn" the tab off by | 366 // Do not start dragging until the user has "torn" the tab off by |
373 // moving more than 3 pixels. | 367 // moving more than 3 pixels. |
374 NSDate* targetDwellDate = nil; // The date this target was first chosen. | 368 NSDate* targetDwellDate = nil; // The date this target was first chosen. |
375 | 369 |
376 NSPoint thisPoint = [NSEvent mouseLocation]; | 370 NSPoint thisPoint = [NSEvent mouseLocation]; |
377 | 371 |
378 // Iterate over possible targets checking for the one the mouse is in. | 372 // Iterate over possible targets checking for the one the mouse is in. |
379 // If the tab is just in the frame, bring the window forward to make it | 373 // If the tab is just in the frame, bring the window forward to make it |
380 // easier to drop something there. If it's in the tab strip, set the new | 374 // easier to drop something there. If it's in the tab strip, set the new |
381 // target so that it pops into that window. We can't cache this because we | 375 // target so that it pops into that window. We can't cache this because we |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // a placeholder so it appears like it's part of that window. | 489 // a placeholder so it appears like it's part of that window. |
496 if (targetController_) { | 490 if (targetController_) { |
497 if (![[targetController_ window] isKeyWindow]) { | 491 if (![[targetController_ window] isKeyWindow]) { |
498 // && ([targetDwellDate timeIntervalSinceNow] < -REQUIRED_DWELL)) { | 492 // && ([targetDwellDate timeIntervalSinceNow] < -REQUIRED_DWELL)) { |
499 [[targetController_ window] orderFront:nil]; | 493 [[targetController_ window] orderFront:nil]; |
500 targetDwellDate = nil; | 494 targetDwellDate = nil; |
501 } | 495 } |
502 | 496 |
503 // Compute where placeholder should go and insert it into the | 497 // Compute where placeholder should go and insert it into the |
504 // destination tab strip. | 498 // destination tab strip. |
505 NSRect dropTabFrame = [[targetController_ tabStripView] frame]; | |
506 TabView* draggedTabView = (TabView*)[draggedController_ selectedTabView]; | 499 TabView* draggedTabView = (TabView*)[draggedController_ selectedTabView]; |
507 NSRect tabFrame = [draggedTabView frame]; | 500 NSRect tabFrame = [draggedTabView frame]; |
508 tabFrame.origin = [dragWindow_ convertBaseToScreen:tabFrame.origin]; | 501 tabFrame.origin = [dragWindow_ convertBaseToScreen:tabFrame.origin]; |
509 tabFrame.origin = [[targetController_ window] | 502 tabFrame.origin = [[targetController_ window] |
510 convertScreenToBase:tabFrame.origin]; | 503 convertScreenToBase:tabFrame.origin]; |
511 tabFrame = [[targetController_ tabStripView] | 504 tabFrame = [[targetController_ tabStripView] |
512 convertRect:tabFrame fromView:nil]; | 505 convertRect:tabFrame fromView:nil]; |
513 NSPoint point = | |
514 [sourceWindow_ convertBaseToScreen: | |
515 [draggedTabView convertPoint:NSZeroPoint toView:nil]]; | |
516 [targetController_ insertPlaceholderForTab:self | 506 [targetController_ insertPlaceholderForTab:self |
517 frame:tabFrame | 507 frame:tabFrame |
518 yStretchiness:0]; | 508 yStretchiness:0]; |
519 [targetController_ layoutTabs]; | 509 [targetController_ layoutTabs]; |
520 } else { | 510 } else { |
521 [dragWindow_ makeKeyAndOrderFront:nil]; | 511 [dragWindow_ makeKeyAndOrderFront:nil]; |
522 } | 512 } |
523 | 513 |
524 // Adjust the visibility of the window background. If there is a drop target, | 514 // Adjust the visibility of the window background. If there is a drop target, |
525 // we want to hide the window background so the tab stands out for | 515 // we want to hide the window background so the tab stands out for |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 } | 950 } |
961 | 951 |
962 if (nextUpdate < kNoUpdate) | 952 if (nextUpdate < kNoUpdate) |
963 [self performSelector:_cmd withObject:nil afterDelay:nextUpdate]; | 953 [self performSelector:_cmd withObject:nil afterDelay:nextUpdate]; |
964 | 954 |
965 [self resetLastGlowUpdateTime]; | 955 [self resetLastGlowUpdateTime]; |
966 [self setNeedsDisplay:YES]; | 956 [self setNeedsDisplay:YES]; |
967 } | 957 } |
968 | 958 |
969 @end // @implementation TabView(Private) | 959 @end // @implementation TabView(Private) |
OLD | NEW |