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

Side by Side Diff: chrome/browser/ui/views/create_application_shortcut_view.cc

Issue 1424913007: Added ImageFamily::CreateExact, which scales the best image to size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master-plus
Patch Set: Added test for CreateExact on an non-N32 bitmap. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | ui/gfx/icon_util.cc » ('j') | ui/gfx/icon_util.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/create_application_shortcut_view.h" 5 #include "chrome/browser/ui/views/create_application_shortcut_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 void AppInfoView::UpdateText(const base::string16& title, 170 void AppInfoView::UpdateText(const base::string16& title,
171 const base::string16& description) { 171 const base::string16& description) {
172 title_->SetText(title); 172 title_->SetText(title);
173 PrepareDescriptionLabel(description); 173 PrepareDescriptionLabel(description);
174 174
175 SetupLayout(); 175 SetupLayout();
176 } 176 }
177 177
178 void AppInfoView::UpdateIcon(const gfx::ImageFamily& image) { 178 void AppInfoView::UpdateIcon(const gfx::ImageFamily& image) {
179 // Get the icon closest to the desired preview size. 179 // Get an icon at the desired preview size (scaling from a larger image if
180 const gfx::Image* icon = image.GetBest(kIconPreviewSizePixels, 180 // none is available at that exact size).
181 kIconPreviewSizePixels); 181 gfx::Image icon =
182 if (!icon || icon->IsEmpty()) 182 image.CreateExact(kIconPreviewSizePixels, kIconPreviewSizePixels);
183 // The family has no icons. Leave the image blank. 183 icon_->SetImage(icon.ToImageSkia());
184 return;
185 const SkBitmap& bitmap = *icon->ToSkBitmap();
186 if (bitmap.width() == kIconPreviewSizePixels &&
187 bitmap.height() == kIconPreviewSizePixels) {
188 icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
189 } else {
190 // Resize the image to the desired size.
191 SkBitmap resized_bitmap = skia::ImageOperations::Resize(
192 bitmap, skia::ImageOperations::RESIZE_LANCZOS3,
193 kIconPreviewSizePixels, kIconPreviewSizePixels);
194
195 icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(resized_bitmap));
196 }
197 } 184 }
198 185
199 void AppInfoView::OnPaint(gfx::Canvas* canvas) { 186 void AppInfoView::OnPaint(gfx::Canvas* canvas) {
200 gfx::Rect bounds = GetLocalBounds(); 187 gfx::Rect bounds = GetLocalBounds();
201 188
202 SkRect border_rect = { 189 SkRect border_rect = {
203 SkIntToScalar(bounds.x()), 190 SkIntToScalar(bounds.x()),
204 SkIntToScalar(bounds.y()), 191 SkIntToScalar(bounds.y()),
205 SkIntToScalar(bounds.right()), 192 SkIntToScalar(bounds.right()),
206 SkIntToScalar(bounds.bottom()) 193 SkIntToScalar(bounds.bottom())
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 close_callback_.Run(false); 551 close_callback_.Run(false);
565 return CreateApplicationShortcutView::Cancel(); 552 return CreateApplicationShortcutView::Cancel();
566 } 553 }
567 554
568 void CreateChromeApplicationShortcutView::OnAppInfoLoaded( 555 void CreateChromeApplicationShortcutView::OnAppInfoLoaded(
569 scoped_ptr<web_app::ShortcutInfo> shortcut_info, 556 scoped_ptr<web_app::ShortcutInfo> shortcut_info,
570 const extensions::FileHandlersInfo& file_handlers_info) { 557 const extensions::FileHandlersInfo& file_handlers_info) {
571 shortcut_info_ = shortcut_info.Pass(); 558 shortcut_info_ = shortcut_info.Pass();
572 file_handlers_info_ = file_handlers_info; 559 file_handlers_info_ = file_handlers_info;
573 } 560 }
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/icon_util.cc » ('j') | ui/gfx/icon_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698