Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: third_party/WebKit/Source/web/ContextMenuClientImpl.cpp

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Fix WebFrameTest.cpp Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 =
119 DocumentMarker::MisspellingMarkers()); 119 selection_range.StartPosition().ComputeContainerNode();
120 if (markers.size() != 1) 120 const unsigned selection_start_offset =
121 selection_range.StartPosition().ComputeOffsetInContainerNode();
122 Node* selection_end_container =
123 selection_range.EndPosition().ComputeContainerNode();
124 const unsigned selection_end_offset =
125 selection_range.EndPosition().ComputeOffsetInContainerNode();
126
127 Node* found_marker_anchor_node = nullptr;
128 const DocumentMarker* found_marker = nullptr;
129 for (Node& node : selection_range.Nodes()) {
Xiaocheng 2017/05/10 22:54:22 Same here. No need to iterate over all nodes.
130 if (found_marker)
131 break;
132
133 const DocumentMarkerVector& markers_in_node =
134 selected_frame->GetDocument()->Markers().MarkersFor(
135 &node, DocumentMarker::MisspellingMarkers());
136 for (DocumentMarker* marker : markers_in_node) {
137 if (&node == selection_start_container &&
138 marker->EndOffset() <= selection_start_offset)
139 continue;
140 if (&node == selection_end_container &&
141 marker->StartOffset() >= selection_end_offset)
142 continue;
143
144 found_marker_anchor_node = &node;
145 found_marker = markers_in_node[0];
146 break;
147 }
148 }
149
150 if (!found_marker)
121 return String(); 151 return String();
122 description = markers[0]->Description();
123 152
124 // Cloning a range fails only for invalid ranges. 153 description = found_marker->Description();
125 Range* marker_range = selection_range->cloneRange(); 154
Xiaocheng 2017/05/10 22:54:22 Same here. The existing code doesn't work when the
126 marker_range->setStart(marker_range->startContainer(), 155 Range* marker_range =
127 markers[0]->StartOffset()); 156 Range::Create(*selected_frame->GetDocument(), found_marker_anchor_node,
128 marker_range->setEnd(marker_range->endContainer(), markers[0]->EndOffset()); 157 found_marker->StartOffset(), found_marker_anchor_node,
158 found_marker->EndOffset());
129 159
130 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != 160 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) !=
131 selection_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) 161 CreateRange(selection_range)
162 ->GetText()
163 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation))
132 return String(); 164 return String();
133 165
134 return marker_range->GetText(); 166 return marker_range->GetText();
135 } 167 }
136 168
137 // static 169 // static
138 int ContextMenuClientImpl::ComputeEditFlags(Document& selected_document, 170 int ContextMenuClientImpl::ComputeEditFlags(Document& selected_document,
139 Editor& editor) { 171 Editor& editor) {
140 int edit_flags = WebContextMenuData::kCanDoNone; 172 int edit_flags = WebContextMenuData::kCanDoNone;
141 if (!selected_document.IsHTMLDocument() && 173 if (!selected_document.IsHTMLDocument() &&
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 sub_menu_items.Swap(output_items); 498 sub_menu_items.Swap(output_items);
467 } 499 }
468 500
469 void ContextMenuClientImpl::PopulateCustomMenuItems( 501 void ContextMenuClientImpl::PopulateCustomMenuItems(
470 const ContextMenu* default_menu, 502 const ContextMenu* default_menu,
471 WebContextMenuData* data) { 503 WebContextMenuData* data) {
472 PopulateSubMenuItems(default_menu->Items(), data->custom_items); 504 PopulateSubMenuItems(default_menu->Items(), data->custom_items);
473 } 505 }
474 506
475 } // namespace blink 507 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698