Add CSS -webkit-appearance property for Apple Pay buttons
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2016 17:45:56 +0000 (17:45 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2016 17:45:56 +0000 (17:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161986

Reviewed by Dean Jackson.

Add a new -webkit-appearance property, "-apple-pay-button".
Also, add two properties, "-apple-pay-button-type" and "-apple-pay-button-style".

* WebCore.xcodeproj/project.pbxproj:
Add RenderThemeCocoa.h and RenderThemeCocoa.mm.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
Handle CSSPropertyApplePayButtonStyle and CSSPropertyApplePayButtonType.

* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::operator ApplePayButtonStyle):
(WebCore::CSSPrimitiveValue::operator ApplePayButtonType):
Add ApplePayButtonStyle and ApplePayButtonType conversion routines.

* css/CSSPropertyNames.in:
Add -apple-pay-button-style and -apple-pay-button-type.

* css/CSSValueKeywords.in:
Add CSS values.

* css/parser/CSSParser.cpp:
(WebCore::isValidKeywordPropertyAndValue):
Handle CSSPropertyApplePayButtonStyle and CSSPropertyApplePayButtonType.

* css/parser/CSSParserFastPaths.cpp:
(WebCore::CSSParserFastPaths::isKeywordPropertyID):
Handle CSSPropertyApplePayButtonStyle and CSSPropertyApplePayButtonType.

(WebCore::isAppleLegacyCSSPropertyKeyword):
New function that returns whether the CSS property should be rewritten to -webkit-.
We want to rewrite -apple- but not -apple-pay-.

(WebCore::cssPropertyID):
Use the newly added isAppleLegacyCSSPropertyKeyword.

(WebCore::isAppleLegacyCSSValueKeyword):
Check for "-apple-pay-" in addition to "-apple-system-".

* platform/ThemeTypes.h:
Add ApplePayButtonPart.

* platform/spi/cocoa/PassKitSPI.h:
Add PKDrawApplePayButton declaration.

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::adjustStyle):
Handle ApplePayButtonPart.

(WebCore::RenderTheme::paint):
Handle ApplePayButtonPart.

* rendering/RenderTheme.h:
(WebCore::RenderTheme::adjustApplePayButtonStyle):
(WebCore::RenderTheme::paintApplePayButton):
Add new functions.

* rendering/RenderThemeCocoa.h: Added.
* rendering/RenderThemeCocoa.mm: Added.
(WebCore::RenderThemeCocoa::adjustApplePayButtonStyle):
Adjust the minimum width and minimum height accordingly.

(WebCore::toPKPaymentButtonStyle):
(WebCore::toPKPaymentButtonType):
Helper functions that convert our WebCore types to PK types.

(WebCore::RenderThemeCocoa::paintApplePayButton):
Call PKDrawApplePayButton.

* rendering/RenderThemeIOS.h:
* rendering/RenderThemeMac.h:
Inherit from RenderThemeCocoa.

* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::applePayButtonStyle):
(WebCore::RenderStyle::applePayButtonType):
(WebCore::RenderStyle::setApplePayButtonStyle):
(WebCore::RenderStyle::setApplePayButtonType):
(WebCore::RenderStyle::initialApplePayButtonStyle):
(WebCore::RenderStyle::initialApplePayButtonType):
* rendering/style/RenderStyleConstants.h:
* rendering/style/StyleRareInheritedData.cpp:
(WebCore::StyleRareInheritedData::StyleRareInheritedData):
(WebCore::StyleRareInheritedData::operator==):
* rendering/style/StyleRareInheritedData.h:
Add new style members for the button style and button type properties.

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

20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/parser/CSSParser.cpp
Source/WebCore/css/parser/CSSParserFastPaths.cpp
Source/WebCore/platform/ThemeTypes.h
Source/WebCore/platform/spi/cocoa/PassKitSPI.h
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeCocoa.h [new file with mode: 0644]
Source/WebCore/rendering/RenderThemeCocoa.mm [new file with mode: 0644]
Source/WebCore/rendering/RenderThemeIOS.h
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/RenderStyleConstants.h
Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp
Source/WebCore/rendering/style/StyleRareNonInheritedData.h

