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

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 2616623002: Do not send redundant selectionchange-events (decouple focus) (Closed)
Patch Set: Move isSelectionInDocument() and selectionHasFocus() to EditingUtilities 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 const Node* result = nullptr; 365 const Node* result = nullptr;
366 for (const Node* n = &node; n && hasEditableStyle(*n); n = n->parentNode()) { 366 for (const Node* n = &node; n && hasEditableStyle(*n); n = n->parentNode()) {
367 if (n->isElementNode()) 367 if (n->isElementNode())
368 result = n; 368 result = n;
369 if (node.document().body() == n) 369 if (node.document().body() == n)
370 break; 370 break;
371 } 371 }
372 return toElement(const_cast<Node*>(result)); 372 return toElement(const_cast<Node*>(result));
373 } 373 }
374 374
375 bool isSelectionInDocument(const VisibleSelectionInFlatTree& visibleSelection,
376 const Document& document) {
377 const PositionInFlatTree& start = visibleSelection.start();
378 if (start.isNotNull() &&
379 (!start.isConnected() || start.document() != document))
380 return false;
381 const PositionInFlatTree& end = visibleSelection.end();
382 if (end.isNotNull() && (!end.isConnected() || end.document() != document))
383 return false;
384 const PositionInFlatTree extent = visibleSelection.extent();
385 if (extent.isNotNull() &&
386 (!extent.isConnected() || extent.document() != document))
387 return false;
388 return true;
389 }
390
391 bool selectionHasFocus(const LocalFrame& frame) {
392 const VisibleSelectionInFlatTree& selection =
393 frame.selection().computeVisibleSelectionInFlatTree();
394 if (!isSelectionInDocument(selection, *frame.document()))
yosin_UTC9 2017/03/21 06:49:59 We can assume SelectionInFlatTree in FrameSelecito
hugoh_UTC2 2017/03/22 02:54:47 Done.
395 return false;
396
397 const Element* focus = frame.document()->focusedElement();
398 if (!focus) {
399 // No focused element means document root has focus.
400 focus = frame.document()->documentElement();
401 }
402
403 const Node* const nodeWhereSelectionStarts =
yosin_UTC9 2017/03/21 06:49:59 To check base/extent in focus element, we don't ne
hugoh_UTC2 2017/03/22 02:54:47 FrameSelection has no public getter that returns t
404 selection.base().computeContainerNode();
405 const Node* const nodeWhereSelectionEnds =
406 selection.extent().computeContainerNode();
407
408 return focus->containsIncludingHostElements(*nodeWhereSelectionStarts) ||
409 focus->containsIncludingHostElements(*nodeWhereSelectionEnds);
410 }
411
375 ContainerNode* highestEditableRoot( 412 ContainerNode* highestEditableRoot(
376 const Position& position, 413 const Position& position,
377 Element* (*rootEditableElementOf)(const Position&), 414 Element* (*rootEditableElementOf)(const Position&),
378 bool (*hasEditableStyle)(const Node&)) { 415 bool (*hasEditableStyle)(const Node&)) {
379 if (position.isNull()) 416 if (position.isNull())
380 return 0; 417 return 0;
381 418
382 ContainerNode* highestRoot = rootEditableElementOf(position); 419 ContainerNode* highestRoot = rootEditableElementOf(position);
383 if (!highestRoot) 420 if (!highestRoot)
384 return 0; 421 return 0;
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 return InputType::DeleteWordBackward; 2208 return InputType::DeleteWordBackward;
2172 if (granularity == LineBoundary) 2209 if (granularity == LineBoundary)
2173 return InputType::DeleteLineBackward; 2210 return InputType::DeleteLineBackward;
2174 return InputType::DeleteContentBackward; 2211 return InputType::DeleteContentBackward;
2175 default: 2212 default:
2176 return InputType::None; 2213 return InputType::None;
2177 } 2214 }
2178 } 2215 }
2179 2216
2180 } // namespace blink 2217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698