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.
The simulated window hasn't been dragged.
Install it
- Install the app on a desktop computer, from the button above or from the browser's menu on the app page.
- 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.
- 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.
- Press the app's "minimize()", "maximize() or restore()" and "close()" buttons. It reports whether
window.minimize(),maximize()andrestore()exist and what they did.
Show the code a window drawn by one canvas
- The manifest asks for the window controls overlay.
- One canvas with three children: the title bar, the body, and the block for the drag test.
- The drag region is CSS on the title bar element.
app-regionis the property that browsers have now.window-dragis the newer name. - What the app asks the window: the free part of the title bar, the position, whether it's active.
- Size the bar to the title bar area.
- 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.
- Lay out again when the overlay, the size or the focus changes.
- The simulated window on this page. It finds the drag region with
elementFromPoint()and the computedapp-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
- One canvas can draw a whole window, title bar included. The bar is an element. Its tabs take clicks and its text field takes typing where the canvas draws them, in the simulated window, by mouse and by emulated touch.
- What the canvas adds to the bar is drawn around the element's picture. The gradient under the bar, the glow that follows the pointer and the grey of an inactive window are canvas drawing. The element itself has a transparent background.
- The computed
app-regionis readable on an element found at its drawn position.elementFromPoint()at the picture of the orange block returns the block, 150 px from its layout box, and its computed style saysdrag. At the layout box it returns the body. A simulated window built on those two calls therefore drags from the picture. - Whether a real window drags from the picture or from the layout box isn't known. The browser sends the window manager a list of drag rectangles. This page can't see that list, and the test browser has no installed-app window. The app's two tests measure it from the change of
screenXandscreenY. window-dragisn't in the test browsers. Chromium 153 and 157 acceptapp-region: dragand rejectwindow-drag: draginCSS.supports(). The app sets both.- The windowing calls are missing in a tab.
window.minimize,maximize,restore,setResizableandsetShapeare undefined in the test browsers, and so isnavigator.install. The app's buttons report what they find where it runs. Window Shape is limited to allowlisted Isolated Web Apps on ChromeOS and wasn't tried. - A drag region gives the page no pointer events. In a real window, a pointer over the bar's drag region is the system's, so the glow can't follow it there. It follows the pointer over the tabs and the field, which aren't drag regions.