summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/editing/markers/suggestion_marker.cc
blob: 57b25336eec39cd93fd2f64783b9d61defa0ba23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/editing/markers/suggestion_marker.h"

#include "third_party/blink/renderer/core/editing/markers/suggestion_marker_properties.h"

namespace blink {

int32_t SuggestionMarker::current_tag_ = 0;

SuggestionMarker::SuggestionMarker(unsigned start_offset,
                                   unsigned end_offset,
                                   const SuggestionMarkerProperties& properties)
    : StyleableMarker(start_offset,
                      end_offset,
                      properties.UnderlineColor(),
                      properties.Thickness(),
                      properties.BackgroundColor()),
      tag_(NextTag()),
      suggestions_(properties.Suggestions()),
      suggestion_type_(properties.Type()),
      remove_on_finish_composing_(properties.RemoveOnFinishComposing()),
      suggestion_highlight_color_(properties.HighlightColor()) {
  DCHECK_GT(tag_, 0);
}

int32_t SuggestionMarker::Tag() const {
  return tag_;
}

DocumentMarker::MarkerType SuggestionMarker::GetType() const {
  return DocumentMarker::kSuggestion;
}

const Vector<String>& SuggestionMarker::Suggestions() const {
  return suggestions_;
}

bool SuggestionMarker::IsMisspelling() const {
  return suggestion_type_ == SuggestionType::kMisspelling;
}

bool SuggestionMarker::NeedsRemovalOnFinishComposing() const {
  return remove_on_finish_composing_ == RemoveOnFinishComposing::kRemove;
}

Color SuggestionMarker::SuggestionHighlightColor() const {
  return suggestion_highlight_color_;
}

void SuggestionMarker::SetSuggestion(uint32_t suggestion_index,
                                     const String& new_suggestion) {
  DCHECK_LT(suggestion_index, suggestions_.size());
  suggestions_[suggestion_index] = new_suggestion;
}

// static
int32_t SuggestionMarker::NextTag() {
  return ++current_tag_;
}

}  // namespace blink