suit - 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

Retweet of krisstraub

2015 Sep 20, 8:34
RT @chainsawsuit: good for what ails ya http://fb.me/7nPENCYPZ  pic.twitter.com/Rm8rLguHXx
PermalinkComments

Tweet from David_Risney

2015 Mar 26, 2:45
Hilarious dev's Tinder bot woman proxies male suitors' messages to one another. http://www.theverge.com/2015/3/25/8277743/tinder-hack-bros-swiping-bros … Sitcom misunderstanding generator.
PermalinkComments

Retweet of DrPizza

2015 Feb 11, 12:38
btw, @fxshaw, if Microsoft wants to rebrand with my new logo, I'm sure we can come to a suitable arrangement. http://cdn.arstechnica.net/wp-content/uploads/2015/02/cool-microsoft1-300x150.png …
PermalinkComments

URI functions in Windows Store Applications

2013 Jul 25, 1:00PermalinkCommentsc# c++ javascript technical uri windows windows-runtime windows-store

Nanex ~ 03-Aug-2012 ~ The Knightmare Explained

2012 Aug 6, 4:29

We believe Knight accidentally released the test software they used to verify that their market making software functioned properly, into NYSE’s live system.

I get chills breaking the build at work.  I can’t imagine how much worse it would feel to deploy your test suite and destroy the company you work for.

PermalinkCommentsmoney stock knight software trading technical

Its a suitcase 3D printer. Nice soundtrack too.

2012 Jul 28, 1:54PermalinkCommentsmake 3d-printer video suitcase

Line Simplification

2012 Jun 3, 12:47

Neat demo of Visvalingam’s line simplification algorithm in JavaScript applied to a map of the US.

To simplify geometry to suit the displayed resolution, various line simplification algorithms exist. While Douglas–Peucker is the most well-known, Visvalingam’s algorithm may be more effective and has a remarkably intuitive explanation: it progressively removes points with the least-perceptible change.

PermalinkCommentsline-simplification demo technical javascript

Dad holding bear suit Alex

2011 Dec 31, 11:21

PermalinkComments

Dad holding bear suit Alex

2011 Dec 31, 11:19

PermalinkComments

(via alvin, simon)

2011 Dec 27, 12:22


(via alvin, simon)

PermalinkCommentshumor comic

(via please reblog and remove all attribution (3 Comments))

2011 Nov 17, 2:22


(via please reblog and remove all attribution (3 Comments))

PermalinkComments

Alex in Bear Suit

2011 Sep 10, 10:36

PermalinkCommentsfamily alex

Hey, Bethesda! Let's settle this! : The Word of Notch

2011 Aug 17, 4:52This is awesome: "I challenge Bethesda to a game of Quake 3. ... If we win, you drop the lawsuit. If you win, we will change the name of Scrolls to something you’re fine with." I could have been a lawyer if things worked this way.PermalinkCommentsminecraft game law quake3

RFC 5987 - Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters

2010 Aug 13, 11:47Other characters sets for HTTP headers: "By default, message header field parameters in Hypertext Transfer Protocol (HTTP) messages cannot carry characters outside the ISO-8859-1 character set. RFC 2231 defines an encoding mechanism for use in Multipurpose Internet Mail Extensions (MIME) headers. This document specifies an encoding suitable for use in HTTP header fields that is compatible with a profile of the encoding defined in RFC 2231."PermalinkCommentsrfc language localization charset http technical reference http-header

Shepard Fairey - Interview Magazine

2010 May 10, 8:59Iggy Pop interviews Shepard Fairey, including his Obama HOPE poster and AP lawsuit:

"... but the American public is generally pretty superficial, so an image like that just allows them to project whatever limited idea they have onto it. Obviously, not everyone is like that—I actually think there were a lot of people who were bummed by the image because they felt it was shallow propaganda."

"If I spend time conceiving and making a piece of art and somebody else sees that it has market value and replicates it in order to steal part of my market, then that’s not cool. But the way I make art—the way a lot of people make art—is as an extension of language and communication, where references are incredibly important. It’s about making a work that is inspired by something preexisting but changes it to have a new value and meaning that doesn’t in any way take away from the original—and, in fact, might provide the original with a second life or a new audience."
PermalinkCommentsart legal law ip shepard-fairey obey interview

Chromium Blog: Does Your Browser Behave?

2010 Mar 12, 7:56A tool to run Google's ECMA conformance test suite on your browser.PermalinkCommentschrome web browser javascript technical tool test google

GIFT BOX GEEK IE EXPLORER MENS SUIT EXECUTIVE CUFFLINKS - eBay (item 390155859600 end time Mar-13-10 08:40:03 PST)

2010 Feb 26, 2:41Knock off Internet Explorer cufflinks available on eBay. I know, you totally thought these were legit, right?
PermalinkCommentshumor ie web browser gift wishlist purchase cufflink

Thanksgiving 2009

2009 Nov 29, 1:32

Pre Thanksgiving DinnerSarah and I had Thanksgiving dinner at our house the Sunday before. Sarah's parents and siblings came as well as my parents who came up for the a handful of days. It was our first time hosting Thanksgiving so I was a little nervous, but my parents helped us setup and get ready so of course it went well! I cheated a bit: I ordered a turkey online from Whole Foods where you can just tell them when you want to pick it up, they have it cooked and ready including garnish and you just need to warm it up. When we moved in together Sarah and I each had slightly different small dining room tables. Thankfully they're roughly the same height and width and we could put them together end to end and seat everybody with no room to spare. On actual Thanksgiving day we went over to Rachel & Anson's lovely new place for Thanksgiving and the annual game of Trivial Pursuit.

PermalinkCommentsturkey whole foods thanksgiving holiday

Inspirations typographiques françaises | Pixiome : nouvelles inspirations et tendances.

2009 Nov 23, 1:21"Je vous propose aujourd’hui de découvrir le travail de StarType, un ex typographe qui a connu le temps du plomb et travaillé dans de nombreuses imprimeries pour évoluer et devenir graphiste par la suite."PermalinkCommentstypography advertising font french design history
Older Entries Creative Commons License Some rights reserved.