Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer_context_menu/render_view_context_menu.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 #include "ppapi/features/features.h" | 110 #include "ppapi/features/features.h" |
| 111 #include "printing/features/features.h" | 111 #include "printing/features/features.h" |
| 112 #include "services/service_manager/public/cpp/interface_provider.h" | 112 #include "services/service_manager/public/cpp/interface_provider.h" |
| 113 #include "third_party/WebKit/public/public_features.h" | 113 #include "third_party/WebKit/public/public_features.h" |
| 114 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 114 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 115 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" | 115 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 116 #include "third_party/WebKit/public/web/WebPluginAction.h" | 116 #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 117 #include "ui/base/clipboard/clipboard.h" | 117 #include "ui/base/clipboard/clipboard.h" |
| 118 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 118 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 119 #include "ui/base/l10n/l10n_util.h" | 119 #include "ui/base/l10n/l10n_util.h" |
| 120 #include "ui/gfx/canvas.h" | |
| 121 #include "ui/gfx/favicon_size.h" | 120 #include "ui/gfx/favicon_size.h" |
| 122 #include "ui/gfx/geometry/point.h" | 121 #include "ui/gfx/geometry/point.h" |
| 123 #include "ui/gfx/geometry/size.h" | |
| 124 #include "ui/gfx/path.h" | |
| 125 #include "ui/gfx/text_elider.h" | 122 #include "ui/gfx/text_elider.h" |
| 126 | 123 |
| 127 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 124 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 128 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer .h" | 125 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer .h" |
| 129 #endif | 126 #endif |
| 130 | 127 |
| 131 #if BUILDFLAG(ENABLE_EXTENSIONS) | 128 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 132 #include "chrome/browser/extensions/devtools_util.h" | 129 #include "chrome/browser/extensions/devtools_util.h" |
| 133 #include "chrome/browser/extensions/extension_service.h" | 130 #include "chrome/browser/extensions/extension_service.h" |
| 134 #include "extensions/browser/extension_host.h" | 131 #include "extensions/browser/extension_host.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 net::UnescapeRule::NONE, nullptr, nullptr, nullptr); | 432 net::UnescapeRule::NONE, nullptr, nullptr, nullptr); |
| 436 | 433 |
| 437 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); | 434 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 438 scw.WriteURL(text); | 435 scw.WriteURL(text); |
| 439 } | 436 } |
| 440 | 437 |
| 441 bool g_custom_id_ranges_initialized = false; | 438 bool g_custom_id_ranges_initialized = false; |
| 442 | 439 |
| 443 #if !defined(OS_CHROMEOS) | 440 #if !defined(OS_CHROMEOS) |
| 444 void AddAvatarToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) { | 441 void AddAvatarToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) { |
| 442 // NOTE: On high dpi this will cause fuzzy output. | |
| 443 const float raster_scale = 1.f; | |
| 445 int width = icon.Width(); | 444 int width = icon.Width(); |
| 446 int height = icon.Height(); | 445 int height = icon.Height(); |
| 447 | 446 |
| 448 // Don't try to scale too small icons. | 447 // Don't try to scale too small icons. |
| 449 if (width < 16 || height < 16) | 448 if (width < 16 || height < 16) |
| 450 return; | 449 return; |
| 451 | 450 |
| 452 // Profile avatars are supposed to be displayed with a circular mask, so apply | 451 // Profile avatars are supposed to be displayed with a circular mask, so apply |
| 453 // one. | 452 // one. |
| 454 gfx::Path circular_mask; | 453 SkBitmap bitmap; |
| 455 gfx::Canvas canvas(icon.Size(), 1.0f, true); | 454 bitmap.allocN32Pixels(width, height, false /* opaque */); |
| 456 canvas.FillRect(gfx::Rect(icon.Size()), SK_ColorTRANSPARENT, | 455 SkCanvas canvas(bitmap); |
| 457 SkBlendMode::kClear); | 456 |
| 457 canvas.clear(SK_ColorTRANSPARENT); | |
| 458 | |
| 459 SkPath circular_mask; | |
| 458 circular_mask.addCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2, | 460 circular_mask.addCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2, |
| 459 SkIntToScalar(std::min(width, height)) / 2); | 461 SkIntToScalar(std::min(width, height)) / 2); |
| 460 canvas.ClipPath(circular_mask, true); | 462 canvas.clipPath(circular_mask, true /* antialias */); |
| 461 canvas.DrawImageInt(*icon.ToImageSkia(), 0, 0); | 463 |
| 464 const gfx::ImageSkiaRep& rep = | |
| 465 icon.ToImageSkia()->GetRepresentation(raster_scale); | |
|
Peter Kasting
2017/03/22 00:04:15
Rather than used this fixed-scale representation,
| |
| 466 canvas.save(); | |
| 467 canvas.scale(raster_scale / rep.scale(), raster_scale / rep.scale()); | |
| 468 canvas.drawBitmap(rep.sk_bitmap(), 0, 0); | |
| 469 canvas.restore(); | |
| 462 | 470 |
| 463 gfx::CalculateFaviconTargetSize(&width, &height); | 471 gfx::CalculateFaviconTargetSize(&width, &height); |
|
danakj
2017/03/22 14:41:42
I had some trouble understanding if the width/heig
| |
| 464 gfx::Image sized_icon = profiles::GetSizedAvatarIcon( | 472 gfx::Image sized_icon = profiles::GetSizedAvatarIcon( |
| 465 gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())), true, width, | 473 gfx::Image(gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, raster_scale))), true, |
| 466 height); | 474 width, height); |
| 467 menu->SetIcon(menu->GetItemCount() - 1, sized_icon); | 475 menu->SetIcon(menu->GetItemCount() - 1, sized_icon); |
| 468 } | 476 } |
| 469 #endif // !defined(OS_CHROMEOS) | 477 #endif // !defined(OS_CHROMEOS) |
| 470 | 478 |
| 471 // Adds Google icon to the last added menu item. Used for Google-powered | 479 // Adds Google icon to the last added menu item. Used for Google-powered |
| 472 // services like translate and search. | 480 // services like translate and search. |
| 473 void AddGoogleIconToLastMenuItem(ui::SimpleMenuModel* menu) { | 481 void AddGoogleIconToLastMenuItem(ui::SimpleMenuModel* menu) { |
| 474 #if defined(GOOGLE_CHROME_BUILD) | 482 #if defined(GOOGLE_CHROME_BUILD) |
| 475 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 483 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 476 switches::kEnableGoogleBrandedContextMenu) || | 484 switches::kEnableGoogleBrandedContextMenu) || |
| (...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2519 void RenderViewContextMenu::PluginActionAt( | 2527 void RenderViewContextMenu::PluginActionAt( |
| 2520 const gfx::Point& location, | 2528 const gfx::Point& location, |
| 2521 const WebPluginAction& action) { | 2529 const WebPluginAction& action) { |
| 2522 source_web_contents_->GetRenderViewHost()-> | 2530 source_web_contents_->GetRenderViewHost()-> |
| 2523 ExecutePluginActionAtLocation(location, action); | 2531 ExecutePluginActionAtLocation(location, action); |
| 2524 } | 2532 } |
| 2525 | 2533 |
| 2526 Browser* RenderViewContextMenu::GetBrowser() const { | 2534 Browser* RenderViewContextMenu::GetBrowser() const { |
| 2527 return chrome::FindBrowserWithWebContents(embedder_web_contents_); | 2535 return chrome::FindBrowserWithWebContents(embedder_web_contents_); |
| 2528 } | 2536 } |
| OLD | NEW |