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

Unified Diff: third_party/WebKit/Source/core/dom/Range.cpp

Issue 2687273002: Selection API: Mutating a Range object after adding it to Selection should update Selection attribu… (Closed)
Patch Set: . Created 3 years, 10 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
Index: third_party/WebKit/Source/core/dom/Range.cpp
diff --git a/third_party/WebKit/Source/core/dom/Range.cpp b/third_party/WebKit/Source/core/dom/Range.cpp
index 3187a1e9c746f3eef49a70065a484b4e3f5c92da..8ee35a6d8c63fe8858d9fc72dc8f7b96cae11e2a 100644
--- a/third_party/WebKit/Source/core/dom/Range.cpp
+++ b/third_party/WebKit/Source/core/dom/Range.cpp
@@ -36,6 +36,8 @@
#include "core/dom/ProcessingInstruction.h"
#include "core/dom/Text.h"
#include "core/editing/EditingUtilities.h"
+#include "core/editing/EphemeralRange.h"
+#include "core/editing/FrameSelection.h"
#include "core/editing/VisiblePosition.h"
#include "core/editing/VisibleUnits.h"
#include "core/editing/iterators/TextIterator.h"
@@ -184,6 +186,8 @@ void Range::setStart(Node* refNode,
if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
yosin_UTC9 2017/02/10 10:26:27 nit: Can we use early-return style? if (didMoveDo
tkent 2017/02/13 04:04:13 Good point. I'll investigate Firefox/Edge behavio
tkent 2017/02/13 05:45:29 Both of Firefox and Edge keep Selection.getRangeAt
tkent 2017/02/13 07:31:40 We discussed offline, and agreed that we should un
collapse(true);
+ else
+ updateSelectionIfAddedToSelection();
}
void Range::setEnd(Node* refNode, int offset, ExceptionState& exceptionState) {
@@ -208,6 +212,8 @@ void Range::setEnd(Node* refNode, int offset, ExceptionState& exceptionState) {
if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
yosin_UTC9 2017/02/10 10:26:27 Similar to L187 in Range::setStart()
tkent 2017/02/13 07:31:40 Done.
collapse(false);
+ else
+ updateSelectionIfAddedToSelection();
}
void Range::setStart(const Position& start, ExceptionState& exceptionState) {
@@ -227,6 +233,7 @@ void Range::collapse(bool toStart) {
m_end = m_start;
else
m_start = m_end;
+ updateSelectionIfAddedToSelection();
}
bool Range::isNodeFullyContained(Node& node) const {
@@ -1218,6 +1225,7 @@ void Range::selectNodeContents(Node* refNode, ExceptionState& exceptionState) {
m_start.setToStartOfNode(*refNode);
m_end.setToEndOfNode(*refNode);
+ updateSelectionIfAddedToSelection();
}
bool Range::selectNodeContents(Node* refNode, Position& start, Position& end) {
@@ -1700,6 +1708,16 @@ FloatRect Range::boundingRect() const {
return result;
}
+void Range::updateSelectionIfAddedToSelection() {
+ if (!ownerDocument().frame())
+ return;
+ FrameSelection& selection = ownerDocument().frame()->selection();
+ if (this != selection.documentCachedRange())
+ return;
+ selection.setSelectedRange(EphemeralRange(this), VP_DEFAULT_AFFINITY);
+ selection.cacheRangeOfDocument(this);
+}
+
DEFINE_TRACE(Range) {
visitor->trace(m_ownerDocument);
visitor->trace(m_start);

Powered by Google App Engine
This is Rietveld 408576698