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

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: Remove declaration for DocumentMarker constructor being removed 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() {}
yosin_UTC9 2017/05/29 05:13:48 nit: s/{}/ = 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), 42 : type_(type), start_offset_(start_offset), end_offset_(end_offset) {}
yosin_UTC9 2017/05/29 05:13:48 Let's add DCHECK_LT(start_offset_, end_offset_)
69 start_offset_(start_offset),
70 end_offset_(end_offset),
71 details_(nullptr) {}
72
73 DocumentMarker::DocumentMarker(MarkerType type,
74 unsigned start_offset,
75 unsigned end_offset,
76 const String& description)
77 : type_(type),
78 start_offset_(start_offset),
79 end_offset_(end_offset),
80 details_(description.IsEmpty()
81 ? nullptr
82 : DocumentMarkerDescription::Create(description)) {}
83 43
84 Optional<DocumentMarker::MarkerOffsets> 44 Optional<DocumentMarker::MarkerOffsets>
85 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset, 45 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset,
86 unsigned old_length, 46 unsigned old_length,
87 unsigned new_length) const { 47 unsigned new_length) const {
88 MarkerOffsets result; 48 MarkerOffsets result;
89 result.start_offset = StartOffset(); 49 result.start_offset = StartOffset();
90 result.end_offset = EndOffset(); 50 result.end_offset = EndOffset();
91 51
92 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace 52 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 return WTF::nullopt; 85 return WTF::nullopt;
126 86
127 return result; 87 return result;
128 } 88 }
129 89
130 void DocumentMarker::ShiftOffsets(int delta) { 90 void DocumentMarker::ShiftOffsets(int delta) {
131 start_offset_ += delta; 91 start_offset_ += delta;
132 end_offset_ += delta; 92 end_offset_ += delta;
133 } 93 }
134 94
135 const String& DocumentMarker::Description() const {
136 if (DocumentMarkerDescription* details =
137 ToDocumentMarkerDescription(details_.Get()))
138 return details->Description();
139 return g_empty_string;
140 }
141
142 DEFINE_TRACE(DocumentMarker) {
143 visitor->Trace(details_);
144 }
145
146 } // namespace blink 95 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698