Your Search Results

    Working with content views

    Mobile Only in Gecko 2.0
    Available only in Firefox Mobile as of Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

    In Gecko-based applications that use the Electrolysis multi-process framework (such as Firefox Mobile 4), frames each get rendered in their own process. To support this, the nsIFrameLoader interface, whose job it is to load and manage frames, uses content views for each child frame, passing events to the child views to ask them to perform desired tasks, such as scrolling and scaling.

    Note: Technically, it's possible to enable this in Firefox 4 on the desktop, but it's so far under the hood there that we're documenting it as if it's not available at all for now.

    How content views work

    To handle quickly scrolling and scaling content in web content, Gecko creates a displayport, which caches more pixels that are actually visible; this is done by calling nsIDOMWindowUtils.setDisplayPort(). Then, when the parent process wants to scroll, it modifies a view, which in turn simply translates the cached image. Then it sends a message to the content process to update the display port, so that new content is available in the displayport's cache based on the new scroll position.

    The view can also scale the image for fast zooming, and calls to nsIDOMWindowUtils.setResolution() can re-render content at that zoom level.

    Getting access to content views

    Since frames and overflowed <div>s can be scrolled, a document can have more than one content view. Every document has a root content view, which you can obtain from the nsIContentViewManager attribute rootContentManager; this is used for scrolling the entire document. In addition, each child frame has a content view.

    The nsIContentViewManager interface, which is subsumed by nsIFrameLoader when Electrolysis is available, provides access to the document's content views; use the nsIContentViewManager.getContentViewsIn() method. That method will return a list of the content views inside a specified rectangle in the browser.

    To obtain a reference to the view manager for a document, use code like this:

    /* get the browser */
    var browser = document.getElementById("content");
    /* get the frame loader for the browser */
    var frameLoader = browser.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader;
    /* get the view manager */
    var viewManager = frameLoader.QueryInterface(Components.interfaces.nsIContentViewManager);

    Once you have the view manager, you can call getContentViewsIn() to get a list of the content views for a given portion of the browser display, then use those nsIContentView objects to manipulate the content views.

    Using the content view

    Once you have access to a content view, you can use its methods to ask the view to scroll or scale. Calling these methods does not immediately make the change take effect; instead, it sets a target scaling factor and/or scroll position with respect to the current content view. The next time the content is painted, the scroll and scale attributes are used to set up a compensating transform. If the metrics of the content document's current pixels don't match the view configuration, the transform may need to translate content pixels and/or perform fuzzy scaling that doesn't re-rasterize fonts or intelligently resample images.

    For example:

    contentView.scrollBy(10.0, 10.0);

    This code sends a request to the content view, asking it to scroll by 10 pixels on each of the X and Y axes. The actual screen update will take place the next time the view gets repainted.

    The attributes can to transform content pixels in such a way that the browser's visible rectangle encloses pixels that the content document doesn't (yet) define.

    See also

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,