1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. 4 * Copyright (C) 2011 Igalia S.L. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 25 * THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include "config.h" 29#include "WebPage.h" 30 31#include "EditorState.h" 32#include "EventHandler.h" 33#include "NotImplemented.h" 34#include "WebEvent.h" 35#include "WindowsKeyboardCodes.h" 36#include <WebCore/BackForwardController.h> 37#include <WebCore/EflKeyboardUtilities.h> 38#include <WebCore/FocusController.h> 39#include <WebCore/Frame.h> 40#include <WebCore/FrameView.h> 41#include <WebCore/KeyboardEvent.h> 42#include <WebCore/Page.h> 43#include <WebCore/PlatformKeyboardEvent.h> 44#include <WebCore/RenderThemeEfl.h> 45#include <WebCore/Settings.h> 46 47#if HAVE(ACCESSIBILITY) 48#include "WebPageAccessibilityObject.h" 49#endif 50 51using namespace WebCore; 52 53namespace WebKit { 54 55void WebPage::platformInitialize() 56{ 57#if HAVE(ACCESSIBILITY) 58 m_accessibilityObject = adoptGRef(webPageAccessibilityObjectNew(this)); 59#else 60 notImplemented(); 61#endif 62} 63 64#if HAVE(ACCESSIBILITY) 65void WebPage::updateAccessibilityTree() 66{ 67 if (!m_accessibilityObject) 68 return; 69 70 webPageAccessibilityObjectRefresh(m_accessibilityObject.get()); 71} 72#endif 73 74void WebPage::platformPreferencesDidChange(const WebPreferencesStore&) 75{ 76 notImplemented(); 77} 78 79static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity) 80{ 81 page->focusController().focusedOrMainFrame().eventHandler().scrollRecursively(direction, granularity); 82} 83 84bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent) 85{ 86 if (keyboardEvent.type() != WebEvent::KeyDown && keyboardEvent.type() != WebEvent::RawKeyDown) 87 return false; 88 89 switch (keyboardEvent.windowsVirtualKeyCode()) { 90 case VK_BACK: 91 if (keyboardEvent.shiftKey()) 92 m_page->backForward().goForward(); 93 else 94 m_page->backForward().goBack(); 95 break; 96 case VK_SPACE: 97 scroll(m_page.get(), keyboardEvent.shiftKey() ? ScrollUp : ScrollDown, ScrollByPage); 98 break; 99 case VK_LEFT: 100 scroll(m_page.get(), ScrollLeft, ScrollByLine); 101 break; 102 case VK_RIGHT: 103 scroll(m_page.get(), ScrollRight, ScrollByLine); 104 break; 105 case VK_UP: 106 scroll(m_page.get(), ScrollUp, ScrollByLine); 107 break; 108 case VK_DOWN: 109 scroll(m_page.get(), ScrollDown, ScrollByLine); 110 break; 111 case VK_HOME: 112 scroll(m_page.get(), ScrollUp, ScrollByDocument); 113 break; 114 case VK_END: 115 scroll(m_page.get(), ScrollDown, ScrollByDocument); 116 break; 117 case VK_PRIOR: 118 scroll(m_page.get(), ScrollUp, ScrollByPage); 119 break; 120 case VK_NEXT: 121 scroll(m_page.get(), ScrollDown, ScrollByPage); 122 break; 123 default: 124 return false; 125 } 126 127 return true; 128} 129 130bool WebPage::platformHasLocalDataForURL(const URL&) 131{ 132 notImplemented(); 133 return false; 134} 135 136String WebPage::cachedResponseMIMETypeForURL(const URL&) 137{ 138 notImplemented(); 139 return String(); 140} 141 142bool WebPage::platformCanHandleRequest(const ResourceRequest&) 143{ 144 notImplemented(); 145 return true; 146} 147 148String WebPage::cachedSuggestedFilenameForURL(const URL&) 149{ 150 notImplemented(); 151 return String(); 152} 153 154PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const URL&) 155{ 156 notImplemented(); 157 return 0; 158} 159 160const char* WebPage::interpretKeyEvent(const KeyboardEvent* event) 161{ 162 ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent); 163 164 if (event->type() == eventNames().keydownEvent) 165 return getKeyDownCommandName(event); 166 167 return getKeyPressCommandName(event); 168} 169 170void WebPage::setThemePath(const String& themePath) 171{ 172 WebCore::RenderThemeEfl& theme = static_cast<WebCore::RenderThemeEfl&>(m_page->theme()); 173 theme.setThemePath(themePath); 174} 175 176static Frame* targetFrameForEditing(WebPage* page) 177{ 178 Frame& frame = page->corePage()->focusController().focusedOrMainFrame(); 179 180 Editor& editor = frame.editor(); 181 if (!editor.canEdit()) 182 return 0; 183 184 if (editor.hasComposition()) { 185 // We should verify the parent node of this IME composition node are 186 // editable because JavaScript may delete a parent node of the composition 187 // node. In this case, WebKit crashes while deleting texts from the parent 188 // node, which doesn't exist any longer. 189 if (PassRefPtr<Range> range = editor.compositionRange()) { 190 Node* node = range->startContainer(); 191 if (!node || !node->isContentEditable()) 192 return 0; 193 } 194 } 195 196 return &frame; 197} 198 199void WebPage::confirmComposition(const String& compositionString) 200{ 201 Frame* targetFrame = targetFrameForEditing(this); 202 if (!targetFrame) 203 return; 204 205 targetFrame->editor().confirmComposition(compositionString); 206} 207 208void WebPage::setComposition(const String& compositionString, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition) 209{ 210 Frame* targetFrame = targetFrameForEditing(this); 211 if (!targetFrame) 212 return; 213 214 targetFrame->editor().setComposition(compositionString, underlines, cursorPosition, 0); 215} 216 217void WebPage::cancelComposition() 218{ 219 Frame& frame = m_page->focusController().focusedOrMainFrame(); 220 frame.editor().cancelComposition(); 221} 222 223String WebPage::platformUserAgent(const URL&) const 224{ 225 return String(); 226} 227 228} // namespace WebKit 229