index 0e48acb..e14944d 100644 (file)
@@ -1,3 +1,98 @@
+2016-09-14  Anders Carlsson  <andersca@apple.com>
+
+        Add CSS -webkit-appearance property for Apple Pay buttons
+        https://bugs.webkit.org/show_bug.cgi?id=161986
+
+        Reviewed by Dean Jackson.
+
+        Add a new -webkit-appearance property, "-apple-pay-button".
+        Also, add two properties, "-apple-pay-button-type" and "-apple-pay-button-style".
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Add RenderThemeCocoa.h and RenderThemeCocoa.mm.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::propertyValue):
+        Handle CSSPropertyApplePayButtonStyle and CSSPropertyApplePayButtonType.
+
+        * css/CSSPrimitiveValueMappings.h:
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+        (WebCore::CSSPrimitiveValue::operator ApplePayButtonStyle):
+        (WebCore::CSSPrimitiveValue::operator ApplePayButtonType):
+        Add ApplePayButtonStyle and ApplePayButtonType conversion routines.
+
+        * css/CSSPropertyNames.in:
+        Add -apple-pay-button-style and -apple-pay-button-type.
+
+        * css/CSSValueKeywords.in:
+        Add CSS values.
+
+        * css/parser/CSSParser.cpp:
+        (WebCore::isValidKeywordPropertyAndValue):
+        Handle CSSPropertyApplePayButtonStyle and CSSPropertyApplePayButtonType.
+
+        * css/parser/CSSParserFastPaths.cpp:
+        (WebCore::CSSParserFastPaths::isKeywordPropertyID):
+        Handle CSSPropertyApplePayButtonStyle and CSSPropertyApplePayButtonType.
+
+        (WebCore::isAppleLegacyCSSPropertyKeyword):
+        New function that returns whether the CSS property should be rewritten to -webkit-.
+        We want to rewrite -apple- but not -apple-pay-.
+
+        (WebCore::cssPropertyID):
+        Use the newly added isAppleLegacyCSSPropertyKeyword.
+
+        (WebCore::isAppleLegacyCSSValueKeyword):
+        Check for "-apple-pay-" in addition to "-apple-system-".
+
+        * platform/ThemeTypes.h:
+        Add ApplePayButtonPart.
+
+        * platform/spi/cocoa/PassKitSPI.h:
+        Add PKDrawApplePayButton declaration.
+
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::adjustStyle):
+        Handle ApplePayButtonPart.
+
+        (WebCore::RenderTheme::paint):
+        Handle ApplePayButtonPart.
+
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::adjustApplePayButtonStyle):
+        (WebCore::RenderTheme::paintApplePayButton):
+        Add new functions.
+
+        * rendering/RenderThemeCocoa.h: Added.
+        * rendering/RenderThemeCocoa.mm: Added.
+        (WebCore::RenderThemeCocoa::adjustApplePayButtonStyle):
+        Adjust the minimum width and minimum height accordingly.
+
+        (WebCore::toPKPaymentButtonStyle):
+        (WebCore::toPKPaymentButtonType):
+        Helper functions that convert our WebCore types to PK types.
+
+        (WebCore::RenderThemeCocoa::paintApplePayButton):
+        Call PKDrawApplePayButton.
+
+        * rendering/RenderThemeIOS.h:
+        * rendering/RenderThemeMac.h:
+        Inherit from RenderThemeCocoa.
+
+        * rendering/style/RenderStyle.h:
+        (WebCore::RenderStyle::applePayButtonStyle):
+        (WebCore::RenderStyle::applePayButtonType):
+        (WebCore::RenderStyle::setApplePayButtonStyle):
+        (WebCore::RenderStyle::setApplePayButtonType):
+        (WebCore::RenderStyle::initialApplePayButtonStyle):
+        (WebCore::RenderStyle::initialApplePayButtonType):
+        * rendering/style/RenderStyleConstants.h:
+        * rendering/style/StyleRareInheritedData.cpp:
+        (WebCore::StyleRareInheritedData::StyleRareInheritedData):
+        (WebCore::StyleRareInheritedData::operator==):
+        * rendering/style/StyleRareInheritedData.h:
+        Add new style members for the button style and button type properties.
+
 2016-09-15  Sergio Villar Senin  <svillar@igalia.com>
 
         [css-grid] Implement fit-content track size
index 4c6fcc9..c43b38b 100644 (file)
                1A22464E0CC98DDB00C05240 /* SQLiteTransaction.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2246480CC98DDB00C05240 /* SQLiteTransaction.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1A24844D1D1A272A00F56BA7 /* PaymentHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A24844C1D1A270100F56BA7 /* PaymentHeaders.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1A250E0D1CDD632000D0BE63 /* LinkIconType.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A250E0C1CDD632000D0BE63 /* LinkIconType.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               1A299FE71D7F5FA600A60093 /* RenderThemeCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A299FE51D7F5FA600A60093 /* RenderThemeCocoa.mm */; };
