1/*
2 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
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 COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * 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#include "config.h"
29#include "EventHandler.h"
30
31#include "ClipboardQt.h"
32#include "Cursor.h"
33#include "Document.h"
34#include "EventNames.h"
35#include "FloatPoint.h"
36#include "FocusController.h"
37#include "Frame.h"
38#include "FrameLoader.h"
39#include "FrameTree.h"
40#include "FrameView.h"
41#include "HTMLFrameSetElement.h"
42#include "HitTestRequest.h"
43#include "HitTestResult.h"
44#include "KeyboardEvent.h"
45#include "MouseEventWithHitTestResults.h"
46#include "Page.h"
47#include "PlatformKeyboardEvent.h"
48#include "PlatformWheelEvent.h"
49#include "RenderWidget.h"
50#include "Scrollbar.h"
51#include "NotImplemented.h"
52
53QT_BEGIN_NAMESPACE
54extern Q_GUI_EXPORT bool qt_tab_all_widgets; // from qapplication.cpp
55QT_END_NAMESPACE
56
57namespace WebCore {
58
59const double EventHandler::TextDragDelay = 0.0;
60
61static bool isKeyboardOptionTab(KeyboardEvent* event)
62{
63    return event
64        && (event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent)
65        && event->altKey()
66        && event->keyIdentifier() == "U+0009";
67}
68
69bool EventHandler::invertSenseOfTabsToLinks(KeyboardEvent* event) const
70{
71    return isKeyboardOptionTab(event);
72}
73
74bool EventHandler::tabsToAllControls(KeyboardEvent* event) const
75{
76    return (isKeyboardOptionTab(event) ? !qt_tab_all_widgets : qt_tab_all_widgets);
77}
78
79void EventHandler::focusDocumentView()
80{
81    Page* page = m_frame->page();
82    if (!page)
83        return;
84    page->focusController()->setFocusedFrame(m_frame);
85}
86
87bool EventHandler::passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults&)
88{
89    notImplemented();
90    return false;
91}
92
93bool EventHandler::eventActivatedView(const PlatformMouseEvent&) const
94{
95    //Qt has an activation event which is sent independently
96    //   of mouse event so this thing will be a snafu to implement
97    //   correctly
98    return false;
99}
100
101bool EventHandler::passWheelEventToWidget(PlatformWheelEvent& event, Widget* widget)
102{
103    Q_ASSERT(widget);
104    if (!widget->isFrameView())
105        return false;
106
107    return static_cast<FrameView*>(widget)->frame()->eventHandler()->handleWheelEvent(event);
108}
109
110PassRefPtr<Clipboard> EventHandler::createDraggingClipboard() const
111{
112    return ClipboardQt::create(ClipboardWritable, true);
113}
114
115bool EventHandler::passMousePressEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe)
116{
117    subframe->eventHandler()->handleMousePressEvent(mev.event());
118    return true;
119}
120
121bool EventHandler::passMouseMoveEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe, HitTestResult* hoveredNode)
122{
123    subframe->eventHandler()->handleMouseMoveEvent(mev.event(), hoveredNode);
124    return true;
125}
126
127bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe)
128{
129    subframe->eventHandler()->handleMouseReleaseEvent(mev.event());
130    return true;
131}
132
133unsigned EventHandler::accessKeyModifiers()
134{
135    return PlatformKeyboardEvent::CtrlKey;
136}
137
138}
139