Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends

nsDisplayItem Class Reference

This is the unit of rendering and event testing. More...

#include <nsDisplayList.h>

Inheritance diagram for nsDisplayItem:
Collaboration diagram for nsDisplayItem:

List of all members.

Classes

struct  HitTestState

Public Types

enum  Type {
  TYPE_ALT_FEEDBACK = 1, TYPE_BACKGROUND, TYPE_BORDER, TYPE_BOX_SHADOW_OUTER,
  TYPE_BOX_SHADOW_INNER, TYPE_BULLET, TYPE_BUTTON_BORDER_BACKGROUND, TYPE_BUTTON_BOX_SHADOW_OUTER,
  TYPE_BUTTON_FOREGROUND, TYPE_CANVAS, TYPE_CANVAS_BACKGROUND, TYPE_CANVAS_FOCUS,
  TYPE_CARET, TYPE_CHECKED_CHECKBOX, TYPE_CHECKED_RADIOBUTTON, TYPE_CLIP,
  TYPE_CLIP_ROUNDED_RECT, TYPE_COLUMN_RULE, TYPE_COMBOBOX_FOCUS, TYPE_EVENT_RECEIVER,
  TYPE_FIELDSET_BORDER_BACKGROUND, TYPE_FRAMESET_BORDER, TYPE_FRAMESET_BLANK, TYPE_HEADER_FOOTER,
  TYPE_IMAGE, TYPE_LIST_FOCUS, TYPE_OPACITY, TYPE_OPTION_EVENT_GRABBER,
  TYPE_OUTLINE, TYPE_OWN_LAYER, TYPE_PAGE_CONTENT, TYPE_PAGE_SEQUENCE,
  TYPE_PLUGIN, TYPE_PRINT_PREVIEW_BACKGROUND, TYPE_PRINT_PLUGIN, TYPE_REMOTE,
  TYPE_REMOTE_SHADOW, TYPE_SCROLL_LAYER, TYPE_SELECTION_OVERLAY, TYPE_SOLID_COLOR,
  TYPE_TABLE_CELL_BACKGROUND, TYPE_TABLE_CELL_SELECTION, TYPE_TABLE_ROW_BACKGROUND, TYPE_TABLE_ROW_GROUP_BACKGROUND,
  TYPE_TABLE_BORDER_BACKGROUND, TYPE_TEXT, TYPE_TEXT_DECORATION, TYPE_TEXT_SHADOW,
  TYPE_TRANSFORM, TYPE_VIDEO, TYPE_WRAP_LIST, TYPE_ZOOM,
  TYPE_MAX
}
 

It's useful to be able to dynamically check the type of certain items.

More...
enum  { TYPE_BITS = 8 }
typedef
mozilla::layers::FrameMetrics::ViewID 
ViewID
typedef mozilla::layers::Layer Layer
typedef
mozilla::layers::LayerManager 
LayerManager
typedef mozilla::LayerState LayerState

Public Member Functions

 nsDisplayItem (nsDisplayListBuilder *aBuilder, nsIFrame *aFrame)
virtual ~nsDisplayItem ()
void * operator new (size_t aSize, nsDisplayListBuilder *aBuilder) throw ()
virtual Type GetType ()=0
 Some consecutive items should be rendered together as a unit, e.g., outlines for the same element.
virtual PRUint32 GetPerFrameKey ()
 If this returns a non-zero value, then pairing this with the GetUnderlyingFrame() pointer gives a key that uniquely identifies this display item in the display item tree.
virtual void HitTest (nsDisplayListBuilder *aBuilder, const nsRect &aRect, HitTestState *aState, nsTArray< nsIFrame * > *aOutFrames)
 This is called after we've constructed a display list for event handling.
nsIFrame * GetUnderlyingFrame ()
virtual nsRect GetBounds (nsDisplayListBuilder *aBuilder)
 The default bounds is the frame border rect.
virtual nsRegion GetOpaqueRegion (nsDisplayListBuilder *aBuilder, PRBool *aForceTransparentSurface=0L)
virtual PRBool IsUniform (nsDisplayListBuilder *aBuilder, nscolor *aColor)
 If this returns true, then aColor is set to the uniform color.
