Tiled Gallery: Separate computation from HTML.

Square layout item computation is now separated from the HTML generation logic.