SAT - Dave's Blog

Search
My timeline on Mastodon

Tiny browser features: JSBrowser zoom

2018 May 10, 3:49

JSBrowser is a basic browser built as a Win10 JavaScript UWP app around the WebView HTML element. Its fun and relatively simple to implement tiny browser features in JavaScript and in this post I'm implementing zoom.

My plan to implement zoom is to add a zoom slider to the settings div that controls the scale of the WebView element via CSS transform. My resulting zoom change is in git and you can try the whole thing out in my JSBrowser fork.

Slider

I can implement the zoom settings slider as a range type input HTML element. This conveniently provides me a min, max, and step property and suits exactly my purposes. I chose some values that I thought would be reasonable so the browser can scale between half to 3x by increments of one quarter. This is a tiny browser feature after all so there's no custom zoom entry.

<a><label for="webviewZoom">Zoom</label><input type="range" min="50" max="300" step="25" value="100" id="webviewZoom" /></a>

To let the user know this slider is for controlling zoom, I make a label HTML element that says Zoom. The label HTML element has a for attribute which takes the id of another HTML element. This lets the browser know what the label is labelling and lets the browser do things like when the label is clicked to put focus on the slider.

Scale

There are no explicit scale APIs for WebView so to change the size of the content in the WebView we use CSS.

        this.applyWebviewZoom = state => {
const minValue = this.webviewZoom.getAttribute("min");
const maxValue = this.webviewZoom.getAttribute("max");
const scaleValue = Math.max(Math.min(parseInt(this.webviewZoom.value, 10), maxValue), minValue) / 100;

// Use setAttribute so they all change together to avoid weird visual glitches
this.webview.setAttribute("style", [
["width", (100 / scaleValue) + "%"],
["height", "calc(" + (-40 / scaleValue) + "px + " + (100 / scaleValue) + "%)"],
["transform", "scale(" + scaleValue + ")"]
].map(pair => pair[0] + ": " + pair[1]).join("; "));
};

Because the user changes the scale at runtime I accordingly replace the static CSS for the WebView element with the script above to programmatically modify the style of the WebView. I change the style with one setAttribute call to do my best to avoid the browser performing unnecessary work or displaying the WebView in an intermediate and incomplete state. Applying the scale to the element is as simple as adding 'transform: scale(X)' but then there are two interesting problems.

The first is that the size of the WebView is also scaled not just the content within it. To keep the WebView the same effective size so that it still fits properly into our browser UI, we must compensate for the scale in the WebView width and height. Accordingly, you can see that we scale up by scaleValue and then in width and height we divide by the scaleValue.

transform-origin: 0% 0%;

The other issue is that by default the scale transform's origin is the center of the WebView element. This means when scaled up all sides of the WebView would expand out. But when modifying the width and height those apply relative to the upper left of the element so our inverse scale application to the width and height above aren't quite enough. We also have to change the origin of the scale transform to match the origin of the changes to the width and height.

PermalinkCommentsbrowser css-transform javascript JS jsbrowser uwp webview win10

Tweet from Alex Norris

2016 Oct 5, 9:42
trying to join a twitter conversation between people you admire
PermalinkComments

Tweet from David Risney

2016 Aug 23, 1:48
Loved @PFTompkins ep of @SamplerShow https://gimletmedia.com/episode/25-paul-f-tompkins-the-mayor-of-podcastland/  including PFTs reaction to Ice-Ts reaction to fake Ice-T PFT conversation.
PermalinkComments

Retweet of thegrugq

2015 Dec 21, 5:26
Succinct explanation of the Dual EC travesty as realized in the Juniper debacle.https://storify.com/thegrugq/conversation-with-stewartbaker-ethan-heilman-matth … pic.twitter.com/tR1dDuJm8u
PermalinkComments

Retweet of lamutsa

2015 Oct 20, 7:36
@USATODAY will you release this cover too? pic.twitter.com/d0VnrrhQzD
PermalinkComments

When they went to the Moon, they received the same per diem...

2012 Aug 28, 4:38


When they went to the Moon, they received the same per diem compensation as they would have for being away from base in Bakersfield: eight dollars a day, before various deductions (like for accommodation, because the government was providing the bed in the spaceship).

theatlantic:

Apollo 11’s Astronauts Received an $8 Per Diem for the Mission to the Moon

The astronauts of Apollo 11: Intrepid explorers. Inspirational heroes. Government employees.

Read more. [Image: Reuters]

PermalinkCommentshumor space nasa moon government

Gangnam Style looks like he’s riding a horse but actually...

2012 Aug 24, 1:29


Gangnam Style looks like he’s riding a horse but actually its satire.

Also, the making of video: http://youtu.be/9HPiBJBCOq8

PermalinkCommentshumor music music-video video psy south-korea

Funny People: Steve Heinrich, You Don’t Know Jack head writer | Interview | The Gameological Society

2012 Jul 1, 3:38

