1 | /* |
2 | * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | * |
25 | */ |
26 | |
27 | #include "config.h" |
28 | #include "TextEvent.h" |
29 | |
30 | #include "DocumentFragment.h" |
31 | #include "Editor.h" |
32 | #include "EventNames.h" |
33 | |
34 | namespace WebCore { |
35 | |
36 | Ref<TextEvent> TextEvent::createForBindings() |
37 | { |
38 | return adoptRef(*new TextEvent); |
39 | } |
40 | |
41 | Ref<TextEvent> TextEvent::create(RefPtr<WindowProxy>&& view, const String& data, TextEventInputType inputType) |
42 | { |
43 | return adoptRef(*new TextEvent(WTFMove(view), data, inputType)); |
44 | } |
45 | |
46 | Ref<TextEvent> TextEvent::createForPlainTextPaste(RefPtr<WindowProxy>&& view, const String& data, bool shouldSmartReplace) |
47 | { |
48 | return adoptRef(*new TextEvent(WTFMove(view), data, 0, shouldSmartReplace, false, MailBlockquoteHandling::RespectBlockquote)); |
49 | } |
50 | |
51 | Ref<TextEvent> TextEvent::createForFragmentPaste(RefPtr<WindowProxy>&& view, RefPtr<DocumentFragment>&& data, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling) |
52 | { |
53 | return adoptRef(*new TextEvent(WTFMove(view), emptyString(), WTFMove(data), shouldSmartReplace, shouldMatchStyle, mailBlockquoteHandling)); |
54 | } |
55 | |
56 | Ref<TextEvent> TextEvent::createForDrop(RefPtr<WindowProxy>&& view, const String& data) |
57 | { |
58 | return adoptRef(*new TextEvent(WTFMove(view), data, TextEventInputDrop)); |
59 | } |
60 | |
61 | Ref<TextEvent> TextEvent::createForDictation(RefPtr<WindowProxy>&& view, const String& data, const Vector<DictationAlternative>& dictationAlternatives) |
62 | { |
63 | return adoptRef(*new TextEvent(WTFMove(view), data, dictationAlternatives)); |
64 | } |
65 | |
66 | TextEvent::TextEvent() |
67 | : m_inputType(TextEventInputKeyboard) |
68 | , m_shouldSmartReplace(false) |
69 | , m_shouldMatchStyle(false) |
70 | , m_mailBlockquoteHandling(MailBlockquoteHandling::RespectBlockquote) |
71 | { |
72 | } |
73 | |
74 | TextEvent::TextEvent(RefPtr<WindowProxy>&& view, const String& data, TextEventInputType inputType) |
75 | : UIEvent(eventNames().textInputEvent, CanBubble::Yes, IsCancelable::Yes, IsComposed::Yes, WTFMove(view), 0) |
76 | , m_inputType(inputType) |
77 | , m_data(data) |
78 | , m_shouldSmartReplace(false) |
79 | , m_shouldMatchStyle(false) |
80 | , m_mailBlockquoteHandling(MailBlockquoteHandling::RespectBlockquote) |
81 | { |
82 | } |
83 | |
84 | TextEvent::TextEvent(RefPtr<WindowProxy>&& view, const String& data, RefPtr<DocumentFragment>&& pastingFragment, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling) |
85 | : UIEvent(eventNames().textInputEvent, CanBubble::Yes, IsCancelable::Yes, IsComposed::Yes, WTFMove(view), 0) |
86 | , m_inputType(TextEventInputPaste) |
87 | , m_data(data) |
88 | , m_pastingFragment(WTFMove(pastingFragment)) |
89 | , m_shouldSmartReplace(shouldSmartReplace) |
90 | , m_shouldMatchStyle(shouldMatchStyle) |
91 | , m_mailBlockquoteHandling(mailBlockquoteHandling) |
92 | { |
93 | } |
94 | |
95 | TextEvent::TextEvent(RefPtr<WindowProxy>&& view, const String& data, const Vector<DictationAlternative>& dictationAlternatives) |
96 | : UIEvent(eventNames().textInputEvent, CanBubble::Yes, IsCancelable::Yes, IsComposed::Yes, WTFMove(view), 0) |
97 | , m_inputType(TextEventInputDictation) |
98 | , m_data(data) |
99 | , m_shouldSmartReplace(false) |
100 | , m_shouldMatchStyle(false) |
101 | , m_mailBlockquoteHandling(MailBlockquoteHandling::RespectBlockquote) |
102 | , m_dictationAlternatives(dictationAlternatives) |
103 | { |
104 | } |
105 | |
106 | TextEvent::~TextEvent() = default; |
107 | |
108 | void TextEvent::initTextEvent(const AtomicString& type, bool canBubble, bool cancelable, RefPtr<WindowProxy>&& view, const String& data) |
109 | { |
110 | if (isBeingDispatched()) |
111 | return; |
112 | |
113 | initUIEvent(type, canBubble, cancelable, WTFMove(view), 0); |
114 | |
115 | m_inputType = TextEventInputKeyboard; |
116 | |
117 | m_data = data; |
118 | |
119 | m_pastingFragment = nullptr; |
120 | m_shouldSmartReplace = false; |
121 | m_shouldMatchStyle = false; |
122 | m_mailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote; |
123 | m_dictationAlternatives = { }; |
124 | } |
125 | |
126 | EventInterface TextEvent::eventInterface() const |
127 | { |
128 | return TextEventInterfaceType; |
129 | } |
130 | |
131 | bool TextEvent::isTextEvent() const |
132 | { |
133 | return true; |
134 | } |
135 | |
136 | } // namespace WebCore |
137 | |