| 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/location_bar/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/cocoa/image_utils.h" | 8 #import "chrome/browser/cocoa/image_utils.h" |
| 9 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" | 9 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" |
| 10 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h" | 10 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 [NSDate dateWithTimeIntervalSinceNow:kLocationIconDragTimeout]; | 324 [NSDate dateWithTimeIntervalSinceNow:kLocationIconDragTimeout]; |
| 325 NSEvent* event = [NSApp nextEventMatchingMask:(NSLeftMouseDraggedMask | | 325 NSEvent* event = [NSApp nextEventMatchingMask:(NSLeftMouseDraggedMask | |
| 326 NSLeftMouseUpMask) | 326 NSLeftMouseUpMask) |
| 327 untilDate:timeout | 327 untilDate:timeout |
| 328 inMode:NSEventTrackingRunLoopMode | 328 inMode:NSEventTrackingRunLoopMode |
| 329 dequeue:YES]; | 329 dequeue:YES]; |
| 330 if (!event || [event type] == NSLeftMouseDragged) { | 330 if (!event || [event type] == NSLeftMouseDragged) { |
| 331 NSPasteboard* pboard = decoration->GetDragPasteboard(); | 331 NSPasteboard* pboard = decoration->GetDragPasteboard(); |
| 332 DCHECK(pboard); | 332 DCHECK(pboard); |
| 333 | 333 |
| 334 // TODO(shess): My understanding is that the -isFlipped | |
| 335 // adjustment should not be necessary. But without it, the | |
| 336 // image is nowhere near the cursor. Perhaps the decorations's | |
| 337 // rect is incorrectly calculated? | |
| 338 // http://crbug.com/40711 | |
| 339 NSPoint dragPoint = decorationRect.origin; | |
| 340 if ([controlView isFlipped]) | |
| 341 dragPoint.y += NSHeight(decorationRect); | |
| 342 | |
| 343 NSImage* image = decoration->GetDragImage(); | 334 NSImage* image = decoration->GetDragImage(); |
| 344 DCHECK(image); | 335 DCHECK(image); |
| 345 [controlView dragImage:image | 336 |
| 346 at:dragPoint | 337 NSRect dragImageRect = decoration->GetDragImageFrame(decorationRect); |
| 347 offset:NSZeroSize | 338 |
| 348 event:event ? event : theEvent | 339 // If the original click is not within |dragImageRect|, then |
| 349 pasteboard:pboard | 340 // center the image under the mouse. Otherwise, will drag from |
| 350 source:self | 341 // where the click was on the image. |
| 351 slideBack:YES]; | 342 const NSPoint mousePoint = |
| 343 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 344 if (!NSMouseInRect(mousePoint, dragImageRect, [controlView isFlipped])) { |
| 345 dragImageRect.origin = |
| 346 NSMakePoint(mousePoint.x - NSWidth(dragImageRect) / 2.0, |
| 347 mousePoint.y - NSHeight(dragImageRect) / 2.0); |
| 348 } |
| 349 |
| 350 // -[NSView dragImage:at:*] wants the images lower-left point, |
| 351 // regardless of -isFlipped. Converting the rect to window base |
| 352 // coordinates doesn't require any special-casing. Note that |
| 353 // -[NSView dragFile:fromRect:*] takes a rect rather than a |
| 354 // point, likely for this exact reason. |
| 355 const NSPoint dragPoint = |
| 356 [controlView convertRect:dragImageRect toView:nil].origin; |
| 357 [[controlView window] dragImage:image |
| 358 at:dragPoint |
| 359 offset:NSZeroSize |
| 360 event:theEvent |
| 361 pasteboard:pboard |
| 362 source:self |
| 363 slideBack:YES]; |
| 364 |
| 352 return YES; | 365 return YES; |
| 353 } | 366 } |
| 354 | 367 |
| 355 // On mouse-up fall through to mouse-pressed case. | 368 // On mouse-up fall through to mouse-pressed case. |
| 356 DCHECK_EQ([event type], NSLeftMouseUp); | 369 DCHECK_EQ([event type], NSLeftMouseUp); |
| 357 } | 370 } |
| 358 | 371 |
| 359 if (!decoration->OnMousePressed(decorationRect)) | 372 if (!decoration->OnMousePressed(decorationRect)) |
| 360 return NO; | 373 return NO; |
| 361 | 374 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 375 &decorations, &decorationFrames, &textFrame); | 388 &decorations, &decorationFrames, &textFrame); |
| 376 | 389 |
| 377 for (size_t i = 0; i < decorations.size(); ++i) { | 390 for (size_t i = 0; i < decorations.size(); ++i) { |
| 378 NSString* tooltip = decorations[i]->GetToolTip(); | 391 NSString* tooltip = decorations[i]->GetToolTip(); |
| 379 if ([tooltip length] > 0) | 392 if ([tooltip length] > 0) |
| 380 [controlView addToolTip:tooltip forRect:decorationFrames[i]]; | 393 [controlView addToolTip:tooltip forRect:decorationFrames[i]]; |
| 381 } | 394 } |
| 382 } | 395 } |
| 383 | 396 |
| 384 @end | 397 @end |
| OLD | NEW |