Changeset 207544 in webkit
- Timestamp:
- Oct 19, 2016 10:46:42 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r207540 r207544 1 2016-10-19 Chris Dumez <cdumez@apple.com> 2 3 MouseEvent's coordinates should be 0 for simulated clicks 4 https://bugs.webkit.org/show_bug.cgi?id=163648 5 6 Reviewed by Darin Adler. 7 8 Add layout test coverage. I verified that this test is passing in 9 Firefox and Chrome as well. 10 11 * fast/events/element-click-no-coords-expected.txt: Added. 12 * fast/events/element-click-no-coords.html: Added. 13 1 14 2016-10-19 Nan Wang <n_wang@apple.com> 2 15 -
trunk/Source/WebCore/ChangeLog
r207543 r207544 1 2016-10-19 Chris Dumez <cdumez@apple.com> 2 3 MouseEvent's coordinates should be 0 for simulated clicks 4 https://bugs.webkit.org/show_bug.cgi?id=163648 5 6 Reviewed by Darin Adler. 7 8 MouseEvent's coordinates should be 0 / 0 for simulated clicks triggered 9 by JavaScript (i.e. via element.click()). This behavior matches Chrome 10 and Firefox. 11 12 WebKit was computing actual coordinates for the element which was 13 expensive, especially because computing screenX / screenY required 14 a synchronous IPC with the UI process. 15 16 Test: fast/events/element-click-no-coords.html 17 18 * dom/Element.cpp: 19 (WebCore::Element::dispatchSimulatedClick): 20 * dom/SimulatedClick.cpp: 21 (WebCore::simulateMouseEvent): 22 (WebCore::simulateClick): 23 * dom/SimulatedClick.h: 24 * html/HTMLElement.cpp: 25 (WebCore::HTMLElement::click): 26 1 27 2016-10-19 Dave Hyatt <hyatt@apple.com> 2 28 -
trunk/Source/WebCore/dom/Element.cpp
r207521 r207544 336 336 void Element::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions eventOptions, SimulatedClickVisualOptions visualOptions) 337 337 { 338 simulateClick(*this, underlyingEvent, eventOptions, visualOptions, SimulatedClick CreationOptions::FromUserAgent);338 simulateClick(*this, underlyingEvent, eventOptions, visualOptions, SimulatedClickSource::UserAgent); 339 339 } 340 340 -
trunk/Source/WebCore/dom/SimulatedClick.cpp
r204681 r207544 39 39 class SimulatedMouseEvent final : public MouseEvent { 40 40 public: 41 static Ref<SimulatedMouseEvent> create(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target )41 static Ref<SimulatedMouseEvent> create(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target, SimulatedClickSource source) 42 42 { 43 return adoptRef(*new SimulatedMouseEvent(eventType, view, WTFMove(underlyingEvent), target ));43 return adoptRef(*new SimulatedMouseEvent(eventType, view, WTFMove(underlyingEvent), target, source)); 44 44 } 45 45 46 46 private: 47 SimulatedMouseEvent(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target )47 SimulatedMouseEvent(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target, SimulatedClickSource source) 48 48 : MouseEvent(eventType, true, true, underlyingEvent ? underlyingEvent->timeStamp() : currentTime(), view, 0, 0, 0, 0, 0, 49 49 #if ENABLE(POINTER_LOCK) … … 52 52 false, false, false, false, 0, 0, 0, 0, 0, true) 53 53 { 54 if (source == SimulatedClickSource::Bindings) 55 setUntrusted(); 56 54 57 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) { 55 58 m_ctrlKey = keyStateEvent->ctrlKey(); … … 64 67 m_screenLocation = mouseEvent.screenLocation(); 65 68 initCoordinates(mouseEvent.clientLocation()); 66 } else { 69 } else if (source == SimulatedClickSource::UserAgent) { 70 // If there is no underlying event, we only populate the coordinates for events coming 71 // from the user agent (e.g. accessibility). For those coming from JavaScript (e.g. 72 // (element.click()), the coordinates will be 0, similarly to Firefox and Chrome. 73 // Note that the call to screenRect() causes a synchronous IPC with the UI process. 67 74 m_screenLocation = target.screenRect().center(); 68 75 initCoordinates(LayoutPoint(target.clientRect().center())); … … 72 79 }; 73 80 74 static void simulateMouseEvent(const AtomicString& eventType, Element& element, Event* underlyingEvent, SimulatedClick CreationOptions creationOptions)81 static void simulateMouseEvent(const AtomicString& eventType, Element& element, Event* underlyingEvent, SimulatedClickSource source) 75 82 { 76 auto event = SimulatedMouseEvent::create(eventType, element.document().defaultView(), underlyingEvent, element); 77 if (creationOptions == SimulatedClickCreationOptions::FromBindings) 78 event.get().setUntrusted(); 79 EventDispatcher::dispatchEvent(&element, event.get()); 83 auto event = SimulatedMouseEvent::create(eventType, element.document().defaultView(), underlyingEvent, element, source); 84 EventDispatcher::dispatchEvent(&element, event); 80 85 } 81 86 82 void simulateClick(Element& element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions, SimulatedClick CreationOptionscreationOptions)87 void simulateClick(Element& element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions, SimulatedClickSource creationOptions) 83 88 { 84 89 if (element.isDisabledFormControl()) -
trunk/Source/WebCore/dom/SimulatedClick.h
r196598 r207544 34 34 class Event; 35 35 36 enum class SimulatedClick CreationOptions{37 FromBindings,38 FromUserAgent36 enum class SimulatedClickSource { 37 Bindings, 38 UserAgent 39 39 }; 40 40 41 void simulateClick(Element&, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions, SimulatedClick CreationOptions);41 void simulateClick(Element&, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions, SimulatedClickSource); 42 42 43 43 } // namespace WebCore -
trunk/Source/WebCore/html/HTMLElement.cpp
r207514 r207544 702 702 void HTMLElement::click() 703 703 { 704 simulateClick(*this, nullptr, SendNoEvents, DoNotShowPressedLook, SimulatedClick CreationOptions::FromBindings);704 simulateClick(*this, nullptr, SendNoEvents, DoNotShowPressedLook, SimulatedClickSource::Bindings); 705 705 } 706 706
Note: See TracChangeset
for help on using the changeset viewer.