| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 static String SelectMisspellingAsync(LocalFrame* selected_frame, | 107 static String SelectMisspellingAsync(LocalFrame* selected_frame, |
| 108 String& description) { | 108 String& description) { |
| 109 VisibleSelection selection = | 109 VisibleSelection selection = |
| 110 selected_frame->Selection().ComputeVisibleSelectionInDOMTree(); | 110 selected_frame->Selection().ComputeVisibleSelectionInDOMTree(); |
| 111 if (selection.IsNone()) | 111 if (selection.IsNone()) |
| 112 return String(); | 112 return String(); |
| 113 | 113 |
| 114 // Caret and range selections always return valid normalized ranges. | 114 // Caret and range selections always return valid normalized ranges. |
| 115 Range* selection_range = CreateRange(selection.ToNormalizedEphemeralRange()); | 115 const EphemeralRange& selection_range = |
| 116 DocumentMarkerVector markers = | 116 selection.ToNormalizedEphemeralRange(); |
| 117 selected_frame->GetDocument()->Markers().MarkersInRange( | 117 |
| 118 EphemeralRange(selection_range), | 118 Node* found_marker_anchor_node = nullptr; |
| 119 DocumentMarker::MisspellingMarkers()); | 119 const DocumentMarker* found_marker = nullptr; |
| 120 if (markers.size() != 1) | 120 for (Node& node : selection_range.Nodes()) { |
| 121 const DocumentMarkerVector& markers_in_node = |
| 122 selected_frame->GetDocument()->Markers().MarkersFor( |
| 123 &node, DocumentMarker::MisspellingMarkers()); |
| 124 if (!markers_in_node.IsEmpty()) { |
| 125 found_marker_anchor_node = &node; |
| 126 found_marker = markers_in_node[0]; |
| 127 break; |
| 128 } |
| 129 } |
| 130 |
| 131 if (!found_marker) |
| 121 return String(); | 132 return String(); |
| 122 description = markers[0]->Description(); | |
| 123 | 133 |
| 124 // Cloning a range fails only for invalid ranges. | 134 description = found_marker->Description(); |
| 125 Range* marker_range = selection_range->cloneRange(); | 135 |
| 126 marker_range->setStart(marker_range->startContainer(), | 136 Range* marker_range = |
| 127 markers[0]->StartOffset()); | 137 Range::Create(*selected_frame->GetDocument(), found_marker_anchor_node, |
| 128 marker_range->setEnd(marker_range->endContainer(), markers[0]->EndOffset()); | 138 found_marker->StartOffset(), found_marker_anchor_node, |
| 139 found_marker->EndOffset()); |
| 129 | 140 |
| 130 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | 141 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| 131 selection_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 142 CreateRange(selection_range) |
| 143 ->GetText() |
| 144 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 132 return String(); | 145 return String(); |
| 133 | 146 |
| 134 return marker_range->GetText(); | 147 return marker_range->GetText(); |
| 135 } | 148 } |
| 136 | 149 |
| 137 // static | 150 // static |
| 138 int ContextMenuClientImpl::ComputeEditFlags(Document& selected_document, | 151 int ContextMenuClientImpl::ComputeEditFlags(Document& selected_document, |
| 139 Editor& editor) { | 152 Editor& editor) { |
| 140 int edit_flags = WebContextMenuData::kCanDoNone; | 153 int edit_flags = WebContextMenuData::kCanDoNone; |
| 141 if (!selected_document.IsHTMLDocument() && | 154 if (!selected_document.IsHTMLDocument() && |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 sub_menu_items.Swap(output_items); | 479 sub_menu_items.Swap(output_items); |
| 467 } | 480 } |
| 468 | 481 |
| 469 void ContextMenuClientImpl::PopulateCustomMenuItems( | 482 void ContextMenuClientImpl::PopulateCustomMenuItems( |
| 470 const ContextMenu* default_menu, | 483 const ContextMenu* default_menu, |
| 471 WebContextMenuData* data) { | 484 WebContextMenuData* data) { |
| 472 PopulateSubMenuItems(default_menu->Items(), data->custom_items); | 485 PopulateSubMenuItems(default_menu->Items(), data->custom_items); |
| 473 } | 486 } |
| 474 | 487 |
| 475 } // namespace blink | 488 } // namespace blink |
| OLD | NEW |