Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/cpp/dev/find_dev.h" | 5 #include "ppapi/cpp/dev/find_dev.h" |
| 6 | 6 |
| 7 #include "ppapi/c/dev/ppb_find_dev.h" | 7 #include "ppapi/c/dev/ppb_find_dev.h" |
| 8 #include "ppapi/cpp/common.h" | 8 #include "ppapi/cpp/common.h" |
|
dmichael (off chromium)
2011/07/07 22:37:03
could remove this include now
| |
| 9 #include "ppapi/cpp/instance.h" | 9 #include "ppapi/cpp/instance.h" |
| 10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
| 11 #include "ppapi/cpp/module_impl.h" | 11 #include "ppapi/cpp/module_impl.h" |
| 12 | 12 |
| 13 namespace pp { | 13 namespace pp { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 template <> const char* interface_name<PPB_Find_Dev>() { | 17 template <> const char* interface_name<PPB_Find_Dev>() { |
| 18 return PPB_FIND_DEV_INTERFACE; | 18 return PPB_FIND_DEV_INTERFACE; |
| 19 } | 19 } |
| 20 | 20 |
| 21 static const char kPPPFindInterface[] = PPP_FIND_DEV_INTERFACE; | 21 static const char kPPPFindInterface[] = PPP_FIND_DEV_INTERFACE; |
| 22 | 22 |
| 23 PP_Bool StartFind(PP_Instance instance, | 23 PP_Bool StartFind(PP_Instance instance, |
| 24 const char* text, | 24 const char* text, |
| 25 PP_Bool case_sensitive) { | 25 PP_Bool case_sensitive) { |
| 26 void* object = | 26 void* object = |
| 27 pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); | 27 pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); |
| 28 if (!object) | 28 if (!object) |
| 29 return PP_FALSE; | 29 return PP_FALSE; |
| 30 bool return_value = static_cast<Find_Dev*>(object)->StartFind( | 30 bool return_value = static_cast<Find_Dev*>(object)->StartFind( |
| 31 text, PPBoolToBool(case_sensitive)); | 31 text, PP_ToBool(case_sensitive)); |
| 32 return BoolToPPBool(return_value); | 32 return PP_FromBool(return_value); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void SelectFindResult(PP_Instance instance, PP_Bool forward) { | 35 void SelectFindResult(PP_Instance instance, PP_Bool forward) { |
| 36 void* object = | 36 void* object = |
| 37 pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); | 37 pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); |
| 38 if (object) | 38 if (object) |
| 39 static_cast<Find_Dev*>(object)->SelectFindResult(PPBoolToBool(forward)); | 39 static_cast<Find_Dev*>(object)->SelectFindResult(PP_ToBool(forward)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void StopFind(PP_Instance instance) { | 42 void StopFind(PP_Instance instance) { |
| 43 void* object = | 43 void* object = |
| 44 pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); | 44 pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); |
| 45 if (object) | 45 if (object) |
| 46 static_cast<Find_Dev*>(object)->StopFind(); | 46 static_cast<Find_Dev*>(object)->StopFind(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 const PPP_Find_Dev ppp_find = { | 49 const PPP_Find_Dev ppp_find = { |
| 50 &StartFind, | 50 &StartFind, |
| 51 &SelectFindResult, | 51 &SelectFindResult, |
| 52 &StopFind | 52 &StopFind |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 Find_Dev::Find_Dev(Instance* instance) : associated_instance_(instance) { | 57 Find_Dev::Find_Dev(Instance* instance) : associated_instance_(instance) { |
| 58 pp::Module::Get()->AddPluginInterface(kPPPFindInterface, &ppp_find); | 58 pp::Module::Get()->AddPluginInterface(kPPPFindInterface, &ppp_find); |
| 59 associated_instance_->AddPerInstanceObject(kPPPFindInterface, this); | 59 associated_instance_->AddPerInstanceObject(kPPPFindInterface, this); |
| 60 } | 60 } |
| 61 | 61 |
| 62 Find_Dev::~Find_Dev() { | 62 Find_Dev::~Find_Dev() { |
| 63 associated_instance_->RemovePerInstanceObject(kPPPFindInterface, this); | 63 associated_instance_->RemovePerInstanceObject(kPPPFindInterface, this); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void Find_Dev::NumberOfFindResultsChanged(int32_t total, bool final_result) { | 66 void Find_Dev::NumberOfFindResultsChanged(int32_t total, bool final_result) { |
| 67 if (has_interface<PPB_Find_Dev>()) { | 67 if (has_interface<PPB_Find_Dev>()) { |
| 68 get_interface<PPB_Find_Dev>()->NumberOfFindResultsChanged( | 68 get_interface<PPB_Find_Dev>()->NumberOfFindResultsChanged( |
| 69 associated_instance_->pp_instance(), total, BoolToPPBool(final_result)); | 69 associated_instance_->pp_instance(), total, PP_FromBool(final_result)); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 void Find_Dev::SelectedFindResultChanged(int32_t index) { | 73 void Find_Dev::SelectedFindResultChanged(int32_t index) { |
| 74 if (has_interface<PPB_Find_Dev>()) { | 74 if (has_interface<PPB_Find_Dev>()) { |
| 75 get_interface<PPB_Find_Dev>()->SelectedFindResultChanged( | 75 get_interface<PPB_Find_Dev>()->SelectedFindResultChanged( |
| 76 associated_instance_->pp_instance(), index); | 76 associated_instance_->pp_instance(), index); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace pp | 80 } // namespace pp |
| OLD | NEW |