Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends
nsContextMenuInfo Class Reference

#include <nsContextMenuInfo.h>

Inheritance diagram for nsContextMenuInfo:
Inheritance graph
[legend]
Collaboration diagram for nsContextMenuInfo:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsContextMenuInfo ()

Public Attributes

readonly attribute nsIDOMEvent mouseEvent
 The DOM context menu event.
readonly attribute nsIDOMNode targetNode
 The DOM node most relevant to the context.
readonly attribute AString associatedLink
 Given the CONTEXT_LINK flag, targetNode may not nescesarily be a link.
readonly attribute imgIContainer imageContainer
 Given the CONTEXT_IMAGE flag, these methods can be used in order to get the image for viewing, saving, or for the clipboard.
readonly attribute nsIURI imageSrc
readonly attribute imgIContainer backgroundImageContainer
 Given the CONTEXT_BACKGROUND_IMAGE flag, these methods can be used in order to get the image for viewing, saving, or for the clipboard.
readonly attribute nsIURI backgroundImageSrc

Private Member Functions

virtual ~nsContextMenuInfo ()
void SetMouseEvent (nsIDOMEvent *aEvent)
void SetDOMNode (nsIDOMNode *aNode)
void SetAssociatedLink (nsIDOMNode *aLink)
nsresult GetImageRequest (nsIDOMNode *aDOMNode, imgIRequest **aRequest)
PRBool HasBackgroundImage (nsIDOMNode *aDOMNode)
nsresult GetBackgroundImageRequest (nsIDOMNode *aDOMNode, imgIRequest **aRequest)
nsresult GetBackgroundImageRequestInternal (nsIDOMNode *aDOMNode, imgIRequest **aRequest)

Private Attributes

nsCOMPtr< nsIDOMEventmMouseEvent
nsCOMPtr< nsIDOMNodemDOMNode
nsCOMPtr< nsIDOMNodemAssociatedLink

Friends

class ChromeContextMenuListener

Detailed Description

Definition at line 58 of file nsContextMenuInfo.h.


Constructor & Destructor Documentation

Definition at line 69 of file nsContextMenuInfo.cpp.

{
}
nsContextMenuInfo::~nsContextMenuInfo ( ) [private, virtual]

Definition at line 73 of file nsContextMenuInfo.cpp.

{
}

Member Function Documentation

nsresult nsContextMenuInfo::GetBackgroundImageRequest ( nsIDOMNode aDOMNode,
imgIRequest **  aRequest 
) [private]

Definition at line 260 of file nsContextMenuInfo.cpp.

{

  NS_ENSURE_ARG(aDOMNode);
  NS_ENSURE_ARG_POINTER(aRequest);

  nsCOMPtr<nsIDOMNode> domNode = aDOMNode;

  // special case for the <html> element: if it has no background-image
  // we'll defer to <body>
  nsCOMPtr<nsIDOMHTMLHtmlElement> htmlElement = do_QueryInterface(domNode);
  if (htmlElement) {
    nsAutoString nameSpace;
    htmlElement->GetNamespaceURI(nameSpace);
    if (nameSpace.IsEmpty()) {
      nsresult rv = GetBackgroundImageRequestInternal(domNode, aRequest);
      if (NS_SUCCEEDED(rv) && *aRequest)
        return NS_OK;

      // no background-image found
      nsCOMPtr<nsIDOMDocument> document;
      domNode->GetOwnerDocument(getter_AddRefs(document));
      nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(document));
      NS_ENSURE_TRUE(htmlDocument, NS_ERROR_FAILURE);

      nsCOMPtr<nsIDOMHTMLElement> body;
      htmlDocument->GetBody(getter_AddRefs(body));
      domNode = do_QueryInterface(body);
    }
  }
  return GetBackgroundImageRequestInternal(domNode, aRequest);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 294 of file nsContextMenuInfo.cpp.

