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

Side by Side Diff: chrome/browser/cocoa/autocomplete_text_field_cell.mm

Issue 199072: Add SSL icons on Mac OS X (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/autocomplete_text_field_cell.h" 5 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
6 6
7 #import "base/logging.h" 7 #import "base/logging.h"
8 #import "third_party/GTM/AppKit/GTMTheme.h" 8 #import "third_party/GTM/AppKit/GTMTheme.h"
9 9
10 namespace { 10 namespace {
(...skipping 21 matching lines...) Expand all
32 // This moves it down so that there is approximately as much image 32 // This moves it down so that there is approximately as much image
33 // above the lowercase ascender as below the baseline. A better 33 // above the lowercase ascender as below the baseline. A better
34 // technique would be nice to have, though. 34 // technique would be nice to have, though.
35 const NSInteger kKeywordHintImageBaseline = -6; 35 const NSInteger kKeywordHintImageBaseline = -6;
36 36
37 // Offset from the bottom of the field for drawing decoration text. 37 // Offset from the bottom of the field for drawing decoration text.
38 // TODO(shess): Somehow determine the baseline for the text field and 38 // TODO(shess): Somehow determine the baseline for the text field and
39 // use that. 39 // use that.
40 const NSInteger kBaselineOffset = 4; 40 const NSInteger kBaselineOffset = 4;
41 41
42 // The amount of padding on either side reserved for drawing the hint icon
43 const NSInteger kHintIconHorizontalPad = 5;
44
42 } // namespace 45 } // namespace
43 46
44 @implementation AutocompleteTextFieldCell 47 @implementation AutocompleteTextFieldCell
45 48
46 @synthesize fieldEditorNeedsReset = fieldEditorNeedsReset_; 49 @synthesize fieldEditorNeedsReset = fieldEditorNeedsReset_;
47 50
48 // @synthesize doesn't seem to compile for this transition. 51 // @synthesize doesn't seem to compile for this transition.
49 - (NSAttributedString*)keywordString { 52 - (NSAttributedString*)keywordString {
50 return keywordString_.get(); 53 return keywordString_.get();
51 } 54 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 152
150 - (void)clearKeywordAndHint { 153 - (void)clearKeywordAndHint {
151 if (keywordString_ || hintString_) { 154 if (keywordString_ || hintString_) {
152 keywordString_.reset(); 155 keywordString_.reset();
153 hintString_.reset(); 156 hintString_.reset();
154 157
155 fieldEditorNeedsReset_ = YES; 158 fieldEditorNeedsReset_ = YES;
156 } 159 }
157 } 160 }
158 161
162 - (void)setHintIcon:(NSImage*)icon {
163 if (icon != hintIcon_) {
164 hintIcon_.reset([icon retain]);
165 if (!keywordString_ && !hintString_) {
166 fieldEditorNeedsReset_ = YES;
167 }
168 }
169 }
170
159 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 171 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
160 DCHECK([controlView isFlipped]); 172 DCHECK([controlView isFlipped]);
161 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set]; 173 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set];
162 NSFrameRectWithWidthUsingOperation(cellFrame, 1, NSCompositeSourceOver); 174 NSFrameRectWithWidthUsingOperation(cellFrame, 1, NSCompositeSourceOver);
163 175
164 // TODO(shess): This inset is also reflected in ToolbarController 176 // TODO(shess): This inset is also reflected in ToolbarController
165 // -autocompletePopupPosition. 177 // -autocompletePopupPosition.
166 NSRect frame = NSInsetRect(cellFrame, 0, 1); 178 NSRect frame = NSInsetRect(cellFrame, 0, 1);
167 [[self backgroundColor] setFill]; 179 [[self backgroundColor] setFill];
168 NSRect innerFrame = NSInsetRect(frame, 1, 1); 180 NSRect innerFrame = NSInsetRect(frame, 1, 1);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const CGFloat keywordWidth = kKeywordXOffset + 224 const CGFloat keywordWidth = kKeywordXOffset +
213 ceil([keywordString_ size].width) + 2 * kKeywordTokenInset; 225 ceil([keywordString_ size].width) + 2 * kKeywordTokenInset;
214 226
215 // TODO(shess): This could be better. There's support for a 227 // TODO(shess): This could be better. There's support for a
216 // "short" version of the keyword string, work that in in a 228 // "short" version of the keyword string, work that in in a
217 // follow-on pass. 229 // follow-on pass.
218 if (keywordWidth < NSWidth(cellFrame)) { 230 if (keywordWidth < NSWidth(cellFrame)) {
219 textFrame.origin.x += keywordWidth; 231 textFrame.origin.x += keywordWidth;
220 textFrame.size.width = NSMaxX(cellFrame) - NSMinX(textFrame); 232 textFrame.size.width = NSMaxX(cellFrame) - NSMinX(textFrame);
221 } 233 }
234 } else if (hintIcon_) {
235 CGFloat width = [hintIcon_ size].width;
236 width += kHintIconHorizontalPad * 2;
237 if (width < NSWidth(cellFrame)) {
238 textFrame.size.width -= width;
239 }
222 } 240 }
223 241
224 return textFrame; 242 return textFrame;
225 } 243 }
226 244
227 - (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 245 - (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
228 DCHECK(hintString_); 246 DCHECK(hintString_);
229 247
230 NSRect textFrame = [self textFrameForFrame:cellFrame]; 248 NSRect textFrame = [self textFrameForFrame:cellFrame];
231 NSRect infoFrame(NSMakeRect(NSMaxX(textFrame), 249 NSRect infoFrame(NSMakeRect(NSMaxX(textFrame),
(...skipping 26 matching lines...) Expand all
258 [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set]; 276 [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set];
259 [path setLineWidth:1.0]; 277 [path setLineWidth:1.0];
260 [path stroke]; 278 [path stroke];
261 279
262 // Draw text w/in the rectangle. 280 // Draw text w/in the rectangle.
263 infoFrame.origin.x += 4.0; 281 infoFrame.origin.x += 4.0;
264 infoFrame.origin.y += 1.0; 282 infoFrame.origin.y += 1.0;
265 [keywordString_.get() drawInRect:infoFrame]; 283 [keywordString_.get() drawInRect:infoFrame];
266 } 284 }
267 285
286 - (void)drawHintIconWithFrame:(NSRect)cellFrame
287 inView:(NSView*)controlView {
288 // We'll draw the entire image
289 NSRect imageRect = NSZeroRect;
290 imageRect.size = [hintIcon_ size];
291
292 // Move the rect that we're drawing into to the far right
293 cellFrame.origin.x += cellFrame.size.width - imageRect.size.width;
294 // Add back the padding
295 cellFrame.origin.x -= kHintIconHorizontalPad;
296
297 // Center the image vertically in the frame
298 cellFrame.origin.y +=
299 floor((cellFrame.size.height - imageRect.size.height) / 2);
300
301 // Set the drawing size to the image size
302 cellFrame.size = imageRect.size;
303
304 [hintIcon_ setFlipped:[controlView isFlipped]];
305 [hintIcon_ drawInRect:cellFrame
306 fromRect:imageRect
307 operation:NSCompositeSourceOver
308 fraction:1.0];
309 }
310
268 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 311 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
269 if (hintString_) { 312 if (hintString_) {
270 [self drawHintWithFrame:cellFrame inView:controlView]; 313 [self drawHintWithFrame:cellFrame inView:controlView];
271 } else if (keywordString_) { 314 } else if (keywordString_) {
272 [self drawKeywordWithFrame:cellFrame inView:controlView]; 315 [self drawKeywordWithFrame:cellFrame inView:controlView];
316 } else {
Scott Hess - ex-Googler 2009/09/15 18:16:52 else if (hintIcon_), like the other two cases.
hawk 2009/09/15 21:49:17 Done.
317 [self drawHintIconWithFrame:cellFrame inView:controlView];
273 } 318 }
274 319
275 [super drawInteriorWithFrame:[self textFrameForFrame:cellFrame] 320 [super drawInteriorWithFrame:[self textFrameForFrame:cellFrame]
276 inView:controlView]; 321 inView:controlView];
277 } 322 }
278 323
279 // Override these methods so that the field editor shows up in the right place 324 // Override these methods so that the field editor shows up in the right place
280 - (void)editWithFrame:(NSRect)cellFrame 325 - (void)editWithFrame:(NSRect)cellFrame
281 inView:(NSView*)controlView 326 inView:(NSView*)controlView
282 editor:(NSText*)textObj 327 editor:(NSText*)textObj
(...skipping 19 matching lines...) Expand all
302 start:selStart 347 start:selStart
303 length:selLength]; 348 length:selLength];
304 } 349 }
305 350
306 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { 351 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView {
307 [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] 352 [super resetCursorRect:[self textCursorFrameForFrame:cellFrame]
308 inView:controlView]; 353 inView:controlView];
309 } 354 }
310 355
311 @end 356 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_cell.h ('k') | chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698