HN user

bgrins

124 karma
Posts2
Comments47
View on HN

I worked on this project - Web Components had a lot to do with it. It's true they weren't feature complete in Firefox when we started the project (notably missing Shadow DOM) - but the first migration from late 2017 was XBL->Custom Element (https://bugzilla.mozilla.org/show_bug.cgi?id=1500626), and we used the migration project to inform performance and feature work for Web Components within Firefox.

We could have converted the bindings to JS modules (and we did plenty of that too), but Web Components were key because they allowed us to migrate in-place with near API compatibility rather than rewriting the UI. I have a post at https://briangrinstead.com/blog/firefox-webcomponents/ with more detail on that point.

There are pros and cons to using web tech for the application UI. To be clear, the old XBL code was already using JS/DOM, so the most obvious pro in this case was that it didn't require completely rewriting Firefox from scratch (which hasn't historically worked out well). I also expect that dogfooding web technologies means we can improve the tooling and web standard implementations in Gecko.

Regarding performance, this work didn't regress anything. Performance is measured on every commit and staying at least at parity was a requirement for the project.

Audio processing works, but certain codecs do not come bundled with it. It should be possible to configure it with --enable-libmp3lame if you had the source alongside and had everything set up correctly. We didn't have time to try this, but the closest thing I found similar to this when researching was: https://github.com/manuels/unix-toolbox.js-imagemagick. You can see that libpng, libjpeg, etc are all being included in the output.

If you'd like to give this a shot, definitely open up an issue on Github and we can talk more about the details!

Thanks! It will be interesting to see how much it will speed up as JS runtimes get faster, and as we are able to apply additional optimizations with Emscripten.

In particular, asm.js is explicitly disabled right now because of the need for memory growth. In the meantime, I'm planning on having a build with it enabled just to benchmark times on smaller files (where the growth is not needed).

Neat project, I just got done doing the 10K Apart contest and this would have saved me a lot of resizing when testing different widths!

http://www.w3.org/TR/CSS2/box.html#margin-properties

When margin top or bottom is a percentage, it refers to the width, not height, of the containing block. If the parent is 100% width (say, the body), the element will move down 50% of your screen width.

Usually, you don't want this, but you can use it to do some cool tricks with keeping the aspect ratio of an element, like this: http://jsfiddle.net/bgrins/999FP/

Hey Matthew, great job on this! I had fun learning this algorithm, too. My implementation is here: https://github.com/bgrins/javascript-astar/blob/master/astar..., and I have a demo here: http://briangrinstead.com/files/astar/

I have added in a few optimizations: in my first run at it (https://github.com/bgrins/javascript-astar/blob/master/astar...) I used a standard array for the open and closed lists, and I found it slowed down quite a bit as the graph size got larger. I switched the implementation to a binary heap, which made it much faster for larger graphs. Try the original demo then the new one at 100x100 to see what I mean :)

Awesome! There are some really things you could use this for. I have done something similar here: https://github.com/bgrins/DrawWindow

I'm interested to look through the source and see how this was implemented. There are many things that are really tricky to handle using the computedStyle way of rendering HTML. Just to name a few:

* Form elements

* Dotted, dashed, rounded borders

* Gradients

* Text with word-wrap: break-word applied (for some reason measuring each character does not work properly here).

* CSS Outlines can be tricky, though I have gotten that to work pretty well in my implementation using getClientRects().

* Overflows / scrolls with fixed width or height divs (and nested ones)

* Iframes

For basic text and images (such as http://bgrins.github.com/DrawWindow/tests/basic.html) it holds up pretty well.

I have thought about the two window browser IDE before and am glad you implemented that idea, I think it could be really useful for quick HTML/CSS comps.

Two small suggestions:

* When in the two window mode, make ctrl+s do an instant refresh on the preview, and preventDefault on the event so that it doesn't open up the browser save window. I save constantly out of habit, so that gets distracting.

* For the 'inspect element' control: Don't use borders on the active element, because it causes the layout to jump around and if you already have a border applied to an element, it wipes it out. The easiest way to fix this would be to use 'outline' instead - and if you apply it with a class instead of inline styles, it will not wipe out existing outlines after leaving (as it does with borders now). If you really want to make it work to not replace existing outlines, see the 'Firebug.Inspector.BoxModelHighlighter' in http://code.google.com/p/fbug/source/browse/branches/firebug... for an implementation that uses completely different elements instead of changing the style of the active element.

Nice, I have noticed the same thing when working with canvas - any time you can get the pixel level manipulation to happen in native objects there are big performance gains to be had.

I am interested on the general idea behind your new import an existing site feature. I have played around with this a little bit before, and realize that there is no way to directly render HTML onto a canvas (unless of course you have add on permissions in firefox, like this: https://developer.mozilla.org/en/drawing_graphics_with_canva...). Then of course there is something like this: http://www.cuppadev.co.uk/projects/a-browser-within-a-browse... which seems a little incomplete.

I assume you build up the elements array from the elements in the DOM, and manually generate a canvas for each one? That seems like it would be quite tedious, and handling inherited styles, etc could be a pain. Also, once you start moving elements around, they may not really have a place in the HTML anymore, so if I want to share the mockup, is it just an image, or does it become absolutely positioned HTML elements?

Great job on this by the way, I'm impressed with how well it is working.

For a tiled repeating background, I would recommend looking into createPattern function https://developer.mozilla.org/en/Canvas_tutorial/Applying_st....

You can use code like this:

    context.fillStyle = context.createPattern(img, 'repeat');
    context.fillRect(0, 0, 100, 100);
Where 'img' is an Image object you loaded from an src, or even a canvas object that you may have used to build a composite background.

If this doesn't work in your situation, I would at least build this image once in a canvas in memory (using document.createElement), and reference it in the 'drawImage' function instead of building it from scratch each time. Though it sounds like you might already be doing this. Do you have a link to your game?