| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 WebDataSource* ds = WebDataSourceImpl::FromDocumentLoader(dl); | 96 WebDataSource* ds = WebDataSourceImpl::FromDocumentLoader(dl); |
| 97 if (ds) { | 97 if (ds) { |
| 98 return ds->HasUnreachableURL() ? ds->UnreachableURL() | 98 return ds->HasUnreachableURL() ? ds->UnreachableURL() |
| 99 : ds->GetRequest().Url(); | 99 : ds->GetRequest().Url(); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 return WebURL(); | 103 return WebURL(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 static bool IsWhiteSpaceOrPunctuation(UChar c) { | |
| 107 return IsSpaceOrNewline(c) || WTF::Unicode::IsPunct(c); | |
| 108 } | |
| 109 | |
| 110 static String SelectMisspellingAsync(LocalFrame* selected_frame, | |
| 111 String& description) { | |
| 112 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = | |
| 113 selected_frame->GetSpellChecker().GetSpellCheckMarkerUnderSelection(); | |
| 114 if (!node_and_marker) | |
| 115 return String(); | |
| 116 | |
| 117 Node* const marker_node = node_and_marker.value().first; | |
| 118 const SpellCheckMarker* const marker = node_and_marker.value().second; | |
| 119 description = marker->Description(); | |
| 120 | |
| 121 Range* const marker_range = | |
| 122 Range::Create(*selected_frame->GetDocument(), marker_node, | |
| 123 marker->StartOffset(), marker_node, marker->EndOffset()); | |
| 124 | |
| 125 VisibleSelection selection = | |
| 126 selected_frame->Selection().ComputeVisibleSelectionInDOMTree(); | |
| 127 // Caret and range selections (one of which we must have since we found a | |
| 128 // marker) always return valid normalized ranges. | |
| 129 const EphemeralRange& selection_range = | |
| 130 selection.ToNormalizedEphemeralRange(); | |
| 131 | |
| 132 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | |
| 133 CreateRange(selection_range) | |
| 134 ->GetText() | |
| 135 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | |
| 136 return String(); | |
| 137 | |
| 138 return marker_range->GetText(); | |
| 139 } | |
| 140 | |
| 141 // static | 106 // static |
| 142 int ContextMenuClient::ComputeEditFlags(Document& selected_document, | 107 int ContextMenuClient::ComputeEditFlags(Document& selected_document, |
| 143 Editor& editor) { | 108 Editor& editor) { |
| 144 int edit_flags = WebContextMenuData::kCanDoNone; | 109 int edit_flags = WebContextMenuData::kCanDoNone; |
| 145 if (!selected_document.IsHTMLDocument() && | 110 if (!selected_document.IsHTMLDocument() && |
| 146 !selected_document.IsXHTMLDocument()) | 111 !selected_document.IsXHTMLDocument()) |
| 147 return edit_flags; | 112 return edit_flags; |
| 148 | 113 |
| 149 edit_flags |= WebContextMenuData::kCanTranslate; | 114 edit_flags |= WebContextMenuData::kCanTranslate; |
| 150 if (editor.CanUndo()) | 115 if (editor.CanUndo()) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } | 354 } |
| 390 | 355 |
| 391 if (r.IsContentEditable()) { | 356 if (r.IsContentEditable()) { |
| 392 data.is_editable = true; | 357 data.is_editable = true; |
| 393 | 358 |
| 394 // Spellchecker adds spelling markers to misspelled words and attaches | 359 // Spellchecker adds spelling markers to misspelled words and attaches |
| 395 // suggestions to these markers in the background. Therefore, when a | 360 // suggestions to these markers in the background. Therefore, when a |
| 396 // user right-clicks a mouse on a word, Chrome just needs to find a | 361 // user right-clicks a mouse on a word, Chrome just needs to find a |
| 397 // spelling marker on the word instead of spellchecking it. | 362 // spelling marker on the word instead of spellchecking it. |
| 398 String description; | 363 String description; |
| 399 data.misspelled_word = SelectMisspellingAsync(selected_frame, description); | 364 data.misspelled_word = |
| 365 selected_frame->GetSpellChecker().SelectMisspellingAsync(description); |
| 400 if (description.length()) { | 366 if (description.length()) { |
| 401 Vector<String> suggestions; | 367 Vector<String> suggestions; |
| 402 description.Split('\n', suggestions); | 368 description.Split('\n', suggestions); |
| 403 data.dictionary_suggestions = suggestions; | 369 data.dictionary_suggestions = suggestions; |
| 404 } else if (selected_web_frame->TextCheckClient()) { | 370 } else if (selected_web_frame->TextCheckClient()) { |
| 405 int misspelled_offset, misspelled_length; | 371 int misspelled_offset, misspelled_length; |
| 406 selected_web_frame->TextCheckClient()->CheckSpelling( | 372 selected_web_frame->TextCheckClient()->CheckSpelling( |
| 407 data.misspelled_word, misspelled_offset, misspelled_length, | 373 data.misspelled_word, misspelled_offset, misspelled_length, |
| 408 &data.dictionary_suggestions); | 374 &data.dictionary_suggestions); |
| 409 } | 375 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 output_items[i] = sub_items[i]; | 508 output_items[i] = sub_items[i]; |
| 543 sub_menu_items.Swap(output_items); | 509 sub_menu_items.Swap(output_items); |
| 544 } | 510 } |
| 545 | 511 |
| 546 void ContextMenuClient::PopulateCustomMenuItems(const ContextMenu* default_menu, | 512 void ContextMenuClient::PopulateCustomMenuItems(const ContextMenu* default_menu, |
| 547 WebContextMenuData* data) { | 513 WebContextMenuData* data) { |
| 548 PopulateSubMenuItems(default_menu->Items(), data->custom_items); | 514 PopulateSubMenuItems(default_menu->Items(), data->custom_items); |
| 549 } | 515 } |
| 550 | 516 |
| 551 } // namespace blink | 517 } // namespace blink |
| OLD | NEW |