Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Unified Diff: third_party/WebKit/Source/core/page/DragController.cpp

Issue 2428363004: Get rid of createVisibleSelection() taking PositionWithAffinity (Closed)
Patch Set: 2016-10-20T14:00:21 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandlerTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/page/DragController.cpp
diff --git a/third_party/WebKit/Source/core/page/DragController.cpp b/third_party/WebKit/Source/core/page/DragController.cpp
index 25bb2766bf30cd9a58a8ece2b74f73aa08a7c43d..557c8dbe9537cfbb8b70a6782d64916edc473ef5 100644
--- a/third_party/WebKit/Source/core/page/DragController.cpp
+++ b/third_party/WebKit/Source/core/page/DragController.cpp
@@ -456,18 +456,27 @@ DragOperation DragController::operationForLoad(DragData* dragData) {
return dragOperation(dragData);
}
+// Returns true if node at |point| is editable with populating |dragCaret| and
+// |range|, otherwise returns false.
+// TODO(yosin): We should return |VisibleSelection| rather than three values.
static bool setSelectionToDragCaret(LocalFrame* frame,
VisibleSelection& dragCaret,
Range*& range,
const IntPoint& point) {
frame->selection().setSelection(dragCaret);
if (frame->selection().isNone()) {
- // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
+ // TODO(editing-dev): The use of
+ // updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
+ // |LocalFrame::positinForPoint()| requires clean layout.
frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
+ const PositionWithAffinity& position = frame->positionForPoint(point);
+ if (!position.isConnected())
tkent 2016/10/20 08:05:19 In the old code, what happened if !frame->position
yosin_UTC9 2016/10/20 08:34:00 It makes empty selection since visible position ca
tkent 2016/10/21 01:06:27 Because this code is in |if (frame-selection().isN
yosin_UTC9 2016/10/21 01:23:40 Yes, since we attempt to set selection to none on
+ return false;
- dragCaret = createVisibleSelection(frame->positionForPoint(point));
- frame->selection().setSelection(dragCaret);
+ frame->selection().setSelection(
+ SelectionInDOMTree::Builder().collapse(position).build());
+ dragCaret = frame->selection().selection();
range = createRange(dragCaret.toNormalizedEphemeralRange());
}
return !frame->selection().isNone() && frame->selection().isContentEditable();
@@ -482,8 +491,12 @@ DispatchEventResult DragController::dispatchTextInputEventFor(
String text = m_page->dragCaretController().isContentRichlyEditable()
? ""
: dragData->asPlainText();
- Element* target = innerFrame->editor().findEventTargetFrom(
- createVisibleSelection(m_page->dragCaretController().caretPosition()));
+ const PositionWithAffinity& caretPosition =
+ m_page->dragCaretController().caretPosition();
+ DCHECK(caretPosition.isConnected()) << caretPosition;
+ Element* target =
+ innerFrame->editor().findEventTargetFrom(createVisibleSelection(
+ SelectionInDOMTree::Builder().collapse(caretPosition).build()));
return target->dispatchEvent(
TextEvent::createForDrop(innerFrame->domWindow(), text));
}
@@ -539,8 +552,16 @@ bool DragController::concludeEditDrag(DragData* dragData) {
->updateStyleAndLayoutIgnorePendingStylesheets();
}
- VisibleSelection dragCaret =
- createVisibleSelection(m_page->dragCaretController().caretPosition());
+ const PositionWithAffinity& caretPosition =
+ m_page->dragCaretController().caretPosition();
+ if (!caretPosition.isConnected()) {
+ // "editing/pasteboard/drop-text-events-sideeffect-crash.html" and
+ // "editing/pasteboard/drop-text-events-sideeffect.html" reach here.
+ m_page->dragCaretController().clear();
+ return false;
+ }
+ VisibleSelection dragCaret = createVisibleSelection(
+ SelectionInDOMTree::Builder().collapse(caretPosition).build());
m_page->dragCaretController().clear();
// |innerFrame| can be removed by event handler called by
// |dispatchTextInputEventFor()|.
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandlerTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698