Skip to content

Commit

Permalink
Removed old commented out code for the now defunct nsIDocShellEdit an…
Browse files Browse the repository at this point in the history
…d nsIDocShellFile interfaces. Replaced nsIDocShellContainer::GetEnumerator with nsIDocShellContainer::GetChildAt(). Also provided implementation for that function.
  • Loading branch information
tbogard%aol.net committed Dec 1, 1999
1 parent e334909 commit 11a750a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 241 deletions.
244 changes: 7 additions & 237 deletions docshell/base/nsDocShell.cpp
Expand Up @@ -504,239 +504,6 @@ nsDocShell::SetMarginHeight(PRInt32 aHeight)
return NS_OK;
}



// the following code is to be removed. It will show up on content viewer classes
#if 0
//*****************************************************************************
// nsDocShell::nsIDocShellEdit
//*****************************************************************************

NS_IMETHODIMP nsDocShell::Search()
{
NS_WARN_IF_FALSE(PR_FALSE, "Subclasses should override this method!!!!");
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP nsDocShell::GetSearchable(PRBool* aSearchable)
{
NS_ENSURE_ARG_POINTER(aSearchable);
*aSearchable = PR_FALSE;
return NS_OK;
}

NS_IMETHODIMP nsDocShell::ClearSelection()
{
NS_ENSURE_STATE(mContentViewer);
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE);

nsCOMPtr<nsIDOMSelection> selection;
NS_ENSURE_SUCCESS(presShell->GetSelection(SELECTION_NORMAL,
getter_AddRefs(selection)), NS_ERROR_FAILURE);

NS_ENSURE_SUCCESS(selection->ClearSelection(), NS_ERROR_FAILURE);

return NS_OK;
}

/* the basic idea here is to grab the topmost content object
* (for HTML documents, that's the BODY)
* and select all it's children
*/
NS_IMETHODIMP nsDocShell::SelectAll()
{
NS_ENSURE_STATE(mContentViewer);
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);

// get the selection object
nsCOMPtr<nsIDOMSelection> selection;
NS_ENSURE_SUCCESS(presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);

// get the document
nsCOMPtr<nsIDOMNodeList> nodeList;
nsAutoString bodyTag = "body";
nsCOMPtr<nsIDOMDocument> document;
NS_ENSURE_SUCCESS(GetDocument(getter_AddRefs(document)), NS_ERROR_FAILURE);

