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

Side by Side Diff: Source/core/editing/FrameSelection.cpp

Issue 1245843003: [CodeHealth] Use Position::anchorNode instead of deprecatedNode. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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, 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 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 ASSERT(m_frame->document()->lifecycle().state() != DocumentLifecycle::InPain tInvalidation); 1264 ASSERT(m_frame->document()->lifecycle().state() != DocumentLifecycle::InPain tInvalidation);
1265 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 1265 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1266 if (!isNonOrphanedCaret(m_selection)) { 1266 if (!isNonOrphanedCaret(m_selection)) {
1267 clearCaretRect(); 1267 clearCaretRect();
1268 } else { 1268 } else {
1269 if (isTextFormControl(m_selection)) 1269 if (isTextFormControl(m_selection))
1270 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selectio n.start().isCandidate() ? m_selection.start() : Position(), m_selection.affinity ())); 1270 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selectio n.start().isCandidate() ? m_selection.start() : Position(), m_selection.affinity ()));
1271 else 1271 else
1272 updateCaretRect(m_frame->document(), VisiblePosition(m_selection.sta rt(), m_selection.affinity())); 1272 updateCaretRect(m_frame->document(), VisiblePosition(m_selection.sta rt(), m_selection.affinity()));
1273 } 1273 }
1274 return absoluteBoundsForLocalRect(m_selection.start().deprecatedNode(), loca lCaretRectWithoutUpdate()); 1274 return absoluteBoundsForLocalRect(m_selection.start().anchorNode(), localCar etRectWithoutUpdate());
1275 } 1275 }
1276 1276
1277 static LayoutRect localCaretRect(const VisibleSelection& m_selection, const Posi tionWithAffinity& caretPosition, LayoutObject*& layoutObject) 1277 static LayoutRect localCaretRect(const VisibleSelection& m_selection, const Posi tionWithAffinity& caretPosition, LayoutObject*& layoutObject)
1278 { 1278 {
1279 layoutObject = nullptr; 1279 layoutObject = nullptr;
1280 if (!isNonOrphanedCaret(m_selection)) 1280 if (!isNonOrphanedCaret(m_selection))
1281 return LayoutRect(); 1281 return LayoutRect();
1282 1282
1283 return localCaretRectOfPosition(caretPosition, layoutObject); 1283 return localCaretRectOfPosition(caretPosition, layoutObject);
1284 } 1284 }
(...skipping 22 matching lines...) Expand all
1307 1307
1308 m_previousCaretNode = newNode; 1308 m_previousCaretNode = newNode;
1309 m_previousCaretRect = newRect; 1309 m_previousCaretRect = newRect;
1310 m_previousCaretVisibility = caretVisibility(); 1310 m_previousCaretVisibility = caretVisibility();
1311 } 1311 }
1312 1312
1313 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect) 1313 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect)
1314 { 1314 {
1315 if (m_selection.isCaret() && m_shouldPaintCaret) { 1315 if (m_selection.isCaret() && m_shouldPaintCaret) {
1316 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selection.st art(), m_selection.affinity())); 1316 updateCaretRect(m_frame->document(), PositionWithAffinity(m_selection.st art(), m_selection.affinity()));
1317 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai ntOffset, clipRect); 1317 CaretBase::paintCaret(m_selection.start().anchorNode(), context, paintOf fset, clipRect);
1318 } 1318 }
1319 } 1319 }
1320 1320
1321 template <typename Strategy> 1321 template <typename Strategy>
1322 bool FrameSelection::containsAlgorithm(const LayoutPoint& point) 1322 bool FrameSelection::containsAlgorithm(const LayoutPoint& point)
1323 { 1323 {
1324 using PositionType = typename Strategy::PositionType; 1324 using PositionType = typename Strategy::PositionType;
1325 1325
1326 Document* document = m_frame->document(); 1326 Document* document = m_frame->document();
1327 1327
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 } 1803 }
1804 return 0; 1804 return 0;
1805 } 1805 }
1806 1806
1807 // We look for either the form containing the current focus, or for one immediat ely after it 1807 // We look for either the form containing the current focus, or for one immediat ely after it
1808 HTMLFormElement* FrameSelection::currentForm() const 1808 HTMLFormElement* FrameSelection::currentForm() const
1809 { 1809 {
1810 // Start looking either at the active (first responder) node, or where the s election is. 1810 // Start looking either at the active (first responder) node, or where the s election is.
1811 Node* start = m_frame->document()->focusedElement(); 1811 Node* start = m_frame->document()->focusedElement();
1812 if (!start) 1812 if (!start)
1813 start = this->start().deprecatedNode(); 1813 start = this->start().anchorNode();
1814 if (!start) 1814 if (!start)
1815 return 0; 1815 return 0;
1816 1816
1817 // Try walking up the node tree to find a form element. 1817 // Try walking up the node tree to find a form element.
1818 for (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sta rt); element; element = Traversal<HTMLElement>::firstAncestor(*element)) { 1818 for (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sta rt); element; element = Traversal<HTMLElement>::firstAncestor(*element)) {
1819 if (HTMLFormElement* form = associatedFormElement(*element)) 1819 if (HTMLFormElement* form = associatedFormElement(*element))
1820 return form; 1820 return form;
1821 } 1821 }
1822 1822
1823 // Try walking forward in the node tree to find a form element. 1823 // Try walking forward in the node tree to find a form element.
1824 return scanForForm(start); 1824 return scanForForm(start);
1825 } 1825 }
1826 1826
1827 void FrameSelection::revealSelection(const ScrollAlignment& alignment, RevealExt entOption revealExtentOption) 1827 void FrameSelection::revealSelection(const ScrollAlignment& alignment, RevealExt entOption revealExtentOption)
1828 { 1828 {
1829 LayoutRect rect; 1829 LayoutRect rect;
1830 1830
1831 switch (selectionType()) { 1831 switch (selectionType()) {
1832 case NoSelection: 1832 case NoSelection:
1833 return; 1833 return;
1834 case CaretSelection: 1834 case CaretSelection:
1835 rect = LayoutRect(absoluteCaretBounds()); 1835 rect = LayoutRect(absoluteCaretBounds());
1836 break; 1836 break;
1837 case RangeSelection: 1837 case RangeSelection:
1838 rect = LayoutRect(revealExtentOption == RevealExtent ? VisiblePosition(e xtent()).absoluteCaretBounds() : enclosingIntRect(unclippedBounds())); 1838 rect = LayoutRect(revealExtentOption == RevealExtent ? VisiblePosition(e xtent()).absoluteCaretBounds() : enclosingIntRect(unclippedBounds()));
1839 break; 1839 break;
1840 } 1840 }
1841 1841
1842 Position start = this->start(); 1842 Position start = this->start();
1843 ASSERT(start.deprecatedNode()); 1843 ASSERT(start.anchorNode());
1844 if (start.deprecatedNode() && start.deprecatedNode()->layoutObject()) { 1844 if (start.anchorNode() && start.anchorNode()->layoutObject()) {
1845 // FIXME: This code only handles scrolling the startContainer's layer, b ut 1845 // FIXME: This code only handles scrolling the startContainer's layer, b ut
1846 // the selection rect could intersect more than just that. 1846 // the selection rect could intersect more than just that.
1847 // See <rdar://problem/4799899>. 1847 // See <rdar://problem/4799899>.
1848 m_frame->view()->setWasScrolledByUser(true); 1848 m_frame->view()->setWasScrolledByUser(true);
1849 if (start.deprecatedNode()->layoutObject()->scrollRectToVisible(rect, al ignment, alignment)) 1849 if (start.anchorNode()->layoutObject()->scrollRectToVisible(rect, alignm ent, alignment))
1850 updateAppearance(); 1850 updateAppearance();
1851 } 1851 }
1852 } 1852 }
1853 1853
1854 void FrameSelection::setSelectionFromNone() 1854 void FrameSelection::setSelectionFromNone()
1855 { 1855 {
1856 // Put a caret inside the body if the entire frame is editable (either the 1856 // Put a caret inside the body if the entire frame is editable (either the
1857 // entire WebView is editable or designMode is on for this document). 1857 // entire WebView is editable or designMode is on for this document).
1858 1858
1859 Document* document = m_frame->document(); 1859 Document* document = m_frame->document();
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 2043
2044 void showTree(const blink::FrameSelection* sel) 2044 void showTree(const blink::FrameSelection* sel)
2045 { 2045 {
2046 if (sel) 2046 if (sel)
2047 sel->showTreeForThis(); 2047 sel->showTreeForThis();
2048 else 2048 else
2049 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 2049 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
2050 } 2050 }
2051 2051
2052 #endif 2052 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/FormatBlockCommand.cpp ('k') | Source/core/editing/IndentOutdentCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698