[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r12320: implement calling Actionscri
From: |
Rob Savoye |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r12320: implement calling Actionscript methods from Javascript. |
Date: |
Tue, 20 Jul 2010 12:21:26 -0600 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 12320
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Tue 2010-07-20 12:21:26 -0600
message:
implement calling Actionscript methods from Javascript.
modified:
gui/Player.cpp
libcore/movie_root.cpp
libcore/movie_root.h
=== modified file 'gui/Player.cpp'
--- a/gui/Player.cpp 2010-07-19 20:13:29 +0000
+++ b/gui/Player.cpp 2010-07-20 18:21:26 +0000
@@ -667,7 +667,6 @@
return "";
}
-
if (event == "System.capabilities.screenResolutionX") {
std::ostringstream ss;
ss << _gui.getScreenResX();
=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp 2010-07-19 20:13:29 +0000
+++ b/libcore/movie_root.cpp 2010-07-20 18:21:26 +0000
@@ -1560,23 +1560,24 @@
if (_interfaceHandler) _interfaceHandler->exit();
} else if (invoke->name == "SetVariable") {
- // SetVariable doesn't send a response
MovieClip *mc = getLevel(0);
as_object *obj = getObject(mc);
string_table &st = getStringTable(*obj);
std::string var = invoke->args[0].to_string();
as_value &val = invoke->args[1] ;
obj->set_member(st.find(var), val);
+ // SetVariable doesn't send a response
} else if (invoke->name == "GetVariable") {
+ MovieClip *mc = getLevel(0);
+ as_object *obj = getObject(mc);
+ string_table &st = getStringTable(*obj);
+ std::string var = invoke->args[0].to_string();
+ as_value val;
+ obj->get_member(st.find(var), &val);
// GetVariable sends the value of the variable
- MovieClip *mc = getLevel(0);
- as_object *obj = getObject(mc);
- string_table &st = getStringTable(*obj);
- std::string var = invoke->args[0].to_string();
- as_value val;
- obj->get_member(st.find(var), &val);
ss << ExternalInterface::toXML(val);
} else if (invoke->name == "GotoFrame") {
+ log_unimpl("ExternalInterface::GotoFrame()");
// GotoFrame doesn't send a response
} else if (invoke->name == "IsPlaying") {
std::string result = callInterface("ExternalInterface.IsPlaying");
@@ -1586,21 +1587,21 @@
log_unimpl("ExternalInterface::LoadMovie()");
// LoadMovie doesn't send a response
} else if (invoke->name == "Pan") {
+ std::string arg = invoke->args[0].to_string();
+ arg += ":";
+ arg += invoke->args[0].to_string();
+ arg += ":";
+ arg += invoke->args[1].to_string();
+ arg += ":";
+ arg += invoke->args[2].to_string();
+ callInterface("ExternalInterface.Pan", arg);
// Pan doesn't send a response
- std::string arg = invoke->args[0].to_string();
- arg += ":";
- arg += invoke->args[0].to_string();
- arg += ":";
- arg += invoke->args[1].to_string();
- arg += ":";
- arg += invoke->args[2].to_string();
- callInterface("ExternalInterface.Pan", arg);
} else if (invoke->name == "PercentLoaded") {
- // PercentLoaded sends the percentage
MovieClip *mc = getLevel(0);
int loaded = mc->get_bytes_loaded();
int total = mc->get_bytes_total();
as_value val((loaded/total) * 100);
+ // PercentLoaded sends the percentage
ss << ExternalInterface::toXML(val);
} else if (invoke->name == "Play") {
callInterface("ExternalInterface.Play");
@@ -1621,7 +1622,7 @@
callInterface("ExternalInterface.SetZoomRect", arg);
// SetZoomRect doesn't send a response
} else if (invoke->name == "StopPlay") {
- callInterface("ExternalInterface.SetZoomRect");
+ callInterface("ExternalInterface.StopPlay");
// StopPlay doesn't send a response
} else if (invoke->name == "Zoom") {
std::string var = invoke->args[0].to_string();
@@ -1806,10 +1807,15 @@
movie_root::addExternalCallback(as_object *obj, const std::string &name,
as_object *callback)
{
- GNASH_REPORT_FUNCTION;
+ // GNASH_REPORT_FUNCTION;
- _externalCallbacks.push_back(ExternalCallback(obj, name, callback));
+ MovieClip *mc = getLevel(0);
+ as_object *me = getObject(mc);
+ string_table &st = getStringTable(*me);
+ obj->set_member(st.find(name), callback);
+ // When an external callback is added, we have to notify the plugin
+ // that this method is available.
if (_hostfd) {
std::vector<as_value> fnargs;
fnargs.push_back(name);
@@ -1841,8 +1847,8 @@
movie_root::callExternalJavascript(const std::string &name,
const std::vector<as_value> &fnargs)
{
+ // GNASH_REPORT_FUNCTION;
std::string result;
- ExternalCallbacks::const_iterator it;
// If the browser is connected, we send an Invoke message to the
// browser.
if (_controlfd && _hostfd) {
@@ -1868,35 +1874,50 @@
movie_root::callExternalCallback(const std::string &name,
const std::vector<as_value> &fnargs)
{
+ // GNASH_REPORT_FUNCTION;
+
+ MovieClip *mc = getLevel(0);
+ as_object *obj = getObject(mc);
+ string_table &st = getStringTable(*obj);
+ string_table::key key = st.find(name);
+ // FIXME: there has got to be a better way of handling the variable
+ // length arg list
+ as_value val;
+ switch (fnargs.size()) {
+ case 0:
+ val = callMethod(obj, st.find(name));
+ break;
+ case 1:
+ val = callMethod(obj, st.find(name), fnargs[0]);
+ break;
+ case 2:
+ val = callMethod(obj, st.find(name), fnargs[0], fnargs[1]);
+ break;
+ case 3:
+ val = callMethod(obj, st.find(name), fnargs[0], fnargs[1],
+ fnargs[2]);
+ break;
+ default:
+ val = callMethod(obj, st.find(name));
+ break;
+ }
+
+
std::string result;
- ExternalCallbacks::const_iterator it;
- for (it=_externalCallbacks.begin(); it != _externalCallbacks.end(); it++) {
- ExternalCallback ec = *it;
- log_debug("Checking %s against method name: %s", name,
ec.methodName());
-
- // FIXME: call the AS method here!
-
- as_value val;
- if (name == ec.methodName()) {
- std::string result;
- val = ec.call(fnargs);
- }
-
- if (val.is_null()) {
- // Return an error
- result = ExternalInterface::makeString("Error");
- } else {
- result = ExternalInterface::toXML(val);
- }
-
- // If the browser is connected, we send an Invoke message to the
- // browser.
- if (_hostfd) {
- const size_t ret = ExternalInterface::writeBrowser(_hostfd,
result);
- if (ret != result.size()) {
- log_error(_("Could not write to browser fd #%d: %s"),
- _hostfd, std::strerror(errno));
- }
+ if (val.is_null()) {
+ // Return an error
+ result = ExternalInterface::makeString("Error");
+ } else {
+ result = ExternalInterface::toXML(val);
+ }
+
+ // If the browser is connected, we send an Invoke message to the
+ // browser.
+ if (_hostfd) {
+ const size_t ret = ExternalInterface::writeBrowser(_hostfd, result);
+ if (ret != result.size()) {
+ log_error(_("Could not write to browser fd #%d: %s"),
+ _hostfd, std::strerror(errno));
}
}
@@ -1904,29 +1925,6 @@
}
void
-movie_root::ExternalCallback::setReachable() const
-{
- _caller->setReachable();
-}
-
-as_value
-movie_root::ExternalCallback::call(const std::vector<as_value>& /*args*/)
-{
- GNASH_REPORT_FUNCTION;
-
-#if 0
- as_environment env(VM::get());
- fn_call::Args newargs;
- as_function *as_func = _callback->to_function();
- fn_call fn(0, env, newargs);
-
- as_func->call(fn);
-#endif
-
- return as_value();
-}
-
-void
movie_root::add_key_listener(Button* listener)
{
add_listener(_keyListeners, listener);
=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h 2010-07-19 08:08:00 +0000
+++ b/libcore/movie_root.h 2010-07-20 18:21:26 +0000
@@ -165,25 +165,7 @@
SimpleBuffer _buf;
as_object* _obj;
};
- typedef std::list<LoadCallback> LoadCallbacks;
-
- class ExternalCallback {
- public:
- ExternalCallback(as_object *obj, const std::string &name,
- as_object *callback)
- : _name(name),
- _caller(obj),
- _callback(callback)
- {}
- std::string &methodName() { return _name; };
- as_value call(const std::vector<as_value>& args);
- void setReachable() const;
- private:
- std::string _name;
- as_object *_caller;
- as_object *_callback;
- };
- typedef std::list<ExternalCallback> ExternalCallbacks;
+ typedef std::list<LoadCallback> LoadCallbacks;
typedef std::bitset<key::KEYCOUNT> Keys;
@@ -1089,8 +1071,6 @@
LoadCallbacks _loadCallbacks;
- ExternalCallbacks _externalCallbacks;
-
typedef std::map<int, Timer*> TimerMap;
TimerMap _intervalTimers;
unsigned int _lastTimerId;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r12320: implement calling Actionscript methods from Javascript.,
Rob Savoye <=