示例#1
0
static void
gtk_xtbin_destroy (GtkObject *object)
{
  GtkXtBin *xtbin;

#ifdef DEBUG_XTBIN
  printf("gtk_xtbin_destroy()\n");
#endif

  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_XTBIN (object));

  xtbin = GTK_XTBIN (object);

  if(xtbin->xtwindow) {
    /* remove the event handler */
    xt_client_destroy(&(xtbin->xtclient));
    xtbin->xtwindow = 0;

    /* stop X event loop */
    xt_client_xloop_destroy();
  }

  GTK_OBJECT_CLASS(parent_class)->destroy(object);
}
示例#2
0
void
gtk_xtbin_resize (GtkWidget *widget,
                  gint       width,
                  gint       height)
{
  Arg args[2];
  GtkXtBin *xtbin = GTK_XTBIN (widget);
  GtkAllocation allocation;

#ifdef DEBUG_XTBIN
  printf("gtk_xtbin_resize %p %d %d\n", (void *)widget, width, height);
#endif

  XtSetArg(args[0], XtNheight, height);
  XtSetArg(args[1], XtNwidth,  width);
  XtSetValues(xtbin->xtclient.top_widget, args, 2);
  xtbin->height = height;
  xtbin->width  = width;

  /* we need to send a size allocate so the socket knows about the
     size changes */
  allocation.x = xtbin->x;
  allocation.y = xtbin->y;
  allocation.width = xtbin->width;
  allocation.height = xtbin->height;

  gtk_widget_size_allocate(widget, &allocation);
}
static void
gtk_xtbin_realize (GtkWidget *widget)
{
  GtkXtBin     *xtbin;
  GtkAllocation allocation = { 0, 0, 200, 200 };
#if GTK_CHECK_VERSION(2, 18, 0)
  GtkAllocation widget_allocation;
#endif

#ifdef DEBUG_XTBIN
  printf("gtk_xtbin_realize()\n");
#endif

  g_return_if_fail (GTK_IS_XTBIN (widget));

  xtbin = GTK_XTBIN (widget);

  /* caculate the allocation before realize */
#if GTK_CHECK_VERSION(2, 24, 0)
  allocation.width = gdk_window_get_width(xtbin->parent_window);
  allocation.height = gdk_window_get_height(xtbin->parent_window);
#else
  gint  x, y, w, h, d; /* geometry of window */
  gdk_window_get_geometry(xtbin->parent_window, &x, &y, &w, &h, &d);
  allocation.width = w;
  allocation.height = h;
#endif
  gtk_widget_size_allocate (widget, &allocation);

#ifdef DEBUG_XTBIN
  printf("initial allocation %d %d %d %d\n", x, y, w, h);
#endif

#if GTK_CHECK_VERSION(2, 18, 0)
  gtk_widget_get_allocation(widget, &widget_allocation);
  xtbin->width = widget_allocation.width;
  xtbin->height = widget_allocation.height;
#else
  xtbin->width = widget->allocation.width;
  xtbin->height = widget->allocation.height;
#endif

  /* use GtkSocket's realize */
  (*GTK_WIDGET_CLASS(parent_class)->realize)(widget);

  /* create the Xt client widget */
  xt_client_create(&(xtbin->xtclient), 
       gtk_socket_get_id(GTK_SOCKET(xtbin)), 
       xtbin->height, 
       xtbin->width);
  xtbin->xtwindow = XtWindow(xtbin->xtclient.child_widget);

  gdk_flush();

  /* now that we have created the xt client, add it to the socket. */
  gtk_socket_add_id(GTK_SOCKET(widget), xtbin->xtwindow);
}
nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance)
{
  if (aPluginInstance) {
    if (type == NPWindowTypeWindow) {
      if (!mSocketWidget) {
        nsresult rv;

        PRBool needXEmbed = PR_FALSE;
        rv = aPluginInstance->GetValueFromPlugin(NPPVpluginNeedsXEmbed, &needXEmbed);
        // If the call returned an error code make sure we still use our default value.
        if (NS_FAILED(rv)) {
          needXEmbed = PR_FALSE;
        }
#ifdef DEBUG
        printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", needXEmbed);
#endif

        if (needXEmbed) {
          rv = CreateXEmbedWindow();
        }
        else {
          rv = CreateXtWindow();
        }

        if (NS_FAILED(rv)) {
          return NS_ERROR_FAILURE;
        }
      }

      if (!mSocketWidget) {
        return NS_ERROR_FAILURE;
      }

      // Make sure to resize and re-place the window if required.
      // Need to reset "window" each time as nsObjectFrame::DidReflow sets it
      // to the ancestor window.
      if (GTK_IS_XTBIN(mSocketWidget)) {
        gtk_xtbin_resize(mSocketWidget, width, height);
        // Point the NPWindow structures window to the actual X window
        window = (void*)GTK_XTBIN(mSocketWidget)->xtwindow;
      }
      else { // XEmbed
        SetAllocation();
        window = (void*)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));
      }
#ifdef DEBUG
      printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window);
