Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ppapi / cpp / dev / ime_input_event_dev.cc
blob3396a3980a2d06c3c14e44330a2ce9fa18b143ae
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() ? 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>()) {
73 return Var(PASS_REF,
74 get_interface<PPB_IMEInputEvent_Dev_0_2>()->GetText(
75 pp_resource()));
76 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
77 return Var(PASS_REF,
78 get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetText(
79 pp_resource()));
81 return Var();
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(
87 pp_resource());
88 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
89 return get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetSegmentNumber(
90 pp_resource());
92 return 0;
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);
103 return 0;
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(
109 pp_resource());
110 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
111 return get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetTargetSegment(
112 pp_resource());
114 return 0;
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(),
121 &range.first,
122 &range.second);
123 } else if (has_interface<PPB_IMEInputEvent_Dev_0_1>()) {
124 get_interface<PPB_IMEInputEvent_Dev_0_1>()->GetSelection(pp_resource(),
125 &range.first,
126 &range.second);
128 return range;
132 } // namespace pp