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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 1415413009: Use a circular profile icon in "open link as user" context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 5 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 103 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
104 #include "extensions/browser/view_type_utils.h" 104 #include "extensions/browser/view_type_utils.h"
105 #include "extensions/common/extension.h" 105 #include "extensions/common/extension.h"
106 #include "net/base/escape.h" 106 #include "net/base/escape.h"
107 #include "third_party/WebKit/public/web/WebContextMenuData.h" 107 #include "third_party/WebKit/public/web/WebContextMenuData.h"
108 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" 108 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
109 #include "third_party/WebKit/public/web/WebPluginAction.h" 109 #include "third_party/WebKit/public/web/WebPluginAction.h"
110 #include "ui/base/clipboard/clipboard.h" 110 #include "ui/base/clipboard/clipboard.h"
111 #include "ui/base/clipboard/scoped_clipboard_writer.h" 111 #include "ui/base/clipboard/scoped_clipboard_writer.h"
112 #include "ui/base/l10n/l10n_util.h" 112 #include "ui/base/l10n/l10n_util.h"
113 #include "ui/gfx/canvas.h"
113 #include "ui/gfx/favicon_size.h" 114 #include "ui/gfx/favicon_size.h"
114 #include "ui/gfx/geometry/point.h" 115 #include "ui/gfx/geometry/point.h"
115 #include "ui/gfx/geometry/size.h" 116 #include "ui/gfx/geometry/size.h"
117 #include "ui/gfx/path.h"
116 #include "ui/gfx/text_elider.h" 118 #include "ui/gfx/text_elider.h"
117 119
118 #if defined(ENABLE_EXTENSIONS) 120 #if defined(ENABLE_EXTENSIONS)
119 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h" 121 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h"
120 #endif 122 #endif
121 123
122 #if defined(ENABLE_PRINTING) 124 #if defined(ENABLE_PRINTING)
123 #include "chrome/browser/printing/print_view_manager_common.h" 125 #include "chrome/browser/printing/print_view_manager_common.h"
124 #include "components/printing/common/print_messages.h" 126 #include "components/printing/common/print_messages.h"
125 127
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 void WriteTextToClipboard(const base::string16& text) { 383 void WriteTextToClipboard(const base::string16& text) {
382 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); 384 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
383 scw.WriteText(text); 385 scw.WriteText(text);
384 } 386 }
385 387
386 bool g_custom_id_ranges_initialized = false; 388 bool g_custom_id_ranges_initialized = false;
387 389
388 void AddIconToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) { 390 void AddIconToLastMenuItem(gfx::Image icon, ui::SimpleMenuModel* menu) {
389 int width = icon.Width(); 391 int width = icon.Width();
390 int height = icon.Height(); 392 int height = icon.Height();
393
394 // Profile avatars are supposed to be displayed with a circular mask, so apply
395 // one.
396 gfx::Path circular_mask;
397 gfx::Canvas canvas(icon.Size(), 1.0f, true);
398 circular_mask.addCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2,
399 SkIntToScalar(std::min(width, height)) / 2);
400 canvas.ClipPath(circular_mask, true);
401 canvas.DrawImageInt(*icon.ToImageSkia(), 0, 0);
402
391 gfx::CalculateFaviconTargetSize(&width, &height); 403 gfx::CalculateFaviconTargetSize(&width, &height);
392 menu->SetIcon(menu->GetItemCount() - 1, 404 gfx::Image sized_icon = profiles::GetSizedAvatarIcon(
393 profiles::GetSizedAvatarIcon(icon, true, width, height)); 405 gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())), true, width,
406 height);
407 menu->SetIcon(menu->GetItemCount() - 1, sized_icon);
394 } 408 }
395 409
396 void OnProfileCreated(chrome::HostDesktopType desktop_type, 410 void OnProfileCreated(chrome::HostDesktopType desktop_type,
397 const GURL& link_url, 411 const GURL& link_url,
398 const content::Referrer& referrer, 412 const content::Referrer& referrer,
399 Profile* profile, 413 Profile* profile,
400 Profile::CreateStatus status) { 414 Profile::CreateStatus status) {
401 if (status == Profile::CREATE_STATUS_INITIALIZED) { 415 if (status == Profile::CREATE_STATUS_INITIALIZED) {
402 Browser* browser = chrome::FindLastActiveWithProfile(profile, desktop_type); 416 Browser* browser = chrome::FindLastActiveWithProfile(profile, desktop_type);
403 chrome::NavigateParams nav_params(browser, link_url, 417 chrome::NavigateParams nav_params(browser, link_url,
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 source_web_contents_->GetRenderViewHost()-> 2141 source_web_contents_->GetRenderViewHost()->
2128 ExecuteMediaPlayerActionAtLocation(location, action); 2142 ExecuteMediaPlayerActionAtLocation(location, action);
2129 } 2143 }
2130 2144
2131 void RenderViewContextMenu::PluginActionAt( 2145 void RenderViewContextMenu::PluginActionAt(
2132 const gfx::Point& location, 2146 const gfx::Point& location,
2133 const WebPluginAction& action) { 2147 const WebPluginAction& action) {
2134 source_web_contents_->GetRenderViewHost()-> 2148 source_web_contents_->GetRenderViewHost()->
2135 ExecutePluginActionAtLocation(location, action); 2149 ExecutePluginActionAtLocation(location, action);
2136 } 2150 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698