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.
5 #include "ppapi/cpp/dev/find_dev.h"
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"
16 template <> const char* interface_name
<PPB_Find_Dev
>() {
17 return PPB_FIND_DEV_INTERFACE
;
20 static const char kPPPFindInterface
[] = PPP_FIND_DEV_INTERFACE
;
22 PP_Bool
StartFind(PP_Instance instance
,
24 PP_Bool case_sensitive
) {
25 void* object
= Instance::GetPerInstanceObject(instance
, kPPPFindInterface
);
28 bool return_value
= static_cast<Find_Dev
*>(object
)->StartFind(
29 text
, PP_ToBool(case_sensitive
));
30 return PP_FromBool(return_value
);
33 void SelectFindResult(PP_Instance instance
, PP_Bool forward
) {
34 void* object
= Instance::GetPerInstanceObject(instance
, kPPPFindInterface
);
36 static_cast<Find_Dev
*>(object
)->SelectFindResult(PP_ToBool(forward
));
39 void StopFind(PP_Instance instance
) {
40 void* object
= Instance::GetPerInstanceObject(instance
, kPPPFindInterface
);
42 static_cast<Find_Dev
*>(object
)->StopFind();
45 const PPP_Find_Dev ppp_find
= {
53 Find_Dev::Find_Dev(Instance
* instance
) : associated_instance_(instance
) {
54 Module::Get()->AddPluginInterface(kPPPFindInterface
, &ppp_find
);
55 instance
->AddPerInstanceObject(kPPPFindInterface
, this);
58 Find_Dev::~Find_Dev() {
59 Instance::RemovePerInstanceObject(associated_instance_
,
60 kPPPFindInterface
, this);
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
));
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
);