| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 if (matchStyle) | 412 if (matchStyle) |
| 413 options |= ReplaceSelectionCommand::MatchStyle; | 413 options |= ReplaceSelectionCommand::MatchStyle; |
| 414 applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment,
options, EditActionPaste)); | 414 applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment,
options, EditActionPaste)); |
| 415 revealSelectionAfterEditingOperation(); | 415 revealSelectionAfterEditingOperation(); |
| 416 | 416 |
| 417 if (m_frame->selection()->isInPasswordField() || !isContinuousSpellCheckingE
nabled()) | 417 if (m_frame->selection()->isInPasswordField() || !isContinuousSpellCheckingE
nabled()) |
| 418 return; | 418 return; |
| 419 Node* nodeToCheck = m_frame->selection()->rootEditableElement(); | 419 Node* nodeToCheck = m_frame->selection()->rootEditableElement(); |
| 420 if (!nodeToCheck) | 420 if (!nodeToCheck) |
| 421 return; | 421 return; |
| 422 | |
| 423 RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositio
nInNode(nodeToCheck), lastPositionInNode(nodeToCheck)); | 422 RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositio
nInNode(nodeToCheck), lastPositionInNode(nodeToCheck)); |
| 424 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(resolveT
extCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextChe
ckingProcessBatch, rangeToCheck, rangeToCheck)); | 423 TextCheckingParagraph textToCheck(rangeToCheck, rangeToCheck); |
| 424 chunkAndMarkAllMisspellingsAndBadGrammar(resolveTextCheckingTypeMask(TextChe
ckingTypeSpelling | TextCheckingTypeGrammar), textToCheck, true); |
| 425 } | 425 } |
| 426 | 426 |
| 427 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) | 427 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) |
| 428 { | 428 { |
| 429 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t
ext), selectReplacement, smartReplace, true); | 429 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t
ext), selectReplacement, smartReplace, true); |
| 430 } | 430 } |
| 431 | 431 |
| 432 PassRefPtr<Range> Editor::selectedRange() | 432 PassRefPtr<Range> Editor::selectedRange() |
| 433 { | 433 { |
| 434 if (!m_frame) | 434 if (!m_frame) |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 // If we're not in an editable node, bail. | 1502 // If we're not in an editable node, bail. |
| 1503 Node* editableNode = spellingRange->startContainer(); | 1503 Node* editableNode = spellingRange->startContainer(); |
| 1504 if (!editableNode || !editableNode->rendererIsEditable()) | 1504 if (!editableNode || !editableNode->rendererIsEditable()) |
| 1505 return; | 1505 return; |
| 1506 | 1506 |
| 1507 if (!isSpellCheckingEnabledFor(editableNode)) | 1507 if (!isSpellCheckingEnabledFor(editableNode)) |
| 1508 return; | 1508 return; |
| 1509 | 1509 |
| 1510 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; | 1510 Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; |
| 1511 TextCheckingParagraph fullParagraphToCheck(rangeToCheck); | 1511 TextCheckingParagraph fullParagraphToCheck(rangeToCheck); |
| 1512 |
| 1513 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a
synchronousSpellCheckingEnabled(); |
| 1514 chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphT
oCheck, asynchronous); |
| 1515 } |
| 1516 |
| 1517 void Editor::chunkAndMarkAllMisspellingsAndBadGrammar(TextCheckingTypeMask textC
heckingOptions, const TextCheckingParagraph& fullParagraphToCheck, bool asynchro
nous) |
| 1518 { |
| 1512 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty()) | 1519 if (fullParagraphToCheck.isRangeEmpty() || fullParagraphToCheck.isEmpty()) |
| 1513 return; | 1520 return; |
| 1514 | 1521 |
| 1515 // Since the text may be quite big chunk it up and adjust to the sentence bo
undary. | 1522 // Since the text may be quite big chunk it up and adjust to the sentence bo
undary. |
| 1516 const int kChunkSize = 16 * 1024; | 1523 const int kChunkSize = 16 * 1024; |
| 1517 int start = fullParagraphToCheck.checkingStart(); | 1524 int start = fullParagraphToCheck.checkingStart(); |
| 1518 int end = fullParagraphToCheck.checkingEnd(); | 1525 int end = fullParagraphToCheck.checkingEnd(); |
| 1519 start = std::min(start, end); | 1526 start = std::min(start, end); |
| 1520 end = std::max(start, end); | 1527 end = std::max(start, end); |
| 1521 bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->a
synchronousSpellCheckingEnabled(); | |
| 1522 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1)
/ (kChunkSize) : 1; | 1528 const int kNumChunksToCheck = asynchronous ? (end - start + kChunkSize - 1)
/ (kChunkSize) : 1; |
| 1523 int currentChunkStart = start; | 1529 int currentChunkStart = start; |
| 1524 RefPtr<Range> checkRange = asynchronous ? fullParagraphToCheck.paragraphRang
e() : rangeToCheck; | 1530 RefPtr<Range> checkRange = asynchronous ? fullParagraphToCheck.paragraphRang
e() : fullParagraphToCheck.checkingRange(); |
| 1525 RefPtr<Range> paragraphRange = fullParagraphToCheck.paragraphRange(); | 1531 RefPtr<Range> paragraphRange = fullParagraphToCheck.paragraphRange(); |
| 1526 if (kNumChunksToCheck == 1 && asynchronous) { | 1532 if (kNumChunksToCheck == 1 && asynchronous) { |
| 1527 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange
.get(), paragraphRange.get(), asynchronous, 0); | 1533 markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange
.get(), paragraphRange.get(), asynchronous, 0); |
| 1528 return; | 1534 return; |
| 1529 } | 1535 } |
| 1530 | 1536 |
| 1531 for (int iter = 0; iter < kNumChunksToCheck; ++iter) { | 1537 for (int iter = 0; iter < kNumChunksToCheck; ++iter) { |
| 1532 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize
); | 1538 checkRange = fullParagraphToCheck.subrange(currentChunkStart, kChunkSize
); |
| 1533 setStart(checkRange.get(), startOfSentence(checkRange->startPosition()))
; | 1539 setStart(checkRange.get(), startOfSentence(checkRange->startPosition()))
; |
| 1534 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition())); | 1540 setEnd(checkRange.get(), endOfSentence(checkRange->endPosition())); |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2202 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2208 return WebCore::unifiedTextCheckerEnabled(m_frame); |
| 2203 } | 2209 } |
| 2204 | 2210 |
| 2205 void Editor::toggleOverwriteModeEnabled() | 2211 void Editor::toggleOverwriteModeEnabled() |
| 2206 { | 2212 { |
| 2207 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2213 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 2208 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2214 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 2209 }; | 2215 }; |
| 2210 | 2216 |
| 2211 } // namespace WebCore | 2217 } // namespace WebCore |
| OLD | NEW |