OLD | NEW |
---|---|
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 Loading... | |
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() | |
ojan
2016/05/31 22:56:48
At some point, we should get rid of this EventDisp
| |
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 // JavaScript might hold event objects (e.g. for custom redo/undo stack), bu t | |
128 // for performance measurement we don't want to implicitly maintain a bunch | |
129 // of |Range| objects. | |
130 // Here we clear |m_ranges| from event object after dispatch, JavaScript sho uld | |
131 // explicitly call |getRanges()|->|toRange()| if they want to keep a copy of |Range|. | |
ojan
2016/05/31 22:56:48
I see. I reread the meeting notes for this. https:
| |
132 event().m_ranges.clear(); | |
133 return result; | |
96 } | 134 } |
97 | 135 |
98 } // namespace blink | 136 } // namespace blink |
OLD | NEW |