{

  nsCOMPtr<nsIDOMNode> domNode = aDOMNode;
  nsCOMPtr<nsIDOMNode> parentNode;

  nsCOMPtr<nsIDOMDocument> document;
  domNode->GetOwnerDocument(getter_AddRefs(document));
  nsCOMPtr<nsIDOMDocumentView> docView(do_QueryInterface(document));
  NS_ENSURE_TRUE(docView, NS_ERROR_FAILURE);

  nsCOMPtr<nsIDOMAbstractView> defaultView;
  docView->GetDefaultView(getter_AddRefs(defaultView));
  nsCOMPtr<nsIDOMViewCSS> defaultCSSView(do_QueryInterface(defaultView));
  NS_ENSURE_TRUE(defaultCSSView, NS_ERROR_FAILURE);

  nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue;
  nsAutoString bgStringValue;

  while (PR_TRUE) {
    nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(domNode));
    // bail for the parent node of the root element or null argument
    if (!domElement)
      break;
    
    nsCOMPtr<nsIDOMCSSStyleDeclaration> computedStyle;
    defaultCSSView->GetComputedStyle(domElement, EmptyString(),
                                     getter_AddRefs(computedStyle));
    if (computedStyle) {
      nsCOMPtr<nsIDOMCSSValue> cssValue;
      computedStyle->GetPropertyCSSValue(NS_LITERAL_STRING("background-image"),
                                         getter_AddRefs(cssValue));
      primitiveValue = do_QueryInterface(cssValue);
      if (primitiveValue) {
        primitiveValue->GetStringValue(bgStringValue);
        if (!bgStringValue.EqualsLiteral("none")) {
          nsCOMPtr<nsIURI> bgUri;
          NS_NewURI(getter_AddRefs(bgUri), bgStringValue);
          NS_ENSURE_TRUE(bgUri, NS_ERROR_FAILURE);

          nsCOMPtr<imgILoader> il(do_GetService(
                                    "@mozilla.org/image/loader;1"));
          NS_ENSURE_TRUE(il, NS_ERROR_FAILURE);

          return il->LoadImage(bgUri, nsnull, nsnull, nsnull, nsnull, nsnull,
                               nsIRequest::LOAD_NORMAL, nsnull, nsnull,
                               aRequest);
        }
      }

      // bail if we encounter non-transparent background-color
      computedStyle->GetPropertyCSSValue(NS_LITERAL_STRING("background-color"),
                                         getter_AddRefs(cssValue));
      primitiveValue = do_QueryInterface(cssValue);
      if (primitiveValue) {
        primitiveValue->GetStringValue(bgStringValue);
        if (!bgStringValue.EqualsLiteral("transparent"))
          return NS_ERROR_FAILURE;
      }
    }

    domNode->GetParentNode(getter_AddRefs(parentNode));
    domNode = parentNode;
  }

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContextMenuInfo::GetImageRequest ( nsIDOMNode aDOMNode,
imgIRequest **  aRequest 
) [private]

Definition at line 235 of file nsContextMenuInfo.cpp.

Here is the call graph for this function:

Definition at line 249 of file nsContextMenuInfo.cpp.

{
  NS_ENSURE_ARG(aDOMNode);

  nsCOMPtr<imgIRequest> request;
  GetBackgroundImageRequest(aDOMNode, getter_AddRefs(request));
  
  return (request != nsnull);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsContextMenuInfo::SetAssociatedLink ( nsIDOMNode aLink) [inline, private]

Definition at line 77 of file nsContextMenuInfo.h.

                    { mAssociatedLink = aLink; }

Here is the caller graph for this function:

void nsContextMenuInfo::SetDOMNode ( nsIDOMNode aNode) [inline, private]

Definition at line 74 of file nsContextMenuInfo.h.

                    { mDOMNode = aNode; }

Here is the caller graph for this function:

void nsContextMenuInfo::SetMouseEvent ( nsIDOMEvent aEvent) [inline, private]

Definition at line 71 of file nsContextMenuInfo.h.

                    { mMouseEvent = aEvent; }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class ChromeContextMenuListener [friend]

Definition at line 60 of file nsContextMenuInfo.h.


Member Data Documentation

readonly attribute AString nsIContextMenuInfo::associatedLink [inherited]

Given the CONTEXT_LINK flag, targetNode may not nescesarily be a link.

This returns the anchor from targetNode if it has one or that of its nearest ancestor if it does not.

Definition at line 134 of file nsIContextMenuListener2.idl.

Given the CONTEXT_BACKGROUND_IMAGE flag, these methods can be used in order to get the image for viewing, saving, or for the clipboard.

Returns:
NS_OK if successful, otherwise NS_ERROR_FAILURE if no background image was found, or NS_ERROR_NULL_POINTER if an internal error occurs where we think there is a background image, but for some reason it cannot be returned.

Definition at line 157 of file nsIContextMenuListener2.idl.

Definition at line 158 of file nsIContextMenuListener2.idl.

Given the CONTEXT_IMAGE flag, these methods can be used in order to get the image for viewing, saving, or for the clipboard.

Returns:
NS_OK if successful, otherwise NS_ERROR_FAILURE if no image was found, or NS_ERROR_NULL_POINTER if an internal error occurs where we think there is an image, but for some reason it cannot be returned.

Definition at line 145 of file nsIContextMenuListener2.idl.

Definition at line 146 of file nsIContextMenuListener2.idl.

Definition at line 94 of file nsContextMenuInfo.h.

Definition at line 93 of file nsContextMenuInfo.h.

Definition at line 92 of file nsContextMenuInfo.h.

The DOM context menu event.

Definition at line 122 of file nsIContextMenuListener2.idl.

The DOM node most relevant to the context.

Definition at line 127 of file nsIContextMenuListener2.idl.


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