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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(), | 822 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(), |
823 markers[0]->startOffset()), | 823 markers[0]->startOffset()), |
824 Position(caretRange.endPosition().computeContainerNode(), | 824 Position(caretRange.endPosition().computeContainerNode(), |
825 markers[0]->endOffset())); | 825 markers[0]->endOffset())); |
826 if (markerRange.isNull()) | 826 if (markerRange.isNull()) |
827 return; | 827 return; |
828 | 828 |
829 frame().selection().setSelection( | 829 frame().selection().setSelection( |
830 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build()); | 830 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build()); |
831 | 831 |
832 Document& currentDocument = *frame().document(); | |
833 | |
834 // Dispatch 'beforeinput'. | |
835 Element* const target = frame().editor().findEventTargetFromSelection(); | |
836 RangeVector* const ranges = | |
837 new RangeVector(1, frame().selection().firstRange()); | |
838 DataTransfer* const dataTransfer = DataTransfer::create( | |
839 DataTransfer::DataTransferType::InsertReplacementText, | |
840 DataTransferAccessPolicy::DataTransferReadable, | |
841 DataObject::createFromString(text)); | |
842 | |
843 const bool cancel = | |
844 dispatchBeforeInputDataTransfer( | |
845 target, InputEvent::InputType::InsertReplacementText, dataTransfer, | |
846 ranges) != DispatchEventResult::NotCanceled; | |
847 | |
848 // 'beforeinput' event handler may destroy target frame. | |
849 if (currentDocument != frame().document()) | |
850 return; | |
851 | |
852 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 832 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
853 // needs to be audited. See http://crbug.com/590369 for more details. | 833 // needs to be audited. See http://crbug.com/590369 for more details. |
854 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 834 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
855 | |
856 if (cancel) | |
857 return; | |
858 frame().editor().replaceSelectionForSpellChecker(text); | 835 frame().editor().replaceSelectionForSpellChecker(text); |
859 } | 836 } |
860 | 837 |
861 static bool shouldCheckOldSelection(const Position& oldSelectionStart) { | 838 static bool shouldCheckOldSelection(const Position& oldSelectionStart) { |
862 if (!oldSelectionStart.isConnected()) | 839 if (!oldSelectionStart.isConnected()) |
863 return false; | 840 return false; |
864 if (isPositionInTextField(oldSelectionStart)) | 841 if (isPositionInTextField(oldSelectionStart)) |
865 return false; | 842 return false; |
866 if (isPositionInTextArea(oldSelectionStart)) | 843 if (isPositionInTextArea(oldSelectionStart)) |
867 return true; | 844 return true; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 startOfNextParagraph(createVisiblePosition(paragraphEnd)); | 1143 startOfNextParagraph(createVisiblePosition(paragraphEnd)); |
1167 paragraphStart = newParagraphStart.toParentAnchoredPosition(); | 1144 paragraphStart = newParagraphStart.toParentAnchoredPosition(); |
1168 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); | 1145 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); |
1169 firstIteration = false; | 1146 firstIteration = false; |
1170 totalLengthProcessed += currentLength; | 1147 totalLengthProcessed += currentLength; |
1171 } | 1148 } |
1172 return std::make_pair(firstFoundItem, firstFoundOffset); | 1149 return std::make_pair(firstFoundItem, firstFoundOffset); |
1173 } | 1150 } |
1174 | 1151 |
1175 } // namespace blink | 1152 } // namespace blink |
OLD | NEW |