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

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

Issue 2153043002: Make "Undo" command to restore selection after validating with the latest Layout tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-07-21T19:03:31 Created 4 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, 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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 return isRichlyEditablePosition(toPositionInDOMTree(start())); 723 return isRichlyEditablePosition(toPositionInDOMTree(start()));
724 } 724 }
725 725
726 template <typename Strategy> 726 template <typename Strategy>
727 Element* VisibleSelectionTemplate<Strategy>::rootEditableElement() const 727 Element* VisibleSelectionTemplate<Strategy>::rootEditableElement() const
728 { 728 {
729 return rootEditableElementOf(start()); 729 return rootEditableElementOf(start());
730 } 730 }
731 731
732 template <typename Strategy> 732 template <typename Strategy>
733 static bool isValidPosition(const PositionTemplate<Strategy>& position)
734 {
735 if (!position.isConnected())
736 return false;
737
738 if (!position.isOffsetInAnchor())
739 return true;
740
741 if (position.offsetInContainerNode() < 0)
742 return false;
743
744 const unsigned offset = static_cast<unsigned>(position.offsetInContainerNode ());
745 const unsigned nodeLength = position.anchorNode()->lengthOfContents();
746 return offset <= nodeLength;
747 }
748
749 template <typename Strategy>
750 void VisibleSelectionTemplate<Strategy>::updateIfNeeded() 733 void VisibleSelectionTemplate<Strategy>::updateIfNeeded()
751 { 734 {
752 Document* document = m_base.document(); 735 Document* document = m_base.document();
753 if (!document) 736 if (!document)
754 return; 737 return;
755 document->updateStyleAndLayoutIgnorePendingStylesheets(); 738 document->updateStyleAndLayoutIgnorePendingStylesheets();
756 const bool hasTrailingWhitespace = m_hasTrailingWhitespace; 739 const bool hasTrailingWhitespace = m_hasTrailingWhitespace;
757 validate(m_granularity); 740 validate(m_granularity);
758 if (!hasTrailingWhitespace) 741 if (!hasTrailingWhitespace)
759 return; 742 return;
760 appendTrailingWhitespace(); 743 appendTrailingWhitespace();
761 } 744 }
762 745
746 // TODO(yosin): Since |validatePositionsIfNeeded()| is called just one place,
747 // we should move it to the call site.
763 template <typename Strategy> 748 template <typename Strategy>
764 void VisibleSelectionTemplate<Strategy>::validatePositionsIfNeeded() 749 void VisibleSelectionTemplate<Strategy>::validatePositionsIfNeeded()
765 { 750 {
766 if (!m_base.isConnected() || !m_extent.isConnected()) { 751 if (!m_base.isConnected() || !m_extent.isConnected()) {
767 *this = VisibleSelectionTemplate(); 752 *this = VisibleSelectionTemplate();
768 return; 753 return;
769 } 754 }
770 if (isValidPosition(m_base) && isValidPosition(m_extent) && isValidPosition( m_start) && isValidPosition(m_end)) 755 updateIfNeeded();
771 return;
772 validate();
773 } 756 }
774 757
775 template <typename Strategy> 758 template <typename Strategy>
776 static bool equalSelectionsAlgorithm(const VisibleSelectionTemplate<Strategy>& s election1, const VisibleSelectionTemplate<Strategy>& selection2) 759 static bool equalSelectionsAlgorithm(const VisibleSelectionTemplate<Strategy>& s election1, const VisibleSelectionTemplate<Strategy>& selection2)
777 { 760 {
778 if (selection1.affinity() != selection2.affinity() || selection1.isDirection al() != selection2.isDirectional()) 761 if (selection1.affinity() != selection2.affinity() || selection1.isDirection al() != selection2.isDirectional())
779 return false; 762 return false;
780 763
781 if (selection1.isNone()) 764 if (selection1.isNone())
782 return selection2.isNone(); 765 return selection2.isNone();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 { 891 {
909 sel.showTreeForThis(); 892 sel.showTreeForThis();
910 } 893 }
911 894
912 void showTree(const blink::VisibleSelectionInFlatTree* sel) 895 void showTree(const blink::VisibleSelectionInFlatTree* sel)
913 { 896 {
914 if (sel) 897 if (sel)
915 sel->showTreeForThis(); 898 sel->showTreeForThis();
916 } 899 }
917 #endif 900 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698