virtual PRBool IsVaryingRelativeToMovingFrame (nsDisplayListBuilder *aBuilder, nsIFrame *aFrame)
virtual PRBool IsFixedAndCoveringViewport (nsDisplayListBuilder *aBuilder)
virtual LayerState GetLayerState (nsDisplayListBuilder *aBuilder, LayerManager *aManager)
virtual void Paint (nsDisplayListBuilder *aBuilder, nsIRenderingContext *aCtx)
 Actually paint this item to some rendering context.
virtual already_AddRefed< LayerBuildLayer (nsDisplayListBuilder *aBuilder, LayerManager *aManager)
 Get the layer drawn by this display item.
virtual PRBool ComputeVisibility (nsDisplayListBuilder *aBuilder, nsRegion *aVisibleRegion)
 On entry, aVisibleRegion contains the region (relative to ReferenceFrame()) which may be visible.
virtual PRBool TryMerge (nsDisplayListBuilder *aBuilder, nsDisplayItem *aItem)
 Try to merge with the other item (which is below us in the display list).
virtual nsDisplayListGetList ()
 If this is a leaf item we return null, otherwise we return the wrapped list.
const nsRectGetVisibleRect ()
 Returns the visible rect.
nsDisplayItemGetAbove ()
PRBool RecomputeVisibility (nsDisplayListBuilder *aBuilder, nsRegion *aVisibleRegion)
 Like ComputeVisibility, but does the work that nsDisplayList does per-item: -- Intersects GetBounds with aVisibleRegion and puts the result in mVisibleRect -- Subtracts bounds from aVisibleRegion if the item is opaque.
const nsPointToReferenceFrame ()
 Returns the result of aBuilder->ToReferenceFrame(GetUnderlyingFrame()).
