| 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/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "gfx/font.h" | 9 #include "gfx/font.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 const NSInteger kIconLabelYOffset = 7; | 47 const NSInteger kIconLabelYOffset = 7; |
| 48 | 48 |
| 49 // How far the editor insets itself, for purposes of determining if | 49 // How far the editor insets itself, for purposes of determining if |
| 50 // decorations need to be trimmed. | 50 // decorations need to be trimmed. |
| 51 const CGFloat kEditorHorizontalInset = 3.0; | 51 const CGFloat kEditorHorizontalInset = 3.0; |
| 52 | 52 |
| 53 // Cause the location icon to line up above the icons in the popup. | 53 // Cause the location icon to line up above the icons in the popup. |
| 54 const CGFloat kLocationIconXOffset = 9.0; | 54 const CGFloat kLocationIconXOffset = 9.0; |
| 55 const CGFloat kLocationIconXPad = 5.0; | 55 const CGFloat kLocationIconXPad = 5.0; |
| 56 | 56 |
| 57 // How long to wait for mouse-up on the location icon before assuming |
| 58 // that the user wants to drag. |
| 59 const NSTimeInterval kLocationIconDragTimeout = 0.25; |
| 60 |
| 57 // Conveniences to centralize width+offset calculations. | 61 // Conveniences to centralize width+offset calculations. |
| 58 CGFloat WidthForHint(NSAttributedString* hintString) { | 62 CGFloat WidthForHint(NSAttributedString* hintString) { |
| 59 return kHintXOffset + ceil([hintString size].width); | 63 return kHintXOffset + ceil([hintString size].width); |
| 60 } | 64 } |
| 61 CGFloat WidthForKeyword(NSAttributedString* keywordString) { | 65 CGFloat WidthForKeyword(NSAttributedString* keywordString) { |
| 62 return kKeywordXOffset + ceil([keywordString size].width) + | 66 return kKeywordXOffset + ceil([keywordString size].width) + |
| 63 2 * kKeywordTokenInset; | 67 2 * kKeywordTokenInset; |
| 64 } | 68 } |
| 65 | 69 |
| 66 // Convenience to draw |image| in the |rect| portion of |view|. | 70 // Convenience to draw |image| in the |rect| portion of |view|. |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 AutocompleteTextFieldIcon* | 585 AutocompleteTextFieldIcon* |
| 582 icon = [self iconForEvent:theEvent inRect:cellFrame ofView:controlView]; | 586 icon = [self iconForEvent:theEvent inRect:cellFrame ofView:controlView]; |
| 583 if (icon) | 587 if (icon) |
| 584 return [icon view]->GetMenu(); | 588 return [icon view]->GetMenu(); |
| 585 return nil; | 589 return nil; |
| 586 } | 590 } |
| 587 | 591 |
| 588 - (BOOL)mouseDown:(NSEvent*)theEvent | 592 - (BOOL)mouseDown:(NSEvent*)theEvent |
| 589 inRect:(NSRect)cellFrame | 593 inRect:(NSRect)cellFrame |
| 590 ofView:(AutocompleteTextField*)controlView { | 594 ofView:(AutocompleteTextField*)controlView { |
| 591 AutocompleteTextFieldIcon* | 595 AutocompleteTextFieldIcon* icon = |
| 592 icon = [self iconForEvent:theEvent inRect:cellFrame ofView:controlView]; | 596 [self iconForEvent:theEvent inRect:cellFrame ofView:controlView]; |
| 593 if (icon) { | 597 if (!icon) |
| 594 [icon view]->OnMousePressed([icon rect]); | 598 return NO; |
| 595 return YES; | 599 |
| 600 // If the icon is draggable, then initiate a drag if the user drags |
| 601 // or holds the mouse down for awhile. |
| 602 if ([icon view]->IsDraggable()) { |
| 603 NSDate* timeout = |
| 604 [NSDate dateWithTimeIntervalSinceNow:kLocationIconDragTimeout]; |
| 605 NSEvent* event = [NSApp nextEventMatchingMask:(NSLeftMouseDraggedMask | |
| 606 NSLeftMouseUpMask) |
| 607 untilDate:timeout |
| 608 inMode:NSEventTrackingRunLoopMode |
| 609 dequeue:YES]; |
| 610 if (!event || [event type] == NSLeftMouseDragged) { |
| 611 NSPasteboard* pboard = [icon view]->GetDragPasteboard(); |
| 612 DCHECK(pboard); |
| 613 |
| 614 // TODO(shess): My understanding is that the -isFlipped |
| 615 // adjustment should not be necessary. But without it, the |
| 616 // image is nowhere near the cursor. Perhaps the icon's rect is |
| 617 // incorrectly calculated? |
| 618 // http://crbug.com/40711 |
| 619 NSPoint dragPoint = [icon rect].origin; |
| 620 if ([controlView isFlipped]) |
| 621 dragPoint.y += NSHeight([icon rect]); |
| 622 |
| 623 [controlView dragImage:[icon view]->GetImage() |
| 624 at:dragPoint |
| 625 offset:NSZeroSize |
| 626 event:event ? event : theEvent |
| 627 pasteboard:pboard |
| 628 source:self |
| 629 slideBack:YES]; |
| 630 return YES; |
| 631 } |
| 632 |
| 633 // On mouse-up fall through to mouse-pressed case. |
| 634 DCHECK_EQ([event type], NSLeftMouseUp); |
| 596 } | 635 } |
| 597 | 636 |
| 598 return NO; | 637 [icon view]->OnMousePressed([icon rect]); |
| 638 return YES; |
| 639 } |
| 640 |
| 641 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { |
| 642 return NSDragOperationCopy; |
| 599 } | 643 } |
| 600 | 644 |
| 601 @end | 645 @end |
| OLD | NEW |