Home | History | Annotate | Download | only in private
      1 // Copyright 2014 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/private/find_private.h"
      6 
      7 #include "ppapi/c/private/ppb_find_private.h"
      8 #include "ppapi/cpp/instance.h"
      9 #include "ppapi/cpp/module.h"
     10 #include "ppapi/cpp/module_impl.h"
     11 #include "ppapi/cpp/rect.h"
     12 
     13 namespace pp {
     14 
     15 namespace {
     16 
     17 template <> const char* interface_name<PPB_Find_Private>() {
     18   return PPB_FIND_PRIVATE_INTERFACE;
     19 }
     20 
     21 static const char kPPPFindInterface[] = PPP_FIND_PRIVATE_INTERFACE;
     22 
     23 PP_Bool StartFind(PP_Instance instance,
     24                   const char* text,
     25                   PP_Bool case_sensitive) {
     26   void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface);
     27   if (!object)
     28     return PP_FALSE;
     29   bool return_value = static_cast<Find_Private*>(object)->StartFind(
     30       text, PP_ToBool(case_sensitive));
     31   return PP_FromBool(return_value);
     32 }
     33 
     34 void SelectFindResult(PP_Instance instance, PP_Bool forward) {
     35   void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface);
     36   if (object)
     37     static_cast<Find_Private*>(object)->SelectFindResult(PP_ToBool(forward));
     38 }
     39 
     40 void StopFind(PP_Instance instance) {
     41   void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface);
     42   if (object)
     43     static_cast<Find_Private*>(object)->StopFind();
     44 }
     45 
     46 const PPP_Find_Private ppp_find = {
     47   &StartFind,
     48   &SelectFindResult,
     49   &StopFind
     50 };
     51 
     52 }  // namespace
     53 
     54 Find_Private::Find_Private(Instance* instance)
     55       : associated_instance_(instance) {
     56   Module::Get()->AddPluginInterface(kPPPFindInterface, &ppp_find);
     57   instance->AddPerInstanceObject(kPPPFindInterface, this);
     58 }
     59 
     60 Find_Private::~Find_Private() {
     61   Instance::RemovePerInstanceObject(associated_instance_,
     62                                     kPPPFindInterface, this);
     63 }
     64 
     65 void Find_Private::SetPluginToHandleFindRequests() {
     66   if (has_interface<PPB_Find_Private>()) {
     67     get_interface<PPB_Find_Private>()->SetPluginToHandleFindRequests(
     68         associated_instance_.pp_instance());
     69   }
     70 }
     71 
     72 void Find_Private::NumberOfFindResultsChanged(int32_t total,
     73                                               bool final_result) {
     74   if (has_interface<PPB_Find_Private>()) {
     75     get_interface<PPB_Find_Private>()->NumberOfFindResultsChanged(
     76         associated_instance_.pp_instance(), total, PP_FromBool(final_result));
     77   }
     78 }
     79 
     80 void Find_Private::SelectedFindResultChanged(int32_t index) {
     81   if (has_interface<PPB_Find_Private>()) {
     82     get_interface<PPB_Find_Private>()->SelectedFindResultChanged(
     83         associated_instance_.pp_instance(), index);
     84   }
     85 }
     86 
     87 void Find_Private::SetTickmarks(const std::vector<pp::Rect>& tickmarks) {
     88   if (has_interface<PPB_Find_Private>()) {
     89     std::vector<PP_Rect> tickmarks_converted(tickmarks.begin(),
     90                                              tickmarks.end());
     91     PP_Rect* array =
     92         tickmarks_converted.empty() ? NULL : &tickmarks_converted[0];
     93     get_interface<PPB_Find_Private>()->SetTickmarks(
     94         associated_instance_.pp_instance(), array,
     95         static_cast<uint32_t>(tickmarks.size()));
     96   }
     97 }
     98 
     99 }  // namespace pp
    100