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

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 2457523003: Support 'insertReplacementText' for spellcheck (Closed)
Patch Set: fix for yosin's comments Created 4 years, 1 month 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) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/editing/EditingUtilities.h" 26 #include "core/editing/EditingUtilities.h"
27 27
28 #include "core/HTMLElementFactory.h" 28 #include "core/HTMLElementFactory.h"
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/clipboard/DataObject.h"
30 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
31 #include "core/dom/ElementTraversal.h" 32 #include "core/dom/ElementTraversal.h"
32 #include "core/dom/NodeComputedStyle.h" 33 #include "core/dom/NodeComputedStyle.h"
33 #include "core/dom/Range.h" 34 #include "core/dom/Range.h"
34 #include "core/dom/Text.h" 35 #include "core/dom/Text.h"
35 #include "core/dom/shadow/ShadowRoot.h" 36 #include "core/dom/shadow/ShadowRoot.h"
36 #include "core/editing/EditingStrategy.h" 37 #include "core/editing/EditingStrategy.h"
37 #include "core/editing/Editor.h" 38 #include "core/editing/Editor.h"
38 #include "core/editing/PlainTextRange.h" 39 #include "core/editing/PlainTextRange.h"
39 #include "core/editing/PositionIterator.h" 40 #include "core/editing/PositionIterator.h"
(...skipping 10 matching lines...) Expand all
50 #include "core/frame/UseCounter.h" 51 #include "core/frame/UseCounter.h"
51 #include "core/html/HTMLBRElement.h" 52 #include "core/html/HTMLBRElement.h"
52 #include "core/html/HTMLDivElement.h" 53 #include "core/html/HTMLDivElement.h"
53 #include "core/html/HTMLLIElement.h" 54 #include "core/html/HTMLLIElement.h"
54 #include "core/html/HTMLParagraphElement.h" 55 #include "core/html/HTMLParagraphElement.h"
55 #include "core/html/HTMLSpanElement.h" 56 #include "core/html/HTMLSpanElement.h"
56 #include "core/html/HTMLTableCellElement.h" 57 #include "core/html/HTMLTableCellElement.h"
57 #include "core/html/HTMLUListElement.h" 58 #include "core/html/HTMLUListElement.h"
58 #include "core/layout/LayoutObject.h" 59 #include "core/layout/LayoutObject.h"
59 #include "core/layout/LayoutTableCell.h" 60 #include "core/layout/LayoutTableCell.h"
61 #include "platform/clipboard/ClipboardMimeTypes.h"
60 #include "wtf/Assertions.h" 62 #include "wtf/Assertions.h"
61 #include "wtf/StdLibExtras.h" 63 #include "wtf/StdLibExtras.h"
62 #include "wtf/text/StringBuilder.h" 64 #include "wtf/text/StringBuilder.h"
63 #include "wtf/text/Unicode.h" 65 #include "wtf/text/Unicode.h"
64 66
65 namespace blink { 67 namespace blink {
66 68
67 using namespace HTMLNames; 69 using namespace HTMLNames;
68 70
69 namespace { 71 namespace {
(...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 2080
2079 DispatchEventResult dispatchBeforeInputDataTransfer( 2081 DispatchEventResult dispatchBeforeInputDataTransfer(
2080 EventTarget* target, 2082 EventTarget* target,
2081 InputEvent::InputType inputType, 2083 InputEvent::InputType inputType,
2082 DataTransfer* dataTransfer, 2084 DataTransfer* dataTransfer,
2083 const RangeVector* ranges) { 2085 const RangeVector* ranges) {
2084 if (!RuntimeEnabledFeatures::inputEventEnabled()) 2086 if (!RuntimeEnabledFeatures::inputEventEnabled())
2085 return DispatchEventResult::NotCanceled; 2087 return DispatchEventResult::NotCanceled;
2086 if (!target) 2088 if (!target)
2087 return DispatchEventResult::NotCanceled; 2089 return DispatchEventResult::NotCanceled;
2088 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( 2090
2089 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, 2091 DCHECK(inputType == InputEvent::InputType::InsertFromPaste ||
2090 InputEvent::EventIsComposing::NotComposing, ranges); 2092 inputType == InputEvent::InputType::InsertReplacementText ||
2093 inputType == InputEvent::InputType::InsertFromDrop)
2094 << "Unsupported inputType: " << (int)inputType;
2095
2096 InputEvent* beforeInputEvent;
2097
2098 if (hasRichlyEditableStyle(*(target->toNode()))) {
2099 beforeInputEvent = InputEvent::createBeforeInput(
2100 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable,
2101 InputEvent::EventIsComposing::NotComposing, ranges);
2102 } else {
2103 String data = dataTransfer->getData(mimeTypeTextPlain);
2104 // TODO(chongz): Pass appreciate |ranges| after it's defined on spec.
dtapuska 2016/11/09 14:44:56 Should this comment indicate // Pass appropriate?
2105 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype
2106 beforeInputEvent = InputEvent::createBeforeInput(
2107 inputType, data, InputEvent::EventCancelable::IsCancelable,
2108 InputEvent::EventIsComposing::NotComposing, nullptr);
2109 }
2091 return target->dispatchEvent(beforeInputEvent); 2110 return target->dispatchEvent(beforeInputEvent);
2092 } 2111 }
2093 2112
2094 InputEvent::InputType deletionInputTypeFromTextGranularity( 2113 InputEvent::InputType deletionInputTypeFromTextGranularity(
2095 DeleteDirection direction, 2114 DeleteDirection direction,
2096 TextGranularity granularity) { 2115 TextGranularity granularity) {
2097 using InputType = InputEvent::InputType; 2116 using InputType = InputEvent::InputType;
2098 switch (direction) { 2117 switch (direction) {
2099 case DeleteDirection::Forward: 2118 case DeleteDirection::Forward:
2100 if (granularity == WordGranularity) 2119 if (granularity == WordGranularity)
2101 return InputType::DeleteWordForward; 2120 return InputType::DeleteWordForward;
2102 if (granularity == LineBoundary) 2121 if (granularity == LineBoundary)
2103 return InputType::DeleteLineForward; 2122 return InputType::DeleteLineForward;
2104 return InputType::DeleteContentForward; 2123 return InputType::DeleteContentForward;
2105 case DeleteDirection::Backward: 2124 case DeleteDirection::Backward:
2106 if (granularity == WordGranularity) 2125 if (granularity == WordGranularity)
2107 return InputType::DeleteWordBackward; 2126 return InputType::DeleteWordBackward;
2108 if (granularity == LineBoundary) 2127 if (granularity == LineBoundary)
2109 return InputType::DeleteLineBackward; 2128 return InputType::DeleteLineBackward;
2110 return InputType::DeleteContentBackward; 2129 return InputType::DeleteContentBackward;
2111 default: 2130 default:
2112 return InputType::None; 2131 return InputType::None;
2113 } 2132 }
2114 } 2133 }
2115 2134
2116 } // namespace blink 2135 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698