Media query for default appearance
authormegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 11 Mar 2018 01:38:06 +0000 (01:38 +0000)
committermegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 11 Mar 2018 01:38:06 +0000 (01:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183539
<rdar://problem/38326388>

Reviewed by Tim Horton.

Source/WebCore:

Not currently testable, will add tests in a later patch.

Write a media query to evaluate appearance.

* css/CSSValueKeywords.in:
* css/MediaFeatureNames.h:
* css/MediaQueryEvaluator.cpp:
(WebCore::defaultAppearanceEvaluate):
* css/MediaQueryExpression.cpp:
(WebCore::featureWithValidIdent):
(WebCore::isFeatureValidWithoutValue):
* page/Page.h:
(WebCore::Page::defaultAppearance const):
(WebCore::Page::setDefaultAppearance):

Source/WebKit:

Write a media query to evaluate appearance.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
(-[WKWebView _setUseSystemAppearance:]):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::setDefaultAppearance):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::defaultAppearance const):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_credentialsMessenger):
(WebKit::WebPage::setDefaultAppearance):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Source/WebKitLegacy/mac:

Write a media query to evaluate appearance.

* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView _setUseSystemAppearance:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229511 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/MediaFeatureNames.h
Source/WebCore/css/MediaQueryEvaluator.cpp
Source/WebCore/css/MediaQueryExpression.cpp
Source/WebCore/page/Page.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebView.mm

index 80a696b..bd0f14b 100644 (file)
@@ -1,3 +1,26 @@
+2018-03-10  Megan Gardner  <megan_gardner@apple.com>
+
+        Media query for default appearance
+        https://bugs.webkit.org/show_bug.cgi?id=183539
+        <rdar://problem/38326388>
+
+        Reviewed by Tim Horton.
+
+        Not currently testable, will add tests in a later patch.
+
+        Write a media query to evaluate appearance.
+
+        * css/CSSValueKeywords.in:
+        * css/MediaFeatureNames.h:
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::defaultAppearanceEvaluate):
+        * css/MediaQueryExpression.cpp:
+        (WebCore::featureWithValidIdent):
+        (WebCore::isFeatureValidWithoutValue):
+        * page/Page.h:
+        (WebCore::Page::defaultAppearance const):
+        (WebCore::Page::setDefaultAppearance):
+
 2018-03-10  Daniel Bates  <dabates@apple.com>
 
         InlineTextBox should own shadow data
index d1287ba..352a0df 100644 (file)
@@ -1333,6 +1333,10 @@ rec2020
 sRGB
 display-p3
 
+// prefers-default-appearance
+prefers
+// no-preference
+
 // prefers-reduced-motion
 reduce
 no-preference
index 21d8750..adbd6f0 100644 (file)
 #define CSS_MEDIAQUERY_DISPLAY_MODE(macro)
 #endif
 
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/MediaFeatureNamesAdditions.h>
+#else
+#define DEFAULT_APPEARANCE_MEDIA_QUERY "prefers-default-appearance"
+#endif
+
+
 #define CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(macro) \
     macro(animation, "-webkit-animation") \
     macro(anyHover, "any-hover") \
@@ -70,6 +77,7 @@
     macro(monochrome, "monochrome") \
     macro(orientation, "orientation") \
     macro(pointer, "pointer") \
+    macro(defaultAppearance, DEFAULT_APPEARANCE_MEDIA_QUERY) \
     macro(prefersReducedMotion, "prefers-reduced-motion") \
     macro(resolution, "resolution") \
     macro(transform2d, "-webkit-transform-2d") \
