| 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,
|
| + 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);
|
| + } 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);
|
| }
|
|
|