1 // Copyright 2019 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/ime/text_update_event.h"
6 
7 #include "third_party/blink/renderer/bindings/core/v8/v8_text_update_event_init.h"
8 #include "third_party/blink/renderer/core/event_interface_names.h"
9 #include "third_party/blink/renderer/core/event_type_names.h"
10 
11 namespace blink {
12 
TextUpdateEvent(const TextUpdateEventInit * dict)13 TextUpdateEvent::TextUpdateEvent(const TextUpdateEventInit* dict) {
14   if (dict->hasUpdateText())
15     update_text_ = dict->updateText();
16 
17   if (dict->hasUpdateRangeStart())
18     update_range_start_ = dict->updateRangeStart();
19 
20   if (dict->hasUpdateRangeEnd())
21     update_range_end_ = dict->updateRangeEnd();
22 
23   if (dict->hasNewSelectionStart())
24     new_selection_start_ = dict->newSelectionStart();
25 
26   if (dict->hasNewSelectionEnd())
27     new_selection_end_ = dict->newSelectionEnd();
28 }
29 
TextUpdateEvent(const String & update_text,uint32_t update_range_start,uint32_t update_range_end,uint32_t new_selection_start,uint32_t new_selection_end)30 TextUpdateEvent::TextUpdateEvent(const String& update_text,
31                                  uint32_t update_range_start,
32                                  uint32_t update_range_end,
33                                  uint32_t new_selection_start,
34                                  uint32_t new_selection_end)
35     : Event(event_type_names::kTextupdate,
36             Bubbles::kNo,
37             Cancelable::kYes,
38             ComposedMode::kComposed,
39             base::TimeTicks::Now()),
40       update_text_(update_text),
41       update_range_start_(update_range_start),
42       update_range_end_(update_range_end),
43       new_selection_start_(new_selection_start),
44       new_selection_end_(new_selection_end) {}
45 
Create(const TextUpdateEventInit * dict)46 TextUpdateEvent* TextUpdateEvent::Create(const TextUpdateEventInit* dict) {
47   return MakeGarbageCollected<TextUpdateEvent>(dict);
48 }
49 
50 TextUpdateEvent::~TextUpdateEvent() = default;
51 
updateText() const52 String TextUpdateEvent::updateText() const {
53   return update_text_;
54 }
55 
updateRangeStart() const56 uint32_t TextUpdateEvent::updateRangeStart() const {
57   return update_range_start_;
58 }
59 
updateRangeEnd() const60 uint32_t TextUpdateEvent::updateRangeEnd() const {
61   return update_range_end_;
62 }
63 
newSelectionStart() const64 uint32_t TextUpdateEvent::newSelectionStart() const {
65   return new_selection_start_;
66 }
newSelectionEnd() const67 uint32_t TextUpdateEvent::newSelectionEnd() const {
68   return new_selection_end_;
69 }
70 
InterfaceName() const71 const AtomicString& TextUpdateEvent::InterfaceName() const {
72   return event_interface_names::kTextUpdateEvent;
73 }
74 
75 }  // namespace blink
76