Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
CIEHtmlSelectionObject Class Reference

#include <IEHtmlSelectionObject.h>

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

List of all members.

Public Member Functions

 CIEHtmlSelectionObject ()
void SetSelection (nsISelection *pSelection)
void SetDOMDocumentRange (nsIDOMDocumentRange *pDOMDocumentRange)
virtual HRESULT STDMETHODCALLTYPE createRange (IDispatch __RPC_FAR *__RPC_FAR *range)
virtual HRESULT STDMETHODCALLTYPE empty ()
virtual HRESULT STDMETHODCALLTYPE clear ()
virtual HRESULT STDMETHODCALLTYPE get_type (BSTR __RPC_FAR *p)

Protected Member Functions

virtual ~CIEHtmlSelectionObject ()

Protected Attributes

nsCOMPtr< nsISelectionmSelection
nsCOMPtr< nsIDOMDocumentRangemDOMDocumentRange

Detailed Description

Definition at line 44 of file IEHtmlSelectionObject.h.


Constructor & Destructor Documentation

Definition at line 43 of file IEHtmlSelectionObject.cpp.

{
}

Definition at line 47 of file IEHtmlSelectionObject.cpp.

{
}

Member Function Documentation

HRESULT STDMETHODCALLTYPE CIEHtmlSelectionObject::clear ( ) [virtual]

Definition at line 158 of file IEHtmlSelectionObject.cpp.

{
    if (!mSelection)
        return E_FAIL;
    mSelection->DeleteFromDocument();
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CIEHtmlSelectionObject::createRange ( IDispatch __RPC_FAR *__RPC_FAR *  range) [virtual]

Definition at line 60 of file IEHtmlSelectionObject.cpp.

{
    if (range == NULL)
        return E_INVALIDARG;
    *range = NULL;
    if (!mSelection)
        return E_FAIL;
    // get range corresponding to mSelection:
    nsCOMPtr<nsIDOMRange> domRange;
    int rc;
    mSelection->GetRangeCount(&rc);
    if (rc>0)
        mSelection->GetRangeAt(0, getter_AddRefs(domRange));
    else
    {
        // create empty range
        mDOMDocumentRange->CreateRange(getter_AddRefs(domRange));
    }
    if (!domRange)
        return E_FAIL;
    // create com object:
    CComBSTR strType;
    get_type(&strType);
    if (wcscmp(OLE2W(strType), L"Control") == 0)
    {
        // IHTMLControlRange:
        CIEHtmlControlRangeInstance *pControlRange = NULL;
        CIEHtmlControlRangeInstance::CreateInstance(&pControlRange);
        if (!pControlRange)
            return E_FAIL;
        // gives the range to the com object:
        pControlRange->SetRange(domRange);
        // return com object:
        pControlRange->QueryInterface(IID_IDispatch, (void **)range);
    } else
    {
        // IHTMLTxtRange:
        CIEHtmlTxtRangeInstance *pTxtRange = NULL;
        CIEHtmlTxtRangeInstance::CreateInstance(&pTxtRange);
        if (!pTxtRange)
            return E_FAIL;
        // gives the range to the com object:
        pTxtRange->SetRange(domRange);
        // return com object:
        pTxtRange->QueryInterface(IID_IDispatch, (void **)range);
    }
    return S_OK;
}

Here is the call graph for this function:

HRESULT STDMETHODCALLTYPE CIEHtmlSelectionObject::empty ( ) [virtual]

Definition at line 150 of file IEHtmlSelectionObject.cpp.

{
    if (!mSelection)
        return E_FAIL;
    mSelection->RemoveAllRanges();
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CIEHtmlSelectionObject::get_type ( BSTR __RPC_FAR *  p) [virtual]

Definition at line 109 of file IEHtmlSelectionObject.cpp.

{
    static NS_NAMED_LITERAL_STRING(strText,"Text");
    static NS_NAMED_LITERAL_STRING(strControl,"Control");
    static NS_NAMED_LITERAL_STRING(strNone,"None");
    nsCOMPtr<nsIDOMRange> domRange;
    nsCOMPtr<nsIDOMNode> domNode;

    if (p == NULL)
        return E_INVALIDARG;
    *p = NULL;
    
    // get range corresponding to mSelection:
    int rc;
    mSelection->GetRangeCount(&rc);
    if (rc<1) {
        *p = SysAllocString(strNone.get());
        return p ? S_OK : E_OUTOFMEMORY;
    }
    mSelection->GetRangeAt(0, getter_AddRefs(domRange));
    if (!domRange)
        return E_FAIL;
    domRange->GetStartContainer(getter_AddRefs(domNode));
    if (!domNode)
        return E_FAIL;
    unsigned short nodeType;
    domNode->GetNodeType(&nodeType);
    switch (nodeType)
    {
    case nsIDOMNode::ELEMENT_NODE:
        *p = SysAllocString(strControl.get());
        break;
    case nsIDOMNode::TEXT_NODE:
        *p = SysAllocString(strText.get());
        break;
    default:
        return E_UNEXPECTED;
    }
    return p ? S_OK : E_OUTOFMEMORY;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 56 of file IEHtmlSelectionObject.cpp.

                                                                                       {
    mDOMDocumentRange = pDOMDocumentRange;
}

Definition at line 51 of file IEHtmlSelectionObject.cpp.

{
    mSelection = pSelection;
}

Member Data Documentation

Definition at line 74 of file IEHtmlSelectionObject.h.

Definition at line 71 of file IEHtmlSelectionObject.h.


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