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

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

Issue 2389343002: [Mac] Updating AutocompleteTextFieldCell to 10.8 (Closed)
Patch Set: Comment nit Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 DCHECK_EQ([event type], NSLeftMouseUp); 511 DCHECK_EQ([event type], NSLeftMouseUp);
512 } 512 }
513 513
514 const NSPoint mouseLocation = [theEvent locationInWindow]; 514 const NSPoint mouseLocation = [theEvent locationInWindow];
515 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil]; 515 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil];
516 return decoration->OnMousePressed( 516 return decoration->OnMousePressed(
517 decorationRect, NSMakePoint(point.x - decorationRect.origin.x, 517 decorationRect, NSMakePoint(point.x - decorationRect.origin.x,
518 point.y - decorationRect.origin.y)); 518 point.y - decorationRect.origin.y));
519 } 519 }
520 520
521 // Given a newly created .webloc plist url file, also give it a resource
522 // fork and insert 'TEXT and 'url ' resources holding further copies of the
523 // url data. This is required for apps such as Terminal and Safari to accept it
524 // as a real webloc file when dragged in.
525 // It's expected that the resource fork requirement will go away at some
526 // point and this code can then be deleted.
527 OSErr WriteURLToNewWebLocFileResourceFork(NSURL* file, NSString* urlStr) {
528 ResFileRefNum refNum = kResFileNotOpened;
529 ResFileRefNum prevResRef = CurResFile();
530 FSRef fsRef;
531 OSErr err = noErr;
532 HFSUniStr255 resourceForkName;
533 FSGetResourceForkName(&resourceForkName);
534
535 if (![[NSFileManager defaultManager] fileExistsAtPath:[file path]])
536 return fnfErr;
537
538 if (!CFURLGetFSRef((CFURLRef)file, &fsRef))
539 return fnfErr;
540
541 err = FSCreateResourceFork(&fsRef,
542 resourceForkName.length,
543 resourceForkName.unicode,
544 0);
545 if (err)
546 return err;
547 err = FSOpenResourceFile(&fsRef,
548 resourceForkName.length,
549 resourceForkName.unicode,
550 fsRdWrPerm, &refNum);
551 if (err)
552 return err;
553
554 const char* utf8URL = [urlStr UTF8String];
555 int urlChars = strlen(utf8URL);
556
557 Handle urlHandle = NewHandle(urlChars);
558 memcpy(*urlHandle, utf8URL, urlChars);
559
560 Handle textHandle = NewHandle(urlChars);
561 memcpy(*textHandle, utf8URL, urlChars);
562
563 // Data for the 'drag' resource.
564 // This comes from derezzing webloc files made by the Finder.
565 // It's bigendian data, so it's represented here as chars to preserve
566 // byte order.
567 char dragData[] = {
568 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // Header.
569 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
570 0x54, 0x45, 0x58, 0x54, 0x00, 0x00, 0x01, 0x00, // 'TEXT', 0, 256
571 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
572 0x75, 0x72, 0x6C, 0x20, 0x00, 0x00, 0x01, 0x00, // 'url ', 0, 256
573 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
574 };
575 Handle dragHandle = NewHandleClear(sizeof(dragData));
576 memcpy(*dragHandle, &dragData[0], sizeof(dragData));
577
578 // Save the resources to the file.
579 ConstStr255Param noName = {0};
580 AddResource(dragHandle, 'drag', 128, noName);
581 AddResource(textHandle, 'TEXT', 256, noName);
582 AddResource(urlHandle, 'url ', 256, noName);
583
584 CloseResFile(refNum);
585 UseResFile(prevResRef);
586 return noErr;
587 }
588
589 // Returns the file path for file |name| if saved at NSURL |base|. 521 // Returns the file path for file |name| if saved at NSURL |base|.
590 static NSString* PathWithBaseURLAndName(NSURL* base, NSString* name) { 522 static NSString* PathWithBaseURLAndName(NSURL* base, NSString* name) {
591 NSString* filteredName = 523 NSString* filteredName =
592 [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 524 [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
593 return [[NSURL URLWithString:filteredName relativeToURL:base] path]; 525 return [[NSURL URLWithString:filteredName relativeToURL:base] path];
594 } 526 }
595 527
596 // Returns if there is already a file |name| at dir NSURL |base|. 528 // Returns if there is already a file |name| at dir NSURL |base|.
597 static BOOL FileAlreadyExists(NSURL* base, NSString* name) { 529 static BOOL FileAlreadyExists(NSURL* base, NSString* name) {
598 NSString* path = PathWithBaseURLAndName(base, name); 530 NSString* path = PathWithBaseURLAndName(base, name);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 return NULL; 609 return NULL;
678 610
679 NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys: 611 NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
680 [NSNumber numberWithBool:YES], NSFileExtensionHidden, 612 [NSNumber numberWithBool:YES], NSFileExtensionHidden,
681 [NSNumber numberWithUnsignedLong:'ilht'], NSFileHFSTypeCode, 613 [NSNumber numberWithUnsignedLong:'ilht'], NSFileHFSTypeCode,
682 [NSNumber numberWithUnsignedLong:'MACS'], NSFileHFSCreatorCode, 614 [NSNumber numberWithUnsignedLong:'MACS'], NSFileHFSCreatorCode,
683 nil]; 615 nil];
684 [fileManager setAttributes:attr 616 [fileManager setAttributes:attr
685 ofItemAtPath:[outputURL path] 617 ofItemAtPath:[outputURL path]
686 error:nil]; 618 error:nil];
687 // Add resource data. 619
688 OSErr resStatus = WriteURLToNewWebLocFileResourceFork(outputURL, urlStr); 620 // Write the URL to the .webloc plist url file.
Robert Sesek 2016/10/05 17:32:03 Isn't this being done on line 605 already?
spqchan 2016/10/06 23:41:20 Wow, I can't believe I missed that. Looks like the
689 OSSTATUS_DCHECK(resStatus == noErr, resStatus); 621 NSMutableDictionary* plist =
622 [NSMutableDictionary dictionaryWithContentsOfFile:urlStr];
623 [plist setObject:outputURL forKey:@"URL"];
624 [plist writeToFile:urlStr atomically:YES];
690 625
691 return [NSArray arrayWithObject:nameWithExtensionStr]; 626 return [NSArray arrayWithObject:nameWithExtensionStr];
692 } 627 }
693 628
694 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { 629 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
695 return NSDragOperationCopy; 630 return NSDragOperationCopy;
696 } 631 }
697 632
698 - (void)updateToolTipsInRect:(NSRect)cellFrame 633 - (void)updateToolTipsInRect:(NSRect)cellFrame
699 ofView:(AutocompleteTextField*)controlView { 634 ofView:(AutocompleteTextField*)controlView {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 666
732 - (void)handleFocusEvent:(NSEvent*)event 667 - (void)handleFocusEvent:(NSEvent*)event
733 ofView:(AutocompleteTextField*)controlView { 668 ofView:(AutocompleteTextField*)controlView {
734 if ([controlView observer]) { 669 if ([controlView observer]) {
735 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; 670 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0;
736 [controlView observer]->OnSetFocus(controlDown); 671 [controlView observer]->OnSetFocus(controlDown);
737 } 672 }
738 } 673 }
739 674
740 @end 675 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698