cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / cpp / dev / ime_input_event_dev.cc
blob9ddc16e913881cfe2f0247dfdb12552150ddac69
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"
12 namespace pp {
14 namespace {
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;
24 } // namespace
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())) {
36 is_ime_event = true;
38 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
39 if (get_interface<PPB_IMEInputEvent_Dev_0_1>()->IsIMEInputEvent(
40 event.pp_resource())) {
41 is_ime_event = true;
45 if (is_ime_event) {
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,
55 const Var& text,
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>())
60 return;
61 uint32_t dummy = 0;
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>()) {
72 return Var(PASS_REF,
73 get_interface<PPB_IMEInputEvent_Dev_0_2>()->GetText(
74 pp_resource()));
75 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
76 return Var(PASS_REF,
77 get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetText(
78 pp_resource()));
80 return Var();
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(
86 pp_resource());
87 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
88 return get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetSegmentNumber(
89 pp_resource());
91 return 0;
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);
102 return 0;
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(
108 pp_resource());
109 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
110 return get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetTargetSegment(
111 pp_resource());
113 return 0;
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(),
120 &range.first,
121 &range.second);
122 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
123 get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetSelection(pp_resource(),
124 &range.first,
125 &range.second);
127 return range;
131 } // namespace pp