OLD | NEW |
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 "chrome/browser/ui/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 namespace autocomplete_text_field { | 442 namespace autocomplete_text_field { |
443 | 443 |
444 void DrawInstantSuggestion(NSAttributedString* mainText, | 444 void DrawInstantSuggestion(NSAttributedString* mainText, |
445 NSString* suggestText, | 445 NSString* suggestText, |
446 NSColor* suggestColor, | 446 NSColor* suggestColor, |
447 NSView* controlView, | 447 NSView* controlView, |
448 NSRect frame) { | 448 NSRect frame) { |
449 if (![suggestText length]) | 449 if (![suggestText length]) |
450 return; | 450 return; |
451 | 451 |
452 scoped_nsobject<NSTextFieldCell> cell( | 452 base::scoped_nsobject<NSTextFieldCell> cell( |
453 [[NSTextFieldCell alloc] initTextCell:@""]); | 453 [[NSTextFieldCell alloc] initTextCell:@""]); |
454 [cell setBordered:NO]; | 454 [cell setBordered:NO]; |
455 [cell setDrawsBackground:NO]; | 455 [cell setDrawsBackground:NO]; |
456 [cell setEditable:NO]; | 456 [cell setEditable:NO]; |
457 | 457 |
458 scoped_nsobject<NSMutableAttributedString> combinedText( | 458 base::scoped_nsobject<NSMutableAttributedString> combinedText( |
459 [[NSMutableAttributedString alloc] initWithAttributedString:mainText]); | 459 [[NSMutableAttributedString alloc] initWithAttributedString:mainText]); |
460 NSRange range = NSMakeRange([combinedText length], 0); | 460 NSRange range = NSMakeRange([combinedText length], 0); |
461 [combinedText replaceCharactersInRange:range withString:suggestText]; | 461 [combinedText replaceCharactersInRange:range withString:suggestText]; |
462 [combinedText addAttribute:NSForegroundColorAttributeName | 462 [combinedText addAttribute:NSForegroundColorAttributeName |
463 value:suggestColor | 463 value:suggestColor |
464 range:NSMakeRange(range.location, [suggestText length])]; | 464 range:NSMakeRange(range.location, [suggestText length])]; |
465 [cell setAttributedStringValue:combinedText]; | 465 [cell setAttributedStringValue:combinedText]; |
466 | 466 |
467 CGFloat mainTextWidth = [mainText size].width; | 467 CGFloat mainTextWidth = [mainText size].width; |
468 CGFloat suggestWidth = NSWidth(frame) - mainTextWidth; | 468 CGFloat suggestWidth = NSWidth(frame) - mainTextWidth; |
469 NSRect suggestRect = NSMakeRect(NSMinX(frame) + mainTextWidth, | 469 NSRect suggestRect = NSMakeRect(NSMinX(frame) + mainTextWidth, |
470 NSMinY(frame), | 470 NSMinY(frame), |
471 suggestWidth, | 471 suggestWidth, |
472 NSHeight(frame)); | 472 NSHeight(frame)); |
473 | 473 |
474 gfx::ScopedNSGraphicsContextSaveGState saveGState; | 474 gfx::ScopedNSGraphicsContextSaveGState saveGState; |
475 NSRectClip(suggestRect); | 475 NSRectClip(suggestRect); |
476 [cell drawInteriorWithFrame:frame inView:controlView]; | 476 [cell drawInteriorWithFrame:frame inView:controlView]; |
477 } | 477 } |
478 | 478 |
479 } // namespace autocomplete_text_field | 479 } // namespace autocomplete_text_field |
OLD | NEW |