| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "app/text_elider.h" | 8 #include "app/text_elider.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 10 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // buttons. | 30 // buttons. |
| 31 const CGFloat kPopupRoundingRadius = 3.5; | 31 const CGFloat kPopupRoundingRadius = 3.5; |
| 32 | 32 |
| 33 // Gap between the field and the popup. | 33 // Gap between the field and the popup. |
| 34 const CGFloat kPopupFieldGap = 2.0; | 34 const CGFloat kPopupFieldGap = 2.0; |
| 35 | 35 |
| 36 // How opaque the popup window should be. This matches Windows (see | 36 // How opaque the popup window should be. This matches Windows (see |
| 37 // autocomplete_popup_contents_view.cc, kGlassPopupTransparency). | 37 // autocomplete_popup_contents_view.cc, kGlassPopupTransparency). |
| 38 const CGFloat kPopupAlpha = 240.0 / 255.0; | 38 const CGFloat kPopupAlpha = 240.0 / 255.0; |
| 39 | 39 |
| 40 // How much space to leave for the left and right margins. | 40 // How far to offset image column from the left. |
| 41 const CGFloat kLeftRightMargin = 5.0; | 41 const CGFloat kImageXOffset = 2.0; |
| 42 | 42 |
| 43 // How far to offset the text column from the left. | 43 // How far to offset the text column from the left. |
| 44 const CGFloat kTextXOffset = 29.0; | 44 const CGFloat kTextXOffset = 25.0; |
| 45 | 45 |
| 46 // Animation duration when animating the popup window smaller. | 46 // Animation duration when animating the popup window smaller. |
| 47 const NSTimeInterval kShrinkAnimationDuration = 0.1; | 47 const NSTimeInterval kShrinkAnimationDuration = 0.1; |
| 48 | 48 |
| 49 // A very short animation duration used to cancel running animations. | 49 // A very short animation duration used to cancel running animations. |
| 50 const NSTimeInterval kCancelAnimationDuration = 0.00001; | 50 const NSTimeInterval kCancelAnimationDuration = 0.00001; |
| 51 | 51 |
| 52 // Maximum fraction of the popup width that can be used to display match | 52 // Maximum fraction of the popup width that can be used to display match |
| 53 // contents. | 53 // contents. |
| 54 const float kMaxContentsFraction = 0.7; | 54 const float kMaxContentsFraction = 0.7; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 ContentTextColor(), font); | 188 ContentTextColor(), font); |
| 189 | 189 |
| 190 // If there is a description, append it, separated from the contents | 190 // If there is a description, append it, separated from the contents |
| 191 // with an en dash, and decorated with a distinct color. | 191 // with an en dash, and decorated with a distinct color. |
| 192 if (!match.description.empty()) { | 192 if (!match.description.empty()) { |
| 193 // Make sure the current string fits w/in kMaxContentsFraction of | 193 // Make sure the current string fits w/in kMaxContentsFraction of |
| 194 // the cell to make sure the description will be at least | 194 // the cell to make sure the description will be at least |
| 195 // partially visible. | 195 // partially visible. |
| 196 // TODO(shess): Consider revising our NSCell subclass to have two | 196 // TODO(shess): Consider revising our NSCell subclass to have two |
| 197 // bits and just draw them right, rather than truncating here. | 197 // bits and just draw them right, rather than truncating here. |
| 198 const float textWidth = cellWidth - kTextXOffset - kLeftRightMargin; | 198 const float textWidth = cellWidth - kTextXOffset; |
| 199 as = ElideString(as, match.contents, font, | 199 as = ElideString(as, match.contents, font, |
| 200 textWidth * kMaxContentsFraction); | 200 textWidth * kMaxContentsFraction); |
| 201 | 201 |
| 202 NSDictionary* attributes = | 202 NSDictionary* attributes = |
| 203 [NSDictionary dictionaryWithObjectsAndKeys: | 203 [NSDictionary dictionaryWithObjectsAndKeys: |
| 204 font.nativeFont(), NSFontAttributeName, | 204 font.nativeFont(), NSFontAttributeName, |
| 205 ContentTextColor(), NSForegroundColorAttributeName, | 205 ContentTextColor(), NSForegroundColorAttributeName, |
| 206 nil]; | 206 nil]; |
| 207 NSString* rawEnDash = [NSString stringWithFormat:@" %C ", 0x2013]; | 207 NSString* rawEnDash = [NSString stringWithFormat:@" %C ", 0x2013]; |
| 208 NSAttributedString* enDash = | 208 NSAttributedString* enDash = |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 [[self backgroundColor] set]; | 487 [[self backgroundColor] set]; |
| 488 NSRectFill(cellFrame); | 488 NSRectFill(cellFrame); |
| 489 | 489 |
| 490 // Put the image centered vertically but in a fixed column. | 490 // Put the image centered vertically but in a fixed column. |
| 491 NSImage* image = [self image]; | 491 NSImage* image = [self image]; |
| 492 if (image) { | 492 if (image) { |
| 493 NSRect imageRect = cellFrame; | 493 NSRect imageRect = cellFrame; |
| 494 imageRect.size = [image size]; | 494 imageRect.size = [image size]; |
| 495 imageRect.origin.y += kImageBaselineAdjust + | 495 imageRect.origin.y += kImageBaselineAdjust + |
| 496 floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2); | 496 floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2); |
| 497 imageRect.origin.x += kLeftRightMargin; | 497 imageRect.origin.x += kImageXOffset; |
| 498 [image drawInRect:imageRect | 498 [image drawInRect:imageRect |
| 499 fromRect:NSZeroRect // Entire image | 499 fromRect:NSZeroRect // Entire image |
| 500 operation:NSCompositeSourceOver | 500 operation:NSCompositeSourceOver |
| 501 fraction:1.0 | 501 fraction:1.0 |
| 502 neverFlipped:YES]; | 502 neverFlipped:YES]; |
| 503 } | 503 } |
| 504 | 504 |
| 505 // Adjust the title position to be lined up under the field's text. | 505 // Adjust the title position to be lined up under the field's text. |
| 506 NSAttributedString* title = [self attributedTitle]; | 506 NSAttributedString* title = [self attributedTitle]; |
| 507 if (title) { | 507 if (title) { |
| 508 NSRect titleRect = cellFrame; | 508 NSRect titleRect = cellFrame; |
| 509 titleRect.size.width -= (kTextXOffset + kLeftRightMargin); | 509 titleRect.size.width -= kTextXOffset; |
| 510 titleRect.origin.x += kTextXOffset; | 510 titleRect.origin.x += kTextXOffset; |
| 511 [self drawTitle:title withFrame:titleRect inView:controlView]; | 511 [self drawTitle:title withFrame:titleRect inView:controlView]; |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 | 514 |
| 515 @end | 515 @end |
| 516 | 516 |
| 517 @implementation AutocompleteMatrix | 517 @implementation AutocompleteMatrix |
| 518 | 518 |
| 519 | 519 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 yRadius:kPopupRoundingRadius]; | 704 yRadius:kPopupRoundingRadius]; |
| 705 | 705 |
| 706 // Draw the matrix clipped to our border. | 706 // Draw the matrix clipped to our border. |
| 707 [NSGraphicsContext saveGraphicsState]; | 707 [NSGraphicsContext saveGraphicsState]; |
| 708 [path addClip]; | 708 [path addClip]; |
| 709 [super drawRect:rect]; | 709 [super drawRect:rect]; |
| 710 [NSGraphicsContext restoreGraphicsState]; | 710 [NSGraphicsContext restoreGraphicsState]; |
| 711 } | 711 } |
| 712 | 712 |
| 713 @end | 713 @end |
| OLD | NEW |