Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights |
| 7 * reserved. | 7 * reserved. |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "core/editing/markers/DocumentMarkerController.h" | 29 #include "core/editing/markers/DocumentMarkerController.h" |
| 30 | 30 |
| 31 #include <algorithm> | 31 #include <algorithm> |
| 32 #include "core/dom/Node.h" | 32 #include "core/dom/Node.h" |
| 33 #include "core/dom/NodeTraversal.h" | 33 #include "core/dom/NodeTraversal.h" |
| 34 #include "core/dom/Range.h" | 34 #include "core/dom/Range.h" |
| 35 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
| 36 #include "core/editing/iterators/TextIterator.h" | 36 #include "core/editing/iterators/TextIterator.h" |
| 37 #include "core/editing/markers/CompositionMarker.h" | |
| 37 #include "core/editing/markers/CompositionMarkerList.h" | 38 #include "core/editing/markers/CompositionMarkerList.h" |
| 38 #include "core/editing/markers/DocumentMarkerList.h" | 39 #include "core/editing/markers/DocumentMarkerList.h" |
| 39 #include "core/editing/markers/EditingMarkerList.h" | 40 #include "core/editing/markers/EditingMarkerList.h" |
| 41 #include "core/editing/markers/SpellCheckMarker.h" | |
| 40 #include "core/editing/markers/SpellCheckMarkerList.h" | 42 #include "core/editing/markers/SpellCheckMarkerList.h" |
| 41 #include "core/editing/markers/TextMatchMarkerList.h" | 43 #include "core/editing/markers/TextMatchMarkerList.h" |
| 42 #include "core/frame/FrameView.h" | 44 #include "core/frame/FrameView.h" |
| 43 #include "core/layout/LayoutObject.h" | 45 #include "core/layout/LayoutObject.h" |
| 44 | 46 |
| 45 #ifndef NDEBUG | 47 #ifndef NDEBUG |
| 46 #include <stdio.h> | 48 #include <stdio.h> |
| 47 #endif | 49 #endif |
| 48 | 50 |
| 49 namespace blink { | 51 namespace blink { |
| 50 | 52 |
| 51 DocumentMarkerController::DocumentMarkerController(Document& document) | 53 DocumentMarkerController::DocumentMarkerController(Document& document) |
| 52 : m_document(&document) { | 54 : m_document(&document) { |
| 53 setContext(&document); | 55 setContext(&document); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void DocumentMarkerController::clear() { | 58 void DocumentMarkerController::clear() { |
| 57 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { | 59 for (DocumentMarker::MarkerType type : DocumentMarker::AllMarkers()) { |
| 58 MarkerMap& markerMap = markerMapForType(type); | 60 MarkerMap& markerMap = markerMapForType(type); |
| 59 markerMap.clear(); | 61 markerMap.clear(); |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| 63 void DocumentMarkerController::addMarker(const Position& start, | 65 void DocumentMarkerController::addMarker(const Position& start, |
| 64 const Position& end, | 66 const Position& end, |
| 65 DocumentMarker::MarkerType type, | 67 DocumentMarker::MarkerType type, |
| 66 const String& description) { | 68 const String& description) { |
| 67 DCHECK(type != DocumentMarker::TextMatch); | |
|
Xiaocheng
2017/03/29 23:40:11
nit: no need to remove this check.
rlanday
2017/03/31 01:34:53
SpellCheckMarker already DCHECKs that the type bei
Xiaocheng
2017/03/31 02:01:01
Makes sense.
| |
| 68 // Use a TextIterator to visit the potentially multiple nodes the range | 69 // Use a TextIterator to visit the potentially multiple nodes the range |
| 69 // covers. | 70 // covers. |
| 70 for (TextIterator markedText(start, end); !markedText.atEnd(); | 71 for (TextIterator markedText(start, end); !markedText.atEnd(); |
| 71 markedText.advance()) { | 72 markedText.advance()) { |
| 72 addMarker(markedText.currentContainer(), | 73 addMarker(markedText.currentContainer(), |
| 73 new DocumentMarker( | 74 new SpellCheckMarker( |
| 74 type, markedText.startOffsetInCurrentContainer(), | 75 type, markedText.startOffsetInCurrentContainer(), |
| 75 markedText.endOffsetInCurrentContainer(), description)); | 76 markedText.endOffsetInCurrentContainer(), description)); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 void DocumentMarkerController::addTextMatchMarker(const EphemeralRange& range, | 80 void DocumentMarkerController::addTextMatchMarker(const EphemeralRange& range, |
| 80 bool activeMatch) { | 81 bool activeMatch) { |
| 81 DCHECK(!m_document->needsLayoutTreeUpdate()); | 82 DCHECK(!m_document->needsLayoutTreeUpdate()); |
| 82 | 83 |
| 83 // Use a TextIterator to visit the potentially multiple nodes the range | 84 // Use a TextIterator to visit the potentially multiple nodes the range |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 96 void DocumentMarkerController::addCompositionMarker(const Position& start, | 97 void DocumentMarkerController::addCompositionMarker(const Position& start, |
| 97 const Position& end, | 98 const Position& end, |
| 98 Color underlineColor, | 99 Color underlineColor, |
| 99 bool thick, | 100 bool thick, |
| 100 Color backgroundColor) { | 101 Color backgroundColor) { |
| 101 DCHECK(!m_document->needsLayoutTreeUpdate()); | 102 DCHECK(!m_document->needsLayoutTreeUpdate()); |
| 102 | 103 |
| 103 for (TextIterator markedText(start, end); !markedText.atEnd(); | 104 for (TextIterator markedText(start, end); !markedText.atEnd(); |
| 104 markedText.advance()) { | 105 markedText.advance()) { |
| 105 addMarker(markedText.currentContainer(), | 106 addMarker(markedText.currentContainer(), |
| 106 new DocumentMarker(markedText.startOffsetInCurrentContainer(), | 107 new CompositionMarker(markedText.startOffsetInCurrentContainer(), |
| 107 markedText.endOffsetInCurrentContainer(), | 108 markedText.endOffsetInCurrentContainer(), |
| 108 underlineColor, thick, backgroundColor)); | 109 underlineColor, thick, backgroundColor)); |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 void DocumentMarkerController::prepareForDestruction() { | 113 void DocumentMarkerController::prepareForDestruction() { |
| 113 clear(); | 114 clear(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void DocumentMarkerController::removeMarkers( | 117 void DocumentMarkerController::removeMarkers( |
| 117 const EphemeralRange& range, | 118 const EphemeralRange& range, |
| 118 DocumentMarker::MarkerTypes markerTypes, | 119 DocumentMarker::MarkerTypes markerTypes, |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 } | 586 } |
| 586 | 587 |
| 587 } // namespace blink | 588 } // namespace blink |
| 588 | 589 |
| 589 #ifndef NDEBUG | 590 #ifndef NDEBUG |
| 590 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { | 591 void showDocumentMarkers(const blink::DocumentMarkerController* controller) { |
| 591 if (controller) | 592 if (controller) |
| 592 controller->showMarkers(); | 593 controller->showMarkers(); |
| 593 } | 594 } |
| 594 #endif | 595 #endif |
| OLD | NEW |