Ejemplo n.º 1
0
//
// DidSetStyleContext
//
// When the style context changes, make sure that all of our image is up to date.
//
/* virtual */ void
nsImageBoxFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
{
  nsLeafBoxFrame::DidSetStyleContext(aOldStyleContext);

  // Fetch our subrect.
  const nsStyleList* myList = GetStyleList();
  mSubRect = myList->mImageRegion; // before |mSuppressStyleCheck| test!

  if (mUseSrcAttr || mSuppressStyleCheck)
    return; // No more work required, since the image isn't specified by style.

  // If we're using a native theme implementation, we shouldn't draw anything.
  const nsStyleDisplay* disp = GetStyleDisplay();
  if (disp->mAppearance && nsBox::gTheme && 
      nsBox::gTheme->ThemeSupportsWidget(nsnull, this, disp->mAppearance))
    return;

  // If list-style-image changes, we have a new image.
  nsCOMPtr<nsIURI> oldURI, newURI;
  if (mImageRequest)
    mImageRequest->GetURI(getter_AddRefs(oldURI));
  if (myList->GetListStyleImage())
    myList->GetListStyleImage()->GetURI(getter_AddRefs(newURI));
  PRBool equal;
  if (newURI == oldURI ||   // handles null==null
      (newURI && oldURI &&
       NS_SUCCEEDED(newURI->Equals(oldURI, &equal)) && equal))
    return;

  UpdateImage();
} // DidSetStyleContext
Ejemplo n.º 2
0
void
nsImageBoxFrame::UpdateImage()
{
  if (mImageRequest) {
    mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
    mImageRequest = nsnull;
  }

  // get the new image src
  nsAutoString src;
  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src);
  mUseSrcAttr = !src.IsEmpty();
  if (mUseSrcAttr) {
    nsIDocument* doc = mContent->GetDocument();
    if (!doc) {
      // No need to do anything here...
      return;
    }
    nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
    nsCOMPtr<nsIURI> uri;
    nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
                                              src,
                                              doc,
                                              baseURI);

    if (uri && nsContentUtils::CanLoadImage(uri, mContent, doc,
                                            mContent->NodePrincipal())) {
      nsContentUtils::LoadImage(uri, doc, mContent->NodePrincipal(),
                                doc->GetDocumentURI(), mListener, mLoadFlags,
                                getter_AddRefs(mImageRequest));
    }
  } else {
    // Only get the list-style-image if we aren't being drawn
    // by a native theme.
    PRUint8 appearance = GetStyleDisplay()->mAppearance;
    if (!(appearance && nsBox::gTheme && 
          nsBox::gTheme->ThemeSupportsWidget(nsnull, this, appearance))) {
      // get the list-style-image
      imgIRequest *styleRequest = GetStyleList()->GetListStyleImage();
      if (styleRequest) {
        styleRequest->Clone(mListener, getter_AddRefs(mImageRequest));
      }
    }
  }

  if (!mImageRequest) {
    // We have no image, so size to 0
    mIntrinsicSize.SizeTo(0, 0);
  } else {
    // We don't want discarding or decode-on-draw for xul images.
    mImageRequest->RequestDecode();
    mImageRequest->LockImage();
  }
}
Ejemplo n.º 3
0
ChEXPORT void WrdStyleSheet::resolve(WrdCharacterProperties& io_charProps, ChUINT2 in_unParagraphStyleIndex) const
{
    ChUINT2 unStyleIndex = in_unParagraphStyleIndex;

	// If the character properties does have the style descriptor overridden,
	// use that one first.	
    if (io_charProps.isStyleIndexOverridden())
    {
    	unStyleIndex = io_charProps.getStyleIndex();
    
        // Design-wise, a more elegant solution is to access the first base style,
        // and then apply the derived style's properties on top of the base style,
        // and recursively do this, until lastly, the delta character properties 
        // are applied. However, to do this elegantly requires using recursion,
        // and also requires the creation of an additional WrdCharacterProperties 
        // structure which contains the base style and the derived style's
        // merged results. Given the need to minimize stack usage and heap memory,
        // the alternative is to traverse the style's backwards and apply all 
        // changes directly to the delta set of properties. Thus, we get the style
        // that the delta references, apply its properties, then get the
        // base style, and apply its properties, and go upwards to the top-most
        // style.
        do
        {
            const WrdStyle&               style = getStyle(unStyleIndex);
            const WrdCharacterProperties& styleCharProps = style.getResolvedCharProps();

            if (io_charProps.getUseParagraphStylesProperties())
            {
                // If the character properties' says to use the paragraph style's
                // properties, then we can ignore all the different overrides
                // currently set, and take the style's character properties instead.
                // The only thing that is preserved should be the special character.
                ChUINT2 unSpecialCharacter = io_charProps.getSpecialCharacter();
                io_charProps = styleCharProps;
                io_charProps.setSpecialCharacter(unSpecialCharacter);
            }
    	    else if (styleCharProps.isAnythingOverridden())
    	    {
    	        // Only apply the style properties if there is something that has been
    	        // overridden.
        	    io_charProps.applyBaseProperties(styleCharProps);
            }

            unStyleIndex = style.getBaseStyleIndex();
        }
        while (unStyleIndex != 0x0FFF);
    }

    // Now apply the paragraph properties's character styling information
    unStyleIndex = in_unParagraphStyleIndex;

	// get a base char props
	WrdCharacterProperties charProps(m_pDefaultStyle->getOrigCharProps());

	// get style list
	ChVector<ChUINT2> vecStyles;
	GetStyleList(in_unParagraphStyleIndex, vecStyles);	// last one should always be 0

	for (int i = vecStyles.size() - 1; i >= 0; i--)
    {
		unStyleIndex = vecStyles[i];
        const WrdStyle&               style = getStyle(unStyleIndex);
        const WrdCharacterProperties& styleCharProps = style.getOrigCharProps();
    
    	// Only apply the style properties if there is something that has been overridden.
    	if (styleCharProps.isAnythingOverridden())
    	{
        	charProps.applyNextProperties(styleCharProps);
        }
    }

	// apply styles we came in with
    charProps.applyNextProperties(io_charProps);
	// return
	io_charProps = charProps;
}