Class GeckoView

All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewManager, ViewParent, GeckoDisplay.NewSurfaceProvider

@UiThread public class GeckoView extends FrameLayout implements GeckoDisplay.NewSurfaceProvider
  • Field Details

    • mDisplay

      @NonNull protected final org.mozilla.geckoview.GeckoView.Display mDisplay
    • mSession

      @Nullable protected GeckoSession mSession
    • BACKEND_SURFACE_VIEW

      public static final int BACKEND_SURFACE_VIEW
      This GeckoView instance will be backed by a SurfaceView.

      This option offers the best performance at the price of not being able to animate GeckoView.

      See Also:
    • BACKEND_TEXTURE_VIEW

      public static final int BACKEND_TEXTURE_VIEW
      This GeckoView instance will be backed by a TextureView.

      This option offers worse performance compared to BACKEND_SURFACE_VIEW but allows you to animate GeckoView or to paint a GeckoView on top of another GeckoView.

      See Also:
  • Constructor Details

  • Method Details

    • coverUntilFirstPaint

      public void coverUntilFirstPaint(int color)
      Set a color to cover the display surface while a document is being shown. The color is automatically cleared once the new document starts painting.
      Parameters:
      color - Cover color.
    • setViewBackend

      public void setViewBackend(int backend)
      Set which view should be used by this GeckoView instance to display content.

      By default, GeckoView will use a SurfaceView.

      Parameters:
      backend - Any of BACKEND_*.
    • shouldPinOnScreen

      public boolean shouldPinOnScreen()
      Return whether the view should be pinned on the screen. When pinned, the view should not be moved on the screen due to animation, scrolling, etc. A common reason for the view being pinned is when the user is dragging a selection caret inside the view; normal user interaction would be disrupted in that case if the view was moved on screen.
      Returns:
      True if view should be pinned on the screen.
    • setVerticalClipping

      public void setVerticalClipping(int clippingHeight)
      Update the amount of vertical space that is clipped or visibly obscured in the bottom portion of the view. 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.
    • setDynamicToolbarMaxHeight

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

      If there are two or more dynamic toolbars, the height value should be the total amount of the height of each dynamic toolbar.

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

      @UiThread @Nullable public GeckoSession releaseSession()
      Unsets the current session from this instance and returns it, if any. You must call this before setSession(GeckoSession) if there is already an open session set for this instance.

      Note: this method does not close the session and the session remains active. The caller is responsible for calling GeckoSession.close() when appropriate.

      Returns:
      The GeckoSession that was set for this instance. May be null.
    • setSession

      @UiThread public void setSession(@NonNull GeckoSession session)
      Attach a session to this view. If this instance already has an open session, you must use releaseSession() first, otherwise IllegalStateException will be thrown. This is to avoid potentially leaking the currently opened session.
      Parameters:
      session - The session to be attached.
      Throws:
      IllegalArgumentException - if an existing open session is already set.
    • getSession

      @AnyThread @Nullable public GeckoSession getSession()
    • getPanZoomController

      @NonNull public PanZoomController getPanZoomController()
    • onAttachedToWindow

      public void onAttachedToWindow()
      Overrides:
      onAttachedToWindow in class ViewGroup
    • onDetachedFromWindow

      public void onDetachedFromWindow()
      Overrides:
      onDetachedFromWindow in class ViewGroup
    • onConfigurationChanged

      protected void onConfigurationChanged(Configuration newConfig)
      Overrides:
      onConfigurationChanged in class View
    • gatherTransparentRegion

      public boolean gatherTransparentRegion(Region region)
      Overrides:
      gatherTransparentRegion in class ViewGroup
    • onWindowFocusChanged

      public void onWindowFocusChanged(boolean hasWindowFocus)
      Overrides:
      onWindowFocusChanged in class View
    • onWindowVisibilityChanged

      protected void onWindowVisibilityChanged(int visibility)
      Overrides:
      onWindowVisibilityChanged in class View
    • onFocusChanged

      protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
      Overrides:
      onFocusChanged in class View
    • getHandler

      public Handler getHandler()
      Overrides:
      getHandler in class View
    • onCreateInputConnection

      public InputConnection onCreateInputConnection(EditorInfo outAttrs)
      Overrides:
      onCreateInputConnection in class View
    • onKeyPreIme

      public boolean onKeyPreIme(int keyCode, KeyEvent event)
      Overrides:
      onKeyPreIme in class View
    • onKeyUp

      public boolean onKeyUp(int keyCode, KeyEvent event)
      Specified by:
      onKeyUp in interface KeyEvent.Callback
      Overrides:
      onKeyUp in class View
    • onKeyDown

      public boolean onKeyDown(int keyCode, KeyEvent event)
      Specified by:
      onKeyDown in interface KeyEvent.Callback
      Overrides:
      onKeyDown in class View
    • onKeyLongPress

      public boolean onKeyLongPress(int keyCode, KeyEvent event)
      Specified by:
      onKeyLongPress in interface KeyEvent.Callback
      Overrides:
      onKeyLongPress in class View
    • onKeyMultiple

      public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
      Specified by:
      onKeyMultiple in interface KeyEvent.Callback
      Overrides:
      onKeyMultiple in class View
    • dispatchDraw

      public void dispatchDraw(@Nullable Canvas canvas)
      Overrides:
      dispatchDraw in class ViewGroup
    • onTouchEvent

      public boolean onTouchEvent(MotionEvent event)
      Overrides:
      onTouchEvent in class View
    • onTouchEventForDetailResult

      @NonNull public GeckoResult<PanZoomController.InputResultDetail> onTouchEventForDetailResult(@NonNull MotionEvent event)
      Dispatches a MotionEvent to the PanZoomController. This is the same as onTouchEvent(MotionEvent), but instead returns a PanZoomController.InputResult indicating how the event was handled.

      NOTE: It is highly recommended to only call this with ACTION_DOWN or in otherwise limited capacity. Returning a GeckoResult for every touch event will generate a lot of allocations and unnecessary GC pressure.

      Parameters:
      event - A MotionEvent
      Returns:
      A GeckoResult resolving to PanZoomController.InputResultDetail.
    • onGenericMotionEvent

      public boolean onGenericMotionEvent(MotionEvent event)
      Overrides:
      onGenericMotionEvent in class View
    • onProvideAutofillVirtualStructure

      public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags)
      Overrides:
      onProvideAutofillVirtualStructure in class View
    • autofill

      public void autofill(@NonNull SparseArray<AutofillValue> values)
      Overrides:
      autofill in class View
    • isVisibleToUserForAutofill

      public boolean isVisibleToUserForAutofill(int virtualId)
      Overrides:
      isVisibleToUserForAutofill in class View
    • capturePixels

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

      See GeckoDisplay.capturePixels() for more details.

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

      public void setAutofillEnabled(boolean enabled)
      Sets whether or not this View participates in Android autofill.

      When enabled, this will set an Autofill.Delegate on the GeckoSession for this instance.

      Parameters:
      enabled - Whether or not Android autofill is enabled for this view.
    • getAutofillEnabled

      public boolean getAutofillEnabled()
      Returns:
      Whether or not Android autofill is enabled for this view.
    • setActivityContextDelegate

      public void setActivityContextDelegate(@Nullable GeckoView.ActivityContextDelegate delegate)
      Sets the delegate for the GeckoView.
      Parameters:
      delegate - to provide activity context or null
    • getActivityContextDelegate

      @Nullable public GeckoView.ActivityContextDelegate getActivityContextDelegate()
      Gets the delegate from the GeckoView.
      Returns:
      delegate, if set
    • getPrintDelegate

      @Nullable public GeckoSession.PrintDelegate getPrintDelegate()
      Retrieves the GeckoView's print delegate.
      Returns:
      The GeckoView's print delegate.
    • getPrintDelegate

      public void getPrintDelegate(@Nullable GeckoSession.PrintDelegate delegate)
      Sets the GeckoView's print delegate.
      Parameters:
      delegate - for printing
    • requestNewSurface

      public void requestNewSurface()
      Description copied from interface: GeckoDisplay.NewSurfaceProvider
      Called by Gecko to request a new Surface from the application.

      Occasionally the Surface provided to Gecko via GeckoDisplay.surfaceChanged(SurfaceInfo) is invalid and Gecko is unable to render in to it. This function will be called in such circumstances. It is the implementation's responsibility to ensure that GeckoDisplay.surfaceChanged(SurfaceInfo) gets called soon afterwards with a new Surface, allowing Gecko to resume rendering.

      Failure to implement this function may result in Gecko either crashing or not rendering correctly should it encounter an invalid Surface.

      Specified by:
      requestNewSurface in interface GeckoDisplay.NewSurfaceProvider
    • onDragEvent

      public boolean onDragEvent(DragEvent event)
      Handle drag and drop event
      Overrides:
      onDragEvent in class View