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

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

Issue 315493004: reset VisibleSelection at the Undo command. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add the VisibleSelection::validateIfNeeded method Created 6 years, 6 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 | « Source/core/editing/VisibleSelection.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, 2005, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 764
765 void VisibleSelection::trace(Visitor* visitor) 765 void VisibleSelection::trace(Visitor* visitor)
766 { 766 {
767 visitor->trace(m_base); 767 visitor->trace(m_base);
768 visitor->trace(m_extent); 768 visitor->trace(m_extent);
769 visitor->trace(m_start); 769 visitor->trace(m_start);
770 visitor->trace(m_end); 770 visitor->trace(m_end);
771 visitor->trace(m_changeObserver); 771 visitor->trace(m_changeObserver);
772 } 772 }
773 773
774 static bool isValidPosition(const Position& position)
775 {
776 if (!position.inDocument())
777 return false;
778
779 if (position.anchorType() != Position::PositionIsOffsetInAnchor)
780 return true;
781
782 if (position.offsetInContainerNode() < 0)
783 return false;
784
785 const unsigned offset = static_cast<unsigned>(position.offsetInContainerNode ());
786 const unsigned nodeLength = position.anchorNode()->lengthOfContents();
787 return offset <= nodeLength;
788 }
789
790 void VisibleSelection::validatePositionsIfNeeded()
791 {
792 if (!isValidPosition(m_base) || !isValidPosition(m_extent) || !isValidPositi on(m_start) || !isValidPosition(m_end))
793 validate();
794 }
795
774 #ifndef NDEBUG 796 #ifndef NDEBUG
775 797
776 void VisibleSelection::debugPosition() const 798 void VisibleSelection::debugPosition() const
777 { 799 {
778 fprintf(stderr, "VisibleSelection ===============\n"); 800 fprintf(stderr, "VisibleSelection ===============\n");
779 801
780 if (!m_start.anchorNode()) 802 if (!m_start.anchorNode())
781 fputs("pos: null", stderr); 803 fputs("pos: null", stderr);
782 else if (m_start == m_end) { 804 else if (m_start == m_end) {
783 fprintf(stderr, "pos: %s ", m_start.anchorNode()->nodeName().utf8().da ta()); 805 fprintf(stderr, "pos: %s ", m_start.anchorNode()->nodeName().utf8().da ta());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 sel.showTreeForThis(); 857 sel.showTreeForThis();
836 } 858 }
837 859
838 void showTree(const WebCore::VisibleSelection* sel) 860 void showTree(const WebCore::VisibleSelection* sel)
839 { 861 {
840 if (sel) 862 if (sel)
841 sel->showTreeForThis(); 863 sel->showTreeForThis();
842 } 864 }
843 865
844 #endif 866 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698