Fix bug 208601: DocumentViewerImpl::GetCanGetContents() was incorrectly returning false for text fields, because it was looking at the document's selection, rather than the text field selection. Fix by exposing nsIPresShell::GetSelectionForCopy(), and calling that. This fixes the Services menu in Camino to work in text fields. r/sr=roc.

This commit is contained in:
smfr@smfr.org
2005-08-29 15:19:13 +00:00
parent 1603787d43
commit c0eec993a9
3 changed files with 20 additions and 17 deletions

View File

@@ -2187,6 +2187,9 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget,
return rv;
}
// Return the selection for the document. Note that text fields have their
// own selection, which cannot be accessed with this method. Use
// mPresShell->GetSelectionForCopy() instead.
nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection,
nsIPresShell *aPresShell)
{
@@ -2265,6 +2268,7 @@ NS_IMETHODIMP DocumentViewerImpl::ClearSelection()
nsresult rv;
nsCOMPtr<nsISelection> selection;
// use mPresShell->GetSelectionForCopy() ?
rv = GetDocumentSelection(getter_AddRefs(selection));
if (NS_FAILED(rv)) return rv;
@@ -2278,6 +2282,8 @@ NS_IMETHODIMP DocumentViewerImpl::SelectAll()
// functions to make this easier.
nsCOMPtr<nsISelection> selection;
nsresult rv;
// use mPresShell->GetSelectionForCopy() ?
rv = GetDocumentSelection(getter_AddRefs(selection));
if (NS_FAILED(rv)) return rv;
@@ -2343,9 +2349,10 @@ NS_IMETHODIMP DocumentViewerImpl::CopyImage(PRInt32 aCopyFlags)
NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable)
{
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsISelection> selection;
nsresult rv;
rv = GetDocumentSelection(getter_AddRefs(selection));
nsresult rv = mPresShell->GetSelectionForCopy(getter_AddRefs(selection));
if (NS_FAILED(rv)) return rv;
PRBool isCollapsed;
@@ -2389,17 +2396,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetContents(const char *mimeType, PRBool selec
/* readonly attribute boolean canGetContents; */
NS_IMETHODIMP DocumentViewerImpl::GetCanGetContents(PRBool *aCanGetContents)
{
NS_ENSURE_ARG_POINTER(aCanGetContents);
nsCOMPtr<nsISelection> selection;
nsresult rv = GetDocumentSelection(getter_AddRefs(selection));
if (NS_FAILED(rv)) return rv;
PRBool isCollapsed;
selection->GetIsCollapsed(&isCollapsed);
*aCanGetContents = !isCollapsed;
return NS_OK;
return GetCopyable(aCanGetContents);
}
#ifdef XP_MAC

View File

@@ -88,6 +88,7 @@ class nsIDOMNode;
class nsIStyleFrameConstruction;
class nsIStyleSheet;
class nsCSSFrameConstructor;
class nsISelection;
#define NS_IPRESSHELL_IID \
{ 0x8be1b911, 0x7a04, 0x44e8, \
@@ -455,6 +456,12 @@ public:
*/
NS_IMETHOD DoCopy() = 0;
/**
* Get the selection of the focussed element (either the page selection,
* or the selection for a text field).
*/
NS_IMETHOD GetSelectionForCopy(nsISelection** outSelection) = 0;
/**
* Get link location.
*/

View File

@@ -1120,6 +1120,8 @@ public:
NS_IMETHOD NotifyDestroyingFrame(nsIFrame* aFrame);
NS_IMETHOD DoCopy();
NS_IMETHOD GetSelectionForCopy(nsISelection** outSelection);
NS_IMETHOD GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocationString);
NS_IMETHOD DoGetContents(const nsACString& aMimeType, PRUint32 aFlags, PRBool aSelectionOnly, nsAString& outValue);
@@ -1334,9 +1336,6 @@ protected:
nsresult SetPrefNoScriptRule();
nsresult SetPrefNoFramesRule(void);
nsresult GetSelectionForCopy(nsISelection** outSelection);
nsICSSStyleSheet* mPrefStyleSheet; // mStyleSet owns it but we maintain a ref, may be null
#ifdef DEBUG
PRUint32 mUpdateCount;
@@ -4545,7 +4544,7 @@ NS_IMETHODIMP PresShell::GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocation
return NS_ERROR_FAILURE;
}
nsresult
NS_IMETHODIMP
PresShell::GetSelectionForCopy(nsISelection** outSelection)
{
nsresult rv = NS_OK;