| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. | 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 template <typename Strategy> | 53 template <typename Strategy> |
| 54 VisiblePositionTemplate<Strategy>::VisiblePositionTemplate(const PositionWithAff
inityTemplate<Strategy>& positionWithAffinity) | 54 VisiblePositionTemplate<Strategy>::VisiblePositionTemplate(const PositionWithAff
inityTemplate<Strategy>& positionWithAffinity) |
| 55 : m_positionWithAffinity(positionWithAffinity) | 55 : m_positionWithAffinity(positionWithAffinity) |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 template<typename Strategy> | 59 template<typename Strategy> |
| 60 VisiblePositionTemplate<Strategy> VisiblePositionTemplate<Strategy>::create(cons
t PositionWithAffinityTemplate<Strategy>& positionWithAffinity) | 60 VisiblePositionTemplate<Strategy> VisiblePositionTemplate<Strategy>::create(cons
t PositionWithAffinityTemplate<Strategy>& positionWithAffinity) |
| 61 { | 61 { |
| 62 const PositionTemplate<Strategy> deepPosition = canonicalPositionOf(position
WithAffinity.position()); | 62 if (positionWithAffinity.isNull()) |
| 63 return VisiblePositionTemplate<Strategy>(); |
| 64 DCHECK(positionWithAffinity.position().inShadowIncludingDocument()) << posit
ionWithAffinity; |
| 65 const PositionTemplate<Strategy>& deepPosition = canonicalPositionOf(positio
nWithAffinity.position()); |
| 63 if (deepPosition.isNull()) | 66 if (deepPosition.isNull()) |
| 64 return VisiblePositionTemplate<Strategy>(); | 67 return VisiblePositionTemplate<Strategy>(); |
| 65 DCHECK(positionWithAffinity.position().inShadowIncludingDocument()) << posit
ionWithAffinity; | 68 DCHECK(deepPosition.inShadowIncludingDocument()) << positionWithAffinity; |
| 66 const PositionWithAffinityTemplate<Strategy> downstreamPosition(deepPosition
); | 69 const PositionWithAffinityTemplate<Strategy> downstreamPosition(deepPosition
); |
| 67 if (positionWithAffinity.affinity() == TextAffinity::Downstream) | 70 if (positionWithAffinity.affinity() == TextAffinity::Downstream) |
| 68 return VisiblePositionTemplate<Strategy>(downstreamPosition); | 71 return VisiblePositionTemplate<Strategy>(downstreamPosition); |
| 69 | 72 |
| 70 // When not at a line wrap, make sure to end up with | 73 // When not at a line wrap, make sure to end up with |
| 71 // |TextAffinity::Downstream| affinity. | 74 // |TextAffinity::Downstream| affinity. |
| 72 const PositionWithAffinityTemplate<Strategy> upstreamPosition(deepPosition,
TextAffinity::Upstream); | 75 const PositionWithAffinityTemplate<Strategy> upstreamPosition(deepPosition,
TextAffinity::Upstream); |
| 73 if (inSameLine(downstreamPosition, upstreamPosition)) | 76 if (inSameLine(downstreamPosition, upstreamPosition)) |
| 74 return VisiblePositionTemplate<Strategy>(downstreamPosition); | 77 return VisiblePositionTemplate<Strategy>(downstreamPosition); |
| 75 return VisiblePositionTemplate<Strategy>(upstreamPosition); | 78 return VisiblePositionTemplate<Strategy>(upstreamPosition); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 93 VisiblePositionInFlatTree createVisiblePosition(const PositionInFlatTreeWithAffi
nity& positionWithAffinity) | 96 VisiblePositionInFlatTree createVisiblePosition(const PositionInFlatTreeWithAffi
nity& positionWithAffinity) |
| 94 { | 97 { |
| 95 return VisiblePositionInFlatTree::create(positionWithAffinity); | 98 return VisiblePositionInFlatTree::create(positionWithAffinity); |
| 96 } | 99 } |
| 97 | 100 |
| 98 #ifndef NDEBUG | 101 #ifndef NDEBUG |
| 99 | 102 |
| 100 template<typename Strategy> | 103 template<typename Strategy> |
| 101 void VisiblePositionTemplate<Strategy>::debugPosition(const char* msg) const | 104 void VisiblePositionTemplate<Strategy>::debugPosition(const char* msg) const |
| 102 { | 105 { |
| 103 if (isNull()) { | 106 VLOG(0) << msg << ' ' << *this; |
| 104 fprintf(stderr, "Position [%s]: null\n", msg); | |
| 105 return; | |
| 106 } | |
| 107 deepEquivalent().debugPosition(msg); | |
| 108 } | 107 } |
| 109 | 108 |
| 110 template<typename Strategy> | 109 template<typename Strategy> |
| 111 void VisiblePositionTemplate<Strategy>::formatForDebugger(char* buffer, unsigned
length) const | 110 void VisiblePositionTemplate<Strategy>::formatForDebugger(char* buffer, unsigned
length) const |
| 112 { | 111 { |
| 113 deepEquivalent().formatForDebugger(buffer, length); | 112 deepEquivalent().formatForDebugger(buffer, length); |
| 114 } | 113 } |
| 115 | 114 |
| 116 template<typename Strategy> | 115 template<typename Strategy> |
| 117 void VisiblePositionTemplate<Strategy>::showTreeForThis() const | 116 void VisiblePositionTemplate<Strategy>::showTreeForThis() const |
| 118 { | 117 { |
| 119 deepEquivalent().showTreeForThis(); | 118 deepEquivalent().showTreeForThis(); |
| 119 VLOG(0) << *this; |
| 120 } | 120 } |
| 121 | 121 |
| 122 #endif | 122 #endif |
| 123 | 123 |
| 124 template class CORE_TEMPLATE_EXPORT VisiblePositionTemplate<EditingStrategy>; | 124 template class CORE_TEMPLATE_EXPORT VisiblePositionTemplate<EditingStrategy>; |
| 125 template class CORE_TEMPLATE_EXPORT VisiblePositionTemplate<EditingInFlatTreeStr
ategy>; | 125 template class CORE_TEMPLATE_EXPORT VisiblePositionTemplate<EditingInFlatTreeStr
ategy>; |
| 126 | 126 |
| 127 std::ostream& operator<<(std::ostream& ostream, const VisiblePosition& position) | 127 std::ostream& operator<<(std::ostream& ostream, const VisiblePosition& position) |
| 128 { | 128 { |
| 129 return ostream << position.deepEquivalent() << '/' << position.affinity(); | 129 return ostream << position.deepEquivalent() << '/' << position.affinity(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 146 } | 146 } |
| 147 DVLOG(0) << "Cannot showTree for (nil) VisiblePosition."; | 147 DVLOG(0) << "Cannot showTree for (nil) VisiblePosition."; |
| 148 } | 148 } |
| 149 | 149 |
| 150 void showTree(const blink::VisiblePosition& vpos) | 150 void showTree(const blink::VisiblePosition& vpos) |
| 151 { | 151 { |
| 152 vpos.showTreeForThis(); | 152 vpos.showTreeForThis(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 #endif | 155 #endif |
| OLD | NEW |