1/* 2 * Copyright (C) 2012, 2013 University of Washington. All rights reserved. 3 * Copyright (C) 2014 Apple Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 16 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 18 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#ifndef UserInputBridge_h 29#define UserInputBridge_h 30 31#include "ScrollTypes.h" 32#include <wtf/Noncopyable.h> 33 34namespace JSC { 35class InputCursor; 36} 37 38namespace WebCore { 39 40struct FrameLoadRequest; 41 42class Frame; 43class Page; 44class PlatformKeyboardEvent; 45class PlatformMouseEvent; 46class PlatformWheelEvent; 47 48// Real user inputs come from WebKit or WebKit2. 49// Synthetic inputs come from within WebCore (i.e., from web replay or fake mouse moves). 50enum class InputSource { 51 User, 52 Synthetic 53}; 54 55class UserInputBridge { 56 WTF_MAKE_NONCOPYABLE(UserInputBridge); 57public: 58 UserInputBridge(Page&); 59 60#if ENABLE(WEB_REPLAY) 61 enum class State { 62 Capturing, 63 Open, 64 Replaying, 65 }; 66 67 void setState(State bridgeState) { m_state = bridgeState; } 68 State state() const { return m_state; } 69 70 JSC::InputCursor& activeCursor() const; 71#endif 72 73 // User input APIs. 74#if ENABLE(CONTEXT_MENUS) 75 bool handleContextMenuEvent(const PlatformMouseEvent&, const Frame*, InputSource source = InputSource::User); 76#endif 77 bool handleMousePressEvent(const PlatformMouseEvent&, InputSource source = InputSource::User); 78 bool handleMouseReleaseEvent(const PlatformMouseEvent&, InputSource source = InputSource::User); 79 bool handleMouseMoveEvent(const PlatformMouseEvent&, InputSource source = InputSource::User); 80 bool handleMouseMoveOnScrollbarEvent(const PlatformMouseEvent&, InputSource source = InputSource::User); 81 bool handleWheelEvent(const PlatformWheelEvent&, InputSource source = InputSource::User); 82 bool handleKeyEvent(const PlatformKeyboardEvent&, InputSource source = InputSource::User); 83 bool handleAccessKeyEvent(const PlatformKeyboardEvent&, InputSource source = InputSource::User); 84 void focusSetActive(bool active, InputSource source = InputSource::User); 85 void focusSetFocused(bool focused, InputSource source = InputSource::User); 86 bool scrollRecursively(ScrollDirection, ScrollGranularity, InputSource source = InputSource::User); 87 bool logicalScrollRecursively(ScrollLogicalDirection, ScrollGranularity, InputSource source = InputSource::User); 88 89 // Navigation APIs. 90 void loadRequest(const FrameLoadRequest&, InputSource source = InputSource::User); 91 void reloadFrame(Frame*, bool endToEndReload, InputSource source = InputSource::User); 92 void stopLoadingFrame(Frame*, InputSource source = InputSource::User); 93 bool tryClosePage(InputSource source = InputSource::User); 94 95private: 96 Page& m_page; 97#if ENABLE(WEB_REPLAY) 98 State m_state; 99#endif 100}; 101 102} // namespace WebCore 103 104#endif // UserInputBridge_h 105