PP_Resource
ppb_keyboard_input_event_create_1_2(PP_Instance instance, PP_InputEvent_Type type,
                                    PP_TimeTicks time_stamp, uint32_t modifiers, uint32_t key_code,
                                    struct PP_Var character_text, struct PP_Var code)
{
    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return 0;
    }
    PP_Resource input_event = pp_resource_allocate(PP_RESOURCE_INPUT_EVENT, pp_i);
    struct pp_input_event_s *ie = pp_resource_acquire(input_event, PP_RESOURCE_INPUT_EVENT);
    if (!ie) {
        trace_error("%s, can't allocate memory\n", __func__);
        return 0;
    }
    ie->event_class = PP_INPUTEVENT_CLASS_KEYBOARD;
    ie->type = type;
    ie->time_stamp = time_stamp;
    ie->modifiers = modifiers;
    ie->key_code = key_code;
    ie->character_text = character_text;
    ie->code = code;
    ppb_var_add_ref(character_text);
    ppb_var_add_ref(code);

    pp_resource_release(input_event);
    return input_event;
}
Example #2
0
struct PP_Var
ppb_instance_private_execute_script(PP_Instance instance, struct PP_Var script,
                                    struct PP_Var *exception)
{
    if (script.type != PP_VARTYPE_STRING) {
        trace_error("%s, 'script' is not a string\n", __func__);
        // TODO: fill exception
        return PP_MakeUndefined();
    }

    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }

    struct execute_script_param_s p;
    p.script =  script;
    p.pp_i =    pp_i;
    p.m_loop =  ppb_message_loop_get_current();
    p.depth =   ppb_message_loop_get_depth(p.m_loop) + 1;

    ppb_var_add_ref(script);
    ppb_message_loop_post_work(p.m_loop, PP_MakeCompletionCallback(_execute_script_comt, &p), 0);
    ppb_message_loop_run_int(p.m_loop, 1);
    ppb_var_release(script);

    return p.result;
}
struct PP_Var
ppb_keyboard_input_event_get_character_text(PP_Resource character_event)
{
    struct pp_input_event_s *ie = pp_resource_acquire(character_event, PP_RESOURCE_INPUT_EVENT);
    if (!ie) {
        trace_error("%s, bad resource\n", __func__);
        return PP_MakeUndefined();
    }
    if (ie->event_class != PP_INPUTEVENT_CLASS_KEYBOARD) {
        trace_error("%s, not a keyboard event\n", __func__);
        pp_resource_release(character_event);
        return PP_MakeUndefined();
    }

    struct PP_Var character_text = ie->character_text;
    ppb_var_add_ref(character_text);
    pp_resource_release(character_event);
    return character_text;
}