| OLD | NEW |
| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (isNone()) | 197 if (isNone()) |
| 198 return false; | 198 return false; |
| 199 Position start = m_start.parentAnchoredEquivalent(); | 199 Position start = m_start.parentAnchoredEquivalent(); |
| 200 Position end = m_end.parentAnchoredEquivalent(); | 200 Position end = m_end.parentAnchoredEquivalent(); |
| 201 TrackExceptionState exceptionState; | 201 TrackExceptionState exceptionState; |
| 202 return Range::intersectsNode(node, start, end, exceptionState) && !exception
State.hadException(); | 202 return Range::intersectsNode(node, start, end, exceptionState) && !exception
State.hadException(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 PassRefPtrWillBeRawPtr<Range> VisibleSelection::toNormalizedRange() const | 205 PassRefPtrWillBeRawPtr<Range> VisibleSelection::toNormalizedRange() const |
| 206 { | 206 { |
| 207 Position start, end; |
| 208 if (toNormalizedPositions(start, end)) |
| 209 return Range::create(*start.document(), start, end); |
| 210 return nullptr; |
| 211 } |
| 212 |
| 213 bool VisibleSelection::toNormalizedPositions(Position& start, Position& end) con
st |
| 214 { |
| 207 if (isNone()) | 215 if (isNone()) |
| 208 return nullptr; | 216 return false; |
| 209 | 217 |
| 210 // Make sure we have an updated layout since this function is called | 218 // Make sure we have an updated layout since this function is called |
| 211 // in the course of running edit commands which modify the DOM. | 219 // in the course of running edit commands which modify the DOM. |
| 212 // Failing to call this can result in equivalentXXXPosition calls returning | 220 // Failing to call this can result in equivalentXXXPosition calls returning |
| 213 // incorrect results. | 221 // incorrect results. |
| 214 m_start.document()->updateLayout(); | 222 m_start.document()->updateLayout(); |
| 215 | 223 |
| 216 // Check again, because updating layout can clear the selection. | 224 // Check again, because updating layout can clear the selection. |
| 217 if (isNone()) | 225 if (isNone()) |
| 218 return nullptr; | 226 return false; |
| 219 | 227 |
| 220 Position s, e; | |
| 221 if (isCaret()) { | 228 if (isCaret()) { |
| 222 // If the selection is a caret, move the range start upstream. This help
s us match | 229 // If the selection is a caret, move the range start upstream. This help
s us match |
| 223 // the conventions of text editors tested, which make style determinatio
ns based | 230 // the conventions of text editors tested, which make style determinatio
ns based |
| 224 // on the character before the caret, if any. | 231 // on the character before the caret, if any. |
| 225 s = m_start.upstream().parentAnchoredEquivalent(); | 232 start = m_start.upstream().parentAnchoredEquivalent(); |
| 226 e = s; | 233 end = start; |
| 227 } else { | 234 } else { |
| 228 // If the selection is a range, select the minimum range that encompasse
s the selection. | 235 // If the selection is a range, select the minimum range that encompasse
s the selection. |
| 229 // Again, this is to match the conventions of text editors tested, which
make style | 236 // Again, this is to match the conventions of text editors tested, which
make style |
| 230 // determinations based on the first character of the selection. | 237 // determinations based on the first character of the selection. |
| 231 // For instance, this operation helps to make sure that the "X" selected
below is the | 238 // For instance, this operation helps to make sure that the "X" selected
below is the |
| 232 // only thing selected. The range should not be allowed to "leak" out to
the end of the | 239 // only thing selected. The range should not be allowed to "leak" out to
the end of the |
| 233 // previous text node, or to the beginning of the next text node, each o
f which has a | 240 // previous text node, or to the beginning of the next text node, each o
f which has a |
| 234 // different style. | 241 // different style. |
| 235 // | 242 // |
| 236 // On a treasure map, <b>X</b> marks the spot. | 243 // On a treasure map, <b>X</b> marks the spot. |
| 237 // ^ selected | 244 // ^ selected |
| 238 // | 245 // |
| 239 ASSERT(isRange()); | 246 ASSERT(isRange()); |
| 240 s = m_start.downstream(); | 247 start = m_start.downstream(); |
| 241 e = m_end.upstream(); | 248 end = m_end.upstream(); |
| 242 if (comparePositions(s, e) > 0) { | 249 if (comparePositions(start, end) > 0) { |
| 243 // Make sure the start is before the end. | 250 // Make sure the start is before the end. |
| 244 // The end can wind up before the start if collapsed whitespace is t
he only thing selected. | 251 // The end can wind up before the start if collapsed whitespace is t
he only thing selected. |
| 245 Position tmp = s; | 252 Position tmp = start; |
| 246 s = e; | 253 start = end; |
| 247 e = tmp; | 254 end = tmp; |
| 248 } | 255 } |
| 249 s = s.parentAnchoredEquivalent(); | 256 start = start.parentAnchoredEquivalent(); |
| 250 e = e.parentAnchoredEquivalent(); | 257 end = end.parentAnchoredEquivalent(); |
| 251 } | 258 } |
| 252 | 259 |
| 253 if (!s.containerNode() || !e.containerNode()) | 260 if (!start.containerNode() || !end.containerNode()) |
| 254 return nullptr; | 261 return false; |
| 255 | 262 |
| 256 // VisibleSelections are supposed to always be valid. This constructor will
ASSERT | 263 return true; |
| 257 // if a valid range could not be created, which is fine for this callsite. | |
| 258 return Range::create(*s.document(), s, e); | |
| 259 } | 264 } |
| 260 | 265 |
| 261 bool VisibleSelection::expandUsingGranularity(TextGranularity granularity) | 266 bool VisibleSelection::expandUsingGranularity(TextGranularity granularity) |
| 262 { | 267 { |
| 263 if (isNone()) | 268 if (isNone()) |
| 264 return false; | 269 return false; |
| 265 | 270 |
| 266 // FIXME: Do we need to check all of them? | 271 // FIXME: Do we need to check all of them? |
| 267 Position oldBase = m_base; | 272 Position oldBase = m_base; |
| 268 Position oldExtent = m_extent; | 273 Position oldExtent = m_extent; |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 sel.showTreeForThis(); | 871 sel.showTreeForThis(); |
| 867 } | 872 } |
| 868 | 873 |
| 869 void showTree(const blink::VisibleSelection* sel) | 874 void showTree(const blink::VisibleSelection* sel) |
| 870 { | 875 { |
| 871 if (sel) | 876 if (sel) |
| 872 sel->showTreeForThis(); | 877 sel->showTreeForThis(); |
| 873 } | 878 } |
| 874 | 879 |
| 875 #endif | 880 #endif |
| OLD | NEW |