| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google 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 22 matching lines...) Expand all Loading... |
| 33 #include "core/frame/LocalFrame.h" | 33 #include "core/frame/LocalFrame.h" |
| 34 #include "core/frame/Settings.h" | 34 #include "core/frame/Settings.h" |
| 35 #include "platform/text/TextCheckerClient.h" | 35 #include "platform/text/TextCheckerClient.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 SpellCheckRequest::SpellCheckRequest( | 39 SpellCheckRequest::SpellCheckRequest( |
| 40 Range* checkingRange, | 40 Range* checkingRange, |
| 41 Range* paragraphRange, | 41 Range* paragraphRange, |
| 42 const String& text, | 42 const String& text, |
| 43 TextCheckingTypeMask mask, | |
| 44 TextCheckingProcessType processType, | 43 TextCheckingProcessType processType, |
| 45 const Vector<uint32_t>& documentMarkersInRange, | 44 const Vector<uint32_t>& documentMarkersInRange, |
| 46 const Vector<unsigned>& documentMarkerOffsets, | 45 const Vector<unsigned>& documentMarkerOffsets, |
| 47 int requestNumber) | 46 int requestNumber) |
| 48 : m_requester(nullptr) | 47 : m_requester(nullptr) |
| 49 , m_checkingRange(checkingRange) | 48 , m_checkingRange(checkingRange) |
| 50 , m_paragraphRange(paragraphRange) | 49 , m_paragraphRange(paragraphRange) |
| 51 , m_rootEditableElement(blink::rootEditableElement(*m_checkingRange->startCo
ntainer())) | 50 , m_rootEditableElement(blink::rootEditableElement(*m_checkingRange->startCo
ntainer())) |
| 52 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do
cumentMarkersInRange, documentMarkerOffsets) | 51 , m_requestData(unrequestedTextCheckingSequence, text, processType, document
MarkersInRange, documentMarkerOffsets) |
| 53 , m_requestNumber(requestNumber) | 52 , m_requestNumber(requestNumber) |
| 54 { | 53 { |
| 55 DCHECK(m_checkingRange); | 54 DCHECK(m_checkingRange); |
| 56 DCHECK(m_checkingRange->isConnected()); | 55 DCHECK(m_checkingRange->isConnected()); |
| 57 DCHECK(m_paragraphRange); | 56 DCHECK(m_paragraphRange); |
| 58 DCHECK(m_paragraphRange->isConnected()); | 57 DCHECK(m_paragraphRange->isConnected()); |
| 59 DCHECK(m_rootEditableElement); | 58 DCHECK(m_rootEditableElement); |
| 60 } | 59 } |
| 61 | 60 |
| 62 SpellCheckRequest::~SpellCheckRequest() | 61 SpellCheckRequest::~SpellCheckRequest() |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 | 73 |
| 75 void SpellCheckRequest::dispose() | 74 void SpellCheckRequest::dispose() |
| 76 { | 75 { |
| 77 if (m_checkingRange) | 76 if (m_checkingRange) |
| 78 m_checkingRange->dispose(); | 77 m_checkingRange->dispose(); |
| 79 if (m_paragraphRange && m_paragraphRange != m_checkingRange) | 78 if (m_paragraphRange && m_paragraphRange != m_checkingRange) |
| 80 m_paragraphRange->dispose(); | 79 m_paragraphRange->dispose(); |
| 81 } | 80 } |
| 82 | 81 |
| 83 // static | 82 // static |
| 84 SpellCheckRequest* SpellCheckRequest::create(TextCheckingTypeMask textCheckingOp
tions, TextCheckingProcessType processType, const EphemeralRange& checkingRange,
const EphemeralRange& paragraphRange, int requestNumber) | 83 SpellCheckRequest* SpellCheckRequest::create(TextCheckingProcessType processType
, const EphemeralRange& checkingRange, const EphemeralRange& paragraphRange, int
requestNumber) |
| 85 { | 84 { |
| 86 if (checkingRange.isNull()) | 85 if (checkingRange.isNull()) |
| 87 return nullptr; | 86 return nullptr; |
| 88 if (!blink::rootEditableElement(*checkingRange.startPosition().computeContai
nerNode())) | 87 if (!blink::rootEditableElement(*checkingRange.startPosition().computeContai
nerNode())) |
| 89 return nullptr; | 88 return nullptr; |
| 90 | 89 |
| 91 String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCha
racter); | 90 String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCha
racter); |
| 92 if (text.isEmpty()) | 91 if (text.isEmpty()) |
| 93 return nullptr; | 92 return nullptr; |
| 94 | 93 |
| 95 Range* checkingRangeObject = createRange(checkingRange); | 94 Range* checkingRangeObject = createRange(checkingRange); |
| 96 Range* paragraphRangeObject = nullptr; | 95 Range* paragraphRangeObject = nullptr; |
| 97 // Share identical Range objects. | 96 // Share identical Range objects. |
| 98 if (checkingRange == paragraphRange) | 97 if (checkingRange == paragraphRange) |
| 99 paragraphRangeObject = checkingRangeObject; | 98 paragraphRangeObject = checkingRangeObject; |
| 100 else | 99 else |
| 101 paragraphRangeObject = createRange(paragraphRange); | 100 paragraphRangeObject = createRange(paragraphRange); |
| 102 | 101 |
| 103 const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().m
arkers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers()
); | 102 const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().m
arkers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers()
); |
| 104 Vector<uint32_t> hashes(markers.size()); | 103 Vector<uint32_t> hashes(markers.size()); |
| 105 Vector<unsigned> offsets(markers.size()); | 104 Vector<unsigned> offsets(markers.size()); |
| 106 for (size_t i = 0; i < markers.size(); ++i) { | 105 for (size_t i = 0; i < markers.size(); ++i) { |
| 107 hashes[i] = markers[i]->hash(); | 106 hashes[i] = markers[i]->hash(); |
| 108 offsets[i] = markers[i]->startOffset(); | 107 offsets[i] = markers[i]->startOffset(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 return new SpellCheckRequest(checkingRangeObject, paragraphRangeObject, text
, textCheckingOptions, processType, hashes, offsets, requestNumber); | 110 return new SpellCheckRequest(checkingRangeObject, paragraphRangeObject, text
, processType, hashes, offsets, requestNumber); |
| 112 } | 111 } |
| 113 | 112 |
| 114 const TextCheckingRequestData& SpellCheckRequest::data() const | 113 const TextCheckingRequestData& SpellCheckRequest::data() const |
| 115 { | 114 { |
| 116 return m_requestData; | 115 return m_requestData; |
| 117 } | 116 } |
| 118 | 117 |
| 119 bool SpellCheckRequest::isValid() const | 118 bool SpellCheckRequest::isValid() const |
| 120 { | 119 { |
| 121 return m_checkingRange->isConnected() && m_paragraphRange->isConnected() &&
m_rootEditableElement->isConnected(); | 120 return m_checkingRange->isConnected() && m_paragraphRange->isConnected() &&
m_rootEditableElement->isConnected(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 clearProcessingRequest(); | 280 clearProcessingRequest(); |
| 282 if (!m_requestQueue.isEmpty()) | 281 if (!m_requestQueue.isEmpty()) |
| 283 m_timerToProcessQueuedRequest.startOneShot(0, BLINK_FROM_HERE); | 282 m_timerToProcessQueuedRequest.startOneShot(0, BLINK_FROM_HERE); |
| 284 } | 283 } |
| 285 | 284 |
| 286 void SpellCheckRequester::didCheckSucceed(int sequence, const Vector<TextCheckin
gResult>& results) | 285 void SpellCheckRequester::didCheckSucceed(int sequence, const Vector<TextCheckin
gResult>& results) |
| 287 { | 286 { |
| 288 TextCheckingRequestData requestData = m_processingRequest->data(); | 287 TextCheckingRequestData requestData = m_processingRequest->data(); |
| 289 if (requestData.sequence() == sequence) { | 288 if (requestData.sequence() == sequence) { |
| 290 DocumentMarker::MarkerTypes markers = DocumentMarker::SpellCheckClientMa
rkers(); | 289 DocumentMarker::MarkerTypes markers = DocumentMarker::SpellCheckClientMa
rkers(); |
| 291 if (!requestData.maskContains(TextCheckingTypeSpelling)) | |
| 292 markers.remove(DocumentMarker::Spelling); | |
| 293 if (!requestData.maskContains(TextCheckingTypeGrammar)) | |
| 294 markers.remove(DocumentMarker::Grammar); | |
| 295 if (m_processingRequest->isValid()) { | 290 if (m_processingRequest->isValid()) { |
| 296 Range* checkingRange = m_processingRequest->checkingRange(); | 291 Range* checkingRange = m_processingRequest->checkingRange(); |
| 297 frame().document()->markers().removeMarkers(EphemeralRange(checkingR
ange), markers); | 292 frame().document()->markers().removeMarkers(EphemeralRange(checkingR
ange), markers); |
| 298 } | 293 } |
| 299 } | 294 } |
| 300 didCheck(sequence, results); | 295 didCheck(sequence, results); |
| 301 } | 296 } |
| 302 | 297 |
| 303 void SpellCheckRequester::didCheckCancel(int sequence) | 298 void SpellCheckRequester::didCheckCancel(int sequence) |
| 304 { | 299 { |
| 305 Vector<TextCheckingResult> results; | 300 Vector<TextCheckingResult> results; |
| 306 didCheck(sequence, results); | 301 didCheck(sequence, results); |
| 307 } | 302 } |
| 308 | 303 |
| 309 DEFINE_TRACE(SpellCheckRequester) | 304 DEFINE_TRACE(SpellCheckRequester) |
| 310 { | 305 { |
| 311 visitor->trace(m_frame); | 306 visitor->trace(m_frame); |
| 312 visitor->trace(m_processingRequest); | 307 visitor->trace(m_processingRequest); |
| 313 visitor->trace(m_requestQueue); | 308 visitor->trace(m_requestQueue); |
| 314 } | 309 } |
| 315 | 310 |
| 316 } // namespace blink | 311 } // namespace blink |
| OLD | NEW |