Skip to content

Commit

Permalink
Merge pull request #199 from pec1985/timob-14207
Browse files Browse the repository at this point in the history
[TIMOB-14207] Fixed webview Ti events
  • Loading branch information
Russ McMahon committed Dec 18, 2013
2 parents 9e777e9 + d27365e commit 7045ca1
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/tibb/Modules/App/TiAppModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <bb/ApplicationInfo>
#include <bb/PackageInfo>

#include "TiUIWebView.h"

TiAppModule::TiAppModule(const char* name) : Ti::TiModule(name)
{

Expand Down Expand Up @@ -49,6 +51,24 @@ TiAppModule::~TiAppModule()

}

void TiAppModule::fireEvent(QString eventName, Ti::TiEventParameters eventParams)
{
Ti::TiProxy::fireEvent(eventName, eventParams);
QList<TiUIWebView*> webViews = TiUIWebView::getWebViews();
if(webViews.size() > 0)
{
Ti::TiEventParameters webViewEventParams;
webViewEventParams.addParam("data", eventParams);
webViewEventParams.addParam("id", eventName);

QString json = webViewEventParams.toJsonQString();
for(int i = 0, len = webViews.length(); i < len; i++)
{
webViews.at(i)->getNativeWebView()->postMessage(json);
}
}
}

Ti::TiValue TiAppModule::getModuleId()
{
Ti::TiValue val;
Expand Down
2 changes: 2 additions & 0 deletions src/tibb/Modules/App/TiAppModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class TiAppModule : public Ti::TiModule
virtual Ti::TiValue getModuleVersion();
virtual Ti::TiValue getModuleName();

virtual void fireEvent(QString, Ti::TiEventParameters);

Ti::TiValue fireSystemEvent(Ti::TiValue);
Ti::TiValue getArguments(Ti::TiValue);

Expand Down
3 changes: 3 additions & 0 deletions src/ticore/include/Ti_EventParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class TiEventParameters {
void addParam(QString, TiProxy*);
void addParam(QString, TiEventParameters);
bool contains(QString);

QString toJsonQString();

static void addParametersToObject(Ti::TiEventParameters*, Handle<Object>);
private:
QMap<QString, QString> stringMap;
Expand Down
55 changes: 55 additions & 0 deletions src/ticore/src/Ti_EventParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,61 @@ void Ti::TiEventParameters::addParam(QString key, TiEventParameters value)
objectMap[key] = value;
}

QString Ti::TiEventParameters::toJsonQString()
{
QString json = "{";

foreach(QString key, stringMap.keys())
{
// "key":"value",
json.append("\"").append(key).append("\":\"").append(stringMap[key]).append("\",");
}

foreach(QString key, numberMap.keys())
{
// "key":"value",
json.append("\"").append(key).append("\":\"").append(QString::number(numberMap[key])).append("\",");
}

foreach(QString key, proxyMap.keys())
{
json.append("\"").append(key).append("\":\"").append(proxyMap[key]->getProxyName()).append("\",");
}

foreach(QString key, objectMap.keys())
{
json.append("\"").append(key).append("\":").append(
objectMap[key].toJsonQString()
).append(",");
}

/*
foreach(QString key, arrayMap.keys())
{
json.append("\"").append(key).append("\":");
json.append("[");
foreach(TiEventParameters params, arrayMap[key])
{
json.append(params.toJsonQString()).append(",");
}
if(json.endsWith(","))
{
json.chop(1);
}
json.append("],");
}
*/
if(json.endsWith(","))
{
json.chop(1);
}
json.append("}");

qDebug() << "[TiEventParameters]" << json;

return json;
}

void Ti::TiEventParameters::addParametersToObject(Ti::TiEventParameters* parameters, Handle<Object> object)
{

Expand Down
10 changes: 10 additions & 0 deletions src/ticore/src/Ti_Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ Ti::TiValue Ti::TiProxy::fireEvent(Ti::TiValue value)
{
eventParams.addParam(name, val.toProxy());
}
/*
else if (val.isList())
{
// TODO:
}
else if (val.isMap())
{
// TODO:
}
*/
else // if(val.isString())
{
eventParams.addParam(name, val.toString());
Expand Down

0 comments on commit 7045ca1

Please sign in to comment.