| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 { | 1338 { |
| 1339 IntPoint contentsPos = m_frame->view()->windowToContents(event.pos()); | 1339 IntPoint contentsPos = m_frame->view()->windowToContents(event.pos()); |
| 1340 | 1340 |
| 1341 RefPtr<MouseEvent> me = MouseEvent::create(eventType, | 1341 RefPtr<MouseEvent> me = MouseEvent::create(eventType, |
| 1342 true, true, m_frame->document()->defaultView(), | 1342 true, true, m_frame->document()->defaultView(), |
| 1343 0, event.globalX(), event.globalY(), contentsPos.x(), contentsPos.y(), | 1343 0, event.globalX(), event.globalY(), contentsPos.x(), contentsPos.y(), |
| 1344 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), | 1344 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), |
| 1345 0, 0, clipboard); | 1345 0, 0, clipboard); |
| 1346 | 1346 |
| 1347 ExceptionCode ec = 0; | 1347 ExceptionCode ec = 0; |
| 1348 dragTarget->dispatchEvent(me.get(), ec); | 1348 EventTargetNodeCast(dragTarget)->dispatchEvent(me.get(), ec); |
| 1349 return me->defaultPrevented(); | 1349 return me->defaultPrevented(); |
| 1350 } | 1350 } |
| 1351 | 1351 |
| 1352 bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard*
clipboard) | 1352 bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard*
clipboard) |
| 1353 { | 1353 { |
| 1354 bool accept = false; | 1354 bool accept = false; |
| 1355 | 1355 |
| 1356 if (!m_frame->document()) | 1356 if (!m_frame->document()) |
| 1357 return false; | 1357 return false; |
| 1358 | 1358 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 m_lastNodeUnderMouse = 0; | 1525 m_lastNodeUnderMouse = 0; |
| 1526 m_lastScrollbarUnderMouse = 0; | 1526 m_lastScrollbarUnderMouse = 0; |
| 1527 #if ENABLE(SVG) | 1527 #if ENABLE(SVG) |
| 1528 m_lastInstanceUnderMouse = 0; | 1528 m_lastInstanceUnderMouse = 0; |
| 1529 #endif | 1529 #endif |
| 1530 } | 1530 } |
| 1531 | 1531 |
| 1532 if (m_lastNodeUnderMouse != m_nodeUnderMouse) { | 1532 if (m_lastNodeUnderMouse != m_nodeUnderMouse) { |
| 1533 // send mouseout event to the old node | 1533 // send mouseout event to the old node |
| 1534 if (m_lastNodeUnderMouse) | 1534 if (m_lastNodeUnderMouse) |
| 1535 m_lastNodeUnderMouse->dispatchMouseEvent(mouseEvent, eventNames(
).mouseoutEvent, 0, m_nodeUnderMouse.get()); | 1535 EventTargetNodeCast(m_lastNodeUnderMouse.get())->dispatchMouseEv
ent(mouseEvent, eventNames().mouseoutEvent, 0, m_nodeUnderMouse.get()); |
| 1536 // send mouseover event to the new node | 1536 // send mouseover event to the new node |
| 1537 if (m_nodeUnderMouse) | 1537 if (m_nodeUnderMouse) |
| 1538 m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, eventNames().mo
useoverEvent, 0, m_lastNodeUnderMouse.get()); | 1538 EventTargetNodeCast(m_nodeUnderMouse.get())->dispatchMouseEvent(
mouseEvent, eventNames().mouseoverEvent, 0, m_lastNodeUnderMouse.get()); |
| 1539 } | 1539 } |
| 1540 m_lastNodeUnderMouse = m_nodeUnderMouse; | 1540 m_lastNodeUnderMouse = m_nodeUnderMouse; |
| 1541 #if ENABLE(SVG) | 1541 #if ENABLE(SVG) |
| 1542 m_lastInstanceUnderMouse = instanceAssociatedWithShadowTreeElement(m_nod
eUnderMouse.get()); | 1542 m_lastInstanceUnderMouse = instanceAssociatedWithShadowTreeElement(m_nod
eUnderMouse.get()); |
| 1543 #endif | 1543 #endif |
| 1544 } | 1544 } |
| 1545 } | 1545 } |
| 1546 | 1546 |
| 1547 bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe
tNode, bool /*cancelable*/, int clickCount, const PlatformMouseEvent& mouseEvent
, bool setUnder) | 1547 bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe
tNode, bool /*cancelable*/, int clickCount, const PlatformMouseEvent& mouseEvent
, bool setUnder) |
| 1548 { | 1548 { |
| 1549 updateMouseEventTargetNode(targetNode, mouseEvent, setUnder); | 1549 updateMouseEventTargetNode(targetNode, mouseEvent, setUnder); |
| 1550 | 1550 |
| 1551 bool swallowEvent = false; | 1551 bool swallowEvent = false; |
| 1552 | 1552 |
| 1553 if (m_nodeUnderMouse) | 1553 if (m_nodeUnderMouse) |
| 1554 swallowEvent = m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, eventTyp
e, clickCount); | 1554 swallowEvent = EventTargetNodeCast(m_nodeUnderMouse.get())->dispatchMous
eEvent(mouseEvent, eventType, clickCount); |
| 1555 | 1555 |
| 1556 if (!swallowEvent && eventType == eventNames().mousedownEvent) { | 1556 if (!swallowEvent && eventType == eventNames().mousedownEvent) { |
| 1557 // Blur current focus node when a link/button is clicked; this | 1557 // Blur current focus node when a link/button is clicked; this |
| 1558 // is expected by some sites that rely on onChange handlers running | 1558 // is expected by some sites that rely on onChange handlers running |
| 1559 // from form fields before the button click is processed. | 1559 // from form fields before the button click is processed. |
| 1560 Node* node = m_nodeUnderMouse.get(); | 1560 Node* node = m_nodeUnderMouse.get(); |
| 1561 RenderObject* renderer = node ? node->renderer() : 0; | 1561 RenderObject* renderer = node ? node->renderer() : 0; |
| 1562 | 1562 |
| 1563 // Walk up the render tree to search for a node to focus. | 1563 // Walk up the render tree to search for a node to focus. |
| 1564 // Walking up the DOM tree wouldn't work for shadow trees, like those be
hind the engine-based text fields. | 1564 // Walking up the DOM tree wouldn't work for shadow trees, like those be
hind the engine-based text fields. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 if (result.isOverWidget() && target && target->isWidget()) { | 1621 if (result.isOverWidget() && target && target->isWidget()) { |
| 1622 Widget* widget = static_cast<RenderWidget*>(target)->widget(); | 1622 Widget* widget = static_cast<RenderWidget*>(target)->widget(); |
| 1623 | 1623 |
| 1624 if (widget && passWheelEventToWidget(e, widget)) { | 1624 if (widget && passWheelEventToWidget(e, widget)) { |
| 1625 e.accept(); | 1625 e.accept(); |
| 1626 return true; | 1626 return true; |
| 1627 } | 1627 } |
| 1628 } | 1628 } |
| 1629 | 1629 |
| 1630 node = node->shadowAncestorNode(); | 1630 node = node->shadowAncestorNode(); |
| 1631 node->dispatchWheelEvent(e); | 1631 EventTargetNodeCast(node)->dispatchWheelEvent(e); |
| 1632 if (e.isAccepted()) | 1632 if (e.isAccepted()) |
| 1633 return true; | 1633 return true; |
| 1634 | 1634 |
| 1635 if (node->renderer()) { | 1635 if (node->renderer()) { |
| 1636 // Just break up into two scrolls if we need to. Diagonal movement
on | 1636 // Just break up into two scrolls if we need to. Diagonal movement
on |
| 1637 // a MacBook pro is an example of a 2-dimensional mouse wheel event
(where both deltaX and deltaY can be set). | 1637 // a MacBook pro is an example of a 2-dimensional mouse wheel event
(where both deltaX and deltaY can be set). |
| 1638 scrollAndAcceptEvent(e.deltaX(), ScrollLeft, ScrollRight, e, node); | 1638 scrollAndAcceptEvent(e.deltaX(), ScrollLeft, ScrollRight, e, node); |
| 1639 scrollAndAcceptEvent(e.deltaY(), ScrollUp, ScrollDown, e, node); | 1639 scrollAndAcceptEvent(e.deltaY(), ScrollUp, ScrollDown, e, node); |
| 1640 } | 1640 } |
| 1641 } | 1641 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 // Whether or not a mouse down can begin the creation of a selection. Fires the
selectStart event. | 1686 // Whether or not a mouse down can begin the creation of a selection. Fires the
selectStart event. |
| 1687 bool EventHandler::canMouseDownStartSelect(Node* node) | 1687 bool EventHandler::canMouseDownStartSelect(Node* node) |
| 1688 { | 1688 { |
| 1689 if (!node || !node->renderer()) | 1689 if (!node || !node->renderer()) |
| 1690 return true; | 1690 return true; |
| 1691 | 1691 |
| 1692 // Some controls and images can't start a select on a mouse down. | 1692 // Some controls and images can't start a select on a mouse down. |
| 1693 if (!node->canStartSelection()) | 1693 if (!node->canStartSelection()) |
| 1694 return false; | 1694 return false; |
| 1695 | 1695 |
| 1696 for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) { | 1696 for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) |
| 1697 if (Node* node = curr->element()) | 1697 if (Node* node = curr->element()) |
| 1698 return node->dispatchEventForType(eventNames().selectstartEvent, tru
e, true); | 1698 return EventTargetNodeCast(node)->dispatchEventForType(eventNames().
selectstartEvent, true, true); |
| 1699 } | 1699 |
| 1700 | |
| 1701 return true; | 1700 return true; |
| 1702 } | 1701 } |
| 1703 | 1702 |
| 1704 bool EventHandler::canMouseDragExtendSelect(Node* node) | 1703 bool EventHandler::canMouseDragExtendSelect(Node* node) |
| 1705 { | 1704 { |
| 1706 if (!node || !node->renderer()) | 1705 if (!node || !node->renderer()) |
| 1707 return true; | 1706 return true; |
| 1708 | 1707 |
| 1709 for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) { | 1708 for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) |
| 1710 if (Node* node = curr->element()) | 1709 if (Node* node = curr->element()) |
| 1711 return node->dispatchEventForType(eventNames().selectstartEvent, tru
e, true); | 1710 return EventTargetNodeCast(node)->dispatchEventForType(eventNames().
selectstartEvent, true, true); |
| 1712 } | 1711 |
| 1713 | |
| 1714 return true; | 1712 return true; |
| 1715 } | 1713 } |
| 1716 | 1714 |
| 1717 void EventHandler::setResizingFrameSet(HTMLFrameSetElement* frameSet) | 1715 void EventHandler::setResizingFrameSet(HTMLFrameSetElement* frameSet) |
| 1718 { | 1716 { |
| 1719 m_frameSetBeingResized = frameSet; | 1717 m_frameSetBeingResized = frameSet; |
| 1720 } | 1718 } |
| 1721 | 1719 |
| 1722 void EventHandler::resizeLayerDestroyed() | 1720 void EventHandler::resizeLayerDestroyed() |
| 1723 { | 1721 { |
| 1724 ASSERT(m_resizeLayer); | 1722 ASSERT(m_resizeLayer); |
| 1725 m_resizeLayer = 0; | 1723 m_resizeLayer = 0; |
| 1726 } | 1724 } |
| 1727 | 1725 |
| 1728 void EventHandler::hoverTimerFired(Timer<EventHandler>*) | 1726 void EventHandler::hoverTimerFired(Timer<EventHandler>*) |
| 1729 { | 1727 { |
| 1730 m_hoverTimer.stop(); | 1728 m_hoverTimer.stop(); |
| 1731 | 1729 |
| 1732 ASSERT(m_frame); | 1730 ASSERT(m_frame); |
| 1733 ASSERT(m_frame->document()); | 1731 ASSERT(m_frame->document()); |
| 1734 | 1732 |
| 1735 if (RenderView* renderer = m_frame->contentRenderer()) { | 1733 if (RenderView* renderer = m_frame->contentRenderer()) { |
| 1736 HitTestRequest request(HitTestRequest::MouseMove); | 1734 HitTestRequest request(HitTestRequest::MouseMove); |
| 1737 HitTestResult result(m_frame->view()->windowToContents(m_currentMousePos
ition)); | 1735 HitTestResult result(m_frame->view()->windowToContents(m_currentMousePos
ition)); |
| 1738 renderer->layer()->hitTest(request, result); | 1736 renderer->layer()->hitTest(request, result); |
| 1739 m_frame->document()->updateRendering(); | 1737 m_frame->document()->updateRendering(); |
| 1740 } | 1738 } |
| 1741 } | 1739 } |
| 1742 | 1740 |
| 1743 static Node* eventTargetNodeForDocument(Document* doc) | 1741 static EventTargetNode* eventTargetNodeForDocument(Document* doc) |
| 1744 { | 1742 { |
| 1745 if (!doc) | 1743 if (!doc) |
| 1746 return 0; | 1744 return 0; |
| 1747 Node* node = doc->focusedNode(); | 1745 Node* node = doc->focusedNode(); |
| 1748 if (!node) { | 1746 if (!node) { |
| 1749 if (doc->isHTMLDocument()) | 1747 if (doc->isHTMLDocument()) |
| 1750 node = doc->body(); | 1748 node = doc->body(); |
| 1751 else | 1749 else |
| 1752 node = doc->documentElement(); | 1750 node = doc->documentElement(); |
| 1753 if (!node) | 1751 if (!node) |
| 1754 return 0; | 1752 return 0; |
| 1755 } | 1753 } |
| 1756 return node; | 1754 return EventTargetNodeCast(node); |
| 1757 } | 1755 } |
| 1758 | 1756 |
| 1759 bool EventHandler::handleAccessKey(const PlatformKeyboardEvent& evt) | 1757 bool EventHandler::handleAccessKey(const PlatformKeyboardEvent& evt) |
| 1760 { | 1758 { |
| 1761 // FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do. | 1759 // FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do. |
| 1762 // IE matches lower and upper case access keys regardless of Shift key state
- but if both upper and | 1760 // IE matches lower and upper case access keys regardless of Shift key state
- but if both upper and |
| 1763 // lower case variants are present in a document, the correct element is mat
ched based on Shift key state. | 1761 // lower case variants are present in a document, the correct element is mat
ched based on Shift key state. |
| 1764 // Firefox only matches an access key if Shift is not pressed, and does that
case-insensitively. | 1762 // Firefox only matches an access key if Shift is not pressed, and does that
case-insensitively. |
| 1765 ASSERT(!(accessKeyModifiers() & PlatformKeyboardEvent::ShiftKey)); | 1763 ASSERT(!(accessKeyModifiers() & PlatformKeyboardEvent::ShiftKey)); |
| 1766 if ((evt.modifiers() & ~PlatformKeyboardEvent::ShiftKey) != accessKeyModifie
rs()) | 1764 if ((evt.modifiers() & ~PlatformKeyboardEvent::ShiftKey) != accessKeyModifie
rs()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1789 if (initialKeyEvent.keyIdentifier() == escKeyId && initialKeyEvent.type(
) == PlatformKeyboardEvent::KeyUp) | 1787 if (initialKeyEvent.keyIdentifier() == escKeyId && initialKeyEvent.type(
) == PlatformKeyboardEvent::KeyUp) |
| 1790 stopAutoscrollTimer(); | 1788 stopAutoscrollTimer(); |
| 1791 | 1789 |
| 1792 // If we were in autoscroll/panscroll mode, we swallow the key event | 1790 // If we were in autoscroll/panscroll mode, we swallow the key event |
| 1793 return true; | 1791 return true; |
| 1794 } | 1792 } |
| 1795 #endif | 1793 #endif |
| 1796 | 1794 |
| 1797 // Check for cases where we are too early for events -- possible unmatched k
ey up | 1795 // Check for cases where we are too early for events -- possible unmatched k
ey up |
| 1798 // from pressing return in the location bar. | 1796 // from pressing return in the location bar. |
| 1799 RefPtr<Node> node = eventTargetNodeForDocument(m_frame->document()); | 1797 RefPtr<EventTargetNode> node = eventTargetNodeForDocument(m_frame->document(
)); |
| 1800 if (!node) | 1798 if (!node) |
| 1801 return false; | 1799 return false; |
| 1802 | 1800 |
| 1803 // FIXME: what is this doing here, in keyboard event handler? | 1801 // FIXME: what is this doing here, in keyboard event handler? |
| 1804 m_frame->loader()->resetMultipleFormSubmissionProtection(); | 1802 m_frame->loader()->resetMultipleFormSubmissionProtection(); |
| 1805 | 1803 |
| 1806 // In IE, access keys are special, they are handled after default keydown pr
ocessing, but cannot be canceled - this is hard to match. | 1804 // In IE, access keys are special, they are handled after default keydown pr
ocessing, but cannot be canceled - this is hard to match. |
| 1807 // On Mac OS X, we process them before dispatching keydown, as the default k
eydown handler implements Emacs key bindings, which may conflict | 1805 // On Mac OS X, we process them before dispatching keydown, as the default k
eydown handler implements Emacs key bindings, which may conflict |
| 1808 // with access keys. Then we dispatch keydown, but suppress its default hand
ling. | 1806 // with access keys. Then we dispatch keydown, but suppress its default hand
ling. |
| 1809 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch
ing a keypress event for WM_SYSCHAR messages. | 1807 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch
ing a keypress event for WM_SYSCHAR messages. |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2314 } | 2312 } |
| 2315 | 2313 |
| 2316 bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults&
mev, Scrollbar* scrollbar) | 2314 bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults&
mev, Scrollbar* scrollbar) |
| 2317 { | 2315 { |
| 2318 if (!scrollbar || !scrollbar->enabled()) | 2316 if (!scrollbar || !scrollbar->enabled()) |
| 2319 return false; | 2317 return false; |
| 2320 return scrollbar->mouseDown(mev.event()); | 2318 return scrollbar->mouseDown(mev.event()); |
| 2321 } | 2319 } |
| 2322 | 2320 |
| 2323 } | 2321 } |
| OLD | NEW |