<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Allen Day's Blog &#187; Javascript</title>
	<atom:link href="http://www.spicylogic.com/allenday/blog/category/computing/software/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.spicylogic.com/allenday/blog</link>
	<description>♥data♥</description>
	<lastBuildDate>Mon, 21 Jun 2010 23:28:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mozilla Firefox Layout DOM and element positioning ; BoxObject Box Object getBoundingClientRect getBoxObjectFor</title>
		<link>http://www.spicylogic.com/allenday/blog/2008/07/19/mozilla-firefox-layout-dom-and-element-positioning-boxobject-box-object-getboundingclientrect-getboxobjectfor/</link>
		<comments>http://www.spicylogic.com/allenday/blog/2008/07/19/mozilla-firefox-layout-dom-and-element-positioning-boxobject-box-object-getboundingclientrect-getboxobjectfor/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 00:55:53 +0000</pubDate>
		<dc:creator>allenday</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.spicylogic.com/allenday/blog/?p=43</guid>
		<description><![CDATA[
Hopefully the keywords I&#8217;m using here will help the next poor soul who has to learn this part of the Mozilla API.  I needed to find where in the window some elements were.  This information is not contained in the usual DOM referred to via the document variable.  There are actually two [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.spicylogic.com/allenday/blog/wp-content/uploads/2008/07/slide0015.gif'><img src="http://www.spicylogic.com/allenday/blog/wp-content/uploads/2008/07/slide0015-300x225.gif" alt="" title="Mozilla Content and Layout DOM" width="300" height="225" class="alignright size-medium wp-image-44" /></a></p>
<p>Hopefully the keywords I&#8217;m using here will help the next poor soul who has to learn this part of the Mozilla API.  I needed to find where in the window some elements were.  This information is not contained in the usual DOM referred to via the <code>document</code> variable.  There are actually two parallel DOMs: the Content DOM (the usual one) and the Layout DOM.  The Layout DOM&#8217;s structure contains all the elements in the Content DOM, but has positional information available to you as <code>BoxObject</code> (Firefox 2.*) or <code>BoundingClientRect</code> (Firefox 3.*) objects.  Read the <a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:Box_Objects">XUL Box Object Tutorial</a></p>
<p>Here&#8217;s how you get the boxes.  For the sake of example, we&#8217;ll refer to the first<br />
<table/> element in the page.</p>
<p>Firefox 2.*:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">tab = document.<span style="color: #006600;">getElementsByTagName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#41;</span>;
tabBox = document.<span style="color: #006600;">getBoxObjectFor</span><span style="color: #66cc66;">&#40;</span>tab<span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">//tabBox.x</span>
<span style="color: #009900; font-style: italic;">//tabBox.y</span>
<span style="color: #009900; font-style: italic;">//tabBox.width</span>
<span style="color: #009900; font-style: italic;">//tabBox.height</span></pre></div></div>

<p>the <code>x, y</code> attributes give the location of the upper-left corner of the element, relative to the browser window.  <code>width, height</code> tell you the size of the element.</p>
<p>Firefox 3.*:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">tab = document.<span style="color: #006600;">getElementsByTagName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#41;</span>;
tabBox = document.<span style="color: #006600;">getBoundingClientRect</span><span style="color: #66cc66;">&#40;</span>tab<span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">//tabBox.left</span>
<span style="color: #009900; font-style: italic;">//tabBox.top</span>
<span style="color: #009900; font-style: italic;">//tabBox.width</span>
<span style="color: #009900; font-style: italic;">//tabBox.height</span></pre></div></div>

<p>The <code>left, top</code> attributes are equivalent to the Firefox 2.* <code>x, y</code> attributes, and <code>width, height</code> have identical meaning.</p>
<p>These docs helped me piece this together:<br />
<a href="http://developer.mozilla.org/en/docs/DOM:element.getBoundingClientRect">http://developer.mozilla.org/en/docs/DOM:element.getBoundingClientRect</a><br />
<a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:Box_Objects<br />
">http://developer.mozilla.org/en/docs/XUL_Tutorial:Box_Objects</a></p>
<p>Some good stuff on MouseEvents I&#8217;m stashing here for my own reference:<br />
<a href="http://developer.mozilla.org/samples/domref/dispatchEvent.html<br />
">http://developer.mozilla.org/samples/domref/dispatchEvent.html</a><br />
<a href="http://blog.stchur.com/blogcode/event-rerouting/">http://blog.stchur.com/blogcode/event-rerouting/</a></p>
<p>Image borrowed from <a href="http://www.mozilla.org/newlayout/doc/layout-2006-07-12/master.xhtml">Mozilla&#8217;s Layout Engine by L. David Baron</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.spicylogic.com/allenday/blog/2008/07/19/mozilla-firefox-layout-dom-and-element-positioning-boxobject-box-object-getboundingclientrect-getboxobjectfor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
