Browse Source

SetAccel

CreateButton
import/tags/kmeleon75
boisso 8 years ago
parent
commit
5f721e202f
  1. 4
      k-meleon/JSBridge/JSBridge.vcxproj
  2. 121
      k-meleon/JSBridge/jscomp.cpp
  3. 33
      k-meleon/JSBridge/jsplugin.cpp
  4. 7
      k-meleon/JSBridge/nsIJSBridge.idl

4
k-meleon/JSBridge/JSBridge.vcxproj

@ -58,7 +58,7 @@
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>xul.lib;mozalloc.lib;nss3.lib;xpcomglue_s.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>nss3.lib;xul.lib;mozalloc.lib;mozjs.lib;xpcomglue_s.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>..\..\debug\kplugins\$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>../../xulrunner-sdk/lib_dbg;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
@ -85,7 +85,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>xul.lib;mozalloc.lib;nss3.lib;xpcomglue_s.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>mozjs.lib;xul.lib;mozalloc.lib;nss3.lib;xpcomglue_s.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>..\..\release\kplugins\$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>../../xulrunner-sdk/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Windows</SubSystem>

121
k-meleon/JSBridge/jscomp.cpp

@ -8,14 +8,19 @@
#include <nsServiceManagerUtils.h>
#include <nsIWebBrowserChrome.h>
#include <nsIEmbeddingSiteWindow.h>
#include <nsComponentManagerUtils.h>
#include <nsMemory.h>
#include <jsapi.h>
#include "jscomp.h"
#include "..\kmeleon_plugin.h"
#include "nsComponentManagerUtils.h"
#include "nsMemory.h"
extern kmeleonPlugin kPlugin;
extern CCmdList* cmdList;
CCmdList* GetCmdList() {
if (!cmdList) cmdList = new CCmdList();
return cmdList;
}
NS_IMPL_ISUPPORTS (CJSCommand, kmICommand)
NS_IMETHODIMP CJSCommand::GetName(char * *aName)
@ -43,6 +48,40 @@ NS_IMETHODIMP CJSCommand::SetImage(const char * aImage)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMPL_ISUPPORTS (CJSButton, kmIButton)
/* attribute string image; */
NS_IMETHODIMP CJSButton::GetImage(char * *aImage)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CJSButton::SetImage(const char * aImage)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute bool checked; */
NS_IMETHODIMP CJSButton::GetChecked(bool *aChecked)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CJSButton::SetChecked(bool aChecked)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute bool disabled; */
NS_IMETHODIMP CJSButton::GetDisabled(bool *aDisabled)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CJSButton::SetDisabled(bool aDisabled)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMPL_ISUPPORTS (CJSBridge, nsIJSBridge)
NS_IMETHODIMP CJSBridge::SetMenuCallback(const char *menu, const char *label, kmICommandFunction *command, const char *before)
@ -56,7 +95,7 @@ NS_IMETHODIMP CJSBridge::SetMenuCallback(const char *menu, const char *label, km
//JS_CallFunctionValue(cx, JS_GetGlobalObject(cx), *(JS_ARGV(cx, command)), 0, NULL, &retVal);
//JS_GetStringCharsZ(ctx->GetNativeContext(), command.toString()
item.command = kPlugin.kFuncs->GetCommandIDs(1);
cmdList->Add(item.command, command);
::GetCmdList()->Add(item.command, command);
if (before && *before) {
item.before = atoi(before);
@ -145,7 +184,6 @@ NS_IMETHODIMP CJSBridge::GetCmdList(PRUint32 *length, kmICommand ***list)
unsigned size = kPlugin.kFuncs->GetCmdList(nullptr, 0);
kmeleonCommand* kcs = new kmeleonCommand[size];
size = kPlugin.kFuncs->GetCmdList(kcs, size);
size = 1;
kmICommand** cmds = static_cast<kmICommand**>(NS_Alloc(size*sizeof(kmICommand*)));
for (unsigned i = 0;i<size;i++) {
CJSCommand* cmd = new CJSCommand();
@ -162,21 +200,50 @@ NS_IMETHODIMP CJSBridge::GetCmdList(PRUint32 *length, kmICommand ***list)
}
NS_IMETHODIMP CJSBridge::RegisterCmd(const char * name, const char * desc,
kmICommandFunction *command, const char* icon,
kmICallback *enabled, kmICallback *checked, int32_t *_retval)
kmICommandFunction *command, JS::HandleValue icon,
kmICallback *enabled, kmICallback *checked, JSContext* cx, int32_t *_retval)
{
UINT id = kPlugin.kFuncs->RegisterCmd(name, desc, icon);
cmdList->Add(id, command);
if (!kPlugin.kFuncs) return NS_ERROR_NOT_INITIALIZED;
char* iconPath;
UINT id = 0;
if (icon.isObject()) {
JS::RootedObject obj(cx);
obj = icon.toObjectOrNull();
JS::Rooted<JS::Value> vpath(cx);
JS::Rooted<JS::Value> vt(cx);
JS::Rooted<JS::Value> vb(cx);
JS::Rooted<JS::Value> vr(cx);
JS::Rooted<JS::Value> vl(cx);
if (!JS_GetProperty(cx, obj, "path", &vpath))
return NS_ERROR_INVALID_ARG;
if (!JS_GetProperty(cx, obj, "top", &vt))
return NS_ERROR_INVALID_ARG;
if (!JS_GetProperty(cx, obj, "bottom", &vb))
return NS_ERROR_INVALID_ARG;
if (!JS_GetProperty(cx, obj, "left", &vl))
return NS_ERROR_INVALID_ARG;
if (!JS_GetProperty(cx, obj, "right", &vr))
return NS_ERROR_INVALID_ARG;
RECT rect = {vl.toInt32(), vt.toInt32(), vr.toInt32(), vb.toInt32()};
id = kPlugin.kFuncs->RegisterCmd(name, desc, nullptr);
iconPath = JS_EncodeString(cx, vpath.toString());
kPlugin.kFuncs->SetCmdIcon(name, iconPath, &rect, nullptr, nullptr, nullptr, nullptr);
} else {
iconPath = JS_EncodeString(cx, icon.toString());
id = kPlugin.kFuncs->RegisterCmd(name, desc, iconPath);
}
::GetCmdList()->Add(id, command);
if (iconPath) JS_free(cx, iconPath);
return NS_OK;
}
NS_IMETHODIMP CJSBridge::AddButton(const char * name, const char *command, const char* menu)
{
kmeleonButton b = {0};
b.action = command;
b.menu = menu;
b.enabled = true;
kPlugin.kFuncs->AddButton(name, &b);
kPlugin.kFuncs->AddButton(name, command, menu);
return NS_OK;
}
@ -199,3 +266,31 @@ NS_IMETHODIMP CJSBridge::GetActiveBrowser(nsIWebBrowser * *_retval)
return NS_OK;
}
NS_IMETHODIMP CJSBridge::SetAccel(const char * key, const char * command)
{
kPlugin.kFuncs->SetAccel(key, command);
return NS_OK;
}
NS_IMETHODIMP CJSBridge::CreateButton(const char * cmd, const char * menu, const char * tooltip, const char * label, kmIButton * *_retval)
{
CJSButton* button = new CJSButton();
nsresult rv;
void *result;
rv = button->QueryInterface(NS_GET_TEMPLATE_IID(kmIButton), &result);
*_retval = (kmIButton*)result;
return rv;
}
NS_IMETHODIMP CJSBridge::CreateCallbackButton(kmICommandFunction *command, const char * menu, const char * tooltip, const char * label, kmIButton * *_retval)
{
CJSButton* button = new CJSButton();
nsresult rv;
void *result;
rv = button->QueryInterface(NS_GET_TEMPLATE_IID(kmIButton), &result);
*_retval = (kmIButton*)result;
button->id = kPlugin.kFuncs->GetCommandIDs(1);
::GetCmdList()->Add(button->id, command);
return rv;
}

