| 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" |
| 40 #include "core/editing/VisiblePosition.h" | 41 #include "core/editing/VisiblePosition.h" |
| 41 #include "core/editing/VisibleSelection.h" | 42 #include "core/editing/VisibleSelection.h" |
| 42 #include "core/editing/VisibleUnits.h" | 43 #include "core/editing/VisibleUnits.h" |
| 43 #include "core/editing/iterators/TextIterator.h" | 44 #include "core/editing/iterators/TextIterator.h" |
| 44 #include "core/editing/serializers/HTMLInterchange.h" | 45 #include "core/editing/serializers/HTMLInterchange.h" |
| 45 #include "core/editing/state_machines/BackspaceStateMachine.h" | 46 #include "core/editing/state_machines/BackspaceStateMachine.h" |
| 46 #include "core/editing/state_machines/BackwardGraphemeBoundaryStateMachine.h" | 47 #include "core/editing/state_machines/BackwardGraphemeBoundaryStateMachine.h" |
| 47 #include "core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h" | 48 #include "core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h" |
| 48 #include "core/frame/FrameView.h" | 49 #include "core/frame/FrameView.h" |
| 49 #include "core/frame/LocalFrame.h" | 50 #include "core/frame/LocalFrame.h" |
| 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" |
| 60 #include "core/layout/LayoutTableCell.h" |
| 61 #include "platform/clipboard/ClipboardMimeTypes.h" |
| 59 #include "wtf/Assertions.h" | 62 #include "wtf/Assertions.h" |
| 60 #include "wtf/StdLibExtras.h" | 63 #include "wtf/StdLibExtras.h" |
| 61 #include "wtf/text/StringBuilder.h" | 64 #include "wtf/text/StringBuilder.h" |
| 62 #include "wtf/text/Unicode.h" | 65 #include "wtf/text/Unicode.h" |
| 63 | 66 |
| 64 namespace blink { | 67 namespace blink { |
| 65 | 68 |
| 66 using namespace HTMLNames; | 69 using namespace HTMLNames; |
| 67 | 70 |
| 68 namespace { | 71 namespace { |
| (...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 return node && node->layoutObject() && | 2030 return node && node->layoutObject() && |
| 2028 node->layoutObject()->style()->textSecurity() != TSNONE; | 2031 node->layoutObject()->style()->textSecurity() != TSNONE; |
| 2029 } | 2032 } |
| 2030 | 2033 |
| 2031 DispatchEventResult dispatchBeforeInputInsertText(EventTarget* target, | 2034 DispatchEventResult dispatchBeforeInputInsertText(EventTarget* target, |
| 2032 const String& data) { | 2035 const String& data) { |
| 2033 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2036 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2034 return DispatchEventResult::NotCanceled; | 2037 return DispatchEventResult::NotCanceled; |
| 2035 if (!target) | 2038 if (!target) |
| 2036 return DispatchEventResult::NotCanceled; | 2039 return DispatchEventResult::NotCanceled; |
| 2037 // TODO(chongz): Pass appreciate |ranges| after it's defined on spec. | 2040 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| 2038 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | 2041 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| 2039 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( | 2042 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| 2040 InputEvent::InputType::InsertText, data, | 2043 InputEvent::InputType::InsertText, data, |
| 2041 InputEvent::EventCancelable::IsCancelable, | 2044 InputEvent::EventCancelable::IsCancelable, |
| 2042 InputEvent::EventIsComposing::NotComposing, nullptr); | 2045 InputEvent::EventIsComposing::NotComposing, nullptr); |
| 2043 return target->dispatchEvent(beforeInputEvent); | 2046 return target->dispatchEvent(beforeInputEvent); |
| 2044 } | 2047 } |
| 2045 | 2048 |
| 2046 DispatchEventResult dispatchBeforeInputFromComposition( | 2049 DispatchEventResult dispatchBeforeInputFromComposition( |
| 2047 EventTarget* target, | 2050 EventTarget* target, |
| 2048 InputEvent::InputType inputType, | 2051 InputEvent::InputType inputType, |
| 2049 const String& data, | 2052 const String& data, |
| 2050 InputEvent::EventCancelable cancelable) { | 2053 InputEvent::EventCancelable cancelable) { |
| 2051 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2054 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2052 return DispatchEventResult::NotCanceled; | 2055 return DispatchEventResult::NotCanceled; |
| 2053 if (!target) | 2056 if (!target) |
| 2054 return DispatchEventResult::NotCanceled; | 2057 return DispatchEventResult::NotCanceled; |
| 2055 // TODO(chongz): Pass appreciate |ranges| after it's defined on spec. | 2058 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| 2056 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | 2059 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| 2057 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( | 2060 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| 2058 inputType, data, cancelable, InputEvent::EventIsComposing::IsComposing, | 2061 inputType, data, cancelable, InputEvent::EventIsComposing::IsComposing, |
| 2059 nullptr); | 2062 nullptr); |
| 2060 return target->dispatchEvent(beforeInputEvent); | 2063 return target->dispatchEvent(beforeInputEvent); |
| 2061 } | 2064 } |
| 2062 | 2065 |
| 2063 DispatchEventResult dispatchBeforeInputEditorCommand( | 2066 DispatchEventResult dispatchBeforeInputEditorCommand( |
| 2064 EventTarget* target, | 2067 EventTarget* target, |
| 2065 InputEvent::InputType inputType, | 2068 InputEvent::InputType inputType, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2076 | 2079 |
| 2077 DispatchEventResult dispatchBeforeInputDataTransfer( | 2080 DispatchEventResult dispatchBeforeInputDataTransfer( |
| 2078 EventTarget* target, | 2081 EventTarget* target, |
| 2079 InputEvent::InputType inputType, | 2082 InputEvent::InputType inputType, |
| 2080 DataTransfer* dataTransfer, | 2083 DataTransfer* dataTransfer, |
| 2081 const RangeVector* ranges) { | 2084 const RangeVector* ranges) { |
| 2082 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2085 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2083 return DispatchEventResult::NotCanceled; | 2086 return DispatchEventResult::NotCanceled; |
| 2084 if (!target) | 2087 if (!target) |
| 2085 return DispatchEventResult::NotCanceled; | 2088 return DispatchEventResult::NotCanceled; |
| 2086 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( | 2089 |
| 2087 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, | 2090 DCHECK(inputType == InputEvent::InputType::InsertFromPaste || |
| 2088 InputEvent::EventIsComposing::NotComposing, ranges); | 2091 inputType == InputEvent::InputType::InsertReplacementText || |
| 2092 inputType == InputEvent::InputType::InsertFromDrop || |
| 2093 inputType == InputEvent::InputType::DeleteByCut) |
| 2094 << "Unsupported inputType: " << (int)inputType; |
| 2095 |
| 2096 InputEvent* beforeInputEvent; |
| 2097 |
| 2098 if (hasRichlyEditableStyle(*(target->toNode())) || !dataTransfer) { |
| 2099 beforeInputEvent = InputEvent::createBeforeInput( |
| 2100 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, |
| 2101 InputEvent::EventIsComposing::NotComposing, ranges); |
| 2102 } else { |
| 2103 const String& data = dataTransfer->getData(mimeTypeTextPlain); |
| 2104 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| 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 } |
| 2089 return target->dispatchEvent(beforeInputEvent); | 2110 return target->dispatchEvent(beforeInputEvent); |
| 2090 } | 2111 } |
| 2091 | 2112 |
| 2092 InputEvent::InputType deletionInputTypeFromTextGranularity( | 2113 InputEvent::InputType deletionInputTypeFromTextGranularity( |
| 2093 DeleteDirection direction, | 2114 DeleteDirection direction, |
| 2094 TextGranularity granularity) { | 2115 TextGranularity granularity) { |
| 2095 using InputType = InputEvent::InputType; | 2116 using InputType = InputEvent::InputType; |
| 2096 switch (direction) { | 2117 switch (direction) { |
| 2097 case DeleteDirection::Forward: | 2118 case DeleteDirection::Forward: |
| 2098 if (granularity == WordGranularity) | 2119 if (granularity == WordGranularity) |
| 2099 return InputType::DeleteWordForward; | 2120 return InputType::DeleteWordForward; |
| 2100 if (granularity == LineBoundary) | 2121 if (granularity == LineBoundary) |
| 2101 return InputType::DeleteLineForward; | 2122 return InputType::DeleteLineForward; |
| 2102 return InputType::DeleteContentForward; | 2123 return InputType::DeleteContentForward; |
| 2103 case DeleteDirection::Backward: | 2124 case DeleteDirection::Backward: |
| 2104 if (granularity == WordGranularity) | 2125 if (granularity == WordGranularity) |
| 2105 return InputType::DeleteWordBackward; | 2126 return InputType::DeleteWordBackward; |
| 2106 if (granularity == LineBoundary) | 2127 if (granularity == LineBoundary) |
| 2107 return InputType::DeleteLineBackward; | 2128 return InputType::DeleteLineBackward; |
| 2108 return InputType::DeleteContentBackward; | 2129 return InputType::DeleteContentBackward; |
| 2109 default: | 2130 default: |
| 2110 return InputType::None; | 2131 return InputType::None; |
| 2111 } | 2132 } |
| 2112 } | 2133 } |
| 2113 | 2134 |
| 2114 } // namespace blink | 2135 } // namespace blink |
| OLD | NEW |