Skip to content

Commit

Permalink
Remove PlatformMouseEvent and use WebMouseEvent instead
Browse files Browse the repository at this point in the history
Perform similar cleanup as GestureEvents used in change:
https://codereview.chromium.org/2539283002/
https://codereview.chromium.org/2586133003/
https://codereview.chromium.org/2646163002/

Cleanup proposal: https://docs.google.com/document/d/1s4Lfy22CNU1OZ5Rec6Oano_5BvIhdK6uFVsVe7FphKI/edit

BUG=625684
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2650403006
Cr-Commit-Position: refs/heads/master@{#446853}
  • Loading branch information
dtapuska authored and Commit bot committed Jan 28, 2017
1 parent 14bb3dc commit 6a0ddfb
Show file tree
Hide file tree
Showing 73 changed files with 1,098 additions and 1,166 deletions.
6 changes: 2 additions & 4 deletions third_party/WebKit/Source/core/dom/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3542,7 +3542,7 @@ ReferrerPolicy Document::getReferrerPolicy() const {
MouseEventWithHitTestResults Document::performMouseEventHitTest(
const HitTestRequest& request,
const LayoutPoint& documentPoint,
const PlatformMouseEvent& event) {
const WebMouseEvent& event) {
DCHECK(layoutViewItem().isNull() || layoutViewItem().isLayoutView());

// LayoutView::hitTest causes a layout, and we don't want to hit that until
Expand All @@ -3562,15 +3562,13 @@ MouseEventWithHitTestResults Document::performMouseEventHitTest(
updateHoverActiveState(request, result.innerElement(), result.scrollbar());

if (isHTMLCanvasElement(result.innerNode())) {
PlatformMouseEvent eventWithRegion = event;
HitTestCanvasResult* hitTestCanvasResult =
toHTMLCanvasElement(result.innerNode())
->getControlAndIdIfHitRegionExists(result.pointInInnerNodeFrame());
if (hitTestCanvasResult->getControl()) {
result.setInnerNode(hitTestCanvasResult->getControl());
}
eventWithRegion.setRegion(hitTestCanvasResult->getId());
return MouseEventWithHitTestResults(eventWithRegion, result);
result.setCanvasRegionId(hitTestCanvasResult->getId());
}

return MouseEventWithHitTestResults(event, result);
Expand Down
12 changes: 5 additions & 7 deletions third_party/WebKit/Source/core/dom/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class NodeIterator;
class NthIndexCache;
class OriginAccessEntry;
class Page;
class PlatformMouseEvent;
class ProcessingInstruction;
class PropertyRegistry;
class QualifiedName;
Expand Down Expand Up @@ -172,12 +171,12 @@ class TouchList;
class TransformSource;
class TreeWalker;
class VisitedLinkState;
class WebMouseEvent;
struct AnnotatedRegionValue;
struct FocusParams;
struct IconURL;

using MouseEventWithHitTestResults =
EventWithHitTestResults<PlatformMouseEvent>;
using MouseEventWithHitTestResults = EventWithHitTestResults<WebMouseEvent>;
using ExceptionCode = int;

enum NodeListInvalidationType {
Expand Down Expand Up @@ -687,10 +686,9 @@ class CORE_EXPORT Document : public ContainerNode,
TextLinkColors& textLinkColors() { return m_textLinkColors; }
VisitedLinkState& visitedLinkState() const { return *m_visitedLinkState; }

MouseEventWithHitTestResults performMouseEventHitTest(
const HitTestRequest&,
const LayoutPoint&,
const PlatformMouseEvent&);
MouseEventWithHitTestResults performMouseEventHitTest(const HitTestRequest&,
const LayoutPoint&,
const WebMouseEvent&);

/* Newly proposed CSS3 mechanism for selecting alternate
stylesheets using the DOM. May be subject to change as
Expand Down
26 changes: 14 additions & 12 deletions third_party/WebKit/Source/core/dom/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ DispatchEventResult Node::dispatchDOMActivateEvent(int detail,
}

void Node::createAndDispatchPointerEvent(const AtomicString& mouseEventName,
const PlatformMouseEvent& mouseEvent,
const WebMouseEvent& mouseEvent,
LocalDOMWindow* view) {
AtomicString pointerEventName;
if (mouseEventName == EventTypeNames::mousemove)
Expand All @@ -2137,22 +2137,22 @@ void Node::createAndDispatchPointerEvent(const AtomicString& mouseEventName,
pointerEventInit.setPointerType("mouse");
pointerEventInit.setIsPrimary(true);
pointerEventInit.setButtons(
MouseEvent::platformModifiersToButtons(mouseEvent.getModifiers()));
MouseEvent::platformModifiersToButtons(mouseEvent.modifiers()));

pointerEventInit.setBubbles(true);
pointerEventInit.setCancelable(true);
pointerEventInit.setComposed(true);
pointerEventInit.setDetail(0);

pointerEventInit.setScreenX(mouseEvent.globalPosition().x());
pointerEventInit.setScreenY(mouseEvent.globalPosition().y());
pointerEventInit.setScreenX(mouseEvent.globalX);
pointerEventInit.setScreenY(mouseEvent.globalY);

IntPoint locationInFrameZoomed;
if (view && view->frame() && view->frame()->view()) {
LocalFrame* frame = view->frame();
FrameView* frameView = frame->view();
IntPoint locationInContents =
frameView->rootFrameToContents(mouseEvent.position());
IntPoint locationInContents = frameView->rootFrameToContents(
flooredIntPoint(mouseEvent.positionInRootFrame()));
locationInFrameZoomed = frameView->contentsToFrame(locationInContents);
float scaleFactor = 1 / frame->pageZoomFactor();
locationInFrameZoomed.scale(scaleFactor, scaleFactor);
Expand All @@ -2164,28 +2164,30 @@ void Node::createAndDispatchPointerEvent(const AtomicString& mouseEventName,

if (pointerEventName == EventTypeNames::pointerdown ||
pointerEventName == EventTypeNames::pointerup) {
pointerEventInit.setButton(
static_cast<int>(mouseEvent.pointerProperties().button));
pointerEventInit.setButton(static_cast<int>(mouseEvent.button));
} else {
pointerEventInit.setButton(
static_cast<int>(WebPointerProperties::Button::NoButton));
}

UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit,
mouseEvent.getModifiers());
UIEventWithKeyState::setFromWebInputEventModifiers(
pointerEventInit,
static_cast<WebInputEvent::Modifiers>(mouseEvent.modifiers()));
pointerEventInit.setView(view);

dispatchEvent(PointerEvent::create(pointerEventName, pointerEventInit));
}

void Node::dispatchMouseEvent(const PlatformMouseEvent& nativeEvent,
void Node::dispatchMouseEvent(const WebMouseEvent& nativeEvent,
const AtomicString& mouseEventType,
int detail,
const String& canvasRegionId,
Node* relatedTarget) {
createAndDispatchPointerEvent(mouseEventType, nativeEvent,
document().domWindow());
dispatchEvent(MouseEvent::create(mouseEventType, document().domWindow(),
nativeEvent, detail, relatedTarget));
nativeEvent, detail, canvasRegionId,
relatedTarget));
}

void Node::dispatchSimulatedClick(Event* underlyingEvent,
Expand Down
9 changes: 5 additions & 4 deletions third_party/WebKit/Source/core/dom/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class EventDispatchHandlingState;
class NodeList;
class NodeListsNodeData;
class NodeRareData;
class PlatformMouseEvent;
class QualifiedName;
class RegisteredEventListener;
class LayoutBox;
Expand All @@ -74,6 +73,7 @@ class StaticNodeTypeList;
using StaticNodeList = StaticNodeTypeList<Node>;
class StyleChangeReasonForTracing;
class Text;
class WebMouseEvent;

const int nodeStyleChangeShift = 18;
const int nodeCustomElementShift = 20;
Expand Down Expand Up @@ -717,9 +717,10 @@ class CORE_EXPORT Node : public EventTarget {
DispatchEventResult dispatchDOMActivateEvent(int detail,
Event& underlyingEvent);

void dispatchMouseEvent(const PlatformMouseEvent&,
void dispatchMouseEvent(const WebMouseEvent&,
const AtomicString& eventType,
int clickCount = 0,
const String& canvasNodeId = String(),
Node* relatedTarget = nullptr);

void dispatchSimulatedClick(
Expand Down Expand Up @@ -842,10 +843,10 @@ class CORE_EXPORT Node : public EventTarget {
void clearFlag(NodeFlags mask) { m_nodeFlags &= ~mask; }

// TODO(mustaq): This is a hack to fix sites with flash objects. We should
// instead route all PlatformMouseEvents through EventHandler. See
// instead route all WebMouseEvents through EventHandler. See
// crbug.com/665924.
void createAndDispatchPointerEvent(const AtomicString& mouseEventName,
const PlatformMouseEvent&,
const WebMouseEvent&,
LocalDOMWindow* view);

protected:
Expand Down
41 changes: 21 additions & 20 deletions third_party/WebKit/Source/core/editing/SelectionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ bool SelectionController::handleMousePressEventSingleClick(
// Don't restart the selection when the mouse is pressed on an
// existing selection so we can allow for text dragging.
if (FrameView* view = m_frame->view()) {
const LayoutPoint vPoint =
view->rootFrameToContents(event.event().position());
const LayoutPoint vPoint = view->rootFrameToContents(
flooredIntPoint(event.event().positionInRootFrame()));
if (!extendSelection && this->selection().contains(vPoint)) {
m_mouseDownWasSingleClickInSelection = true;
if (!event.event().fromTouch())
Expand Down Expand Up @@ -245,8 +245,8 @@ bool SelectionController::handleMousePressEventSingleClick(
.selectAllChildren(*innerNode)
.build())
.isCaret();
const bool notLeftClick = event.event().pointerProperties().button !=
WebPointerProperties::Button::Left;
const bool notLeftClick =
event.event().button != WebPointerProperties::Button::Left;
if (!isTextBoxEmpty || notLeftClick)
isHandleVisible = event.event().fromTouch();
}
Expand Down Expand Up @@ -538,7 +538,7 @@ void SelectionController::selectClosestWordFromMouseEvent(
return;

AppendTrailingWhitespace appendTrailingWhitespace =
(result.event().clickCount() == 2 &&
(result.event().clickCount == 2 &&
m_frame->editor().isSelectTrailingWhitespaceEnabled())
? AppendTrailingWhitespace::ShouldAppend
: AppendTrailingWhitespace::DontAppend;
Expand All @@ -558,7 +558,7 @@ void SelectionController::selectClosestMisspellingFromMouseEvent(

selectClosestMisspellingFromHitTestResult(
result.hitTestResult(),
(result.event().clickCount() == 2 &&
(result.event().clickCount == 2 &&
m_frame->editor().isSelectTrailingWhitespaceEnabled())
? AppendTrailingWhitespace::ShouldAppend
: AppendTrailingWhitespace::DontAppend);
Expand Down Expand Up @@ -733,8 +733,7 @@ bool SelectionController::handleMousePressEventDoubleClick(
if (!m_mouseDownAllowsMultiClick)
return handleMousePressEventSingleClick(event);

if (event.event().pointerProperties().button !=
WebPointerProperties::Button::Left)
if (event.event().button != WebPointerProperties::Button::Left)
return false;

if (selection().isRange()) {
Expand Down Expand Up @@ -763,8 +762,7 @@ bool SelectionController::handleMousePressEventTripleClick(
if (!m_mouseDownAllowsMultiClick)
return handleMousePressEventSingleClick(event);

if (event.event().pointerProperties().button !=
WebPointerProperties::Button::Left)
if (event.event().button != WebPointerProperties::Button::Left)
return false;

Node* innerNode = event.innerNode();
Expand Down Expand Up @@ -865,9 +863,9 @@ bool SelectionController::handleMouseReleaseEvent(
// editing, place the caret.
if (m_mouseDownWasSingleClickInSelection &&
m_selectionState != SelectionState::ExtendedSelection &&
dragStartPos == event.event().position() && selection().isRange() &&
event.event().pointerProperties().button !=
WebPointerProperties::Button::Right) {
dragStartPos == flooredIntPoint(event.event().positionInRootFrame()) &&
selection().isRange() &&
event.event().button != WebPointerProperties::Button::Right) {
// TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
Expand All @@ -893,8 +891,7 @@ bool SelectionController::handleMouseReleaseEvent(

selection().selectFrameElementInParentIfFullySelected();

if (event.event().pointerProperties().button ==
WebPointerProperties::Button::Middle &&
if (event.event().button == WebPointerProperties::Button::Middle &&
!event.isOverLink()) {
// Ignore handled, since we want to paste to where the caret was placed
// anyway.
Expand All @@ -905,7 +902,7 @@ bool SelectionController::handleMouseReleaseEvent(
}

bool SelectionController::handlePasteGlobalSelection(
const PlatformMouseEvent& mouseEvent) {
const WebMouseEvent& mouseEvent) {
// If the event was a middle click, attempt to copy global selection in after
// the newly set caret position.
//
Expand All @@ -922,7 +919,7 @@ bool SelectionController::handlePasteGlobalSelection(
// down then the text is pasted just before the onclick handler runs and
// clears the text box. So it's important this happens after the event
// handlers have been fired.
if (mouseEvent.type() != PlatformEvent::MouseReleased)
if (mouseEvent.type() != WebInputEvent::MouseUp)
return false;

if (!m_frame->page())
Expand Down Expand Up @@ -1022,7 +1019,8 @@ void SelectionController::passMousePressEventToSubframe(
// greyed out even though we're clicking on the selection. This looks
// really strange (having the whole frame be greyed out), so we deselect the
// selection.
IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position());
IntPoint p = m_frame->view()->rootFrameToContents(
flooredIntPoint(mev.event().positionInRootFrame()));
if (!selection().contains(p))
return;

Expand Down Expand Up @@ -1071,13 +1069,16 @@ FrameSelection& SelectionController::selection() const {
}

bool isLinkSelection(const MouseEventWithHitTestResults& event) {
return event.event().altKey() && event.isOverLink();
return (event.event().modifiers() & WebInputEvent::Modifiers::AltKey) != 0 &&
event.isOverLink();
}

bool isExtendingSelection(const MouseEventWithHitTestResults& event) {
bool isMouseDownOnLinkOrImage =
event.isOverLink() || event.hitTestResult().image();
return event.event().shiftKey() && !isMouseDownOnLinkOrImage;
return (event.event().modifiers() & WebInputEvent::Modifiers::ShiftKey) !=
0 &&
!isMouseDownOnLinkOrImage;
}

} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CORE_EXPORT SelectionController final
const IntPoint&);
bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&,
const LayoutPoint&);
bool handlePasteGlobalSelection(const PlatformMouseEvent&);
bool handlePasteGlobalSelection(const WebMouseEvent&);
bool handleGestureLongPress(const WebGestureEvent&, const HitTestResult&);
void handleGestureTwoFingerTap(const GestureEventWithHitTestResults&);
void handleGestureLongTap(const GestureEventWithHitTestResults&);
Expand Down
42 changes: 20 additions & 22 deletions third_party/WebKit/Source/core/events/DragEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@

namespace blink {

DragEvent* DragEvent::create(
const AtomicString& type,
bool canBubble,
bool cancelable,
AbstractView* view,
int detail,
int screenX,
int screenY,
int windowX,
int windowY,
int movementX,
int movementY,
PlatformEvent::Modifiers modifiers,
short button,
unsigned short buttons,
EventTarget* relatedTarget,
TimeTicks platformTimeStamp,
DataTransfer* dataTransfer,
PlatformMouseEvent::SyntheticEventType syntheticEventType) {
DragEvent* DragEvent::create(const AtomicString& type,
bool canBubble,
bool cancelable,
AbstractView* view,
int detail,
int screenX,
int screenY,
int windowX,
int windowY,
int movementX,
int movementY,
PlatformEvent::Modifiers modifiers,
short button,
unsigned short buttons,
EventTarget* relatedTarget,
TimeTicks platformTimeStamp,
DataTransfer* dataTransfer,
SyntheticEventType syntheticEventType) {
return new DragEvent(type, canBubble, cancelable, view, detail, screenX,
screenY, windowX, windowY, movementX, movementY,
modifiers, button, buttons, relatedTarget,
Expand Down Expand Up @@ -57,7 +56,7 @@ DragEvent::DragEvent(const AtomicString& eventType,
EventTarget* relatedTarget,
TimeTicks platformTimeStamp,
DataTransfer* dataTransfer,
PlatformMouseEvent::SyntheticEventType syntheticEventType)
SyntheticEventType syntheticEventType)
: MouseEvent(
eventType,
canBubble,
Expand All @@ -78,8 +77,7 @@ DragEvent::DragEvent(const AtomicString& eventType,
syntheticEventType,
// TODO(zino): Should support canvas hit region because the drag event
// is a kind of mouse event. Please see http://crbug.com/594073
String(),
nullptr),
String()),
m_dataTransfer(dataTransfer)

{}
Expand Down
5 changes: 2 additions & 3 deletions third_party/WebKit/Source/core/events/DragEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class CORE_EXPORT DragEvent final : public MouseEvent {
EventTarget* relatedTarget,
TimeTicks platformTimeStamp,
DataTransfer*,
PlatformMouseEvent::SyntheticEventType =
PlatformMouseEvent::RealOrIndistinguishable);
SyntheticEventType = RealOrIndistinguishable);

static DragEvent* create(const AtomicString& type,
const DragEventInit& initializer) {
Expand Down Expand Up @@ -79,7 +78,7 @@ class CORE_EXPORT DragEvent final : public MouseEvent {
EventTarget* relatedTarget,
TimeTicks platformTimeStamp,
DataTransfer*,
PlatformMouseEvent::SyntheticEventType);
SyntheticEventType);

DragEvent(const AtomicString& type, const DragEventInit&);

Expand Down
Loading

0 comments on commit 6a0ddfb

Please sign in to comment.