[Swfdec] [Swfdec-commits] swfdec/swfdec_text_field_movie.c swfdec/swfdec_text_field_movie.h

Benjamin Otte otte at gnome.org
Wed Aug 20 03:55:23 PDT 2008


Just looking at this, shouldn't the sandbox be available from
SWFDEC_MOVIE (text)->resource->sandbox ?
And if so, I think we do want a swfdec_movie_get_sandbox() function so
noone gets it wrong again. :)

Benjamin


On Sat, Aug 16, 2008 at 4:19 PM, Pekka Lampila
<medar at kemper.freedesktop.org> wrote:
>  swfdec/swfdec_text_field_movie.c |  135 ++++++++++++++++++++++++++-------------
>  swfdec/swfdec_text_field_movie.h |    2
>  2 files changed, 95 insertions(+), 42 deletions(-)
>
> New commits:
> commit bff97ca6943329fc42fef894009c9304c0b8d22e
> Author: Pekka Lampila <pekka.lampila at iki.fi>
> Date:   Sat Aug 16 18:18:36 2008 +0300
>
>    Support asfunction: links in TextField
>
> diff --git a/swfdec/swfdec_text_field_movie.c b/swfdec/swfdec_text_field_movie.c
> index 93dab9e..4b702b7 100644
> --- a/swfdec/swfdec_text_field_movie.c
> +++ b/swfdec/swfdec_text_field_movie.c
> @@ -395,6 +395,8 @@ swfdec_text_field_movie_init_movie (SwfdecMovie *movie)
>
>   cx = swfdec_gc_object_get_context (movie);
>
> +  text->sandbox = SWFDEC_SANDBOX (cx->global);
> +
>   swfdec_text_field_movie_init_properties (cx);
>
>   swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_TextField, &val);
> @@ -530,6 +532,90 @@ swfdec_text_field_movie_contains (SwfdecMovie *movie, double x, double y,
>  }
>
>  static void
> +swfdec_text_field_movie_parse_listen_variable (SwfdecTextFieldMovie *text,
> +    const char *variable, SwfdecAsObject **object, const char **name)
> +{
> +  SwfdecAsContext *cx;
> +  SwfdecAsObject *parent;
> +  const char *p1, *p2;
> +
> +  g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
> +  g_return_if_fail (variable != NULL);
> +  g_return_if_fail (object != NULL);
> +  g_return_if_fail (name != NULL);
> +
> +  *object = NULL;
> +  *name = NULL;
> +
> +  if (SWFDEC_MOVIE (text)->parent == NULL)
> +    return;
> +
> +  g_assert (SWFDEC_IS_AS_OBJECT (SWFDEC_MOVIE (text)->parent));
> +  cx = swfdec_gc_object_get_context (text);
> +  parent = SWFDEC_AS_OBJECT (SWFDEC_MOVIE (text)->parent);
> +
> +  p1 = strrchr (variable, '.');
> +  p2 = strrchr (variable, ':');
> +  if (p1 == NULL && p2 == NULL) {
> +    *object = parent;
> +    *name = variable;
> +  } else {
> +    if (p1 == NULL || (p2 != NULL && p2 > p1))
> +      p1 = p2;
> +    if (strlen (p1) == 1)
> +      return;
> +    *object = swfdec_action_lookup_object (cx, parent, variable, p1);
> +    if (*object == NULL)
> +      return;
> +    *name = swfdec_as_context_get_string (cx, p1 + 1);
> +  }
> +}
> +
> +static void
> +swfdec_text_field_movie_asfunction (SwfdecTextFieldMovie *text,
> +    const char *url)
> +{
> +  char **parts;
> +  SwfdecAsObject *object;
> +  const char *name;
> +  SwfdecAsContext *cx;
> +
> +  g_return_if_fail (g_ascii_strncasecmp (url, "asfunction:",
> +       strlen ("asfunction:")) == 0);
> +
> +  cx = swfdec_gc_object_get_context (text);
> +
> +  parts = g_strsplit (url + strlen ("asfunction:"), ",", 2);
> +  if (parts[0] == NULL) {
> +    SWFDEC_ERROR ("asfunction link without function name clicked");
> +    g_strfreev (parts);
> +    return;
> +  }
> +
> +  swfdec_text_field_movie_parse_listen_variable (text,
> +      swfdec_as_context_get_string (cx, parts[0]), &object, &name);
> +
> +  if (object == NULL || name == NULL) {
> +    SWFDEC_ERROR ("Function in asfunction link not found: %s", parts[0]);
> +    g_strfreev (parts);
> +    return;
> +  }
> +
> +  swfdec_sandbox_use (text->sandbox);
> +  if (parts[1] != NULL) {
> +    SwfdecAsValue val;
> +    SWFDEC_AS_VALUE_SET_STRING (&val,
> +       swfdec_as_context_get_string (cx, parts[1]));
> +    swfdec_as_object_call (object, name, 1, &val, NULL);
> +  } else {
> +    swfdec_as_object_call (object, name, 0, NULL, NULL);
> +  }
> +  swfdec_sandbox_unuse (text->sandbox);
> +
> +  g_strfreev (parts);
> +}
> +
> +static void
>  swfdec_text_field_movie_letter_clicked (SwfdecTextFieldMovie *text,
>     guint index_)
>  {
> @@ -541,8 +627,13 @@ swfdec_text_field_movie_letter_clicked (SwfdecTextFieldMovie *text,
>   attr = swfdec_text_buffer_get_attributes (text->text, index_);
>
>   if (attr->url != SWFDEC_AS_STR_EMPTY) {
> -    swfdec_player_launch (SWFDEC_PLAYER (swfdec_gc_object_get_context (text)),
> -       attr->url, attr->target, NULL);
> +    if (g_ascii_strncasecmp (attr->url, "asfunction:",
> +         strlen ("asfunction:")) == 0) {
> +      swfdec_text_field_movie_asfunction (text, attr->url);
> +    } else {
> +      swfdec_player_launch (SWFDEC_PLAYER (swfdec_gc_object_get_context (text)),
> +         attr->url, attr->target, NULL);
> +    }
>   }
>  }
>
> @@ -923,46 +1014,6 @@ swfdec_text_field_movie_init (SwfdecTextFieldMovie *text)
>   text->character_pressed = -1;
>  }
>
> -static void
> -swfdec_text_field_movie_parse_listen_variable (SwfdecTextFieldMovie *text,
> -    const char *variable, SwfdecAsObject **object, const char **name)
> -{
> -  SwfdecAsContext *cx;
> -  SwfdecAsObject *parent;
> -  const char *p1, *p2;
> -
> -  g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
> -  g_return_if_fail (variable != NULL);
> -  g_return_if_fail (object != NULL);
> -  g_return_if_fail (name != NULL);
> -
> -  *object = NULL;
> -  *name = NULL;
> -
> -  if (SWFDEC_MOVIE (text)->parent == NULL)
> -    return;
> -
> -  g_assert (SWFDEC_IS_AS_OBJECT (SWFDEC_MOVIE (text)->parent));
> -  cx = swfdec_gc_object_get_context (text);
> -  parent = SWFDEC_AS_OBJECT (SWFDEC_MOVIE (text)->parent);
> -
> -  p1 = strrchr (variable, '.');
> -  p2 = strrchr (variable, ':');
> -  if (p1 == NULL && p2 == NULL) {
> -    *object = parent;
> -    *name = variable;
> -  } else {
> -    if (p1 == NULL || (p2 != NULL && p2 > p1))
> -      p1 = p2;
> -    if (strlen (p1) == 1)
> -      return;
> -    *object = swfdec_action_lookup_object (cx, parent, variable, p1);
> -    if (*object == NULL)
> -      return;
> -    *name = swfdec_as_context_get_string (cx, p1 + 1);
> -  }
> -}
> -
>  void
>  swfdec_text_field_movie_set_listen_variable_text (SwfdecTextFieldMovie *text,
>     const char *value)
> diff --git a/swfdec/swfdec_text_field_movie.h b/swfdec/swfdec_text_field_movie.h
> index fabab63..720892b 100644
> --- a/swfdec/swfdec_text_field_movie.h
> +++ b/swfdec/swfdec_text_field_movie.h
> @@ -43,6 +43,8 @@ typedef struct _SwfdecTextFieldMovieClass SwfdecTextFieldMovieClass;
>  struct _SwfdecTextFieldMovie {
>   SwfdecActor          actor;
>
> +  SwfdecSandbox                *sandbox;
> +
>   SwfdecRect           extents;                /* original extents (copied from graphic) - queue extents update when modifying */
>   /* these are updated with the movie's extents - so call swfdec_movie_update() */
>   cairo_matrix_t       to_layout;              /* matrix to go from movie => layout */
> _______________________________________________
> Swfdec-commits mailing list
> Swfdec-commits at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/swfdec-commits
>


More information about the Swfdec mailing list