index 8461871..6dc80b7 100644 (file)
@@ -710,6 +710,19 @@ static bool anyPointerEvaluate(CSSValue* value, const CSSToLengthConversionData&
 {
     return pointerEvaluate(value, cssToLengthConversionData, frame, prefix);
 }
+    
+static bool defaultAppearanceEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
+{
+    bool defaultAppearance = false;
+    
+    if (!frame.page()->defaultAppearance())
+        defaultAppearance = true;
+    
+    if (!value)
+        return defaultAppearance;
+    
+    return downcast<CSSPrimitiveValue>(*value).valueID() == (defaultAppearance ? CSSValuePrefers : CSSValueNoPreference);
+}
 
 static bool prefersReducedMotionEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
 {
index 223322a..6b76539 100644 (file)
@@ -52,7 +52,8 @@ static inline bool featureWithValidIdent(const AtomicString& mediaFeature, const
 #if ENABLE(APPLICATION_MANIFEST)
     || mediaFeature == MediaFeatureNames::displayMode
 #endif
-    || mediaFeature == MediaFeatureNames::prefersReducedMotion;
+    || mediaFeature == MediaFeatureNames::prefersReducedMotion
+    || mediaFeature == MediaFeatureNames::defaultAppearance;
 }
 
 static inline bool featureWithValidDensity(const String& mediaFeature, const CSSPrimitiveValue& value)
@@ -160,6 +161,7 @@ static inline bool isFeatureValidWithoutValue(const AtomicString& mediaFeature)
         || mediaFeature == MediaFeatureNames::invertedColors
         || mediaFeature == MediaFeatureNames::pointer
         || mediaFeature == MediaFeatureNames::prefersReducedMotion
+        || mediaFeature == MediaFeatureNames::defaultAppearance
         || mediaFeature == MediaFeatureNames::devicePixelRatio
         || mediaFeature == MediaFeatureNames::resolution
 #if ENABLE(APPLICATION_MANIFEST)
index 7f0afea..671eded 100644 (file)
@@ -327,6 +327,9 @@ public:
     
     bool useSystemAppearance() const { return m_useSystemAppearance; }
     void setUseSystemAppearance(bool a) { m_useSystemAppearance = a; }
+    
+    bool defaultAppearance() const { return m_defaultAppearance; }
+    void setDefaultAppearance(bool a) { m_defaultAppearance = a; }
 
 #if ENABLE(TEXT_AUTOSIZING)
     float textAutosizingWidth() const { return m_textAutosizingWidth; }
@@ -707,6 +710,7 @@ private:
 #endif
     
     bool m_useSystemAppearance { false };
+    bool m_defaultAppearance { true };
 
 #if ENABLE(TEXT_AUTOSIZING)
     float m_textAutosizingWidth { 0 };
index 5f7a825..d7d0240 100644 (file)
@@ -1,3 +1,31 @@
+2018-03-10  Megan Gardner  <megan_gardner@apple.com>
+
+        Media query for default appearance
+        https://bugs.webkit.org/show_bug.cgi?id=183539
+        <rdar://problem/38326388>
+
+        Reviewed by Tim Horton.
+
+        Write a media query to evaluate appearance.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        (-[WKWebView _setUseSystemAppearance:]):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        (WebKit::WebPageProxy::setDefaultAppearance):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::defaultAppearance const):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_credentialsMessenger):
+        (WebKit::WebPage::setDefaultAppearance):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2018-03-09  Jer Noble  <jer.noble@apple.com>
 
         Unconditionalize more methods in VideoFullscreenInterface (and related classes)
index 3280757..c4997e3 100644 (file)
@@ -82,6 +82,7 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
 #if PLATFORM(MAC)
     encoder << colorSpace;
     encoder << useSystemAppearance;
+    encoder << defaultAppearance;
 #endif
 #if PLATFORM(IOS)
     encoder << screenSize;
@@ -235,6 +236,8 @@ std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::
         return std::nullopt;
     if (!decoder.decode(parameters.useSystemAppearance))
         return std::nullopt;
+    if (!decoder.decode(parameters.defaultAppearance))
+        return std::nullopt;
 #endif
 
 #if PLATFORM(IOS)
index b0247b2..a37a734 100644 (file)
@@ -139,6 +139,7 @@ struct WebPageCreationParameters {
 #if PLATFORM(MAC)
     ColorSpaceData colorSpace;
     bool useSystemAppearance;
+    bool defaultAppearance;
 #endif
 #if PLATFORM(IOS)
     WebCore::FloatSize screenSize;
index c0432ed..2ade614 100644 (file)
@@ -471,8 +471,15 @@ static uint32_t convertSystemLayoutDirection(NSUserInterfaceLayoutDirection dire
     }
     return static_cast<uint32_t>(WebCore::UserInterfaceLayoutDirection::LTR);
 }
+
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/WebViewAndWKWebViewAdditions.mm>
+#else
+- (bool)_defaultAppearance { return true; }
 #endif
 
+#endif // PLATFORM(MAC)
+
 static void validate(WKWebViewConfiguration *configuration)
 {
     if (!configuration.processPool)
@@ -677,6 +684,8 @@ static void validate(WKWebViewConfiguration *configuration)
 
     _impl->setAutomaticallyAdjustsContentInsets(true);
     _impl->setRequiresUserActionForEditingControlsManager([configuration _requiresUserActionForEditingControlsManager]);
+    
+    _page->setDefaultAppearance([self _defaultAppearance]);
 #endif
 
     _page->setBackgroundExtendsBeyondPage(true);
@@ -6155,6 +6164,7 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
 - (void)_setUseSystemAppearance:(BOOL)useSystemAppearance
 {
     _page->setUseSystemAppearance(useSystemAppearance);
+    _page->setDefaultAppearance([self _defaultAppearance]);
 }
 
 - (void)_setHeaderBannerHeight:(int)height
index 13e6531..51dd3cb 100644 (file)
@@ -5855,6 +5855,7 @@ WebPageCreationParameters WebPageProxy::creationParameters()
 #if PLATFORM(MAC)
     parameters.colorSpace = m_pageClient.colorSpace();
     parameters.useSystemAppearance = m_useSystemAppearance;
+    parameters.defaultAppearance = m_defaultAppearance;
 #endif
 #if PLATFORM(IOS)
     parameters.screenSize = screenSize();
@@ -6962,6 +6963,18 @@ void WebPageProxy::setUseSystemAppearance(bool useSystemAppearance)
     m_useSystemAppearance = useSystemAppearance;
     m_process->send(Messages::WebPage::SetUseSystemAppearance(useSystemAppearance), m_pageID);
 }
