Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ppapi / cpp / private / find_private.cc
blob2765ae02eb1818d748d9e774dc4dafe7fdb1f31e
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.
5 #include "ppapi/cpp/private/find_private.h"
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"
13 namespace pp {
15 namespace {
17 template <> const char* interface_name<PPB_Find_Private>() {
18 return PPB_FIND_PRIVATE_INTERFACE;
21 static const char kPPPFindInterface[] = PPP_FIND_PRIVATE_INTERFACE;
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);
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));
40 void StopFind(PP_Instance instance) {
41 void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface);
42 if (object)
43 static_cast<Find_Private*>(object)->StopFind();
46 const PPP_Find_Private ppp_find = {
47 &StartFind,
48 &SelectFindResult,
49 &StopFind
52 } // namespace
54 Find_Private::Find_Private(Instance* instance)
55 : associated_instance_(instance) {
56 Module::Get()->AddPluginInterface(kPPPFindInterface, &ppp_find);
57 instance->AddPerInstanceObject(kPPPFindInterface, this);
60 Find_Private::~Find_Private() {
61 Instance::RemovePerInstanceObject(associated_instance_,
62 kPPPFindInterface, this);
65 void Find_Private::SetPluginToHandleFindRequests() {
66 if (has_interface<PPB_Find_Private>()) {
67 get_interface<PPB_Find_Private>()->SetPluginToHandleFindRequests(
68 associated_instance_.pp_instance());
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));
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);
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()));
99 } // namespace pp