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

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

Issue 2650113004: [WIP] Add support for Android SuggestionSpans when editing text (Closed)
Patch Set: Remove logging statements, fix copyright years in new files Created 3 years, 11 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 eaf5c8ba476b638f4b47ec92aa1e3d7ec8de1a0b..36b38e73f16ae5498d1acf458050140b21f6174d 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp
@@ -90,18 +90,11 @@ inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch(
return 0;
}
-class TextCompositionMarkerDetails final : public DocumentMarkerDetails {
+class TextCompositionMarkerDetails : public DocumentMarkerDetails {
public:
static TextCompositionMarkerDetails* create(Color underlineColor,
bool thick,
Color backgroundColor);
-
- bool isComposition() const override { return true; }
- Color underlineColor() const { return m_underlineColor; }
- bool thick() const { return m_thick; }
- Color backgroundColor() const { return m_backgroundColor; }
-
- private:
TextCompositionMarkerDetails(Color underlineColor,
bool thick,
Color backgroundColor)
@@ -109,6 +102,12 @@ class TextCompositionMarkerDetails final : public DocumentMarkerDetails {
m_backgroundColor(backgroundColor),
m_thick(thick) {}
+ bool isComposition() const override { return true; }
+ Color underlineColor() const { return m_underlineColor; }
+ bool thick() const { return m_thick; }
+ Color backgroundColor() const { return m_backgroundColor; }
+
+ private:
Color m_underlineColor;
Color m_backgroundColor;
bool m_thick;
@@ -129,6 +128,50 @@ inline TextCompositionMarkerDetails* toTextCompositionMarkerDetails(
return nullptr;
}
+class TextSuggestionMarkerDetails final : public TextCompositionMarkerDetails {
+ public:
+ static TextSuggestionMarkerDetails* create(
+ Color underlineColor,
+ bool thick,
+ Color backgroundColor,
+ const std::vector<std::string>& suggestions,
esprehn 2017/01/31 22:41:35 ditto
rlanday 2017/01/31 23:30:09 Ok
+ int id);
+
+ bool isSuggestion() const override { return true; }
+ std::vector<std::string>& suggestions() { return m_suggestions; }
+ int id() { return m_id; }
+
+ private:
+ TextSuggestionMarkerDetails(Color underlineColor,
+ bool thick,
+ Color backgroundColor,
+ const std::vector<std::string>& suggestions,
+ int id)
+ : TextCompositionMarkerDetails(underlineColor, thick, backgroundColor),
+ m_suggestions(suggestions),
+ m_id(id) {}
+
+ std::vector<std::string> m_suggestions;
+ int m_id;
+};
+
+TextSuggestionMarkerDetails* TextSuggestionMarkerDetails::create(
+ Color underlineColor,
+ bool thick,
+ Color backgroundColor,
+ const std::vector<std::string>& suggestions,
+ int id) {
+ return new TextSuggestionMarkerDetails(underlineColor, thick, backgroundColor,
+ suggestions, id);
+}
+
+inline TextSuggestionMarkerDetails* toTextSuggestionMarkerDetails(
+ DocumentMarkerDetails* details) {
+ if (details && details->isSuggestion())
+ return static_cast<TextSuggestionMarkerDetails*>(details);
+ return nullptr;
+}
+
DocumentMarker::DocumentMarker(MarkerType type,
unsigned startOffset,
unsigned endOffset,
@@ -151,12 +194,13 @@ DocumentMarker::DocumentMarker(unsigned startOffset,
m_details(DocumentMarkerTextMatch::create(activeMatch)),
m_hash(0) {}
-DocumentMarker::DocumentMarker(unsigned startOffset,
+DocumentMarker::DocumentMarker(MarkerType type,
+ unsigned startOffset,
unsigned endOffset,
Color underlineColor,
bool thick,
Color backgroundColor)
- : m_type(DocumentMarker::Composition),
+ : m_type(type),
m_startOffset(startOffset),
m_endOffset(endOffset),
m_details(TextCompositionMarkerDetails::create(underlineColor,
@@ -164,6 +208,26 @@ DocumentMarker::DocumentMarker(unsigned startOffset,
backgroundColor)),
m_hash(0) {}
+DocumentMarker::DocumentMarker(unsigned startOffset,
+ unsigned endOffset,
+ Color underlineColor,
+ bool thick,
+ Color backgroundColor,
+ const std::vector<std::string>& suggestions,
+ int suggestionMarkerID)
+ : m_startOffset(startOffset), m_endOffset(endOffset), m_hash(0) {
+ if (suggestions.empty()) {
+ m_type = DocumentMarker::Composition;
+ m_details = TextCompositionMarkerDetails::create(underlineColor, thick,
+ backgroundColor);
rlanday 2017/01/31 19:50:21 note: the suggestionMarkerID has already been incr
+ } else {
+ m_type = DocumentMarker::Suggestion;
+ m_details = TextSuggestionMarkerDetails::create(
+ underlineColor, thick, backgroundColor, suggestions,
+ suggestionMarkerID);
+ }
+}
+
DocumentMarker::DocumentMarker(const DocumentMarker& marker)
: m_type(marker.type()),
m_startOffset(marker.startOffset()),
@@ -215,6 +279,27 @@ Color DocumentMarker::backgroundColor() const {
return Color::transparent;
}
+const std::vector<std::string> DocumentMarker::suggestions() const {
+ if (TextSuggestionMarkerDetails* details =
+ toTextSuggestionMarkerDetails(m_details.get()))
+ return details->suggestions();
+ return std::vector<std::string>();
+}
+
+int DocumentMarker::suggestionMarkerID() const {
+ if (TextSuggestionMarkerDetails* details =
+ toTextSuggestionMarkerDetails(m_details.get()))
+ return details->id();
+ return -1;
+}
+
+void DocumentMarker::replaceSuggestion(int index,
+ const std::string& newSuggestion) {
+ if (TextSuggestionMarkerDetails* details =
+ toTextSuggestionMarkerDetails(m_details.get()))
+ details->suggestions()[index] = newSuggestion;
+}
+
DEFINE_TRACE(DocumentMarker) {
visitor->trace(m_details);
}

Powered by Google App Engine
This is Rietveld 408576698