A veteran of the satirical trivia game series since its first heyday in the 1990s, Heinrich talks about Jack’s writing process, its long hiatus, and that short-lived live-action TV version.

PermalinkCommentsgame interview video-game you-dont-know-jack ydkj

Matter Anti-Matter: The Revolution Will Not Be Televised

2012 Jun 7, 3:07

ensignau:

The conversation surrounding how to liberate HBO from its cable partners and create the entertainment utopia viewers have long desired has been fascinating.

The resulting analyses of the numbers has pretty much shown that the amount people are willing to pay is not nearly enough to…

PermalinkCommentstv economics youtube video internet web

paulftompkins: So! Here is the trailer for a web series I’ll be...

2012 May 6, 7:31


paulftompkins:

So! Here is the trailer for a web series I’ll be hosting, where I chat with cool people over actual alcoholic drinks. We’ve shot a dozen of these so far and I am grateful to have been asked to host them.  I got to have interesting conversations with strangers and friends alike.

It goes live on Monday 5/7!

Internet terms!

PermalinkCommentshumor paul-f-tompkins interview youtube video

The three terrifying minutes that created The Gunstringer

2011 Sep 29, 8:35This story is funny and also reminds me to go eat at Matador... "Twisted Pixel chief creative officer Josh Bear had responded with abounding confidence, if only to mask the truth. Because the fact of the matter, the fact that he and CEO Mike Wilford were all too aware of, as they sat in Redmond, WA Tex-Mex restaurant The Matador, was this: The idea wasn't "awesome." It was nonexistent."
PermalinkCommentsfood microsoft game gunstringer humor technical

LulzSec manifesto: "We screw each other over for a jolt of satisfaction"

2011 Jun 20, 2:09"Why did the hackers at Lulz Security ("LulzSec") invade Sony Pictures websites, take down cia.gov, and release 60,000+ e-mail addresses and passwords? For the lulz, of course—but what might look lulzy to one person could certainly enrage another. In honor of its 1,000th tweet, the witty wankers of LulzSec released a manifesto of sorts, defending their actions to the angry Internets."PermalinkCommentsinternet security privacy hack technical

Telltale Games times 'Back to the Future' project - Game Hunters: In search of video games and interactive awesomeness - USATODAY.com

2010 Sep 1, 12:42Christopher Lloyd will voice Doc Brown in the Back to the Future game series
PermalinkCommentsgame videogame backtothefuture bttf christopher-lloyd

File-sharing has weakened copyright - and helped society

2010 Jul 1, 3:33"By charting the production of new books, new music albums, and new feature films over the last decade, the authors tried to see whether creative output went up or down in correlation with file-sharing." They find that creative output is going up while piracy also increases. But this is correlation not causation. They can't say there wouldn't be more creative output with less piracy. Regardless, still an interesting statistic.PermalinkCommentsarstechnica copyright law economics ip piracy music technical

INTERCAL -- the Language From Hell

2010 May 10, 5:21An old article by Charles Stross on INTERCAL the satirical programming language. It contains great features such as 'come from' the inverse of 'goto'.PermalinkCommentsc programming humor technical language software charles-stross intercal goto

Childrens' Hospital: Watch Full Episodes on TheWB.com. Starring Hot Tub Time Machine's Rob Corddry

2010 Apr 5, 10:41A satirical hospital drama TV show starring tons of humorous people like Rob Corddry, David Wain, Jason Sudeikis and many many more people who you will recognize but not necessarily know their name.PermalinkCommentshumor tv hospital satire rob-corddry

YouTube - Charlie Brooker - How To Report The News

2010 Jan 30, 2:26Similar to the "This is the title of a typical incendiary blog post" (http://faultline.org/index.php/site/item/incendiary/) except this is a typical news report. "...and this is a lighthouse keeper being beheaded by a lighthouse beam."PermalinkCommentsbbc humor video via:waxy satire journalism tv news

Don't Be Afraid: Passengers Break into "Hey Jude" During Newark Scare | NBC New York

2010 Jan 5, 5:47Oppresive airport security brings people together! 'A traveling guitarist is becoming viral sensation after leading a group of passengers in a rousing round of the Beatles' classic "Hey Jude" while stuck at Newark airport over the weekend.' Includes videoPermalinkCommentsvideo humor airport security music beatles

Every College Student Should Just Buy a Typewriter - Typewriters - Gizmodo

2009 Dec 11, 5:13"A real true history lesson: Before there were laptops, everyone had to carry entire desktop computers to class. Before there were desktops, they had to lug typewriters. Before that, everyone just tried real hard to remember stuff. Ask your grandparents!"PermalinkCommentshumor typewriter satire laptop college

McSweeney's Internet Tendency: It's Decorative Gourd Season, Motherf*rs.

2009 Oct 27, 6:16It's Decorative Gourd Season, Motherf*rs, By COLIN NISSANPermalinkCommentshumor satire halloween gourd pumpkin fall essay
Older Entries Creative Commons License Some rights reserved.