OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/location_bar/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 417 } |
418 | 418 |
419 // NOTE: This function must closely match the logic in | 419 // NOTE: This function must closely match the logic in |
420 // |-textFrameForFrame:|. | 420 // |-textFrameForFrame:|. |
421 | 421 |
422 // Superclass draws text portion WRT original |cellFrame|. | 422 // Superclass draws text portion WRT original |cellFrame|. |
423 ui::ScopedCGContextSmoothFonts fontSmoothing; | 423 ui::ScopedCGContextSmoothFonts fontSmoothing; |
424 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 424 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
425 } | 425 } |
426 | 426 |
| 427 - (BOOL)canDropAtLocationInWindow:(NSPoint)location |
| 428 ofView:(AutocompleteTextField*)controlView { |
| 429 NSRect cellFrame = [controlView bounds]; |
| 430 const NSPoint locationInView = |
| 431 [controlView convertPoint:location fromView:nil]; |
| 432 |
| 433 // If we have decorations, the drop can't occur at their horizontal padding. |
| 434 if (!leftDecorations_.empty() && locationInView.x < LeftDecorationXOffset()) |
| 435 return false; |
| 436 |
| 437 if (!rightDecorations_.empty() && |
| 438 locationInView.x > NSWidth(cellFrame) - kRightDecorationXOffset) { |
| 439 return false; |
| 440 } |
| 441 |
| 442 LocationBarDecoration* decoration = |
| 443 [self decorationForLocationInWindow:location |
| 444 inRect:cellFrame |
| 445 ofView:controlView]; |
| 446 return !decoration; |
| 447 } |
| 448 |
427 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent | 449 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
428 inRect:(NSRect)cellFrame | 450 inRect:(NSRect)cellFrame |
429 ofView:(AutocompleteTextField*)controlView | 451 ofView:(AutocompleteTextField*)controlView |
430 { | 452 { |
| 453 return [self decorationForLocationInWindow:[theEvent locationInWindow] |
| 454 inRect:cellFrame |
| 455 ofView:controlView]; |
| 456 } |
| 457 |
| 458 - (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location |
| 459 inRect:(NSRect)cellFrame |
| 460 ofView:(AutocompleteTextField*) |
| 461 controlView { |
431 const BOOL flipped = [controlView isFlipped]; | 462 const BOOL flipped = [controlView isFlipped]; |
432 const NSPoint location = | 463 const NSPoint locationInView = |
433 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; | 464 [controlView convertPoint:location fromView:nil]; |
434 | 465 |
435 std::vector<LocationBarDecoration*> decorations; | 466 std::vector<LocationBarDecoration*> decorations; |
436 std::vector<NSRect> decorationFrames; | 467 std::vector<NSRect> decorationFrames; |
437 NSRect textFrame; | 468 NSRect textFrame; |
438 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 469 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, |
439 &decorations, &decorationFrames, &textFrame); | 470 &decorations, &decorationFrames, &textFrame); |
440 | 471 |
441 for (size_t i = 0; i < decorations.size(); ++i) { | 472 for (size_t i = 0; i < decorations.size(); ++i) { |
442 if (NSMouseInRect(location, decorationFrames[i], flipped)) | 473 if (NSMouseInRect(locationInView, decorationFrames[i], flipped)) |
443 return decorations[i]; | 474 return decorations[i]; |
444 } | 475 } |
445 | 476 |
446 return NULL; | 477 return NULL; |
447 } | 478 } |
448 | 479 |
449 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent | 480 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent |
450 inRect:(NSRect)cellFrame | 481 inRect:(NSRect)cellFrame |
451 ofView:(AutocompleteTextField*)controlView { | 482 ofView:(AutocompleteTextField*)controlView { |
452 LocationBarDecoration* decoration = | 483 LocationBarDecoration* decoration = |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 776 |
746 - (void)handleFocusEvent:(NSEvent*)event | 777 - (void)handleFocusEvent:(NSEvent*)event |
747 ofView:(AutocompleteTextField*)controlView { | 778 ofView:(AutocompleteTextField*)controlView { |
748 if ([controlView observer]) { | 779 if ([controlView observer]) { |
749 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; | 780 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; |
750 [controlView observer]->OnSetFocus(controlDown); | 781 [controlView observer]->OnSetFocus(controlDown); |
751 } | 782 } |
752 } | 783 } |
753 | 784 |
754 @end | 785 @end |
OLD | NEW |