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

Unified Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 2616623002: Do not send redundant selectionchange-events (decouple focus) (Closed)
Patch Set: Get Document from selection Created 3 years, 9 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/editing/EditingUtilities.cpp
diff --git a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
index 736d889bf286020e88b7afa6ef2f399bf276d8fd..488d718b20351078c9bf732a3a7c27a4e4b3ac36 100644
--- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
+++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
@@ -374,6 +374,23 @@ Element* rootEditableElement(const Node& node) {
return toElement(const_cast<Node*>(result));
}
+bool selectionHasFocus(const SelectionInFlatTree& selection) {
+ const Document* document = selection.base().document();
yosin_UTC9 2017/03/22 09:11:35 Let's handle document == nullptr case, selection.i
hugoh_UTC2 2017/03/22 09:19:14 You mean when selection.isNone(), we return false?
yosin_UTC9 2017/03/22 09:26:35 Yes, just return false if selection.isNone(), So,
hugoh_UTC2 2017/03/22 09:41:11 Done. See PS26.
+ const Element* focus = document->focusedElement();
+ if (!focus) {
+ // No focused element means document root has focus.
+ focus = document->documentElement();
+ }
+
+ const Node* const nodeWhereSelectionStarts =
+ selection.base().computeContainerNode();
+ const Node* const nodeWhereSelectionEnds =
+ selection.extent().computeContainerNode();
+
+ return focus->containsIncludingHostElements(*nodeWhereSelectionStarts) ||
+ focus->containsIncludingHostElements(*nodeWhereSelectionEnds);
+}
+
ContainerNode* highestEditableRoot(
const Position& position,
Element* (*rootEditableElementOf)(const Position&),
« no previous file with comments | « third_party/WebKit/Source/core/editing/EditingUtilities.h ('k') | third_party/WebKit/Source/core/editing/PendingSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698