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

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

Issue 1756763002: 2016-03-02T18:53:01 LayoutPosition Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-25T19:02:18 Created 4 years, 7 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 retainsssshowTree 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
(...skipping 13 matching lines...) Expand all
31 #include "core/dom/Range.h" 31 #include "core/dom/Range.h"
32 #include "core/editing/EditingUtilities.h" 32 #include "core/editing/EditingUtilities.h"
33 #include "core/editing/SelectionAdjuster.h" 33 #include "core/editing/SelectionAdjuster.h"
34 #include "core/editing/iterators/CharacterIterator.h" 34 #include "core/editing/iterators/CharacterIterator.h"
35 #include "core/layout/LayoutObject.h" 35 #include "core/layout/LayoutObject.h"
36 #include "platform/geometry/LayoutPoint.h" 36 #include "platform/geometry/LayoutPoint.h"
37 #include "wtf/Assertions.h" 37 #include "wtf/Assertions.h"
38 #include "wtf/text/CString.h" 38 #include "wtf/text/CString.h"
39 #include "wtf/text/CharacterNames.h" 39 #include "wtf/text/CharacterNames.h"
40 #include "wtf/text/StringBuilder.h" 40 #include "wtf/text/StringBuilder.h"
41 #include <ostream> // NOLINT
41 42
42 namespace blink { 43 namespace blink {
43 44
44 template <typename Strategy> 45 template <typename Strategy>
45 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate() 46 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate()
46 : m_affinity(TextAffinity::Downstream) 47 : m_affinity(TextAffinity::Downstream)
47 , m_changeObserver(nullptr) 48 , m_changeObserver(nullptr)
48 , m_selectionType(NoSelection) 49 , m_selectionType(NoSelection)
49 , m_baseIsFirst(true) 50 , m_baseIsFirst(true)
50 , m_isDirectional(false) 51 , m_isDirectional(false)
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 const bool hasTrailingWhitespace = m_hasTrailingWhitespace; 848 const bool hasTrailingWhitespace = m_hasTrailingWhitespace;
848 validate(m_granularity); 849 validate(m_granularity);
849 if (!hasTrailingWhitespace) 850 if (!hasTrailingWhitespace)
850 return; 851 return;
851 appendTrailingWhitespace(); 852 appendTrailingWhitespace();
852 } 853 }
853 854
854 template <typename Strategy> 855 template <typename Strategy>
855 void VisibleSelectionTemplate<Strategy>::validatePositionsIfNeeded() 856 void VisibleSelectionTemplate<Strategy>::validatePositionsIfNeeded()
856 { 857 {
857 if (!isValidPosition(m_base) || !isValidPosition(m_extent) || !isValidPositi on(m_start) || !isValidPosition(m_end)) 858 if (!m_base.inShadowIncludingDocument() || !m_extent.inShadowIncludingDocume nt()) {
858 validate(); 859 *this = VisibleSelectionTemplate();
860 return;
861 }
862 if (isValidPosition(m_base) && isValidPosition(m_extent) && isValidPosition( m_start) && isValidPosition(m_end))
863 return;
864 validate();
859 } 865 }
860 866
861 template <typename Strategy> 867 template <typename Strategy>
862 static bool equalSelectionsAlgorithm(const VisibleSelectionTemplate<Strategy>& s election1, const VisibleSelectionTemplate<Strategy>& selection2) 868 static bool equalSelectionsAlgorithm(const VisibleSelectionTemplate<Strategy>& s election1, const VisibleSelectionTemplate<Strategy>& selection2)
863 { 869 {
864 if (selection1.affinity() != selection2.affinity() || selection1.isDirection al() != selection2.isDirectional()) 870 if (selection1.affinity() != selection2.affinity() || selection1.isDirection al() != selection2.isDirectional())
865 return false; 871 return false;
866 872
867 if (selection1.isNone()) 873 if (selection1.isNone())
868 return selection2.isNone(); 874 return selection2.isNone();
(...skipping 16 matching lines...) Expand all
885 891
886 template <typename Strategy> 892 template <typename Strategy>
887 bool VisibleSelectionTemplate<Strategy>::operator==(const VisibleSelectionTempla te<Strategy>& other) const 893 bool VisibleSelectionTemplate<Strategy>::operator==(const VisibleSelectionTempla te<Strategy>& other) const
888 { 894 {
889 return equalSelectionsAlgorithm<Strategy>(*this, other); 895 return equalSelectionsAlgorithm<Strategy>(*this, other);
890 } 896 }
891 897
892 #ifndef NDEBUG 898 #ifndef NDEBUG
893 899
894 template <typename Strategy> 900 template <typename Strategy>
895 void VisibleSelectionTemplate<Strategy>::debugPosition(const char* message) cons t
896 {
897 fprintf(stderr, "VisibleSelection (%s) ===============\n", message);
898
899 if (m_baseIsFirst) {
900 m_start.debugPosition("start: ");
901 m_base.debugPosition("base: ");
902 m_end.debugPosition("end: ");
903 m_extent.debugPosition("extent: ");
904 } else {
905 m_start.debugPosition("start: ");
906 m_extent.debugPosition("extent: ");
907 m_end.debugPosition("end: ");
908 m_base.debugPosition("base: ");
909 }
910
911 fprintf(stderr, "isDirectional=%s\n", isDirectional() ? "true" : "false");
912 fprintf(stderr, "affinity=%s\n", affinity() == TextAffinity::Downstream ? "D OWNSTREaM" : affinity() == TextAffinity::Upstream ? "UPSTREAM" : "UNKNOWN");
913 fprintf(stderr, "================================\n");
914 }
915
916 template <typename Strategy>
917 void VisibleSelectionTemplate<Strategy>::formatForDebugger(char* buffer, unsigne d length) const 901 void VisibleSelectionTemplate<Strategy>::formatForDebugger(char* buffer, unsigne d length) const
918 { 902 {
919 StringBuilder result; 903 StringBuilder result;
920 String s; 904 String s;
921 905
922 if (isNone()) { 906 if (isNone()) {
923 result.appendLiteral("<none>"); 907 result.appendLiteral("<none>");
924 } else { 908 } else {
925 const int FormatBufferSize = 1024; 909 const int FormatBufferSize = 1024;
926 char s[FormatBufferSize]; 910 char s[FormatBufferSize];
927 result.appendLiteral("from "); 911 result.appendLiteral("from ");
928 start().formatForDebugger(s, FormatBufferSize); 912 start().formatForDebugger(s, FormatBufferSize);
929 result.append(s); 913 result.append(s);
930 result.appendLiteral(" to "); 914 result.appendLiteral(" to ");
931 end().formatForDebugger(s, FormatBufferSize); 915 end().formatForDebugger(s, FormatBufferSize);
932 result.append(s); 916 result.append(s);
933 } 917 }
934 918
935 strncpy(buffer, result.toString().utf8().data(), length - 1); 919 strncpy(buffer, result.toString().utf8().data(), length - 1);
936 } 920 }
937 921
938 template <typename Strategy> 922 template <typename Strategy>
923 void VisibleSelectionTemplate<Strategy>::debugPosition(const char* message) cons t
924 {
925 VLOG(0) << message << ' ' << *this;
926 }
927
928 template <typename Strategy>
939 void VisibleSelectionTemplate<Strategy>::showTreeForThis() const 929 void VisibleSelectionTemplate<Strategy>::showTreeForThis() const
940 { 930 {
941 if (start().anchorNode()) { 931 if (!start().anchorNode())
942 start().anchorNode()->showTreeAndMark(start().anchorNode(), "S", end().a nchorNode(), "E"); 932 return;
943 fputs("start: ", stderr); 933 start().anchorNode()->showTreeAndMark(start().anchorNode(), "S", end().ancho rNode(), "E");
944 start().showAnchorTypeAndOffset(); 934 VLOG(0) << *this;
945 fputs("end: ", stderr);
946 end().showAnchorTypeAndOffset();
947 }
948 } 935 }
949 936
950 #endif 937 #endif
951 938
952 template class CORE_TEMPLATE_EXPORT VisibleSelectionTemplate<EditingStrategy>; 939 template class CORE_TEMPLATE_EXPORT VisibleSelectionTemplate<EditingStrategy>;
953 template class CORE_TEMPLATE_EXPORT VisibleSelectionTemplate<EditingInFlatTreeSt rategy>; 940 template class CORE_TEMPLATE_EXPORT VisibleSelectionTemplate<EditingInFlatTreeSt rategy>;
954 941
942 std::ostream& operator<<(std::ostream& ostream, const VisibleSelection& selectio n)
943 {
944 return ostream << "VisibleSelection(base=" << selection.base()
945 << " extent=" << selection.extent()
946 << " start=" << selection.start()
947 << " end=" << selection.end()
948 << selection.affinity()
949 << (selection.isDirectional() ? "Directional" : "NotDirectional") << ')' ;
950 }
951
952 std::ostream& operator<<(std::ostream& ostream, const VisibleSelectionInFlatTree & selection)
953 {
954 return ostream << "VisibleSelection(base=" << selection.base()
955 << " extent=" << selection.extent()
956 << " start=" << selection.start()
957 << " end=" << selection.end()
958 << selection.affinity()
959 << (selection.isDirectional() ? "Directional" : "NotDirectional") << ')' ;
960 }
961
955 } // namespace blink 962 } // namespace blink
956 963
957 #ifndef NDEBUG 964 #ifndef NDEBUG
958 965
959 void showTree(const blink::VisibleSelection& sel) 966 void showTree(const blink::VisibleSelection& sel)
960 { 967 {
961 sel.showTreeForThis(); 968 sel.showTreeForThis();
962 } 969 }
963 970
964 void showTree(const blink::VisibleSelection* sel) 971 void showTree(const blink::VisibleSelection* sel)
965 { 972 {
966 if (sel) 973 if (sel)
967 sel->showTreeForThis(); 974 sel->showTreeForThis();
968 } 975 }
969 976
970 void showTree(const blink::VisibleSelectionInFlatTree& sel) 977 void showTree(const blink::VisibleSelectionInFlatTree& sel)
971 { 978 {
972 sel.showTreeForThis(); 979 sel.showTreeForThis();
973 } 980 }
974 981
975 void showTree(const blink::VisibleSelectionInFlatTree* sel) 982 void showTree(const blink::VisibleSelectionInFlatTree* sel)
976 { 983 {
977 if (sel) 984 if (sel)
978 sel->showTreeForThis(); 985 sel->showTreeForThis();
979 } 986 }
980 #endif 987 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.h ('k') | third_party/WebKit/Source/core/editing/VisibleUnits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698