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 |
| (...skipping 2024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2035 // otherwise, make sure to be at the start of the first selected node, | 2035 // otherwise, make sure to be at the start of the first selected node, |
| 2036 // instead of possibly at the end of the last node before the selection | 2036 // instead of possibly at the end of the last node before the selection |
| 2037 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 2037 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 2038 } | 2038 } |
| 2039 | 2039 |
| 2040 bool isTextSecurityNode(const Node* node) { | 2040 bool isTextSecurityNode(const Node* node) { |
| 2041 return node && node->layoutObject() && | 2041 return node && node->layoutObject() && |
| 2042 node->layoutObject()->style()->textSecurity() != TSNONE; | 2042 node->layoutObject()->style()->textSecurity() != TSNONE; |
| 2043 } | 2043 } |
| 2044 | 2044 |
| 2045 DispatchEventResult dispatchBeforeInputInsertText(EventTarget* target, | 2045 const RangeVector* targetRangesForInputEvent(Node* node) { |
|
yosin_UTC9
2017/02/14 03:43:45
Could you use |const Node&|? |node| can not be nul
chongz
2017/02/14 18:57:51
Done.
| |
| 2046 if (!hasRichlyEditableStyle(*node)) | |
| 2047 return nullptr; | |
| 2048 return new RangeVector( | |
| 2049 1, firstRangeOf(node->document().frame()->selection().selection())); | |
| 2050 } | |
| 2051 | |
| 2052 DispatchEventResult dispatchBeforeInputInsertText(Node* target, | |
| 2046 const String& data) { | 2053 const String& data) { |
| 2047 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2054 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2048 return DispatchEventResult::NotCanceled; | 2055 return DispatchEventResult::NotCanceled; |
| 2049 if (!target) | 2056 if (!target) |
| 2050 return DispatchEventResult::NotCanceled; | 2057 return DispatchEventResult::NotCanceled; |
| 2051 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. | 2058 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| 2052 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | 2059 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| 2053 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( | 2060 InputEvent* beforeInputEvent = |
| 2054 InputEvent::InputType::InsertText, data, | 2061 InputEvent::createBeforeInput(InputEvent::InputType::InsertText, data, |
| 2055 InputEvent::EventCancelable::IsCancelable, | 2062 InputEvent::EventCancelable::IsCancelable, |
| 2056 InputEvent::EventIsComposing::NotComposing, nullptr); | 2063 InputEvent::EventIsComposing::NotComposing, |
| 2064 targetRangesForInputEvent(target)); | |
| 2057 return target->dispatchEvent(beforeInputEvent); | 2065 return target->dispatchEvent(beforeInputEvent); |
| 2058 } | 2066 } |
| 2059 | 2067 |
| 2060 DispatchEventResult dispatchBeforeInputEditorCommand( | 2068 DispatchEventResult dispatchBeforeInputEditorCommand( |
| 2061 EventTarget* target, | 2069 Node* target, |
| 2062 InputEvent::InputType inputType, | 2070 InputEvent::InputType inputType, |
| 2063 const RangeVector* ranges) { | 2071 const RangeVector* ranges) { |
| 2064 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2072 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2065 return DispatchEventResult::NotCanceled; | 2073 return DispatchEventResult::NotCanceled; |
| 2066 if (!target) | 2074 if (!target) |
| 2067 return DispatchEventResult::NotCanceled; | 2075 return DispatchEventResult::NotCanceled; |
| 2068 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( | 2076 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| 2069 inputType, nullAtom, InputEvent::EventCancelable::IsCancelable, | 2077 inputType, nullAtom, InputEvent::EventCancelable::IsCancelable, |
| 2070 InputEvent::EventIsComposing::NotComposing, ranges); | 2078 InputEvent::EventIsComposing::NotComposing, ranges); |
| 2071 return target->dispatchEvent(beforeInputEvent); | 2079 return target->dispatchEvent(beforeInputEvent); |
| 2072 } | 2080 } |
| 2073 | 2081 |
| 2074 DispatchEventResult dispatchBeforeInputDataTransfer( | 2082 DispatchEventResult dispatchBeforeInputDataTransfer( |
| 2075 EventTarget* target, | 2083 Node* target, |
| 2076 InputEvent::InputType inputType, | 2084 InputEvent::InputType inputType, |
| 2077 DataTransfer* dataTransfer, | 2085 DataTransfer* dataTransfer) { |
| 2078 const RangeVector* ranges) { | |
| 2079 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2086 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2080 return DispatchEventResult::NotCanceled; | 2087 return DispatchEventResult::NotCanceled; |
| 2081 if (!target) | 2088 if (!target) |
| 2082 return DispatchEventResult::NotCanceled; | 2089 return DispatchEventResult::NotCanceled; |
| 2083 | 2090 |
| 2084 DCHECK(inputType == InputEvent::InputType::InsertFromPaste || | 2091 DCHECK(inputType == InputEvent::InputType::InsertFromPaste || |
| 2085 inputType == InputEvent::InputType::InsertReplacementText || | 2092 inputType == InputEvent::InputType::InsertReplacementText || |
| 2086 inputType == InputEvent::InputType::InsertFromDrop || | 2093 inputType == InputEvent::InputType::InsertFromDrop || |
| 2087 inputType == InputEvent::InputType::DeleteByCut) | 2094 inputType == InputEvent::InputType::DeleteByCut) |
| 2088 << "Unsupported inputType: " << (int)inputType; | 2095 << "Unsupported inputType: " << (int)inputType; |
| 2089 | 2096 |
| 2090 InputEvent* beforeInputEvent; | 2097 InputEvent* beforeInputEvent; |
| 2091 | 2098 |
| 2092 if (hasRichlyEditableStyle(*(target->toNode())) || !dataTransfer) { | 2099 if (hasRichlyEditableStyle(*(target->toNode())) || !dataTransfer) { |
| 2093 beforeInputEvent = InputEvent::createBeforeInput( | 2100 beforeInputEvent = InputEvent::createBeforeInput( |
| 2094 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, | 2101 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, |
| 2095 InputEvent::EventIsComposing::NotComposing, ranges); | 2102 InputEvent::EventIsComposing::NotComposing, |
| 2103 targetRangesForInputEvent(target)); | |
| 2096 } else { | 2104 } else { |
| 2097 const String& data = dataTransfer->getData(mimeTypeTextPlain); | 2105 const String& data = dataTransfer->getData(mimeTypeTextPlain); |
| 2098 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. | 2106 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| 2099 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | 2107 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| 2100 beforeInputEvent = InputEvent::createBeforeInput( | 2108 beforeInputEvent = InputEvent::createBeforeInput( |
| 2101 inputType, data, InputEvent::EventCancelable::IsCancelable, | 2109 inputType, data, InputEvent::EventCancelable::IsCancelable, |
| 2102 InputEvent::EventIsComposing::NotComposing, nullptr); | 2110 InputEvent::EventIsComposing::NotComposing, |
| 2111 targetRangesForInputEvent(target)); | |
| 2103 } | 2112 } |
| 2104 return target->dispatchEvent(beforeInputEvent); | 2113 return target->dispatchEvent(beforeInputEvent); |
| 2105 } | 2114 } |
| 2106 | 2115 |
| 2107 InputEvent::InputType deletionInputTypeFromTextGranularity( | 2116 InputEvent::InputType deletionInputTypeFromTextGranularity( |
| 2108 DeleteDirection direction, | 2117 DeleteDirection direction, |
| 2109 TextGranularity granularity) { | 2118 TextGranularity granularity) { |
| 2110 using InputType = InputEvent::InputType; | 2119 using InputType = InputEvent::InputType; |
| 2111 switch (direction) { | 2120 switch (direction) { |
| 2112 case DeleteDirection::Forward: | 2121 case DeleteDirection::Forward: |
| 2113 if (granularity == WordGranularity) | 2122 if (granularity == WordGranularity) |
| 2114 return InputType::DeleteWordForward; | 2123 return InputType::DeleteWordForward; |
| 2115 if (granularity == LineBoundary) | 2124 if (granularity == LineBoundary) |
| 2116 return InputType::DeleteLineForward; | 2125 return InputType::DeleteLineForward; |
| 2117 return InputType::DeleteContentForward; | 2126 return InputType::DeleteContentForward; |
| 2118 case DeleteDirection::Backward: | 2127 case DeleteDirection::Backward: |
| 2119 if (granularity == WordGranularity) | 2128 if (granularity == WordGranularity) |
| 2120 return InputType::DeleteWordBackward; | 2129 return InputType::DeleteWordBackward; |
| 2121 if (granularity == LineBoundary) | 2130 if (granularity == LineBoundary) |
| 2122 return InputType::DeleteLineBackward; | 2131 return InputType::DeleteLineBackward; |
| 2123 return InputType::DeleteContentBackward; | 2132 return InputType::DeleteContentBackward; |
| 2124 default: | 2133 default: |
| 2125 return InputType::None; | 2134 return InputType::None; |
| 2126 } | 2135 } |
| 2127 } | 2136 } |
| 2128 | 2137 |
| 2129 } // namespace blink | 2138 } // namespace blink |
| OLD | NEW |