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

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

Issue 2973006: Use the extension icon for extension omnibox results instead of the generic (Closed)
Patch Set: fixed mac Created 10 years, 5 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/stl_util-inl.h"
9 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_edit.h" 11 #include "chrome/browser/autocomplete/autocomplete_edit.h"
11 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 12 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
12 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 13 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
13 #include "chrome/browser/cocoa/event_utils.h" 14 #include "chrome/browser/cocoa/event_utils.h"
14 #include "chrome/browser/cocoa/image_utils.h" 15 #include "chrome/browser/cocoa/image_utils.h"
15 #include "gfx/rect.h" 16 #include "gfx/rect.h"
16 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "skia/ext/skia_utils_mac.h"
17 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" 19 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
18 20
19 namespace { 21 namespace {
20 22
21 // The size delta between the font used for the edit and the result 23 // The size delta between the font used for the edit and the result
22 // rows. 24 // rows.
23 const int kEditFontAdjust = -1; 25 const int kEditFontAdjust = -1;
24 26
25 // How much to adjust the cell sizing up from the default determined 27 // How much to adjust the cell sizing up from the default determined
26 // by the font. 28 // by the font.
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // Don't use the GTM additon for the "Steve" slowdown because this can happen 351 // Don't use the GTM additon for the "Steve" slowdown because this can happen
350 // async from user actions and the effects could be a surprise. 352 // async from user actions and the effects could be a surprise.
351 [[NSAnimationContext currentContext] setDuration:duration]; 353 [[NSAnimationContext currentContext] setDuration:duration];
352 [[popup_ animator] setFrame:popupFrame display:YES]; 354 [[popup_ animator] setFrame:popupFrame display:YES];
353 [NSAnimationContext endGrouping]; 355 [NSAnimationContext endGrouping];
354 356
355 if (!IsOpen()) 357 if (!IsOpen())
356 [[field_ window] addChildWindow:popup_ ordered:NSWindowAbove]; 358 [[field_ window] addChildWindow:popup_ ordered:NSWindowAbove];
357 } 359 }
358 360
361 NSImage* AutocompletePopupViewMac::ImageForMatch(
362 const AutocompleteMatch& match) {
363 const SkBitmap* bitmap = model_->GetSpecialIconForMatch(match);
364 if (bitmap)
365 return gfx::SkBitmapToNSImage(*bitmap);
366
367 const int resource_id = match.starred ?
368 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match.type);
369 return AutocompleteEditViewMac::ImageForResource(resource_id);
370 }
371
359 void AutocompletePopupViewMac::UpdatePopupAppearance() { 372 void AutocompletePopupViewMac::UpdatePopupAppearance() {
360 DCHECK([NSThread isMainThread]); 373 DCHECK([NSThread isMainThread]);
361 const AutocompleteResult& result = model_->result(); 374 const AutocompleteResult& result = model_->result();
362 if (result.empty()) { 375 if (result.empty()) {
363 [[popup_ parentWindow] removeChildWindow:popup_]; 376 [[popup_ parentWindow] removeChildWindow:popup_];
364 [popup_ orderOut:nil]; 377 [popup_ orderOut:nil];
365 378
366 // Break references to |this| because the popup may not be 379 // Break references to |this| because the popup may not be
367 // deallocated immediately. 380 // deallocated immediately.
368 AutocompleteMatrix* matrix = [popup_ contentView]; 381 AutocompleteMatrix* matrix = [popup_ contentView];
(...skipping 24 matching lines...) Expand all
393 DCHECK_GT(popupWidth, 0.0); 406 DCHECK_GT(popupWidth, 0.0);
394 const CGFloat matrixWidth = popupWidth / [popup_ userSpaceScaleFactor]; 407 const CGFloat matrixWidth = popupWidth / [popup_ userSpaceScaleFactor];
395 408
396 // Load the results into the popup's matrix. 409 // Load the results into the popup's matrix.
397 const size_t rows = model_->result().size(); 410 const size_t rows = model_->result().size();
398 DCHECK_GT(rows, 0U); 411 DCHECK_GT(rows, 0U);
399 [matrix renewRows:rows columns:1]; 412 [matrix renewRows:rows columns:1];
400 for (size_t ii = 0; ii < rows; ++ii) { 413 for (size_t ii = 0; ii < rows; ++ii) {
401 AutocompleteButtonCell* cell = [matrix cellAtRow:ii column:0]; 414 AutocompleteButtonCell* cell = [matrix cellAtRow:ii column:0];
402 const AutocompleteMatch& match = model_->result().match_at(ii); 415 const AutocompleteMatch& match = model_->result().match_at(ii);
403 const int resource_id = match.starred ? IDR_OMNIBOX_STAR 416 [cell setImage:ImageForMatch(match)];
404 : AutocompleteMatch::TypeToIcon(match.type);
405 [cell setImage:AutocompleteEditViewMac::ImageForResource(resource_id)];
406 [cell setAttributedTitle:MatchText(match, resultFont, matrixWidth)]; 417 [cell setAttributedTitle:MatchText(match, resultFont, matrixWidth)];
407 } 418 }
408 419
409 // Set the cell size to fit a line of text in the cell's font. All 420 // Set the cell size to fit a line of text in the cell's font. All
410 // cells should use the same font and each should layout in one 421 // cells should use the same font and each should layout in one
411 // line, so they should all be about the same height. 422 // line, so they should all be about the same height.
412 const NSSize cellSize = [[matrix cellAtRow:0 column:0] cellSize]; 423 const NSSize cellSize = [[matrix cellAtRow:0 column:0] cellSize];
413 DCHECK_GT(cellSize.height, 0.0); 424 DCHECK_GT(cellSize.height, 0.0);
414 const CGFloat cellHeight = cellSize.height + kCellHeightAdjust; 425 const CGFloat cellHeight = cellSize.height + kCellHeightAdjust;
415 [matrix setCellSize:NSMakeSize(matrixWidth, cellHeight)]; 426 [matrix setCellSize:NSMakeSize(matrixWidth, cellHeight)];
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 yRadius:kPopupRoundingRadius]; 715 yRadius:kPopupRoundingRadius];
705 716
706 // Draw the matrix clipped to our border. 717 // Draw the matrix clipped to our border.
707 [NSGraphicsContext saveGraphicsState]; 718 [NSGraphicsContext saveGraphicsState];
708 [path addClip]; 719 [path addClip];
709 [super drawRect:rect]; 720 [super drawRect:rect];
710 [NSGraphicsContext restoreGraphicsState]; 721 [NSGraphicsContext restoreGraphicsState];
711 } 722 }
712 723
713 @end 724 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698