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

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

Issue 2127009: Cleanup a bunch of TODO(shess). (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Created 10 years, 7 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
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 "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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 NSColor* BackgroundColor() { 67 NSColor* BackgroundColor() {
68 return [[NSColor controlBackgroundColor] colorWithAlphaComponent:kPopupAlpha]; 68 return [[NSColor controlBackgroundColor] colorWithAlphaComponent:kPopupAlpha];
69 } 69 }
70 NSColor* SelectedBackgroundColor() { 70 NSColor* SelectedBackgroundColor() {
71 return [[NSColor selectedControlColor] colorWithAlphaComponent:kPopupAlpha]; 71 return [[NSColor selectedControlColor] colorWithAlphaComponent:kPopupAlpha];
72 } 72 }
73 NSColor* HoveredBackgroundColor() { 73 NSColor* HoveredBackgroundColor() {
74 return [[NSColor controlHighlightColor] colorWithAlphaComponent:kPopupAlpha]; 74 return [[NSColor controlHighlightColor] colorWithAlphaComponent:kPopupAlpha];
75 } 75 }
76 76
77 // TODO(shess): These are totally unprincipled. I experimented with
78 // +controlTextColor and the like, but found myself wondering whether
79 // that was really appropriate. Circle back after consulting with
80 // someone more knowledgeable about the ins and outs of this.
81 static const NSColor* ContentTextColor() { 77 static const NSColor* ContentTextColor() {
82 return [NSColor blackColor]; 78 return [NSColor blackColor];
83 } 79 }
84 static const NSColor* URLTextColor() { 80 static const NSColor* URLTextColor() {
85 return [NSColor colorWithCalibratedRed:0.0 green:0.55 blue:0.0 alpha:1.0]; 81 return [NSColor colorWithCalibratedRed:0.0 green:0.55 blue:0.0 alpha:1.0];
86 } 82 }
87 static const NSColor* DescriptionTextColor() { 83 static const NSColor* DescriptionTextColor() {
88 return [NSColor darkGrayColor]; 84 return [NSColor darkGrayColor];
89 } 85 }
90 86
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 edit_view_(edit_view), 257 edit_view_(edit_view),
262 field_(field), 258 field_(field),
263 popup_(nil) { 259 popup_(nil) {
264 DCHECK(edit_view); 260 DCHECK(edit_view);
265 DCHECK(edit_model); 261 DCHECK(edit_model);
266 DCHECK(profile); 262 DCHECK(profile);
267 edit_model->SetPopupModel(model_.get()); 263 edit_model->SetPopupModel(model_.get());
268 } 264 }
269 265
270 AutocompletePopupViewMac::~AutocompletePopupViewMac() { 266 AutocompletePopupViewMac::~AutocompletePopupViewMac() {
271 // TODO(shess): Having to be aware of destructor ordering in this
272 // way seems brittle. There must be a better way.
273
274 // Destroy the popup model before this object is destroyed, because 267 // Destroy the popup model before this object is destroyed, because
275 // it can call back to us in the destructor. 268 // it can call back to us in the destructor.
276 model_.reset(); 269 model_.reset();
277 270
278 // Break references to |this| because the popup may not be 271 // Break references to |this| because the popup may not be
279 // deallocated immediately. 272 // deallocated immediately.
280 AutocompleteMatrix* matrix = [popup_ contentView]; 273 AutocompleteMatrix* matrix = [popup_ contentView];
281 DCHECK(matrix == nil || [matrix isKindOfClass:[AutocompleteMatrix class]]); 274 DCHECK(matrix == nil || [matrix isKindOfClass:[AutocompleteMatrix class]]);
282 [matrix setPopupView:NULL]; 275 [matrix setPopupView:NULL];
283 } 276 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 DCHECK(matrix == nil || [matrix isKindOfClass:[AutocompleteMatrix class]]); 358 DCHECK(matrix == nil || [matrix isKindOfClass:[AutocompleteMatrix class]]);
366 [matrix setPopupView:NULL]; 359 [matrix setPopupView:NULL];
367 360
368 popup_.reset(nil); 361 popup_.reset(nil);
369 362
370 return; 363 return;
371 } 364 }
372 365
373 CreatePopupIfNeeded(); 366 CreatePopupIfNeeded();
374 367
375 // The popup's font is a slightly smaller version of what |field_| 368 // The popup's font is a slightly smaller version of the field's.
376 // uses. 369 NSFont* fieldFont = AutocompleteEditViewMac::GetFieldFont();
377 NSFont* fieldFont = [field_ font];
378 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust; 370 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust;
379 gfx::Font resultFont = gfx::Font::CreateFont( 371 gfx::Font resultFont = gfx::Font::CreateFont(
380 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize); 372 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize);
381 373
382 AutocompleteMatrix* matrix = [popup_ contentView]; 374 AutocompleteMatrix* matrix = [popup_ contentView];
383 375
384 // Calculate the width of the matrix based on backing out the 376 // Calculate the width of the matrix based on backing out the
385 // popup's border from the width of the field. Would prefer to use 377 // popup's border from the width of the field. Would prefer to use
386 // [matrix convertSize:fromView:] for converting from screen size, 378 // [matrix convertSize:fromView:] for converting from screen size,
387 // but that doesn't work until the popup is on-screen (bug?). 379 // but that doesn't work until the popup is on-screen (bug?).
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 return SelectedBackgroundColor(); 465 return SelectedBackgroundColor();
474 } else if ([self isHighlighted]) { 466 } else if ([self isHighlighted]) {
475 return HoveredBackgroundColor(); 467 return HoveredBackgroundColor();
476 } 468 }
477 return BackgroundColor(); 469 return BackgroundColor();
478 } 470 }
479 471
480 // The default NSButtonCell drawing leaves the image flush left and 472 // The default NSButtonCell drawing leaves the image flush left and
481 // the title next to the image. This spaces things out to line up 473 // the title next to the image. This spaces things out to line up
482 // with the star button and autocomplete field. 474 // with the star button and autocomplete field.
483 // TODO(shess): Determine if the star button can change size (other
484 // than scaling coordinates), in which case this needs to be more
485 // dynamic.
486 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { 475 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
487 [[self backgroundColor] set]; 476 [[self backgroundColor] set];
488 NSRectFill(cellFrame); 477 NSRectFill(cellFrame);
489 478
490 // Put the image centered vertically but in a fixed column. 479 // Put the image centered vertically but in a fixed column.
491 // TODO(shess) Currently, the images are all 16x16 png files, so
492 // left-justified works out fine. If that changes, it may be
493 // appropriate to align them on their centers instead of their
494 // left-hand sides.
495 NSImage* image = [self image]; 480 NSImage* image = [self image];
496 if (image) { 481 if (image) {
497 NSRect imageRect = cellFrame; 482 NSRect imageRect = cellFrame;
498 imageRect.size = [image size]; 483 imageRect.size = [image size];
499 imageRect.origin.y += 484 imageRect.origin.y +=
500 floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2); 485 floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2);
501 imageRect.origin.x += kLeftRightMargin; 486 imageRect.origin.x += kLeftRightMargin;
502 [image setFlipped:[controlView isFlipped]]; 487 [image setFlipped:[controlView isFlipped]];
503 [image drawInRect:imageRect 488 [image drawInRect:imageRect
504 fromRect:NSZeroRect // Entire image 489 fromRect:NSZeroRect // Entire image
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 bottomRightCornerRadius:0.0]; 698 bottomRightCornerRadius:0.0];
714 699
715 // Draw the matrix clipped to our border. 700 // Draw the matrix clipped to our border.
716 [NSGraphicsContext saveGraphicsState]; 701 [NSGraphicsContext saveGraphicsState];
717 [path addClip]; 702 [path addClip];
718 [super drawRect:rect]; 703 [super drawRect:rect];
719 [NSGraphicsContext restoreGraphicsState]; 704 [NSGraphicsContext restoreGraphicsState];
720 } 705 }
721 706
722 @end 707 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698