Bug 183418 - Allow WebViews to disable system appearance
Summary: Allow WebViews to disable system appearance
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Megan Gardner
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-03-07 15:38 PST by Megan Gardner
Modified: 2018-03-09 11:01 PST (History)
7 users (show)

See Also:


Attachments
Patch (46.67 KB, patch)
2018-03-07 15:46 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (47.64 KB, patch)
2018-03-07 16:40 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-sierra (2.89 MB, application/zip)
2018-03-07 17:54 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews117 for mac-sierra (2.41 MB, application/zip)
2018-03-07 18:24 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews107 for mac-sierra-wk2 (2.92 MB, application/zip)
2018-03-07 18:27 PST, EWS Watchlist
no flags Details
Patch (50.76 KB, patch)
2018-03-07 19:24 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-sierra (2.64 MB, application/zip)
2018-03-07 20:33 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews114 for mac-sierra (1.68 MB, application/zip)
2018-03-07 20:47 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews126 for ios-simulator-wk2 (2.22 MB, application/zip)
2018-03-07 21:00 PST, EWS Watchlist
no flags Details
Patch (51.76 KB, patch)
2018-03-07 22:10 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-sierra-wk2 (2.28 MB, application/zip)
2018-03-07 23:11 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews101 for mac-sierra (2.51 MB, application/zip)
2018-03-07 23:36 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews115 for mac-sierra (1.46 MB, application/zip)
2018-03-07 23:44 PST, EWS Watchlist
no flags Details
Patch (55.06 KB, patch)
2018-03-08 09:48 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (55.06 KB, patch)
2018-03-08 10:25 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (55.98 KB, patch)
2018-03-08 10:38 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (56.18 KB, patch)
2018-03-08 11:36 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (56.98 KB, patch)
2018-03-08 11:48 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (57.47 KB, patch)
2018-03-08 13:24 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (57.67 KB, patch)
2018-03-08 13:46 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (57.89 KB, patch)
2018-03-08 16:19 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (57.31 KB, patch)
2018-03-08 17:24 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (57.94 KB, patch)
2018-03-08 18:17 PST, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch (53.29 KB, patch)
2018-03-08 19:54 PST, Megan Gardner
thorton: review+
Details | Formatted Diff | Diff
Patch (53.18 KB, patch)
2018-03-08 20:39 PST, Megan Gardner
thorton: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Megan Gardner 2018-03-07 15:38:59 PST
Allow WebViews to disable system appearance
Comment 1 Megan Gardner 2018-03-07 15:46:10 PST
Created attachment 335229 [details]
Patch
Comment 2 Megan Gardner 2018-03-07 15:48:32 PST
<rdar://problem/36975642>
Comment 3 Tim Horton 2018-03-07 16:20:27 PST
Comment on attachment 335229 [details]
Patch

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

> Source/WebCore/css/StyleColor.cpp:40
> +Color StyleColor::colorFromKeyword(CSSValueID keyword, bool useSystemAppearance)

Not necessary to do in this patch but it would probably be better to make this an enum class

> Source/WebCore/css/StyleResolver.cpp:1825
> +        return RenderTheme::focusRingColor(document().page()->useSystemAppearance());

Can page be null?

> Source/WebCore/css/StyleResolver.cpp:1832
> +        return StyleColor::colorFromKeyword(identifier, document().page()->useSystemAppearance());

Can page be null?

> Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp:87
> +    context->drawFocusRing(path, 1, 1, RenderTheme::focusRingColor(element.document().page()->useSystemAppearance()));

Can Page be null?

> Source/WebCore/platform/mac/ThemeMac.mm:76
> +    WebCore::LocalDefaultSystemAppearance localAppearence(useSystemAppearance);

This local is spelled wrong. There might be others, maybe grep for "appearence"

> Source/WebCore/rendering/RenderTheme.h:153
> +    virtual Color platformFocusRingColor(bool useSystemAppearance) const { UNUSED_PARAM(useSystemAppearance); return Color(0, 0, 0); }

You can just leave the name off the arg instead, then you don't have to UNUSED_PARAM
Comment 4 Tim Horton 2018-03-07 16:35:40 PST
Comment on attachment 335229 [details]
Patch

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

>> Source/WebCore/css/StyleColor.cpp:40
>> +Color StyleColor::colorFromKeyword(CSSValueID keyword, bool useSystemAppearance)
> 
> Not necessary to do in this patch but it would probably be better to make this an enum class

Something like:

enum class UseSystemAppearance { Yes, No }

