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

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

Issue 2560993002: [Mac] Fix omnibox text overlap (Closed)
Patch Set: Created 4 years 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 | « chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_editor.h" 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
6 6
7 #include "base/mac/sdk_forward_declarations.h" 7 #include "base/mac/sdk_forward_declarations.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" // IDC_* 10 #include "chrome/app/chrome_command_ids.h" // IDC_*
(...skipping 21 matching lines...) Expand all
32 // accidentally paste large amounts, so place a limit on what will be 32 // accidentally paste large amounts, so place a limit on what will be
33 // accepted. 33 // accepted.
34 // 34 //
35 // 10k characters was arbitrarily chosen by seeing how much a text 35 // 10k characters was arbitrarily chosen by seeing how much a text
36 // field could handle in a single line before it started getting too 36 // field could handle in a single line before it started getting too
37 // janky to recover from (jankiness was detectable around 5k). 37 // janky to recover from (jankiness was detectable around 5k).
38 // www.google.com returns an error for searches around 2k characters, 38 // www.google.com returns an error for searches around 2k characters,
39 // so this is conservative. 39 // so this is conservative.
40 const NSUInteger kMaxPasteLength = 10000; 40 const NSUInteger kMaxPasteLength = 10000;
41 41
42 // How much the text should be offset from its left.
43 const CGFloat kTextXOffset = -1.0;
44
42 // Returns |YES| if too much text would be pasted. 45 // Returns |YES| if too much text would be pasted.
43 BOOL ThePasteboardIsTooDamnBig() { 46 BOOL ThePasteboardIsTooDamnBig() {
44 NSPasteboard* pb = [NSPasteboard generalPasteboard]; 47 NSPasteboard* pb = [NSPasteboard generalPasteboard];
45 NSString* type = 48 NSString* type =
46 [pb availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]]; 49 [pb availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]];
47 if (!type) 50 if (!type)
48 return NO; 51 return NO;
49 52
50 return [[pb stringForType:type] length] > kMaxPasteLength; 53 return [[pb stringForType:type] length] > kMaxPasteLength;
51 } 54 }
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 NSAttributedString* selection = 595 NSAttributedString* selection =
593 [self attributedSubstringForProposedRange:selectedRange 596 [self attributedSubstringForProposedRange:selectedRange
594 actualRange:NULL]; 597 actualRange:NULL];
595 if (!selection) 598 if (!selection)
596 return; 599 return;
597 600
598 [[FindPasteboard sharedInstance] setFindText:[selection string]]; 601 [[FindPasteboard sharedInstance] setFindText:[selection string]];
599 } 602 }
600 603
601 - (void)drawRect:(NSRect)rect { 604 - (void)drawRect:(NSRect)rect {
605 gfx::ScopedNSGraphicsContextSaveGState saveGraphicsState;
602 AutocompleteTextFieldObserver* observer = [self observer]; 606 AutocompleteTextFieldObserver* observer = [self observer];
603 if (observer) 607 if (observer)
604 observer->OnBeforeDrawRect(); 608 observer->OnBeforeDrawRect();
609
610 NSAffineTransform* transform = [NSAffineTransform transform];
611 [transform translateXBy:kTextXOffset yBy:0];
612 [transform concat];
613
605 [super drawRect:rect]; 614 [super drawRect:rect];
606 if (observer) 615 if (observer)
607 observer->OnDidDrawRect(); 616 observer->OnDidDrawRect();
608 } 617 }
609 618
610 // ThemedWindowDrawing implementation. 619 // ThemedWindowDrawing implementation.
611 620
612 - (void)windowDidChangeTheme { 621 - (void)windowDidChangeTheme {
613 [self updateColorsToMatchTheme]; 622 [self updateColorsToMatchTheme];
614 } 623 }
615 624
616 - (void)windowDidChangeActive { 625 - (void)windowDidChangeActive {
617 } 626 }
618 627
619 @end 628 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698