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

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

Issue 2591073002: Simplify context menu for misspelled words + add metrics to this context (Closed)
Patch Set: Merge Created 3 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/renderer_context_menu/spelling_menu_observer.cc » ('j') | 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 {28, -1, IDC_VIEW_SOURCE}, 259 {28, -1, IDC_VIEW_SOURCE},
260 {29, -1, IDC_CONTENT_CONTEXT_INSPECTELEMENT}, 260 {29, -1, IDC_CONTENT_CONTEXT_INSPECTELEMENT},
261 {30, -1, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE}, 261 {30, -1, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE},
262 {31, -1, IDC_CONTENT_CONTEXT_VIEWPAGEINFO}, 262 {31, -1, IDC_CONTENT_CONTEXT_VIEWPAGEINFO},
263 {32, -1, IDC_CONTENT_CONTEXT_TRANSLATE}, 263 {32, -1, IDC_CONTENT_CONTEXT_TRANSLATE},
264 {33, -1, IDC_CONTENT_CONTEXT_RELOADFRAME}, 264 {33, -1, IDC_CONTENT_CONTEXT_RELOADFRAME},
265 {34, -1, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE}, 265 {34, -1, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE},
266 {35, -1, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO}, 266 {35, -1, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO},
267 {36, -1, IDC_CONTENT_CONTEXT_UNDO}, 267 {36, -1, IDC_CONTENT_CONTEXT_UNDO},
268 {37, -1, IDC_CONTENT_CONTEXT_REDO}, 268 {37, -1, IDC_CONTENT_CONTEXT_REDO},
269 {38, -1, IDC_CONTENT_CONTEXT_CUT}, 269 {38, 28, IDC_CONTENT_CONTEXT_CUT},
270 {39, 4, IDC_CONTENT_CONTEXT_COPY}, 270 {39, 4, IDC_CONTENT_CONTEXT_COPY},
271 {40, -1, IDC_CONTENT_CONTEXT_PASTE}, 271 {40, 29, IDC_CONTENT_CONTEXT_PASTE},
272 {41, -1, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE}, 272 {41, -1, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE},
273 {42, -1, IDC_CONTENT_CONTEXT_DELETE}, 273 {42, -1, IDC_CONTENT_CONTEXT_DELETE},
274 {43, -1, IDC_CONTENT_CONTEXT_SELECTALL}, 274 {43, -1, IDC_CONTENT_CONTEXT_SELECTALL},
275 {44, 17, IDC_CONTENT_CONTEXT_SEARCHWEBFOR}, 275 {44, 17, IDC_CONTENT_CONTEXT_SEARCHWEBFOR},
276 {45, -1, IDC_CONTENT_CONTEXT_GOTOURL}, 276 {45, -1, IDC_CONTENT_CONTEXT_GOTOURL},
277 {46, -1, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS}, 277 {46, -1, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS},
278 {47, -1, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS}, 278 {47, -1, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS},
279 {52, -1, IDC_CONTENT_CONTEXT_OPENLINKWITH}, 279 {52, -1, IDC_CONTENT_CONTEXT_OPENLINKWITH},
280 {53, -1, IDC_CHECK_SPELLING_WHILE_TYPING}, 280 {53, -1, IDC_CHECK_SPELLING_WHILE_TYPING},
281 {54, -1, IDC_SPELLCHECK_MENU}, 281 {54, -1, IDC_SPELLCHECK_MENU},
282 {55, -1, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE}, 282 {55, 27, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE},
283 {56, -1, IDC_SPELLCHECK_LANGUAGES_FIRST}, 283 {56, -1, IDC_SPELLCHECK_LANGUAGES_FIRST},
284 {57, 11, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, 284 {57, 11, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE},
285 {58, -1, IDC_SPELLCHECK_SUGGESTION_0}, 285 {58, 25, IDC_SPELLCHECK_SUGGESTION_0},
286 {59, -1, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, 286 {59, 26, IDC_SPELLCHECK_ADD_TO_DICTIONARY},
287 {60, -1, IDC_SPELLPANEL_TOGGLE}, 287 {60, -1, IDC_SPELLPANEL_TOGGLE},
288 {61, -1, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, 288 {61, -1, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB},
289 {62, -1, IDC_WRITING_DIRECTION_MENU}, 289 {62, -1, IDC_WRITING_DIRECTION_MENU},
290 {63, -1, IDC_WRITING_DIRECTION_DEFAULT}, 290 {63, -1, IDC_WRITING_DIRECTION_DEFAULT},
291 {64, -1, IDC_WRITING_DIRECTION_LTR}, 291 {64, -1, IDC_WRITING_DIRECTION_LTR},
292 {65, -1, IDC_WRITING_DIRECTION_RTL}, 292 {65, -1, IDC_WRITING_DIRECTION_RTL},
293 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, 293 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE},
294 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, 294 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD},
295 {68, -1, IDC_ROUTE_MEDIA}, 295 {68, -1, IDC_ROUTE_MEDIA},
296 {69, -1, IDC_CONTENT_CONTEXT_COPYLINKTEXT}, 296 {69, -1, IDC_CONTENT_CONTEXT_COPYLINKTEXT},
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_EDITABLE)) 790 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_EDITABLE))
791 AppendEditableItems(); 791 AppendEditableItems();
792 792
793 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_COPY)) { 793 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_COPY)) {
794 DCHECK(!content_type_->SupportsGroup( 794 DCHECK(!content_type_->SupportsGroup(
795 ContextMenuContentType::ITEM_GROUP_EDITABLE)); 795 ContextMenuContentType::ITEM_GROUP_EDITABLE));
796 AppendCopyItem(); 796 AppendCopyItem();
797 } 797 }
798 798
799 if (content_type_->SupportsGroup( 799 if (content_type_->SupportsGroup(
800 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER)) { 800 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER) &&
801 params_.misspelled_word.empty()) {
801 AppendSearchProvider(); 802 AppendSearchProvider();
802 } 803 }
803 804
804 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT) && 805 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT) &&
805 !content_type_->SupportsGroup( 806 !content_type_->SupportsGroup(
806 ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE)) { 807 ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE)) {
807 AppendPrintItem(); 808 AppendPrintItem();
808 } 809 }
809 810
810 if (content_type_->SupportsGroup( 811 if (content_type_->SupportsGroup(
811 ContextMenuContentType::ITEM_GROUP_EDITABLE)) { 812 ContextMenuContentType::ITEM_GROUP_EDITABLE) &&
813 params_.misspelled_word.empty()) {
812 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 814 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
813 AppendLanguageSettings(); 815 AppendLanguageSettings();
814 AppendPlatformEditableItems(); 816 AppendPlatformEditableItems();
815 } 817 }
816 818
817 if (content_type_->SupportsGroup( 819 if (content_type_->SupportsGroup(
818 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) { 820 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) {
819 AppendRotationItems(); 821 AppendRotationItems();
820 } 822 }
821 823
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 } 878 }
877 // Selected text context. 879 // Selected text context.
878 if (content_type_->SupportsGroup( 880 if (content_type_->SupportsGroup(
879 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER) && 881 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER) &&
880 content_type_->SupportsGroup( 882 content_type_->SupportsGroup(
881 ContextMenuContentType::ITEM_GROUP_PRINT)) { 883 ContextMenuContentType::ITEM_GROUP_PRINT)) {
882 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.SelectedText", 884 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.SelectedText",
883 enum_id, 885 enum_id,
884 kUmaEnumToControlId[kMappingSize - 1].enum_id); 886 kUmaEnumToControlId[kMappingSize - 1].enum_id);
885 } 887 }
888 // Misspelled word context.
889 if (!params_.misspelled_word.empty()) {
890 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.MisspelledWord",
891 enum_id,
892 kUmaEnumToControlId[kMappingSize - 1].enum_id);
893 }
886 } else { 894 } else {
887 NOTREACHED() << "Update kUmaEnumToControlId. Unhanded IDC: " << id; 895 NOTREACHED() << "Update kUmaEnumToControlId. Unhanded IDC: " << id;
888 } 896 }
889 } 897 }
890 898
891 void RenderViewContextMenu::RecordShownItem(int id) { 899 void RenderViewContextMenu::RecordShownItem(int id) {
892 int enum_id = FindUMAEnumValueForCommand(id, GENERAL_ENUM_ID); 900 int enum_id = FindUMAEnumValueForCommand(id, GENERAL_ENUM_ID);
893 if (enum_id != -1) { 901 if (enum_id != -1) {
894 const size_t kMappingSize = arraysize(kUmaEnumToControlId); 902 const size_t kMappingSize = arraysize(kUmaEnumToControlId);
895 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Shown", enum_id, 903 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Shown", enum_id,
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 void RenderViewContextMenu::AppendCopyItem() { 1284 void RenderViewContextMenu::AppendCopyItem() {
1277 if (menu_model_.GetItemCount()) 1285 if (menu_model_.GetItemCount())
1278 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 1286 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1279 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, 1287 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY,
1280 IDS_CONTENT_CONTEXT_COPY); 1288 IDS_CONTENT_CONTEXT_COPY);
1281 } 1289 }
1282 1290
1283 void RenderViewContextMenu::AppendPrintItem() { 1291 void RenderViewContextMenu::AppendPrintItem() {
1284 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && 1292 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) &&
1285 (params_.media_type == WebContextMenuData::MediaTypeNone || 1293 (params_.media_type == WebContextMenuData::MediaTypeNone ||
1286 params_.media_flags & WebContextMenuData::MediaCanPrint)) { 1294 params_.media_flags & WebContextMenuData::MediaCanPrint) &&
1295 params_.misspelled_word.empty()) {
Lei Zhang 2017/08/02 01:37:17 Why does printing care if there's misspelled words
edwardjung 2017/08/02 13:10:25 We're trying to optimise the context menu so that
1287 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); 1296 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT);
1288 } 1297 }
1289 } 1298 }
1290 1299
1291 void RenderViewContextMenu::AppendMediaRouterItem() { 1300 void RenderViewContextMenu::AppendMediaRouterItem() {
1292 if (media_router::MediaRouterEnabled(browser_context_)) { 1301 if (media_router::MediaRouterEnabled(browser_context_)) {
1293 menu_model_.AddItemWithStringId(IDC_ROUTE_MEDIA, 1302 menu_model_.AddItemWithStringId(IDC_ROUTE_MEDIA,
1294 IDS_MEDIA_ROUTER_MENU_ITEM_TITLE); 1303 IDS_MEDIA_ROUTER_MENU_ITEM_TITLE);
1295 } 1304 }
1296 } 1305 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 printable_selection_text)); 1367 printable_selection_text));
1359 } 1368 }
1360 } 1369 }
1361 } 1370 }
1362 1371
1363 void RenderViewContextMenu::AppendEditableItems() { 1372 void RenderViewContextMenu::AppendEditableItems() {
1364 const bool use_spelling = !chrome::IsRunningInForcedAppMode(); 1373 const bool use_spelling = !chrome::IsRunningInForcedAppMode();
1365 if (use_spelling) 1374 if (use_spelling)
1366 AppendSpellingSuggestionItems(); 1375 AppendSpellingSuggestionItems();
1367 1376
1377 if (!params_.misspelled_word.empty()) {
1378 AppendSearchProvider();
1379 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1380 }
1381
1368 // 'Undo' and 'Redo' for text input with no suggestions and no text selected. 1382 // 'Undo' and 'Redo' for text input with no suggestions and no text selected.
1369 // We make an exception for OS X as context clicking will select the closest 1383 // We make an exception for OS X as context clicking will select the closest
1370 // word. In this case both items are always shown. 1384 // word. In this case both items are always shown.
1371 #if defined(OS_MACOSX) 1385 #if defined(OS_MACOSX)
1372 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, 1386 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO,
1373 IDS_CONTENT_CONTEXT_UNDO); 1387 IDS_CONTENT_CONTEXT_UNDO);
1374 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO, 1388 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO,
1375 IDS_CONTENT_CONTEXT_REDO); 1389 IDS_CONTENT_CONTEXT_REDO);
1376 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 1390 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1377 #else 1391 #else
1378 if (!IsDevToolsURL(params_.page_url) && !menu_model_.GetItemCount() && 1392 if (!IsDevToolsURL(params_.page_url) && !menu_model_.GetItemCount() &&
1379 !content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) { 1393 !content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) {
1380 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, 1394 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO,
1381 IDS_CONTENT_CONTEXT_UNDO); 1395 IDS_CONTENT_CONTEXT_UNDO);
1382 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO, 1396 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO,
1383 IDS_CONTENT_CONTEXT_REDO); 1397 IDS_CONTENT_CONTEXT_REDO);
1384 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 1398 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1385 } 1399 }
1386 #endif 1400 #endif
1387 1401
1388 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_CUT, 1402 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_CUT,
1389 IDS_CONTENT_CONTEXT_CUT); 1403 IDS_CONTENT_CONTEXT_CUT);
1390 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, 1404 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY,
1391 IDS_CONTENT_CONTEXT_COPY); 1405 IDS_CONTENT_CONTEXT_COPY);
1392 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE, 1406 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE,
1393 IDS_CONTENT_CONTEXT_PASTE); 1407 IDS_CONTENT_CONTEXT_PASTE);
1394 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, 1408 if (params_.misspelled_word.empty()) {
1395 IDS_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE); 1409 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE,
1396 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, 1410 IDS_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE);
1397 IDS_CONTENT_CONTEXT_SELECTALL); 1411 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL,
1412 IDS_CONTENT_CONTEXT_SELECTALL);
1413 }
1398 1414
1399 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 1415 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1400 } 1416 }
1401 1417
1402 void RenderViewContextMenu::AppendLanguageSettings() { 1418 void RenderViewContextMenu::AppendLanguageSettings() {
1403 const bool use_spelling = !chrome::IsRunningInForcedAppMode(); 1419 const bool use_spelling = !chrome::IsRunningInForcedAppMode();
1404 if (!use_spelling) 1420 if (!use_spelling)
1405 return; 1421 return;
1406 1422
1407 #if defined(OS_MACOSX) 1423 #if defined(OS_MACOSX)
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 void RenderViewContextMenu::PluginActionAt( 2524 void RenderViewContextMenu::PluginActionAt(
2509 const gfx::Point& location, 2525 const gfx::Point& location,
2510 const WebPluginAction& action) { 2526 const WebPluginAction& action) {
2511 source_web_contents_->GetRenderViewHost()-> 2527 source_web_contents_->GetRenderViewHost()->
2512 ExecutePluginActionAtLocation(location, action); 2528 ExecutePluginActionAtLocation(location, action);
2513 } 2529 }
2514 2530
2515 Browser* RenderViewContextMenu::GetBrowser() const { 2531 Browser* RenderViewContextMenu::GetBrowser() const {
2516 return chrome::FindBrowserWithWebContents(embedder_web_contents_); 2532 return chrome::FindBrowserWithWebContents(embedder_web_contents_);
2517 } 2533 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_context_menu/spelling_menu_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698