Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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); |
|
chongz
2016/10/28 02:12:16
|inputType| could also be |InsertFromDrop|.
yosin_UTC9
2016/10/28 04:06:14
Could you add "<< inputType" for ease of debugging
| |
| 2093 | |
| 2094 InputEvent* beforeInputEvent; | |
| 2095 | |
| 2096 if (hasRichlyEditableStyle(*(target->toNode()))) { | |
| 2097 beforeInputEvent = InputEvent::createBeforeInput( | |
| 2098 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, | |
| 2099 InputEvent::EventIsComposing::NotComposing, ranges); | |
| 2100 } else { | |
| 2101 String data = dataTransfer->getData(mimeTypeTextPlain); | |
| 2102 // TODO(chongz): Pass appreciate |ranges| after it's defined on spec. | |
| 2103 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | |
| 2104 beforeInputEvent = InputEvent::createBeforeInput( | |
| 2105 inputType, data, InputEvent::EventCancelable::IsCancelable, | |
| 2106 InputEvent::EventIsComposing::NotComposing, nullptr); | |
| 2107 } | |
| 2091 return target->dispatchEvent(beforeInputEvent); | 2108 return target->dispatchEvent(beforeInputEvent); |
| 2092 } | 2109 } |
| 2093 | 2110 |
| 2094 InputEvent::InputType deletionInputTypeFromTextGranularity( | 2111 InputEvent::InputType deletionInputTypeFromTextGranularity( |
| 2095 DeleteDirection direction, | 2112 DeleteDirection direction, |
| 2096 TextGranularity granularity) { | 2113 TextGranularity granularity) { |
| 2097 using InputType = InputEvent::InputType; | 2114 using InputType = InputEvent::InputType; |
| 2098 switch (direction) { | 2115 switch (direction) { |
| 2099 case DeleteDirection::Forward: | 2116 case DeleteDirection::Forward: |
| 2100 if (granularity == WordGranularity) | 2117 if (granularity == WordGranularity) |
| 2101 return InputType::DeleteWordForward; | 2118 return InputType::DeleteWordForward; |
| 2102 if (granularity == LineBoundary) | 2119 if (granularity == LineBoundary) |
| 2103 return InputType::DeleteLineForward; | 2120 return InputType::DeleteLineForward; |
| 2104 return InputType::DeleteContentForward; | 2121 return InputType::DeleteContentForward; |
| 2105 case DeleteDirection::Backward: | 2122 case DeleteDirection::Backward: |
| 2106 if (granularity == WordGranularity) | 2123 if (granularity == WordGranularity) |
| 2107 return InputType::DeleteWordBackward; | 2124 return InputType::DeleteWordBackward; |
| 2108 if (granularity == LineBoundary) | 2125 if (granularity == LineBoundary) |
| 2109 return InputType::DeleteLineBackward; | 2126 return InputType::DeleteLineBackward; |
| 2110 return InputType::DeleteContentBackward; | 2127 return InputType::DeleteContentBackward; |
| 2111 default: | 2128 default: |
| 2112 return InputType::None; | 2129 return InputType::None; |
| 2113 } | 2130 } |
| 2114 } | 2131 } |
| 2115 | 2132 |
| 2116 } // namespace blink | 2133 } // namespace blink |
| OLD | NEW |