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

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: review2 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
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]);
290 suggestColor_.reset([suggestColor retain]);
291 }
292
293 - (NSString*)suggestText {
294 return suggestText_;
295 }
296
297 - (NSColor*)suggestColor {
298 return suggestColor_;
299 }
300
301 - (NSPoint)bubblePointForDecoration:(LocationBarDecoration*)decoration { 286 - (NSPoint)bubblePointForDecoration:(LocationBarDecoration*)decoration {
302 const NSRect frame = 287 const NSRect frame =
303 [[self cell] frameForDecoration:decoration inFrame:[self bounds]]; 288 [[self cell] frameForDecoration:decoration inFrame:[self bounds]];
304 const NSPoint point = decoration->GetBubblePointInFrame(frame); 289 const NSPoint point = decoration->GetBubblePointInFrame(frame);
305 return [self convertPoint:point toView:nil]; 290 return [self convertPoint:point toView:nil];
306 } 291 }
307 292
308 // TODO(shess): -resetFieldEditorFrameIfNeeded is the place where 293 // TODO(shess): -resetFieldEditorFrameIfNeeded is the place where
309 // changes to the cell layout should be flushed. LocationBarViewMac 294 // changes to the cell layout should be flushed. LocationBarViewMac
310 // and ToolbarController are calling this routine directly, and I 295 // and ToolbarController are calling this routine directly, and I
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 - (BOOL)resignFirstResponder { 471 - (BOOL)resignFirstResponder {
487 BOOL doResign = [super resignFirstResponder]; 472 BOOL doResign = [super resignFirstResponder];
488 if (doResign) { 473 if (doResign) {
489 [[BrowserWindowController browserWindowControllerForView:self] 474 [[BrowserWindowController browserWindowControllerForView:self]
490 releaseToolbarVisibilityForOwner:self 475 releaseToolbarVisibilityForOwner:self
491 withAnimation:YES]; 476 withAnimation:YES];
492 } 477 }
493 return doResign; 478 return doResign;
494 } 479 }
495 480
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) 481 // (URLDropTarget protocol)
507 - (id<URLDropTargetController>)urlDropController { 482 - (id<URLDropTargetController>)urlDropController {
508 BrowserWindowController* windowController = 483 BrowserWindowController* windowController =
509 [BrowserWindowController browserWindowControllerForView:self]; 484 [BrowserWindowController browserWindowControllerForView:self];
510 return [windowController toolbarController]; 485 return [windowController toolbarController];
511 } 486 }
512 487
513 // (URLDropTarget protocol) 488 // (URLDropTarget protocol)
514 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { 489 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
515 // Make ourself the first responder, which will select the text to indicate 490 // 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. 531 // ThemedWindowDrawing implementation.
557 532
558 - (void)windowDidChangeTheme { 533 - (void)windowDidChangeTheme {
559 [self updateColorsToMatchTheme]; 534 [self updateColorsToMatchTheme];
560 } 535 }
561 536
562 - (void)windowDidChangeActive { 537 - (void)windowDidChangeActive {
563 } 538 }
564 539
565 @end 540 @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