Commit 84a77be0 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Simplify TargetIsFrame function in core/input/event_handler.cc

Driven-by CL, and follow up of jbroman's remark in [1].

This CL simplifies TargetIsFrame function in core/input/event_handler.cc,
given that it produces two values, and the usage always checks both,
even though the function returns true if it produces a non-null value.

[1] https://crrev.com.com/c/1487391/3/third_party/blink/renderer/core/input/event_handler.cc

BUG=None

Change-Id: Ib556803d078fad3fd5b48dbdb1e6a4e5e6a1ed15
Reviewed-on: https://chromium-review.googlesource.com/c/1496215
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636945}
parent 13febd5a
...@@ -1090,16 +1090,12 @@ WebInputEventResult EventHandler::HandleMouseReleaseEvent( ...@@ -1090,16 +1090,12 @@ WebInputEventResult EventHandler::HandleMouseReleaseEvent(
return event_result; return event_result;
} }
// TODO(jbroman): Simplify this method, given that it produces two values, static LocalFrame* LocalFrameFromTargetNode(Node* target) {
// and the usage always checks both, even though the function returns true
// if it produces a non-null value.
static bool TargetIsFrame(Node* target, LocalFrame*& frame) {
if (!IsHTMLFrameElementBase(target)) if (!IsHTMLFrameElementBase(target))
return false; return nullptr;
// Cross-process drag and drop is not yet supported. // Cross-process drag and drop is not yet supported.
frame = DynamicTo<LocalFrame>(ToHTMLFrameElementBase(target)->ContentFrame()); return DynamicTo<LocalFrame>(ToHTMLFrameElementBase(target)->ContentFrame());
return !!frame;
} }
WebInputEventResult EventHandler::UpdateDragAndDrop( WebInputEventResult EventHandler::UpdateDragAndDrop(
...@@ -1134,11 +1130,9 @@ WebInputEventResult EventHandler::UpdateDragAndDrop( ...@@ -1134,11 +1130,9 @@ WebInputEventResult EventHandler::UpdateDragAndDrop(
// //
// Moreover, this ordering conforms to section 7.9.4 of the HTML 5 spec. // Moreover, this ordering conforms to section 7.9.4 of the HTML 5 spec.
// <http://dev.w3.org/html5/spec/Overview.html#drag-and-drop-processing-model>. // <http://dev.w3.org/html5/spec/Overview.html#drag-and-drop-processing-model>.
LocalFrame* target_frame; if (auto* target_frame = LocalFrameFromTargetNode(new_target)) {
if (TargetIsFrame(new_target, target_frame)) { event_result = target_frame->GetEventHandler().UpdateDragAndDrop(
if (target_frame) event, data_transfer);
event_result = target_frame->GetEventHandler().UpdateDragAndDrop(
event, data_transfer);
} else if (new_target) { } else if (new_target) {
// As per section 7.9.4 of the HTML 5 spec., we must always fire a drag // As per section 7.9.4 of the HTML 5 spec., we must always fire a drag
// event before firing a dragenter, dragleave, or dragover event. // event before firing a dragenter, dragleave, or dragover event.
...@@ -1153,10 +1147,9 @@ WebInputEventResult EventHandler::UpdateDragAndDrop( ...@@ -1153,10 +1147,9 @@ WebInputEventResult EventHandler::UpdateDragAndDrop(
data_transfer); data_transfer);
} }
if (TargetIsFrame(drag_target_.Get(), target_frame)) { if (auto* target_frame = LocalFrameFromTargetNode(drag_target_.Get())) {
if (target_frame) event_result = target_frame->GetEventHandler().UpdateDragAndDrop(
event_result = target_frame->GetEventHandler().UpdateDragAndDrop( event, data_transfer);
event, data_transfer);
} else if (drag_target_) { } else if (drag_target_) {
mouse_event_manager_->DispatchDragEvent(event_type_names::kDragleave, mouse_event_manager_->DispatchDragEvent(event_type_names::kDragleave,
drag_target_.Get(), new_target, drag_target_.Get(), new_target,
...@@ -1171,11 +1164,9 @@ WebInputEventResult EventHandler::UpdateDragAndDrop( ...@@ -1171,11 +1164,9 @@ WebInputEventResult EventHandler::UpdateDragAndDrop(
should_only_fire_drag_over_event_ = true; should_only_fire_drag_over_event_ = true;
} }
} else { } else {
LocalFrame* target_frame; if (auto* target_frame = LocalFrameFromTargetNode(new_target)) {
if (TargetIsFrame(new_target, target_frame)) { event_result = target_frame->GetEventHandler().UpdateDragAndDrop(
if (target_frame) event, data_transfer);
event_result = target_frame->GetEventHandler().UpdateDragAndDrop(
event, data_transfer);
} else if (new_target) { } else if (new_target) {
// Note, when dealing with sub-frames, we may need to fire only a dragover // Note, when dealing with sub-frames, we may need to fire only a dragover
// event as a drag event may have been fired earlier. // event as a drag event may have been fired earlier.
...@@ -1199,10 +1190,8 @@ WebInputEventResult EventHandler::UpdateDragAndDrop( ...@@ -1199,10 +1190,8 @@ WebInputEventResult EventHandler::UpdateDragAndDrop(
void EventHandler::CancelDragAndDrop(const WebMouseEvent& event, void EventHandler::CancelDragAndDrop(const WebMouseEvent& event,
DataTransfer* data_transfer) { DataTransfer* data_transfer) {
LocalFrame* target_frame; if (auto* target_frame = LocalFrameFromTargetNode(drag_target_.Get())) {
if (TargetIsFrame(drag_target_.Get(), target_frame)) { target_frame->GetEventHandler().CancelDragAndDrop(event, data_transfer);
if (target_frame)
target_frame->GetEventHandler().CancelDragAndDrop(event, data_transfer);
} else if (drag_target_.Get()) { } else if (drag_target_.Get()) {
if (mouse_event_manager_->GetDragState().drag_src_) { if (mouse_event_manager_->GetDragState().drag_src_) {
mouse_event_manager_->DispatchDragSrcEvent(event_type_names::kDrag, mouse_event_manager_->DispatchDragSrcEvent(event_type_names::kDrag,
...@@ -1218,12 +1207,10 @@ void EventHandler::CancelDragAndDrop(const WebMouseEvent& event, ...@@ -1218,12 +1207,10 @@ void EventHandler::CancelDragAndDrop(const WebMouseEvent& event,
WebInputEventResult EventHandler::PerformDragAndDrop( WebInputEventResult EventHandler::PerformDragAndDrop(
const WebMouseEvent& event, const WebMouseEvent& event,
DataTransfer* data_transfer) { DataTransfer* data_transfer) {
LocalFrame* target_frame;
WebInputEventResult result = WebInputEventResult::kNotHandled; WebInputEventResult result = WebInputEventResult::kNotHandled;
if (TargetIsFrame(drag_target_.Get(), target_frame)) { if (auto* target_frame = LocalFrameFromTargetNode(drag_target_.Get())) {
if (target_frame) result = target_frame->GetEventHandler().PerformDragAndDrop(event,
result = target_frame->GetEventHandler().PerformDragAndDrop( data_transfer);
event, data_transfer);
} else if (drag_target_.Get()) { } else if (drag_target_.Get()) {
result = mouse_event_manager_->DispatchDragEvent( result = mouse_event_manager_->DispatchDragEvent(
event_type_names::kDrop, drag_target_.Get(), nullptr, event, event_type_names::kDrop, drag_target_.Get(), nullptr, event,
...@@ -2105,12 +2092,9 @@ void EventHandler::DragSourceEndedAt(const WebMouseEvent& event, ...@@ -2105,12 +2092,9 @@ void EventHandler::DragSourceEndedAt(const WebMouseEvent& event,
MouseEventWithHitTestResults mev = MouseEventWithHitTestResults mev =
event_handling_util::PerformMouseEventHitTest(frame_, request, event); event_handling_util::PerformMouseEventHitTest(frame_, request, event);
LocalFrame* target_frame; if (auto* target_frame = LocalFrameFromTargetNode(mev.InnerNode())) {
if (TargetIsFrame(mev.InnerNode(), target_frame)) { target_frame->GetEventHandler().DragSourceEndedAt(event, operation);
if (target_frame) { return;
target_frame->GetEventHandler().DragSourceEndedAt(event, operation);
return;
}
} }
mouse_event_manager_->DragSourceEndedAt(event, operation); mouse_event_manager_->DragSourceEndedAt(event, operation);
......
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