Changeset 266993 in webkit
- Timestamp:
- Sep 13, 2020 8:43:58 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r266992 r266993 1 2020-09-13 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add a key to the text manipulation userInfo dictionary indicating whether the translated item is on-screen 4 https://bugs.webkit.org/show_bug.cgi?id=216452 5 <rdar://problem/68785397> 6 7 Reviewed by Darin Adler. 8 9 For debugging purposes, and also to provide a hint as to what text should be prioritized when translating 10 web pages, WebKit clients have requested a new field in the userInfo metadata dictionary associated with each 11 token that indicates whether or not a translation (i.e. text manipulation) token represents an element that is 12 currently on-screen. See below for more details. 13 14 Test: TextManipulation.StartTextManipulationExtractsUserInfo 15 16 * editing/TextManipulationController.cpp: 17 (WebCore::tokenInfo): 18 19 Set the flag by checking whether or not the absolute bounding rect intersects with the visible content rect of 20 the enclosing frame. Note that since subframe content is currently never extracted for translation, we don't 21 need logic yet to recursively check that parent iframe elements are visible. 22 23 * editing/TextManipulationController.h: 24 25 Add a new `bool` flag in `ManipulationTokenInfo`. 26 27 (WebCore::TextManipulationController::ManipulationTokenInfo::encode const): 28 (WebCore::TextManipulationController::ManipulationTokenInfo::decode): 29 1 30 2020-09-13 Philippe Normand <pnormand@igalia.com> 2 31 -
trunk/Source/WebCore/editing/TextManipulationController.cpp
r266075 r266993 298 298 if (element->hasAttributeWithoutSynchronization(HTMLNames::roleAttr)) 299 299 result.roleAttribute = element->attributeWithoutSynchronization(HTMLNames::roleAttr); 300 if (auto frame = makeRefPtr(node->document().frame()); frame && frame->view() && element->renderer()) { 301 // FIXME: This doesn't account for overflow clip. 302 auto elementRect = element->renderer()->absoluteAnchorRect(); 303 auto visibleContentRect = frame->view()->visibleContentRect(); 304 result.isVisible = visibleContentRect.intersects(enclosingIntRect(elementRect)); 305 } 300 306 } 301 307 return result; -
trunk/Source/WebCore/editing/TextManipulationController.h
r265286 r266993 53 53 String roleAttribute; 54 54 URL documentURL; 55 bool isVisible { false }; 55 56 56 57 template<class Encoder> void encode(Encoder&) const; … … 203 204 encoder << roleAttribute; 204 205 encoder << documentURL; 206 encoder << isVisible; 205 207 } 206 208 … … 216 218 217 219 if (!decoder.decode(result.documentURL)) 220 return WTF::nullopt; 221 222 if (!decoder.decode(result.isVisible)) 218 223 return WTF::nullopt; 219 224 -
trunk/Source/WebKit/ChangeLog
r266990 r266993 1 2020-09-13 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add a key to the text manipulation userInfo dictionary indicating whether the translated item is on-screen 4 https://bugs.webkit.org/show_bug.cgi?id=216452 5 <rdar://problem/68785397> 6 7 Reviewed by Darin Adler. 8 9 Add `_WKTextManipulationTokenUserInfoVisibilityKey` and set its value to the value of the `isVisible` member in 10 `ManipulationTokenInfo`. See WebCore ChangeLog for more details. 11 12 * UIProcess/API/Cocoa/WKWebView.mm: 13 (createUserInfo): 14 * UIProcess/API/Cocoa/_WKTextManipulationToken.h: 15 * UIProcess/API/Cocoa/_WKTextManipulationToken.mm: 16 1 17 2020-09-13 Pablo Saavedra <psaavedra@igalia.com> 2 18 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r266890 r266993 1623 1623 if (!info->roleAttribute.isNull()) 1624 1624 [result setObject:(NSString *)info->roleAttribute forKey:_WKTextManipulationTokenUserInfoRoleAttributeKey]; 1625 [result setObject:@(info->isVisible) forKey:_WKTextManipulationTokenUserInfoVisibilityKey]; 1625 1626 1626 1627 return result; -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.h
r260865 r266993 32 32 WK_EXTERN NSString * const _WKTextManipulationTokenUserInfoTagNameKey WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 33 33 WK_EXTERN NSString * const _WKTextManipulationTokenUserInfoRoleAttributeKey WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 34 WK_EXTERN NSString * const _WKTextManipulationTokenUserInfoVisibilityKey WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 34 35 35 36 WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)) -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.mm
r260865 r266993 32 32 NSString * const _WKTextManipulationTokenUserInfoTagNameKey = @"_WKTextManipulationTokenUserInfoTagNameKey"; 33 33 NSString * const _WKTextManipulationTokenUserInfoRoleAttributeKey = @"_WKTextManipulationTokenUserInfoRoleAttributeKey"; 34 NSString * const _WKTextManipulationTokenUserInfoVisibilityKey = @"_WKTextManipulationTokenUserInfoVisibilityKey"; 34 35 35 36 @implementation _WKTextManipulationToken { -
trunk/Tools/ChangeLog
r266988 r266993 1 2020-09-13 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add a key to the text manipulation userInfo dictionary indicating whether the translated item is on-screen 4 https://bugs.webkit.org/show_bug.cgi?id=216452 5 <rdar://problem/68785397> 6 7 Reviewed by Darin Adler. 8 9 Adjust an existing test so that it adds a fourth text paragraph with 2000px of top margin, and also 10 programmatically scrolls after loading the page so that only this last paragraph is visible. We expect the 11 metadata to indicate that none of the other tokens except this last one has a value of `YES` for 12 `_WKTextManipulationTokenUserInfoVisibilityKey`. 13 14 * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm: 15 (TestWebKitAPI::TEST): 16 1 17 2020-09-12 Darin Adler <darin@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm
r266075 r266993 802 802 " <div role='button'>Second</div>" 803 803 " <span>Third</span>" 804 " <div style='margin-top: 2000px;'>Fourth</div>" 805 " <script>scrollTo(0, 2000);</script>" 804 806 "</body>"]; 805 807 808 [webView waitForNextPresentationUpdate]; 809 806 810 done = false; 807 811 [webView _startTextManipulationsWithConfiguration:nil completion:^{ … … 811 815 812 816 auto items = [delegate items]; 813 EXPECT_EQ(items.count, 4UL);817 EXPECT_EQ(items.count, 5UL); 814 818 EXPECT_EQ(items[0].tokens.count, 1UL); 815 819 EXPECT_EQ(items[1].tokens.count, 1UL); 816 820 EXPECT_EQ(items[2].tokens.count, 1UL); 817 821 EXPECT_EQ(items[3].tokens.count, 1UL); 822 EXPECT_EQ(items[4].tokens.count, 1UL); 818 823 EXPECT_WK_STREQ("This is a test", items[0].tokens[0].content); 819 824 EXPECT_WK_STREQ("First", items[1].tokens[0].content); 820 825 EXPECT_WK_STREQ("Second", items[2].tokens[0].content); 821 826 EXPECT_WK_STREQ("Third", items[3].tokens[0].content); 827 EXPECT_WK_STREQ("Fourth", items[4].tokens[0].content); 822 828 { 823 829 auto userInfo = items[0].tokens[0].userInfo; 824 830 EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]); 825 831 EXPECT_WK_STREQ("TITLE", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]); 832 EXPECT_FALSE([userInfo[_WKTextManipulationTokenUserInfoVisibilityKey] boolValue]); 826 833 } 827 834 { … … 829 836 EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]); 830 837 EXPECT_WK_STREQ("P", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]); 838 EXPECT_FALSE([userInfo[_WKTextManipulationTokenUserInfoVisibilityKey] boolValue]); 831 839 } 832 840 { … … 835 843 EXPECT_WK_STREQ("DIV", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]); 836 844 EXPECT_WK_STREQ("button", (NSString *)userInfo[_WKTextManipulationTokenUserInfoRoleAttributeKey]); 845 EXPECT_FALSE([userInfo[_WKTextManipulationTokenUserInfoVisibilityKey] boolValue]); 837 846 } 838 847 { … … 840 849 EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]); 841 850 EXPECT_WK_STREQ("SPAN", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]); 851 EXPECT_FALSE([userInfo[_WKTextManipulationTokenUserInfoVisibilityKey] boolValue]); 852 } 853 { 854 auto userInfo = items[4].tokens[0].userInfo; 855 EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]); 856 EXPECT_WK_STREQ("DIV", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]); 857 EXPECT_TRUE([userInfo[_WKTextManipulationTokenUserInfoVisibilityKey] boolValue]); 842 858 } 843 859 }
Note: See TracChangeset
for help on using the changeset viewer.