1 // Copyright (c) 2012 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.
5 #include "ppapi/cpp/dev/ime_input_event_dev.h"
7 #include "ppapi/cpp/instance.h"
8 #include "ppapi/cpp/module.h"
9 #include "ppapi/cpp/module_impl.h"
10 #include "ppapi/cpp/var.h"
16 template <> const char* interface_name
<PPB_IMEInputEvent_Dev_0_2
>() {
17 return PPB_IME_INPUT_EVENT_DEV_INTERFACE_0_2
;
20 template <> const char* interface_name
<PPB_IMEInputEvent_Dev_0_1
>() {
21 return PPB_IME_INPUT_EVENT_DEV_INTERFACE_0_1
;
26 // IMEInputEvent_Dev -------------------------------------------------------
28 IMEInputEvent_Dev::IMEInputEvent_Dev() : InputEvent() {
31 IMEInputEvent_Dev::IMEInputEvent_Dev(const InputEvent
& event
) : InputEvent() {
32 bool is_ime_event
= false;
33 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
34 if (get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->IsIMEInputEvent(
35 event
.pp_resource())) {
38 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
39 if (get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->IsIMEInputEvent(
40 event
.pp_resource())) {
46 Module::Get()->core()->AddRefResource(event
.pp_resource());
47 PassRefFromConstructor(event
.pp_resource());
51 IMEInputEvent_Dev::IMEInputEvent_Dev(
52 const InstanceHandle
& instance
,
53 PP_InputEvent_Type type
,
54 PP_TimeTicks time_stamp
,
56 const std::vector
<uint32_t>& segment_offsets
,
57 int32_t target_segment
,
58 const std::pair
<uint32_t, uint32_t>& selection
) : InputEvent() {
59 if (!has_interface
<PPB_IMEInputEvent_Dev_0_2
>())
62 PassRefFromConstructor(get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->Create(
63 instance
.pp_instance(), type
, time_stamp
, text
.pp_var(),
64 segment_offsets
.empty() ? 0u :
65 static_cast<uint32_t>(segment_offsets
.size() - 1),
66 segment_offsets
.empty() ? &dummy
: &segment_offsets
[0],
67 target_segment
, selection
.first
, selection
.second
));
71 Var
IMEInputEvent_Dev::GetText() const {
72 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
74 get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetText(
76 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
78 get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetText(
84 uint32_t IMEInputEvent_Dev::GetSegmentNumber() const {
85 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
86 return get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetSegmentNumber(
88 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
89 return get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetSegmentNumber(
95 uint32_t IMEInputEvent_Dev::GetSegmentOffset(uint32_t index
) const {
96 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
97 return get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetSegmentOffset(
98 pp_resource(), index
);
99 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
100 return get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetSegmentOffset(
101 pp_resource(), index
);
106 int32_t IMEInputEvent_Dev::GetTargetSegment() const {
107 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
108 return get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetTargetSegment(
110 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
111 return get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetTargetSegment(
117 std::pair
<uint32_t, uint32_t> IMEInputEvent_Dev::GetSelection() const {
118 std::pair
<uint32_t, uint32_t> range(0, 0);
119 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
120 get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetSelection(pp_resource(),
123 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
124 get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetSelection(pp_resource(),