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

Side by Side Diff: Source/WebKit/chromium/src/ContextMenuClientImpl.cpp

Issue 14185003: Use ContextMenu code path that was guarded by CROSS_PLATFORM_CONTEXT_MENU (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use ContextMenu code path that was guarded by CROSS_PLATFORM_CONTEXT_MENU Created 7 years, 8 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 /* 1 /*
2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 selectedFrame->selection()->setSelection(selection, WordGranularity); 171 selectedFrame->selection()->setSelection(selection, WordGranularity);
172 selectionRange = selection.toNormalizedRange(); 172 selectionRange = selection.toNormalizedRange();
173 } 173 }
174 174
175 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation)) 175 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation))
176 return String(); 176 return String();
177 177
178 return markerRange->text(); 178 return markerRange->text();
179 } 179 }
180 180
181 PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems( 181 PassOwnPtr<WebCore::ContextMenu> ContextMenuClientImpl::customizeMenu(PassOwnPtr <WebCore::ContextMenu> defaultMenu)
182 ContextMenu* defaultMenu)
183 { 182 {
184 // Displaying the context menu in this function is a big hack as we don't 183 // Displaying the context menu in this function is a big hack as we don't
185 // have context, i.e. whether this is being invoked via a script or in 184 // have context, i.e. whether this is being invoked via a script or in
186 // response to user input (Mouse event WM_RBUTTONDOWN, 185 // response to user input (Mouse event WM_RBUTTONDOWN,
187 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked 186 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked
188 // in response to the above input events before popping up the context menu. 187 // in response to the above input events before popping up the context menu.
189 if (!m_webView->contextMenuAllowed()) 188 if (!m_webView->contextMenuAllowed())
190 return 0; 189 return defaultMenu;
191 190
192 HitTestResult r = m_webView->page()->contextMenuController()->hitTestResult( ); 191 HitTestResult r = m_webView->page()->contextMenuController()->hitTestResult( );
193 Frame* selectedFrame = r.innerNodeFrame(); 192 Frame* selectedFrame = r.innerNodeFrame();
194 193
195 WebContextMenuData data; 194 WebContextMenuData data;
196 data.mousePosition = selectedFrame->view()->contentsToWindow(r.roundedPointI nInnerNodeFrame()); 195 data.mousePosition = selectedFrame->view()->contentsToWindow(r.roundedPointI nInnerNodeFrame());
197 196
198 // Compute edit flags. 197 // Compute edit flags.
199 data.editFlags = WebContextMenuData::CanDoNone; 198 data.editFlags = WebContextMenuData::CanDoNone;
200 if (m_webView->focusedWebCoreFrame()->editor()->canUndo()) 199 if (m_webView->focusedWebCoreFrame()->editor()->canUndo())
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 data.dictionarySuggestions = suggestions; 318 data.dictionarySuggestions = suggestions;
320 } else if (m_webView->spellCheckClient()) { 319 } else if (m_webView->spellCheckClient()) {
321 int misspelledOffset, misspelledLength; 320 int misspelledOffset, misspelledLength;
322 m_webView->spellCheckClient()->spellCheck(data.misspelledWord, m isspelledOffset, misspelledLength, &data.dictionarySuggestions); 321 m_webView->spellCheckClient()->spellCheck(data.misspelledWord, m isspelledOffset, misspelledLength, &data.dictionarySuggestions);
323 } 322 }
324 } else { 323 } else {
325 data.isSpellCheckingEnabled = 324 data.isSpellCheckingEnabled =
326 m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellChe ckingEnabled(); 325 m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellChe ckingEnabled();
327 // Spellchecking might be enabled for the field, but could be disabl ed on the node. 326 // Spellchecking might be enabled for the field, but could be disabl ed on the node.
328 if (m_webView->focusedWebCoreFrame()->editor()->isSpellCheckingEnabl edInFocusedNode()) { 327 if (m_webView->focusedWebCoreFrame()->editor()->isSpellCheckingEnabl edInFocusedNode()) {
329 data.misspelledWord = selectMisspelledWord(defaultMenu, selected Frame); 328 data.misspelledWord = selectMisspelledWord(defaultMenu.get(), se lectedFrame);
330 if (m_webView->spellCheckClient()) { 329 if (m_webView->spellCheckClient()) {
331 int misspelledOffset, misspelledLength; 330 int misspelledOffset, misspelledLength;
332 m_webView->spellCheckClient()->spellCheck( 331 m_webView->spellCheckClient()->spellCheck(
333 data.misspelledWord, misspelledOffset, misspelledLength, 332 data.misspelledWord, misspelledOffset, misspelledLength,
334 &data.dictionarySuggestions); 333 &data.dictionarySuggestions);
335 if (!misspelledLength) 334 if (!misspelledLength)
336 data.misspelledWord.reset(); 335 data.misspelledWord.reset();
337 } 336 }
338 } 337 }
339 } 338 }
(...skipping 17 matching lines...) Expand all
357 356
358 // Now retrieve the security info. 357 // Now retrieve the security info.
359 DocumentLoader* dl = selectedFrame->loader()->documentLoader(); 358 DocumentLoader* dl = selectedFrame->loader()->documentLoader();
360 WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); 359 WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl);
361 if (ds) 360 if (ds)
362 data.securityInfo = ds->response().securityInfo(); 361 data.securityInfo = ds->response().securityInfo();
363 362
364 data.referrerPolicy = static_cast<WebReferrerPolicy>(selectedFrame->document ()->referrerPolicy()); 363 data.referrerPolicy = static_cast<WebReferrerPolicy>(selectedFrame->document ()->referrerPolicy());
365 364
366 // Filter out custom menu elements and add them into the data. 365 // Filter out custom menu elements and add them into the data.
367 populateCustomMenuItems(defaultMenu, &data); 366 populateCustomMenuItems(defaultMenu.get(), &data);
368 367
369 data.node = r.innerNonSharedNode(); 368 data.node = r.innerNonSharedNode();
370 369
371 WebFrame* selected_web_frame = WebFrameImpl::fromFrame(selectedFrame); 370 WebFrame* selected_web_frame = WebFrameImpl::fromFrame(selectedFrame);
372 if (m_webView->client()) 371 if (m_webView->client())
373 m_webView->client()->showContextMenu(selected_web_frame, data); 372 m_webView->client()->showContextMenu(selected_web_frame, data);
374 373
375 return 0; 374 return defaultMenu;
376 } 375 }
377 376
378 static void populateSubMenuItems(PlatformMenuDescription inputMenu, WebVector<We bMenuItemInfo>& subMenuItems) 377 static void populateSubMenuItems(const Vector<ContextMenuItem>& inputMenu, WebVe ctor<WebMenuItemInfo>& subMenuItems)
379 { 378 {
380 Vector<WebMenuItemInfo> subItems; 379 Vector<WebMenuItemInfo> subItems;
381 for (size_t i = 0; i < inputMenu->size(); ++i) { 380 for (size_t i = 0; i < inputMenu.size(); ++i) {
382 const ContextMenuItem* inputItem = &inputMenu->at(i); 381 const ContextMenuItem* inputItem = &inputMenu.at(i);
383 if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->act ion() > ContextMenuItemLastCustomTag) 382 if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->act ion() > ContextMenuItemLastCustomTag)
384 continue; 383 continue;
385 384
386 WebMenuItemInfo outputItem; 385 WebMenuItemInfo outputItem;
387 outputItem.label = inputItem->title(); 386 outputItem.label = inputItem->title();
388 outputItem.enabled = inputItem->enabled(); 387 outputItem.enabled = inputItem->enabled();
389 outputItem.checked = inputItem->checked(); 388 outputItem.checked = inputItem->checked();
390 outputItem.action = static_cast<unsigned>(inputItem->action() - ContextM enuItemBaseCustomTag); 389 outputItem.action = static_cast<unsigned>(inputItem->action() - ContextM enuItemBaseCustomTag);
391 switch (inputItem->type()) { 390 switch (inputItem->type()) {
392 case ActionType: 391 case ActionType:
393 outputItem.type = WebMenuItemInfo::Option; 392 outputItem.type = WebMenuItemInfo::Option;
394 break; 393 break;
395 case CheckableActionType: 394 case CheckableActionType:
396 outputItem.type = WebMenuItemInfo::CheckableOption; 395 outputItem.type = WebMenuItemInfo::CheckableOption;
397 break; 396 break;
398 case SeparatorType: 397 case SeparatorType:
399 outputItem.type = WebMenuItemInfo::Separator; 398 outputItem.type = WebMenuItemInfo::Separator;
400 break; 399 break;
401 case SubmenuType: 400 case SubmenuType:
402 outputItem.type = WebMenuItemInfo::SubMenu; 401 outputItem.type = WebMenuItemInfo::SubMenu;
403 populateSubMenuItems(inputItem->platformSubMenu(), outputItem.subMen uItems); 402 populateSubMenuItems(inputItem->subMenuItems(), outputItem.subMenuIt ems);
404 break; 403 break;
405 } 404 }
406 subItems.append(outputItem); 405 subItems.append(outputItem);
407 } 406 }
408 407
409 WebVector<WebMenuItemInfo> outputItems(subItems.size()); 408 WebVector<WebMenuItemInfo> outputItems(subItems.size());
410 for (size_t i = 0; i < subItems.size(); ++i) 409 for (size_t i = 0; i < subItems.size(); ++i)
411 outputItems[i] = subItems[i]; 410 outputItems[i] = subItems[i];
412 subMenuItems.swap(outputItems); 411 subMenuItems.swap(outputItems);
413 } 412 }
414 413
415 void ContextMenuClientImpl::populateCustomMenuItems(WebCore::ContextMenu* defaul tMenu, WebContextMenuData* data) 414 void ContextMenuClientImpl::populateCustomMenuItems(WebCore::ContextMenu* defaul tMenu, WebContextMenuData* data)
416 { 415 {
417 populateSubMenuItems(defaultMenu->platformDescription(), data->customItems); 416 populateSubMenuItems(defaultMenu->items(), data->customItems);
418 } 417 }
419 418
420 } // namespace WebKit 419 } // namespace WebKit
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/ContextMenuClientImpl.h ('k') | Source/WebKit/chromium/src/WebViewImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698