#endif
    } // NPWindowTypeWindow
    aPluginInstance->SetWindow(this);
  }
  else if (mPluginInstance)
    mPluginInstance->SetWindow(nsnull);

  SetPluginInstance(aPluginInstance);
  return NS_OK;
}
nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance)
{
  if(aPluginInstance) {
    if (type == nsPluginWindowType_Window) {
      nsresult rv;
      if(!mSocketWidget) {
        PRBool needXEmbed = PR_FALSE;
        if (CanGetValueFromPlugin(aPluginInstance)) {
          rv = aPluginInstance->GetValue
            ((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &needXEmbed);
#ifdef DEBUG
          printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", needXEmbed);
#endif
        }
        nsresult rv;
        if(needXEmbed) {
#ifdef MOZ_COMPOSITED_PLUGINS
          rv = CreateXCompositedWindow();
#else
          rv = CreateXEmbedWindow();
#endif
        }
        else {
          rv = CreateXtWindow();
        }
        if(NS_FAILED(rv))
          return NS_ERROR_FAILURE;
      }

      if(!mSocketWidget)
        return NS_ERROR_FAILURE;

      // Make sure to resize and re-place the window if required.
      // Need to reset "window" each time as nsObjectFrame::DidReflow sets it
      // to the ancestor window.
      if(GTK_IS_XTBIN(mSocketWidget)) {
        gtk_xtbin_resize(mSocketWidget, width, height);
        // Point the NPWindow structures window to the actual X window
        window = (nsPluginPort *)GTK_XTBIN(mSocketWidget)->xtwindow;
      }
      else { // XEmbed
        SetAllocation();
        window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));
      }
#ifdef DEBUG
      printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window);
#endif
    } // nsPluginWindowType_Window
    aPluginInstance->SetWindow(this);
  }
  else if (mPluginInstance)
    mPluginInstance->SetWindow(nsnull);

  SetPluginInstance(aPluginInstance);
  return NS_OK;
}
示例#6
0
nsresult nsPluginNativeWindowGtk::CreateXtWindow() {
    NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");

#ifdef DEBUG
    printf("About to create new xtbin of %i X %i from %p...\n",
           width, height, (void*)window);
#endif
    GdkDisplay *display = gdk_display_get_default();
    GdkWindow *gdkWindow = gdk_x11_window_lookup_for_display(display, GetWindow());
    mSocketWidget = gtk_xtbin_new(gdkWindow, 0);
    // Check to see if creating the xtbin failed for some reason.
    // if it did, we can't go any further.
    if (!mSocketWidget)
        return NS_ERROR_FAILURE;

    g_signal_connect(mSocketWidget, "destroy",
                     G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

    gtk_widget_set_size_request(mSocketWidget, width, height);

#ifdef DEBUG
    printf("About to show xtbin(%p)...\n", (void*)mSocketWidget);
    fflush(nullptr);
#endif
    gtk_widget_show(mSocketWidget);
#ifdef DEBUG
    printf("completed gtk_widget_show(%p)\n", (void*)mSocketWidget);
    fflush(nullptr);
#endif

    // Fill out the ws_info structure.
    GtkXtBin* xtbin = GTK_XTBIN(mSocketWidget);
    // The xtbin has its own Display structure.
    mWsInfo.display = xtbin->xtdisplay;
    mWsInfo.colormap = xtbin->xtclient.xtcolormap;
    mWsInfo.visual = xtbin->xtclient.xtvisual;
    mWsInfo.depth = xtbin->xtclient.xtdepth;
    // Leave mWsInfo.type = 0 - Who knows what this is meant to be?

    XFlush(mWsInfo.display);

    return NS_OK;
}
示例#7
0
static void
gtk_xtbin_unrealize (GtkWidget *object)
{
  GtkXtBin *xtbin;
  GtkWidget *widget;

#ifdef DEBUG_XTBIN
  printf("gtk_xtbin_unrealize()\n");
#endif

  /* gtk_object_destroy() will already hold a refcount on object
   */
  xtbin = GTK_XTBIN(object);
  widget = GTK_WIDGET(object);

  GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
  if (GTK_WIDGET_REALIZED (widget)) {
    xt_client_unrealize(&(xtbin->xtclient));
  }

  (*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget);
}
static void
gtk_xtbin_unrealize (GtkWidget *object)
{
  GtkXtBin *xtbin;
  GtkWidget *widget;

#ifdef DEBUG_XTBIN
  printf("gtk_xtbin_unrealize()\n");
#endif

  /* gtk_object_destroy() will already hold a refcount on object
   */
  xtbin = GTK_XTBIN(object);
  widget = GTK_WIDGET(object);

  gtk_widget_set_visible(widget, FALSE);
  if (gtk_widget_get_realized (widget)) {
    xt_client_unrealize(&(xtbin->xtclient));
  }

  (*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget);
}
示例#9
0
static void
gtk_xtbin_destroy (GtkObject *object)
{
  GtkXtBin *xtbin;

#ifdef DEBUG_XTBIN
  printf("gtk_xtbin_destroy()\n");
#endif

  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_XTBIN (object));

  xtbin = GTK_XTBIN (object);

  if(xtbin->xtwindow) {
    /* remove the event handler */
    xt_client_destroy(&(xtbin->xtclient));
    xtbin->xtwindow = 0;

    num_widgets--; /* reduce our usage count */

    /* If this is the last running widget, remove the Xt display
       connection from the mainloop */
    if (0 == num_widgets) {
#ifdef DEBUG_XTBIN
      printf("removing the Xt connection from the main loop\n");
#endif
      g_main_context_remove_poll((GMainContext*)NULL, &xt_event_poll_fd);
      g_source_remove(tag);

      gtk_timeout_remove(xt_polling_timer_id);
      xt_polling_timer_id = 0;
    }
  }

  GTK_OBJECT_CLASS(parent_class)->destroy(object);
}
示例#10
0
nsresult nsPluginNativeWindowGtk::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance)
{
    if (aPluginInstance) {
        if (type == NPWindowTypeWindow) {
            if (!mSocketWidget) {
                nsresult rv;

                // The documentation on the types for many variables in NP(N|P)_GetValue
                // is vague.  Often boolean values are NPBool (1 byte), but
                // https://developer.mozilla.org/en/XEmbed_Extension_for_Mozilla_Plugins
                // treats NPPVpluginNeedsXEmbed as PRBool (int), and
                // on x86/32-bit, flash stores to this using |movl 0x1,&needsXEmbed|.
                // thus we can't use NPBool for needsXEmbed, or the three bytes above
                // it on the stack would get clobbered. so protect with the larger bool.
                int needsXEmbed = 0;
                rv = aPluginInstance->GetValueFromPlugin(NPPVpluginNeedsXEmbed, &needsXEmbed);
                // If the call returned an error code make sure we still use our default value.
                if (NS_FAILED(rv)) {
                    needsXEmbed = 0;
                }
#ifdef DEBUG
                printf("nsPluginNativeWindowGtk: NPPVpluginNeedsXEmbed=%d\n", needsXEmbed);
#endif

                bool isOOPPlugin = aPluginInstance->GetPlugin()->GetLibrary()->IsOOP();
                if (needsXEmbed || isOOPPlugin) {
                    bool enableXtFocus = !needsXEmbed;
                    rv = CreateXEmbedWindow(enableXtFocus);
                }
                else {
#if (MOZ_WIDGET_GTK == 2)
                    rv = CreateXtWindow();
#else
                    return NS_ERROR_FAILURE;
#endif
                }

                if (NS_FAILED(rv)) {
                    return NS_ERROR_FAILURE;
                }
            }

            if (!mSocketWidget) {
                return NS_ERROR_FAILURE;
            }

            // Make sure to resize and re-place the window if required.
            SetAllocation();
            // Need to reset "window" each time as nsPluginFrame::DidReflow sets it
            // to the ancestor window.
#if (MOZ_WIDGET_GTK == 2)
            if (GTK_IS_XTBIN(mSocketWidget)) {
                // Point the NPWindow structures window to the actual X window
                SetWindow(GTK_XTBIN(mSocketWidget)->xtwindow);
            }
            else { // XEmbed or OOP&Xt
                SetWindow(gtk_socket_get_id(GTK_SOCKET(mSocketWidget)));
            }
#else
            // Gtk3 supports only OOP by GtkSocket
            SetWindow(gtk_socket_get_id(GTK_SOCKET(mSocketWidget)));
#endif

#ifdef DEBUG
            printf("nsPluginNativeWindowGtk: call SetWindow with xid=%p\n", (void *)window);
#endif
        } // NPWindowTypeWindow
        aPluginInstance->SetWindow(this);
    }
    else if (mPluginInstance)
        mPluginInstance->SetWindow(nullptr);

    SetPluginInstance(aPluginInstance);
    return NS_OK;
}
示例#11
0
void PluginView::setNPWindowIfNeeded()
{
    if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow)
        return;

    // If the plugin didn't load sucessfully, no point in calling setwindow
    if (m_status != PluginStatusLoadedSuccessfully)
        return;

    // On Unix, only call plugin's setwindow if it's full-page or windowed
    if (m_mode != NP_FULL && m_mode != NP_EMBED)
        return;

    // Check if the platformPluginWidget still exists
    if (m_isWindowed && !platformPluginWidget())
        return;

    if (m_clipRect.isEmpty()) {
        // If width or height are null, set the clipRect to null,
        // indicating that the plugin is not visible/scrolled out.
        m_npWindow.clipRect.left = 0;
        m_npWindow.clipRect.right = 0;
        m_npWindow.clipRect.top = 0;
        m_npWindow.clipRect.bottom = 0;
    } else {
        // Clipping rectangle of the plug-in; the origin is the top left corner of the drawable or window. 
        m_npWindow.clipRect.left = m_npWindow.x + m_clipRect.x();
        m_npWindow.clipRect.top = m_npWindow.y + m_clipRect.y();
        m_npWindow.clipRect.right = m_npWindow.x + m_clipRect.x() + m_clipRect.width();
        m_npWindow.clipRect.bottom = m_npWindow.y + m_clipRect.y() + m_clipRect.height();
    }

    // FLASH WORKAROUND: Only set initially. Multiple calls to
    // setNPWindow() cause the plugin to crash in windowed mode.
    if (!m_plugin->quirks().contains(PluginQuirkDontCallSetWindowMoreThanOnce) || !m_isWindowed
        || m_npWindow.width == static_cast<uint32_t>(-1) || m_npWindow.height == static_cast<uint32_t>(-1)) {
        m_npWindow.width = m_windowRect.width();
        m_npWindow.height = m_windowRect.height();
    }

    PluginView::setCurrentPluginView(this);
    JSC::JSLock::DropAllLocks dropAllLocks(JSDOMWindowBase::commonVM());
    setCallingPlugin(true);
    m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);
    setCallingPlugin(false);
    PluginView::setCurrentPluginView(0);

    if (!m_isWindowed)
        return;

#if PLATFORM(GTK)
    // GtkXtBin will call gtk_widget_size_allocate, so we don't need to do it here.
    if (!m_needsXEmbed) {
        gtk_xtbin_set_position(GTK_XTBIN(platformPluginWidget()), m_windowRect.x(), m_windowRect.y());
        gtk_xtbin_resize(platformPluginWidget(), m_windowRect.width(), m_windowRect.height());
        return;
    }

    m_delayedAllocation = m_windowRect;
    updateWidgetAllocationAndClip();
#endif
}