virtual nsRect GetComponentAlphaBounds (nsDisplayListBuilder *aBuilder)
 Checks if this display item (or any children) contains content that might be rendered with component alpha (e.g.
virtual void DisableComponentAlpha ()
 Disable usage of component alpha.

Protected Member Functions

 nsDisplayItem ()

Protected Attributes

nsIFrame * mFrame
nsPoint mToReferenceFrame
nsRect mVisibleRect

Friends

class nsDisplayList

Detailed Description

This is the unit of rendering and event testing.

Each instance of this class represents an entity that can be drawn on the screen, e.g., a frame's CSS background, or a frame's text string.

nsDisplayListItems can be containers --- i.e., they can perform hit testing and painting by recursively traversing a list of child items.

These are arena-allocated during display list construction. A typical subclass would just have a frame pointer, so its object would be just three pointers (vtable, next-item, frame).

Display items belong to a list at all times (except temporarily as they move from one list to another).


Member Typedef Documentation


Member Enumeration Documentation

anonymous enum
Enumerator:
TYPE_BITS 

It's useful to be able to dynamically check the type of certain items.

Every subclass of nsDisplayItem must have a new type added here for the purposes of easy comparison and matching of items in different display lists.

This is included inside nsDisplayItem.

Enumerator:
TYPE_ALT_FEEDBACK 
TYPE_BACKGROUND 
TYPE_BORDER 
TYPE_BOX_SHADOW_OUTER 
TYPE_BOX_SHADOW_INNER 
TYPE_BULLET 
TYPE_BUTTON_BORDER_BACKGROUND 
TYPE_BUTTON_BOX_SHADOW_OUTER 
TYPE_BUTTON_FOREGROUND 
TYPE_CANVAS 
TYPE_CANVAS_BACKGROUND 
TYPE_CANVAS_FOCUS 
TYPE_CARET 
TYPE_CHECKED_CHECKBOX 
TYPE_CHECKED_RADIOBUTTON 
TYPE_CLIP 
TYPE_CLIP_ROUNDED_RECT 
TYPE_COLUMN_RULE 
TYPE_COMBOBOX_FOCUS 
TYPE_EVENT_RECEIVER 
TYPE_FIELDSET_BORDER_BACKGROUND 
TYPE_FRAMESET_BORDER 
TYPE_FRAMESET_BLANK 
TYPE_HEADER_FOOTER 
TYPE_IMAGE 
TYPE_LIST_FOCUS 
TYPE_OPACITY 
TYPE_OPTION_EVENT_GRABBER 
TYPE_OUTLINE 
TYPE_OWN_LAYER 
TYPE_PAGE_CONTENT 
TYPE_PAGE_SEQUENCE 
TYPE_PLUGIN 
TYPE_PRINT_PREVIEW_BACKGROUND 
TYPE_PRINT_PLUGIN 
TYPE_REMOTE 
TYPE_REMOTE_SHADOW 
TYPE_SCROLL_LAYER 
TYPE_SELECTION_OVERLAY 
TYPE_SOLID_COLOR 
TYPE_TABLE_CELL_BACKGROUND 
TYPE_TABLE_CELL_SELECTION 
TYPE_TABLE_ROW_BACKGROUND 
TYPE_TABLE_ROW_GROUP_BACKGROUND 
TYPE_TABLE_BORDER_BACKGROUND 
TYPE_TEXT 
TYPE_TEXT_DECORATION 
TYPE_TEXT_SHADOW 
TYPE_TRANSFORM 
TYPE_VIDEO 
TYPE_WRAP_LIST 
TYPE_ZOOM 
TYPE_MAX 

Constructor & Destructor Documentation

nsDisplayItem::nsDisplayItem ( nsDisplayListBuilder aBuilder,
nsIFrame *  aFrame 
) [inline]
virtual nsDisplayItem::~nsDisplayItem (  )  [inline, virtual]
nsDisplayItem::nsDisplayItem (  )  [inline, protected]

Member Function Documentation

virtual already_AddRefed<Layer> nsDisplayItem::BuildLayer ( nsDisplayListBuilder aBuilder,
LayerManager aManager 
) [inline, virtual]

Get the layer drawn by this display item.

Call this only if GetLayerState() returns something other than LAYER_NONE. If GetLayerState returned LAYER_NONE then Paint will be called instead. This is called while aManager is in the construction phase.

The caller (nsDisplayList) is responsible for setting the visible region of the layer.

Reimplemented in nsDisplayRemote, nsDisplayOpacity, nsDisplayOwnLayer, and nsDisplayTransform.

virtual PRBool nsDisplayItem::ComputeVisibility ( nsDisplayListBuilder aBuilder,
nsRegion aVisibleRegion 
) [inline, virtual]

On entry, aVisibleRegion contains the region (relative to ReferenceFrame()) which may be visible.

If the display item opaquely covers an area, it can remove that area from aVisibleRegion before returning. nsDisplayList::ComputeVisibility automatically subtracts the region returned by GetOpaqueRegion, and automatically removes items whose bounds do not intersect the visible area, so implementations of nsDisplayItem::ComputeVisibility do not need to do these things. nsDisplayList::ComputeVisibility will already have set mVisibleRect on this item to the intersection of *aVisibleRegion and this item's bounds. We rely on that, so this should only be called by nsDisplayList::ComputeVisibility or nsDisplayItem::RecomputeVisibility.

Returns:
PR_TRUE if the item is visible, PR_FALSE if no part of the item is visible

Reimplemented in nsDisplayCanvasBackground, nsDisplayBorder, nsDisplayBackground, nsDisplayBoxShadowOuter, nsDisplayBoxShadowInner, nsDisplayOutline, nsDisplayWrapList, nsDisplayOpacity, nsDisplayClip, nsDisplayClipRoundedRect, nsDisplayZoom, and nsDisplayTransform.

virtual void nsDisplayItem::DisableComponentAlpha (  )  [inline, virtual]

Disable usage of component alpha.

Currently only relevant for items that have text.

nsDisplayItem* nsDisplayItem::GetAbove (  )  [inline]
virtual nsRect nsDisplayItem::GetBounds ( nsDisplayListBuilder aBuilder  )  [inline, virtual]

The default bounds is the frame border rect.

Returns:
a rectangle relative to aBuilder->ReferenceFrame() that contains the area drawn by this display item

Reimplemented in nsDisplayRemoteShadow, nsDisplayCanvasBackground, nsDisplayCaret, nsDisplayBorder, nsDisplaySolidColor, nsDisplayBackground, nsDisplayBoxShadowOuter, nsDisplayOutline, nsDisplayWrapList, nsDisplayClip, nsDisplayZoom, and nsDisplayTransform.

virtual nsRect nsDisplayItem::GetComponentAlphaBounds ( nsDisplayListBuilder aBuilder  )  [inline, virtual]

Checks if this display item (or any children) contains content that might be rendered with component alpha (e.g.

subpixel antialiasing). Returns the bounds of the area that needs component alpha, or an empty rect if nothing in the item does.

Reimplemented in nsDisplayGeneric, nsDisplayWrapList, and nsDisplayTransform.

virtual LayerState nsDisplayItem::GetLayerState ( nsDisplayListBuilder aBuilder,
LayerManager aManager 
) [inline, virtual]
Returns:
LAYER_NONE if BuildLayer will return null. In this case there is no layer for the item, and Paint should be called instead to paint the content using Thebes. Return LAYER_INACTIVE if there is a layer --- BuildLayer will not return null (unless there's an error) --- but the layer contents are not changing frequently. In this case it makes sense to composite the layer into a ThebesLayer with other content, so we don't have to recomposite it every time we paint. Note: GetLayerState is only allowed to return LAYER_INACTIVE if all descendant display items returned LAYER_INACTIVE or LAYER_NONE. Also, all descendant display item frames must have an active scrolled root that's either the same as this item's frame's active scrolled root, or a descendant of this item's frame. This ensures that the entire set of display items can be collapsed onto a single ThebesLayer. Return LAYER_ACTIVE if the layer is active, that is, its contents are changing frequently. In this case it makes sense to keep the layer as a separate buffer in VRAM and composite it into the destination every time we paint.

Reimplemented in nsDisplayRemote, nsDisplayOpacity, nsDisplayOwnLayer, and nsDisplayTransform.

virtual nsDisplayList* nsDisplayItem::GetList (  )  [inline, virtual]

If this is a leaf item we return null, otherwise we return the wrapped list.

Reimplemented in nsDisplayWrapList.

virtual nsRegion nsDisplayItem::GetOpaqueRegion ( nsDisplayListBuilder aBuilder,
PRBool aForceTransparentSurface = 0L 
) [inline, virtual]
Returns:
a region of the item that is opaque --- every pixel painted with an opaque color.

Reimplemented in nsDisplayCanvasBackground, nsDisplaySolidColor, nsDisplayBackground, nsDisplayWrapList, nsDisplayOpacity, nsDisplayClipRoundedRect, and nsDisplayTransform.

virtual PRUint32 nsDisplayItem::GetPerFrameKey (  )  [inline, virtual]

If this returns a non-zero value, then pairing this with the GetUnderlyingFrame() pointer gives a key that uniquely identifies this display item in the display item tree.

This will only return a zero value for items which wrap display lists and do not create a CSS stacking context, therefore requiring display items to be individually wrapped --- currently nsDisplayClip and nsDisplayClipRoundedRect only.

Reimplemented in nsDisplayRemoteShadow, and nsDisplayClip.

virtual Type nsDisplayItem::GetType (  )  [pure virtual]

Some consecutive items should be rendered together as a unit, e.g., outlines for the same element.

For this, we need a way for items to identify their type. We use the type for other purposes too.

Implemented in nsDisplayCanvasBackground, nsDisplayGeneric, nsDisplayCaret, nsDisplayBorder, nsDisplaySolidColor, nsDisplayBackground, nsDisplayBoxShadowOuter, nsDisplayBoxShadowInner, nsDisplayOutline, nsDisplayEventReceiver, nsDisplayWrapList, nsDisplayOpacity, nsDisplayOwnLayer, nsDisplayClip, nsDisplayClipRoundedRect, nsDisplayZoom, and nsDisplayTransform.

nsIFrame* nsDisplayItem::GetUnderlyingFrame (  )  [inline]
Returns:
the frame that this display item is based on. This is used to sort items by z-index and content order and for some other uses. For some items that wrap item lists, this could return nsnull because there is no single underlying frame; for leaf items it will never return nsnull.
const nsRect& nsDisplayItem::GetVisibleRect (  )  [inline]

Returns the visible rect.

Should only be called after ComputeVisibility has happened.

virtual void nsDisplayItem::HitTest ( nsDisplayListBuilder aBuilder,
const nsRect aRect,
HitTestState aState,
nsTArray< nsIFrame * > *  aOutFrames 
) [inline, virtual]

This is called after we've constructed a display list for event handling.

When this is called, we've already ensured that aRect intersects the item's bounds.

Parameters:
aState must point to a HitTestState. If you don't have one, just create one with the default constructor and pass it in.
aOutFrames each item appends the frame(s) in this display item that the rect is considered over (if any) to aOutFrames.

Reimplemented in nsDisplayRemoteShadow, nsDisplayCanvasBackground, nsDisplayBackground, nsDisplayEventReceiver, nsDisplayWrapList, nsDisplayClipRoundedRect, nsDisplayZoom, and nsDisplayTransform.

virtual PRBool nsDisplayItem::IsFixedAndCoveringViewport ( nsDisplayListBuilder aBuilder  )  [inline, virtual]
Returns:
PR_TRUE if the contents of this item are rendered fixed relative to the nearest viewport *and* they cover the viewport's scrollport. Only return true if the contents actually vary when scrolling in the viewport.

Reimplemented in nsDisplayBackground.

virtual PRBool nsDisplayItem::IsUniform ( nsDisplayListBuilder aBuilder,
nscolor aColor 
) [inline, virtual]

If this returns true, then aColor is set to the uniform color.

Returns:
PR_TRUE if the item is guaranteed to paint every pixel in its bounds with the same (possibly translucent) color

Reimplemented in nsDisplayCanvasBackground, nsDisplaySolidColor, nsDisplayBackground, nsDisplayWrapList, and nsDisplayTransform.

virtual PRBool nsDisplayItem::IsVaryingRelativeToMovingFrame ( nsDisplayListBuilder aBuilder,
nsIFrame *  aFrame 
) [inline, virtual]
Returns:
PR_FALSE if the painting performed by the item is invariant when the item's underlying frame is moved relative to aFrame. In other words, if you render the item at locations P and P', the rendering only differs by the translation. It return PR_TRUE for all wrapped lists.

Reimplemented in nsDisplayBackground, and nsDisplayWrapList.

void* nsDisplayItem::operator new ( size_t  aSize,
nsDisplayListBuilder aBuilder 
) throw () [inline]
virtual void nsDisplayItem::Paint ( nsDisplayListBuilder aBuilder,
nsIRenderingContext *  aCtx 
) [inline, virtual]

Actually paint this item to some rendering context.

Content outside mVisibleRect need not be painted. aCtx must be set up as for nsDisplayList::Paint.

Reimplemented in nsDisplayCanvasBackground, nsDisplayGeneric, nsDisplayCaret, nsDisplayBorder, nsDisplaySolidColor, nsDisplayBackground, nsDisplayBoxShadowOuter, nsDisplayBoxShadowInner, nsDisplayOutline, nsDisplayWrapList, nsDisplayClip, and nsDisplayZoom.

PRBool nsDisplayItem::RecomputeVisibility ( nsDisplayListBuilder aBuilder,
nsRegion aVisibleRegion 
)

Like ComputeVisibility, but does the work that nsDisplayList does per-item: -- Intersects GetBounds with aVisibleRegion and puts the result in mVisibleRect -- Subtracts bounds from aVisibleRegion if the item is opaque.

const nsPoint& nsDisplayItem::ToReferenceFrame (  )  [inline]

Returns the result of aBuilder->ToReferenceFrame(GetUnderlyingFrame()).

virtual PRBool nsDisplayItem::TryMerge ( nsDisplayListBuilder aBuilder,
nsDisplayItem aItem 
) [inline, virtual]

Try to merge with the other item (which is below us in the display list).

This gets used by nsDisplayClip to coalesce clipping operations (optimization), by nsDisplayOpacity to merge rendering for the same content element into a single opacity group (correctness), and will be used by nsDisplayOutline to merge multiple outlines for the same element (also for correctness).

Returns:
PR_TRUE if the merge was successful and the other item should be deleted

Reimplemented in nsDisplayWrapList, nsDisplayOpacity, nsDisplayOwnLayer, nsDisplayClip, nsDisplayClipRoundedRect, and nsDisplayTransform.


Friends And Related Function Documentation

friend class nsDisplayList [friend]

Reimplemented from nsDisplayItemLink.


Member Data Documentation

nsIFrame* nsDisplayItem::mFrame [protected]

The documentation for this class was generated from the following files: