| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 std::ostream& operator<<(std::ostream& os, PositionMoveType type) { | 73 std::ostream& operator<<(std::ostream& os, PositionMoveType type) { |
| 74 static const char* const texts[] = {"CodeUnit", "BackwardDeletion", | 74 static const char* const texts[] = {"CodeUnit", "BackwardDeletion", |
| 75 "GraphemeCluster"}; | 75 "GraphemeCluster"}; |
| 76 const auto& it = std::begin(texts) + static_cast<size_t>(type); | 76 const auto& it = std::begin(texts) + static_cast<size_t>(type); |
| 77 DCHECK_GE(it, std::begin(texts)) << "Unknown PositionMoveType value"; | 77 DCHECK_GE(it, std::begin(texts)) << "Unknown PositionMoveType value"; |
| 78 DCHECK_LT(it, std::end(texts)) << "Unknown PositionMoveType value"; | 78 DCHECK_LT(it, std::end(texts)) << "Unknown PositionMoveType value"; |
| 79 return os << *it; | 79 return os << *it; |
| 80 } | 80 } |
| 81 | 81 |
| 82 InputEvent::EventCancelable inputTypeIsCancelable( |
| 83 InputEvent::InputType inputType) { |
| 84 using InputType = InputEvent::InputType; |
| 85 switch (inputType) { |
| 86 case InputType::InsertText: |
| 87 case InputType::InsertLineBreak: |
| 88 case InputType::InsertParagraph: |
| 89 case InputType::InsertCompositionText: |
| 90 case InputType::InsertReplacementText: |
| 91 case InputType::DeleteWordBackward: |
| 92 case InputType::DeleteWordForward: |
| 93 case InputType::DeleteLineBackward: |
| 94 case InputType::DeleteLineForward: |
| 95 case InputType::DeleteContentBackward: |
| 96 case InputType::DeleteContentForward: |
| 97 return InputEvent::EventCancelable::NotCancelable; |
| 98 default: |
| 99 return InputEvent::EventCancelable::IsCancelable; |
| 100 } |
| 101 } |
| 102 |
| 82 } // namespace | 103 } // namespace |
| 83 | 104 |
| 84 static bool needsLayoutTreeUpdate(const Node& node) { | 105 static bool needsLayoutTreeUpdate(const Node& node) { |
| 85 const Document& document = node.document(); | 106 const Document& document = node.document(); |
| 86 if (document.needsLayoutTreeUpdate()) | 107 if (document.needsLayoutTreeUpdate()) |
| 87 return true; | 108 return true; |
| 88 // TODO(yosin): We should make |document::needsLayoutTreeUpdate()| to | 109 // TODO(yosin): We should make |document::needsLayoutTreeUpdate()| to |
| 89 // check |LayoutView::needsLayout()|. | 110 // check |LayoutView::needsLayout()|. |
| 90 return document.view() && document.view()->needsLayout(); | 111 return document.view() && document.view()->needsLayout(); |
| 91 } | 112 } |
| (...skipping 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 } | 2074 } |
| 2054 | 2075 |
| 2055 DispatchEventResult dispatchBeforeInputInsertText(Node* target, | 2076 DispatchEventResult dispatchBeforeInputInsertText(Node* target, |
| 2056 const String& data) { | 2077 const String& data) { |
| 2057 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2078 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2058 return DispatchEventResult::NotCanceled; | 2079 return DispatchEventResult::NotCanceled; |
| 2059 if (!target) | 2080 if (!target) |
| 2060 return DispatchEventResult::NotCanceled; | 2081 return DispatchEventResult::NotCanceled; |
| 2061 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. | 2082 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| 2062 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | 2083 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| 2063 InputEvent* beforeInputEvent = | 2084 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| 2064 InputEvent::createBeforeInput(InputEvent::InputType::InsertText, data, | 2085 InputEvent::InputType::InsertText, data, |
| 2065 InputEvent::EventCancelable::IsCancelable, | 2086 inputTypeIsCancelable(InputEvent::InputType::InsertText), |
| 2066 InputEvent::EventIsComposing::NotComposing, | 2087 InputEvent::EventIsComposing::NotComposing, |
| 2067 targetRangesForInputEvent(*target)); | 2088 targetRangesForInputEvent(*target)); |
| 2068 return target->dispatchEvent(beforeInputEvent); | 2089 return target->dispatchEvent(beforeInputEvent); |
| 2069 } | 2090 } |
| 2070 | 2091 |
| 2071 DispatchEventResult dispatchBeforeInputEditorCommand( | 2092 DispatchEventResult dispatchBeforeInputEditorCommand( |
| 2072 Node* target, | 2093 Node* target, |
| 2073 InputEvent::InputType inputType, | 2094 InputEvent::InputType inputType, |
| 2074 const RangeVector* ranges) { | 2095 const RangeVector* ranges) { |
| 2075 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2096 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2076 return DispatchEventResult::NotCanceled; | 2097 return DispatchEventResult::NotCanceled; |
| 2077 if (!target) | 2098 if (!target) |
| 2078 return DispatchEventResult::NotCanceled; | 2099 return DispatchEventResult::NotCanceled; |
| 2079 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( | 2100 InputEvent* beforeInputEvent = InputEvent::createBeforeInput( |
| 2080 inputType, nullAtom, InputEvent::EventCancelable::IsCancelable, | 2101 inputType, nullAtom, inputTypeIsCancelable(inputType), |
| 2081 InputEvent::EventIsComposing::NotComposing, ranges); | 2102 InputEvent::EventIsComposing::NotComposing, ranges); |
| 2082 return target->dispatchEvent(beforeInputEvent); | 2103 return target->dispatchEvent(beforeInputEvent); |
| 2083 } | 2104 } |
| 2084 | 2105 |
| 2085 DispatchEventResult dispatchBeforeInputDataTransfer( | 2106 DispatchEventResult dispatchBeforeInputDataTransfer( |
| 2086 Node* target, | 2107 Node* target, |
| 2087 InputEvent::InputType inputType, | 2108 InputEvent::InputType inputType, |
| 2088 DataTransfer* dataTransfer) { | 2109 DataTransfer* dataTransfer) { |
| 2089 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 2110 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 2090 return DispatchEventResult::NotCanceled; | 2111 return DispatchEventResult::NotCanceled; |
| 2091 if (!target) | 2112 if (!target) |
| 2092 return DispatchEventResult::NotCanceled; | 2113 return DispatchEventResult::NotCanceled; |
| 2093 | 2114 |
| 2094 DCHECK(inputType == InputEvent::InputType::InsertFromPaste || | 2115 DCHECK(inputType == InputEvent::InputType::InsertFromPaste || |
| 2095 inputType == InputEvent::InputType::InsertReplacementText || | 2116 inputType == InputEvent::InputType::InsertReplacementText || |
| 2096 inputType == InputEvent::InputType::InsertFromDrop || | 2117 inputType == InputEvent::InputType::InsertFromDrop || |
| 2097 inputType == InputEvent::InputType::DeleteByCut) | 2118 inputType == InputEvent::InputType::DeleteByCut) |
| 2098 << "Unsupported inputType: " << (int)inputType; | 2119 << "Unsupported inputType: " << (int)inputType; |
| 2099 | 2120 |
| 2100 InputEvent* beforeInputEvent; | 2121 InputEvent* beforeInputEvent; |
| 2101 | 2122 |
| 2102 if (hasRichlyEditableStyle(*(target->toNode())) || !dataTransfer) { | 2123 if (hasRichlyEditableStyle(*(target->toNode())) || !dataTransfer) { |
| 2103 beforeInputEvent = InputEvent::createBeforeInput( | 2124 beforeInputEvent = InputEvent::createBeforeInput( |
| 2104 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable, | 2125 inputType, dataTransfer, inputTypeIsCancelable(inputType), |
| 2105 InputEvent::EventIsComposing::NotComposing, | 2126 InputEvent::EventIsComposing::NotComposing, |
| 2106 targetRangesForInputEvent(*target)); | 2127 targetRangesForInputEvent(*target)); |
| 2107 } else { | 2128 } else { |
| 2108 const String& data = dataTransfer->getData(mimeTypeTextPlain); | 2129 const String& data = dataTransfer->getData(mimeTypeTextPlain); |
| 2109 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. | 2130 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec. |
| 2110 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | 2131 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype |
| 2111 beforeInputEvent = InputEvent::createBeforeInput( | 2132 beforeInputEvent = InputEvent::createBeforeInput( |
| 2112 inputType, data, InputEvent::EventCancelable::IsCancelable, | 2133 inputType, data, inputTypeIsCancelable(inputType), |
| 2113 InputEvent::EventIsComposing::NotComposing, | 2134 InputEvent::EventIsComposing::NotComposing, |
| 2114 targetRangesForInputEvent(*target)); | 2135 targetRangesForInputEvent(*target)); |
| 2115 } | 2136 } |
| 2116 return target->dispatchEvent(beforeInputEvent); | 2137 return target->dispatchEvent(beforeInputEvent); |
| 2117 } | 2138 } |
| 2118 | 2139 |
| 2119 InputEvent::InputType deletionInputTypeFromTextGranularity( | 2140 InputEvent::InputType deletionInputTypeFromTextGranularity( |
| 2120 DeleteDirection direction, | 2141 DeleteDirection direction, |
| 2121 TextGranularity granularity) { | 2142 TextGranularity granularity) { |
| 2122 using InputType = InputEvent::InputType; | 2143 using InputType = InputEvent::InputType; |
| 2123 switch (direction) { | 2144 switch (direction) { |
| 2124 case DeleteDirection::Forward: | 2145 case DeleteDirection::Forward: |
| 2125 if (granularity == WordGranularity) | 2146 if (granularity == WordGranularity) |
| 2126 return InputType::DeleteWordForward; | 2147 return InputType::DeleteWordForward; |
| 2127 if (granularity == LineBoundary) | 2148 if (granularity == LineBoundary) |
| 2128 return InputType::DeleteLineForward; | 2149 return InputType::DeleteLineForward; |
| 2129 return InputType::DeleteContentForward; | 2150 return InputType::DeleteContentForward; |
| 2130 case DeleteDirection::Backward: | 2151 case DeleteDirection::Backward: |
| 2131 if (granularity == WordGranularity) | 2152 if (granularity == WordGranularity) |
| 2132 return InputType::DeleteWordBackward; | 2153 return InputType::DeleteWordBackward; |
| 2133 if (granularity == LineBoundary) | 2154 if (granularity == LineBoundary) |
| 2134 return InputType::DeleteLineBackward; | 2155 return InputType::DeleteLineBackward; |
| 2135 return InputType::DeleteContentBackward; | 2156 return InputType::DeleteContentBackward; |
| 2136 default: | 2157 default: |
| 2137 return InputType::None; | 2158 return InputType::None; |
| 2138 } | 2159 } |
| 2139 } | 2160 } |
| 2140 | 2161 |
| 2141 } // namespace blink | 2162 } // namespace blink |
| OLD | NEW |