OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Native Client 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 "native_client/src/shared/ppapi_proxy/plugin_ppb_widget.h" |
| 6 |
| 7 #include "native_client/src/include/portability.h" |
| 8 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" |
| 9 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
| 10 #include "native_client/src/shared/ppapi_proxy/utility.h" |
| 11 #include "ppapi/c/dev/ppb_scrollbar_dev.h" |
| 12 #include "ppapi/c/pp_completion_callback.h" |
| 13 #include "ppapi/c/pp_errors.h" |
| 14 #include "ppapi/c/pp_input_event.h" |
| 15 #include "ppapi/c/pp_rect.h" |
| 16 #include "srpcgen/ppb_rpc.h" |
| 17 |
| 18 namespace ppapi_proxy { |
| 19 |
| 20 namespace { |
| 21 |
| 22 const nacl_abi_size_t kPPRectBytes = |
| 23 static_cast<nacl_abi_size_t>(sizeof(struct PP_Rect)); |
| 24 |
| 25 PP_Bool IsWidget(PP_Resource resource) { |
| 26 DebugPrintf("PPB_Widget::IsWidget: " |
| 27 "resource=%"NACL_PRIu32"\n", resource); |
| 28 |
| 29 int32_t is_widget = 0; |
| 30 NaClSrpcError srpc_result = |
| 31 PpbWidgetRpcClient::PPB_Widget_IsWidget( |
| 32 GetMainSrpcChannel(), |
| 33 resource, |
| 34 &is_widget); |
| 35 |
| 36 DebugPrintf("PPB_Widget::IsWidget: %s\n", |
| 37 NaClSrpcErrorString(srpc_result)); |
| 38 |
| 39 if (srpc_result == NACL_SRPC_RESULT_OK && is_widget) |
| 40 return PP_TRUE; |
| 41 return PP_FALSE; |
| 42 } |
| 43 |
| 44 PP_Bool Paint( |
| 45 PP_Resource widget, |
| 46 const struct PP_Rect* rect, |
| 47 PP_Resource image) { |
| 48 DebugPrintf("PPB_Widget::Paint: " |
| 49 "widget=%"NACL_PRIu32"\n", widget); |
| 50 |
| 51 int32_t success = 0; |
| 52 NaClSrpcError srpc_result = |
| 53 PpbWidgetRpcClient::PPB_Widget_Paint( |
| 54 GetMainSrpcChannel(), |
| 55 widget, |
| 56 kPPRectBytes, |
| 57 reinterpret_cast<char*>(const_cast<struct PP_Rect*>(rect)), |
| 58 image, |
| 59 &success); |
| 60 |
| 61 DebugPrintf("PPB_Widget::Paint: %s\n", |
| 62 NaClSrpcErrorString(srpc_result)); |
| 63 |
| 64 if (srpc_result == NACL_SRPC_RESULT_OK && success) |
| 65 return PP_TRUE; |
| 66 return PP_FALSE; |
| 67 } |
| 68 |
| 69 PP_Bool HandleEvent(PP_Resource widget, PP_Resource event) { |
| 70 DebugPrintf("PPB_Widget::HandleEvent: widget=%"NACL_PRId32", " |
| 71 "event=%"NACL_PRId32"\n", |
| 72 widget, event); |
| 73 |
| 74 int32_t handled = 0; |
| 75 NaClSrpcError srpc_result = |
| 76 PpbWidgetRpcClient::PPB_Widget_HandleEvent(GetMainSrpcChannel(), |
| 77 widget, |
| 78 event, |
| 79 &handled); |
| 80 |
| 81 DebugPrintf("PPB_Widget::HandleEvent: %s\n", |
| 82 NaClSrpcErrorString(srpc_result)); |
| 83 |
| 84 if (srpc_result == NACL_SRPC_RESULT_OK && handled) |
| 85 return PP_TRUE; |
| 86 return PP_FALSE; |
| 87 } |
| 88 |
| 89 PP_Bool GetLocation( |
| 90 PP_Resource widget, |
| 91 struct PP_Rect* location) { |
| 92 DebugPrintf("PPB_Widget::GetLocation: " |
| 93 "widget=%"NACL_PRIu32"\n", widget); |
| 94 |
| 95 int32_t visible = 0; |
| 96 nacl_abi_size_t location_size = kPPRectBytes; |
| 97 NaClSrpcError srpc_result = |
| 98 PpbWidgetRpcClient::PPB_Widget_GetLocation( |
| 99 GetMainSrpcChannel(), |
| 100 widget, |
| 101 &location_size, |
| 102 reinterpret_cast<char*>(location), |
| 103 &visible); |
| 104 |
| 105 DebugPrintf("PPB_Widget::GetLocation: %s\n", |
| 106 NaClSrpcErrorString(srpc_result)); |
| 107 |
| 108 if (srpc_result == NACL_SRPC_RESULT_OK && visible && |
| 109 location_size == kPPRectBytes) |
| 110 return PP_TRUE; |
| 111 return PP_FALSE; |
| 112 } |
| 113 |
| 114 void SetLocation( |
| 115 PP_Resource widget, |
| 116 const struct PP_Rect* location) { |
| 117 DebugPrintf("PPB_Widget::SetLocation: " |
| 118 "widget=%"NACL_PRIu32"\n", widget); |
| 119 |
| 120 NaClSrpcError srpc_result = |
| 121 PpbWidgetRpcClient::PPB_Widget_SetLocation( |
| 122 GetMainSrpcChannel(), |
| 123 widget, |
| 124 kPPRectBytes, |
| 125 reinterpret_cast<char*>(const_cast<struct PP_Rect*>(location))); |
| 126 |
| 127 DebugPrintf("PPB_Widget::SetLocation: %s\n", |
| 128 NaClSrpcErrorString(srpc_result)); |
| 129 } |
| 130 |
| 131 } // namespace |
| 132 |
| 133 const PPB_Widget_Dev* PluginWidget::GetInterface() { |
| 134 static const PPB_Widget_Dev widget_interface = { |
| 135 IsWidget, |
| 136 Paint, |
| 137 HandleEvent, |
| 138 GetLocation, |
| 139 SetLocation |
| 140 }; |
| 141 return &widget_interface; |
| 142 } |
| 143 |
| 144 } // namespace ppapi_proxy |
| 145 |
OLD | NEW |