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

Side by Side Diff: third_party/WebKit/Source/core/events/InputEvent.cpp

Issue 2074423004: [InputEvent] Dispatch 'input' event for ContentEditable and typing on Input element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tkent's review Created 4 years, 6 months 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/events/InputEvent.h" 5 #include "core/events/InputEvent.h"
6 6
7 #include "core/dom/Range.h" 7 #include "core/dom/Range.h"
8 #include "core/events/EventDispatcher.h" 8 #include "core/events/EventDispatcher.h"
9 #include "public/platform/WebEditingCommandType.h" 9 #include "public/platform/WebEditingCommandType.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 namespace { 13 namespace {
14 14
15 const struct { 15 const struct {
16 InputEvent::InputType inputType; 16 InputEvent::InputType inputType;
17 const char* stringName; 17 const char* stringName;
18 } kInputTypeStringNameMap[] = { 18 } kInputTypeStringNameMap[] = {
19 {InputEvent::InputType::None, ""}, 19 { InputEvent::InputType::None, "" },
20 {InputEvent::InputType::InsertText, "insertText"}, 20 { InputEvent::InputType::InsertText, "insertText" },
21 {InputEvent::InputType::ReplaceContent, "replaceContent"}, 21 { InputEvent::InputType::ReplaceContent, "replaceContent" },
22 {InputEvent::InputType::DeleteContent, "deleteContent"}, 22 { InputEvent::InputType::DeleteContent, "deleteContent" },
23 {InputEvent::InputType::DeleteComposedCharacter, "deleteComposedCharacter"}, 23 { InputEvent::InputType::DeleteComposedCharacter, "deleteComposedCharacter" },
24 {InputEvent::InputType::Undo, "undo"}, 24 { InputEvent::InputType::Undo, "undo" },
25 {InputEvent::InputType::Redo, "redo"}, 25 { InputEvent::InputType::Redo, "redo" },
26 }; 26 };
27 27
28 static_assert(arraysize(kInputTypeStringNameMap) == static_cast<size_t>(InputEve nt::InputType::NumberOfInputTypes), 28 static_assert(arraysize(kInputTypeStringNameMap) == static_cast<size_t>(InputEve nt::InputType::NumberOfInputTypes),
29 "must handle all InputEvent::InputType"); 29 "must handle all InputEvent::InputType");
30 30
31 String convertInputTypeToString(InputEvent::InputType inputType) 31 String convertInputTypeToString(InputEvent::InputType inputType)
32 { 32 {
33 const auto& it = std::begin(kInputTypeStringNameMap) + static_cast<size_t>(i nputType); 33 const auto& it = std::begin(kInputTypeStringNameMap) + static_cast<size_t>(i nputType);
34 if (it >= std::begin(kInputTypeStringNameMap) && it < std::end(kInputTypeStr ingNameMap)) 34 if (it >= std::begin(kInputTypeStringNameMap) && it < std::end(kInputTypeStr ingNameMap))
35 return AtomicString(it->stringName); 35 return AtomicString(it->stringName);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // See InputEvent::InputEvent() for the second conversion. 78 // See InputEvent::InputEvent() for the second conversion.
79 inputEventInit.setInputType(convertInputTypeToString(inputType)); 79 inputEventInit.setInputType(convertInputTypeToString(inputType));
80 inputEventInit.setData(data); 80 inputEventInit.setData(data);
81 inputEventInit.setIsComposing(isComposing == IsComposing); 81 inputEventInit.setIsComposing(isComposing == IsComposing);
82 if (ranges) 82 if (ranges)
83 inputEventInit.setRanges(*ranges); 83 inputEventInit.setRanges(*ranges);
84 84
85 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); 85 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit);
86 } 86 }
87 87
88 /* static */
89 InputEvent* InputEvent::createInput(InputType inputType, const String& data, Eve ntIsComposing isComposing, const RangeVector* ranges)
90 {
91 InputEventInit inputEventInit;
92
93 inputEventInit.setBubbles(true);
94 inputEventInit.setCancelable(false);
95 // TODO(ojan): We should find a way to prevent conversion like String->enum- >String just in order to use initializer.
96 // See InputEvent::InputEvent() for the second conversion.
97 inputEventInit.setInputType(convertInputTypeToString(inputType));
98 inputEventInit.setData(data);
99 inputEventInit.setIsComposing(isComposing == IsComposing);
100 if (ranges)
101 inputEventInit.setRanges(*ranges);
102
103 return InputEvent::create(EventTypeNames::input, inputEventInit);
104 }
105
88 String InputEvent::inputType() const 106 String InputEvent::inputType() const
89 { 107 {
90 return convertInputTypeToString(m_inputType); 108 return convertInputTypeToString(m_inputType);
91 } 109 }
92 110
93 StaticRangeVector InputEvent::getRanges() const 111 StaticRangeVector InputEvent::getRanges() const
94 { 112 {
95 StaticRangeVector staticRanges; 113 StaticRangeVector staticRanges;
96 for (const auto& range : m_ranges) 114 for (const auto& range : m_ranges)
97 staticRanges.append(StaticRange::create(range->ownerDocument(), range->s tartContainer(), range->startOffset(), range->endContainer(), range->endOffset() )); 115 staticRanges.append(StaticRange::create(range->ownerDocument(), range->s tartContainer(), range->startOffset(), range->endContainer(), range->endOffset() ));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // 3. We don't want authors to hold live |Range| indefinitely by holding | InputEvent|, so we 161 // 3. We don't want authors to hold live |Range| indefinitely by holding | InputEvent|, so we
144 // clear them after dispatch. 162 // clear them after dispatch.
145 // Authors should explicitly call |getRanges()|->|toRange()| if they want to keep a copy of |Range|. 163 // Authors should explicitly call |getRanges()|->|toRange()| if they want to keep a copy of |Range|.
146 // See Editing TF meeting notes: 164 // See Editing TF meeting notes:
147 // https://docs.google.com/document/d/1hCj6QX77NYIVY0RWrMHT1Yra6t8_Qu8PopaWL G0AM58/edit?usp=sharing 165 // https://docs.google.com/document/d/1hCj6QX77NYIVY0RWrMHT1Yra6t8_Qu8PopaWL G0AM58/edit?usp=sharing
148 event().m_ranges.clear(); 166 event().m_ranges.clear();
149 return result; 167 return result;
150 } 168 }
151 169
152 } // namespace blink 170 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698