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