From 2baa86a01ae2e98e22196dbb4baef0f2ef8f4778 Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Fri, 22 Dec 2000 01:13:46 +0000 Subject: [PATCH] clean up interface, per directions. adding copyLinkLocation(), and specifying semantics of selectNone() wrt insertion point location. Implemented selectNone(). r=saari/a=hyatt. bug#s 46867, 63001 git-svn-id: svn://10.0.0.236/trunk@83971 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsWebShell.cpp | 41 +++++++++++++++---- .../powerplant/source/CBrowserShell.cpp | 4 +- mozilla/embedding/tests/winEmbed/winEmbed.cpp | 8 ++-- .../webshell/public/nsIClipboardCommands.idl | 12 ++++-- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index cc04f210b01..ad8301bf440 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -1264,7 +1264,7 @@ nsWebShell::CanCopySelection(PRBool* aResult) } NS_IMETHODIMP -nsWebShell::CanPasteSelection(PRBool* aResult) +nsWebShell::CanPaste(PRBool* aResult) { nsresult rv = NS_ERROR_NULL_POINTER; @@ -1287,7 +1287,13 @@ nsWebShell::CopySelection(void) } NS_IMETHODIMP -nsWebShell::PasteSelection(void) +nsWebShell::CopyLinkLocation(void) +{ + return DoCommand ( NS_LITERAL_STRING("cmd_copy_link") ); +} + +NS_IMETHODIMP +nsWebShell::Paste(void) { return DoCommand ( NS_LITERAL_STRING("cmd_paste") ); } @@ -1297,16 +1303,14 @@ nsWebShell::SelectAll(void) { nsresult rv; - nsCOMPtr docViewer; - rv = mContentViewer->QueryInterface(NS_GET_IID(nsIDocumentViewer), - getter_AddRefs(docViewer)); + nsCOMPtr docViewer ( do_QueryInterface(mContentViewer, &rv) ); if (NS_FAILED(rv) || !docViewer) return rv; nsCOMPtr presShell; rv = docViewer->GetPresShell(*getter_AddRefs(presShell)); if (NS_FAILED(rv) || !presShell) return rv; - nsCOMPtr selCon = do_QueryInterface(presShell); + nsCOMPtr selCon = do_QueryInterface(presShell, &rv); if (NS_FAILED(rv) || !selCon) return rv; nsCOMPtr selection; @@ -1353,10 +1357,33 @@ nsWebShell::SelectAll(void) return rv; } + +// +// SelectNone +// +// Collapses the current selection, insertion point ends up at beginning +// of previous selection. +// NS_IMETHODIMP nsWebShell::SelectNone(void) { - return NS_ERROR_FAILURE; + nsresult rv = NS_OK; + + nsCOMPtr docViewer ( do_QueryInterface(mContentViewer, &rv) ); + if (NS_FAILED(rv) || !docViewer) return rv; + + nsCOMPtr presShell; + rv = docViewer->GetPresShell(*getter_AddRefs(presShell)); + if (NS_FAILED(rv) || !presShell) return rv; + + nsCOMPtr selCon = do_QueryInterface(presShell, &rv); + if (NS_FAILED(rv) || !selCon) return rv; + + nsCOMPtr selection; + rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + if (NS_FAILED(rv) || !selection) return rv; + + return selection->CollapseToStart(); } diff --git a/mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp b/mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp index 64d21d781b6..7ffba380637 100644 --- a/mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp +++ b/mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp @@ -287,7 +287,7 @@ Boolean CBrowserShell::ObeyCommand(PP_PowerPlant::CommandT inCommand, void* ioPa case cmd_Paste: rv = GetClipboardHandler(getter_AddRefs(clipCmd)); if (NS_SUCCEEDED(rv)) - clipCmd->PasteSelection(); + clipCmd->Paste(); break; case cmd_SelectAll: @@ -374,7 +374,7 @@ void CBrowserShell::FindCommandStatus(PP_PowerPlant::CommandT inCommand, case cmd_Paste: rv = GetClipboardHandler(getter_AddRefs(clipCmd)); if (NS_SUCCEEDED(rv)) { - rv = clipCmd->CanPasteSelection(&canDo); + rv = clipCmd->CanPaste(&canDo); outEnabled = NS_SUCCEEDED(rv) && canDo; } break; diff --git a/mozilla/embedding/tests/winEmbed/winEmbed.cpp b/mozilla/embedding/tests/winEmbed/winEmbed.cpp index 0e501427901..4968c4beeb5 100644 --- a/mozilla/embedding/tests/winEmbed/winEmbed.cpp +++ b/mozilla/embedding/tests/winEmbed/winEmbed.cpp @@ -342,14 +342,14 @@ void UpdateUI(nsIWebBrowserChrome *aChrome) PRBool canCutSelection = PR_FALSE; PRBool canCopySelection = PR_FALSE; - PRBool canPasteSelection = PR_FALSE; + PRBool canPaste = PR_FALSE; nsCOMPtr clipCmds = do_GetInterface(webBrowser); if (nsIClipboardCommands) { clipCmds->CanCutSelection(&canCutSelection); clipCmds->CanCopySelection(&canCopySelection); - clipCmds->CanPasteSelection(&canPasteSelection); + clipCmds->CanPaste(&canPaste); } HMENU hmenu = GetMenu(hwndDlg); @@ -365,7 +365,7 @@ void UpdateUI(nsIWebBrowserChrome *aChrome) EnableMenuItem(hmenu, MOZ_Copy, MF_BYCOMMAND | ((canCopySelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); EnableMenuItem(hmenu, MOZ_Paste, MF_BYCOMMAND | - ((canPasteSelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); + ((canPaste) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); } EnableWindow(GetDlgItem(hwndDlg, IDC_BACK), canGoBack); @@ -499,7 +499,7 @@ BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar case MOZ_Paste: { nsCOMPtr clipCmds = do_GetInterface(webBrowser); - clipCmds->PasteSelection(); + clipCmds->Paste(); } break; diff --git a/mozilla/webshell/public/nsIClipboardCommands.idl b/mozilla/webshell/public/nsIClipboardCommands.idl index 40363a5a05d..fa322960a99 100644 --- a/mozilla/webshell/public/nsIClipboardCommands.idl +++ b/mozilla/webshell/public/nsIClipboardCommands.idl @@ -37,7 +37,7 @@ interface nsIClipboardCommands : nsISupports { * Returns whether the current contents of the clipboard can be * pasted and if the current selection is not read-only. */ - boolean canPasteSelection(); + boolean canPaste(); /** * Cut the current selection onto the clipboard. @@ -48,11 +48,16 @@ interface nsIClipboardCommands : nsISupports { * Copy the current selection onto the clipboard. */ void copySelection(); + + /** + * Copy the URL of the current selection, say for an inside an + */ + void copyLinkLocation(); /** * Paste the contents of the clipboard into the current selection. */ - void pasteSelection(); + void paste(); /** * Select the entire contents. @@ -60,7 +65,8 @@ interface nsIClipboardCommands : nsISupports { void selectAll(); /** - * Clear the current selection (if any). + * Clear the current selection (if any). Insertion point ends up + * at beginning of current selection. */ void selectNone(); };