- Revision
- 253112
- Author
- [email protected]
- Date
- 2019-12-04 10:36:15 -0800 (Wed, 04 Dec 2019)
Log Message
Add exclusion rule for text manipulation SPI to exclude based on element class
https://bugs.webkit.org/show_bug.cgi?id=204754
<rdar://problem/57398802>
Patch by Louie Livon-Bemel <[email protected]> on 2019-12-04
Reviewed by Ryosuke Niwa.
Source/WebCore:
Tests: TextManipulation.StartTextManipulationApplyInclusionExclusionRulesForClass
TextManipulation.StartTextManipulationApplyInclusionExclusionRulesForClassAndAttribute
* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::ExclusionRule::match const):
When matching a ClassRule, check that the element has at least one class, and that the classList contains
the rule's class name. Checking it this way rather than checking if the ClassList contains the rule allows
us to avoid mutating the element in this function.
* editing/TextManipulationController.h:
Add a new rule type for a ClassRule.
(WebCore::TextManipulationController::ExclusionRule::ClassRule::encode const):
(WebCore::TextManipulationController::ExclusionRule::ClassRule::decode):
Source/WebKit:
Give clients another option for adding an exclusion for text manipulation; allow them to exclude based on an
element having a certain class.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _startTextManipulationsWithConfiguration:completion:]):
If the rule doesn't have an attribute but does have a class name, treat it as a ClassRule exclusion.
* UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.h:
Add an initializer for excluding based on a class name. Also add a getter for the className.
* UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.mm:
(-[_WKTextManipulationExclusionRule initExclusion:forClass:]):
(-[_WKTextManipulationExclusionRule className]):
Tools:
* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
(TestWebKitAPI::TEST):
- When matching a class, it should work even with other class names on the element.
- All children elements should get the same exclusion rule, unless overridden by another rule.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (253111 => 253112)
--- trunk/Source/WebCore/ChangeLog 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Source/WebCore/ChangeLog 2019-12-04 18:36:15 UTC (rev 253112)
@@ -1,3 +1,24 @@
+2019-12-04 Louie Livon-Bemel <[email protected]>
+
+ Add exclusion rule for text manipulation SPI to exclude based on element class
+ https://bugs.webkit.org/show_bug.cgi?id=204754
+ <rdar://problem/57398802>
+
+ Reviewed by Ryosuke Niwa.
+
+ Tests: TextManipulation.StartTextManipulationApplyInclusionExclusionRulesForClass
+ TextManipulation.StartTextManipulationApplyInclusionExclusionRulesForClassAndAttribute
+
+ * editing/TextManipulationController.cpp:
+ (WebCore::TextManipulationController::ExclusionRule::match const):
+ When matching a ClassRule, check that the element has at least one class, and that the classList contains
+ the rule's class name. Checking it this way rather than checking if the ClassList contains the rule allows
+ us to avoid mutating the element in this function.
+ * editing/TextManipulationController.h:
+ Add a new rule type for a ClassRule.
+ (WebCore::TextManipulationController::ExclusionRule::ClassRule::encode const):
+ (WebCore::TextManipulationController::ExclusionRule::ClassRule::decode):
+
2019-12-04 Kenneth Russell <[email protected]>
Enable WebGL's ASTC extension all the time
Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (253111 => 253112)
--- trunk/Source/WebCore/editing/TextManipulationController.cpp 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp 2019-12-04 18:36:15 UTC (rev 253112)
@@ -41,6 +41,8 @@
return rule.localName == element.localName();
}, [&element] (AttributeRule rule) {
return equalIgnoringASCIICase(element.getAttribute(rule.name), rule.value);
+ }, [&element] (ClassRule rule) {
+ return element.hasClass() && element.classNames().contains(rule.className);
});
}
Modified: trunk/Source/WebCore/editing/TextManipulationController.h (253111 => 253112)
--- trunk/Source/WebCore/editing/TextManipulationController.h 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Source/WebCore/editing/TextManipulationController.h 2019-12-04 18:36:15 UTC (rev 253112)
@@ -74,8 +74,15 @@
template<class Decoder> static Optional<AttributeRule> decode(Decoder&);
};
+ struct ClassRule {
+ AtomString className;
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<ClassRule> decode(Decoder&);
+ };
+
Type type;
- WTF::Variant<ElementRule, AttributeRule> rule;
+ WTF::Variant<ElementRule, AttributeRule, ClassRule> rule;
bool match(const Element&) const;
@@ -181,6 +188,21 @@
return result;
}
+template<class Encoder>
+void TextManipulationController::ExclusionRule::ClassRule::encode(Encoder& encoder) const
+{
+ encoder << className;
+}
+
+template<class Decoder>
+Optional<TextManipulationController::ExclusionRule::ClassRule> TextManipulationController::ExclusionRule::ClassRule::decode(Decoder& decoder)
+{
+ ClassRule result;
+ if (!decoder.decode(result.className))
+ return WTF::nullopt;
+ return result;
+}
+
} // namespace WebCore
namespace WTF {
Modified: trunk/Source/WebKit/ChangeLog (253111 => 253112)
--- trunk/Source/WebKit/ChangeLog 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Source/WebKit/ChangeLog 2019-12-04 18:36:15 UTC (rev 253112)
@@ -1,3 +1,23 @@
+2019-12-04 Louie Livon-Bemel <[email protected]>
+
+ Add exclusion rule for text manipulation SPI to exclude based on element class
+ https://bugs.webkit.org/show_bug.cgi?id=204754
+ <rdar://problem/57398802>
+
+ Reviewed by Ryosuke Niwa.
+
+ Give clients another option for adding an exclusion for text manipulation; allow them to exclude based on an
+ element having a certain class.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _startTextManipulationsWithConfiguration:completion:]):
+ If the rule doesn't have an attribute but does have a class name, treat it as a ClassRule exclusion.
+ * UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.h:
+ Add an initializer for excluding based on a class name. Also add a getter for the className.
+ * UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.mm:
+ (-[_WKTextManipulationExclusionRule initExclusion:forClass:]):
+ (-[_WKTextManipulationExclusionRule className]):
+
2019-12-04 Kenneth Russell <[email protected]>
Enable WebGL's ASTC extension all the time
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (253111 => 253112)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-12-04 18:36:15 UTC (rev 253112)
@@ -7585,6 +7585,8 @@
auto type = wkRule.isExclusion ? ExclusionRule::Type::Exclude : ExclusionRule::Type::Include;
if (wkRule.attributeName)
exclusionRules.append({type, ExclusionRule::AttributeRule { wkRule.attributeName, wkRule.attributeValue } });
+ else if (wkRule.className)
+ exclusionRules.append({type, ExclusionRule::ClassRule { wkRule.className } });
else
exclusionRules.append({type, ExclusionRule::ElementRule { wkRule.elementName } });
}
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.h (253111 => 253112)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.h 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.h 2019-12-04 18:36:15 UTC (rev 253112)
@@ -33,10 +33,12 @@
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initExclusion:(BOOL)exclusion forElement:(NSString *)localName;
- (instancetype)initExclusion:(BOOL)exclusion forAttribute:(NSString *)name value:(NSString *)value;
+- (instancetype)initExclusion:(BOOL)exclusion forClass:(NSString *)className;
@property (nonatomic, readonly) BOOL isExclusion;
@property (nonatomic, readonly) NSString *elementName;
@property (nonatomic, readonly) NSString *attributeName;
@property (nonatomic, readonly) NSString *attributeValue;
+@property (nonatomic, readonly) NSString *className;
@end
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.mm (253111 => 253112)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.mm 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.mm 2019-12-04 18:36:15 UTC (rev 253112)
@@ -33,6 +33,7 @@
RetainPtr<NSString> _elementName;
RetainPtr<NSString> _attributeName;
RetainPtr<NSString> _attributeValue;
+ RetainPtr<NSString> _className;
}
- (instancetype)initExclusion:(BOOL)exclusion forElement:(NSString *)localName
@@ -58,6 +59,17 @@
return self;
}
+- (instancetype)initExclusion:(BOOL)exclusion forClass:(NSString *)className
+{
+ if (!(self = [super init]))
+ return nil;
+
+ _isExclusion = exclusion;
+ _className = className;
+
+ return self;
+}
+
- (NSString *)elementName
{
return _elementName.get();
@@ -73,5 +85,10 @@
return _attributeValue.get();
}
+- (NSString *)className
+{
+ return _className.get();
+}
+
@end
Modified: trunk/Tools/ChangeLog (253111 => 253112)
--- trunk/Tools/ChangeLog 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Tools/ChangeLog 2019-12-04 18:36:15 UTC (rev 253112)
@@ -1,3 +1,16 @@
+2019-12-04 Louie Livon-Bemel <[email protected]>
+
+ Add exclusion rule for text manipulation SPI to exclude based on element class
+ https://bugs.webkit.org/show_bug.cgi?id=204754
+ <rdar://problem/57398802>
+
+ Reviewed by Ryosuke Niwa.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+ (TestWebKitAPI::TEST):
+ - When matching a class, it should work even with other class names on the element.
+ - All children elements should get the same exclusion rule, unless overridden by another rule.
+
2019-12-04 youenn fablet <[email protected]>
WebProcessPool::terminateServiceWorkerProcess should be renamed terminateServiceWorkers
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (253111 => 253112)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2019-12-04 18:19:25 UTC (rev 253111)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm 2019-12-04 18:36:15 UTC (rev 253112)
@@ -236,6 +236,70 @@
EXPECT_FALSE(items[0].tokens[1].isExcluded);
}
+TEST(TextManipulation, StartTextManipulationApplyInclusionExclusionRulesForClass)
+{
+ auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+ [webView _setTextManipulationDelegate:delegate.get()];
+
+ [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html>"
+ "<html><body><span class='someClass exclude'>Message: <b>hello, </b><span>world</span></span></body></html>"];
+
+ auto configuration = adoptNS([[_WKTextManipulationConfiguration alloc] init]);
+ [configuration setExclusionRules:@[
+ [[[_WKTextManipulationExclusionRule alloc] initExclusion:YES forClass:@"exclude"] autorelease],
+ ]];
+
+ done = false;
+ [webView _startTextManipulationsWithConfiguration:configuration.get() completion:^{
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+
+ auto *items = [delegate items];
+ EXPECT_EQ(items.count, 1UL);
+ EXPECT_EQ(items[0].tokens.count, 3UL);
+ EXPECT_STREQ("Message: ", items[0].tokens[0].content.UTF8String);
+ EXPECT_TRUE(items[0].tokens[0].isExcluded);
+ EXPECT_STREQ("hello, ", items[0].tokens[1].content.UTF8String);
+ EXPECT_TRUE(items[0].tokens[1].isExcluded);
+ EXPECT_STREQ("world", items[0].tokens[2].content.UTF8String);
+ EXPECT_TRUE(items[0].tokens[2].isExcluded);
+}
+
+TEST(TextManipulation, StartTextManipulationApplyInclusionExclusionRulesForClassAndAttribute)
+{
+ auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+ [webView _setTextManipulationDelegate:delegate.get()];
+
+ [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html>"
+ "<html><body><span class='someClass exclude'>Message: <b data-exclude=no>hello, </b><span>world</span></span></body></html>"];
+
+ auto configuration = adoptNS([[_WKTextManipulationConfiguration alloc] init]);
+ [configuration setExclusionRules:@[
+ [[[_WKTextManipulationExclusionRule alloc] initExclusion:YES forAttribute:@"data-exclude" value:@"yes"] autorelease],
+ [[[_WKTextManipulationExclusionRule alloc] initExclusion:NO forAttribute:@"data-exclude" value:@"no"] autorelease],
+ [[[_WKTextManipulationExclusionRule alloc] initExclusion:YES forClass:@"exclude"] autorelease],
+ ]];
+
+ done = false;
+ [webView _startTextManipulationsWithConfiguration:configuration.get() completion:^{
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+
+ auto *items = [delegate items];
+ EXPECT_EQ(items.count, 1UL);
+ EXPECT_EQ(items[0].tokens.count, 3UL);
+ EXPECT_STREQ("Message: ", items[0].tokens[0].content.UTF8String);
+ EXPECT_TRUE(items[0].tokens[0].isExcluded);
+ EXPECT_STREQ("hello, ", items[0].tokens[1].content.UTF8String);
+ EXPECT_FALSE(items[0].tokens[1].isExcluded);
+ EXPECT_STREQ("world", items[0].tokens[2].content.UTF8String);
+ EXPECT_TRUE(items[0].tokens[2].isExcluded);
+}
+
struct Token {
NSString *identifier;
NSString *content;