+               1A299FE81D7F5FA600A60093 /* RenderThemeCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A299FE61D7F5FA600A60093 /* RenderThemeCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1A2A68230B5BEDE70002A480 /* ProgressTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2A68210B5BEDE70002A480 /* ProgressTracker.cpp */; };
                1A2A68240B5BEDE70002A480 /* ProgressTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2A68220B5BEDE70002A480 /* ProgressTracker.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1A2AAC580DC2A3B100A20D9A /* ApplicationCacheStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2AAC560DC2A3B100A20D9A /* ApplicationCacheStorage.cpp */; };
                1A2246480CC98DDB00C05240 /* SQLiteTransaction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLiteTransaction.h; sourceTree = "<group>"; };
                1A24844C1D1A270100F56BA7 /* PaymentHeaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaymentHeaders.h; sourceTree = "<group>"; };
                1A250E0C1CDD632000D0BE63 /* LinkIconType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkIconType.h; sourceTree = "<group>"; };
+               1A299FE51D7F5FA600A60093 /* RenderThemeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderThemeCocoa.mm; sourceTree = "<group>"; };
+               1A299FE61D7F5FA600A60093 /* RenderThemeCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderThemeCocoa.h; sourceTree = "<group>"; };
                1A2A68210B5BEDE70002A480 /* ProgressTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ProgressTracker.cpp; sourceTree = "<group>"; };
                1A2A68220B5BEDE70002A480 /* ProgressTracker.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ProgressTracker.h; sourceTree = "<group>"; };
                1A2AAC560DC2A3B100A20D9A /* ApplicationCacheStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationCacheStorage.cpp; sourceTree = "<group>"; };
                                E4C91A15180999F100A17F6D /* RenderTextLineBoxes.h */,
                                BCEA484A097D93020094C9E4 /* RenderTheme.cpp */,
                                BCEA484B097D93020094C9E4 /* RenderTheme.h */,
+                               1A299FE61D7F5FA600A60093 /* RenderThemeCocoa.h */,
+                               1A299FE51D7F5FA600A60093 /* RenderThemeCocoa.mm */,
                                FED13D500CEA949700D89466 /* RenderThemeIOS.h */,
                                C55C7BA01718AFBA001327E4 /* RenderThemeIOS.mm */,
                                BCEA4848097D93020094C9E4 /* RenderThemeMac.h */,
                                BC926F810C0552470082776B /* JSHTMLFrameSetElement.h in Headers */,
                                A80E7B150A19D606007FB8C5 /* JSHTMLHeadElement.h in Headers */,
                                1AE2AA2F0A1CDAB400B42B25 /* JSHTMLHeadingElement.h in Headers */,
+                               1A299FE81D7F5FA600A60093 /* RenderThemeCocoa.h in Headers */,
                                1AE2AA310A1CDAB400B42B25 /* JSHTMLHRElement.h in Headers */,
                                1A85B1900A1B18A200D8C87C /* JSHTMLHtmlElement.h in Headers */,
                                BC4918C90BFEA050009D6316 /* JSHTMLIFrameElement.h in Headers */,
                                F45C231D1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp in Sources */,
                                37F57ACF1A5072DD00876F98 /* AXObjectCache.cpp in Sources */,
                                AAA728F916D1D8BC00D3BBC6 /* AXObjectCacheIOS.mm in Sources */,
+                               1A299FE71D7F5FA600A60093 /* RenderThemeCocoa.mm in Sources */,
                                29A8124B0FBB9CA900510293 /* AXObjectCacheMac.mm in Sources */,
                                BCA8C81F11E3D36900812FB7 /* BackForwardController.cpp in Sources */,
                                BCA8CA5F11E4E6D100812FB7 /* BackForwardList.cpp in Sources */,
index c7c8725..cbeeef4 100644 (file)
@@ -3758,6 +3758,13 @@ RefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID,
             return cssValuePool.createValue(style->trailingWord());
 #endif
 
+#if ENABLE(APPLE_PAY)
+        case CSSPropertyApplePayButtonStyle:
+            return cssValuePool.createValue(style->applePayButtonStyle());
+        case CSSPropertyApplePayButtonType:
+            return cssValuePool.createValue(style->applePayButtonType());
+#endif
+
         /* Individual properties not part of the spec */
         case CSSPropertyBackgroundRepeatX:
         case CSSPropertyBackgroundRepeatY:
index 4efc07f..8f8ea41 100644 (file)
@@ -616,6 +616,11 @@ template<> inline CSSPrimitiveValue::CSSPrimitiveValue(ControlPart e)
         m_value.valueID = CSSValueImageControlsButton;
         break;
 #endif
+#if ENABLE(APPLE_PAY)
+    case ApplePayButtonPart:
+        m_value.valueID = CSSValueApplePayButton;
+        break;
+#endif
     }
 }
 
