Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp

Issue 2911723002: [DMC #24] Add SpellingMarker and GrammarMarker (subclasses of DocumentMarker) (Closed)
Patch Set: Rebase, respond to comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/editing/markers/DocumentMarker.h" 31 #include "core/editing/markers/DocumentMarker.h"
32 32
33 #include "platform/wtf/StdLibExtras.h" 33 #include "platform/wtf/StdLibExtras.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 DocumentMarkerDetails::~DocumentMarkerDetails() {} 37 DocumentMarker::~DocumentMarker() = default;
38
39 class DocumentMarkerDescription final : public DocumentMarkerDetails {
40 public:
41 static DocumentMarkerDescription* Create(const String&);
42
43 const String& Description() const { return description_; }
44 bool IsDescription() const override { return true; }
45
46 private:
47 explicit DocumentMarkerDescription(const String& description)
48 : description_(description) {}
49
50 String description_;
51 };
52
53 DocumentMarkerDescription* DocumentMarkerDescription::Create(
54 const String& description) {
55 return new DocumentMarkerDescription(description);
56 }
57
58 inline DocumentMarkerDescription* ToDocumentMarkerDescription(
59 DocumentMarkerDetails* details) {
60 if (details && details->IsDescription())
61 return static_cast<DocumentMarkerDescription*>(details);
62 return 0;
63 }
64 38
65 DocumentMarker::DocumentMarker(MarkerType type, 39 DocumentMarker::DocumentMarker(MarkerType type,
66 unsigned start_offset, 40 unsigned start_offset,
67 unsigned end_offset) 41 unsigned end_offset)
68 : type_(type), start_offset_(start_offset), end_offset_(end_offset) { 42 : type_(type), start_offset_(start_offset), end_offset_(end_offset) {
69 DCHECK_LT(start_offset, end_offset); 43 DCHECK_LT(start_offset_, end_offset_);
Xiaocheng 2017/05/31 22:17:16 Redundant change.
70 } 44 }
71 45
72 DocumentMarker::DocumentMarker(MarkerType type,
73 unsigned start_offset,
74 unsigned end_offset,
75 const String& description)
76 : type_(type),
77 start_offset_(start_offset),
78 end_offset_(end_offset),
79 details_(description.IsEmpty()
80 ? nullptr
81 : DocumentMarkerDescription::Create(description)) {}
82
83 Optional<DocumentMarker::MarkerOffsets> 46 Optional<DocumentMarker::MarkerOffsets>
84 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset, 47 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset,
85 unsigned old_length, 48 unsigned old_length,
86 unsigned new_length) const { 49 unsigned new_length) const {
87 MarkerOffsets result; 50 MarkerOffsets result;
88 result.start_offset = StartOffset(); 51 result.start_offset = StartOffset();
89 result.end_offset = EndOffset(); 52 result.end_offset = EndOffset();
90 53
91 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace 54 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace
92 // but with some changes 55 // but with some changes
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return WTF::nullopt; 87 return WTF::nullopt;
125 88
126 return result; 89 return result;
127 } 90 }
128 91
129 void DocumentMarker::ShiftOffsets(int delta) { 92 void DocumentMarker::ShiftOffsets(int delta) {
130 start_offset_ += delta; 93 start_offset_ += delta;
131 end_offset_ += delta; 94 end_offset_ += delta;
132 } 95 }
133 96
134 const String& DocumentMarker::Description() const {
135 if (DocumentMarkerDescription* details =
136 ToDocumentMarkerDescription(details_.Get()))
137 return details->Description();
138 return g_empty_string;
139 }
140
141 DEFINE_TRACE(DocumentMarker) {
142 visitor->Trace(details_);
143 }
144
145 } // namespace blink 97 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698