Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: ppapi/cpp/ime_input_event.cc

Issue 18671004: PPAPI: Move IMEInputEvent and TextInput to stable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "ppapi/cpp/ime_input_event.h"
6
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"
11
12 namespace pp {
13
14 namespace {
15
16 template <> const char* interface_name<PPB_IMEInputEvent_1_0>() {
17 return PPB_IME_INPUT_EVENT_INTERFACE_1_0;
18 }
19
20 } // namespace
21
22 // IMEInputEvent -------------------------------------------------------
23
24 IMEInputEvent::IMEInputEvent() : InputEvent() {
25 }
26
27 IMEInputEvent::IMEInputEvent(const InputEvent& event) : InputEvent() {
28 bool is_ime_event = false;
29 if (has_interface<PPB_IMEInputEvent_1_0>()) {
30 if (get_interface<PPB_IMEInputEvent_1_0>()->IsIMEInputEvent(
31 event.pp_resource())) {
32 is_ime_event = true;
33 }
34 } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
35 if (get_interface<PPB_IMEInputEvent_1_0>()->IsIMEInputEvent(
36 event.pp_resource())) {
37 is_ime_event = true;
38 }
39 }
40
41 if (is_ime_event) {
42 Module::Get()->core()->AddRefResource(event.pp_resource());
43 PassRefFromConstructor(event.pp_resource());
44 }
45 }
46
47 IMEInputEvent::IMEInputEvent(
48 const InstanceHandle& instance,
49 PP_InputEvent_Type type,
50 PP_TimeTicks time_stamp,
51 const Var& text,
52 const std::vector<uint32_t>& segment_offsets,
53 int32_t target_segment,
54 const std::pair<uint32_t, uint32_t>& selection) : InputEvent() {
55 if (!has_interface<PPB_IMEInputEvent_1_0>())
56 return;
57 uint32_t dummy = 0;
58 PassRefFromConstructor(get_interface<PPB_IMEInputEvent_1_0>()->Create(
59 instance.pp_instance(), type, time_stamp, text.pp_var(),
60 segment_offsets.empty() ? 0 : segment_offsets.size() - 1,
61 segment_offsets.empty() ? &dummy : &segment_offsets[0],
62 target_segment, selection.first, selection.second));
63 }
64
65
66 Var IMEInputEvent::GetText() const {
67 if (has_interface<PPB_IMEInputEvent_1_0>()) {
68 return Var(PASS_REF,
69 get_interface<PPB_IMEInputEvent_1_0>()->GetText(
70 pp_resource()));
71 } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
72 return Var(PASS_REF,
73 get_interface<PPB_IMEInputEvent_1_0>()->GetText(
74 pp_resource()));
75 }
76 return Var();
77 }
78
79 uint32_t IMEInputEvent::GetSegmentNumber() const {
80 if (has_interface<PPB_IMEInputEvent_1_0>()) {
81 return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentNumber(
82 pp_resource());
83 } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
84 return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentNumber(
85 pp_resource());
86 }
87 return 0;
88 }
89
90 uint32_t IMEInputEvent::GetSegmentOffset(uint32_t index) const {
91 if (has_interface<PPB_IMEInputEvent_1_0>()) {
92 return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentOffset(
93 pp_resource(), index);
94 } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
95 return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentOffset(
96 pp_resource(), index);
97 }
98 return 0;
99 }
100
101 int32_t IMEInputEvent::GetTargetSegment() const {
102 if (has_interface<PPB_IMEInputEvent_1_0>()) {
103 return get_interface<PPB_IMEInputEvent_1_0>()->GetTargetSegment(
104 pp_resource());
105 } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
106 return get_interface<PPB_IMEInputEvent_1_0>()->GetTargetSegment(
107 pp_resource());
108 }
109 return 0;
110 }
111
112 std::pair<uint32_t, uint32_t> IMEInputEvent::GetSelection() const {
113 std::pair<uint32_t, uint32_t> range(0, 0);
114 if (has_interface<PPB_IMEInputEvent_1_0>()) {
115 get_interface<PPB_IMEInputEvent_1_0>()->GetSelection(pp_resource(),
116 &range.first,
117 &range.second);
118 } else if (has_interface<PPB_IMEInputEvent_1_0>()) {
119 get_interface<PPB_IMEInputEvent_1_0>()->GetSelection(pp_resource(),
120 &range.first,
121 &range.second);
122 }
123 return range;
124 }
125
126
127 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698