1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "third_party/blink/renderer/core/editing/markers/suggestion_marker.h"
6 
7 #include "third_party/blink/renderer/core/editing/markers/suggestion_marker_properties.h"
8 
9 namespace blink {
10 
11 int32_t SuggestionMarker::current_tag_ = 0;
12 
SuggestionMarker(unsigned start_offset,unsigned end_offset,const SuggestionMarkerProperties & properties)13 SuggestionMarker::SuggestionMarker(unsigned start_offset,
14                                    unsigned end_offset,
15                                    const SuggestionMarkerProperties& properties)
16     : StyleableMarker(start_offset,
17                       end_offset,
18                       properties.UnderlineColor(),
19                       properties.Thickness(),
20                       properties.UnderlineStyle(),
21                       properties.TextColor(),
22                       properties.BackgroundColor()),
23       tag_(NextTag()),
24       suggestions_(properties.Suggestions()),
25       suggestion_type_(properties.Type()),
26       remove_on_finish_composing_(properties.RemoveOnFinishComposing()),
27       suggestion_highlight_color_(properties.HighlightColor()) {
28   DCHECK_GT(tag_, 0);
29 }
30 
Tag() const31 int32_t SuggestionMarker::Tag() const {
32   return tag_;
33 }
34 
GetSuggestionType() const35 SuggestionMarker::SuggestionType SuggestionMarker::GetSuggestionType() const {
36   return suggestion_type_;
37 }
38 
GetType() const39 DocumentMarker::MarkerType SuggestionMarker::GetType() const {
40   return DocumentMarker::kSuggestion;
41 }
42 
Suggestions() const43 const Vector<String>& SuggestionMarker::Suggestions() const {
44   return suggestions_;
45 }
46 
IsMisspelling() const47 bool SuggestionMarker::IsMisspelling() const {
48   return suggestion_type_ == SuggestionType::kMisspelling;
49 }
50 
NeedsRemovalOnFinishComposing() const51 bool SuggestionMarker::NeedsRemovalOnFinishComposing() const {
52   return remove_on_finish_composing_ == RemoveOnFinishComposing::kRemove;
53 }
54 
SuggestionHighlightColor() const55 Color SuggestionMarker::SuggestionHighlightColor() const {
56   return suggestion_highlight_color_;
57 }
58 
SetSuggestion(uint32_t suggestion_index,const String & new_suggestion)59 void SuggestionMarker::SetSuggestion(uint32_t suggestion_index,
60                                      const String& new_suggestion) {
61   DCHECK_LT(suggestion_index, suggestions_.size());
62   suggestions_[suggestion_index] = new_suggestion;
63 }
64 
65 // static
NextTag()66 int32_t SuggestionMarker::NextTag() {
67   return ++current_tag_;
68 }
69 
70 }  // namespace blink
71