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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_view_mac.mm

Issue 6306011: Remove wstring from autocomplete. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months 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 | Annotate | Revision Log
OLDNEW
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 "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 static NSColor* URLTextColor() { 96 static NSColor* URLTextColor() {
97 return [NSColor colorWithCalibratedRed:0.0 green:0.55 blue:0.0 alpha:1.0]; 97 return [NSColor colorWithCalibratedRed:0.0 green:0.55 blue:0.0 alpha:1.0];
98 } 98 }
99 } // namespace 99 } // namespace
100 100
101 // Helper for MatchText() to allow sharing code between the contents 101 // Helper for MatchText() to allow sharing code between the contents
102 // and description cases. Returns NSMutableAttributedString as a 102 // and description cases. Returns NSMutableAttributedString as a
103 // convenience for MatchText(). 103 // convenience for MatchText().
104 NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString( 104 NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString(
105 const std::wstring &matchString, 105 const string16 &matchString,
106 const AutocompleteMatch::ACMatchClassifications &classifications, 106 const AutocompleteMatch::ACMatchClassifications &classifications,
107 NSColor* textColor, NSColor* dimTextColor, gfx::Font& font) { 107 NSColor* textColor, NSColor* dimTextColor, gfx::Font& font) {
108 // Cache for on-demand computation of the bold version of |font|. 108 // Cache for on-demand computation of the bold version of |font|.
109 NSFont* boldFont = nil; 109 NSFont* boldFont = nil;
110 110
111 // Start out with a string using the default style info. 111 // Start out with a string using the default style info.
112 NSString* s = base::SysWideToNSString(matchString); 112 NSString* s = base::SysUTF16ToNSString(matchString);
113 NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: 113 NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
114 font.GetNativeFont(), NSFontAttributeName, 114 font.GetNativeFont(), NSFontAttributeName,
115 textColor, NSForegroundColorAttributeName, 115 textColor, NSForegroundColorAttributeName,
116 nil]; 116 nil];
117 NSMutableAttributedString* as = 117 NSMutableAttributedString* as =
118 [[[NSMutableAttributedString alloc] initWithString:s 118 [[[NSMutableAttributedString alloc] initWithString:s
119 attributes:attributes] 119 attributes:attributes]
120 autorelease]; 120 autorelease];
121 121
122 // Mark up the runs which differ from the default. 122 // Mark up the runs which differ from the default.
(...skipping 24 matching lines...) Expand all
147 value:dimTextColor 147 value:dimTextColor
148 range:range]; 148 range:range];
149 } 149 }
150 } 150 }
151 151
152 return as; 152 return as;
153 } 153 }
154 154
155 NSMutableAttributedString* AutocompletePopupViewMac::ElideString( 155 NSMutableAttributedString* AutocompletePopupViewMac::ElideString(
156 NSMutableAttributedString* aString, 156 NSMutableAttributedString* aString,
157 const std::wstring originalString, 157 const string16 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(ui::ElideText( 166 const string16 elided = ui::ElideText(originalString, font, width, false);
167 WideToUTF16Hack(originalString), font, width, false)));
168 if (0 == elided.compare(originalString)) { 167 if (0 == elided.compare(originalString)) {
169 return aString; 168 return aString;
170 } 169 }
171 170
172 // If everything was elided away, clear the string. 171 // If everything was elided away, clear the string.
173 if (elided.size() == 0) { 172 if (elided.size() == 0) {
174 [aString deleteCharactersInRange:NSMakeRange(0, [aString length])]; 173 [aString deleteCharactersInRange:NSMakeRange(0, [aString length])];
175 return aString; 174 return aString;
176 } 175 }
177 176
178 // The ellipses should be the last character, and everything before 177 // The ellipses should be the last character, and everything before
179 // that should match the original string. 178 // that should match the original string.
180 const size_t i(elided.size() - 1); 179 const size_t i(elided.size() - 1);
181 DCHECK(0 != elided.compare(0, i, originalString)); 180 DCHECK(0 != elided.compare(0, i, originalString));
182 181
183 // Replace the end of |aString| with the ellipses from |elided|. 182 // Replace the end of |aString| with the ellipses from |elided|.
184 NSString* s = base::SysWideToNSString(elided.substr(i)); 183 NSString* s = base::SysUTF16ToNSString(elided.substr(i));
185 [aString replaceCharactersInRange:NSMakeRange(i, [aString length] - i) 184 [aString replaceCharactersInRange:NSMakeRange(i, [aString length] - i)
186 withString:s]; 185 withString:s];
187 186
188 return aString; 187 return aString;
189 } 188 }
190 189
191 // Return the text to show for the match, based on the match's 190 // Return the text to show for the match, based on the match's
192 // contents and description. Result will be in |font|, with the 191 // contents and description. Result will be in |font|, with the
193 // boldfaced version used for matches. 192 // boldfaced version used for matches.
194 NSAttributedString* AutocompletePopupViewMac::MatchText( 193 NSAttributedString* AutocompletePopupViewMac::MatchText(
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 disposition = 540 disposition =
542 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); 541 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
543 } 542 }
544 543
545 // OpenURL() may close the popup, which will clear the result set 544 // OpenURL() may close the popup, which will clear the result set
546 // and, by extension, |match| and its contents. So copy the 545 // and, by extension, |match| and its contents. So copy the
547 // relevant strings out to make sure they stay alive until the call 546 // relevant strings out to make sure they stay alive until the call
548 // completes. 547 // completes.
549 const AutocompleteMatch& match = model_->result().match_at(row); 548 const AutocompleteMatch& match = model_->result().match_at(row);
550 const GURL url(match.destination_url); 549 const GURL url(match.destination_url);
551 std::wstring keyword; 550 string16 keyword;
552 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); 551 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword);
553 edit_view_->OpenURL(url, disposition, match.transition, GURL(), row, 552 edit_view_->OpenURL(url, disposition, match.transition, GURL(), row,
554 is_keyword_hint ? std::wstring() : keyword); 553 is_keyword_hint ? string16() : keyword);
555 } 554 }
556 555
557 void AutocompletePopupViewMac::UserPressedOptIn(bool opt_in) { 556 void AutocompletePopupViewMac::UserPressedOptIn(bool opt_in) {
558 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); 557 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
559 DCHECK(counter); 558 DCHECK(counter);
560 counter->Hide(); 559 counter->Hide();
561 if (opt_in) { 560 if (opt_in) {
562 browser::ShowInstantConfirmDialogIfNecessary([field_ window], 561 browser::ShowInstantConfirmDialogIfNecessary([field_ window],
563 model_->profile()); 562 model_->profile());
564 } 563 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 bottomRightCornerRadius:kPopupRoundingRadius]; 826 bottomRightCornerRadius:kPopupRoundingRadius];
828 827
829 // Draw the matrix clipped to our border. 828 // Draw the matrix clipped to our border.
830 [NSGraphicsContext saveGraphicsState]; 829 [NSGraphicsContext saveGraphicsState];
831 [path addClip]; 830 [path addClip];
832 [super drawRect:rect]; 831 [super drawRect:rect];
833 [NSGraphicsContext restoreGraphicsState]; 832 [NSGraphicsContext restoreGraphicsState];
834 } 833 }
835 834
836 @end 835 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698