Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm

Issue 2324593002: [Mac] Fix for security indicator drag&drop navigation (Closed)
Patch Set: Cleaned up Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 BOOL flipped = [controlView isFlipped];
431 const NSPoint locationInView =
432 [controlView convertPoint:location fromView:nil];
433
434 // If we have decorations, the drop can't occur at their horizontal padding.
435 if (!leftDecorations_.empty()) {
436 NSRect leftPaddingFrame = cellFrame;
437 leftPaddingFrame.size.width = LeftDecorationXOffset();
438 if (NSMouseInRect(locationInView, leftPaddingFrame, flipped))
shrike 2016/09/16 18:28:41 You could also just say if (locationInView.x < Lef
spqchan 2016/09/20 21:00:00 Done.
439 return false;
440 }
441
442 if (!rightDecorations_.empty()) {
shrike 2016/09/16 18:28:41 Do you think we really need this check? Seems like
spqchan 2016/09/20 21:00:00 I think it's better to be consistent with the left
443 NSRect rightPaddingFrame = cellFrame;
444 rightPaddingFrame.origin.x = NSMaxX(cellFrame) - kRightDecorationXOffset;
445 rightPaddingFrame.size.width = kRightDecorationXOffset;
446 if (NSMouseInRect(locationInView, rightPaddingFrame, flipped))
447 return false;
448 }
449
450 LocationBarDecoration* decoration =
451 [self decorationForLocationInWindow:location
452 inRect:cellFrame
453 ofView:controlView];
454 return !decoration;
455 }
456
427 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent 457 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent
428 inRect:(NSRect)cellFrame 458 inRect:(NSRect)cellFrame
429 ofView:(AutocompleteTextField*)controlView 459 ofView:(AutocompleteTextField*)controlView
430 { 460 {
461 return [self decorationForLocationInWindow:[theEvent locationInWindow]
462 inRect:cellFrame
463 ofView:controlView];
464 }
465
466 - (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location
467 inRect:(NSRect)cellFrame
468 ofView:(AutocompleteTextField*)
469 controlView {
431 const BOOL flipped = [controlView isFlipped]; 470 const BOOL flipped = [controlView isFlipped];
432 const NSPoint location = 471 const NSPoint locationInView =
433 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; 472 [controlView convertPoint:location fromView:nil];
434 473
435 std::vector<LocationBarDecoration*> decorations; 474 std::vector<LocationBarDecoration*> decorations;
436 std::vector<NSRect> decorationFrames; 475 std::vector<NSRect> decorationFrames;
437 NSRect textFrame; 476 NSRect textFrame;
438 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 477 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_,
439 &decorations, &decorationFrames, &textFrame); 478 &decorations, &decorationFrames, &textFrame);
440 479
441 for (size_t i = 0; i < decorations.size(); ++i) { 480 for (size_t i = 0; i < decorations.size(); ++i) {
442 if (NSMouseInRect(location, decorationFrames[i], flipped)) 481 if (NSMouseInRect(locationInView, decorationFrames[i], flipped))
443 return decorations[i]; 482 return decorations[i];
444 } 483 }
445 484
446 return NULL; 485 return NULL;
447 } 486 }
448 487
449 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent 488 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent
450 inRect:(NSRect)cellFrame 489 inRect:(NSRect)cellFrame
451 ofView:(AutocompleteTextField*)controlView { 490 ofView:(AutocompleteTextField*)controlView {
452 LocationBarDecoration* decoration = 491 LocationBarDecoration* decoration =
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 784
746 - (void)handleFocusEvent:(NSEvent*)event 785 - (void)handleFocusEvent:(NSEvent*)event
747 ofView:(AutocompleteTextField*)controlView { 786 ofView:(AutocompleteTextField*)controlView {
748 if ([controlView observer]) { 787 if ([controlView observer]) {
749 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; 788 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0;
750 [controlView observer]->OnSetFocus(controlDown); 789 [controlView observer]->OnSetFocus(controlDown);
751 } 790 }
752 } 791 }
753 792
754 @end 793 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698