33
k-meleon/JSBridge/jsplugin.cpp

@ -63,7 +63,6 @@ extern NS_COM_GLUE nsresult NS_NewGenericFactory(nsIGenericFactory* *result,
int Load()
{
cmdList = new CCmdList();
return 1;
}
@ -88,7 +87,7 @@ BOOL Init()
BOOL Quit()
{
delete cmdList;
if (cmdList) delete cmdList;
nsresult rv;
nsCOMPtr<nsIComponentRegistrar> compReg;
rv = NS_GetComponentRegistrar(getter_AddRefs (compReg));
@ -160,11 +159,36 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message) {
case WM_COMMAND:
if (cmdList->Run(LOWORD(wParam), lParam)) return 0;
if (cmdList && cmdList->Run(LOWORD(wParam), lParam)) return 0;
}
return CallWindowProc(KMeleonWndProc, hWnd, message, wParam, lParam);
}
/*
static const mozilla::Module::CIDEntry kCIDs[] = {
{ &kJSBridgeCID,true, NULL, CJSBridgeConstructor },
{ NULL }
};
static const mozilla::Module::ContractIDEntry kContracts[] = {
{"@kmeleon/jsbridge;1", &kJSBridgeCID},
{ NULL }
};
static const mozilla::Module::CategoryEntry kCategory[] = {
{ NULL }
};
static const mozilla::Module kModule = {
mozilla::Module::kVersion,
kCIDs,
kContracts,
kCategory
};
NSMODULE_DEFN(nsBrowserCompsModule) = &kModule;*/
extern "C" {
KMELEON_PLUGIN kmeleonPlugin *GetKmeleonPlugin() {
@ -173,3 +197,6 @@ KMELEON_PLUGIN kmeleonPlugin *GetKmeleonPlugin() {
}

7
k-meleon/JSBridge/nsIJSBridge.idl

@ -51,6 +51,8 @@ interface nsIJSBridge : nsISupports
void SetMenu(in string menu,in unsigned short type, in string label, in string command, [optional] in string before);
void RebuildMenu(in string menu);
kmIButton CreateButton(in string cmd, [optional] in string menu, [optional] in string tooltip, [optional] in string label);
kmIButton CreateCallbackButton(in kmICommandFunction command, [optional] in string menu, [optional] in string tooltip, [optional] in string label);
//void AddButton(in string toolbar, in kmIButton button);
void AddButton(in string toolbar, in string command, [optional] in string menu);
void RemoveButton(in string toolbar, in string command);
@ -58,12 +60,13 @@ interface nsIJSBridge : nsISupports
void id(in nsIDOMWindow window, in string id);
long SendMessage(in string plugin, in string to, in string from, in string data1);
void GetCmdList([optional] out unsigned long length, [array, size_is(length), retval] out kmICommand list);
[implicit_jscontext]
long RegisterCmd(in string name, in string desc,
in kmICommandFunction command, [optional] in string icon,
in kmICommandFunction command, [optional] in jsval icon,
[optional] in kmICallback enabled, [optional] in kmICallback checked);
void SetAccel(in string key, in string command);
nsIWebBrowser Open(in string url, in unsigned short state);
nsIWebBrowser GetActiveBrowser();
};

Loading…
Cancel
Save