// get the body tag(s) in the document
NS_ENSURE_SUCCESS(document->GetElementsByTagName(bodyTag,
getter_AddRefs(nodeList)),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(nodeList, NS_OK); // this means the document has no body, so nothing to select

// verify this document has exactly one body node
PRUint32 count;
NS_ENSURE_SUCCESS(nodeList->GetLength(&count), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(count != 1, NS_OK); // could be true for a frameset doc

// select all children of the body
nsCOMPtr<nsIDOMNode> bodyNode;
NS_ENSURE_SUCCESS(nodeList->Item(0, getter_AddRefs(bodyNode)), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(bodyNode, NS_ERROR_FAILURE);
// start the selection in front of the first child
NS_ENSURE_SUCCESS(selection->Collapse(bodyNode, 0), NS_ERROR_FAILURE);
// end the selection after the last child
PRInt32 numBodyChildren=0;
nsCOMPtr<nsIDOMNode>lastChild;
NS_ENSURE_SUCCESS(bodyNode->GetLastChild(getter_AddRefs(lastChild)),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(lastChild, NS_OK); // body isn't required to have any children, so it's ok if lastChild is null.
// in this case, we just have a collapsed selection at (body, 0)
NS_ENSURE_SUCCESS(GetChildOffset(lastChild, bodyNode, &numBodyChildren),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(selection->Extend(bodyNode, numBodyChildren+1), NS_ERROR_FAILURE);

return NS_OK;
}

NS_IMETHODIMP nsDocShell::CopySelection()
{
NS_ENSURE_STATE(mContentViewer);
PRBool copyable;
NS_ENSURE_SUCCESS(GetCopyable(&copyable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(copyable, NS_ERROR_UNEXPECTED);

nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE);

// the pres shell knows how to copy, so let it do the work
NS_ENSURE_SUCCESS(presShell->DoCopy(), NS_ERROR_FAILURE);
return NS_OK;
}

/* the docShell is "copyable" if it has a selection and the selection is not
* collapsed (that is, at least one token is selected, a character or a node
*/
NS_IMETHODIMP nsDocShell::GetCopyable(PRBool *aCopyable)
{
NS_ENSURE_ARG_POINTER(aCopyable);
NS_ENSURE_STATE(mContentViewer);

nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE);

nsCOMPtr<nsIDOMSelection> selection;
NS_ENSURE_SUCCESS(presShell->GetSelection(SELECTION_NORMAL,
getter_AddRefs(selection)), NS_ERROR_FAILURE);

if(!selection)
{
*aCopyable = PR_FALSE;
return NS_OK;
}

PRBool isCollapsed;
NS_ENSURE_SUCCESS(selection->GetIsCollapsed(&isCollapsed), NS_ERROR_FAILURE);
*aCopyable = !isCollapsed;

return NS_OK;
}

NS_IMETHODIMP nsDocShell::CutSelection()
{
NS_ENSURE_STATE(mContentViewer);
PRBool cutable;
NS_ENSURE_SUCCESS(GetCutable(&cutable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(cutable, NS_ERROR_UNEXPECTED);



//XXXIMPL
//Should check to find the current focused object. Then cut the contents.
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP nsDocShell::GetCutable(PRBool* aCutable)
{
NS_ENSURE_ARG_POINTER(aCutable);

//XXXIMPL Implement
//Should check to find the current focused object. Then see if it can
//be cut out of. For now the answer is always no since CutSelection()
// has not been implemented.
*aCutable = PR_FALSE;
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP nsDocShell::Paste()
{
NS_ENSURE_STATE(mContentViewer);
PRBool pasteable;
NS_ENSURE_SUCCESS(GetPasteable(&pasteable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(pasteable, NS_ERROR_UNEXPECTED);

//XXXIMPL Implement
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP nsDocShell::GetPasteable(PRBool* aPasteable)
{
NS_ENSURE_ARG_POINTER(aPasteable);

//XXXIMPL Implement
//Should check to find the current focused object. Then see if it can
//be pasted into. For now the answer is always no since Paste()
// has not been implemented.
*aPasteable = PR_FALSE;
return NS_OK;
}

//*****************************************************************************
// nsDocShell::nsIDocShellFile
//*****************************************************************************

NS_IMETHODIMP nsDocShell::Save()
{
NS_ENSURE_STATE(mContentViewer);
PRBool saveable;
NS_ENSURE_SUCCESS(GetSaveable(&saveable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(saveable, NS_ERROR_UNEXPECTED);

//XXXIMPL
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP nsDocShell::GetSaveable(PRBool* saveable)
{
NS_ENSURE_ARG_POINTER(saveable);
// XXXIMPL
// Should check if a doc is loaded and if it is in a state that that is
// ready to save. For now the answer is always no since saving isn't
// implemented.

*saveable = PR_FALSE;
return NS_OK;
}

NS_IMETHODIMP nsDocShell::Print()
{
NS_ENSURE_STATE(mContentViewer);
PRBool printable;
NS_ENSURE_SUCCESS(GetPrintable(&printable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(printable, NS_ERROR_UNEXPECTED);

//XXXIMPL
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP nsDocShell::GetPrintable(PRBool* printable)
{
NS_ENSURE_ARG_POINTER(printable);
// XXXIMPL
// Should check if a doc is loaded and if it is in a state that that is
// ready to print. For now the answer is always no since printing isn't
// implemented.

*printable = PR_FALSE;
return NS_OK;
}
#endif

//*****************************************************************************
// nsDocShell::nsIDocShellContainer
//*****************************************************************************
Expand Down Expand Up @@ -798,12 +565,15 @@ NS_IMETHODIMP nsDocShell::RemoveChild(nsIDocShell *aChild)
return NS_OK;
}

/* readonly attribute nsIEnumerator childEnumerator; */
NS_IMETHODIMP nsDocShell::GetChildEnumerator(nsIEnumerator * *aChildEnumerator)
NS_IMETHODIMP nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShell** aDocShell)
{
NS_ENSURE_ARG_POINTER(aChildEnumerator);
NS_ENSURE_ARG_POINTER(aDocShell);
NS_ENSURE_ARG_RANGE(aIndex, 0, mChildren.Count() - 1);

return NS_OK;
*aDocShell = (nsIDocShell*) mChildren.ElementAt(aIndex);
NS_IF_ADDREF(*aDocShell);

return NS_OK;
}

/* depth-first search for a child shell with aName */
Expand Down
6 changes: 2 additions & 4 deletions docshell/base/nsIDocShellContainer.idl
Expand Up @@ -49,10 +49,8 @@ interface nsIDocShellContainer : nsISupports
*/
void RemoveChild(in nsIDocShell child);

/*
Enumerator to walk child list.
*/
readonly attribute nsIEnumerator childEnumerator;
/* Return the child at the index requested. This is 0-based.*/
void GetChildAt(in long index, out nsIDocShell child);

/*
Return the child DocShell with the specified name
Expand Down

0 comments on commit 11a750a

Please sign in to comment.