| OLD | NEW |
| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 static bool isASingleWord(const String& text) | 99 static bool isASingleWord(const String& text) |
| 100 { | 100 { |
| 101 TextBreakIterator* it = wordBreakIterator(text.characters(), text.length()); | 101 TextBreakIterator* it = wordBreakIterator(text.characters(), text.length()); |
| 102 return it && textBreakNext(it) == static_cast<int>(text.length()); | 102 return it && textBreakNext(it) == static_cast<int>(text.length()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Helper function to get misspelled word on which context menu | 105 // Helper function to get misspelled word on which context menu |
| 106 // is to be invoked. This function also sets the word on which context menu | 106 // is to be invoked. This function also sets the word on which context menu |
| 107 // has been invoked to be the selected word, as required. This function changes | 107 // has been invoked to be the selected word, as required. This function changes |
| 108 // the selection only when there were no selected characters on OS X. | 108 // the selection only when there were no selected characters on OS X. |
| 109 static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* select
edFrame) | 109 static String selectMisspelledWord(Frame* selectedFrame) |
| 110 { | 110 { |
| 111 // First select from selectedText to check for multiple word selection. | 111 // First select from selectedText to check for multiple word selection. |
| 112 String misspelledWord = selectedFrame->editor()->selectedText().stripWhiteSp
ace(); | 112 String misspelledWord = selectedFrame->editor()->selectedText().stripWhiteSp
ace(); |
| 113 | 113 |
| 114 // If some texts were already selected, we don't change the selection. | 114 // If some texts were already selected, we don't change the selection. |
| 115 if (!misspelledWord.isEmpty()) { | 115 if (!misspelledWord.isEmpty()) { |
| 116 // Don't provide suggestions for multiple words. | 116 // Don't provide suggestions for multiple words. |
| 117 if (!isASingleWord(misspelledWord)) | 117 if (!isASingleWord(misspelledWord)) |
| 118 return String(); | 118 return String(); |
| 119 return misspelledWord; | 119 return misspelledWord; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 PassOwnPtr<WebCore::ContextMenu> ContextMenuClientImpl::customizeMenu(PassOwnPtr
<WebCore::ContextMenu> defaultMenu) | 181 void ContextMenuClientImpl::showContextMenu(const WebCore::ContextMenu* defaultM
enu) |
| 182 { | 182 { |
| 183 // 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 |
| 184 // 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 |
| 185 // response to user input (Mouse event WM_RBUTTONDOWN, | 185 // response to user input (Mouse event WM_RBUTTONDOWN, |
| 186 // 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 |
| 187 // 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. |
| 188 if (!m_webView->contextMenuAllowed()) | 188 if (!m_webView->contextMenuAllowed()) |
| 189 return defaultMenu; | 189 return; |
| 190 | 190 |
| 191 HitTestResult r = m_webView->page()->contextMenuController()->hitTestResult(
); | 191 HitTestResult r = m_webView->page()->contextMenuController()->hitTestResult(
); |
| 192 Frame* selectedFrame = r.innerNodeFrame(); | 192 Frame* selectedFrame = r.innerNodeFrame(); |
| 193 | 193 |
| 194 WebContextMenuData data; | 194 WebContextMenuData data; |
| 195 data.mousePosition = selectedFrame->view()->contentsToWindow(r.roundedPointI
nInnerNodeFrame()); | 195 data.mousePosition = selectedFrame->view()->contentsToWindow(r.roundedPointI
nInnerNodeFrame()); |
| 196 | 196 |
| 197 // Compute edit flags. | 197 // Compute edit flags. |
| 198 data.editFlags = WebContextMenuData::CanDoNone; | 198 data.editFlags = WebContextMenuData::CanDoNone; |
| 199 if (m_webView->focusedWebCoreFrame()->editor()->canUndo()) | 199 if (m_webView->focusedWebCoreFrame()->editor()->canUndo()) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 data.dictionarySuggestions = suggestions; | 319 data.dictionarySuggestions = suggestions; |
| 320 } else if (m_webView->spellCheckClient()) { | 320 } else if (m_webView->spellCheckClient()) { |
| 321 int misspelledOffset, misspelledLength; | 321 int misspelledOffset, misspelledLength; |
| 322 m_webView->spellCheckClient()->spellCheck(data.misspelledWord, m
isspelledOffset, misspelledLength, &data.dictionarySuggestions); | 322 m_webView->spellCheckClient()->spellCheck(data.misspelledWord, m
isspelledOffset, misspelledLength, &data.dictionarySuggestions); |
| 323 } | 323 } |
| 324 } else { | 324 } else { |
| 325 data.isSpellCheckingEnabled = | 325 data.isSpellCheckingEnabled = |
| 326 m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellChe
ckingEnabled(); | 326 m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellChe
ckingEnabled(); |
| 327 // Spellchecking might be enabled for the field, but could be disabl
ed on the node. | 327 // Spellchecking might be enabled for the field, but could be disabl
ed on the node. |
| 328 if (m_webView->focusedWebCoreFrame()->editor()->isSpellCheckingEnabl
edInFocusedNode()) { | 328 if (m_webView->focusedWebCoreFrame()->editor()->isSpellCheckingEnabl
edInFocusedNode()) { |
| 329 data.misspelledWord = selectMisspelledWord(defaultMenu.get(), se
lectedFrame); | 329 data.misspelledWord = selectMisspelledWord(selectedFrame); |
| 330 if (m_webView->spellCheckClient()) { | 330 if (m_webView->spellCheckClient()) { |
| 331 int misspelledOffset, misspelledLength; | 331 int misspelledOffset, misspelledLength; |
| 332 m_webView->spellCheckClient()->spellCheck( | 332 m_webView->spellCheckClient()->spellCheck( |
| 333 data.misspelledWord, misspelledOffset, misspelledLength, | 333 data.misspelledWord, misspelledOffset, misspelledLength, |
| 334 &data.dictionarySuggestions); | 334 &data.dictionarySuggestions); |
| 335 if (!misspelledLength) | 335 if (!misspelledLength) |
| 336 data.misspelledWord.reset(); | 336 data.misspelledWord.reset(); |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 } | 339 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 357 | 357 |
| 358 // Now retrieve the security info. | 358 // Now retrieve the security info. |
| 359 DocumentLoader* dl = selectedFrame->loader()->documentLoader(); | 359 DocumentLoader* dl = selectedFrame->loader()->documentLoader(); |
| 360 WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); | 360 WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); |
| 361 if (ds) | 361 if (ds) |
| 362 data.securityInfo = ds->response().securityInfo(); | 362 data.securityInfo = ds->response().securityInfo(); |
| 363 | 363 |
| 364 data.referrerPolicy = static_cast<WebReferrerPolicy>(selectedFrame->document
()->referrerPolicy()); | 364 data.referrerPolicy = static_cast<WebReferrerPolicy>(selectedFrame->document
()->referrerPolicy()); |
| 365 | 365 |
| 366 // Filter out custom menu elements and add them into the data. | 366 // Filter out custom menu elements and add them into the data. |
| 367 populateCustomMenuItems(defaultMenu.get(), &data); | 367 populateCustomMenuItems(defaultMenu, &data); |
| 368 | 368 |
| 369 data.node = r.innerNonSharedNode(); | 369 data.node = r.innerNonSharedNode(); |
| 370 | 370 |
| 371 WebFrame* selected_web_frame = WebFrameImpl::fromFrame(selectedFrame); | 371 WebFrame* selected_web_frame = WebFrameImpl::fromFrame(selectedFrame); |
| 372 if (m_webView->client()) | 372 if (m_webView->client()) |
| 373 m_webView->client()->showContextMenu(selected_web_frame, data); | 373 m_webView->client()->showContextMenu(selected_web_frame, data); |
| 374 | |
| 375 return defaultMenu; | |
| 376 } | 374 } |
| 377 | 375 |
| 378 static void populateSubMenuItems(const Vector<ContextMenuItem>& inputMenu, WebVe
ctor<WebMenuItemInfo>& subMenuItems) | 376 static void populateSubMenuItems(const Vector<ContextMenuItem>& inputMenu, WebVe
ctor<WebMenuItemInfo>& subMenuItems) |
| 379 { | 377 { |
| 380 Vector<WebMenuItemInfo> subItems; | 378 Vector<WebMenuItemInfo> subItems; |
| 381 for (size_t i = 0; i < inputMenu.size(); ++i) { | 379 for (size_t i = 0; i < inputMenu.size(); ++i) { |
| 382 const ContextMenuItem* inputItem = &inputMenu.at(i); | 380 const ContextMenuItem* inputItem = &inputMenu.at(i); |
| 383 if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->act
ion() > ContextMenuItemLastCustomTag) | 381 if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->act
ion() > ContextMenuItemLastCustomTag) |
| 384 continue; | 382 continue; |
| 385 | 383 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 405 } | 403 } |
| 406 subItems.append(outputItem); | 404 subItems.append(outputItem); |
| 407 } | 405 } |
| 408 | 406 |
| 409 WebVector<WebMenuItemInfo> outputItems(subItems.size()); | 407 WebVector<WebMenuItemInfo> outputItems(subItems.size()); |
| 410 for (size_t i = 0; i < subItems.size(); ++i) | 408 for (size_t i = 0; i < subItems.size(); ++i) |
| 411 outputItems[i] = subItems[i]; | 409 outputItems[i] = subItems[i]; |
| 412 subMenuItems.swap(outputItems); | 410 subMenuItems.swap(outputItems); |
| 413 } | 411 } |
| 414 | 412 |
| 415 void ContextMenuClientImpl::populateCustomMenuItems(WebCore::ContextMenu* defaul
tMenu, WebContextMenuData* data) | 413 void ContextMenuClientImpl::populateCustomMenuItems(const WebCore::ContextMenu*
defaultMenu, WebContextMenuData* data) |
| 416 { | 414 { |
| 417 populateSubMenuItems(defaultMenu->items(), data->customItems); | 415 populateSubMenuItems(defaultMenu->items(), data->customItems); |
| 418 } | 416 } |
| 419 | 417 |
| 420 } // namespace WebKit | 418 } // namespace WebKit |
| OLD | NEW |