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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 Position oldBase = m_base; | 257 Position oldBase = m_base; |
258 Position oldExtent = m_extent; | 258 Position oldExtent = m_extent; |
259 Position oldStart = m_start; | 259 Position oldStart = m_start; |
260 Position oldEnd = m_end; | 260 Position oldEnd = m_end; |
261 validate(granularity); | 261 validate(granularity); |
262 if (m_base != oldBase || m_extent != oldExtent || m_start != oldStart || m_e
nd != oldEnd) | 262 if (m_base != oldBase || m_extent != oldExtent || m_start != oldStart || m_e
nd != oldEnd) |
263 didChange(); | 263 didChange(); |
264 return true; | 264 return true; |
265 } | 265 } |
266 | 266 |
267 static PassRefPtr<Range> makeSearchRange(const Position& pos) | |
268 { | |
269 Node* node = pos.deprecatedNode(); | |
270 if (!node) | |
271 return nullptr; | |
272 Document& document = node->document(); | |
273 if (!document.documentElement()) | |
274 return nullptr; | |
275 Element* boundary = enclosingBlockFlowElement(*node); | |
276 if (!boundary) | |
277 return nullptr; | |
278 | |
279 RefPtr<Range> searchRange(Range::create(document)); | |
280 TrackExceptionState exceptionState; | |
281 | |
282 Position start(pos.parentAnchoredEquivalent()); | |
283 searchRange->selectNodeContents(boundary, exceptionState); | |
284 searchRange->setStart(start.containerNode(), start.offsetInContainerNode(),
exceptionState); | |
285 | |
286 ASSERT(!exceptionState.had_exception()); | |
287 if (exceptionState.had_exception()) | |
288 return nullptr; | |
289 | |
290 return searchRange.release(); | |
291 } | |
292 | |
293 void VisibleSelection::appendTrailingWhitespace() | |
294 { | |
295 RefPtr<Range> searchRange = makeSearchRange(m_end); | |
296 if (!searchRange) | |
297 return; | |
298 | |
299 CharacterIterator charIt(searchRange.get(), TextIteratorEmitsCharactersBetwe
enAllVisiblePositions); | |
300 bool changed = false; | |
301 | |
302 for (; charIt.length(); charIt.advance(1)) { | |
303 UChar c = charIt.characterAt(0); | |
304 if ((!isSpaceOrNewline(c) && c != noBreakSpace) || c == '\n') | |
305 break; | |
306 m_end = charIt.range()->endPosition(); | |
307 changed = true; | |
308 } | |
309 if (changed) | |
310 didChange(); | |
311 } | |
312 | |
313 void VisibleSelection::setBaseAndExtentToDeepEquivalents() | 267 void VisibleSelection::setBaseAndExtentToDeepEquivalents() |
314 { | 268 { |
315 // Move the selection to rendered positions, if possible. | 269 // Move the selection to rendered positions, if possible. |
316 bool baseAndExtentEqual = m_base == m_extent; | 270 bool baseAndExtentEqual = m_base == m_extent; |
317 if (m_base.isNotNull()) { | 271 if (m_base.isNotNull()) { |
318 m_base = VisiblePosition(m_base, m_affinity).deepEquivalent(); | 272 m_base = VisiblePosition(m_base, m_affinity).deepEquivalent(); |
319 if (baseAndExtentEqual) | 273 if (baseAndExtentEqual) |
320 m_extent = m_base; | 274 m_extent = m_base; |
321 } | 275 } |
322 if (m_extent.isNotNull() && !baseAndExtentEqual) | 276 if (m_extent.isNotNull() && !baseAndExtentEqual) |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 sel.showTreeForThis(); | 801 sel.showTreeForThis(); |
848 } | 802 } |
849 | 803 |
850 void showTree(const blink::VisibleSelection* sel) | 804 void showTree(const blink::VisibleSelection* sel) |
851 { | 805 { |
852 if (sel) | 806 if (sel) |
853 sel->showTreeForThis(); | 807 sel->showTreeForThis(); |
854 } | 808 } |
855 | 809 |
856 #endif | 810 #endif |
OLD | NEW |