Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 continue; | 901 continue; |
| 902 | 902 |
| 903 return std::make_pair(&node, &ToSpellCheckMarker(*marker)); | 903 return std::make_pair(&node, &ToSpellCheckMarker(*marker)); |
| 904 } | 904 } |
| 905 } | 905 } |
| 906 | 906 |
| 907 // No marker found | 907 // No marker found |
| 908 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 908 return Optional<std::pair<Node*, SpellCheckMarker*>>(); |
| 909 } | 909 } |
| 910 | 910 |
| 911 String SpellChecker::SelectMisspellingAsync(String& description) { | 911 Optional<std::pair<String, String>> SpellChecker::SelectMisspellingAsync() { |
| 912 VisibleSelection selection = | 912 VisibleSelection selection = |
| 913 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); | 913 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); |
| 914 if (selection.IsNone()) | 914 if (selection.IsNone()) |
| 915 return String(); | 915 return Optional<std::pair<String, String>>(); |
|
yosin_UTC9
2017/07/20 01:00:54
I think we write |return {};|
Could you try this t
rlanday
2017/07/20 21:14:27
I am simplifying the implementation of this method
rlanday
2017/07/20 23:37:07
I've updated this CL to return {}
| |
| 916 | 916 |
| 917 // Caret and range selections always return valid normalized ranges. | 917 // Caret and range selections always return valid normalized ranges. |
| 918 const EphemeralRange& selection_range = | 918 const EphemeralRange& selection_range = |
| 919 selection.ToNormalizedEphemeralRange(); | 919 selection.ToNormalizedEphemeralRange(); |
| 920 | 920 |
| 921 Node* const selection_start_container = | 921 Node* const selection_start_container = |
| 922 selection_range.StartPosition().ComputeContainerNode(); | 922 selection_range.StartPosition().ComputeContainerNode(); |
| 923 Node* const selection_end_container = | 923 Node* const selection_end_container = |
| 924 selection_range.EndPosition().ComputeContainerNode(); | 924 selection_range.EndPosition().ComputeContainerNode(); |
| 925 | 925 |
| 926 // We don't currently support the case where a misspelling spans multiple | 926 // We don't currently support the case where a misspelling spans multiple |
| 927 // nodes. See crbug.com/720065 | 927 // nodes. See crbug.com/720065 |
| 928 if (selection_start_container != selection_end_container) | 928 if (selection_start_container != selection_end_container) |
| 929 return String(); | 929 return Optional<std::pair<String, String>>(); |
| 930 | 930 |
| 931 const unsigned selection_start_offset = | 931 const unsigned selection_start_offset = |
| 932 selection_range.StartPosition().ComputeOffsetInContainerNode(); | 932 selection_range.StartPosition().ComputeOffsetInContainerNode(); |
| 933 const unsigned selection_end_offset = | 933 const unsigned selection_end_offset = |
| 934 selection_range.EndPosition().ComputeOffsetInContainerNode(); | 934 selection_range.EndPosition().ComputeOffsetInContainerNode(); |
| 935 | 935 |
| 936 const DocumentMarkerVector& markers_in_node = | 936 const DocumentMarkerVector& markers_in_node = |
| 937 GetFrame().GetDocument()->Markers().MarkersFor( | 937 GetFrame().GetDocument()->Markers().MarkersFor( |
| 938 selection_start_container, DocumentMarker::MisspellingMarkers()); | 938 selection_start_container, DocumentMarker::MisspellingMarkers()); |
| 939 | 939 |
| 940 const auto marker_it = | 940 const auto marker_it = |
| 941 std::find_if(markers_in_node.begin(), markers_in_node.end(), | 941 std::find_if(markers_in_node.begin(), markers_in_node.end(), |
| 942 [=](const DocumentMarker* marker) { | 942 [=](const DocumentMarker* marker) { |
| 943 return marker->StartOffset() < selection_end_offset && | 943 return marker->StartOffset() < selection_end_offset && |
| 944 marker->EndOffset() > selection_start_offset; | 944 marker->EndOffset() > selection_start_offset; |
| 945 }); | 945 }); |
| 946 if (marker_it == markers_in_node.end()) | 946 if (marker_it == markers_in_node.end()) |
| 947 return String(); | 947 return Optional<std::pair<String, String>>(); |
| 948 | 948 |
| 949 const SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); | 949 const SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); |
| 950 description = found_marker->Description(); | |
| 951 | |
| 952 Range* const marker_range = | 950 Range* const marker_range = |
| 953 Range::Create(*GetFrame().GetDocument(), selection_start_container, | 951 Range::Create(*GetFrame().GetDocument(), selection_start_container, |
| 954 found_marker->StartOffset(), selection_start_container, | 952 found_marker->StartOffset(), selection_start_container, |
| 955 found_marker->EndOffset()); | 953 found_marker->EndOffset()); |
| 956 | 954 |
| 957 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | 955 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| 958 CreateRange(selection_range) | 956 CreateRange(selection_range) |
| 959 ->GetText() | 957 ->GetText() |
| 960 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 958 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 961 return String(); | 959 return Optional<std::pair<String, String>>(); |
| 962 | 960 |
| 963 return marker_range->GetText(); | 961 return std::make_pair(marker_range->GetText(), found_marker->Description()); |
| 964 } | 962 } |
| 965 | 963 |
| 966 void SpellChecker::ReplaceMisspelledRange(const String& text) { | 964 void SpellChecker::ReplaceMisspelledRange(const String& text) { |
| 967 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = | 965 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = |
| 968 GetSpellCheckMarkerTouchingSelection(); | 966 GetSpellCheckMarkerTouchingSelection(); |
| 969 if (!node_and_marker) | 967 if (!node_and_marker) |
| 970 return; | 968 return; |
| 971 | 969 |
| 972 Node* const container_node = node_and_marker.value().first; | 970 Node* const container_node = node_and_marker.value().first; |
| 973 const SpellCheckMarker* const marker = node_and_marker.value().second; | 971 const SpellCheckMarker* const marker = node_and_marker.value().second; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1360 if (!input.IsFocusedElementInDocument()) | 1358 if (!input.IsFocusedElementInDocument()) |
| 1361 return false; | 1359 return false; |
| 1362 } | 1360 } |
| 1363 } | 1361 } |
| 1364 HTMLElement* element = | 1362 HTMLElement* element = |
| 1365 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1363 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
| 1366 return element && element->IsSpellCheckingEnabled(); | 1364 return element && element->IsSpellCheckingEnabled(); |
| 1367 } | 1365 } |
| 1368 | 1366 |
| 1369 } // namespace blink | 1367 } // namespace blink |
| OLD | NEW |