Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/media/tab_desktop_media_list.h" | 5 #include "chrome/browser/media/tab_desktop_media_list.h" |
| 6 | 6 |
| 7 #include "base/hash.h" | 7 #include "base/hash.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 gfx::ImageSkia CreateEnclosedFaviconImage(gfx::Size size, | 29 gfx::ImageSkia CreateEnclosedFaviconImage(gfx::Size size, |
| 30 const gfx::ImageSkia& favicon) { | 30 const gfx::ImageSkia& favicon) { |
| 31 DCHECK_GE(size.width(), 20); | 31 DCHECK_GE(size.width(), 20); |
| 32 DCHECK_GE(size.height(), 20); | 32 DCHECK_GE(size.height(), 20); |
| 33 | 33 |
| 34 // Create a bitmap. | 34 // Create a bitmap. |
| 35 SkBitmap result; | 35 SkBitmap result; |
| 36 result.allocN32Pixels(size.width(), size.height(), true); | 36 result.allocN32Pixels(size.width(), size.height(), false); |
| 37 SkCanvas canvas(result); | 37 SkCanvas canvas(result); |
| 38 | 38 |
| 39 // White background. | 39 // Draw transparent background. |
| 40 canvas.drawARGB(255, 255, 255, 255); | 40 const SkColor bg_color = 0; |
| 41 | 41 canvas.clear(bg_color); |
|
msw
2016/05/20 23:26:36
Just inline canvas.clear(SK_ColorTRANSPARENT), rem
qiangchen
2016/05/24 00:03:36
Done.
| |
| 42 // Black border. | |
| 43 const int thickness = 5; | |
| 44 SkPaint paint; | |
| 45 paint.setARGB(255, 0, 0, 0); | |
| 46 paint.setStyle(SkPaint::kStroke_Style); | |
| 47 paint.setStrokeWidth(thickness); | |
| 48 canvas.drawRectCoords(thickness, // left | |
| 49 thickness, // top | |
| 50 result.width() - thickness, // right | |
| 51 result.height() - thickness, // bottom | |
| 52 paint); | |
| 53 | 42 |
| 54 // Draw the favicon image into the center of result image. If the favicon is | 43 // Draw the favicon image into the center of result image. If the favicon is |
| 55 // too big, scale it down. | 44 // too big, scale it down. |
| 56 gfx::Size fill_size = favicon.size(); | 45 gfx::Size fill_size = favicon.size(); |
| 57 const double fraction = 0.75; | 46 if (result.width() < favicon.width() || result.height() < favicon.height()) { |
| 58 if (result.width() * fraction < favicon.width() || | 47 gfx::Size target_size(result.width(), result.height()); |
|
msw
2016/05/20 23:26:36
optional nit: remove |target_size|, inline |size|
qiangchen
2016/05/24 00:03:36
Done.
| |
| 59 result.height() * fraction < favicon.height()) { | |
| 60 gfx::Size target_size(result.width() * fraction, | |
| 61 result.height() * fraction); | |
| 62 fill_size = media::ScaleSizeToFitWithinTarget(favicon.size(), target_size); | 48 fill_size = media::ScaleSizeToFitWithinTarget(favicon.size(), target_size); |
| 63 } | 49 } |
| 64 gfx::Rect center_rect(result.width(), result.height()); | 50 gfx::Rect center_rect(result.width(), result.height()); |
| 65 center_rect.ClampToCenteredSize(fill_size); | 51 center_rect.ClampToCenteredSize(fill_size); |
| 66 SkRect dest_rect = | 52 SkRect dest_rect = |
| 67 SkRect::MakeLTRB(center_rect.x(), center_rect.y(), center_rect.right(), | 53 SkRect::MakeLTRB(center_rect.x(), center_rect.y(), center_rect.right(), |
| 68 center_rect.bottom()); | 54 center_rect.bottom()); |
| 69 const std::unique_ptr<SkImage> bitmap( | 55 const std::unique_ptr<SkImage> bitmap( |
| 70 SkImage::NewFromBitmap(*favicon.bitmap())); | 56 SkImage::NewFromBitmap(*favicon.bitmap())); |
| 71 canvas.drawImageRect(bitmap.get(), dest_rect, nullptr); | 57 canvas.drawImageRect(bitmap.get(), dest_rect, nullptr); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i); | 102 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i); |
| 117 DCHECK(contents); | 103 DCHECK(contents); |
| 118 content::RenderFrameHost* main_frame = contents->GetMainFrame(); | 104 content::RenderFrameHost* main_frame = contents->GetMainFrame(); |
| 119 DCHECK(main_frame); | 105 DCHECK(main_frame); |
| 120 DesktopMediaID media_id( | 106 DesktopMediaID media_id( |
| 121 DesktopMediaID::TYPE_WEB_CONTENTS, DesktopMediaID::kNullId, | 107 DesktopMediaID::TYPE_WEB_CONTENTS, DesktopMediaID::kNullId, |
| 122 content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(), | 108 content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(), |
| 123 main_frame->GetRoutingID())); | 109 main_frame->GetRoutingID())); |
| 124 | 110 |
| 125 // Create display tab title. | 111 // Create display tab title. |
| 126 const base::string16 title = l10n_util::GetStringFUTF16( | 112 const base::string16 title = contents->GetTitle(); |
|
msw
2016/05/20 23:26:36
optional nit: inline contents->GetTitle() below, r
qiangchen
2016/05/24 00:03:36
Done.
| |
| 127 IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE, contents->GetTitle()); | |
|
msw
2016/05/20 23:26:35
Remove IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE i
qiangchen
2016/05/24 00:03:36
You are right. I thought Mac side still used it, b
| |
| 128 | 113 |
| 129 // Get tab's last active time stamp. | 114 // Get tab's last active time stamp. |
| 130 const base::TimeTicks t = contents->GetLastActiveTime(); | 115 const base::TimeTicks t = contents->GetLastActiveTime(); |
| 131 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title))); | 116 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title))); |
| 132 | 117 |
| 133 // Get favicon for tab. | 118 // Get favicon for tab. |
| 134 favicon::FaviconDriver* favicon_driver = | 119 favicon::FaviconDriver* favicon_driver = |
| 135 favicon::ContentFaviconDriver::FromWebContents(contents); | 120 favicon::ContentFaviconDriver::FromWebContents(contents); |
| 136 if (!favicon_driver) | 121 if (!favicon_driver) |
| 137 continue; | 122 continue; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 155 |
| 171 // ScheduleNextRefresh() needs to be called after all calls for | 156 // ScheduleNextRefresh() needs to be called after all calls for |
| 172 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted | 157 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted |
| 173 // to the same sequenced task runner that CreateEnlargedFaviconImag() | 158 // to the same sequenced task runner that CreateEnlargedFaviconImag() |
| 174 // is posted. | 159 // is posted. |
| 175 thumbnail_task_runner_.get()->PostTaskAndReply( | 160 thumbnail_task_runner_.get()->PostTaskAndReply( |
| 176 FROM_HERE, base::Bind(&base::DoNothing), | 161 FROM_HERE, base::Bind(&base::DoNothing), |
| 177 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh, | 162 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh, |
| 178 weak_factory_.GetWeakPtr())); | 163 weak_factory_.GetWeakPtr())); |
| 179 } | 164 } |
| OLD | NEW |