Tab switcher: live pages in a fan

Four pages of one small app, each in a same-origin <iframe> inside a canvas, drawn as a hand of cards. The cards are the running pages: start the timer on one card and the others show the time, pick a colour in Settings and every card changes. Tap inside a card to use the page. Tap a card's title bar to open it at full size, and tap the bar again to go back. Drag sideways on the bars or the background to turn the fan.

 

Show the code the pose of a card, the draw, the title bars
  1. The markup. Four iframes with drawable.
  2. Where a card goes. An angle on a circle for the fan, the middle of the canvas when open, and a blend of the two in between.
  3. On paint. Rotate, scale and draw each iframe, then draw its title bar.
  4. Input on the title bars. The bars are canvas drawing, so the page hit tests them itself.
  5. How the pages talk to each other. One BroadcastChannel.
  6. Styles.

How it works

Each iframe is laid out at 300 by 440 CSS pixels, so its page sees a phone-sized viewport at all times. On every paint event the canvas works out a pose for each card: a centre, an angle and a scale. In the fan the centres lie on a circle whose middle is 380 pixels below the canvas, 11 degrees apart, at about 0.6 scale. drawElementImage() draws the iframe under that transform and puts its hit region there, so a tap on a rotated card reaches the page inside it at the right place.

A change inside any iframe raises the canvas's paint event, so the page runs no timer for the cards. The title in a card's bar is read from iframe.contentDocument.title on each paint. The Timer page puts the running time in its title.

The title bars and the close marks are drawn by the canvas and aren't elements. Pointer events over them go to the canvas, and the page maps the pointer into each card's own coordinates with the inverse of the card's matrix.

Opening a card blends its pose towards the middle of the canvas at the largest scale that fits. The other cards drop below the canvas, and their hit regions are shrunk to a point so they take no input. Where two cards overlap, the one drawn last is on top in the picture and also takes the tap.

The iframes are added and removed from click handlers, never inside the paint event: Chromium 157 crashes if an iframe is inserted or removed there.

Live checks

These run on their own small iframes in the corner of the window.

Findings