Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: Source/core/page/EventHandler.cpp

Issue 766143002: Fix contextmenu event location for menu key in an iframe (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 // Clear mouse press state to avoid initiating a drag while context menu is up. 2777 // Clear mouse press state to avoid initiating a drag while context menu is up.
2778 m_mousePressed = false; 2778 m_mousePressed = false;
2779 2779
2780 static const int kContextMenuMargin = 1; 2780 static const int kContextMenuMargin = 1;
2781 2781
2782 #if OS(WIN) 2782 #if OS(WIN)
2783 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT); 2783 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT);
2784 #else 2784 #else
2785 int rightAligned = 0; 2785 int rightAligned = 0;
2786 #endif 2786 #endif
2787 IntPoint location; 2787 IntPoint rootViewLocation;
2788
2789 Element* focusedElement = doc->focusedElement(); 2788 Element* focusedElement = doc->focusedElement();
2790 FrameSelection& selection = m_frame->selection(); 2789 FrameSelection& selection = m_frame->selection();
2791 Position start = selection.selection().start(); 2790 Position start = selection.selection().start();
2792 bool shouldTranslateToRootView = true;
2793 2791
2794 if (start.deprecatedNode() && (selection.rootEditableElement() || selection. isRange())) { 2792 if (start.deprecatedNode() && (selection.rootEditableElement() || selection. isRange())) {
2795 RefPtrWillBeRawPtr<Range> selectionRange = selection.toNormalizedRange() ; 2793 RefPtrWillBeRawPtr<Range> selectionRange = selection.toNormalizedRange() ;
2796 IntRect firstRect = m_frame->editor().firstRectForRange(selectionRange.g et()); 2794 IntRect firstRect = m_frame->editor().firstRectForRange(selectionRange.g et());
2797 2795
2798 int x = rightAligned ? firstRect.maxX() : firstRect.x(); 2796 int x = rightAligned ? firstRect.maxX() : firstRect.x();
2799 // In a multiline edit, firstRect.maxY() would endup on the next line, s o -1. 2797 // In a multiline edit, firstRect.maxY() would endup on the next line, s o -1.
2800 int y = firstRect.maxY() ? firstRect.maxY() - 1 : 0; 2798 int y = firstRect.maxY() ? firstRect.maxY() - 1 : 0;
2801 location = IntPoint(x, y); 2799 rootViewLocation = view->contentsToRootView(IntPoint(x, y));
2802 } else if (focusedElement) { 2800 } else if (focusedElement) {
2803 IntRect clippedRect = focusedElement->boundsInRootViewSpace(); 2801 IntRect clippedRect = focusedElement->boundsInRootViewSpace();
2804 location = IntPoint(clippedRect.center()); 2802 rootViewLocation = IntPoint(clippedRect.center());
2805 } else { 2803 } else {
2806 location = IntPoint( 2804 rootViewLocation = IntPoint(
2807 rightAligned ? view->contentsWidth() - kContextMenuMargin : kContext MenuMargin, 2805 rightAligned ? view->contentsWidth() - kContextMenuMargin : kContext MenuMargin,
2808 kContextMenuMargin); 2806 kContextMenuMargin);
2809 shouldTranslateToRootView = false;
2810 } 2807 }
2811 2808
2812 m_frame->view()->setCursor(pointerCursor()); 2809 m_frame->view()->setCursor(pointerCursor());
2813 2810 IntPoint globalPosition = view->hostWindow()->rootViewToScreen(IntRect(rootV iewLocation, IntSize())).location();
2814 IntPoint position = shouldTranslateToRootView ? view->contentsToRootView(loc ation) : location;
2815 IntPoint globalPosition = view->hostWindow()->rootViewToScreen(IntRect(posit ion, IntSize())).location();
2816 2811
2817 Node* targetNode = doc->focusedElement(); 2812 Node* targetNode = doc->focusedElement();
2818 if (!targetNode) 2813 if (!targetNode)
2819 targetNode = doc; 2814 targetNode = doc;
2820 2815
2821 // Use the focused node as the target for hover and active. 2816 // Use the focused node as the target for hover and active.
2822 HitTestResult result(position); 2817 HitTestResult result(rootViewLocation);
2823 result.setInnerNode(targetNode); 2818 result.setInnerNode(targetNode);
2824 doc->updateHoverActiveState(HitTestRequest::Active, result.innerElement()); 2819 doc->updateHoverActiveState(HitTestRequest::Active, result.innerElement());
2825 2820
2826 // The contextmenu event is a mouse event even when invoked using the keyboa rd. 2821 // The contextmenu event is a mouse event even when invoked using the keyboa rd.
2827 // This is required for web compatibility. 2822 // This is required for web compatibility.
2828 PlatformEvent::Type eventType = PlatformEvent::MousePressed; 2823 PlatformEvent::Type eventType = PlatformEvent::MousePressed;
2829 if (m_frame->settings()->showContextMenuOnMouseUp()) 2824 if (m_frame->settings()->showContextMenuOnMouseUp())
2830 eventType = PlatformEvent::MouseReleased; 2825 eventType = PlatformEvent::MouseReleased;
2831 2826
2832 PlatformMouseEvent mouseEvent(position, globalPosition, RightButton, eventTy pe, 1, false, false, false, false, PlatformMouseEvent::RealOrIndistinguishable, WTF::currentTime()); 2827 PlatformMouseEvent mouseEvent(rootViewLocation, globalPosition, RightButton, eventType, 1, false, false, false, false, PlatformMouseEvent::RealOrIndistingui shable, WTF::currentTime());
2833 2828
2834 handleMousePressEvent(mouseEvent); 2829 handleMousePressEvent(mouseEvent);
2835 return sendContextMenuEvent(mouseEvent); 2830 return sendContextMenuEvent(mouseEvent);
2836 } 2831 }
2837 2832
2838 bool EventHandler::sendContextMenuEventForGesture(const GestureEventWithHitTestR esults& targetedEvent) 2833 bool EventHandler::sendContextMenuEventForGesture(const GestureEventWithHitTestR esults& targetedEvent)
2839 { 2834 {
2840 unsigned modifiers = targetedEvent.event().modifiers(); 2835 unsigned modifiers = targetedEvent.event().modifiers();
2841 PlatformEvent::Type eventType = PlatformEvent::MousePressed; 2836 PlatformEvent::Type eventType = PlatformEvent::MousePressed;
2842 2837
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
3884 unsigned EventHandler::accessKeyModifiers() 3879 unsigned EventHandler::accessKeyModifiers()
3885 { 3880 {
3886 #if OS(MACOSX) 3881 #if OS(MACOSX)
3887 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3882 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3888 #else 3883 #else
3889 return PlatformEvent::AltKey; 3884 return PlatformEvent::AltKey;
3890 #endif 3885 #endif
3891 } 3886 }
3892 3887
3893 } // namespace blink 3888 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698