Browse Source

Check selection in editor content as well

master
Roy Tam 5 years ago
parent
commit
dcb2948301
  1. 2
      k-meleon/app/BrowserGlue.cpp
  2. 46
      k-meleon/app/BrowserWindow.h

2
k-meleon/app/BrowserGlue.cpp

@ -430,7 +430,7 @@ void CBrowserGlue::ShowContextMenu(UINT aContextFlags)
CString menu;
if (!(aContextFlags & CONTEXT_LINK) &&
!(aContextFlags & CONTEXT_IMAGE) &&
!mpBrowserView->GetBrowserWrapper()->IsSelectionCollapsed())
!mpBrowserView->GetBrowserWrapper()->CanCopy2())
{
// printf("CBrowserGlue::ShowContextMenu(%08x) = SelectedText\n", aContextFlags);
menu = _T("SelectedText");

46
k-meleon/app/BrowserWindow.h

@ -33,7 +33,8 @@ class nsIX509Cert;
#include "nsIWebBrowserFocus.h"
#include "nsIWebBrowserPrint.h"
#include "nsIBaseWindow.h"
#include "nsIDOMNSEditableElement.h"
#include "nsIEditor.h"
class nsITypeAheadFind;
class nsIDOMKeyEvent;
@ -130,13 +131,50 @@ public:
return res;
}
BOOL IsSelectionCollapsed()
BOOL GetEditor2(nsCOMPtr<nsPIDOMWindow> piWin, nsCOMPtr<nsIEditor>& editor)
{
if (!piWin) return FALSE;
nsIDocShell* docShell = piWin->GetDocShell();
if (!docShell) return FALSE;
docShell->GetEditor(getter_AddRefs(editor));
NS_ENSURE_TRUE(editor, FALSE);
return TRUE;
}
BOOL GetEditor1(nsCOMPtr<nsIEditor>& editor)
{
nsresult rv;
NS_ENSURE_TRUE(mWebBrowserFocus, FALSE);
nsCOMPtr<nsIDOMElement> elem;
rv = mWebBrowserFocus->GetFocusedElement(getter_AddRefs(elem));
NS_ENSURE_TRUE(elem, FALSE);
nsCOMPtr<nsIDOMNSEditableElement> ee(do_QueryInterface(elem));
NS_ENSURE_TRUE(ee, FALSE);
rv = ee->GetEditor(getter_AddRefs(editor));
NS_ENSURE_TRUE(editor, FALSE);
return TRUE;
}
BOOL CanCopy2()
{
nsCOMPtr<nsIDOMWindow> dom;
if (mWebBrowser) mWebBrowser->GetContentDOMWindow(getter_AddRefs(dom));
nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(dom);
nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(dom);
nsCOMPtr<nsIEditor> editor;
nsCOMPtr<nsISelection> domSelection;
domWindow->GetSelection(getter_AddRefs(domSelection));
if (GetEditor1(editor) || GetEditor2(domWindow, editor)) {
editor->GetSelection(getter_AddRefs(domSelection));
} else {
domWindow->GetSelection(getter_AddRefs(domSelection));
}
NS_ENSURE_TRUE(domSelection, false);
bool selectionCollapsed = false;
domSelection->GetIsCollapsed(&selectionCollapsed);
return selectionCollapsed;

Loading…
Cancel
Save