Commit 11ad36ab authored by Tatiana Meshkova's avatar Tatiana Meshkova

Added Context menu handler from metro browser

Added selection handler from metro browser.
Added clipboard override component in order to avoid bad behaviour coming from old default Qt implementation (expecting UI thread same as content thread)
parent c57dbad2
This diff is collapsed.
......@@ -2,6 +2,9 @@ jsscripts_manifestdir=$(libdir)/mozembedlite/chrome/embedlite/content
jsscripts_manifest_DATA = \
embedhelper.js \
SelectHelper.js \
SelectionHandler.js \
Util.js \
ContextMenuHandler.js \
bing.xml \
google.xml \
yahoo.xml \
......
This diff is collapsed.
This diff is collapsed.
......@@ -15,6 +15,8 @@ let HTMLSelectElement = Ci.nsIDOMHTMLSelectElement;
let HTMLLabelElement = Ci.nsIDOMHTMLLabelElement;
let HTMLIFrameElement = Ci.nsIDOMHTMLIFrameElement;
let HTMLFrameElement = Ci.nsIDOMHTMLFrameElement;
let HTMLTextAreaElement = Ci.nsIDOMHTMLTextAreaElement;
let HTMLInputElement = Ci.nsIDOMHTMLInputElement;
XPCOMUtils.defineLazyServiceGetter(this, "DOMUtils",
"@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
......@@ -47,11 +49,6 @@ EmbedHelper.prototype = {
_init: function()
{
dump("Init Called:" + this + "\n");
Services.prefs.setBoolPref("embedlite.azpc.handle.singletap", false);
Services.prefs.setBoolPref("embedlite.azpc.json.singletap", true);
Services.prefs.setBoolPref("embedlite.azpc.handle.longtap", false);
Services.prefs.setBoolPref("embedlite.azpc.json.longtap", true);
Services.prefs.setBoolPref("embedlite.azpc.json.viewport", true);
addEventListener("touchstart", this, false);
addEventListener("touchmove", this, false);
addEventListener("touchend", this, false);
......@@ -61,6 +58,7 @@ EmbedHelper.prototype = {
addMessageListener("Gesture:SingleTap", this);
addMessageListener("Gesture:LongTap", this);
addMessageListener("embedui:find", this);
addMessageListener("Gesture:ContextMenuSynth", this);
Services.obs.addObserver(this, "before-first-paint", true);
Services.prefs.addObserver("browser.zoom.reflowOnZoom", this, false);
},
......@@ -183,6 +181,12 @@ EmbedHelper.prototype = {
receiveMessage: function receiveMessage(aMessage) {
switch (aMessage.name) {
case "Gesture:ContextMenuSynth": {
let [x, y] = [aMessage.json.x, aMessage.json.y];
let element = this._touchElement;
this._sendContextMenuEvent(element, x, y);
break;
}
case "Gesture:SingleTap": {
let element = this._touchElement;
if (element) {
......@@ -404,6 +408,16 @@ EmbedHelper.prototype = {
}
},
_sendContextMenuEvent: function _sendContextMenuEvent(aElement, aX, aY) {
let window = aElement.ownerDocument.defaultView;
try {
let cwu = window.top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
cwu.sendMouseEventToWindow("contextmenu", aX, aY, 2, 1, 0, false);
} catch(e) {
Cu.reportError(e);
}
},
handleEvent: function(aEvent) {
switch (aEvent.type) {
case 'touchstart':
......@@ -463,6 +477,7 @@ EmbedHelper.prototype = {
closest = aEvent.target;
if (closest) {
// SelectionHandler._onSelectionAttach(aEvent.changedTouches[0].screenX, aEvent.changedTouches[0].screenY);
let uri = this._getLinkURI(closest);
if (uri) {
Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null);
......@@ -782,5 +797,9 @@ const ElementTouchHelper = {
}
};
Services.scriptloader.loadSubScript("chrome://embedlite/content/Util.js");
Services.scriptloader.loadSubScript("chrome://embedlite/content/ContextMenuHandler.js");
//Services.scriptloader.loadSubScript("chrome://embedlite/content/SelectionHandler.js");
globalObject = new EmbedHelper();
......@@ -54,6 +54,9 @@ rm -rf $TARGET_DIR/chrome/embedlite;
mkdir -p $TARGET_DIR/chrome/embedlite/content;
ln -s $(pwd)/jsscripts/embedhelper.js $TARGET_DIR/chrome/embedlite/content/embedhelper.js;
ln -s $(pwd)/jsscripts/SelectHelper.js $TARGET_DIR/chrome/embedlite/content/SelectHelper.js;
ln -s $(pwd)/jsscripts/SelectionHandler.js $TARGET_DIR/chrome/embedlite/content/SelectionHandler.js;
ln -s $(pwd)/jsscripts/Util.js $TARGET_DIR/chrome/embedlite/content/Util.js;
ln -s $(pwd)/jsscripts/ContextMenuHandler.js $TARGET_DIR/chrome/embedlite/content/ContextMenuHandler.js;
ln -s $(pwd)/jsscripts/google.xml $TARGET_DIR/chrome/embedlite/content/google.xml;
ln -s $(pwd)/jsscripts/bing.xml $TARGET_DIR/chrome/embedlite/content/bing.xml;
ln -s $(pwd)/jsscripts/yahoo.xml $TARGET_DIR/chrome/embedlite/content/yahoo.xml;
......
......@@ -18,10 +18,15 @@
#include "nsIFormHistory.h"
#include "nsWidgetsCID.h"
#include "nsFilePicker.h"
#include "nsClipboard.h"
using namespace mozilla::embedlite;
const char* clipBoardCONTRACTID = "@mozilla.org/widget/clipboard;1";
const char* filepickerCONTRACTID = "@mozilla.org/filepicker;1";
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEmbedFilePicker)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEmbedClipboard)
EmbedWidgetFactoryRegister::EmbedWidgetFactoryRegister()
{
......@@ -49,10 +54,10 @@ EmbedWidgetFactoryRegister::Init()
NS_WARNING("Unable to create factory for component");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIFactory> oldFactory = do_GetClassObject("@mozilla.org/filepicker;1");
nsCOMPtr<nsIFactory> oldFactory = do_GetClassObject(filepickerCONTRACTID);
if (oldFactory) {
nsCID* cid = NULL;
rv = cr->ContractIDToCID("@mozilla.org/filepicker;1", &cid);
rv = cr->ContractIDToCID(filepickerCONTRACTID, &cid);
if (!NS_FAILED(rv)) {
rv = cr->UnregisterFactory(*cid, oldFactory.get());
NS_Free(cid);
......@@ -64,7 +69,30 @@ EmbedWidgetFactoryRegister::Init()
nsCID fpickerCID = NS_EMBED_FILEPICKER_SERVICE_CID;
rv = cr->RegisterFactory(fpickerCID, "EmbedLite FilePicker",
"@mozilla.org/filepicker;1", fp);
filepickerCONTRACTID, fp);
fp = new mozilla::embedlite::GenericFactory(nsEmbedClipboardConstructor);
if (!fp) {
NS_WARNING("Unable to create factory for component");
return NS_ERROR_FAILURE;
}
oldFactory = do_GetClassObject(clipBoardCONTRACTID);
if (oldFactory) {
nsCID* cid = NULL;
rv = cr->ContractIDToCID(clipBoardCONTRACTID, &cid);
if (!NS_FAILED(rv)) {
rv = cr->UnregisterFactory(*cid, oldFactory.get());
NS_Free(cid);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
}
}
nsCID clipboardCID = NS_EMBED_CLIPBOARD_SERVICE_CID;
rv = cr->RegisterFactory(clipboardCID, "EmbedLite ClipBoard",
clipBoardCONTRACTID, fp);
return NS_OK;
}
......@@ -12,7 +12,7 @@ NS_IMPL_ISUPPORTS1(GenericFactory, nsIFactory)
NS_IMETHODIMP
GenericFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult)
void** aResult)
{
return mCtor(aOuter, aIID, aResult);
}
......
......@@ -6,6 +6,7 @@ libwidgetfactory_la_SOURCES = \
nsFilePicker.cpp \
GenericFactory.cpp \
nsEmbedChildModule.cpp \
nsClipboard.cpp \
$(NULL)
libwidgetfactory_la_CPPFLAGS = \
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Util.h"
#include "nsClipboard.h"
#include "nsISupportsPrimitives.h"
#include "nsIInputStream.h"
#include "nsStringStream.h"
#include "nsComponentManagerUtils.h"
#include "imgIContainer.h"
#include "gfxImageSurface.h"
using namespace mozilla;
NS_IMPL_ISUPPORTS1(nsEmbedClipboard, nsIClipboard)
nsEmbedClipboard::nsEmbedClipboard() : nsIClipboard()
{
}
nsEmbedClipboard::~nsEmbedClipboard()
{
}
NS_IMETHODIMP
nsEmbedClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner, int32_t aWhichClipboard)
{
printf("nsEmbedClipboard::SetData NONIMPL\n");
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::GetData(nsITransferable* aTransferable, int32_t aWhichClipboard)
{
printf("nsEmbedClipboard::GetData NONIMPL\n");
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::EmptyClipboard(int32_t aWhichClipboard)
{
printf("nsEmbedClipboard::EmptyClipboard NONIMPL\n");
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::HasDataMatchingFlavors(const char* *aFlavorList, uint32_t aLength, int32_t aWhichClipboard, bool* _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
printf("nsEmbedClipboard::HasDataMatchingFlavors NONIMPL\n");
*_retval = false;
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::SupportsSelectionClipboard(bool* _retval)
{
printf("nsEmbedClipboard::SupportsSelectionClipboard NONIMPL\n");
*_retval = false;
return NS_OK;
}
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsEmbedClipboard_h__
#define nsEmbedClipboard_h__
#include "nsIClipboard.h"
#include "nsIClipboardOwner.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
/* Native Qt Clipboard wrapper */
class nsEmbedClipboard : public nsIClipboard
{
public:
nsEmbedClipboard();
virtual ~nsEmbedClipboard();
//nsISupports
NS_DECL_ISUPPORTS
// nsIClipboard
NS_DECL_NSICLIPBOARD
};
#define NS_EMBED_CLIPBOARD_SERVICE_CID \
{ 0xb27ca13c, \
0xb6d5, \
0x11e2, \
{ 0xb8, 0xc8, 0x1b, 0x7d, 0x85, 0x77, 0x09 }}
#endif // nsEmbedClipboard_h__
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