+    
+void WebPageProxy::setDefaultAppearance(bool defaultAppearance)
+{
+    if (!isValid())
+        return;
+    
+    if (defaultAppearance == m_defaultAppearance)
+        return;
+    
+    m_defaultAppearance = defaultAppearance;
+    m_process->send(Messages::WebPage::SetDefaultAppearance(defaultAppearance), m_pageID);
+}
 
 void WebPageProxy::setHeaderBannerHeightForTesting(int height)
 {
index 8cc4a10..a4c6685 100644 (file)
@@ -805,6 +805,8 @@ public:
 #if PLATFORM(MAC)
     void setUseSystemAppearance(bool);
     bool useSystemAppearance() const { return m_useSystemAppearance; }
+    void setDefaultAppearance(bool);
+    bool defaultAppearance() const { return m_defaultAppearance; }
 #endif
 
 #if PLATFORM(COCOA)
@@ -1795,6 +1797,7 @@ private:
         
 #if PLATFORM(MAC)
     bool m_useSystemAppearance { false };
+    bool m_defaultAppearance { true };
 #endif
 
 #if ENABLE(APPLE_PAY)
index 0c83f9e..db12c97 100644 (file)
@@ -492,7 +492,10 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
     setPageLength(parameters.pageLength);
     setGapBetweenPages(parameters.gapBetweenPages);
     setPaginationLineGridEnabled(parameters.paginationLineGridEnabled);
-    
+#if PLATFORM(MAC)
+    setUseSystemAppearance(parameters.useSystemAppearance);
+    setDefaultAppearance(parameters.defaultAppearance);
+#endif
     // If the page is created off-screen, its visibilityState should be prerender.
     m_page->setActivityState(m_activityState);
     if (!isVisible())
@@ -4123,6 +4126,11 @@ void WebPage::setUseSystemAppearance(bool useSystemAppearance)
 {
     corePage()->setUseSystemAppearance(useSystemAppearance);
 }
+    
+void WebPage::setDefaultAppearance(bool defaultAppearance)
+{
+    corePage()->setDefaultAppearance(defaultAppearance);
+}
 #endif
 
 void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
index cb69b70..25e7b4c 100644 (file)
@@ -490,6 +490,7 @@ public:
     void setBottomOverhangImage(WebImage*);
     
     void setUseSystemAppearance(bool);
+    void setDefaultAppearance(bool);
 #endif
 
     bool windowIsFocused() const;
index d635389..71f7c51 100644 (file)
@@ -443,6 +443,7 @@ messages -> WebPage LegacyReceiver {
     HandleAcceptedCandidate(struct WebCore::TextCheckingResult acceptedCandidate)
 
     SetUseSystemAppearance(bool useSystemAppearance);
+    SetDefaultAppearance(bool defaultAppearance);
 
     SetHeaderBannerHeightForTesting(int height);
     SetFooterBannerHeightForTesting(int height);
index 39972cd..a07b9cd 100644 (file)
@@ -1,3 +1,17 @@
+2018-03-10  Megan Gardner  <megan_gardner@apple.com>
+
+        Media query for default appearance
+        https://bugs.webkit.org/show_bug.cgi?id=183539
+        <rdar://problem/38326388>
+
+        Reviewed by Tim Horton.
+
+        Write a media query to evaluate appearance.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+        (-[WebView _setUseSystemAppearance:]):
+
 2018-03-09  Andy Estes  <aestes@apple.com>
 
         [Mac] WebKit fails to receive file promises when the embedding app is sandboxed
index 93fe7df..a011462 100644 (file)
@@ -1574,6 +1574,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
         ResourceHandle::forceContentSniffing();
 
     _private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
+    _private->page->setDefaultAppearance([self _defaultAppearance]);
 #endif
 
     _private->page->settings().setContentDispositionAttachmentSandboxEnabled(true);
@@ -5191,10 +5192,18 @@ static Vector<String> toStringVector(NSArray* patterns)
     return insets;
 }
 
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/WebViewAndWKWebViewAdditions.mm>
+#else
+- (bool)_defaultAppearance { return true; }
+#endif
+
 - (void)_setUseSystemAppearance:(BOOL)useSystemAppearance
 {
-    if (auto page = _private->page)
+    if (auto page = _private->page) {
         page->setUseSystemAppearance(useSystemAppearance);
+        page->setDefaultAppearance([self _defaultAppearance]);
+    }
 }
 
 - (BOOL)_useSystemAppearance