| Index: ppapi/cpp/ime_input_event.cc
|
| diff --git a/ppapi/cpp/ime_input_event.cc b/ppapi/cpp/ime_input_event.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..626b975764b7dee48eb8e93d1a08612f3cb5936a
|
| --- /dev/null
|
| +++ b/ppapi/cpp/ime_input_event.cc
|
| @@ -0,0 +1,127 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ppapi/cpp/ime_input_event.h"
|
| +
|
| +#include "ppapi/cpp/instance.h"
|
| +#include "ppapi/cpp/module.h"
|
| +#include "ppapi/cpp/module_impl.h"
|
| +#include "ppapi/cpp/var.h"
|
| +
|
| +namespace pp {
|
| +
|
| +namespace {
|
| +
|
| +template <> const char* interface_name<PPB_IMEInputEvent_1_0>() {
|
| + return PPB_IME_INPUT_EVENT_INTERFACE_1_0;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// IMEInputEvent -------------------------------------------------------
|
| +
|
| +IMEInputEvent::IMEInputEvent() : InputEvent() {
|
| +}
|
| +
|
| +IMEInputEvent::IMEInputEvent(const InputEvent& event) : InputEvent() {
|
| + bool is_ime_event = false;
|
| + if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + if (get_interface<PPB_IMEInputEvent_1_0>()->IsIMEInputEvent(
|
| + event.pp_resource())) {
|
| + is_ime_event = true;
|
| + }
|
| + } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + if (get_interface<PPB_IMEInputEvent_1_0>()->IsIMEInputEvent(
|
| + event.pp_resource())) {
|
| + is_ime_event = true;
|
| + }
|
| + }
|
| +
|
| + if (is_ime_event) {
|
| + Module::Get()->core()->AddRefResource(event.pp_resource());
|
| + PassRefFromConstructor(event.pp_resource());
|
| + }
|
| +}
|
| +
|
| +IMEInputEvent::IMEInputEvent(
|
| + const InstanceHandle& instance,
|
| + PP_InputEvent_Type type,
|
| + PP_TimeTicks time_stamp,
|
| + const Var& text,
|
| + const std::vector<uint32_t>& segment_offsets,
|
| + int32_t target_segment,
|
| + const std::pair<uint32_t, uint32_t>& selection) : InputEvent() {
|
| + if (!has_interface<PPB_IMEInputEvent_1_0>())
|
| + return;
|
| + uint32_t dummy = 0;
|
| + PassRefFromConstructor(get_interface<PPB_IMEInputEvent_1_0>()->Create(
|
| + instance.pp_instance(), type, time_stamp, text.pp_var(),
|
| + segment_offsets.empty() ? 0 : segment_offsets.size() - 1,
|
| + segment_offsets.empty() ? &dummy : &segment_offsets[0],
|
| + target_segment, selection.first, selection.second));
|
| +}
|
| +
|
| +
|
| +Var IMEInputEvent::GetText() const {
|
| + if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return Var(PASS_REF,
|
| + get_interface<PPB_IMEInputEvent_1_0>()->GetText(
|
| + pp_resource()));
|
| + } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return Var(PASS_REF,
|
| + get_interface<PPB_IMEInputEvent_1_0>()->GetText(
|
| + pp_resource()));
|
| + }
|
| + return Var();
|
| +}
|
| +
|
| +uint32_t IMEInputEvent::GetSegmentCount() const {
|
| + if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentCount(
|
| + pp_resource());
|
| + } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentCount(
|
| + pp_resource());
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +uint32_t IMEInputEvent::GetSegmentOffset(uint32_t index) const {
|
| + if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentOffset(
|
| + pp_resource(), index);
|
| + } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentOffset(
|
| + pp_resource(), index);
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +int32_t IMEInputEvent::GetTargetSegment() const {
|
| + if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return get_interface<PPB_IMEInputEvent_1_0>()->GetTargetSegment(
|
| + pp_resource());
|
| + } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + return get_interface<PPB_IMEInputEvent_1_0>()->GetTargetSegment(
|
| + pp_resource());
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +std::pair<uint32_t, uint32_t> IMEInputEvent::GetSelection() const {
|
| + std::pair<uint32_t, uint32_t> range(0, 0);
|
| + if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + get_interface<PPB_IMEInputEvent_1_0>()->GetSelection(pp_resource(),
|
| + &range.first,
|
| + &range.second);
|
| + } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
|
| + get_interface<PPB_IMEInputEvent_1_0>()->GetSelection(pp_resource(),
|
| + &range.first,
|
| + &range.second);
|
| + }
|
| + return range;
|
| +}
|
| +
|
| +
|
| +} // namespace pp
|
|
|