Commit 12f9cbe6 authored by Navid Zolghadr's avatar Navid Zolghadr Committed by Commit Bot

Remove WebMouseEvent from MouseEvent.h

Remove the WebMouseEvent dependency in MouseEvent
and all its subclasses like DragEvent and WheelEvent.

Bug: 820249
Change-Id: Icc62baea6862901cb91a531f7b649c6858ee94dd
Reviewed-on: https://chromium-review.googlesource.com/956543
Commit-Queue: Navid Zolghadr <nzolghadr@chromium.org>
Reviewed-by: default avatarElla Ge <eirage@chromium.org>
Reviewed-by: default avatarMustaq Ahmed <mustaq@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546103}
parent 2b62de0b
...@@ -12,137 +12,281 @@ TEST COMPLETE ...@@ -12,137 +12,281 @@ TEST COMPLETE
pointermove of mouse is received: pointermove of mouse is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mousemove is received: mousemove is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
pointerdown of mouse is received: pointerdown of mouse is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mousedown is received: mousedown is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
pointerup of mouse is received: pointerup of mouse is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mouseup is received: mouseup is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
*** Touch events inside iframe *** *** Touch events inside iframe ***
pointerdown of touch is received: pointerdown of touch is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchstart is received: touchstart is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
pointermove of touch is received: pointermove of touch is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchmove is received: touchmove is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
pointerup of touch is received: pointerup of touch is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchend is received: touchend is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 175
pageY = 200
screenX = 200
screenY = 200
===== scrollX=40, scrollY=140, zoomFactor=1 ===== scrollX=40, scrollY=140, zoomFactor=1
*** Mouse events inside iframe *** *** Mouse events inside iframe ***
pointermove of mouse is received: pointermove of mouse is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mousemove is received: mousemove is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
pointerdown of mouse is received: pointerdown of mouse is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mousedown is received: mousedown is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
pointerup of mouse is received: pointerup of mouse is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mouseup is received: mouseup is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
*** Touch events inside iframe *** *** Touch events inside iframe ***
pointerdown of touch is received: pointerdown of touch is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchstart is received: touchstart is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
pointermove of touch is received: pointermove of touch is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchmove is received: touchmove is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
pointerup of touch is received: pointerup of touch is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchend is received: touchend is received:
clientX = 150 clientX = 150
clientY = 100 clientY = 100
pageX = 190
pageY = 240
screenX = 200
screenY = 200
===== scrollX=40, scrollY=140, zoomFactor=2 ===== scrollX=40, scrollY=140, zoomFactor=2
*** Mouse events inside iframe *** *** Mouse events inside iframe ***
pointermove of mouse is received: pointermove of mouse is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mousemove is received: mousemove is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
pointerdown of mouse is received: pointerdown of mouse is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mousedown is received: mousedown is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
pointerup of mouse is received: pointerup of mouse is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
mouseup is received: mouseup is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
*** Touch events inside iframe *** *** Touch events inside iframe ***
pointerdown of touch is received: pointerdown of touch is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchstart is received: touchstart is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
pointermove of touch is received: pointermove of touch is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchmove is received: touchmove is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
pointerup of touch is received: pointerup of touch is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
view.name = innerFrame view.name = innerFrame
touchend is received: touchend is received:
clientX = 50 clientX = 50
clientY = 0 clientY = 0
pageX = 90
pageY = 140
screenX = 200
screenY = 200
...@@ -34,7 +34,11 @@ window.name = 'outerFrame'; ...@@ -34,7 +34,11 @@ window.name = 'outerFrame';
var attributes = [ var attributes = [
'clientX', 'clientX',
'clientY' 'clientY',
'pageX',
'pageY',
'screenX',
'screenY'
]; ];
document.events = []; document.events = [];
......
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
#include "core/html/custom/CustomElement.h" #include "core/html/custom/CustomElement.h"
#include "core/html_names.h" #include "core/html_names.h"
#include "core/input/EventHandler.h" #include "core/input/EventHandler.h"
#include "core/input/InputDeviceCapabilities.h"
#include "core/layout/LayoutBox.h" #include "core/layout/LayoutBox.h"
#include "core/layout/LayoutEmbeddedContent.h" #include "core/layout/LayoutEmbeddedContent.h"
#include "core/mathml_names.h" #include "core/mathml_names.h"
...@@ -2351,16 +2352,47 @@ void Node::CreateAndDispatchPointerEvent(const AtomicString& mouse_event_name, ...@@ -2351,16 +2352,47 @@ void Node::CreateAndDispatchPointerEvent(const AtomicString& mouse_event_name,
DispatchEvent(PointerEvent::Create(pointer_event_name, pointer_event_init)); DispatchEvent(PointerEvent::Create(pointer_event_name, pointer_event_init));
} }
void Node::DispatchMouseEvent(const WebMouseEvent& native_event, // TODO(crbug.com/665924): This function bypasses all Blink event path.
// It should be using that flow instead of creating/sending events directly.
void Node::DispatchMouseEvent(const WebMouseEvent& event,
const AtomicString& mouse_event_type, const AtomicString& mouse_event_type,
int detail, int detail,
const String& canvas_region_id, const String& canvas_region_id,
Node* related_target) { Node* related_target) {
CreateAndDispatchPointerEvent(mouse_event_type, native_event, CreateAndDispatchPointerEvent(mouse_event_type, event,
GetDocument().domWindow()); GetDocument().domWindow());
DispatchEvent(MouseEvent::Create(mouse_event_type, GetDocument().domWindow(),
native_event, detail, canvas_region_id, bool is_mouse_enter_or_leave =
related_target)); mouse_event_type == EventTypeNames::mouseenter ||
mouse_event_type == EventTypeNames::mouseleave;
MouseEventInit initializer;
initializer.setBubbles(!is_mouse_enter_or_leave);
initializer.setCancelable(!is_mouse_enter_or_leave);
MouseEvent::SetCoordinatesFromWebPointerProperties(
event.FlattenTransform(), GetDocument().domWindow(), initializer);
initializer.setButton(static_cast<short>(event.button));
initializer.setButtons(
MouseEvent::WebInputEventModifiersToButtons(event.GetModifiers()));
initializer.setView(GetDocument().domWindow());
initializer.setDetail(detail);
initializer.setComposed(true);
initializer.setRegion(canvas_region_id);
initializer.setRelatedTarget(related_target);
UIEventWithKeyState::SetFromWebInputEventModifiers(
initializer, static_cast<WebInputEvent::Modifiers>(event.GetModifiers()));
initializer.setSourceCapabilities(
GetDocument().domWindow() ? GetDocument()
.domWindow()
->GetInputDeviceCapabilities()
->FiresTouchEvents(event.FromTouch())
: nullptr);
DispatchEvent(MouseEvent::Create(
mouse_event_type, initializer,
TimeTicksFromSeconds(event.TimeStampSeconds()),
event.FromTouch() ? MouseEvent::kFromTouch
: MouseEvent::kRealOrIndistinguishable,
event.menu_source_type));
} }
void Node::DispatchSimulatedClick(Event* underlying_event, void Node::DispatchSimulatedClick(Event* underlying_event,
......
...@@ -10,80 +10,13 @@ ...@@ -10,80 +10,13 @@
namespace blink { namespace blink {
DragEvent* DragEvent::Create(const AtomicString& type,
Bubbles bubbles,
Cancelable cancelable,
AbstractView* view,
int detail,
double screen_x,
double screen_y,
double window_x,
double window_y,
double movement_x,
double movement_y,
WebInputEvent::Modifiers modifiers,
short button,
unsigned short buttons,
EventTarget* related_target,
TimeTicks platform_time_stamp,
DataTransfer* data_transfer,
SyntheticEventType synthetic_event_type) {
return new DragEvent(
type, bubbles, cancelable, view, detail, screen_x, screen_y, window_x,
window_y, movement_x, movement_y, modifiers, button, buttons,
related_target, platform_time_stamp, data_transfer, synthetic_event_type);
}
DragEvent::DragEvent() : data_transfer_(nullptr) {} DragEvent::DragEvent() : data_transfer_(nullptr) {}
DragEvent::DragEvent(DataTransfer* data_transfer) DragEvent::DragEvent(const AtomicString& type,
: data_transfer_(data_transfer) {} const DragEventInit& initializer,
DragEvent::DragEvent(const AtomicString& event_type,
Bubbles bubbles,
Cancelable cancelable,
AbstractView* view,
int detail,
double screen_x,
double screen_y,
double window_x,
double window_y,
double movement_x,
double movement_y,
WebInputEvent::Modifiers modifiers,
short button,
unsigned short buttons,
EventTarget* related_target,
TimeTicks platform_time_stamp, TimeTicks platform_time_stamp,
DataTransfer* data_transfer,
SyntheticEventType synthetic_event_type) SyntheticEventType synthetic_event_type)
: MouseEvent( : MouseEvent(type, initializer, platform_time_stamp, synthetic_event_type),
event_type,
bubbles,
cancelable,
view,
detail,
screen_x,
screen_y,
window_x,
window_y,
movement_x,
movement_y,
modifiers,
button,
buttons,
related_target,
platform_time_stamp,
synthetic_event_type,
// TODO(zino): Should support canvas hit region because the drag event
// is a kind of mouse event. Please see http://crbug.com/594073
String()),
data_transfer_(data_transfer)
{}
DragEvent::DragEvent(const AtomicString& type, const DragEventInit& initializer)
: MouseEvent(type, initializer),
data_transfer_(initializer.getDataTransfer()) {} data_transfer_(initializer.getDataTransfer()) {}
bool DragEvent::IsDragEvent() const { bool DragEvent::IsDragEvent() const {
......
...@@ -19,32 +19,18 @@ class CORE_EXPORT DragEvent final : public MouseEvent { ...@@ -19,32 +19,18 @@ class CORE_EXPORT DragEvent final : public MouseEvent {
public: public:
static DragEvent* Create() { return new DragEvent; } static DragEvent* Create() { return new DragEvent; }
static DragEvent* Create(DataTransfer* data_transfer) {
return new DragEvent(data_transfer);
}
static DragEvent* Create(const AtomicString& type, static DragEvent* Create(const AtomicString& type,
Bubbles, const DragEventInit& initializer,
Cancelable,
AbstractView*,
int detail,
double screen_x,
double screen_y,
double window_x,
double window_y,
double movement_x,
double movement_y,
WebInputEvent::Modifiers,
short button,
unsigned short buttons,
EventTarget* related_target,
TimeTicks platform_time_stamp, TimeTicks platform_time_stamp,
DataTransfer*, SyntheticEventType synthetic_event_type) {
SyntheticEventType = kRealOrIndistinguishable); return new DragEvent(type, initializer, platform_time_stamp,
synthetic_event_type);
}
static DragEvent* Create(const AtomicString& type, static DragEvent* Create(const AtomicString& type,
const DragEventInit& initializer) { const DragEventInit& initializer) {
return new DragEvent(type, initializer); return new DragEvent(type, initializer, CurrentTimeTicks(),
kRealOrIndistinguishable);
} }
DataTransfer* getDataTransfer() const override { DataTransfer* getDataTransfer() const override {
...@@ -60,28 +46,11 @@ class CORE_EXPORT DragEvent final : public MouseEvent { ...@@ -60,28 +46,11 @@ class CORE_EXPORT DragEvent final : public MouseEvent {
private: private:
DragEvent(); DragEvent();
DragEvent(DataTransfer*);
DragEvent(const AtomicString& type, DragEvent(const AtomicString& type,
Bubbles, const DragEventInit&,
Cancelable,
AbstractView*,
int detail,
double screen_x,
double screen_y,
double window_x,
double window_y,
double movement_x,
double movement_y,
WebInputEvent::Modifiers,
short button,
unsigned short buttons,
EventTarget* related_target,
TimeTicks platform_time_stamp, TimeTicks platform_time_stamp,
DataTransfer*,
SyntheticEventType); SyntheticEventType);
DragEvent(const AtomicString& type, const DragEventInit&);
Member<DataTransfer> data_transfer_; Member<DataTransfer> data_transfer_;
}; };
......
...@@ -94,18 +94,12 @@ MouseEvent* MouseEvent::Create(ScriptState* script_state, ...@@ -94,18 +94,12 @@ MouseEvent* MouseEvent::Create(ScriptState* script_state,
} }
MouseEvent* MouseEvent::Create(const AtomicString& event_type, MouseEvent* MouseEvent::Create(const AtomicString& event_type,
AbstractView* view, const MouseEventInit& initializer,
const WebMouseEvent& event, TimeTicks platform_time_stamp,
int detail, SyntheticEventType synthetic_event_type,
const String& canvas_region_id, WebMenuSourceType menu_source_type) {
Node* related_target) { return new MouseEvent(event_type, initializer, platform_time_stamp,
bool is_mouse_enter_or_leave = event_type == EventTypeNames::mouseenter || synthetic_event_type, menu_source_type);
event_type == EventTypeNames::mouseleave;
Cancelable cancelable =
(!is_mouse_enter_or_leave) ? Cancelable::kYes : Cancelable::kNo;
Bubbles bubbles = (!is_mouse_enter_or_leave) ? Bubbles::kYes : Bubbles::kNo;
return new MouseEvent(event_type, bubbles, cancelable, view, event, detail,
canvas_region_id, related_target);
} }
MouseEvent* MouseEvent::Create(const AtomicString& event_type, MouseEvent* MouseEvent::Create(const AtomicString& event_type,
...@@ -128,12 +122,19 @@ MouseEvent* MouseEvent::Create(const AtomicString& event_type, ...@@ -128,12 +122,19 @@ MouseEvent* MouseEvent::Create(const AtomicString& event_type,
screen_y = mouse_event->screenY(); screen_y = mouse_event->screenY();
} }
MouseEventInit initializer;
initializer.setBubbles(true);
initializer.setCancelable(true);
initializer.setScreenX(screen_x);
initializer.setScreenY(screen_y);
initializer.setView(view);
initializer.setComposed(true);
UIEventWithKeyState::SetFromWebInputEventModifiers(initializer, modifiers);
TimeTicks timestamp = underlying_event ? underlying_event->PlatformTimeStamp() TimeTicks timestamp = underlying_event ? underlying_event->PlatformTimeStamp()
: CurrentTimeTicks(); : CurrentTimeTicks();
MouseEvent* created_event = MouseEvent* created_event =
new MouseEvent(event_type, Bubbles::kYes, Cancelable::kYes, view, 0, new MouseEvent(event_type, initializer, timestamp, synthetic_type);
screen_x, screen_y, 0, 0, 0, 0, modifiers, 0, 0, nullptr,
timestamp, synthetic_type, String());
created_event->SetTrusted(creation_scope == created_event->SetTrusted(creation_scope ==
SimulatedClickCreationScope::kFromUserAgent); SimulatedClickCreationScope::kFromUserAgent);
...@@ -156,97 +157,24 @@ MouseEvent::MouseEvent() ...@@ -156,97 +157,24 @@ MouseEvent::MouseEvent()
synthetic_event_type_(kRealOrIndistinguishable) {} synthetic_event_type_(kRealOrIndistinguishable) {}
MouseEvent::MouseEvent(const AtomicString& event_type, MouseEvent::MouseEvent(const AtomicString& event_type,
Bubbles bubbles, const MouseEventInit& initializer,
Cancelable cancelable,
AbstractView* abstract_view,
const WebMouseEvent& event,
int detail,
const String& region,
EventTarget* related_target)
: UIEventWithKeyState(
event_type,
bubbles,
cancelable,
abstract_view,
detail,
static_cast<WebInputEvent::Modifiers>(event.GetModifiers()),
TimeTicksFromSeconds(event.TimeStampSeconds()),
abstract_view
? abstract_view->GetInputDeviceCapabilities()->FiresTouchEvents(
event.FromTouch())
: nullptr),
screen_location_(event.PositionInScreen().x, event.PositionInScreen().y),
movement_delta_(event.MovementInRootFrame()),
position_type_(PositionType::kPosition),
button_(static_cast<short>(event.button)),
buttons_(WebInputEventModifiersToButtons(event.GetModifiers())),
related_target_(related_target),
synthetic_event_type_(event.FromTouch() ? kFromTouch
: kRealOrIndistinguishable),
region_(region),
menu_source_type_(event.menu_source_type) {
FloatPoint root_frame_coordinates = event.PositionInRootFrame();
InitCoordinatesFromRootFrame(root_frame_coordinates.X(),
root_frame_coordinates.Y());
}
MouseEvent::MouseEvent(const AtomicString& event_type,
Bubbles bubbles,
Cancelable cancelable,
AbstractView* abstract_view,
int detail,
double screen_x,
double screen_y,
double window_x,
double window_y,
double movement_x,
double movement_y,
WebInputEvent::Modifiers modifiers,
short button,
unsigned short buttons,
EventTarget* related_target,
TimeTicks platform_time_stamp, TimeTicks platform_time_stamp,
SyntheticEventType synthetic_event_type, SyntheticEventType synthetic_event_type,
const String& region) WebMenuSourceType menu_source_type)
: UIEventWithKeyState(
event_type,
bubbles,
cancelable,
abstract_view,
detail,
modifiers,
platform_time_stamp,
abstract_view
? abstract_view->GetInputDeviceCapabilities()->FiresTouchEvents(
synthetic_event_type == kFromTouch)
: nullptr),
screen_location_(screen_x, screen_y),
movement_delta_(movement_x, movement_y),
position_type_(synthetic_event_type == kPositionless
? PositionType::kPositionless
: PositionType::kPosition),
button_(button),
buttons_(buttons),
related_target_(related_target),
synthetic_event_type_(synthetic_event_type),
region_(region) {
InitCoordinatesFromRootFrame(window_x, window_y);
}
MouseEvent::MouseEvent(const AtomicString& event_type,
const MouseEventInit& initializer,
TimeTicks platform_time_stamp)
: UIEventWithKeyState(event_type, initializer, platform_time_stamp), : UIEventWithKeyState(event_type, initializer, platform_time_stamp),
screen_location_( screen_location_(
DoublePoint(initializer.screenX(), initializer.screenY())), DoublePoint(initializer.screenX(), initializer.screenY())),
movement_delta_( movement_delta_(
IntPoint(initializer.movementX(), initializer.movementY())), IntPoint(initializer.movementX(), initializer.movementY())),
position_type_(PositionType::kPosition), position_type_(synthetic_event_type == kPositionless
? PositionType::kPositionless
: PositionType::kPosition),
button_(initializer.button()), button_(initializer.button()),
buttons_(initializer.buttons()), buttons_(initializer.buttons()),
related_target_(initializer.relatedTarget()), related_target_(initializer.relatedTarget()),
synthetic_event_type_(kRealOrIndistinguishable), synthetic_event_type_(synthetic_event_type),
region_(initializer.region()) { region_(initializer.region()),
menu_source_type_(menu_source_type) {
InitCoordinates(initializer.clientX(), initializer.clientY()); InitCoordinates(initializer.clientX(), initializer.clientY());
} }
...@@ -263,35 +191,32 @@ void MouseEvent::InitCoordinates(const double client_x, const double client_y) { ...@@ -263,35 +191,32 @@ void MouseEvent::InitCoordinates(const double client_x, const double client_y) {
has_cached_relative_position_ = false; has_cached_relative_position_ = false;
} }
void MouseEvent::InitCoordinatesFromRootFrame(double window_x, void MouseEvent::SetCoordinatesFromWebPointerProperties(
double window_y) { const WebPointerProperties& web_pointer_properties,
DoublePoint adjusted_page_location; const LocalDOMWindow* dom_window,
DoubleSize scroll_offset; MouseEventInit& initializer) {
FloatPoint client_point;
LocalFrame* frame = view() && view()->IsLocalDOMWindow() float scale_factor = 1.0f;
? ToLocalDOMWindow(view())->GetFrame() if (dom_window && dom_window->GetFrame() && dom_window->GetFrame()->View()) {
: nullptr; LocalFrame* frame = dom_window->GetFrame();
if (frame && HasPosition()) { FloatPoint page_point = frame->View()->RootFrameToContents(
scroll_offset = ContentsScrollOffset(view()); web_pointer_properties.PositionInWidget());
if (LocalFrameView* frame_view = frame->View()) { scale_factor = 1.0f / frame->PageZoomFactor();
adjusted_page_location = FloatPoint scroll_position(frame->View()->GetScrollOffset());
frame_view->RootFrameToDocument(FloatPoint(window_x, window_y)); client_point = page_point.ScaledBy(scale_factor);
float scale_factor = 1 / frame->PageZoomFactor(); client_point.MoveBy(scroll_position.ScaledBy(-scale_factor));
if (scale_factor != 1.0f)
adjusted_page_location.Scale(scale_factor, scale_factor);
}
} }
client_location_ = adjusted_page_location - scroll_offset; initializer.setScreenX(web_pointer_properties.PositionInScreen().x);
page_location_ = adjusted_page_location; initializer.setScreenY(web_pointer_properties.PositionInScreen().y);
initializer.setClientX(client_point.X());
initializer.setClientY(client_point.Y());
// Set up initial values for coordinates. // TODO(nzolghadr): We need to scale movement attrinutes as well. But if we do
// Correct values are computed lazily, see computeRelativePosition. // that here and round it to the int again it causes inconsistencies between
layer_location_ = page_location_; // screenX/Y and cumulative movementX/Y.
offset_location_ = page_location_; initializer.setMovementX(web_pointer_properties.movement_x);
initializer.setMovementY(web_pointer_properties.movement_y);
ComputePageLocation();
has_cached_relative_position_ = false;
} }
MouseEvent::~MouseEvent() = default; MouseEvent::~MouseEvent() = default;
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "core/events/MouseEventInit.h" #include "core/events/MouseEventInit.h"
#include "core/events/UIEventWithKeyState.h" #include "core/events/UIEventWithKeyState.h"
#include "public/platform/WebMenuSourceType.h" #include "public/platform/WebMenuSourceType.h"
#include "public/platform/WebMouseEvent.h"
namespace blink { namespace blink {
class DataTransfer; class DataTransfer;
...@@ -52,11 +51,10 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -52,11 +51,10 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
static MouseEvent* Create() { return new MouseEvent; } static MouseEvent* Create() { return new MouseEvent; }
static MouseEvent* Create(const AtomicString& event_type, static MouseEvent* Create(const AtomicString& event_type,
AbstractView*, const MouseEventInit&,
const WebMouseEvent&, TimeTicks platform_time_stamp,
int detail, SyntheticEventType,
const String& canvas_region_id, WebMenuSourceType);
Node* related_target);
static MouseEvent* Create(ScriptState*, static MouseEvent* Create(ScriptState*,
const AtomicString& event_type, const AtomicString& event_type,
...@@ -70,6 +68,10 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -70,6 +68,10 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
~MouseEvent() override; ~MouseEvent() override;
static unsigned short WebInputEventModifiersToButtons(unsigned modifiers); static unsigned short WebInputEventModifiersToButtons(unsigned modifiers);
static void SetCoordinatesFromWebPointerProperties(
const WebPointerProperties&,
const LocalDOMWindow*,
MouseEventInit&);
void initMouseEvent(ScriptState*, void initMouseEvent(ScriptState*,
const AtomicString& type, const AtomicString& type,
...@@ -117,8 +119,6 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -117,8 +119,6 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
int ClickCount() { return detail(); } int ClickCount() { return detail(); }
const WebMouseEvent* NativeEvent() const { return native_event_.get(); }
enum class PositionType { enum class PositionType {
kPosition, kPosition,
// Positionless mouse events are used, for example, for 'click' events from // Positionless mouse events are used, for example, for 'click' events from
...@@ -192,36 +192,11 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -192,36 +192,11 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
protected: protected:
MouseEvent(const AtomicString& type, MouseEvent(const AtomicString& type,
Bubbles, const MouseEventInit&,
Cancelable,
AbstractView*,
const WebMouseEvent&,
int detail,
const String& region,
EventTarget* related_target);
MouseEvent(const AtomicString& type,
Bubbles,
Cancelable,
AbstractView*,
int detail,
double screen_x,
double screen_y,
double window_x,
double window_y,
double movement_x,
double movement_y,
WebInputEvent::Modifiers,
short button,
unsigned short buttons,
EventTarget* related_target,
TimeTicks platform_time_stamp, TimeTicks platform_time_stamp,
SyntheticEventType, SyntheticEventType = kRealOrIndistinguishable,
const String& region); WebMenuSourceType = kMenuSourceNone);
MouseEvent(const AtomicString& type,
const MouseEventInit&,
TimeTicks platform_time_stamp);
MouseEvent(const AtomicString& type, const MouseEventInit& init) MouseEvent(const AtomicString& type, const MouseEventInit& init)
: MouseEvent(type, init, CurrentTimeTicks()) {} : MouseEvent(type, init, CurrentTimeTicks()) {}
...@@ -254,7 +229,6 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -254,7 +229,6 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
unsigned short buttons = 0); unsigned short buttons = 0);
void InitCoordinates(const double client_x, const double client_y); void InitCoordinates(const double client_x, const double client_y);
void InitCoordinatesFromRootFrame(double window_x, double window_y);
void ComputePageLocation(); void ComputePageLocation();
void ComputeRelativePosition(); void ComputeRelativePosition();
...@@ -274,8 +248,6 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -274,8 +248,6 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
// Only used for contextmenu events. // Only used for contextmenu events.
WebMenuSourceType menu_source_type_; WebMenuSourceType menu_source_type_;
std::unique_ptr<WebMouseEvent> native_event_;
}; };
DEFINE_EVENT_TYPE_CASTS(MouseEvent); DEFINE_EVENT_TYPE_CASTS(MouseEvent);
......
...@@ -88,31 +88,16 @@ void UpdateCommonPointerEventInit(const WebPointerEvent& web_pointer_event, ...@@ -88,31 +88,16 @@ void UpdateCommonPointerEventInit(const WebPointerEvent& web_pointer_event,
WebPointerEvent web_pointer_event_in_root_frame = WebPointerEvent web_pointer_event_in_root_frame =
web_pointer_event.WebPointerEventInRootFrame(); web_pointer_event.WebPointerEventInRootFrame();
FloatPoint client_point; MouseEvent::SetCoordinatesFromWebPointerProperties(
float scale_factor = 1.0f; web_pointer_event_in_root_frame, dom_window, *pointer_event_init);
if (dom_window && dom_window->GetFrame() && dom_window->GetFrame()->View()) {
LocalFrame* frame = dom_window->GetFrame();
FloatPoint page_point = frame->View()->RootFrameToContents(
web_pointer_event_in_root_frame.PositionInWidget());
scale_factor = 1.0f / frame->PageZoomFactor();
FloatPoint scroll_position(frame->View()->GetScrollOffset());
client_point = page_point.ScaledBy(scale_factor);
client_point.MoveBy(scroll_position.ScaledBy(-scale_factor));
}
pointer_event_init->setScreenX(web_pointer_event.PositionInScreen().x);
pointer_event_init->setScreenY(web_pointer_event.PositionInScreen().y);
pointer_event_init->setClientX(client_point.X());
pointer_event_init->setClientY(client_point.Y());
// TODO(nzolghadr): We need to scale movement attrinutes as well. But if we do
// that here and round it to the int again it causes inconsistencies between
// screenX/Y and cumulative movementX/Y.
pointer_event_init->setMovementX(web_pointer_event_in_root_frame.movement_x);
pointer_event_init->setMovementY(web_pointer_event_in_root_frame.movement_y);
// If width/height is unknown we let PointerEventInit set it to 1. // If width/height is unknown we let PointerEventInit set it to 1.
// See https://w3c.github.io/pointerevents/#dom-pointerevent-width // See https://w3c.github.io/pointerevents/#dom-pointerevent-width
if (web_pointer_event_in_root_frame.HasWidth() && if (web_pointer_event_in_root_frame.HasWidth() &&
web_pointer_event_in_root_frame.HasHeight()) { web_pointer_event_in_root_frame.HasHeight()) {
float scale_factor = 1.0f;
if (dom_window && dom_window->GetFrame())
scale_factor = 1.0f / dom_window->GetFrame()->PageZoomFactor();
FloatSize point_shape = FloatSize(web_pointer_event_in_root_frame.width, FloatSize point_shape = FloatSize(web_pointer_event_in_root_frame.width,
web_pointer_event_in_root_frame.height) web_pointer_event_in_root_frame.height)
.ScaledBy(scale_factor); .ScaledBy(scale_factor);
......
...@@ -172,24 +172,6 @@ WebPointerEvent TransformWebPointerEvent(LocalFrameView* frame_view, ...@@ -172,24 +172,6 @@ WebPointerEvent TransformWebPointerEvent(LocalFrameView* frame_view,
WebMouseEventBuilder::WebMouseEventBuilder(const LocalFrameView* plugin_parent, WebMouseEventBuilder::WebMouseEventBuilder(const LocalFrameView* plugin_parent,
const LayoutObject* layout_object, const LayoutObject* layout_object,
const MouseEvent& event) { const MouseEvent& event) {
if (event.NativeEvent()) {
*static_cast<WebMouseEvent*>(this) =
event.NativeEvent()->FlattenTransform();
WebFloatPoint absolute_location = PositionInRootFrame();
// TODO(dtapuska): |plugin_parent| should never be null. Remove this
// conditional code.
// Translate the root frame position to content coordinates.
if (plugin_parent) {
absolute_location = plugin_parent->RootFrameToContents(absolute_location);
}
FloatPoint local_point =
layout_object->AbsoluteToLocal(absolute_location, kUseTransforms);
SetPositionInWidget(local_point.X(), local_point.Y());
return;
}
// Code below here can be removed once OOPIF ships. // Code below here can be removed once OOPIF ships.
// OOPIF will prevent synthetic events being dispatched into // OOPIF will prevent synthetic events being dispatched into
// other frames; but for now we allow the fallback to generate // other frames; but for now we allow the fallback to generate
......
...@@ -41,6 +41,30 @@ long NegateIfPossible(long value) { ...@@ -41,6 +41,30 @@ long NegateIfPossible(long value) {
return -value; return -value;
} }
MouseEventInit GetMouseEventInitForWheel(const WebMouseWheelEvent& event,
AbstractView* view) {
MouseEventInit initializer;
initializer.setBubbles(true);
initializer.setCancelable(event.IsCancelable());
MouseEvent::SetCoordinatesFromWebPointerProperties(
event.FlattenTransform(),
view->IsLocalDOMWindow() ? ToLocalDOMWindow(view) : nullptr, initializer);
initializer.setButton(static_cast<short>(event.button));
initializer.setButtons(
MouseEvent::WebInputEventModifiersToButtons(event.GetModifiers()));
initializer.setView(view);
initializer.setComposed(true);
initializer.setDetail(event.click_count);
UIEventWithKeyState::SetFromWebInputEventModifiers(
initializer, static_cast<WebInputEvent::Modifiers>(event.GetModifiers()));
// TODO(zino): Should support canvas hit region because the
// wheel event is a kind of mouse event. Please see
// http://crbug.com/594075
return initializer;
}
} // namespace } // namespace
WheelEvent* WheelEvent::Create(const WebMouseWheelEvent& event, WheelEvent* WheelEvent::Create(const WebMouseWheelEvent& event,
...@@ -69,16 +93,8 @@ WheelEvent::WheelEvent(const AtomicString& type, ...@@ -69,16 +93,8 @@ WheelEvent::WheelEvent(const AtomicString& type,
WheelEvent::WheelEvent(const WebMouseWheelEvent& event, AbstractView* view) WheelEvent::WheelEvent(const WebMouseWheelEvent& event, AbstractView* view)
: MouseEvent(EventTypeNames::wheel, : MouseEvent(EventTypeNames::wheel,
Bubbles::kYes, GetMouseEventInitForWheel(event, view),
event.IsCancelable() ? Cancelable::kYes : Cancelable::kNo, TimeTicksFromSeconds(event.TimeStampSeconds())),
view,
event,
event.click_count,
// TODO(zino): Should support canvas hit region because the
// wheel event is a kind of mouse event. Please see
// http://crbug.com/594075
String(),
nullptr),
wheel_delta_(event.wheel_ticks_x * kTickMultiplier, wheel_delta_(event.wheel_ticks_x * kTickMultiplier,
event.wheel_ticks_y * kTickMultiplier), event.wheel_ticks_y * kTickMultiplier),
delta_x_(-event.DeltaXInRootFrame()), delta_x_(-event.DeltaXInRootFrame()),
......
...@@ -217,10 +217,41 @@ WebInputEventResult MouseEventManager::DispatchMouseEvent( ...@@ -217,10 +217,41 @@ WebInputEventResult MouseEventManager::DispatchMouseEvent(
mouse_event_type == EventTypeNames::dblclick) { mouse_event_type == EventTypeNames::dblclick) {
click_count = click_count_; click_count = click_count_;
} }
bool is_mouse_enter_or_leave =
mouse_event_type == EventTypeNames::mouseenter ||
mouse_event_type == EventTypeNames::mouseleave;
MouseEventInit initializer;
initializer.setBubbles(!is_mouse_enter_or_leave);
initializer.setCancelable(!is_mouse_enter_or_leave);
MouseEvent::SetCoordinatesFromWebPointerProperties(
mouse_event.FlattenTransform(), target_node->GetDocument().domWindow(),
initializer);
initializer.setButton(static_cast<short>(mouse_event.button));
initializer.setButtons(MouseEvent::WebInputEventModifiersToButtons(
mouse_event.GetModifiers()));
initializer.setView(target_node->GetDocument().domWindow());
initializer.setComposed(true);
initializer.setDetail(click_count);
initializer.setRegion(canvas_region_id);
initializer.setRelatedTarget(related_target);
UIEventWithKeyState::SetFromWebInputEventModifiers(
initializer,
static_cast<WebInputEvent::Modifiers>(mouse_event.GetModifiers()));
initializer.setSourceCapabilities(
target_node->GetDocument().domWindow()
? target_node->GetDocument()
.domWindow()
->GetInputDeviceCapabilities()
->FiresTouchEvents(mouse_event.FromTouch())
: nullptr);
MouseEvent* event = MouseEvent::Create( MouseEvent* event = MouseEvent::Create(
mouse_event_type, target_node->GetDocument().domWindow(), mouse_event, mouse_event_type, initializer,
click_count, canvas_region_id, TimeTicksFromSeconds(mouse_event.TimeStampSeconds()),
related_target ? related_target->ToNode() : nullptr); mouse_event.FromTouch() ? MouseEvent::kFromTouch
: MouseEvent::kRealOrIndistinguishable,
mouse_event.menu_source_type);
DispatchEventResult dispatch_result = target->DispatchEvent(event); DispatchEventResult dispatch_result = target->DispatchEvent(event);
return EventHandlingUtil::ToWebInputEventResult(dispatch_result); return EventHandlingUtil::ToWebInputEventResult(dispatch_result);
} }
...@@ -1009,22 +1040,32 @@ WebInputEventResult MouseEventManager::DispatchDragEvent( ...@@ -1009,22 +1040,32 @@ WebInputEventResult MouseEventManager::DispatchDragEvent(
related_target->GetDocument() != drag_target->GetDocument()) related_target->GetDocument() != drag_target->GetDocument())
related_target = nullptr; related_target = nullptr;
const Event::Cancelable cancelable = DragEventInit initializer;
(event_type != EventTypeNames::dragleave && initializer.setBubbles(true);
event_type != EventTypeNames::dragend) initializer.setCancelable(event_type != EventTypeNames::dragleave &&
? Event::Cancelable::kYes event_type != EventTypeNames::dragend);
: Event::Cancelable::kNo; MouseEvent::SetCoordinatesFromWebPointerProperties(
event.FlattenTransform(), frame_->GetDocument()->domWindow(),
initializer);
initializer.setButton(0);
initializer.setButtons(
MouseEvent::WebInputEventModifiersToButtons(event.GetModifiers()));
initializer.setRelatedTarget(related_target);
initializer.setView(frame_->GetDocument()->domWindow());
initializer.setComposed(true);
initializer.setGetDataTransfer(data_transfer);
initializer.setSourceCapabilities(
frame_->GetDocument()->domWindow()
? frame_->GetDocument()
->domWindow()
->GetInputDeviceCapabilities()
->FiresTouchEvents(event.FromTouch())
: nullptr);
UIEventWithKeyState::SetFromWebInputEventModifiers(
initializer, static_cast<WebInputEvent::Modifiers>(event.GetModifiers()));
IntPoint movement = FlooredIntPoint(event.MovementInRootFrame());
DragEvent* me = DragEvent::Create( DragEvent* me = DragEvent::Create(
event_type, Event::Bubbles::kYes, cancelable, event_type, initializer, TimeTicksFromSeconds(event.TimeStampSeconds()),
frame_->GetDocument()->domWindow(), 0, event.PositionInScreen().x,
event.PositionInScreen().y, event.PositionInRootFrame().x,
event.PositionInRootFrame().y, movement.X(), movement.Y(),
static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), 0,
MouseEvent::WebInputEventModifiersToButtons(event.GetModifiers()),
related_target, TimeTicksFromSeconds(event.TimeStampSeconds()),
data_transfer,
event.FromTouch() ? MouseEvent::kFromTouch event.FromTouch() ? MouseEvent::kFromTouch
: MouseEvent::kRealOrIndistinguishable); : MouseEvent::kRealOrIndistinguishable);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment