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

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

Issue 2558643003: [InputEvent] Move 'beforeinput' logic into |CompositeEditCommand::willApplyEditing()| (3/3) (Closed)
Patch Set: Created 4 years 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
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "core/frame/UseCounter.h" 51 #include "core/frame/UseCounter.h"
52 #include "core/html/HTMLBRElement.h" 52 #include "core/html/HTMLBRElement.h"
53 #include "core/html/HTMLDivElement.h" 53 #include "core/html/HTMLDivElement.h"
54 #include "core/html/HTMLLIElement.h" 54 #include "core/html/HTMLLIElement.h"
55 #include "core/html/HTMLParagraphElement.h" 55 #include "core/html/HTMLParagraphElement.h"
56 #include "core/html/HTMLSpanElement.h" 56 #include "core/html/HTMLSpanElement.h"
57 #include "core/html/HTMLTableCellElement.h" 57 #include "core/html/HTMLTableCellElement.h"
58 #include "core/html/HTMLUListElement.h" 58 #include "core/html/HTMLUListElement.h"
59 #include "core/layout/LayoutObject.h" 59 #include "core/layout/LayoutObject.h"
60 #include "core/layout/LayoutTableCell.h" 60 #include "core/layout/LayoutTableCell.h"
61 #include "platform/clipboard/ClipboardMimeTypes.h"
62 #include "wtf/Assertions.h" 61 #include "wtf/Assertions.h"
63 #include "wtf/StdLibExtras.h" 62 #include "wtf/StdLibExtras.h"
64 #include "wtf/text/StringBuilder.h" 63 #include "wtf/text/StringBuilder.h"
65 #include "wtf/text/Unicode.h" 64 #include "wtf/text/Unicode.h"
66 65
67 namespace blink { 66 namespace blink {
68 67
69 using namespace HTMLNames; 68 using namespace HTMLNames;
70 69
71 namespace { 70 namespace {
(...skipping 1968 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 // otherwise, make sure to be at the start of the first selected node, 2039 // otherwise, make sure to be at the start of the first selected node,
2041 // instead of possibly at the end of the last node before the selection 2040 // instead of possibly at the end of the last node before the selection
2042 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 2041 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
2043 } 2042 }
2044 2043
2045 bool isTextSecurityNode(const Node* node) { 2044 bool isTextSecurityNode(const Node* node) {
2046 return node && node->layoutObject() && 2045 return node && node->layoutObject() &&
2047 node->layoutObject()->style()->textSecurity() != TSNONE; 2046 node->layoutObject()->style()->textSecurity() != TSNONE;
2048 } 2047 }
2049 2048
2050 DispatchEventResult dispatchBeforeInputInsertText(EventTarget* target,
2051 const String& data) {
2052 if (!RuntimeEnabledFeatures::inputEventEnabled())
2053 return DispatchEventResult::NotCanceled;
2054 if (!target)
2055 return DispatchEventResult::NotCanceled;
2056 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec.
2057 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype
2058 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(
2059 InputEvent::InputType::InsertText, data,
2060 InputEvent::EventCancelable::IsCancelable,
2061 InputEvent::EventIsComposing::NotComposing, nullptr);
2062 return target->dispatchEvent(beforeInputEvent);
2063 }
2064
2065 DispatchEventResult dispatchBeforeInputFromComposition(
2066 EventTarget* target,
2067 InputEvent::InputType inputType,
2068 const String& data,
2069 InputEvent::EventCancelable cancelable) {
2070 if (!RuntimeEnabledFeatures::inputEventEnabled())
2071 return DispatchEventResult::NotCanceled;
2072 if (!target)
2073 return DispatchEventResult::NotCanceled;
2074 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec.
2075 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype
2076 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(
2077 inputType, data, cancelable, InputEvent::EventIsComposing::IsComposing,
2078 nullptr);
2079 return target->dispatchEvent(beforeInputEvent);
2080 }
2081
2082 DispatchEventResult dispatchBeforeInputEditorCommand(
2083 EventTarget* target,
2084 InputEvent::InputType inputType,
2085 const RangeVector* ranges) {
2086 if (!RuntimeEnabledFeatures::inputEventEnabled())
2087 return DispatchEventResult::NotCanceled;
2088 if (!target)
2089 return DispatchEventResult::NotCanceled;
2090 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(
2091 inputType, nullAtom, InputEvent::EventCancelable::IsCancelable,
2092 InputEvent::EventIsComposing::NotComposing, ranges);
2093 return target->dispatchEvent(beforeInputEvent);
2094 }
2095
2096 DispatchEventResult dispatchBeforeInputDataTransfer(
2097 EventTarget* target,
2098 InputEvent::InputType inputType,
2099 DataTransfer* dataTransfer,
2100 const RangeVector* ranges) {
2101 if (!RuntimeEnabledFeatures::inputEventEnabled())
2102 return DispatchEventResult::NotCanceled;
2103 if (!target)
2104 return DispatchEventResult::NotCanceled;
2105
2106 DCHECK(inputType == InputEvent::InputType::InsertFromPaste ||
2107 inputType == InputEvent::InputType::InsertReplacementText ||
2108 inputType == InputEvent::InputType::InsertFromDrop ||
2109 inputType == InputEvent::InputType::DeleteByCut)
2110 << "Unsupported inputType: " << (int)inputType;
2111
2112 InputEvent* beforeInputEvent;
2113
2114 if (hasRichlyEditableStyle(*(target->toNode())) || !dataTransfer) {
2115 beforeInputEvent = InputEvent::createBeforeInput(
2116 inputType, dataTransfer, InputEvent::EventCancelable::IsCancelable,
2117 InputEvent::EventIsComposing::NotComposing, ranges);
2118 } else {
2119 const String& data = dataTransfer->getData(mimeTypeTextPlain);
2120 // TODO(chongz): Pass appropriate |ranges| after it's defined on spec.
2121 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype
2122 beforeInputEvent = InputEvent::createBeforeInput(
2123 inputType, data, InputEvent::EventCancelable::IsCancelable,
2124 InputEvent::EventIsComposing::NotComposing, nullptr);
2125 }
2126 return target->dispatchEvent(beforeInputEvent);
2127 }
2128
2129 InputEvent::InputType deletionInputTypeFromTextGranularity( 2049 InputEvent::InputType deletionInputTypeFromTextGranularity(
2130 DeleteDirection direction, 2050 DeleteDirection direction,
2131 TextGranularity granularity) { 2051 TextGranularity granularity) {
2132 using InputType = InputEvent::InputType; 2052 using InputType = InputEvent::InputType;
2133 switch (direction) { 2053 switch (direction) {
2134 case DeleteDirection::Forward: 2054 case DeleteDirection::Forward:
2135 if (granularity == WordGranularity) 2055 if (granularity == WordGranularity)
2136 return InputType::DeleteWordForward; 2056 return InputType::DeleteWordForward;
2137 if (granularity == LineBoundary) 2057 if (granularity == LineBoundary)
2138 return InputType::DeleteLineForward; 2058 return InputType::DeleteSoftLineForward;
2139 return InputType::DeleteContentForward; 2059 return InputType::DeleteContentForward;
2140 case DeleteDirection::Backward: 2060 case DeleteDirection::Backward:
2141 if (granularity == WordGranularity) 2061 if (granularity == WordGranularity)
2142 return InputType::DeleteWordBackward; 2062 return InputType::DeleteWordBackward;
2143 if (granularity == LineBoundary) 2063 if (granularity == LineBoundary)
2144 return InputType::DeleteLineBackward; 2064 return InputType::DeleteSoftLineBackward;
2145 return InputType::DeleteContentBackward; 2065 return InputType::DeleteContentBackward;
2146 default: 2066 default:
2147 return InputType::None; 2067 return InputType::None;
2148 } 2068 }
2149 } 2069 }
2150 2070
2151 } // namespace blink 2071 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698