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

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

Issue 2904093002: [DMC #18] Eliminate DocumentMarkerTextMatch (subclass of DocumentMarkerDetails) (Closed)
Patch Set: Add const, rebase Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
index 1accf9afe0e92d19460b3694e0dc88531de4e071..44ab1f978548ee31acf53bc8dd2e05c648871119 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
@@ -30,6 +30,7 @@
#include "core/editing/markers/DocumentMarker.h"
+#include "core/editing/markers/TextMatchMarker.h"
#include "platform/wtf/StdLibExtras.h"
namespace blink {
@@ -62,43 +63,6 @@ inline DocumentMarkerDescription* ToDocumentMarkerDescription(
return 0;
}
-class DocumentMarkerTextMatch final : public DocumentMarkerDetails {
- public:
- static DocumentMarkerTextMatch* Create(DocumentMarker::MatchStatus);
-
- bool IsActiveMatch() const {
- return match_status_ == DocumentMarker::MatchStatus::kActive;
- }
-
- bool IsTextMatch() const override { return true; }
-
- private:
- explicit DocumentMarkerTextMatch(DocumentMarker::MatchStatus match_status)
- : match_status_(match_status) {}
-
- DocumentMarker::MatchStatus match_status_;
-};
-
-DocumentMarkerTextMatch* DocumentMarkerTextMatch::Create(
- DocumentMarker::MatchStatus match_status) {
- DEFINE_STATIC_LOCAL(
- DocumentMarkerTextMatch, active_instance,
- (new DocumentMarkerTextMatch(DocumentMarker::MatchStatus::kActive)));
- DEFINE_STATIC_LOCAL(
- DocumentMarkerTextMatch, inactive_instance,
- (new DocumentMarkerTextMatch(DocumentMarker::MatchStatus::kInactive)));
- return match_status == DocumentMarker::MatchStatus::kActive
- ? &active_instance
- : &inactive_instance;
-}
-
-inline DocumentMarkerTextMatch* ToDocumentMarkerTextMatch(
- DocumentMarkerDetails* details) {
- if (details && details->IsTextMatch())
- return static_cast<DocumentMarkerTextMatch*>(details);
- return 0;
-}
-
class TextCompositionMarkerDetails final : public DocumentMarkerDetails {
public:
static TextCompositionMarkerDetails* Create(Color underline_color,
@@ -140,6 +104,13 @@ inline TextCompositionMarkerDetails* ToTextCompositionMarkerDetails(
DocumentMarker::DocumentMarker(MarkerType type,
unsigned start_offset,
+ unsigned end_offset)
+ : type_(type), start_offset_(start_offset), end_offset_(end_offset) {
+ DCHECK_LT(start_offset, end_offset);
+}
+
+DocumentMarker::DocumentMarker(MarkerType type,
+ unsigned start_offset,
unsigned end_offset,
const String& description)
: type_(type),
@@ -151,14 +122,6 @@ DocumentMarker::DocumentMarker(MarkerType type,
DocumentMarker::DocumentMarker(unsigned start_offset,
unsigned end_offset,
- DocumentMarker::MatchStatus match_status)
- : type_(DocumentMarker::kTextMatch),
- start_offset_(start_offset),
- end_offset_(end_offset),
- details_(DocumentMarkerTextMatch::Create(match_status)) {}
-
-DocumentMarker::DocumentMarker(unsigned start_offset,
- unsigned end_offset,
Color underline_color,
bool thick,
Color background_color)
@@ -219,11 +182,10 @@ void DocumentMarker::ShiftOffsets(int delta) {
start_offset_ += delta;
end_offset_ += delta;
}
-
void DocumentMarker::SetIsActiveMatch(bool active) {
- details_ = DocumentMarkerTextMatch::Create(
- active ? DocumentMarker::MatchStatus::kActive
- : DocumentMarker::MatchStatus::kInactive);
+ if (GetType() != DocumentMarker::kTextMatch)
+ return;
+ ToTextMatchMarker(this)->SetIsActiveMatch(active);
}
const String& DocumentMarker::Description() const {
@@ -234,10 +196,9 @@ const String& DocumentMarker::Description() const {
}
bool DocumentMarker::IsActiveMatch() const {
- if (DocumentMarkerTextMatch* details =
- ToDocumentMarkerTextMatch(details_.Get()))
- return details->IsActiveMatch();
- return false;
+ if (GetType() != DocumentMarker::kTextMatch)
+ return false;
+ return ToTextMatchMarker(this)->IsActiveMatch();
}
Color DocumentMarker::UnderlineColor() const {

Powered by Google App Engine
This is Rietveld 408576698