Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Binding to HTML (again)

5 views
Skip to first unread message

Mike5

unread,
Nov 24, 2009, 3:59:04 AM11/24/09
to
I'm struggling with binding XBL to tags in the HTML document. So far,
no success, even though everyone and everything tells me, this works.

HTML:
<html>
<head>
<title>CAML test</title>
<style type="text/css">
csl_smiley {
-moz-binding: url("camlext.xml#csl_smiley");
border: 1px dotted black;
display: block;
width: 200px;
height: 150px;
overflow: hidden;
}
</style>
</head>
<body>
<div style="border:1px solid red;">Before</div>
<csl_smiley>Blah.</csl_smiley>
<div style="border:1px solid red;">After</div>
</body>
</html>

XBL:
<?xml version="1.0"?>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul">
<binding id="csl_smiley">
<content>
<html:p>I am here</html:p>
<xul:description value="Test 1">Test.</xul:description>
</content>
</binding>
</bindings>

So far, the only thing I see is the box defined by the style (or in
case I delete everything but the -moz-binding line - nothing). Can
someone help with this?

Also, for step 2: I'd like to do all this from an extension - no
explicit declarations in the HTML, if possible. It can be done by
injecting some things into the document, but I'd really like to avoid
putting the work on the user.

Thanks in advance, Miha

Boris Zbarsky

unread,
Nov 24, 2009, 9:09:29 AM11/24/09
to
On 11/24/09 3:59 AM, Mike5 wrote:
> <content>
> <html:p>I am here</html:p>
> <xul:description value="Test 1">Test.</xul:description>
> </content>

An XBL binding that doesn't provide insertion points for all the
element's kids won't have its content shown. You need a <children/> in
there somewhere.

> Also, for step 2: I'd like to do all this from an extension - no
> explicit declarations in the HTML, if possible. It can be done by
> injecting some things into the document, but I'd really like to avoid
> putting the work on the user.

Use a UA stylesheet to do the binding.

-Boris

Mike5

unread,
Nov 25, 2009, 7:38:35 AM11/25/09
to
On Nov 24, 3:09 pm, Boris Zbarsky <bzbar...@mit.edu> wrote:
> On 11/24/09 3:59 AM, Mike5 wrote:
>
> >      <content>
> >        <html:p>I am here</html:p>
> >        <xul:description value="Test 1">Test.</xul:description>
> >      </content>
>
> An XBL binding that doesn't provide insertion points for all the
> element's kids won't have its content shown.  You need a <children/> in
> there somewhere.

Thanks. It's finally starting to display something. But now I have a
problem with namespaces. For example, see this XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns:caml="http://ns.example.com">


<head>
<title>CAML test</title>
<style type="text/css">

@namespace caml url("http://ns.example.com");
caml|csl_smiley {


-moz-binding: url("camlext.xml#csl_smiley");
border: 1px dotted black;
display: block;
width: 200px;
height: 150px;
overflow: hidden;
}
</style>
</head>
<body>
<div style="border:1px solid red;">Before</div>

<caml:csl_smiley> Bla text.</caml:csl_smiley>


<div style="border:1px solid red;">After</div>
</body>
</html>

Again, nothing happens. If I leave everything in a default namespace,
then it works.

> > Also, for step 2: I'd like to do all this from an extension - no
> > explicit declarations in the HTML, if possible.
>

> Use a UA stylesheet to do the binding.

Is this the way to do it (from my chrome.manifest file):

skin camlext camlskin skin/
style chrome://browser/content/browser.xul chrome://camlext/skin/camlext.css

?

Thanks and best regards, Miha

Boris Zbarsky

unread,
Nov 25, 2009, 1:00:43 PM11/25/09
to
On 11/25/09 7:38 AM, Mike5 wrote:
> Thanks. It's finally starting to display something. But now I have a
> problem with namespaces. For example, see this XHTML:
> <html xmlns:caml="http://ns.example.com">

This isn't in the XHTML namespace. Are you actually loading this file
as XHTML, or are you loading it as HTML? The caml:csl_smiley business
won't do what you think in the latter case, of course.

If I load the file as XHTML and set the default namespace on the root
there to the XHTML one, it all works fine for me.

> skin camlext camlskin skin/
> style chrome://browser/content/browser.xul
chrome://camlext/skin/camlext.css

That applies your css to the web browser UI. You want to apply it to
web pages, no?

The right way to do that is using nsIStyleSheetService.

-Boris

Mike5

unread,
Nov 25, 2009, 3:34:30 PM11/25/09
to
On Nov 25, 7:00 pm, Boris Zbarsky <bzbar...@mit.edu> wrote:
> On 11/25/09 7:38 AM, Mike5 wrote:
>
> > Thanks. It's finally starting to display something. But now I have a
> > problem with namespaces. For example, see this XHTML:
> > <html xmlns:caml="http://ns.example.com">
>
> This isn't in the XHTML namespace.  Are you actually loading this file
> as XHTML, or are you loading it as HTML?  The caml:csl_smiley business
> won't do what you think in the latter case, of course.
>
> If I load the file as XHTML and set the default namespace on the root
> there to the XHTML one, it all works fine for me.

I see I've got a lot to learn about Firefox and XHTML, since I thought
that the DOCTYPE forces the browser to use XHTML. Can you please tell
me explicitly what to do to load it as XHTML. Setting the default
namespace to XHTML I know how to do :)

>
> That applies your css to the web browser UI.  You want to apply it to
> web pages, no?
>
> The right way to do that is using nsIStyleSheetService.

Thank you for the pointer. I'll look into it.

Br, Miha

Boris Zbarsky

unread,
Nov 25, 2009, 4:12:04 PM11/25/09
to
On 11/25/09 3:34 PM, Mike5 wrote:
> I see I've got a lot to learn about Firefox and XHTML, since I thought
> that the DOCTYPE forces the browser to use XHTML. Can you please tell
> me explicitly what to do to load it as XHTML.

The MIME type needs to be application/xhtml+xml. If this is being
loaded as a local file, not over HTTP, then the extension needs to be
.xhtml or .xht on Windows, or you need to do whatever will make the OS
MIME setup provide the right MIME type in general (extension is likely
to do it on Linux and Mac OS X; can't speak for other operating systems).

-Boris

Mike5

unread,
Nov 26, 2009, 1:37:47 AM11/26/09
to

Well, all I can say is "DOH!". I wasn't paying attention to my file
extension. Thank you, thank you, thank you!!!!

Miha

Mike5

unread,
Nov 26, 2009, 4:13:55 AM11/26/09
to
Boris, thank you for all your help. I now seem to have the basic setup
working. It's time to move on to some actual content/behavior.

Tei

unread,
Nov 26, 2009, 1:08:24 PM11/26/09
to dev-te...@lists.mozilla.org
Totally off-topic snip of code

var xhtml = "http://www.w3.org/1999/xhtml";
var div = document.createElementNS(xhtml,"div");
div.setAttribute("style","border:0px solid gray");

From here:
http://userscripts.org/scripts/review/54647

This snip of code add HTML to XML like this one:
http://api.erepublik.com/v1/feeds/countries

'
I found it fun that is possible to add a HTML node to a XML tree,
...probably is possible to add XUL nodes to HTML tress, to have XUL
widgets (like <calendar> ) in html.


On Thu, Nov 26, 2009 at 10:13 AM, Mike5 <miha.vi...@gmail.com> wrote:
> Boris, thank you for all your help. I now seem to have the basic setup
> working. It's time to move on to some actual content/behavior.

> _______________________________________________
''


--
--
ℱin del ℳensaje.

0 new messages