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() ? 0 : segment_offsets
.size() - 1,
65 segment_offsets
.empty() ? &dummy
: &segment_offsets
[0],
66 target_segment
, selection
.first
, selection
.second
));
70 Var
IMEInputEvent_Dev::GetText() const {
71 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
73 get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetText(
75 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
77 get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetText(
83 uint32_t IMEInputEvent_Dev::GetSegmentNumber() const {
84 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
85 return get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetSegmentNumber(
87 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
88 return get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetSegmentNumber(
94 uint32_t IMEInputEvent_Dev::GetSegmentOffset(uint32_t index
) const {
95 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
96 return get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetSegmentOffset(
97 pp_resource(), index
);
98 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
99 return get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetSegmentOffset(
100 pp_resource(), index
);
105 int32_t IMEInputEvent_Dev::GetTargetSegment() const {
106 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
107 return get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetTargetSegment(
109 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
110 return get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetTargetSegment(
116 std::pair
<uint32_t, uint32_t> IMEInputEvent_Dev::GetSelection() const {
117 std::pair
<uint32_t, uint32_t> range(0, 0);
118 if (has_interface
<PPB_IMEInputEvent_Dev_0_2
>()) {
119 get_interface
<PPB_IMEInputEvent_Dev_0_2
>()->GetSelection(pp_resource(),
122 } else if (has_interface
<PPB_IMEInputEvent_Dev_0_1
>()) {
123 get_interface
<PPB_IMEInputEvent_Dev_0_1
>()->GetSelection(pp_resource(),