From c3be847acf9493a49ffe16f6ac3110d150a5022e Mon Sep 17 00:00:00 2001 From: "smfr%smfr.org" Date: Mon, 29 Aug 2005 15:19:13 +0000 Subject: [PATCH] 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. git-svn-id: svn://10.0.0.236/trunk@179200 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsDocumentViewer.cpp | 23 ++++++++++------------- mozilla/layout/base/nsIPresShell.h | 7 +++++++ mozilla/layout/base/nsPresShell.cpp | 7 +++---- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index bddf220c303..df9796d1872 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -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 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 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 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 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 diff --git a/mozilla/layout/base/nsIPresShell.h b/mozilla/layout/base/nsIPresShell.h index 4311f93624a..68ebd6bf1f5 100644 --- a/mozilla/layout/base/nsIPresShell.h +++ b/mozilla/layout/base/nsIPresShell.h @@ -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. */ diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 3dc813efdae..cb304554627 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -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;