Commit d581c696 authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1461708 - part 6: Make EditorEventListener::MouseClick() use...

Bug 1461708 - part 6: Make EditorEventListener::MouseClick() use WidgetMouseEvent instead of dom::MouseEvent r=m_kato

The event argument of only EditorEventListener::MouseClick() can be replaced
with WidgetMouseEvent simply.  So, for avoiding unnecessary RefPtr in
EditorEventListener::HandleEvent(), we should fix this now.

Differential Revision: https://phabricator.services.mozilla.com/D7853

--HG--
extra : moz-landing-system : lando
parent fd4e78f2
......@@ -454,18 +454,18 @@ EditorEventListener::HandleEvent(Event* aEvent)
}
// click
case eMouseClick: {
RefPtr<MouseEvent> mouseEvent = aEvent->AsMouseEvent();
if (NS_WARN_IF(!mouseEvent)) {
WidgetMouseEvent* widgetMouseEvent = internalEvent->AsMouseEvent();
if (NS_WARN_IF(!widgetMouseEvent)) {
return NS_OK;
}
// If the preceding mousedown event or mouseup event was consumed,
// editor shouldn't handle this click event.
if (mMouseDownOrUpConsumedByIME) {
mMouseDownOrUpConsumedByIME = false;
mouseEvent->PreventDefault();
widgetMouseEvent->PreventDefault();
return NS_OK;
}
return MouseClick(mouseEvent);
return MouseClick(widgetMouseEvent);
}
// focus
case eFocus:
......@@ -642,17 +642,15 @@ EditorEventListener::KeyPress(WidgetKeyboardEvent* aKeyboardEvent)
}
nsresult
EditorEventListener::MouseClick(MouseEvent* aMouseEvent)
EditorEventListener::MouseClick(WidgetMouseEvent* aMouseClickEvent)
{
if (NS_WARN_IF(!aMouseEvent) || DetachedFromEditor()) {
if (NS_WARN_IF(!aMouseClickEvent) || DetachedFromEditor()) {
return NS_OK;
}
// nothing to do if editor isn't editable or clicked on out of the editor.
RefPtr<TextEditor> textEditor = mEditorBase->AsTextEditor();
WidgetMouseEvent* clickEvent =
aMouseEvent->WidgetEventPtr()->AsMouseEvent();
if (textEditor->IsReadonly() || textEditor->IsDisabled() ||
!textEditor->IsAcceptableInputEvent(clickEvent)) {
!textEditor->IsAcceptableInputEvent(aMouseClickEvent)) {
return NS_OK;
}
......@@ -662,14 +660,14 @@ EditorEventListener::MouseClick(MouseEvent* aMouseEvent)
RefPtr<nsPresContext> presContext = GetPresContext();
if (presContext) {
IMEStateManager::OnClickInEditor(presContext, GetFocusedRootContent(),
clickEvent);
aMouseClickEvent);
if (DetachedFromEditor()) {
return NS_OK;
}
}
}
if (DetachedFromEditorOrDefaultPrevented(clickEvent)) {
if (DetachedFromEditorOrDefaultPrevented(aMouseClickEvent)) {
// We're done if 'preventdefault' is true (see for example bug 70698).
return NS_OK;
}
......@@ -680,7 +678,7 @@ EditorEventListener::MouseClick(MouseEvent* aMouseEvent)
return NS_OK;
}
if (clickEvent->button != WidgetMouseEventBase::eMiddleButton ||
if (aMouseClickEvent->button != WidgetMouseEventBase::eMiddleButton ||
!WidgetMouseEvent::IsMiddleClickPasteEnabled()) {
return NS_OK;
}
......@@ -693,18 +691,19 @@ EditorEventListener::MouseClick(MouseEvent* aMouseEvent)
if (NS_WARN_IF(!presContext)) {
return NS_OK;
}
MOZ_ASSERT(!clickEvent->DefaultPrevented());
MOZ_ASSERT(!aMouseClickEvent->DefaultPrevented());
nsEventStatus status = nsEventStatus_eIgnore;
RefPtr<EventStateManager> esm = presContext->EventStateManager();
DebugOnly<nsresult> rv =
esm->HandleMiddleClickPaste(presShell, clickEvent, &status, textEditor);
esm->HandleMiddleClickPaste(presShell, aMouseClickEvent, &status,
textEditor);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"Failed to paste for the middle button click");
if (status == nsEventStatus_eConsumeNoDefault) {
// Prevent the event from propagating up to be possibly handled
// again by the containing window:
clickEvent->StopImmediatePropagation();
clickEvent->PreventDefault();
aMouseClickEvent->StopImmediatePropagation();
aMouseClickEvent->PreventDefault();
}
return NS_OK;
}
......
......@@ -73,7 +73,7 @@ protected:
virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent);
virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) { return NS_OK; }
MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseClick(dom::MouseEvent* aMouseEvent);
virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent);
nsresult Focus(InternalFocusEvent* aFocusEvent);
nsresult Blur(InternalFocusEvent* aBlurEvent);
MOZ_CAN_RUN_SCRIPT nsresult DragEnter(dom::DragEvent* aDragEvent);
......
......@@ -183,14 +183,16 @@ HTMLEditorEventListener::MouseDown(MouseEvent* aMouseEvent)
}
nsresult
HTMLEditorEventListener::MouseClick(MouseEvent* aMouseEvent)
HTMLEditorEventListener::MouseClick(WidgetMouseEvent* aMouseClickEvent)
{
if (NS_WARN_IF(DetachedFromEditor())) {
return NS_OK;
}
RefPtr<EventTarget> target = aMouseEvent->GetTarget();
NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
RefPtr<EventTarget> target = aMouseClickEvent->GetDOMEventTarget();
if (NS_WARN_IF(!target)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<Element> element = do_QueryInterface(target);
if (NS_WARN_IF(!element)) {
return NS_ERROR_FAILURE;
......@@ -205,7 +207,7 @@ HTMLEditorEventListener::MouseClick(MouseEvent* aMouseEvent)
return NS_OK;
}
return EditorEventListener::MouseClick(aMouseEvent);
return EditorEventListener::MouseClick(aMouseClickEvent);
}
} // namespace mozilla
......@@ -34,7 +34,7 @@ protected:
virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent) override;
virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) override;
MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseClick(dom::MouseEvent* aMouseEvent) override;
virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent) override;
};
} // namespace mozilla
......
Supports Markdown
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