Chromium Code Reviews| 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 // We don't currently support the case where a misspelling spans multiple |
| 119 DocumentMarker::MisspellingMarkers()); | 119 // nodes, so we assume this is the same as selection_end_container |
| 120 if (markers.size() != 1) | 120 Node* selection_start_container = |
|
Xiaocheng
2017/05/10 23:55:15
Same here, we should return if |selection_start_co
| |
| 121 selection_range.StartPosition().ComputeContainerNode(); | |
| 122 const unsigned selection_start_offset = | |
| 123 selection_range.StartPosition().ComputeOffsetInContainerNode(); | |
| 124 const unsigned selection_end_offset = | |
| 125 selection_range.EndPosition().ComputeOffsetInContainerNode(); | |
| 126 | |
| 127 const DocumentMarker* found_marker = nullptr; | |
| 128 const DocumentMarkerVector& markers_in_node = | |
| 129 selected_frame->GetDocument()->Markers().MarkersFor( | |
| 130 selection_start_container, DocumentMarker::MisspellingMarkers()); | |
| 131 for (DocumentMarker* marker : markers_in_node) { | |
| 132 if (marker->EndOffset() <= selection_start_offset) | |
| 133 continue; | |
| 134 if (marker->StartOffset() >= selection_end_offset) | |
| 135 continue; | |
| 136 | |
| 137 found_marker = marker; | |
| 138 break; | |
| 139 } | |
| 140 | |
| 141 if (!found_marker) | |
| 121 return String(); | 142 return String(); |
| 122 description = markers[0]->Description(); | |
| 123 | 143 |
| 124 // Cloning a range fails only for invalid ranges. | 144 description = found_marker->Description(); |
| 125 Range* marker_range = selection_range->cloneRange(); | 145 |
| 126 marker_range->setStart(marker_range->startContainer(), | 146 Range* marker_range = |
| 127 markers[0]->StartOffset()); | 147 Range::Create(*selected_frame->GetDocument(), selection_start_container, |
| 128 marker_range->setEnd(marker_range->endContainer(), markers[0]->EndOffset()); | 148 found_marker->StartOffset(), selection_start_container, |
| 149 found_marker->EndOffset()); | |
| 129 | 150 |
| 130 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | 151 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| 131 selection_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 152 CreateRange(selection_range) |
| 153 ->GetText() | |
| 154 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | |
| 132 return String(); | 155 return String(); |
| 133 | 156 |
| 134 return marker_range->GetText(); | 157 return marker_range->GetText(); |
| 135 } | 158 } |
| 136 | 159 |
| 137 // static | 160 // static |
| 138 int ContextMenuClientImpl::ComputeEditFlags(Document& selected_document, | 161 int ContextMenuClientImpl::ComputeEditFlags(Document& selected_document, |
| 139 Editor& editor) { | 162 Editor& editor) { |
| 140 int edit_flags = WebContextMenuData::kCanDoNone; | 163 int edit_flags = WebContextMenuData::kCanDoNone; |
| 141 if (!selected_document.IsHTMLDocument() && | 164 if (!selected_document.IsHTMLDocument() && |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 sub_menu_items.Swap(output_items); | 489 sub_menu_items.Swap(output_items); |
| 467 } | 490 } |
| 468 | 491 |
| 469 void ContextMenuClientImpl::PopulateCustomMenuItems( | 492 void ContextMenuClientImpl::PopulateCustomMenuItems( |
| 470 const ContextMenu* default_menu, | 493 const ContextMenu* default_menu, |
| 471 WebContextMenuData* data) { | 494 WebContextMenuData* data) { |
| 472 PopulateSubMenuItems(default_menu->Items(), data->custom_items); | 495 PopulateSubMenuItems(default_menu->Items(), data->custom_items); |
| 473 } | 496 } |
| 474 | 497 |
| 475 } // namespace blink | 498 } // namespace blink |
| OLD | NEW |