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

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

Issue 2723133004: Get rid of redundant member variable SelectionEditor::m_logicalRange (Closed)
Patch Set: 2017-03-02T18:01:04 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/SelectionEditor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 m_selection = SelectionInDOMTree(); 54 m_selection = SelectionInDOMTree();
55 m_cachedVisibleSelectionInDOMTree = VisibleSelection(); 55 m_cachedVisibleSelectionInDOMTree = VisibleSelection();
56 m_cachedVisibleSelectionInFlatTree = VisibleSelectionInFlatTree(); 56 m_cachedVisibleSelectionInFlatTree = VisibleSelectionInFlatTree();
57 m_cacheIsDirty = false; 57 m_cacheIsDirty = false;
58 if (!shouldAlwaysUseDirectionalSelection()) 58 if (!shouldAlwaysUseDirectionalSelection())
59 return; 59 return;
60 m_selection.m_isDirectional = true; 60 m_selection.m_isDirectional = true;
61 } 61 }
62 62
63 void SelectionEditor::dispose() { 63 void SelectionEditor::dispose() {
64 resetLogicalRange();
65 clearDocumentCachedRange(); 64 clearDocumentCachedRange();
66 clearVisibleSelection(); 65 clearVisibleSelection();
67 } 66 }
68 67
69 Document& SelectionEditor::document() const { 68 Document& SelectionEditor::document() const {
70 DCHECK(lifecycleContext()); 69 DCHECK(lifecycleContext());
71 return *lifecycleContext(); 70 return *lifecycleContext();
72 } 71 }
73 72
74 const VisibleSelection& SelectionEditor::computeVisibleSelectionInDOMTree() 73 const VisibleSelection& SelectionEditor::computeVisibleSelectionInDOMTree()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return; 114 return;
116 m_cachedVisibleSelectionInFlatTree = VisibleSelectionInFlatTree(); 115 m_cachedVisibleSelectionInFlatTree = VisibleSelectionInFlatTree();
117 m_cachedVisibleSelectionInDOMTree = VisibleSelection(); 116 m_cachedVisibleSelectionInDOMTree = VisibleSelection();
118 m_cacheIsDirty = true; 117 m_cacheIsDirty = true;
119 } 118 }
120 119
121 void SelectionEditor::setSelection(const SelectionInDOMTree& newSelection) { 120 void SelectionEditor::setSelection(const SelectionInDOMTree& newSelection) {
122 newSelection.assertValidFor(document()); 121 newSelection.assertValidFor(document());
123 if (m_selection == newSelection) 122 if (m_selection == newSelection)
124 return; 123 return;
125 resetLogicalRange();
126 clearDocumentCachedRange(); 124 clearDocumentCachedRange();
127 markCacheDirty(); 125 markCacheDirty();
128 m_selection = newSelection; 126 m_selection = newSelection;
129 } 127 }
130 128
131 void SelectionEditor::didChangeChildren(const ContainerNode&) { 129 void SelectionEditor::didChangeChildren(const ContainerNode&) {
132 markCacheDirty(); 130 markCacheDirty();
133 didFinishDOMMutation(); 131 didFinishDOMMutation();
134 } 132 }
135 133
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 didFinishDOMMutation(); 341 didFinishDOMMutation();
344 return; 342 return;
345 } 343 }
346 const Position& newBase = 344 const Position& newBase =
347 updatePostionAfterAdoptingTextNodeSplit(m_selection.m_base, oldNode); 345 updatePostionAfterAdoptingTextNodeSplit(m_selection.m_base, oldNode);
348 const Position& newExtent = 346 const Position& newExtent =
349 updatePostionAfterAdoptingTextNodeSplit(m_selection.m_extent, oldNode); 347 updatePostionAfterAdoptingTextNodeSplit(m_selection.m_extent, oldNode);
350 didFinishTextChange(newBase, newExtent); 348 didFinishTextChange(newBase, newExtent);
351 } 349 }
352 350
353 void SelectionEditor::resetLogicalRange() {
354 // Non-collapsed ranges are not allowed to start at the end of a line that
355 // is wrapped, they start at the beginning of the next line instead
356 if (!m_logicalRange)
357 return;
358 m_logicalRange->dispose();
359 m_logicalRange = nullptr;
360 }
361
362 void SelectionEditor::setLogicalRange(Range* range) {
363 DCHECK_EQ(range->ownerDocument(), document());
364 DCHECK(!m_logicalRange) << "A logical range should be one.";
365 m_logicalRange = range;
366 }
367
368 Range* SelectionEditor::firstRange() const { 351 Range* SelectionEditor::firstRange() const {
369 if (m_logicalRange)
370 return m_logicalRange->cloneRange();
yoichio 2017/03/03 01:54:20 Could you proof logically m_logicalRange == firs
371 return firstRangeOf(computeVisibleSelectionInDOMTree()); 352 return firstRangeOf(computeVisibleSelectionInDOMTree());
372 } 353 }
373 354
374 bool SelectionEditor::shouldAlwaysUseDirectionalSelection() const { 355 bool SelectionEditor::shouldAlwaysUseDirectionalSelection() const {
375 return frame()->editor().behavior().shouldConsiderSelectionAsDirectional(); 356 return frame()->editor().behavior().shouldConsiderSelectionAsDirectional();
376 } 357 }
377 358
378 bool SelectionEditor::needsUpdateVisibleSelection() const { 359 bool SelectionEditor::needsUpdateVisibleSelection() const {
379 return m_cacheIsDirty || m_styleVersion != document().styleVersion(); 360 return m_cacheIsDirty || m_styleVersion != document().styleVersion();
380 } 361 }
381 362
382 void SelectionEditor::updateCachedVisibleSelectionIfNeeded() const { 363 void SelectionEditor::updateCachedVisibleSelectionIfNeeded() const {
383 // Note: Since we |FrameCaret::updateApperance()| is called from 364 // Note: Since we |FrameCaret::updateApperance()| is called from
384 // |FrameView::performPostLayoutTasks()|, we check lifecycle against 365 // |FrameView::performPostLayoutTasks()|, we check lifecycle against
385 // |AfterPerformLayout| instead of |LayoutClean|. 366 // |AfterPerformLayout| instead of |LayoutClean|.
386 DCHECK_GE(document().lifecycle().state(), 367 DCHECK_GE(document().lifecycle().state(),
387 DocumentLifecycle::AfterPerformLayout); 368 DocumentLifecycle::AfterPerformLayout);
388 assertSelectionValid(); 369 assertSelectionValid();
389 if (!needsUpdateVisibleSelection()) 370 if (!needsUpdateVisibleSelection())
390 return; 371 return;
Xiaocheng 2017/03/02 20:34:24 This patch has conflict with https://codereview.ch
yosin_UTC9 2017/03/03 10:35:15 Dependent patch doesn't work well for me; I use fo
391 372
392 m_cachedVisibleSelectionInDOMTree = createVisibleSelection(m_selection); 373 m_cachedVisibleSelectionInDOMTree = createVisibleSelection(m_selection);
393 m_cachedVisibleSelectionInFlatTree = createVisibleSelection( 374 m_cachedVisibleSelectionInFlatTree = createVisibleSelection(
394 SelectionInFlatTree::Builder() 375 SelectionInFlatTree::Builder()
395 .setBaseAndExtent(toPositionInFlatTree(m_selection.base()), 376 .setBaseAndExtent(toPositionInFlatTree(m_selection.base()),
396 toPositionInFlatTree(m_selection.extent())) 377 toPositionInFlatTree(m_selection.extent()))
397 .setAffinity(m_selection.affinity()) 378 .setAffinity(m_selection.affinity())
398 .setHasTrailingWhitespace(m_selection.hasTrailingWhitespace()) 379 .setHasTrailingWhitespace(m_selection.hasTrailingWhitespace())
399 .setGranularity(m_selection.granularity()) 380 .setGranularity(m_selection.granularity())
400 .setIsDirectional(m_selection.isDirectional()) 381 .setIsDirectional(m_selection.isDirectional())
(...skipping 12 matching lines...) Expand all
413 394
414 void SelectionEditor::clearDocumentCachedRange() { 395 void SelectionEditor::clearDocumentCachedRange() {
415 m_cachedRange = nullptr; 396 m_cachedRange = nullptr;
416 } 397 }
417 398
418 DEFINE_TRACE(SelectionEditor) { 399 DEFINE_TRACE(SelectionEditor) {
419 visitor->trace(m_frame); 400 visitor->trace(m_frame);
420 visitor->trace(m_selection); 401 visitor->trace(m_selection);
421 visitor->trace(m_cachedVisibleSelectionInDOMTree); 402 visitor->trace(m_cachedVisibleSelectionInDOMTree);
422 visitor->trace(m_cachedVisibleSelectionInFlatTree); 403 visitor->trace(m_cachedVisibleSelectionInFlatTree);
423 visitor->trace(m_logicalRange);
424 visitor->trace(m_cachedRange); 404 visitor->trace(m_cachedRange);
425 SynchronousMutationObserver::trace(visitor); 405 SynchronousMutationObserver::trace(visitor);
426 } 406 }
427 407
428 } // namespace blink 408 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/SelectionEditor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698