@@ -5473,6 +5478,87 @@ template<> inline CSSPrimitiveValue::operator TrailingWord() const
 }
 #endif
 
+#if ENABLE(APPLE_PAY)
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(ApplePayButtonStyle e)
+    : CSSValue(PrimitiveClass)
+{
+    m_primitiveUnitType = CSS_VALUE_ID;
+    switch (e) {
+    case ApplePayButtonStyle::White:
+        m_value.valueID = CSSValueWhite;
+        break;
+    case ApplePayButtonStyle::WhiteOutline:
+        m_value.valueID = CSSValueWhiteOutline;
+        break;
+    case ApplePayButtonStyle::Black:
+        m_value.valueID = CSSValueBlack;
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+}
+
+template<> inline CSSPrimitiveValue::operator ApplePayButtonStyle() const
+{
+    ASSERT(isValueID());
+    switch (m_value.valueID) {
+    case CSSValueWhite:
+        return ApplePayButtonStyle::White;
+    case CSSValueWhiteOutline:
+        return ApplePayButtonStyle::WhiteOutline;
+    case CSSValueBlack:
+        return ApplePayButtonStyle::Black;
+    default:
+        break;
+    }
+    ASSERT_NOT_REACHED();
+    return ApplePayButtonStyle::Black;
+}
+
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(ApplePayButtonType e)
+    : CSSValue(PrimitiveClass)
+{
+    m_primitiveUnitType = CSS_VALUE_ID;
+    switch (e) {
+    case ApplePayButtonType::Plain:
+        m_value.valueID = CSSValuePlain;
+        break;
+    case ApplePayButtonType::Buy:
+        m_value.valueID = CSSValueBuy;
+        break;
+    case ApplePayButtonType::SetUp:
+        m_value.valueID = CSSValueSetUp;
+        break;
+    case ApplePayButtonType::InStore:
+        m_value.valueID = CSSValueInStore;
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+}
+
+template<> inline CSSPrimitiveValue::operator ApplePayButtonType() const
+{
+    ASSERT(isValueID());
+    switch (m_value.valueID) {
+    case CSSValuePlain:
+        return ApplePayButtonType::Plain;
+    case CSSValueBuy:
+        return ApplePayButtonType::Buy;
+    case CSSValueSetUp:
+        return ApplePayButtonType::SetUp;
+    case CSSValueInStore:
+        return ApplePayButtonType::InStore;
+    default:
+        break;
+    }
+    ASSERT_NOT_REACHED();
+    return ApplePayButtonType::Plain;
+}
+#endif
+
 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(FontVariantPosition position)
     : CSSValue(PrimitiveClass)
 {
index 9b9ee3e..3adb096 100644 (file)
@@ -681,3 +681,8 @@ touch-action
 #if defined(ENABLE_CSS_TRAILING_WORD) && ENABLE_CSS_TRAILING_WORD
 -apple-trailing-word [Inherited, NameForMethods=TrailingWord]
 #endif
+
+#if defined(ENABLE_APPLE_PAY) && ENABLE_APPLE_PAY
+-apple-pay-button-style
+-apple-pay-button-type
+#endif
index 11e851b..f8ff6ea 100644 (file)
@@ -806,6 +806,9 @@ rating-level-indicator
 #if defined(ENABLE_SERVICE_CONTROLS) && ENABLE_SERVICE_CONTROLS
 image-controls-button
 #endif
+#if defined(ENABLE_APPLE_PAY) && ENABLE_APPLE_PAY
+-apple-pay-button
+#endif
 textarea
 #if defined(ENABLE_ATTACHMENT_ELEMENT) && ENABLE_ATTACHMENT_ELEMENT
 attachment
@@ -1185,6 +1188,17 @@ from-intrinsic
 -webkit-partially-balanced
 #endif
 
+#if defined(ENABLE_APPLE_PAY) && ENABLE_APPLE_PAY
+// -apple-pay-button-style
+white-outline
+
+// -apple-pay-button-type
+plain
+buy
+set-up
+in-store
+#endif
+
 // font-synthesis
 weight
 style
index 0611c03..081fc01 100644 (file)
@@ -1050,6 +1050,16 @@ static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int
             return true;
         break;
 #endif
+#if ENABLE(APPLE_PAY)
+    case CSSPropertyApplePayButtonStyle: // white | white-outline | black
+        if (valueID == CSSValueWhite || valueID == CSSValueWhiteOutline || valueID == CSSValueBlack)
+            return true;
+        break;
+    case CSSPropertyApplePayButtonType: // plain | buy | set-up | in-store
+        if (valueID == CSSValuePlain || valueID == CSSValueBuy || valueID == CSSValueSetUp || valueID == CSSValueInStore)
+            return true;
+        break;
+#endif
     case CSSPropertyFontVariantPosition: // normal | sub | super
         if (valueID == CSSValueNormal || valueID == CSSValueSub || valueID == CSSValueSuper)
             return true;
@@ -13313,6 +13323,17 @@ bool CSSParser::parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first
 }
 #endif
 
+#if ENABLE(LEGACY_CSS_VENDOR_PREFIXES)
+static bool isAppleLegacyCSSPropertyKeyword(const char* propertyKeyword, unsigned length)
+{
+    static const char applePrefix[] = "-apple-";
+    static const char applePayPrefix[] = "-apple-pay-";
+
+    return hasPrefix(propertyKeyword, length, applePrefix)
+        && !hasPrefix(propertyKeyword, length, applePayPrefix);
+}
+#endif
+
 template <typename CharacterType>
 static CSSPropertyID cssPropertyID(const CharacterType* propertyName, unsigned length)
 {
@@ -13332,7 +13353,7 @@ static CSSPropertyID cssPropertyID(const CharacterType* propertyName, unsigned l
         // If the prefix is -apple- or -khtml-, change it to -webkit-.
         // This makes the string one character longer.
         if (RuntimeEnabledFeatures::sharedFeatures().legacyCSSVendorPrefixesEnabled()
-            && (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-"))) {
+            && (isAppleLegacyCSSPropertyKeyword(buffer, length) || hasPrefix(buffer, length, "-khtml-"))) {
             memmove(buffer + 7, buffer + 6, length + 1 - 6);
             memcpy(buffer, "-webkit", 7);
             ++length;
@@ -13383,14 +13404,16 @@ void cssPropertyNameIOSAliasing(const char* propertyName, const char*& propertyN
 }
 #endif
 
-static bool isAppleLegacyCssValueKeyword(const char* valueKeyword, unsigned length)
+static bool isAppleLegacyCSSValueKeyword(const char* valueKeyword, unsigned length)
 {
     static const char applePrefix[] = "-apple-";
-    static const char appleSystemPrefix[] = "-apple-system";
+    static const char appleSystemPrefix[] = "-apple-system-";
+    static const char applePayPrefix[] = "-apple-pay-";
     static const char* appleWirelessPlaybackTargetActive = getValueName(CSSValueAppleWirelessPlaybackTargetActive);
 
     return hasPrefix(valueKeyword, length, applePrefix)
         && !hasPrefix(valueKeyword, length, appleSystemPrefix)
+        && !hasPrefix(valueKeyword, length, applePayPrefix)
         && !WTF::equal(reinterpret_cast<const LChar*>(valueKeyword), reinterpret_cast<const LChar*>(appleWirelessPlaybackTargetActive), length);
 }
 
@@ -13412,7 +13435,7 @@ static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned
         // This makes the string one character longer.
         // On iOS we don't want to change values starting with -apple-system to -webkit-system.
         // FIXME: Remove this mangling without breaking the web.
-        if (isAppleLegacyCssValueKeyword(buffer, length) || hasPrefix(buffer, length, "-khtml-")) {
+        if (isAppleLegacyCSSValueKeyword(buffer, length) || hasPrefix(buffer, length, "-khtml-")) {
             memmove(buffer + 7, buffer + 6, length + 1 - 6);
             memcpy(buffer, "-webkit", 7);
             ++length;
index c9b79b0..0a75ce3 100644 (file)
@@ -922,6 +922,10 @@ bool CSSParserFastPaths::isKeywordPropertyID(CSSPropertyID propertyId)
 #if ENABLE(CSS_SCROLL_SNAP)
     case CSSPropertyWebkitScrollSnapType:
 #endif
+#if ENABLE(APPLE_PAY)
+    case CSSPropertyApplePayButtonStyle:
+    case CSSPropertyApplePayButtonType:
+#endif
         return true;
     case CSSPropertyJustifyContent:
     case CSSPropertyAlignContent:
index 0994539..50e6edc 100644 (file)
@@ -23,8 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef ThemeTypes_h
-#define ThemeTypes_h
+#pragma once
 
 namespace WebCore {
 
@@ -49,6 +48,9 @@ enum ControlPart {
 #if ENABLE(SERVICE_CONTROLS)
     ImageControlsButtonPart,
 #endif
+#if ENABLE(APPLE_PAY)
+    ApplePayButtonPart,
+#endif
     TextAreaPart,
 #if ENABLE(ATTACHMENT_ELEMENT)
     AttachmentPart,
@@ -73,4 +75,3 @@ enum ThemeColor {
 };
 
 }
-#endif
index a0c7b99..0520992 100644 (file)
@@ -214,3 +214,6 @@ NS_ASSUME_NONNULL_BEGIN
 NS_ASSUME_NONNULL_END
 
 #endif
+
+extern "C"
+void PKDrawApplePayButton(_Nonnull CGContextRef, CGRect drawRect, CGFloat scale, PKPaymentButtonType, PKPaymentButtonStyle, NSString * _Nullable languageCode);
index 2756f6b..cdd01e3 100644 (file)
@@ -253,6 +253,10 @@ void RenderTheme::adjustStyle(StyleResolver& styleResolver, RenderStyle& style,
 #endif
     case CapsLockIndicatorPart:
         return adjustCapsLockIndicatorStyle(styleResolver, style, element);
+#if ENABLE(APPLE_PAY)
+    case ApplePayButtonPart:
+        return adjustApplePayButtonStyle(styleResolver, style, element);
+#endif
 #if ENABLE(ATTACHMENT_ELEMENT)
     case AttachmentPart:
         return adjustAttachmentStyle(styleResolver, style, element);
@@ -401,6 +405,10 @@ bool RenderTheme::paint(const RenderBox& box, ControlStates& controlStates, cons
 #endif
     case CapsLockIndicatorPart:
         return paintCapsLockIndicator(box, paintInfo, integralSnappedRect);
+#if ENABLE(APPLE_PAY)
+    case ApplePayButtonPart:
+        return paintApplePayButton(box, paintInfo, integralSnappedRect);
+#endif
 #if ENABLE(ATTACHMENT_ELEMENT)
     case AttachmentPart:
         return paintAttachment(box, paintInfo, integralSnappedRect);
index 36a4c89..39b97c8 100644 (file)
@@ -325,6 +325,11 @@ protected:
     virtual void adjustCapsLockIndicatorStyle(StyleResolver&, RenderStyle&, const Element*) const;
     virtual bool paintCapsLockIndicator(const RenderObject&, const PaintInfo&, const IntRect&);
 
+#if ENABLE(APPLE_PAY)
+    virtual void adjustApplePayButtonStyle(StyleResolver&, RenderStyle&, const Element*) const { }
+    virtual bool paintApplePayButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
+#endif
+
 #if ENABLE(ATTACHMENT_ELEMENT)
     virtual void adjustAttachmentStyle(StyleResolver&, RenderStyle&, const Element*) const;
     virtual bool paintAttachment(const RenderObject&, const PaintInfo&, const IntRect&);
diff --git a/Source/WebCore/rendering/RenderThemeCocoa.h b/Source/WebCore/rendering/RenderThemeCocoa.h
new file mode 100644 (file)
index 0000000..b4c587f
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "RenderTheme.h"
+
+namespace WebCore {
+
+class RenderThemeCocoa : public RenderTheme {
+private:
+#if ENABLE(APPLE_PAY)
+    void adjustApplePayButtonStyle(StyleResolver&, RenderStyle&, const Element*) const override;
+    bool paintApplePayButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
+#endif
+};
+
+}
diff --git a/Source/WebCore/rendering/RenderThemeCocoa.mm b/Source/WebCore/rendering/RenderThemeCocoa.mm
new file mode 100644 (file)
index 0000000..74eb7fc
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RenderThemeCocoa.h"
+
+#if ENABLE(APPLE_PAY)
+
+#include "PassKitSPI.h"
+#include "RenderElement.h"
+#include "RenderStyle.h"
+#include "SoftLinking.h"
+#include "TranslateTransformOperation.h"
+
+#if PLATFORM(MAC)
+SOFT_LINK_PRIVATE_FRAMEWORK(PassKit);
+#else
+SOFT_LINK_FRAMEWORK(PassKit);
+#endif
+
+SOFT_LINK_MAY_FAIL(PassKit, PKDrawApplePayButton, void, (CGContextRef context, CGRect drawRect, CGFloat scale, PKPaymentButtonType type, PKPaymentButtonStyle style, NSString *languageCode), (context, drawRect, scale, type, style, languageCode));
+
+namespace WebCore {
+
+static const auto applePayButtonMinimumWidth = 140;
+static const auto applePayButtonPlainMinimumWidth = 100;
+static const auto applePayButtonMinimumHeight = 30;
+
+void RenderThemeCocoa::adjustApplePayButtonStyle(StyleResolver&, RenderStyle& style, const Element*) const
+{
+    if (style.applePayButtonType() == ApplePayButtonType::Plain)
+        style.setMinWidth(Length(applePayButtonPlainMinimumWidth, Fixed));
+    else
+        style.setMinWidth(Length(applePayButtonMinimumWidth, Fixed));
+    style.setMinHeight(Length(applePayButtonMinimumHeight, Fixed));
+}
+
+static PKPaymentButtonStyle toPKPaymentButtonStyle(ApplePayButtonStyle style)
+{
+    switch (style) {
+    case ApplePayButtonStyle::White:
+        return PKPaymentButtonStyleWhite;
+    case ApplePayButtonStyle::WhiteOutline:
+        return PKPaymentButtonStyleWhiteOutline;
+    case ApplePayButtonStyle::Black:
+        return PKPaymentButtonStyleBlack;
+    }
+}
+
+static PKPaymentButtonType toPKPaymentButtonType(ApplePayButtonType type)
+{
+    switch (type) {
+    case ApplePayButtonType::Plain:
+        return PKPaymentButtonTypePlain;
+    case ApplePayButtonType::Buy:
+        return PKPaymentButtonTypeBuy;
+    case ApplePayButtonType::SetUp:
+        return PKPaymentButtonTypeSetUp;
+    case ApplePayButtonType::InStore:
+        return PKPaymentButtonTypeInStore;
+    }
+}
+
+bool RenderThemeCocoa::paintApplePayButton(const RenderObject& renderer, const PaintInfo& paintInfo, const IntRect& paintRect)
+{
+    if (!canLoadPKDrawApplePayButton())
+        return false;
+
+    GraphicsContextStateSaver stateSaver(paintInfo.context());
+
+    paintInfo.context().setShouldSmoothFonts(true);
+    paintInfo.context().scale(FloatSize(1, -1));
+
+    PKDrawApplePayButton(paintInfo.context().platformContext(), CGRectMake(paintRect.x(), -paintRect.maxY(), paintRect.width(), paintRect.height()), 1.0, toPKPaymentButtonType(renderer.style().applePayButtonType()), toPKPaymentButtonStyle(renderer.style().applePayButtonStyle()), renderer.style().locale());
+
+    return false;
+}
+
+}
+
+#endif
index ffb2e3f..fdd7c0a 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef RenderThemeIOS_h
-#define RenderThemeIOS_h
+#pragma once
 
 #if PLATFORM(IOS)
 
-#include "RenderTheme.h"
+#include "RenderThemeCocoa.h"
 
 namespace WebCore {
     
@@ -36,7 +35,7 @@ class RenderStyle;
 class GraphicsContext;
 struct AttachmentLayout;
 
-class RenderThemeIOS final : public RenderTheme {
+class RenderThemeIOS final : public RenderThemeCocoa {
 public:
     static Ref<RenderTheme> create();
 
@@ -135,4 +134,3 @@ private:
 }
 
 #endif // PLATFORM(IOS)
-#endif // RenderThemeIOS_h
index 4e00a48..658f883 100644 (file)
  * Boston, MA 02110-1301, USA.
  *
  */
-#if !PLATFORM(IOS)
 
-#ifndef RenderThemeMac_h
-#define RenderThemeMac_h
+#pragma once
 
-#import "RenderTheme.h"
+#if PLATFORM(MAC)
+
+#import "RenderThemeCocoa.h"
 #import <wtf/RetainPtr.h>
 #import <wtf/HashMap.h>
 
@@ -40,7 +40,7 @@ class RenderProgress;
 class RenderStyle;
 struct AttachmentLayout;
 
-class RenderThemeMac final : public RenderTheme {
+class RenderThemeMac final : public RenderThemeCocoa {
 public:
     static Ref<RenderTheme> create();
 
@@ -250,6 +250,4 @@ private:
 
 } // namespace WebCore
 
-#endif // RenderThemeMac_h
-
-#endif // !PLATFORM(IOS)
+#endif // PLATFORM(MAC)
index 3c05a7c..385d4e5 100644 (file)
@@ -1218,7 +1218,12 @@ public:
 #if ENABLE(CSS_TRAILING_WORD)
     TrailingWord trailingWord() const { return static_cast<TrailingWord>(rareInheritedData->trailingWord); }
 #endif
-    
+
+#if ENABLE(APPLE_PAY)
+    ApplePayButtonStyle applePayButtonStyle() const { return static_cast<ApplePayButtonStyle>(rareNonInheritedData->m_applePayButtonStyle); }
+    ApplePayButtonType applePayButtonType() const { return static_cast<ApplePayButtonType>(rareNonInheritedData->m_applePayButtonType); }
+#endif
+
     void checkVariablesInCustomProperties();
 
 // attribute setter methods
@@ -1735,6 +1740,11 @@ public:
     void setTrailingWord(TrailingWord v) { SET_VAR(rareInheritedData, trailingWord, static_cast<unsigned>(v)); }
 #endif
 
+#if ENABLE(APPLE_PAY)
+    void setApplePayButtonStyle(ApplePayButtonStyle v) { SET_VAR(rareNonInheritedData, m_applePayButtonStyle, static_cast<unsigned>(v)); }
+    void setApplePayButtonType(ApplePayButtonType v) { SET_VAR(rareNonInheritedData, m_applePayButtonType, static_cast<unsigned>(v)); }
+#endif
+
     const SVGRenderStyle& svgStyle() const { return *m_svgStyle; }
     SVGRenderStyle& accessSVGStyle() { return *m_svgStyle.access(); }
 
@@ -2086,6 +2096,11 @@ public:
     static TrailingWord initialTrailingWord() { return TrailingWord::Auto; }
 #endif
 
+#if ENABLE(APPLE_PAY)
+    static ApplePayButtonStyle initialApplePayButtonStyle() { return ApplePayButtonStyle::Black; }
+    static ApplePayButtonType initialApplePayButtonType() { return ApplePayButtonType::Plain; }
+#endif
+
 #if ENABLE(CSS_GRID_LAYOUT)
     // The initial value is 'none' for grid tracks.
     static Vector<GridTrackSize> initialGridColumns() { return Vector<GridTrackSize>(); }
index 3518c2f..7caf715 100644 (file)
@@ -696,6 +696,21 @@ enum class TrailingWord {
 };
 #endif
 
+#if ENABLE(APPLE_PAY)
+enum class ApplePayButtonStyle {
+    White,
+    WhiteOutline,
+    Black,
+};
+
+enum class ApplePayButtonType {
+    Plain,
+    Buy,
+    SetUp,
+    InStore,
+};
+#endif
+
 TextStream& operator<<(TextStream&, EFillSizeType);
 TextStream& operator<<(TextStream&, EFillAttachment);
 TextStream& operator<<(TextStream&, EFillBox);
index 09d5aa4..2054110 100644 (file)
@@ -104,6 +104,10 @@ StyleRareNonInheritedData::StyleRareNonInheritedData()
     , m_effectiveBlendMode(RenderStyle::initialBlendMode())
     , m_isolation(RenderStyle::initialIsolation())
 #endif
+#if ENABLE(APPLE_PAY)
+    , m_applePayButtonStyle(static_cast<unsigned>(RenderStyle::initialApplePayButtonStyle()))
+    , m_applePayButtonType(static_cast<unsigned>(RenderStyle::initialApplePayButtonType()))
+#endif
     , m_objectFit(RenderStyle::initialObjectFit())
     , m_breakBefore(RenderStyle::initialBreakBetween())
     , m_breakAfter(RenderStyle::initialBreakBetween())
@@ -200,6 +204,10 @@ inline StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonIn
     , m_effectiveBlendMode(o.m_effectiveBlendMode)
     , m_isolation(o.m_isolation)
 #endif
+#if ENABLE(APPLE_PAY)
+    , m_applePayButtonStyle(o.m_applePayButtonStyle)
+    , m_applePayButtonType(o.m_applePayButtonType)
+#endif
     , m_objectFit(o.m_objectFit)
     , m_breakBefore(o.m_breakBefore)
     , m_breakAfter(o.m_breakAfter)
@@ -306,6 +314,10 @@ bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) c
         && m_effectiveBlendMode == o.m_effectiveBlendMode
         && m_isolation == o.m_isolation
 #endif
+#if ENABLE(APPLE_PAY)
+        && m_applePayButtonStyle == o.m_applePayButtonStyle
+        && m_applePayButtonType == o.m_applePayButtonType
+#endif
         && m_aspectRatioType == o.m_aspectRatioType
         && m_objectFit == o.m_objectFit
         && m_breakAfter == o.m_breakAfter
index e5f78ad..f7035c3 100644 (file)
@@ -22,8 +22,7 @@
  *
  */
 
-#ifndef StyleRareNonInheritedData_h
-#define StyleRareNonInheritedData_h
+#pragma once
 
 #include "BasicShapes.h"
 #include "CSSPropertyNames.h"
@@ -219,6 +218,11 @@ public:
     unsigned m_isolation : 1; // Isolation
 #endif
 
+#if ENABLE(APPLE_PAY)
+    unsigned m_applePayButtonStyle : 2;
+    unsigned m_applePayButtonType : 3;
+#endif
+
     unsigned m_objectFit : 3; // ObjectFit
     
     unsigned m_breakBefore : 4; // BreakBetween
@@ -236,5 +240,3 @@ private:
 };
 
 } // namespace WebCore
-
-#endif // StyleRareNonInheritedData_h