Class GeckoDisplay

Object
org.mozilla.geckoview.GeckoDisplay

public class GeckoDisplay extends Object
Applications use a GeckoDisplay instance to provide GeckoSession with a Surface for displaying content. To ensure drawing only happens on a valid Surface, GeckoSession will only use the provided Surface after surfaceChanged(SurfaceInfo) is called and before surfaceDestroyed() returns.
  • Constructor Details

    • GeckoDisplay

      protected GeckoDisplay(GeckoSession session)
  • Method Details

    • surfaceChanged

      @UiThread public void surfaceChanged(@NonNull GeckoDisplay.SurfaceInfo surfaceInfo)
      Sets a surface for the compositor render a surface.

      Required call. The display's Surface has been created or changed. Must be called on the application main thread. GeckoSession may block this call to ensure the Surface is valid while resuming drawing.

      If rendering in to a SurfaceView on SDK level 29 or above, please ensure that the SurfaceControl field of the GeckoDisplay.SurfaceInfo object is set.

      Parameters:
      surfaceInfo - Information about the new Surface.
    • surfaceDestroyed

      @UiThread public void surfaceDestroyed()
      Removes the current surface registered with the compositor.

      Required call. The display's Surface has been destroyed. Must be called on the application main thread. GeckoSession may block this call to ensure the Surface is valid while pausing drawing.

    • screenOriginChanged

      @UiThread public void screenOriginChanged(int left, int top)
      Update the position of the surface on the screen.

      Optional call. The display's coordinates on the screen has changed. Must be called on the application main thread.

      Parameters:
      left - The X coordinate of the display on the screen, in screen pixels.
      top - The Y coordinate of the display on the screen, in screen pixels.
    • safeAreaInsetsChanged

      @UiThread public void safeAreaInsetsChanged(int top, int right, int bottom, int left)
      Update the safe area insets of the surface on the screen.
      Parameters:
      left - left margin of safe area
      top - top margin of safe area
      right - right margin of safe area
      bottom - bottom margin of safe area
    • setDynamicToolbarMaxHeight

      @UiThread public void setDynamicToolbarMaxHeight(int height)
      Set the maximum height of the dynamic toolbar(s).

      If the toolbar is dynamic, this function needs to be called with the maximum possible toolbar height so that Gecko can make the ICB static even during the dynamic toolbar height is being changed.

      Parameters:
      height - The maximum height of the dynamic toolbar(s).
    • setVerticalClipping

      @UiThread public void setVerticalClipping(int clippingHeight)
      Update the amount of vertical space that is clipped or visibly obscured in the bottom portion of the display. Tells gecko where to put bottom fixed elements so they are fully visible.

      Optional call. The display's visible vertical space has changed. Must be called on the application main thread.

      Parameters:
      clippingHeight - The height of the bottom clipped space in screen pixels.
    • shouldPinOnScreen

      @UiThread public boolean shouldPinOnScreen()
      Return whether the display should be pinned on the screen.

      When pinned, the display should not be moved on the screen due to animation, scrolling, etc. A common reason for the display being pinned is when the user is dragging a selection caret inside the display; normal user interaction would be disrupted in that case if the display was moved on screen.

      Returns:
      True if display should be pinned on the screen.
    • capturePixels

      @UiThread @NonNull public GeckoResult<Bitmap> capturePixels()
      Request a Bitmap of the visible portion of the web page currently being rendered.

      Returned Bitmap will have the same dimensions as the Surface the GeckoDisplay is currently using.

      If the GeckoSession.isCompositorReady() is false the GeckoResult will complete with an IllegalStateException.

      This function must be called on the UI thread.

      Returns:
      A GeckoResult that completes with a Bitmap containing the pixels and size information of the currently visible rendered web page.
    • screenshot

      @UiThread @NonNull public GeckoDisplay.ScreenshotBuilder screenshot()
      Creates a new screenshot builder.
      Returns:
      The new GeckoDisplay.ScreenshotBuilder