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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 } | 102 } |
| 103 return WebURL(); | 103 return WebURL(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 static bool IsWhiteSpaceOrPunctuation(UChar c) { | 106 static bool IsWhiteSpaceOrPunctuation(UChar c) { |
| 107 return IsSpaceOrNewline(c) || WTF::Unicode::IsPunct(c); | 107 return IsSpaceOrNewline(c) || WTF::Unicode::IsPunct(c); |
| 108 } | 108 } |
| 109 | 109 |
| 110 static String SelectMisspellingAsync(LocalFrame* selected_frame, | 110 static String SelectMisspellingAsync(LocalFrame* selected_frame, |
| 111 String& description) { | 111 String& description) { |
| 112 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = | |
| 113 selected_frame->GetSpellChecker().GetSpellCheckMarkerUnderSelection(); | |
| 114 if (!node_and_marker) | |
|
yosin_UTC9
2017/07/20 01:19:07
How about using |pair.first| which is Node*, as no
rlanday
2017/07/21 00:16:04
I put up a separate CL for this: https://chromium-
| |
| 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, | |
|
yosin_UTC9
2017/07/20 01:19:07
Could you avoid to use temporary Range make this c
| |
| 123 marker->StartOffset(), marker_node, marker->EndOffset()); | |
| 124 | |
| 112 VisibleSelection selection = | 125 VisibleSelection selection = |
| 113 selected_frame->Selection().ComputeVisibleSelectionInDOMTree(); | 126 selected_frame->Selection().ComputeVisibleSelectionInDOMTree(); |
| 114 if (selection.IsNone()) | 127 // Caret and range selections (one of which we must have since we found a |
| 115 return String(); | 128 // marker) always return valid normalized ranges. |
| 116 | |
| 117 // Caret and range selections always return valid normalized ranges. | |
| 118 const EphemeralRange& selection_range = | 129 const EphemeralRange& selection_range = |
| 119 selection.ToNormalizedEphemeralRange(); | 130 selection.ToNormalizedEphemeralRange(); |
| 120 | 131 |
| 121 Node* const selection_start_container = | |
| 122 selection_range.StartPosition().ComputeContainerNode(); | |
| 123 Node* const selection_end_container = | |
| 124 selection_range.EndPosition().ComputeContainerNode(); | |
| 125 | |
| 126 // We don't currently support the case where a misspelling spans multiple | |
| 127 // nodes | |
| 128 if (selection_start_container != selection_end_container) | |
| 129 return String(); | |
| 130 | |
| 131 const unsigned selection_start_offset = | |
| 132 selection_range.StartPosition().ComputeOffsetInContainerNode(); | |
| 133 const unsigned selection_end_offset = | |
| 134 selection_range.EndPosition().ComputeOffsetInContainerNode(); | |
| 135 | |
| 136 const DocumentMarkerVector& markers_in_node = | |
| 137 selected_frame->GetDocument()->Markers().MarkersFor( | |
| 138 selection_start_container, DocumentMarker::MisspellingMarkers()); | |
| 139 | |
| 140 const auto marker_it = | |
| 141 std::find_if(markers_in_node.begin(), markers_in_node.end(), | |
| 142 [=](const DocumentMarker* marker) { | |
| 143 return marker->StartOffset() < selection_end_offset && | |
| 144 marker->EndOffset() > selection_start_offset; | |
| 145 }); | |
| 146 if (marker_it == markers_in_node.end()) | |
| 147 return String(); | |
| 148 | |
| 149 const SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); | |
| 150 description = found_marker->Description(); | |
| 151 | |
| 152 Range* const marker_range = | |
| 153 Range::Create(*selected_frame->GetDocument(), selection_start_container, | |
| 154 found_marker->StartOffset(), selection_start_container, | |
| 155 found_marker->EndOffset()); | |
| 156 | |
| 157 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | 132 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| 158 CreateRange(selection_range) | 133 CreateRange(selection_range) |
| 159 ->GetText() | 134 ->GetText() |
| 160 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 135 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 161 return String(); | 136 return String(); |
| 162 | 137 |
| 163 return marker_range->GetText(); | 138 return marker_range->GetText(); |
| 164 } | 139 } |
| 165 | 140 |
| 166 // static | 141 // static |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 output_items[i] = sub_items[i]; | 542 output_items[i] = sub_items[i]; |
| 568 sub_menu_items.Swap(output_items); | 543 sub_menu_items.Swap(output_items); |
| 569 } | 544 } |
| 570 | 545 |
| 571 void ContextMenuClient::PopulateCustomMenuItems(const ContextMenu* default_menu, | 546 void ContextMenuClient::PopulateCustomMenuItems(const ContextMenu* default_menu, |
| 572 WebContextMenuData* data) { | 547 WebContextMenuData* data) { |
| 573 PopulateSubMenuItems(default_menu->Items(), data->custom_items); | 548 PopulateSubMenuItems(default_menu->Items(), data->custom_items); |
| 574 } | 549 } |
| 575 | 550 |
| 576 } // namespace blink | 551 } // namespace blink |
| OLD | NEW |