summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl/input_event_impl.cc
blob: d0ca57c0b19345e28d426462219497f582013ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) 2011 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/shared_impl/input_event_impl.h"

#include "ppapi/shared_impl/tracker_base.h"
#include "ppapi/shared_impl/var.h"

using ppapi::thunk::PPB_InputEvent_API;

namespace ppapi {

InputEventData::InputEventData()
    : is_filtered(false),
      event_type(PP_INPUTEVENT_TYPE_UNDEFINED),
      event_time_stamp(0.0),
      event_modifiers(0),
      mouse_button(PP_INPUTEVENT_MOUSEBUTTON_NONE),
      mouse_position(PP_MakePoint(0, 0)),
      mouse_click_count(0),
      mouse_movement(PP_MakePoint(0, 0)),
      wheel_delta(PP_MakeFloatPoint(0.0f, 0.0f)),
      wheel_ticks(PP_MakeFloatPoint(0.0f, 0.0f)),
      wheel_scroll_by_page(false),
      key_code(0),
      character_text(),
      composition_target_segment(-1),
      composition_selection_start(0),
      composition_selection_end(0) {
}

InputEventData::~InputEventData() {
}

InputEventImpl::InputEventImpl(const InitAsImpl&,
                               PP_Instance instance,
                               const InputEventData& data)
    : Resource(instance),
      data_(data) {
}

InputEventImpl::InputEventImpl(const InitAsProxy&,
                               PP_Instance instance,
                               const InputEventData& data)
    : Resource(HostResource::MakeInstanceOnly(instance)),
      data_(data) {
}

PPB_InputEvent_API* InputEventImpl::AsPPB_InputEvent_API() {
  return this;
}

const InputEventData& InputEventImpl::GetInputEventData() const {
  return data_;
}

PP_InputEvent_Type InputEventImpl::GetType() {
  return data_.event_type;
}

PP_TimeTicks InputEventImpl::GetTimeStamp() {
  return data_.event_time_stamp;
}

uint32_t InputEventImpl::GetModifiers() {
  return data_.event_modifiers;
}

PP_InputEvent_MouseButton InputEventImpl::GetMouseButton() {
  return data_.mouse_button;
}

PP_Point InputEventImpl::GetMousePosition() {
  return data_.mouse_position;
}

int32_t InputEventImpl::GetMouseClickCount() {
  return data_.mouse_click_count;
}

PP_Point InputEventImpl::GetMouseMovement() {
  return data_.mouse_movement;
}

PP_FloatPoint InputEventImpl::GetWheelDelta() {
  return data_.wheel_delta;
}

PP_FloatPoint InputEventImpl::GetWheelTicks() {
  return data_.wheel_ticks;
}

PP_Bool InputEventImpl::GetWheelScrollByPage() {
  return PP_FromBool(data_.wheel_scroll_by_page);
}

uint32_t InputEventImpl::GetKeyCode() {
  return data_.key_code;
}

PP_Var InputEventImpl::GetCharacterText() {
  return StringVar::StringToPPVar(
      TrackerBase::Get()->GetModuleForInstance(pp_instance()),
      data_.character_text);
}

uint32_t InputEventImpl::GetIMESegmentNumber() {
  if (data_.composition_segment_offsets.empty())
    return 0;
  return data_.composition_segment_offsets.size() - 1;
}

uint32_t InputEventImpl::GetIMESegmentOffset(uint32_t index) {
  if (index >= data_.composition_segment_offsets.size())
    return 0;
  return data_.composition_segment_offsets[index];
}

int32_t InputEventImpl::GetIMETargetSegment() {
  return data_.composition_target_segment;
}

void InputEventImpl::GetIMESelection(uint32_t* start, uint32_t* end) {
  if (start)
    *start = data_.composition_selection_start;
  if (end)
    *end = data_.composition_selection_end;
}

}  // namespace ppapi