and then you'd use it like UseSystemAppearance::Yes.
Comment 5 Megan Gardner 2018-03-07 16:40:36 PST
Created attachment 335244 [details]
Patch
Comment 6 EWS Watchlist 2018-03-07 17:54:18 PST Comment hidden (obsolete)
Comment 7 EWS Watchlist 2018-03-07 17:54:19 PST Comment hidden (obsolete)
Comment 8 EWS Watchlist 2018-03-07 18:24:37 PST Comment hidden (obsolete)
Comment 9 EWS Watchlist 2018-03-07 18:24:38 PST Comment hidden (obsolete)
Comment 10 EWS Watchlist 2018-03-07 18:27:17 PST Comment hidden (obsolete)
Comment 11 EWS Watchlist 2018-03-07 18:27:18 PST Comment hidden (obsolete)
Comment 12 Megan Gardner 2018-03-07 19:24:59 PST
Created attachment 335251 [details]
Patch
Comment 13 EWS Watchlist 2018-03-07 20:33:11 PST
Comment on attachment 335251 [details]
Patch

Attachment 335251 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/6848895

Number of test failures exceeded the failure limit.
Comment 14 EWS Watchlist 2018-03-07 20:33:12 PST
Created attachment 335256 [details]
Archive of layout-test-results from ews101 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 15 EWS Watchlist 2018-03-07 20:47:32 PST
Comment on attachment 335251 [details]
Patch

Attachment 335251 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/6848887

Number of test failures exceeded the failure limit.
Comment 16 EWS Watchlist 2018-03-07 20:47:33 PST
Created attachment 335257 [details]
Archive of layout-test-results from ews114 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 17 EWS Watchlist 2018-03-07 20:59:59 PST
Comment on attachment 335251 [details]
Patch

Attachment 335251 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/6848970

Number of test failures exceeded the failure limit.
Comment 18 EWS Watchlist 2018-03-07 21:00:01 PST
Created attachment 335258 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 19 Tim Horton 2018-03-07 21:36:46 PST
Comment on attachment 335251 [details]
Patch

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

> Source/WebCore/html/canvas/CanvasStyle.cpp:-74
> -    return parseColor(colorString);

It’s pretty clear from the crashes that canvas can be null.

> Source/WebCore/html/canvas/CanvasStyle.cpp:74
> +    CSSParserContext context = CSSParserContext(canvas->document());

Not sure it’s a good idea to make a CSSParserContext here that’s missing most of its context -- we might enable features that we don’t want to, etc., because we don’t create it correctly. Right? Or is this all we need to fill one in?
Comment 20 Megan Gardner 2018-03-07 22:10:42 PST
Created attachment 335263 [details]
Patch
Comment 21 EWS Watchlist 2018-03-07 23:10:58 PST
Comment on attachment 335263 [details]
Patch

Attachment 335263 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/6850889

Number of test failures exceeded the failure limit.
Comment 22 EWS Watchlist 2018-03-07 23:11:00 PST
Created attachment 335265 [details]
Archive of layout-test-results from ews104 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 23 EWS Watchlist 2018-03-07 23:36:19 PST
Comment on attachment 335263 [details]
Patch

Attachment 335263 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/6851132

Number of test failures exceeded the failure limit.
Comment 24 EWS Watchlist 2018-03-07 23:36:20 PST
Created attachment 335269 [details]
Archive of layout-test-results from ews101 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 25 EWS Watchlist 2018-03-07 23:44:25 PST
Comment on attachment 335263 [details]
Patch

Attachment 335263 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/6851095

Number of test failures exceeded the failure limit.
Comment 26 EWS Watchlist 2018-03-07 23:44:26 PST
Created attachment 335270 [details]
Archive of layout-test-results from ews115 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews115  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 27 Megan Gardner 2018-03-08 09:48:52 PST
Created attachment 335311 [details]
Patch
Comment 28 Megan Gardner 2018-03-08 10:25:04 PST
Created attachment 335315 [details]
Patch
Comment 29 Megan Gardner 2018-03-08 10:38:21 PST
Created attachment 335317 [details]
Patch
Comment 30 Megan Gardner 2018-03-08 11:36:18 PST
Created attachment 335322 [details]
Patch
Comment 31 Megan Gardner 2018-03-08 11:48:45 PST
Created attachment 335325 [details]
Patch
Comment 32 Megan Gardner 2018-03-08 13:24:17 PST
Created attachment 335331 [details]
Patch
Comment 33 Megan Gardner 2018-03-08 13:46:15 PST
Created attachment 335339 [details]
Patch
Comment 34 Tim Horton 2018-03-08 13:49:19 PST
Comment on attachment 335339 [details]
Patch

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

> Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp:89
> +    if (element.document().page())

You could probably make this all a lot neater if you put a helper on document that did the null checking for you. Then you'd not need to sprinkle it throughout.
Comment 35 Megan Gardner 2018-03-08 16:19:14 PST
Created attachment 335365 [details]
Patch
Comment 36 Tim Horton 2018-03-08 16:44:41 PST
Comment on attachment 335365 [details]
Patch

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

