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

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

Issue 1965543002: [InputEvent] Support |sequence<Range> getRanges()| in 'beforeinput' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't use |std::unique_ptr<>| with |HeapVector| 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/events/EventDispatcher.h" 8 #include "core/events/EventDispatcher.h"
8 #include "public/platform/WebEditingCommandType.h" 9 #include "public/platform/WebEditingCommandType.h"
9 10
10 namespace blink { 11 namespace blink {
11 12
12 namespace { 13 namespace {
13 14
14 const struct { 15 const struct {
15 InputEvent::InputType inputType; 16 InputEvent::InputType inputType;
16 const char* stringName; 17 const char* stringName;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 : UIEvent(type, initializer) 56 : UIEvent(type, initializer)
56 { 57 {
57 // TODO(ojan): We should find a way to prevent conversion like String->enum- >String just in order to use initializer. 58 // TODO(ojan): We should find a way to prevent conversion like String->enum- >String just in order to use initializer.
58 // See InputEvent::createBeforeInput() for the first conversion. 59 // See InputEvent::createBeforeInput() for the first conversion.
59 if (initializer.hasInputType()) 60 if (initializer.hasInputType())
60 m_inputType = convertStringToInputType(initializer.inputType()); 61 m_inputType = convertStringToInputType(initializer.inputType());
61 if (initializer.hasData()) 62 if (initializer.hasData())
62 m_data = initializer.data(); 63 m_data = initializer.data();
63 if (initializer.hasIsComposing()) 64 if (initializer.hasIsComposing())
64 m_isComposing = initializer.isComposing(); 65 m_isComposing = initializer.isComposing();
66 if (initializer.hasRanges())
67 m_ranges = initializer.ranges();
65 } 68 }
66 69
67 /* static */ 70 /* static */
68 InputEvent* InputEvent::createBeforeInput(InputType inputType, const String& dat a, EventCancelable cancelable, EventIsComposing isComposing) 71 InputEvent* InputEvent::createBeforeInput(InputType inputType, const String& dat a, EventCancelable cancelable, EventIsComposing isComposing, const RangeVector* ranges)
69 { 72 {
70 InputEventInit inputEventInit; 73 InputEventInit inputEventInit;
71 74
72 inputEventInit.setBubbles(true); 75 inputEventInit.setBubbles(true);
73 inputEventInit.setCancelable(cancelable == IsCancelable); 76 inputEventInit.setCancelable(cancelable == IsCancelable);
74 // TODO(ojan): We should find a way to prevent conversion like String->enum- >String just in order to use initializer. 77 // TODO(ojan): We should find a way to prevent conversion like String->enum- >String just in order to use initializer.
75 // See InputEvent::InputEvent() for the second conversion. 78 // See InputEvent::InputEvent() for the second conversion.
76 inputEventInit.setInputType(convertInputTypeToString(inputType)); 79 inputEventInit.setInputType(convertInputTypeToString(inputType));
77 inputEventInit.setData(data); 80 inputEventInit.setData(data);
78 inputEventInit.setIsComposing(isComposing == IsComposing); 81 inputEventInit.setIsComposing(isComposing == IsComposing);
82 if (ranges)
83 inputEventInit.setRanges(*ranges);
79 84
80 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); 85 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit);
81 } 86 }
82 87
83 String InputEvent::inputType() const 88 String InputEvent::inputType() const
84 { 89 {
85 return convertInputTypeToString(m_inputType); 90 return convertInputTypeToString(m_inputType);
86 } 91 }
87 92
88 bool InputEvent::isInputEvent() const 93 bool InputEvent::isInputEvent() const
89 { 94 {
90 return true; 95 return true;
91 } 96 }
92 97
98 EventDispatchMediator* InputEvent::createMediator()
99 {
100 return InputEventDispatchMediator::create(this);
101 }
102
93 DEFINE_TRACE(InputEvent) 103 DEFINE_TRACE(InputEvent)
94 { 104 {
95 UIEvent::trace(visitor); 105 UIEvent::trace(visitor);
106 visitor->trace(m_ranges);
107 }
108
109 InputEventDispatchMediator* InputEventDispatchMediator::create(InputEvent* input Event)
110 {
111 return new InputEventDispatchMediator(inputEvent);
112 }
113
114 InputEventDispatchMediator::InputEventDispatchMediator(InputEvent* inputEvent)
115 : EventDispatchMediator(inputEvent)
116 {
117 }
118
119 InputEvent& InputEventDispatchMediator::event() const
120 {
121 return toInputEvent(EventDispatchMediator::event());
122 }
123
124 DispatchEventResult InputEventDispatchMediator::dispatchEvent(EventDispatcher& d ispatcher) const
125 {
126 DispatchEventResult result = dispatcher.dispatch();
127 // Clear |m_ranges| manually in case event object was held by JavaScript.
ojan 2016/05/31 17:47:29 Can you explain this in more detail? I thought we
chongz 2016/05/31 18:32:26 Added more detailed comments. We want to dereferen
ojan 2016/05/31 21:35:58 I thought the idea was that we would expose Static
128 event().m_ranges.clear();
129 return result;
96 } 130 }
97 131
98 } // namespace blink 132 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698