Questions of the codes

5 views
Skip to first unread message

kong

unread,
Nov 10, 2009, 2:03:03 AM11/10/09
to google-gadgets-for-linux-user
Hi, i am studying the source code of google-gadgets-for-linux, and
i do not understand how does js engine work?

Example
main.xml
<view width="110" height="110"
onopen="_view_onopen()">

<script src="main.js"/>

<img name="HourHand" src="hourhand.png"
x="52" y="52" pinX="3" pinY="27" />
</view>

main.js

function UpdateHourHand(Now)
{
var Hours = Now.getHours();
if(Hours >= 12) Hours -= 12;

var Minutes = Now.getMinutes() + (60 * Hours);

HourHand.rotation = Minutes / 2;
}


Does it need to create a js object of "HourHand" ?
If yes, where and when?

Thanks!

James Su

unread,
Nov 10, 2009, 2:16:02 AM11/10/09
to google-gadgets...@googlegroups.com
There is a js object named "HourHand", but it actually a wrapper of a C++ object, in this case, an ImgElement object. The js object wrapper will be created when loading the gadget, see the Initialize() method in ggadget/gadget.cc (line 210-395), especially line 363:

...
    if (!main_view_->scriptable()->InitFromXML(main_xml, kMainXML)) {
      LOG("Failed to setup the main view");
      main_view_->view()->Alert(StringPrintf(GM_("GADGET_LOAD_FAILURE"),
                                             base_path_.c_str()).c_str());
      return false;
    }
...

You can find the code of InitFromXML() method in ggadget/scriptable_view.cc (line 155-214). You can read this part to see how the main.xml file is loaded. But if you want to understand how does an element is injected into the javascript context, you need to read more code, especially:

ggadget/scriptable_interface.h
ggadget/scriptable_helper.h
ggadget/scriptable_helper.cc
ggadget/script_context_interface.h

Maybe also a real script runtime implementation, eg:
extensions/smjs_script_runtime/*

Regards
James Su

xz kong

unread,
Nov 10, 2009, 2:20:52 AM11/10/09
to google-gadgets...@googlegroups.com
Thanks for your reply.

xz kong

unread,
Nov 10, 2009, 2:25:11 AM11/10/09
to google-gadgets...@googlegroups.com
I have another question: what is the relationship of View and ScriptableView?
Thanks!

On Tue, Nov 10, 2009 at 3:16 PM, James Su <jame...@gmail.com> wrote:

James Su

unread,
Nov 10, 2009, 2:29:47 AM11/10/09
to google-gadgets...@googlegroups.com
According to the comment of ScriptableView class: ScriptableView is a scriptable wrapper for View class.
If you want know what does "scriptable" stand for, please refer to scriptable_interface.h. In short, a scriptable object is an object that can be called from javascript.

Regards
James Su

On Tue, Nov 10, 2009 at 3:25 PM, xz kong <kong...@gmail.com> wrote:

I have another question: what is the relationship of View and ScriptableView?
Thanks!
Reply all
Reply to author
Forward
0 new messages