OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/desktop_media_list.h" |
| 6 |
| 7 #include "third_party/skia/include/core/SkCanvas.h" |
| 8 #include "third_party/skia/include/core/SkImage.h" |
| 9 |
| 10 gfx::ImageSkia CreateEnlargedFaviconImage(gfx::Size size, gfx::Image& favicon) { |
| 11 if (size.width() < 30 || size.height() < 30) |
| 12 return gfx::ImageSkia(); |
| 13 |
| 14 // Create a bitmap. |
| 15 SkBitmap result; |
| 16 result.allocN32Pixels(size.width(), size.height(), true); |
| 17 SkCanvas canvas(result); |
| 18 |
| 19 // Fill with white. |
| 20 canvas.drawARGB(255, 255, 255, 255); |
| 21 |
| 22 // Draw black border. |
| 23 const int thickness = result.width() / 30; |
| 24 SkPaint paint; |
| 25 paint.setARGB(255, 0, 0, 0); |
| 26 paint.setStyle(SkPaint::kStroke_Style); |
| 27 paint.setStrokeWidth(thickness); |
| 28 canvas.drawRectCoords(thickness, // left |
| 29 thickness, // top |
| 30 result.width() - thickness, // right |
| 31 result.height() - thickness, // bottom |
| 32 paint); |
| 33 |
| 34 // Draw a scaled favicon image into the center of result image to take up to |
| 35 // 3/4 of result image. |
| 36 const double scale = fmin(3.0 / 4 * result.width() / favicon.Width(), |
| 37 3.0 / 4 * result.height() / favicon.Height()); |
| 38 SkRect dest_rect; |
| 39 dest_rect.set(result.width() / 2 - favicon.Width() * scale / 2, // left |
| 40 result.height() / 2 - favicon.Height() * scale / 2, // top |
| 41 result.width() / 2 + favicon.Width() * scale / 2, // right |
| 42 result.height() / 2 + favicon.Height() * scale / 2); // bottom |
| 43 const scoped_ptr<SkImage> temp_image( |
| 44 SkImage::NewFromBitmap(favicon.AsBitmap())); |
| 45 canvas.drawImageRect(temp_image.get(), dest_rect, nullptr); |
| 46 |
| 47 // Create a skia image. |
| 48 return gfx::ImageSkia::CreateFrom1xBitmap(result); |
| 49 } |
| 50 |
| 51 WebContentsRegistry* WebContentsRegistry::GetInstance() { |
| 52 return base::Singleton<WebContentsRegistry>::get(); |
| 53 } |
| 54 |
| 55 int WebContentsRegistry::RegisterWebContents( |
| 56 content::WebContents* web_contents) { |
| 57 IDMap<content::WebContents>::const_iterator it(®istered_web_contents_); |
| 58 for (; !it.IsAtEnd(); it.Advance()) { |
| 59 if (it.GetCurrentValue() == web_contents) |
| 60 return it.GetCurrentKey(); |
| 61 } |
| 62 |
| 63 Observe(web_contents); |
| 64 return registered_web_contents_.Add(web_contents); |
| 65 } |
| 66 |
| 67 content::WebContents* WebContentsRegistry::GetWebContentsById(int id) { |
| 68 return registered_web_contents_.Lookup(id); |
| 69 } |
| 70 |
| 71 WebContentsRegistry::WebContentsRegistry(){}; |
| 72 WebContentsRegistry::~WebContentsRegistry(){}; |
| 73 |
| 74 void WebContentsRegistry::WebContentsDestroyed( |
| 75 content::WebContents* web_contents) { |
| 76 IDMap<content::WebContents>::iterator it(®istered_web_contents_); |
| 77 for (; !it.IsAtEnd(); it.Advance()) { |
| 78 if (it.GetCurrentValue() == web_contents) { |
| 79 registered_web_contents_.Remove(it.GetCurrentKey()); |
| 80 return; |
| 81 } |
| 82 } |
| 83 NOTREACHED(); |
| 84 } |
OLD | NEW |