| 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 12 matching lines...) Expand all Loading... |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/editing/VisibleSelection.h" | 27 #include "core/editing/VisibleSelection.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/Element.h" | 31 #include "core/dom/Element.h" |
| 32 #include "core/dom/Range.h" | 32 #include "core/dom/Range.h" |
| 33 #include "core/editing/VisibleUnits.h" | |
| 34 #include "core/editing/htmlediting.h" | 33 #include "core/editing/htmlediting.h" |
| 35 #include "core/editing/iterators/CharacterIterator.h" | 34 #include "core/editing/iterators/CharacterIterator.h" |
| 36 #include "core/layout/LayoutObject.h" | 35 #include "core/layout/LayoutObject.h" |
| 37 #include "platform/geometry/LayoutPoint.h" | 36 #include "platform/geometry/LayoutPoint.h" |
| 38 #include "wtf/Assertions.h" | 37 #include "wtf/Assertions.h" |
| 39 #include "wtf/text/CString.h" | 38 #include "wtf/text/CString.h" |
| 40 #include "wtf/text/StringBuilder.h" | 39 #include "wtf/text/StringBuilder.h" |
| 41 #include "wtf/unicode/CharacterNames.h" | 40 #include "wtf/unicode/CharacterNames.h" |
| 42 | 41 |
| 43 #ifndef NDEBUG | 42 #ifndef NDEBUG |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 else if (m_base.isNull()) { | 342 else if (m_base.isNull()) { |
| 344 m_base = m_extent; | 343 m_base = m_extent; |
| 345 m_baseIsFirst = true; | 344 m_baseIsFirst = true; |
| 346 } else if (m_extent.isNull()) { | 345 } else if (m_extent.isNull()) { |
| 347 m_extent = m_base; | 346 m_extent = m_base; |
| 348 m_baseIsFirst = true; | 347 m_baseIsFirst = true; |
| 349 } else | 348 } else |
| 350 m_baseIsFirst = comparePositions(m_base, m_extent) <= 0; | 349 m_baseIsFirst = comparePositions(m_base, m_extent) <= 0; |
| 351 } | 350 } |
| 352 | 351 |
| 353 void VisibleSelection::setStartRespectingGranularity(TextGranularity granularity
) | 352 void VisibleSelection::setStartRespectingGranularity(TextGranularity granularity
, EWordSide wordSide) |
| 354 { | 353 { |
| 355 m_start = m_baseIsFirst ? m_base : m_extent; | 354 m_start = m_baseIsFirst ? m_base : m_extent; |
| 356 | 355 |
| 357 switch (granularity) { | 356 switch (granularity) { |
| 358 case CharacterGranularity: | 357 case CharacterGranularity: |
| 359 // Don't do any expansion. | 358 // Don't do any expansion. |
| 360 break; | 359 break; |
| 361 case WordGranularity: { | 360 case WordGranularity: { |
| 362 // General case: Select the word the caret is positioned inside of, or a
t the start of (RightWordIfOnBoundary). | 361 // General case: Select the word the caret is positioned inside of. |
| 362 // If the caret is on the word boundary, select the word according to |w
ordSide|. |
| 363 // Edge case: If the caret is after the last word in a soft-wrapped line
or the last word in | 363 // Edge case: If the caret is after the last word in a soft-wrapped line
or the last word in |
| 364 // the document, select that last word (LeftWordIfOnBoundary). | 364 // the document, select that last word (LeftWordIfOnBoundary). |
| 365 // Edge case: If the caret is after the last word in a paragraph, select
from the the end of the | 365 // Edge case: If the caret is after the last word in a paragraph, select
from the the end of the |
| 366 // last word to the line break (also RightWordIfOnBoundary); | 366 // last word to the line break (also RightWordIfOnBoundary); |
| 367 VisiblePosition visibleStart = VisiblePosition(m_start, m_affinity); | 367 VisiblePosition visibleStart = VisiblePosition(m_start, m_affinity); |
| 368 EWordSide side = RightWordIfOnBoundary; | 368 EWordSide side = wordSide; |
| 369 if (isEndOfEditableOrNonEditableContent(visibleStart) || (isEndOfLine(vi
sibleStart) && !isStartOfLine(visibleStart) && !isEndOfParagraph(visibleStart))) | 369 if (isEndOfEditableOrNonEditableContent(visibleStart) || (isEndOfLine(vi
sibleStart) && !isStartOfLine(visibleStart) && !isEndOfParagraph(visibleStart))) |
| 370 side = LeftWordIfOnBoundary; | 370 side = LeftWordIfOnBoundary; |
| 371 m_start = startOfWord(visibleStart, side).deepEquivalent(); | 371 m_start = startOfWord(visibleStart, side).deepEquivalent(); |
| 372 break; | 372 break; |
| 373 } | 373 } |
| 374 case SentenceGranularity: { | 374 case SentenceGranularity: { |
| 375 m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEqui
valent(); | 375 m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEqui
valent(); |
| 376 break; | 376 break; |
| 377 } | 377 } |
| 378 case LineGranularity: { | 378 case LineGranularity: { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 398 case SentenceBoundary: | 398 case SentenceBoundary: |
| 399 m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEqui
valent(); | 399 m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEqui
valent(); |
| 400 break; | 400 break; |
| 401 } | 401 } |
| 402 | 402 |
| 403 // Make sure we do not have a dangling start or end. | 403 // Make sure we do not have a dangling start or end. |
| 404 if (m_start.isNull()) | 404 if (m_start.isNull()) |
| 405 m_start = m_end; | 405 m_start = m_end; |
| 406 } | 406 } |
| 407 | 407 |
| 408 void VisibleSelection::setEndRespectingGranularity(TextGranularity granularity) | 408 void VisibleSelection::setEndRespectingGranularity(TextGranularity granularity,
EWordSide wordSide) |
| 409 { | 409 { |
| 410 m_end = m_baseIsFirst ? m_extent : m_base; | 410 m_end = m_baseIsFirst ? m_extent : m_base; |
| 411 | 411 |
| 412 switch (granularity) { | 412 switch (granularity) { |
| 413 case CharacterGranularity: | 413 case CharacterGranularity: |
| 414 // Don't do any expansion. | 414 // Don't do any expansion. |
| 415 break; | 415 break; |
| 416 case WordGranularity: { | 416 case WordGranularity: { |
| 417 // General case: Select the word the caret is positioned inside of, or a
t the start of (RightWordIfOnBoundary). | 417 // General case: Select the word the caret is positioned inside of. |
| 418 // If the caret is on the word boundary, select the word according to |w
ordSide|. |
| 418 // Edge case: If the caret is after the last word in a soft-wrapped line
or the last word in | 419 // Edge case: If the caret is after the last word in a soft-wrapped line
or the last word in |
| 419 // the document, select that last word (LeftWordIfOnBoundary). | 420 // the document, select that last word (LeftWordIfOnBoundary). |
| 420 // Edge case: If the caret is after the last word in a paragraph, select
from the the end of the | 421 // Edge case: If the caret is after the last word in a paragraph, select
from the the end of the |
| 421 // last word to the line break (also RightWordIfOnBoundary); | 422 // last word to the line break (also RightWordIfOnBoundary); |
| 422 VisiblePosition originalEnd(m_end, m_affinity); | 423 VisiblePosition originalEnd(m_end, m_affinity); |
| 423 EWordSide side = RightWordIfOnBoundary; | 424 EWordSide side = wordSide; |
| 424 if (isEndOfEditableOrNonEditableContent(originalEnd) || (isEndOfLine(ori
ginalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd))) | 425 if (isEndOfEditableOrNonEditableContent(originalEnd) || (isEndOfLine(ori
ginalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd))) |
| 425 side = LeftWordIfOnBoundary; | 426 side = LeftWordIfOnBoundary; |
| 426 | 427 |
| 427 VisiblePosition wordEnd(endOfWord(originalEnd, side)); | 428 VisiblePosition wordEnd(endOfWord(originalEnd, side)); |
| 428 VisiblePosition end(wordEnd); | 429 VisiblePosition end(wordEnd); |
| 429 | 430 |
| 430 if (isEndOfParagraph(originalEnd) && !isEmptyTableCell(m_start.deprecate
dNode())) { | 431 if (isEndOfParagraph(originalEnd) && !isEmptyTableCell(m_start.deprecate
dNode())) { |
| 431 // Select the paragraph break (the space from the end of a paragraph
to the start of | 432 // Select the paragraph break (the space from the end of a paragraph
to the start of |
| 432 // the next one) to match TextEdit. | 433 // the next one) to match TextEdit. |
| 433 end = wordEnd.next(); | 434 end = wordEnd.next(); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 sel.showTreeForThis(); | 910 sel.showTreeForThis(); |
| 910 } | 911 } |
| 911 | 912 |
| 912 void showTree(const blink::VisibleSelection* sel) | 913 void showTree(const blink::VisibleSelection* sel) |
| 913 { | 914 { |
| 914 if (sel) | 915 if (sel) |
| 915 sel->showTreeForThis(); | 916 sel->showTreeForThis(); |
| 916 } | 917 } |
| 917 | 918 |
| 918 #endif | 919 #endif |
| OLD | NEW |