Bug 143560

Summary: Add a persistent, fixed scale factor to make it easy to scale down WK(Web)Views
Product: WebKit Reporter: Tim Horton <thorton>
Component: WebKit2Assignee: Tim Horton <thorton>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, bdakin, darin, mitz, sam, simon.fraser
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch darin: review+

Description Tim Horton 2015-04-09 02:04:29 PDT
Add a persistent, fixed scale factor to make it easy to scale down WK(Web)Views
Comment 1 Tim Horton 2015-04-09 02:07:26 PDT
Created attachment 250429 [details]
Patch
Comment 2 Simon Fraser (smfr) 2015-04-09 11:48:58 PDT
Comment on attachment 250429 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=250429&action=review

> Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h:97
> +@property (nonatomic, setter=_setAutomaticallyComputesFixedLayoutSizeFromViewScale:) BOOL _automaticallyComputesFixedLayoutSizeFromViewScale;

Please add a comment stating that this overrides _fixedLayoutSize. It looks like it also implicitly enables does _setFixedLayoutEnabled:YES? You should say that too.

Maybe we really need:

_setFixedLayoutMode:{NoFixedLayout, FixedLayoutBasedOnViewScale, FixedSizeLayout}

> Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h:99
> +- (void)_killWebContentProcess;

Why doesn't Mac get _didRelaunchProcess ?

> Source/WebKit2/UIProcess/API/mac/WKView.mm:547
> +    [self _setFixedLayoutSize:NSMakeSize(self.frame.size.width * inverseScale, self.frame.size.height * inverseScale)];

Do we want explicit rounding/flooring of that size?
Comment 3 Tim Horton 2015-04-10 23:54:38 PDT
Created attachment 250568 [details]
Patch
Comment 4 Darin Adler 2015-04-11 08:39:20 PDT
Comment on attachment 250568 [details]
Patch

Do we need any range checking to avoid zeroes and infinities and other crazy values?
Comment 5 Tim Horton 2015-04-13 12:23:18 PDT
(In reply to comment #4)
> Comment on attachment 250568 [details]
> Patch
> 
> Do we need any range checking to avoid zeroes and infinities and other crazy
> values?

Seems like a good idea. Will add and land.
Comment 6 Tim Horton 2015-04-13 15:34:26 PDT
(In reply to comment #5)
> (In reply to comment #4)
> > Comment on attachment 250568 [details]
> > Patch
> > 
> > Do we need any range checking to avoid zeroes and infinities and other crazy
> > values?
> 
> Seems like a good idea. Will add and land.

Going to add an ASSERT in WebPageProxy and throw exceptions in WKView and WKWebView, after talking to Dan/Anders.
Comment 7 Alexey Proskuryakov 2015-04-13 22:02:12 PDT
Several 32-bit build failures from this patch:

/Volumes/Data/slave/gala-production-archive/build/build-Production/WebKit2.roots/Sources/WebKit2/UIProcess/API/mac/WKView.mm:570:31: error: no viable conversion from 'NSSize' (aka '_NSSize') to 'CGSize'

/Volumes/Data/slave/gala-production-archive/build/build-Production/WebKit2.roots/Sources/WebKit2/UIProcess/API/mac/WKView.mm:367:17: error: property '_automaticallyComputesFixedLayoutSizeFromViewScale' requires method '_automaticallyComputesFixedLayoutSizeFromViewScale' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation [-Werror,-Wobjc-property-implementation]

/Volumes/Data/slave/gala-production-archive/build/build-Production/WebKit2.roots/Sources/WebKit2/UIProcess/API/mac/WKView.mm:367:17: error: property '_automaticallyComputesFixedLayoutSizeFromViewScale' requires method '_setAutomaticallyComputesFixedLayoutSizeFromViewScale:' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation [-Werror,-Wobjc-property-implementation]
Comment 8 Alexey Proskuryakov 2015-04-13 22:12:43 PDT
Attempted fixes in r182781. Anyone willing to donate hardware for 32-bit EWS?

Tim's patch landed in r182772, so marking the bug as resolved.
Comment 9 Darin Adler 2015-04-14 09:26:13 PDT
(In reply to comment #5)
> > Do we need any range checking to avoid zeroes and infinities and other crazy
> > values?
> 
> Seems like a good idea. Will add and land.

Slight refactoring suggestion on these. Instead of this:

    if (viewScale <= 0 || isnan(viewScale) || isinf(viewScale))
        [NSException raise:NSInvalidArgumentException format:@"View scale should be a positive number"];

I suggest writing this:

    if (!(viewScale > 0) || isinf(viewScale))
        [NSException raise:NSInvalidArgumentException format:@"View scale should be a positive number"];

I think it’s nice to take advantage of the natural property of NAN that it returns false when every you compare it to anything else. And the code ends up matching the exception string slightly more closely since it’s a check for a positive number rather than a check that it’s not zero or negative.