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

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-06T13:02:21 rebase 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();
371 return createRange(firstEphemeralRangeOf(computeVisibleSelectionInDOMTree())); 352 return createRange(firstEphemeralRangeOf(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 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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