Commit 7a8d6bac authored by coderus's avatar coderus Committed by Tatiana Meshkova

Provide basic context menu information to Embedlite UI

parent 036997bb
......@@ -37,6 +37,9 @@
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsIDOMHTMLBodyElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsIDOMHTMLImageElement.h"
using namespace mozilla;
......@@ -65,6 +68,116 @@ void EmbedTouchListener::HandleSingleTap(const nsIntPoint& aPoint)
void EmbedTouchListener::HandleLongTap(const nsIntPoint& aPoint)
{
LOGT("pt[%i,%i]", aPoint.x, aPoint.y);
nsCOMPtr<nsIDOMElement> element;
gfxRect retRect(0,0,0,0);
AnyElementFromPoint(DOMWindow, aPoint.x, aPoint.y, getter_AddRefs(element));
nsAutoString localName;
nsAutoString aHRef;
nsAutoString aSrc;
if (element){
element->GetLocalName(localName);
}
nsCOMPtr<nsIDOMElement> linkContent;
if (localName.LowerCaseEqualsLiteral("a") ||
localName.LowerCaseEqualsLiteral("area") ||
localName.LowerCaseEqualsLiteral("link")) {
bool hasAttr;
element->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr);
if (hasAttr) {
linkContent = element;
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(linkContent));
if (anchor){
anchor->GetHref(aHRef);
}
else {
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(linkContent));
if (area){
area->GetHref(aHRef);
}
else {
nsCOMPtr<nsIDOMHTMLLinkElement> link(do_QueryInterface(linkContent));
if (link){
link->GetHref(aHRef);
}
}
}
}
}
else if (localName.LowerCaseEqualsLiteral("img")) {
bool hasAttr;
element->HasAttribute(NS_LITERAL_STRING("src"), &hasAttr);
if (hasAttr) {
linkContent = element;
nsCOMPtr<nsIDOMHTMLImageElement> image(do_QueryInterface(linkContent));
if (image){
image->GetSrc(aSrc);
}
}
}
nsCOMPtr<nsIDOMNode> curr;
element->GetParentNode(getter_AddRefs(curr));
while (curr) {
element = do_QueryInterface(curr);
if (!element)
break;
element->GetLocalName(localName);
if (localName.LowerCaseEqualsLiteral("a") ||
localName.LowerCaseEqualsLiteral("area") ||
localName.LowerCaseEqualsLiteral("link")) {
bool hasAttr;
element->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr);
if (hasAttr) {
linkContent = element;
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(linkContent));
if (anchor) {
anchor->GetHref(aHRef);
}
else {
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(linkContent));
if (area){
area->GetHref(aHRef);
}
else {
nsCOMPtr<nsIDOMHTMLLinkElement> link(do_QueryInterface(linkContent));
if (link){
link->GetHref(aHRef);
}
}
}
}
else
linkContent = nullptr; // Links can't be nested.
break;
}
else if (localName.LowerCaseEqualsLiteral("img")) {
bool hasAttr;
element->HasAttribute(NS_LITERAL_STRING("src"), &hasAttr);
if (hasAttr) {
linkContent = element;
nsCOMPtr<nsIDOMHTMLImageElement> image(do_QueryInterface(linkContent));
if (image)
image->GetSrc(aSrc);
}
else
linkContent = nullptr; // Links can't be nested.
break;
}
nsCOMPtr<nsIDOMNode> temp = curr;
temp->GetParentNode(getter_AddRefs(curr));
}
if (!aHRef.IsEmpty() || !aSrc.IsEmpty()) {
nsString sendString;
nsCOMPtr<nsIEmbedLiteJSON> json = do_GetService("@mozilla.org/embedlite-json;1");
nsCOMPtr<nsIWritablePropertyBag2> root;
json->CreateObject(getter_AddRefs(root));
root->SetPropertyAsAString(NS_LITERAL_STRING("LinkHref"), aHRef);
root->SetPropertyAsAString(NS_LITERAL_STRING("ImageSrc"), aSrc);
json->CreateJSON(root, sendString);
mService->SendAsyncMessage(mTopWinid, NS_LITERAL_STRING("context:info").get(), sendString.get());
}
}
void EmbedTouchListener::SendAsyncScrollDOMEvent(const mozilla::gfx::Rect& aRect,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment