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

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

Issue 2510373003: Cleanup: Remove "gray text" logic from Omnibox (Closed)
Patch Set: mac Created 4 years, 1 month 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) 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.h" 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #import "base/mac/sdk_forward_declarations.h" 9 #import "base/mac/sdk_forward_declarations.h"
10 #include "chrome/browser/themes/theme_service.h" 10 #include "chrome/browser/themes/theme_service.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (observer_) 276 if (observer_)
277 return observer_->SelectionRangeForProposedRange(newRange); 277 return observer_->SelectionRangeForProposedRange(newRange);
278 return newRange; 278 return newRange;
279 } 279 }
280 280
281 - (void)addToolTip:(NSString*)tooltip forRect:(NSRect)aRect { 281 - (void)addToolTip:(NSString*)tooltip forRect:(NSRect)aRect {
282 [currentToolTips_ addObject:tooltip]; 282 [currentToolTips_ addObject:tooltip];
283 [self addToolTipRect:aRect owner:tooltip userData:nil]; 283 [self addToolTipRect:aRect owner:tooltip userData:nil];
284 } 284 }
285 285
286 - (void)setGrayTextAutocompletion:(NSString*)suggestText
287 textColor:(NSColor*)suggestColor {
288 [self setNeedsDisplay:YES];
289 suggestText_.reset([suggestText retain]);
Peter Kasting 2016/11/21 21:11:43 I would assume suggestText_ and suggestColor_, and
Marc Treib 2016/11/22 10:35:30 Done.
290 suggestColor_.reset([suggestColor retain]);
291 }
292
293 - (NSString*)suggestText { 286 - (NSString*)suggestText {
294 return suggestText_; 287 return suggestText_;
295 } 288 }
296 289
297 - (NSColor*)suggestColor { 290 - (NSColor*)suggestColor {
298 return suggestColor_; 291 return suggestColor_;
299 } 292 }
300 293
301 - (NSPoint)bubblePointForDecoration:(LocationBarDecoration*)decoration { 294 - (NSPoint)bubblePointForDecoration:(LocationBarDecoration*)decoration {
302 const NSRect frame = 295 const NSRect frame =
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 - (BOOL)resignFirstResponder { 479 - (BOOL)resignFirstResponder {
487 BOOL doResign = [super resignFirstResponder]; 480 BOOL doResign = [super resignFirstResponder];
488 if (doResign) { 481 if (doResign) {
489 [[BrowserWindowController browserWindowControllerForView:self] 482 [[BrowserWindowController browserWindowControllerForView:self]
490 releaseToolbarVisibilityForOwner:self 483 releaseToolbarVisibilityForOwner:self
491 withAnimation:YES]; 484 withAnimation:YES];
492 } 485 }
493 return doResign; 486 return doResign;
494 } 487 }
495 488
496 - (void)drawRect:(NSRect)rect {
497 [super drawRect:rect];
498 autocomplete_text_field::DrawGrayTextAutocompletion(
499 [self attributedStringValue],
500 suggestText_,
501 suggestColor_,
502 self,
503 [[self cell] drawingRectForBounds:[self bounds]]);
504 }
505
506 // (URLDropTarget protocol) 489 // (URLDropTarget protocol)
507 - (id<URLDropTargetController>)urlDropController { 490 - (id<URLDropTargetController>)urlDropController {
508 BrowserWindowController* windowController = 491 BrowserWindowController* windowController =
509 [BrowserWindowController browserWindowControllerForView:self]; 492 [BrowserWindowController browserWindowControllerForView:self];
510 return [windowController toolbarController]; 493 return [windowController toolbarController];
511 } 494 }
512 495
513 // (URLDropTarget protocol) 496 // (URLDropTarget protocol)
514 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { 497 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
515 // Make ourself the first responder, which will select the text to indicate 498 // Make ourself the first responder, which will select the text to indicate
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // ThemedWindowDrawing implementation. 539 // ThemedWindowDrawing implementation.
557 540
558 - (void)windowDidChangeTheme { 541 - (void)windowDidChangeTheme {
559 [self updateColorsToMatchTheme]; 542 [self updateColorsToMatchTheme];
560 } 543 }
561 544
562 - (void)windowDidChangeActive { 545 - (void)windowDidChangeActive {
563 } 546 }
564 547
565 @end 548 @end
566
567 namespace autocomplete_text_field {
568
569 void DrawGrayTextAutocompletion(NSAttributedString* mainText,
570 NSString* suggestText,
571 NSColor* suggestColor,
572 NSView* controlView,
573 NSRect frame) {
574 if (![suggestText length])
575 return;
576
577 base::scoped_nsobject<NSTextFieldCell> cell(
578 [[NSTextFieldCell alloc] initTextCell:@""]);
579 [cell setBordered:NO];
580 [cell setDrawsBackground:NO];
581 [cell setEditable:NO];
582
583 base::scoped_nsobject<NSMutableAttributedString> combinedText(
584 [[NSMutableAttributedString alloc] initWithAttributedString:mainText]);
585 NSRange range = NSMakeRange([combinedText length], 0);
586 [combinedText replaceCharactersInRange:range withString:suggestText];
587 [combinedText addAttribute:NSForegroundColorAttributeName
588 value:suggestColor
589 range:NSMakeRange(range.location, [suggestText length])];
590 [cell setAttributedStringValue:combinedText];
591
592 CGFloat mainTextWidth = [mainText size].width;
593 CGFloat suggestWidth = NSWidth(frame) - mainTextWidth;
594 NSRect suggestRect = NSMakeRect(NSMinX(frame) + mainTextWidth,
595 NSMinY(frame),
596 suggestWidth,
597 NSHeight(frame));
598
599 gfx::ScopedNSGraphicsContextSaveGState saveGState;
600 NSRectClip(suggestRect);
601 [cell drawInteriorWithFrame:frame inView:controlView];
602 }
603
604 } // namespace autocomplete_text_field
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698