| 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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 marker_types); | 831 marker_types); |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 } | 834 } |
| 835 | 835 |
| 836 Optional<std::pair<Node*, SpellCheckMarker*>> | 836 Optional<std::pair<Node*, SpellCheckMarker*>> |
| 837 SpellChecker::GetSpellCheckMarkerUnderSelection() { | 837 SpellChecker::GetSpellCheckMarkerUnderSelection() { |
| 838 const VisibleSelection& selection = | 838 const VisibleSelection& selection = |
| 839 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); | 839 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); |
| 840 if (selection.IsNone()) | 840 if (selection.IsNone()) |
| 841 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 841 return {}; |
| 842 | 842 |
| 843 // Caret and range selections always return valid normalized ranges. | 843 // Caret and range selections always return valid normalized ranges. |
| 844 const EphemeralRange& selection_range = FirstEphemeralRangeOf(selection); | 844 const EphemeralRange& selection_range = FirstEphemeralRangeOf(selection); |
| 845 | 845 |
| 846 Node* const selection_start_container = | 846 Node* const selection_start_container = |
| 847 selection_range.StartPosition().ComputeContainerNode(); | 847 selection_range.StartPosition().ComputeContainerNode(); |
| 848 Node* const selection_end_container = | 848 Node* const selection_end_container = |
| 849 selection_range.EndPosition().ComputeContainerNode(); | 849 selection_range.EndPosition().ComputeContainerNode(); |
| 850 | 850 |
| 851 // We don't currently support the case where a misspelling spans multiple | 851 // We don't currently support the case where a misspelling spans multiple |
| 852 // nodes. See crbug.com/720065 | 852 // nodes. See crbug.com/720065 |
| 853 if (selection_start_container != selection_end_container) | 853 if (selection_start_container != selection_end_container) |
| 854 return {}; | 854 return {}; |
| 855 | 855 |
| 856 if (!selection_start_container->IsTextNode()) | 856 if (!selection_start_container->IsTextNode()) |
| 857 return {}; | 857 return {}; |
| 858 | 858 |
| 859 const unsigned selection_start_offset = | 859 const unsigned selection_start_offset = |
| 860 selection_range.StartPosition().ComputeOffsetInContainerNode(); | 860 selection_range.StartPosition().ComputeOffsetInContainerNode(); |
| 861 const unsigned selection_end_offset = | 861 const unsigned selection_end_offset = |
| 862 selection_range.EndPosition().ComputeOffsetInContainerNode(); | 862 selection_range.EndPosition().ComputeOffsetInContainerNode(); |
| 863 | 863 |
| 864 DocumentMarker* const marker = | 864 DocumentMarker* const marker = |
| 865 GetFrame().GetDocument()->Markers().FirstMarkerIntersectingOffsetRange( | 865 GetFrame().GetDocument()->Markers().FirstMarkerIntersectingOffsetRange( |
| 866 ToText(*selection_start_container), selection_start_offset, | 866 ToText(*selection_start_container), selection_start_offset, |
| 867 selection_end_offset, DocumentMarker::MisspellingMarkers()); | 867 selection_end_offset, DocumentMarker::MisspellingMarkers()); |
| 868 if (!marker) | 868 if (!marker) |
| 869 return Optional<std::pair<Node*, SpellCheckMarker*>>(); | 869 return {}; |
| 870 | 870 |
| 871 return std::make_pair(selection_start_container, ToSpellCheckMarker(marker)); | 871 return std::make_pair(selection_start_container, ToSpellCheckMarker(marker)); |
| 872 } | 872 } |
| 873 | 873 |
| 874 String SpellChecker::SelectMisspellingAsync(String& description) { | 874 std::pair<String, String> SpellChecker::SelectMisspellingAsync() { |
| 875 VisibleSelection selection = | 875 VisibleSelection selection = |
| 876 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); | 876 GetFrame().Selection().ComputeVisibleSelectionInDOMTree(); |
| 877 if (selection.IsNone()) | 877 if (selection.IsNone()) |
| 878 return String(); | 878 return {}; |
| 879 | 879 |
| 880 // Caret and range selections always return valid normalized ranges. | 880 // Caret and range selections always return valid normalized ranges. |
| 881 const EphemeralRange& selection_range = | 881 const EphemeralRange& selection_range = |
| 882 selection.ToNormalizedEphemeralRange(); | 882 selection.ToNormalizedEphemeralRange(); |
| 883 | 883 |
| 884 Node* const selection_start_container = | 884 Node* const selection_start_container = |
| 885 selection_range.StartPosition().ComputeContainerNode(); | 885 selection_range.StartPosition().ComputeContainerNode(); |
| 886 Node* const selection_end_container = | 886 Node* const selection_end_container = |
| 887 selection_range.EndPosition().ComputeContainerNode(); | 887 selection_range.EndPosition().ComputeContainerNode(); |
| 888 | 888 |
| 889 // We don't currently support the case where a misspelling spans multiple | 889 // We don't currently support the case where a misspelling spans multiple |
| 890 // nodes. See crbug.com/720065 | 890 // nodes. See crbug.com/720065 |
| 891 if (selection_start_container != selection_end_container) | 891 if (selection_start_container != selection_end_container) |
| 892 return String(); | 892 return {}; |
| 893 | 893 |
| 894 const unsigned selection_start_offset = | 894 const unsigned selection_start_offset = |
| 895 selection_range.StartPosition().ComputeOffsetInContainerNode(); | 895 selection_range.StartPosition().ComputeOffsetInContainerNode(); |
| 896 const unsigned selection_end_offset = | 896 const unsigned selection_end_offset = |
| 897 selection_range.EndPosition().ComputeOffsetInContainerNode(); | 897 selection_range.EndPosition().ComputeOffsetInContainerNode(); |
| 898 | 898 |
| 899 const DocumentMarkerVector& markers_in_node = | 899 const DocumentMarkerVector& markers_in_node = |
| 900 GetFrame().GetDocument()->Markers().MarkersFor( | 900 GetFrame().GetDocument()->Markers().MarkersFor( |
| 901 selection_start_container, DocumentMarker::MisspellingMarkers()); | 901 selection_start_container, DocumentMarker::MisspellingMarkers()); |
| 902 | 902 |
| 903 const auto marker_it = | 903 const auto marker_it = |
| 904 std::find_if(markers_in_node.begin(), markers_in_node.end(), | 904 std::find_if(markers_in_node.begin(), markers_in_node.end(), |
| 905 [=](const DocumentMarker* marker) { | 905 [=](const DocumentMarker* marker) { |
| 906 return marker->StartOffset() < selection_end_offset && | 906 return marker->StartOffset() < selection_end_offset && |
| 907 marker->EndOffset() > selection_start_offset; | 907 marker->EndOffset() > selection_start_offset; |
| 908 }); | 908 }); |
| 909 if (marker_it == markers_in_node.end()) | 909 if (marker_it == markers_in_node.end()) |
| 910 return String(); | 910 return {}; |
| 911 | 911 |
| 912 const SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); | 912 const SpellCheckMarker* const found_marker = ToSpellCheckMarker(*marker_it); |
| 913 description = found_marker->Description(); | |
| 914 | 913 |
| 915 Range* const marker_range = | 914 Range* const marker_range = |
| 916 Range::Create(*GetFrame().GetDocument(), selection_start_container, | 915 Range::Create(*GetFrame().GetDocument(), selection_start_container, |
| 917 found_marker->StartOffset(), selection_start_container, | 916 found_marker->StartOffset(), selection_start_container, |
| 918 found_marker->EndOffset()); | 917 found_marker->EndOffset()); |
| 919 | 918 |
| 920 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | 919 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| 921 CreateRange(selection_range) | 920 CreateRange(selection_range) |
| 922 ->GetText() | 921 ->GetText() |
| 923 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 922 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 924 return String(); | 923 return {}; |
| 925 | 924 |
| 926 return marker_range->GetText(); | 925 return std::make_pair(marker_range->GetText(), found_marker->Description()); |
| 927 } | 926 } |
| 928 | 927 |
| 929 void SpellChecker::ReplaceMisspelledRange(const String& text) { | 928 void SpellChecker::ReplaceMisspelledRange(const String& text) { |
| 930 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = | 929 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = |
| 931 GetSpellCheckMarkerUnderSelection(); | 930 GetSpellCheckMarkerUnderSelection(); |
| 932 if (!node_and_marker) | 931 if (!node_and_marker) |
| 933 return; | 932 return; |
| 934 | 933 |
| 935 Node* const container_node = node_and_marker.value().first; | 934 Node* const container_node = node_and_marker.value().first; |
| 936 const SpellCheckMarker* const marker = node_and_marker.value().second; | 935 const SpellCheckMarker* const marker = node_and_marker.value().second; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 if (!input.IsFocusedElementInDocument()) | 1322 if (!input.IsFocusedElementInDocument()) |
| 1324 return false; | 1323 return false; |
| 1325 } | 1324 } |
| 1326 } | 1325 } |
| 1327 HTMLElement* element = | 1326 HTMLElement* element = |
| 1328 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1327 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
| 1329 return element && element->IsSpellCheckingEnabled(); | 1328 return element && element->IsSpellCheckingEnabled(); |
| 1330 } | 1329 } |
| 1331 | 1330 |
| 1332 } // namespace blink | 1331 } // namespace blink |
| OLD | NEW |