| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 url, url_formatter::kFormatUrlOmitNothing, | 431 url, url_formatter::kFormatUrlOmitNothing, |
| 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(const gfx::Image& icon, |
| 445 int width = icon.Width(); | 442 ui::SimpleMenuModel* menu) { |
| 446 int height = icon.Height(); | |
| 447 | |
| 448 // Don't try to scale too small icons. | 443 // Don't try to scale too small icons. |
| 449 if (width < 16 || height < 16) | 444 if (icon.Width() < 16 || icon.Height() < 16) |
| 450 return; | 445 return; |
| 451 | 446 int target_dip_width = icon.Width(); |
| 452 // Profile avatars are supposed to be displayed with a circular mask, so apply | 447 int target_dip_height = icon.Height(); |
| 453 // one. | 448 gfx::CalculateFaviconTargetSize(&target_dip_width, &target_dip_height); |
| 454 gfx::Path circular_mask; | |
| 455 gfx::Canvas canvas(icon.Size(), 1.0f, true); | |
| 456 canvas.FillRect(gfx::Rect(icon.Size()), SK_ColorTRANSPARENT, | |
| 457 SkBlendMode::kClear); | |
| 458 circular_mask.addCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2, | |
| 459 SkIntToScalar(std::min(width, height)) / 2); | |
| 460 canvas.ClipPath(circular_mask, true); | |
| 461 canvas.DrawImageInt(*icon.ToImageSkia(), 0, 0); | |
| 462 | |
| 463 gfx::CalculateFaviconTargetSize(&width, &height); | |
| 464 gfx::Image sized_icon = profiles::GetSizedAvatarIcon( | 449 gfx::Image sized_icon = profiles::GetSizedAvatarIcon( |
| 465 gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())), true, width, | 450 icon, true /* is_rectangle */, target_dip_width, target_dip_height, |
| 466 height); | 451 profiles::SHAPE_CIRCLE); |
| 467 menu->SetIcon(menu->GetItemCount() - 1, sized_icon); | 452 menu->SetIcon(menu->GetItemCount() - 1, sized_icon); |
| 468 } | 453 } |
| 469 #endif // !defined(OS_CHROMEOS) | 454 #endif // !defined(OS_CHROMEOS) |
| 470 | 455 |
| 471 // Adds Google icon to the last added menu item. Used for Google-powered | 456 // Adds Google icon to the last added menu item. Used for Google-powered |
| 472 // services like translate and search. | 457 // services like translate and search. |
| 473 void AddGoogleIconToLastMenuItem(ui::SimpleMenuModel* menu) { | 458 void AddGoogleIconToLastMenuItem(ui::SimpleMenuModel* menu) { |
| 474 #if defined(GOOGLE_CHROME_BUILD) | 459 #if defined(GOOGLE_CHROME_BUILD) |
| 475 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 460 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 476 switches::kEnableGoogleBrandedContextMenu) || | 461 switches::kEnableGoogleBrandedContextMenu) || |
| (...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2519 void RenderViewContextMenu::PluginActionAt( | 2504 void RenderViewContextMenu::PluginActionAt( |
| 2520 const gfx::Point& location, | 2505 const gfx::Point& location, |
| 2521 const WebPluginAction& action) { | 2506 const WebPluginAction& action) { |
| 2522 source_web_contents_->GetRenderViewHost()-> | 2507 source_web_contents_->GetRenderViewHost()-> |
| 2523 ExecutePluginActionAtLocation(location, action); | 2508 ExecutePluginActionAtLocation(location, action); |
| 2524 } | 2509 } |
| 2525 | 2510 |
| 2526 Browser* RenderViewContextMenu::GetBrowser() const { | 2511 Browser* RenderViewContextMenu::GetBrowser() const { |
| 2527 return chrome::FindBrowserWithWebContents(embedder_web_contents_); | 2512 return chrome::FindBrowserWithWebContents(embedder_web_contents_); |
| 2528 } | 2513 } |
| OLD | NEW |