[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ppapi / cpp / mouse_lock.cc
blob2ece8fac26308a6455620d4e9e71e14e22689036
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/mouse_lock.h"
7 #include "ppapi/c/ppb_mouse_lock.h"
8 #include "ppapi/c/ppp_mouse_lock.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/instance.h"
11 #include "ppapi/cpp/instance_handle.h"
12 #include "ppapi/cpp/module.h"
13 #include "ppapi/cpp/module_impl.h"
15 namespace pp {
17 namespace {
19 static const char kPPPMouseLockInterface[] = PPP_MOUSELOCK_INTERFACE;
21 void MouseLockLost(PP_Instance instance) {
22 void* object =
23 Instance::GetPerInstanceObject(instance, kPPPMouseLockInterface);
24 if (!object)
25 return;
26 static_cast<MouseLock*>(object)->MouseLockLost();
29 const PPP_MouseLock ppp_mouse_lock = {
30 &MouseLockLost
33 template <> const char* interface_name<PPB_MouseLock_1_0>() {
34 return PPB_MOUSELOCK_INTERFACE_1_0;
37 } // namespace
39 MouseLock::MouseLock(Instance* instance)
40 : associated_instance_(instance) {
41 Module::Get()->AddPluginInterface(kPPPMouseLockInterface, &ppp_mouse_lock);
42 instance->AddPerInstanceObject(kPPPMouseLockInterface, this);
45 MouseLock::~MouseLock() {
46 Instance::RemovePerInstanceObject(associated_instance_,
47 kPPPMouseLockInterface, this);
50 int32_t MouseLock::LockMouse(const CompletionCallback& cc) {
51 if (!has_interface<PPB_MouseLock_1_0>())
52 return cc.MayForce(PP_ERROR_NOINTERFACE);
53 return get_interface<PPB_MouseLock_1_0>()->LockMouse(
54 associated_instance_.pp_instance(), cc.pp_completion_callback());
57 void MouseLock::UnlockMouse() {
58 if (has_interface<PPB_MouseLock_1_0>()) {
59 get_interface<PPB_MouseLock_1_0>()->UnlockMouse(
60 associated_instance_.pp_instance());
64 } // namespace pp