Correct context menu on contenteditable

Fix link detection
master
boisso 8 years ago
parent a603c48860
commit f9f1680d6c
  1. 27
      k-meleon/BrowserImpl.cpp
  2. 36
      k-meleon/MozUtils.cpp
  3. 1
      k-meleon/MozUtils.h

@ -315,30 +315,9 @@ NS_IMETHODIMP CBrowserImpl::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
NS_IMETHODIMP CBrowserImpl::ShowAsModal(void)
{
NS_ENSURE_TRUE(m_pBrowserFrameGlue, NS_ERROR_FAILURE);
HWND h = m_pBrowserFrameGlue->GetBrowserFrameNativeWnd();
CBrowserFrame* frame = (CBrowserFrame*)CWnd::FromHandle(h);
/*//https://bugzilla.mozilla.org/show_bug.cgi?id=865729
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
JSContext *cx = xpc->GetCurrentJSContext();
nsCOMPtr<nsIScriptContext> scx =
do_QueryInterface(static_cast<nsISupports *> (::JS_GetContextPrivate(cx)));
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
if (stack && NS_SUCCEEDED(stack->Push(nullptr))) {*/
frame->DoModal();
/* JSContext* cx;
stack->Pop(&cx);
NS_ASSERTION(cx == nullptr, "JSContextStack mismatch");
}
else
return NS_ERROR_FAILURE;*/
frame->DoModal();
return NS_OK;
}
@ -1071,6 +1050,10 @@ NS_IMETHODIMP CBrowserImpl::HandleEvent(nsIDOMEvent *aEvent)
}
}
// contenteditable
if (::IsContentEditable(node))
flags |= CONTEXT_TEXT;
// Check frame
if (::GetFrameURL(mWebBrowser, node, url))
flags |= CONTEXT_FRAME;

@ -287,9 +287,10 @@ BOOL GetLinkTitleAndHref(nsIDOMNode* node, nsString& aHref, nsString& aTitle)
link->GetHref(aHref);
}
}
GatherTextUnder(element, aTitle);
return TRUE;
if (aHref.Length()) {
GatherTextUnder(element, aTitle);
return TRUE;
}
}
}
@ -301,6 +302,35 @@ BOOL GetLinkTitleAndHref(nsIDOMNode* node, nsString& aHref, nsString& aTitle)
return FALSE;
}
BOOL IsContentEditable(nsIDOMNode* node)
{
NS_ENSURE_TRUE(node, FALSE);
nsresult rv;
nsCOMPtr<nsIDOMNode> next;
do {
PRUint16 nodeType;
rv = node->GetNodeType(&nodeType);
NS_ENSURE_SUCCESS(rv, FALSE);
if (nodeType == nsIDOMNode::ELEMENT_NODE) {
// Test if the element has an associated link
nsString attr;
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(node));
if (!element) break;
element->GetAttribute(NS_LITERAL_STRING("contenteditable"), attr);
if (wcscmp(attr.get(), L"true") == 0)
return TRUE;
}
// walk-up-the-tree
node->GetParentNode(getter_AddRefs(next));
node = next;
} while (node);
return FALSE;
}
BOOL GetLinkTitleAndHref(nsIDOMNode* node, CString& aHref, CString& aTitle)
{
nsString url, title;

@ -33,6 +33,7 @@ BOOL GetBackgroundImageSrc(nsIDOMNode *aNode, CString& aUrl);
BOOL GetBackgroundImageSrc(nsIDOMNode *aNode, nsString& aUrl);
BOOL GetImageSrc(nsIDOMNode *aNode, CString& aUrl);
BOOL GetImageSrc(nsIDOMNode *aNode, nsCString& aUrl);
BOOL IsContentEditable(nsIDOMNode* node);
CString GetSearchURL(LPCTSTR query);
bool GetFrameURL(nsIWebBrowser* aWebBrowser, nsIDOMNode* aNode, nsString& url);

Loading…
Cancel
Save