- add sources.
[platform/framework/web/crosswalk.git] / src / ppapi / cpp / dev / find_dev.cc
1 // Copyright (c) 2010 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/dev/find_dev.h"
6
7 #include "ppapi/c/dev/ppb_find_dev.h"
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/module.h"
10 #include "ppapi/cpp/module_impl.h"
11
12 namespace pp {
13
14 namespace {
15
16 template <> const char* interface_name<PPB_Find_Dev>() {
17   return PPB_FIND_DEV_INTERFACE;
18 }
19
20 static const char kPPPFindInterface[] = PPP_FIND_DEV_INTERFACE;
21
22 PP_Bool StartFind(PP_Instance instance,
23                   const char* text,
24                   PP_Bool case_sensitive) {
25   void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface);
26   if (!object)
27     return PP_FALSE;
28   bool return_value = static_cast<Find_Dev*>(object)->StartFind(
29       text, PP_ToBool(case_sensitive));
30   return PP_FromBool(return_value);
31 }
32
33 void SelectFindResult(PP_Instance instance, PP_Bool forward) {
34   void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface);
35   if (object)
36     static_cast<Find_Dev*>(object)->SelectFindResult(PP_ToBool(forward));
37 }
38
39 void StopFind(PP_Instance instance) {
40   void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface);
41   if (object)
42     static_cast<Find_Dev*>(object)->StopFind();
43 }
44
45 const PPP_Find_Dev ppp_find = {
46   &StartFind,
47   &SelectFindResult,
48   &StopFind
49 };
50
51 }  // namespace
52
53 Find_Dev::Find_Dev(Instance* instance) : associated_instance_(instance) {
54   Module::Get()->AddPluginInterface(kPPPFindInterface, &ppp_find);
55   instance->AddPerInstanceObject(kPPPFindInterface, this);
56 }
57
58 Find_Dev::~Find_Dev() {
59   Instance::RemovePerInstanceObject(associated_instance_,
60                                     kPPPFindInterface, this);
61 }
62
63 void Find_Dev::NumberOfFindResultsChanged(int32_t total, bool final_result) {
64   if (has_interface<PPB_Find_Dev>()) {
65     get_interface<PPB_Find_Dev>()->NumberOfFindResultsChanged(
66         associated_instance_.pp_instance(), total, PP_FromBool(final_result));
67   }
68 }
69
70 void Find_Dev::SelectedFindResultChanged(int32_t index) {
71   if (has_interface<PPB_Find_Dev>()) {
72     get_interface<PPB_Find_Dev>()->SelectedFindResultChanged(
73         associated_instance_.pp_instance(), index);
74   }
75 }
76
77 }  // namespace pp