| 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 } | 99 } |
| 100 } | 100 } |
| 101 return WebURL(); | 101 return WebURL(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 static bool IsWhiteSpaceOrPunctuation(UChar c) | 104 static bool IsWhiteSpaceOrPunctuation(UChar c) |
| 105 { | 105 { |
| 106 return isSpaceOrNewline(c) || WTF::Unicode::isPunct(c); | 106 return isSpaceOrNewline(c) || WTF::Unicode::isPunct(c); |
| 107 } | 107 } |
| 108 | 108 |
| 109 static String selectMisspellingAsync(LocalFrame* selectedFrame, String& descript
ion, uint32_t& hash) | 109 static String selectMisspellingAsync(LocalFrame* selectedFrame, String& descript
ion) |
| 110 { | 110 { |
| 111 VisibleSelection selection = selectedFrame->selection().selection(); | 111 VisibleSelection selection = selectedFrame->selection().selection(); |
| 112 if (selection.isNone()) | 112 if (selection.isNone()) |
| 113 return String(); | 113 return String(); |
| 114 | 114 |
| 115 // Caret and range selections always return valid normalized ranges. | 115 // Caret and range selections always return valid normalized ranges. |
| 116 Range* selectionRange = createRange(selection.toNormalizedEphemeralRange()); | 116 Range* selectionRange = createRange(selection.toNormalizedEphemeralRange()); |
| 117 DocumentMarkerVector markers = selectedFrame->document()->markers().markersI
nRange(EphemeralRange(selectionRange), DocumentMarker::MisspellingMarkers()); | 117 DocumentMarkerVector markers = selectedFrame->document()->markers().markersI
nRange(EphemeralRange(selectionRange), DocumentMarker::MisspellingMarkers()); |
| 118 if (markers.size() != 1) | 118 if (markers.size() != 1) |
| 119 return String(); | 119 return String(); |
| 120 description = markers[0]->description(); | 120 description = markers[0]->description(); |
| 121 hash = markers[0]->hash(); | |
| 122 | 121 |
| 123 // Cloning a range fails only for invalid ranges. | 122 // Cloning a range fails only for invalid ranges. |
| 124 Range* markerRange = selectionRange->cloneRange(); | 123 Range* markerRange = selectionRange->cloneRange(); |
| 125 markerRange->setStart(markerRange->startContainer(), markers[0]->startOffset
()); | 124 markerRange->setStart(markerRange->startContainer(), markers[0]->startOffset
()); |
| 126 markerRange->setEnd(markerRange->endContainer(), markers[0]->endOffset()); | 125 markerRange->setEnd(markerRange->endContainer(), markers[0]->endOffset()); |
| 127 | 126 |
| 128 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec
tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 127 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec
tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 129 return String(); | 128 return String(); |
| 130 | 129 |
| 131 return markerRange->text(); | 130 return markerRange->text(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 296 } |
| 298 | 297 |
| 299 if (r.isContentEditable()) { | 298 if (r.isContentEditable()) { |
| 300 data.isEditable = true; | 299 data.isEditable = true; |
| 301 | 300 |
| 302 // Spellchecker adds spelling markers to misspelled words and attaches | 301 // Spellchecker adds spelling markers to misspelled words and attaches |
| 303 // suggestions to these markers in the background. Therefore, when a | 302 // suggestions to these markers in the background. Therefore, when a |
| 304 // user right-clicks a mouse on a word, Chrome just needs to find a | 303 // user right-clicks a mouse on a word, Chrome just needs to find a |
| 305 // spelling marker on the word instead of spellchecking it. | 304 // spelling marker on the word instead of spellchecking it. |
| 306 String description; | 305 String description; |
| 307 uint32_t hash = 0; | 306 data.misspelledWord = selectMisspellingAsync(selectedFrame, description)
; |
| 308 data.misspelledWord = selectMisspellingAsync(selectedFrame, description,
hash); | |
| 309 data.misspellingHash = hash; | |
| 310 if (description.length()) { | 307 if (description.length()) { |
| 311 Vector<String> suggestions; | 308 Vector<String> suggestions; |
| 312 description.split('\n', suggestions); | 309 description.split('\n', suggestions); |
| 313 data.dictionarySuggestions = suggestions; | 310 data.dictionarySuggestions = suggestions; |
| 314 } else if (m_webView->spellCheckClient()) { | 311 } else if (m_webView->spellCheckClient()) { |
| 315 int misspelledOffset, misspelledLength; | 312 int misspelledOffset, misspelledLength; |
| 316 m_webView->spellCheckClient()->spellCheck(data.misspelledWord, missp
elledOffset, misspelledLength, &data.dictionarySuggestions); | 313 m_webView->spellCheckClient()->spellCheck(data.misspelledWord, missp
elledOffset, misspelledLength, &data.dictionarySuggestions); |
| 317 } | 314 } |
| 318 | 315 |
| 319 HTMLFormElement* form = selectedFrame->selection().currentForm(); | 316 HTMLFormElement* form = selectedFrame->selection().currentForm(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 outputItems[i] = subItems[i]; | 418 outputItems[i] = subItems[i]; |
| 422 subMenuItems.swap(outputItems); | 419 subMenuItems.swap(outputItems); |
| 423 } | 420 } |
| 424 | 421 |
| 425 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe
nu, WebContextMenuData* data) | 422 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe
nu, WebContextMenuData* data) |
| 426 { | 423 { |
| 427 populateSubMenuItems(defaultMenu->items(), data->customItems); | 424 populateSubMenuItems(defaultMenu->items(), data->customItems); |
| 428 } | 425 } |
| 429 | 426 |
| 430 } // namespace blink | 427 } // namespace blink |
| OLD | NEW |