2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "EventHandler.h"
30 #include "ChromiumDataObject.h"
31 #include "ClipboardChromium.h"
33 #include "FloatPoint.h"
34 #include "FocusController.h"
36 #include "FrameSelection.h"
37 #include "FrameView.h"
38 #include "HitTestRequest.h"
39 #include "HitTestResult.h"
40 #include "MouseEventWithHitTestResults.h"
41 #include "NotImplemented.h"
43 #include "PlatformKeyboardEvent.h"
44 #include "PlatformWheelEvent.h"
45 #include "RenderWidget.h"
50 const double EventHandler::TextDragDelay = 0.15;
52 const double EventHandler::TextDragDelay = 0.0;
55 bool EventHandler::passMousePressEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe)
57 // If we're clicking into a frame that is selected, the frame will appear
58 // greyed out even though we're clicking on the selection. This looks
59 // really strange (having the whole frame be greyed out), so we deselect the
61 IntPoint p = m_frame->view()->windowToContents(mev.event().pos());
62 if (m_frame->selection()->contains(p)) {
63 VisiblePosition visiblePos(
64 targetNode(mev)->renderer()->positionForPoint(mev.localPoint()));
65 VisibleSelection newSelection(visiblePos);
66 if (m_frame->selection()->shouldChangeSelection(newSelection))
67 m_frame->selection()->setSelection(newSelection);
70 subframe->eventHandler()->handleMousePressEvent(mev.event());
74 bool EventHandler::passMouseMoveEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe, HitTestResult* hoveredNode)
76 if (m_mouseDownMayStartDrag && !m_mouseDownWasInSubframe)
78 subframe->eventHandler()->handleMouseMoveEvent(mev.event(), hoveredNode);
82 bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe)
84 subframe->eventHandler()->handleMouseReleaseEvent(mev.event());
88 bool EventHandler::passWheelEventToWidget(PlatformWheelEvent& wheelEvent, Widget* widget)
90 // We can sometimes get a null widget! EventHandlerMac handles a null
91 // widget by returning false, so we do the same.
95 // If not a FrameView, then probably a plugin widget. Those will receive
96 // the event via an EventTargetNode dispatch when this returns false.
97 if (!widget->isFrameView())
100 return static_cast<FrameView*>(widget)->frame()->eventHandler()->handleWheelEvent(wheelEvent);
103 bool EventHandler::passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults& event)
105 // Figure out which view to send the event to.
106 if (!targetNode(event) || !targetNode(event)->renderer() || !targetNode(event)->renderer()->isWidget())
108 return passMouseDownEventToWidget(toRenderWidget(targetNode(event)->renderer())->widget());
111 bool EventHandler::passMouseDownEventToWidget(Widget* widget)
117 bool EventHandler::tabsToAllFormControls(KeyboardEvent*) const
122 bool EventHandler::eventActivatedView(const PlatformMouseEvent& event) const
124 // FIXME: EventHandlerWin.cpp does the following:
125 // return event.activatedWebView();
129 PassRefPtr<Clipboard> EventHandler::createDraggingClipboard() const
131 RefPtr<ChromiumDataObject> dataObject = ChromiumDataObject::create(Clipboard::DragAndDrop);
132 return ClipboardChromium::create(Clipboard::DragAndDrop, dataObject.get(), ClipboardWritable, m_frame);
135 void EventHandler::focusDocumentView()
137 Page* page = m_frame->page();
140 page->focusController()->setFocusedFrame(m_frame);
143 bool EventHandler::passWidgetMouseDownEventToWidget(RenderWidget* renderWidget)
145 return passMouseDownEventToWidget(renderWidget->widget());
148 unsigned EventHandler::accessKeyModifiers()
151 return PlatformKeyboardEvent::CtrlKey | PlatformKeyboardEvent::AltKey;
153 return PlatformKeyboardEvent::AltKey;
157 #if OS(UNIX) && !OS(DARWIN)
158 // GTK+ must scroll horizontally if the mouse pointer is on top of the
159 // horizontal scrollbar while scrolling with the wheel.
160 // This code comes from gtk/EventHandlerGtk.cpp.
161 bool EventHandler::shouldTurnVerticalTicksIntoHorizontal(const HitTestResult& result) const
163 return result.scrollbar() && result.scrollbar()->orientation() == HorizontalScrollbar;
167 } // namespace WebCore