An installed app whose window frame is a canvas

An installed web app with window-controls-overlay may paint the title bar itself, and CSS marks the parts of it that drag the window. I wanted to know whether one canvas can draw the whole window: a title bar that is a live element with tabs, a text field and window buttons, the content under it, and a drag region that is drawn somewhere other than its layout box. The frame below runs the app in a simulated window. Drag it by its title bar, press the tabs, and type in the title field. The same app can be installed to try the real window.

Canvas window

The simulated window hasn't been dragged.

The system draws
System buttons
Title bar height 38 px
Window

Install it

Open the app in this tab
  1. Install the app on a desktop computer, from the button above or from the browser's menu on the app page.
  2. In the app's window, press the chevron in the title bar to turn on the window controls overlay. The canvas then paints up to the window buttons.
  3. Run "Test 1" and "Test 2" in the app. Each watches the window position for ten seconds while you drag. The app then states whether the drag region is where the block is drawn or where its layout box is.
  4. Press the app's "minimize()", "maximize() or restore()" and "close()" buttons. It reports whether window.minimize(), maximize() and restore() exist and what they did.
Show the code a window drawn by one canvas
  1. The manifest asks for the window controls overlay.
  2. One canvas with three children: the title bar, the body, and the block for the drag test.
  3. The drag region is CSS on the title bar element. app-region is the property that browsers have now. window-drag is the newer name.
  4. What the app asks the window: the free part of the title bar, the position, whether it's active.
  5. Size the bar to the title bar area.
  6. Draw the window. The colour behind the bar, the glow under the pointer and the grey of an inactive window are drawn by the canvas, around the picture of the bar element.
  7. Lay out again when the overlay, the size or the focus changes.
  8. The simulated window on this page. It finds the drag region with elementFromPoint() and the computed app-region.

How it works

The app is one page with one canvas that covers the window. The title bar is a <header> with app-region: drag, and its buttons and text field have app-region: no-drag. With the overlay on, navigator.windowControlsOverlay.getTitlebarAreaRect() gives the rectangle the system buttons leave free. The app sizes the header to that rectangle and draws it there. The canvas paints the full width of the strip first, so its colour continues under the system buttons.

The simulated window is a frame with the same app in it. This page gives the app a simulated title bar rectangle and window position in place of the real ones. To decide whether a press drags the window, it asks the frame's document for the element at the pointer and reads the computed app-region of that element and its ancestors. That follows the position where the canvas drew the element. A real window manager gets its drag regions from the browser by another route, so the simulation doesn't answer what a real window does. The two tests inside the app do, once it's installed.

Live checks

These run on a second copy of the app in a panel at the bottom of the window, not on the window above. They wait for a tap.

Findings