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

Side by Side Diff: chrome/browser/media/tab_desktop_media_list.cc

Issue 1990053002: Desktop Capture Picker New UI: Non Mac Appearance Change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit fixes Created 4 years, 6 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 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
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 canvas.clear(SK_ColorTRANSPARENT);
39 // White background.
40 canvas.drawARGB(255, 255, 255, 255);
41
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 39
54 // Draw the favicon image into the center of result image. If the favicon is 40 // Draw the favicon image into the center of result image. If the favicon is
55 // too big, scale it down. 41 // too big, scale it down.
56 gfx::Size fill_size = favicon.size(); 42 gfx::Size fill_size = favicon.size();
57 const double fraction = 0.75; 43 if (result.width() < favicon.width() || result.height() < favicon.height())
58 if (result.width() * fraction < favicon.width() || 44 fill_size = media::ScaleSizeToFitWithinTarget(favicon.size(), size);
59 result.height() * fraction < favicon.height()) { 45
60 gfx::Size target_size(result.width() * fraction,
61 result.height() * fraction);
62 fill_size = media::ScaleSizeToFitWithinTarget(favicon.size(), target_size);
63 }
64 gfx::Rect center_rect(result.width(), result.height()); 46 gfx::Rect center_rect(result.width(), result.height());
65 center_rect.ClampToCenteredSize(fill_size); 47 center_rect.ClampToCenteredSize(fill_size);
66 SkRect dest_rect = 48 SkRect dest_rect =
67 SkRect::MakeLTRB(center_rect.x(), center_rect.y(), center_rect.right(), 49 SkRect::MakeLTRB(center_rect.x(), center_rect.y(), center_rect.right(),
68 center_rect.bottom()); 50 center_rect.bottom());
69 const std::unique_ptr<SkImage> bitmap( 51 const std::unique_ptr<SkImage> bitmap(
70 SkImage::NewFromBitmap(*favicon.bitmap())); 52 SkImage::NewFromBitmap(*favicon.bitmap()));
71 canvas.drawImageRect(bitmap.get(), dest_rect, nullptr); 53 canvas.drawImageRect(bitmap.get(), dest_rect, nullptr);
72 54
73 return gfx::ImageSkia::CreateFrom1xBitmap(result); 55 return gfx::ImageSkia::CreateFrom1xBitmap(result);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Create id for tab. 97 // Create id for tab.
116 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i); 98 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i);
117 DCHECK(contents); 99 DCHECK(contents);
118 content::RenderFrameHost* main_frame = contents->GetMainFrame(); 100 content::RenderFrameHost* main_frame = contents->GetMainFrame();
119 DCHECK(main_frame); 101 DCHECK(main_frame);
120 DesktopMediaID media_id( 102 DesktopMediaID media_id(
121 DesktopMediaID::TYPE_WEB_CONTENTS, DesktopMediaID::kNullId, 103 DesktopMediaID::TYPE_WEB_CONTENTS, DesktopMediaID::kNullId,
122 content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(), 104 content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(),
123 main_frame->GetRoutingID())); 105 main_frame->GetRoutingID()));
124 106
125 // Create display tab title.
126 const base::string16 title = l10n_util::GetStringFUTF16(
127 IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE, contents->GetTitle());
128
129 // Get tab's last active time stamp. 107 // Get tab's last active time stamp.
130 const base::TimeTicks t = contents->GetLastActiveTime(); 108 const base::TimeTicks t = contents->GetLastActiveTime();
131 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title))); 109 tab_map.insert(
110 std::make_pair(t, SourceDescription(media_id, contents->GetTitle())));
132 111
133 // Get favicon for tab. 112 // Get favicon for tab.
134 favicon::FaviconDriver* favicon_driver = 113 favicon::FaviconDriver* favicon_driver =
135 favicon::ContentFaviconDriver::FromWebContents(contents); 114 favicon::ContentFaviconDriver::FromWebContents(contents);
136 if (!favicon_driver) 115 if (!favicon_driver)
137 continue; 116 continue;
138 117
139 gfx::Image favicon = favicon_driver->GetFavicon(); 118 gfx::Image favicon = favicon_driver->GetFavicon();
140 if (favicon.IsEmpty()) 119 if (favicon.IsEmpty())
141 continue; 120 continue;
(...skipping 28 matching lines...) Expand all
170 149
171 // ScheduleNextRefresh() needs to be called after all calls for 150 // ScheduleNextRefresh() needs to be called after all calls for
172 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted 151 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted
173 // to the same sequenced task runner that CreateEnlargedFaviconImag() 152 // to the same sequenced task runner that CreateEnlargedFaviconImag()
174 // is posted. 153 // is posted.
175 thumbnail_task_runner_.get()->PostTaskAndReply( 154 thumbnail_task_runner_.get()->PostTaskAndReply(
176 FROM_HERE, base::Bind(&base::DoNothing), 155 FROM_HERE, base::Bind(&base::DoNothing),
177 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh, 156 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh,
178 weak_factory_.GetWeakPtr())); 157 weak_factory_.GetWeakPtr()));
179 } 158 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/media/tab_desktop_media_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698