> Source/WebCore/page/Page.h:328
> +#if PLATFORM(MAC)

If you do the same treatment here as you do in Document, you can avoid more #ifs elsewhere.

> Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h:33
> -OBJC_CLASS NSAppearence;
> +@class NSAppearance;

OBJC_CLASS is generally preferred because it works in C++-only files too! There's no reason this header shouldn't be importable in C++ files.

> Source/WebKit/ChangeLog:310
> +>>>>>>> .r229431

Please clean this up
Comment 37 Dean Jackson 2018-03-08 16:48:06 PST
Comment on attachment 335365 [details]
Patch

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

> Source/WebCore/html/canvas/CanvasStyle.cpp:118
> +CanvasStyle CanvasStyle::createFromString(const String& colorString, HTMLCanvasElement* canvas)

There isn't anything you can do about this, but an OffscreenCanvas won't have a document, and thus won't be able to follow the system appearance.

Although, maybe the system appearance query could be somewhere other than the document/page? Could it be on RenderTheme?

> Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h:33
> -OBJC_CLASS NSAppearence;
> +@class NSAppearance;

Why change from OBJC_CLASS?

> Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h:46
>      RetainPtr<NSAppearance> m_savedSystemAppearance;
> +    bool m_didSetSystemAppearance;

Rather than have the boolean, why not just check the nullness of m_savedSystemAppearance?

> Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm:50
> +    if (m_didSetSystemAppearance)
> +        [NSAppearance setCurrentAppearance:m_savedSystemAppearance.get()];

So this would become

if (m_savedSystemAppearance)
   [NSApp....
Comment 38 Tim Horton 2018-03-08 16:56:04 PST
Comment on attachment 335365 [details]
Patch

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

> Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:944
> +        setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha.value(), &downcast<HTMLCanvasElement>(canvasBase())));

Dino says to leave it for now, but in the future: 
"hand in the canvasBase() itself, and then on canvasBase() add a virtual useSystemApperance() that HTMLCanvasElement implements and grabs from Page"
Comment 39 Megan Gardner 2018-03-08 17:24:29 PST
Created attachment 335370 [details]
Patch
Comment 40 Megan Gardner 2018-03-08 18:17:07 PST
Created attachment 335379 [details]
Patch
Comment 41 Megan Gardner 2018-03-08 19:54:23 PST
Created attachment 335387 [details]
Patch
Comment 42 Wenson Hsieh 2018-03-08 20:10:32 PST
Comment on attachment 335387 [details]
Patch

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

> Source/WebKit/UIProcess/WebPageProxy.cpp:6961
> +    if (useSystemAppearance == m_alwaysShowsHorizontalScroller)

I think you meant to compare against m_useSystemAppearance, not m_alwaysShowsHorizontalScroller
Comment 43 Tim Horton 2018-03-08 20:15:03 PST
Comment on attachment 335387 [details]
Patch

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

> Source/WebCore/page/Page.h:706
> +    bool m_useSystemAppearance {false};

Spaces inside the braces!

> Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h:33
> -OBJC_CLASS NSAppearence;
> +OBJC_CLASS NSAppearance;

How did this even compile before? Maybe you don't need it?

> Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm:36
> +    

This newline is wrong.

> Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm:48
> +        m_savedSystemAppearance = nil;

Why bother? You're in the destructor.

> Source/WebCore/rendering/RenderThemeMac.mm:500
> +    return m_systemColorCache.ensure(cssValueID, [this, cssValueID, useSystemAppearance] () -> Color {

Probably need to (perhaps in a future patch) clear this cache when things change

> Source/WebKitLegacy/mac/WebView/WebView.mm:5195
> +#if PLATFORM(MAC)

Do you still need these PLATFORM(MAC)s?
Comment 44 Megan Gardner 2018-03-08 20:39:07 PST
Created attachment 335389 [details]
Patch
Comment 45 Megan Gardner 2018-03-08 21:01:21 PST
https://trac.webkit.org/changeset/229448/webkit
Comment 46 Alex Christensen 2018-03-09 10:54:35 PST
Comment on attachment 335389 [details]
Patch

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

> Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:442
> +@property (nonatomic, readwrite, setter=_setUseSystemAppearance:) BOOL _useSystemAppearance WK_API_AVAILABLE(macosx(WK_MAC_TBA));

Don't we need corresponding C API in WKPage.cpp?
Comment 47 Tim Horton 2018-03-09 11:01:14 PST
(In reply to Alex Christensen from comment #46)
> Comment on attachment 335389 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=335389&action=review
> 
> > Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:442
> > +@property (nonatomic, readwrite, setter=_setUseSystemAppearance:) BOOL _useSystemAppearance WK_API_AVAILABLE(macosx(WK_MAC_TBA));
> 
> Don't we need corresponding C API in WKPage.cpp?

Hopefully not.