2 * Copyright (C) 2011 Samsung Electronics. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebEditorClient.h"
30 #include "NativeWebKeyboardEvent.h"
31 #include "PlatformKeyboardEvent.h"
33 #include "WebPageProxyMessages.h"
34 #include "WebProcess.h"
35 #if ENABLE(TIZEN_ISF_PORT)
36 #include "WindowsKeyboardCodes.h"
38 #include <WebCore/FocusController.h>
39 #include <WebCore/KeyboardEvent.h>
40 #include <WebCore/NotImplemented.h>
41 #include <WebCore/Page.h>
43 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
45 #include <WebCore/DataObjectTizen.h>
48 using namespace WebCore;
52 #if ENABLE(TIZEN_ISF_PORT)
53 static bool handleKeyPressCommands(WebPage* page, KeyboardEvent* event)
55 const NativeWebKeyboardEvent* currentEvent = static_cast<const NativeWebKeyboardEvent*>(WebPage::currentEvent());
56 bool isFiltered = (currentEvent && currentEvent->isFiltered());
58 if (event->type() != eventNames().keypressEvent)
61 Vector<OwnPtr<KeyPressCommand> > commands;
62 page->swapKeyPressCommands(commands);
64 size_t size = commands.size();
68 for (size_t i = 0; i < size; ++i) {
69 switch (commands[i]->type) {
70 case KeyPressCommandSetComposition: {
71 const SetCompositionKeyPressCommand* command = reinterpret_cast<const SetCompositionKeyPressCommand*>(commands[i].get());
73 int nextType = commands[i + 1]->type;
74 if (nextType == KeyPressCommandSetComposition || nextType == KeyPressCommandConfirmComposition)
77 page->setComposition(command->compositionString, command->underlines, command->cursorPosition);
80 case KeyPressCommandConfirmComposition: {
81 const ConfirmCompositionKeyPressCommand* command = reinterpret_cast<const ConfirmCompositionKeyPressCommand*>(commands[i].get());
82 page->confirmComposition(command->compositionString);
85 case KeyPressCommandDeleteText: {
86 const DeleteTextKeyPressCommand* command = reinterpret_cast<const DeleteTextKeyPressCommand*>(commands[i].get());
87 page->deleteSurroundingText(command->offset, command->count);
95 event->setDefaultHandled();
101 void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
103 #if ENABLE(TIZEN_ISF_PORT)
104 if (handleKeyPressCommands(m_page, event))
108 if (m_page->handleEditingKeyboardEvent(event))
109 event->setDefaultHandled();
112 void WebEditorClient::handleInputMethodKeydown(KeyboardEvent* event)
114 #if ENABLE(TIZEN_ISF_PORT)
118 Frame* frame = m_page->corePage()->focusController()->focusedOrMainFrame();
119 if (!frame || !frame->editor()->canEdit())
122 // FIXME: sending sync message might make input lagging.
123 bool handled = false;
124 m_page->sendSync(Messages::WebPageProxy::HandleInputMethodKeydown(), Messages::WebPageProxy::HandleInputMethodKeydown::Reply(handled));
127 event->setDefaultHandled();
130 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
131 void WebEditorClient::setClipboardData(const String& data, const String& type)
133 m_page->send(Messages::WebPageProxy::SetClipboardData(data, type));
136 void WebEditorClient::setClipboardDataForPaste(const String& data, const String& type)
138 DataObjectTizen* dataObject = DataObjectTizen::sharedDataObject();
140 if (type == "Markup") {
141 dataObject->setMarkup(data);
142 char* plainText = evas_textblock_text_markup_to_utf8(0, data.utf8().data());
144 dataObject->setText(data);
147 } else if (type == "PlainText") {
148 dataObject->setText(data);
149 } else if (type == "Image") {
150 dataObject->setImage(data);
151 dataObject->setText(data);
155 void WebEditorClient::clearClipboardData()
157 m_page->send(Messages::WebPageProxy::ClearClipboardData());
161 #if ENABLE(TIZEN_ISF_PORT)
162 void WebEditorClient::didCancelComposition(Node* valueChangedNode)
164 m_page->didCancelComposition(valueChangedNode);