| 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" | 7 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" |
| 8 | 8 |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "app/text_elider.h" | |
| 11 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| 12 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| 13 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 13 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | 14 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_match.h" | 15 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 18 #include "chrome/browser/instant/instant_confirm_dialog.h" | 17 #include "chrome/browser/instant/instant_confirm_dialog.h" |
| 19 #include "chrome/browser/instant/promo_counter.h" | 18 #include "chrome/browser/instant/promo_counter.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/cocoa/event_utils.h" | 20 #include "chrome/browser/ui/cocoa/event_utils.h" |
| 22 #include "chrome/browser/ui/cocoa/image_utils.h" | 21 #include "chrome/browser/ui/cocoa/image_utils.h" |
| 23 #import "chrome/browser/ui/cocoa/location_bar/instant_opt_in_controller.h" | 22 #import "chrome/browser/ui/cocoa/location_bar/instant_opt_in_controller.h" |
| 24 #import "chrome/browser/ui/cocoa/location_bar/instant_opt_in_view.h" | 23 #import "chrome/browser/ui/cocoa/location_bar/instant_opt_in_view.h" |
| 25 #import "chrome/browser/ui/cocoa/location_bar/omnibox_popup_view.h" | 24 #import "chrome/browser/ui/cocoa/location_bar/omnibox_popup_view.h" |
| 26 #include "gfx/rect.h" | 25 #include "gfx/rect.h" |
| 27 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 28 #include "skia/ext/skia_utils_mac.h" | 27 #include "skia/ext/skia_utils_mac.h" |
| 29 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 28 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 30 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 29 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
| 30 #include "ui/base/text/text_elider.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // The size delta between the font used for the edit and the result | 34 // The size delta between the font used for the edit and the result |
| 35 // rows. | 35 // rows. |
| 36 const int kEditFontAdjust = -1; | 36 const int kEditFontAdjust = -1; |
| 37 | 37 |
| 38 // How much to adjust the cell sizing up from the default determined | 38 // How much to adjust the cell sizing up from the default determined |
| 39 // by the font. | 39 // by the font. |
| 40 const int kCellHeightAdjust = 6.0; | 40 const int kCellHeightAdjust = 6.0; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 NSMutableAttributedString* aString, | 156 NSMutableAttributedString* aString, |
| 157 const std::wstring originalString, | 157 const std::wstring originalString, |
| 158 const gfx::Font& font, | 158 const gfx::Font& font, |
| 159 const float width) { | 159 const float width) { |
| 160 // If it already fits, nothing to be done. | 160 // If it already fits, nothing to be done. |
| 161 if ([aString size].width <= width) { | 161 if ([aString size].width <= width) { |
| 162 return aString; | 162 return aString; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // If ElideText() decides to do nothing, nothing to be done. | 165 // If ElideText() decides to do nothing, nothing to be done. |
| 166 const std::wstring elided(UTF16ToWideHack(ElideText( | 166 const std::wstring elided(UTF16ToWideHack(ui::ElideText( |
| 167 WideToUTF16Hack(originalString), font, width, false))); | 167 WideToUTF16Hack(originalString), font, width, false))); |
| 168 if (0 == elided.compare(originalString)) { | 168 if (0 == elided.compare(originalString)) { |
| 169 return aString; | 169 return aString; |
| 170 } | 170 } |
| 171 | 171 |
| 172 // If everything was elided away, clear the string. | 172 // If everything was elided away, clear the string. |
| 173 if (elided.size() == 0) { | 173 if (elided.size() == 0) { |
| 174 [aString deleteCharactersInRange:NSMakeRange(0, [aString length])]; | 174 [aString deleteCharactersInRange:NSMakeRange(0, [aString length])]; |
| 175 return aString; | 175 return aString; |
| 176 } | 176 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 202 | 202 |
| 203 // If there is a description, append it, separated from the contents | 203 // If there is a description, append it, separated from the contents |
| 204 // with an en dash, and decorated with a distinct color. | 204 // with an en dash, and decorated with a distinct color. |
| 205 if (!match.description.empty()) { | 205 if (!match.description.empty()) { |
| 206 // Make sure the current string fits w/in kMaxContentsFraction of | 206 // Make sure the current string fits w/in kMaxContentsFraction of |
| 207 // the cell to make sure the description will be at least | 207 // the cell to make sure the description will be at least |
| 208 // partially visible. | 208 // partially visible. |
| 209 // TODO(shess): Consider revising our NSCell subclass to have two | 209 // TODO(shess): Consider revising our NSCell subclass to have two |
| 210 // bits and just draw them right, rather than truncating here. | 210 // bits and just draw them right, rather than truncating here. |
| 211 const float textWidth = cellWidth - kTextXOffset; | 211 const float textWidth = cellWidth - kTextXOffset; |
| 212 as = ElideString(as, match.contents, font, | 212 as = ui::ElideString(as, match.contents, font, |
| 213 textWidth * kMaxContentsFraction); | 213 textWidth * kMaxContentsFraction); |
| 214 | 214 |
| 215 NSDictionary* attributes = | 215 NSDictionary* attributes = |
| 216 [NSDictionary dictionaryWithObjectsAndKeys: | 216 [NSDictionary dictionaryWithObjectsAndKeys: |
| 217 font.GetNativeFont(), NSFontAttributeName, | 217 font.GetNativeFont(), NSFontAttributeName, |
| 218 ContentTextColor(), NSForegroundColorAttributeName, | 218 ContentTextColor(), NSForegroundColorAttributeName, |
| 219 nil]; | 219 nil]; |
| 220 NSString* rawEnDash = [NSString stringWithFormat:@" %C ", 0x2013]; | 220 NSString* rawEnDash = [NSString stringWithFormat:@" %C ", 0x2013]; |
| 221 NSAttributedString* enDash = | 221 NSAttributedString* enDash = |
| 222 [[[NSAttributedString alloc] initWithString:rawEnDash | 222 [[[NSAttributedString alloc] initWithString:rawEnDash |
| 223 attributes:attributes] autorelease]; | 223 attributes:attributes] autorelease]; |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 bottomRightCornerRadius:kPopupRoundingRadius]; | 827 bottomRightCornerRadius:kPopupRoundingRadius]; |
| 828 | 828 |
| 829 // Draw the matrix clipped to our border. | 829 // Draw the matrix clipped to our border. |
| 830 [NSGraphicsContext saveGraphicsState]; | 830 [NSGraphicsContext saveGraphicsState]; |
| 831 [path addClip]; | 831 [path addClip]; |
| 832 [super drawRect:rect]; | 832 [super drawRect:rect]; |
| 833 [NSGraphicsContext restoreGraphicsState]; | 833 [NSGraphicsContext restoreGraphicsState]; |
| 834 } | 834 } |
| 835 | 835 |
| 836 @end | 836 @end |
| OLD | NEW |