Diff
Modified: trunk/LayoutTests/ChangeLog (235913 => 235914)
--- trunk/LayoutTests/ChangeLog 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/LayoutTests/ChangeLog 2018-09-11 21:56:17 UTC (rev 235914)
@@ -1,3 +1,22 @@
+2018-09-11 Wenson Hsieh <[email protected]>
+
+ [macOS] [WK2] Support changing foreground colors via color panel
+ https://bugs.webkit.org/show_bug.cgi?id=189382
+ <rdar://problem/44227311>
+
+ Reviewed by Ryosuke Niwa.
+
+ Adjust an existing layout test that applies a text color with alpha. Currently, this results in a font element
+ being emitted with the `color` attribute, but this is incorrect, since the `color` attribute of a font element
+ does not support "rgba(…)" values.
+
+ Instead, split this into two cases: verify that setting the color to an opaque color (with alpha = 1) emits a
+ font element with the correct `color` attribute, and fall back to using an inline style when the color is
+ partially transparent.
+
+ * editing/style/inline-style-container-expected.txt:
+ * editing/style/inline-style-container.html:
+
2018-09-11 Justin Fan <[email protected]>
Update webkit-webgl-test-harness.js for more details on WebGL 2 conformance tests part 3
Modified: trunk/LayoutTests/editing/style/inline-style-container-expected.txt (235913 => 235914)
--- trunk/LayoutTests/editing/style/inline-style-container-expected.txt 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/LayoutTests/editing/style/inline-style-container-expected.txt 2018-09-11 21:56:17 UTC (rev 235914)
@@ -13,7 +13,8 @@
PASS fontName(Arial) on all of "<font color="blue">hello</font> world" yields "<font face="Arial"><font color="blue">hello</font> world</font>"
PASS fontName(Arial) on all of "<b><u>hello</u> world</b>" yields "<b><font face="Arial"><u>hello</u> world</font></b>"
PASS foreColor(blue) on all of "<font><u style="color:red;">hello</u></font>" yields "<font color="#0000ff"><u>hello</u></font>"
-PASS foreColor(rgba(0, 50, 100, 0.4)) on all of "<font><u style="color:red;">hello</u></font>" yields "<font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font>"
+PASS foreColor(rgb(0, 50, 100)) on all of "<font><u style="color:red;">hello</u></font>" yields "<font color="#003264"><u>hello</u></font>"
+PASS foreColor(rgba(0, 50, 100, 0.4)) on all of "<font color="#00ff00"><u>hello</u></font>" yields "<u style="color: rgba(0, 50, 100, 0.4);">hello</u>"
PASS bold(null) on all of "<u><strike>hello</strike> <strike>world</strike></u>" yields "<u><b><strike>hello</strike> <strike>world</strike></b></u>"
PASS bold(null) on all of "<i>hello</i> <b>world</b>" yields "<b><i>hello</i> world</b>"
PASS bold(null) on all of "<strike><i><u>hello <b>world</b></u></i> webkit</strike>" yields "<strike><b><i><u>hello world</u></i> webkit</b></strike>"
Modified: trunk/LayoutTests/editing/style/inline-style-container.html (235913 => 235914)
--- trunk/LayoutTests/editing/style/inline-style-container.html 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/LayoutTests/editing/style/inline-style-container.html 2018-09-11 21:56:17 UTC (rev 235914)
@@ -37,7 +37,8 @@
testSingleToggle("fontName", "Arial", '<font color="blue">hello</font> world', '<font face="Arial"><font color="blue">hello</font> world</font>');
testSingleToggle("fontName", "Arial", '<b><u>hello</u> world</b>', '<b><font face="Arial"><u>hello</u> world</font></b>');
testSingleToggle("foreColor", 'blue', '<font><u style="color:red;">hello</u></font>', '<font color="#0000ff"><u>hello</u></font>');
-testSingleToggle("foreColor", 'rgba(0, 50, 100, 0.4)', '<font><u style="color:red;">hello</u></font>', '<font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font>');
+testSingleToggle("foreColor", 'rgb(0, 50, 100)', '<font><u style="color:red;">hello</u></font>', '<font color="#003264"><u>hello</u></font>');
+testSingleToggle("foreColor", 'rgba(0, 50, 100, 0.4)', '<font color="#00ff00"><u>hello</u></font>', '<u style="color: rgba(0, 50, 100, 0.4);">hello</u>');
testSingleToggle("bold", null, '<u><strike>hello</strike> <strike>world</strike></u>', '<u><b><strike>hello</strike> <strike>world</strike></b></u>');
testSingleToggle("bold", null, '<i>hello</i> <b>world</b>', '<b><i>hello</i> world</b>');
testSingleToggle("bold", null, '<strike><i><u>hello <b>world</b></u></i> webkit</strike>', '<strike><b><i><u>hello world</u></i> webkit</b></strike>');
Modified: trunk/Source/WebCore/ChangeLog (235913 => 235914)
--- trunk/Source/WebCore/ChangeLog 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebCore/ChangeLog 2018-09-11 21:56:17 UTC (rev 235914)
@@ -1,3 +1,30 @@
+2018-09-11 Wenson Hsieh <[email protected]>
+
+ [macOS] [WK2] Support changing foreground colors via color panel
+ https://bugs.webkit.org/show_bug.cgi?id=189382
+ <rdar://problem/44227311>
+
+ Reviewed by Ryosuke Niwa.
+
+ Small adjustments to support changing foreground text color using NSColorPanel in WebKit2. See comments below.
+ Tested by FontManagerTests.ChangeFontColorWithColorPanel.
+
+ * editing/EditingStyle.cpp:
+ (WebCore::StyleChange::extractTextStyles):
+
+ Support setting foreground text color with alpha by using a styled span element rather than a font element with
+ attributes. To do this, only populate `StyleChange::m_applyFontColor` if the color is opaque. This is because
+ the font element does not support `rgba()` syntax, so any font colors here with alpha that are serialized to
+ `rgba()` result in a garbage value for the computed color style.
+
+ * editing/FontAttributeChanges.cpp:
+ (WebCore::FontAttributeChanges::editAction const):
+
+ Add a helper to return the relevant EditAction describing this set of FontAttributeChanges.
+
+ * editing/FontAttributeChanges.h:
+ (WebCore::FontChanges::isEmpty const):
+
2018-09-11 Yusuke Suzuki <[email protected]>
Shrink size of ResourseResponseBase
Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (235913 => 235914)
--- trunk/Source/WebCore/editing/EditingStyle.cpp 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp 2018-09-11 21:56:17 UTC (rev 235914)
@@ -1720,8 +1720,11 @@
}
if (style.getPropertyCSSValue(CSSPropertyColor)) {
- m_applyFontColor = Color(textColorFromStyle(style)).serialized();
- style.removeProperty(CSSPropertyColor);
+ auto color = textColorFromStyle(style);
+ if (color.isOpaque()) {
+ m_applyFontColor = color.serialized();
+ style.removeProperty(CSSPropertyColor);
+ }
}
m_applyFontFace = style.getPropertyValue(CSSPropertyFontFamily);
Modified: trunk/Source/WebCore/editing/FontAttributeChanges.cpp (235913 => 235914)
--- trunk/Source/WebCore/editing/FontAttributeChanges.cpp 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebCore/editing/FontAttributeChanges.cpp 2018-09-11 21:56:17 UTC (rev 235914)
@@ -31,6 +31,7 @@
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
#include "CSSValuePool.h"
+#include "EditAction.h"
#include "EditingStyle.h"
#include "StyleProperties.h"
@@ -93,6 +94,18 @@
return list.ptr();
}
+EditAction FontAttributeChanges::editAction() const
+{
+ if (!m_verticalAlign && !m_backgroundColor && !m_shadow && !m_strikeThrough && !m_underline) {
+ if (m_foregroundColor && m_fontChanges.isEmpty())
+ return EditAction::SetColor;
+
+ if (!m_foregroundColor && !m_fontChanges.isEmpty())
+ return EditAction::SetFont;
+ }
+ return EditAction::ChangeAttributes;
+}
+
Ref<EditingStyle> FontAttributeChanges::createEditingStyle() const
{
auto style = m_fontChanges.createStyleProperties();
Modified: trunk/Source/WebCore/editing/FontAttributeChanges.h (235913 => 235914)
--- trunk/Source/WebCore/editing/FontAttributeChanges.h 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebCore/editing/FontAttributeChanges.h 2018-09-11 21:56:17 UTC (rev 235914)
@@ -35,6 +35,7 @@
class EditingStyle;
class MutableStyleProperties;
+enum class EditAction : uint8_t;
enum class VerticalAlignChange : uint8_t { Superscript, Baseline, Subscript };
class FontChanges {
@@ -49,6 +50,11 @@
void setBold(bool bold) { m_bold = bold; }
void setItalic(bool italic) { m_italic = italic; }
+ bool isEmpty() const
+ {
+ return !m_fontName && !m_fontFamily && !m_fontSize && !m_fontSizeDelta && !m_bold && !m_italic;
+ }
+
WEBCORE_EXPORT Ref<EditingStyle> createEditingStyle() const;
Ref<MutableStyleProperties> createStyleProperties() const;
@@ -87,6 +93,7 @@
void setFontChanges(const FontChanges& fontChanges) { m_fontChanges = fontChanges; }
WEBCORE_EXPORT Ref<EditingStyle> createEditingStyle() const;
+ WEBCORE_EXPORT EditAction editAction() const;
private:
std::optional<VerticalAlignChange> m_verticalAlign;
Modified: trunk/Source/WebKit/ChangeLog (235913 => 235914)
--- trunk/Source/WebKit/ChangeLog 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebKit/ChangeLog 2018-09-11 21:56:17 UTC (rev 235914)
@@ -1,3 +1,33 @@
+2018-09-11 Wenson Hsieh <[email protected]>
+
+ [macOS] [WK2] Support changing foreground colors via color panel
+ https://bugs.webkit.org/show_bug.cgi?id=189382
+ <rdar://problem/44227311>
+
+ Reviewed by Ryosuke Niwa.
+
+ Adds support for changing font color in a richly editable element in WebKit2 via NSColorPanel. See below for
+ more detail, as well as the WebCore ChangeLog.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView changeColor:]):
+
+ Implement this selector; AppKit calls into this when changing font color using NSColorPanel.
+
+ * UIProcess/Cocoa/WebViewImpl.h:
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::changeFontColorFromSender):
+
+ Creates and populates new FontAttributeChanges, with only the foreground color determined by asking the sender
+ object for its -color.
+
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+
+ Use the relevant EditAction for the incoming FontAttributeChanges, instead of always specifying
+ EditAction::ChangeAttributes.
+
+ (WebKit::WebPage::changeFontAttributes):
+
2018-09-11 Myles C. Maxfield <[email protected]>
Crash under PlatformPopupMenuData::encode when interacting with a select menu that has variable fonts
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (235913 => 235914)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2018-09-11 21:56:17 UTC (rev 235914)
@@ -3387,6 +3387,11 @@
_impl->changeFontFromFontManager();
}
+- (void)changeColor:(id)sender
+{
+ _impl->changeFontColorFromSender(sender);
+}
+
- (void)changeAttributes:(id)sender
{
_impl->changeFontAttributesFromSender(sender);
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (235913 => 235914)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h 2018-09-11 21:56:17 UTC (rev 235914)
@@ -317,6 +317,7 @@
void updateFontPanelIfNeeded();
void changeFontFromFontManager();
void changeFontAttributesFromSender(id);
+ void changeFontColorFromSender(id);
bool validateUserInterfaceItem(id <NSValidatedUserInterfaceItem>);
void setEditableElementIsFocused(bool);
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (235913 => 235914)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2018-09-11 21:56:17 UTC (rev 235914)
@@ -2749,6 +2749,24 @@
}
}
+void WebViewImpl::changeFontColorFromSender(id sender)
+{
+ if (![sender respondsToSelector:@selector(color)])
+ return;
+
+ id color = [sender color];
+ if (![color isKindOfClass:NSColor.class])
+ return;
+
+ auto& editorState = m_page->editorState();
+ if (!editorState.isContentEditable || editorState.selectionIsNone)
+ return;
+
+ WebCore::FontAttributeChanges changes;
+ changes.setForegroundColor(WebCore::colorFromNSColor((NSColor *)color));
+ m_page->changeFontAttributes(WTFMove(changes));
+}
+
void WebViewImpl::changeFontAttributesFromSender(id sender)
{
auto& editorState = m_page->editorState();
Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (235913 => 235914)
--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2018-09-11 21:56:17 UTC (rev 235914)
@@ -1119,7 +1119,7 @@
{
auto& frame = m_page->focusController().focusedOrMainFrame();
if (frame.selection().selection().isContentEditable())
- frame.editor().applyStyleToSelection(changes.createEditingStyle(), EditAction::ChangeAttributes, Editor::ColorFilterMode::InvertColor);
+ frame.editor().applyStyleToSelection(changes.createEditingStyle(), changes.editAction(), Editor::ColorFilterMode::InvertColor);
}
void WebPage::changeFont(WebCore::FontChanges&& changes)
Modified: trunk/Tools/ChangeLog (235913 => 235914)
--- trunk/Tools/ChangeLog 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Tools/ChangeLog 2018-09-11 21:56:17 UTC (rev 235914)
@@ -1 +1,19 @@
+2018-09-11 Wenson Hsieh <[email protected]>
+
+ [macOS] [WK2] Support changing foreground colors via color panel
+ https://bugs.webkit.org/show_bug.cgi?id=189382
+ <rdar://problem/44227311>
+
+ Reviewed by Ryosuke Niwa.
+
+ Add an API test that uses NSColorPanel to change the color of selected text, and also apply typing styles when
+ the selection is collapsed. The test also exercises switching between opaque colors (alpha = 1) and transparent
+ colors, as well as making different parts of a word different colors.
+
+ * TestWebKitAPI/Tests/mac/FontManagerTests.mm:
+ (-[TestWKWebView collapseToEnd]):
+ (webViewForFontManagerTesting):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/cocoa/TestWKWebView.h:
+
== Rolled over to ChangeLog-2018-09-11 ==
Modified: trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm (235913 => 235914)
--- trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm 2018-09-11 21:56:17 UTC (rev 235914)
@@ -40,6 +40,7 @@
- (NSString *)stylePropertyAtSelectionStart:(NSString *)propertyName;
- (NSString *)stylePropertyAtSelectionEnd:(NSString *)propertyName;
- (void)selectNextWord;
+- (void)collapseToEnd;
@end
@@ -57,6 +58,11 @@
[self selectWord:nil];
}
+- (void)collapseToEnd
+{
+ [self evaluateJavaScript:@"getSelection().collapseToEnd()" completionHandler:nil];
+}
+
- (NSString *)stylePropertyAtSelectionStart:(NSString *)propertyName
{
NSString *script = [NSString stringWithFormat:@"getComputedStyle(getSelection().getRangeAt(0).startContainer.parentElement)['%@']", propertyName];
@@ -74,7 +80,9 @@
static RetainPtr<TestWKWebView> webViewForFontManagerTesting(NSFontManager *fontManager)
{
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
- [webView synchronouslyLoadHTMLString:@"<body contenteditable><span id='foo'>foo</span> <span id='bar'>bar</span> <span id='baz'>baz</span></body>"];
+ [webView synchronouslyLoadHTMLString:@"<body contenteditable>"
+ "<span id='foo'>foo</span> <span id='bar'>bar</span> <span id='baz'>baz</span>"
+ "</body><script>document.body.addEventListener('input', event => lastInputEvent = event)</script>"];
[webView stringByEvaluatingJavaScript:@"document.body.focus()"];
fontManager.target = webView.get();
return webView;
@@ -93,7 +101,7 @@
TEST(FontManagerTests, ChangeFontSizeWithMenuItems)
{
- NSFontManager *fontManager = [NSFontManager sharedFontManager];
+ NSFontManager *fontManager = NSFontManager.sharedFontManager;
auto webView = webViewForFontManagerTesting(fontManager);
auto sizeIncreaseMenuItemCell = menuItemCellForFontAction(NSSizeUpFontAction);
@@ -133,7 +141,7 @@
TEST(FontManagerTests, ChangeFontWithPanel)
{
- NSFontManager *fontManager = [NSFontManager sharedFontManager];
+ NSFontManager *fontManager = NSFontManager.sharedFontManager;
auto webView = webViewForFontManagerTesting(fontManager);
NSFontPanel *fontPanel = [fontManager fontPanel:YES];
@@ -182,7 +190,7 @@
TEST(FontManagerTests, ChangeAttributesWithFontEffectsBox)
{
- NSFontManager *fontManager = [NSFontManager sharedFontManager];
+ NSFontManager *fontManager = NSFontManager.sharedFontManager;
auto webView = webViewForFontManagerTesting(fontManager);
NSFontPanel *fontPanel = [fontManager fontPanel:YES];
@@ -248,6 +256,60 @@
EXPECT_WK_STREQ("none", textDecorationsAroundSelection());
}
+TEST(FontManagerTests, ChangeFontColorWithColorPanel)
+{
+ NSColorPanel *colorPanel = NSColorPanel.sharedColorPanel;
+ colorPanel.showsAlpha = YES;
+
+ auto webView = webViewForFontManagerTesting(NSFontManager.sharedFontManager);
+ auto checkFontColorAtStartAndEndWithInputEvents = [webView] (const char* colorAsString) {
+ EXPECT_WK_STREQ(colorAsString, [webView stylePropertyAtSelectionStart:@"color"]);
+ EXPECT_WK_STREQ(colorAsString, [webView stylePropertyAtSelectionEnd:@"color"]);
+ EXPECT_WK_STREQ("formatFontColor", [webView stringByEvaluatingJavaScript:@"lastInputEvent.inputType"]);
+ EXPECT_WK_STREQ(colorAsString, [webView stringByEvaluatingJavaScript:@"lastInputEvent.data"]);
+ };
+
+ // 1. Select "foo" and turn it red; verify that the font element is used for fully opaque colors.
+ colorPanel.color = NSColor.redColor;
+ [webView selectWord:nil];
+ [webView changeColor:colorPanel];
+ checkFontColorAtStartAndEndWithInputEvents("rgb(255, 0, 0)");
+ EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"!!foo.querySelector('font')"] boolValue]);
+
+ // 2. Now select "bar" and try a few different colors, starting with a color with alpha.
+ colorPanel.color = [NSColor colorWithWhite:1 alpha:0.2];
+ [webView selectNextWord];
+ [webView changeColor:colorPanel];
+ checkFontColorAtStartAndEndWithInputEvents("rgba(255, 255, 255, 0.2)");
+ EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"!!bar.querySelector('font')"] boolValue]);
+
+ // 3a. Switch back to a solid color.
+ colorPanel.color = [NSColor colorWithRed:0.8 green:0.7 blue:0.2 alpha:1];
+ [webView changeColor:colorPanel];
+ checkFontColorAtStartAndEndWithInputEvents("rgb(204, 179, 51)");
+ EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"!!bar.querySelector('font')"] boolValue]);
+
+ // 3b. Switch back again to a color with alpha.
+ colorPanel.color = [NSColor colorWithRed:0.8 green:0.7 blue:0.2 alpha:0.2];
+ [webView changeColor:colorPanel];
+ checkFontColorAtStartAndEndWithInputEvents("rgba(204, 179, 51, 0.2)");
+ EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"!!bar.querySelector('font')"] boolValue]);
+
+ // 4a. Now collapse the selection to the end and set the typing style color to green.
+ colorPanel.color = NSColor.greenColor;
+ [webView collapseToEnd];
+ [webView changeColor:colorPanel];
+ EXPECT_WK_STREQ("formatFontColor", [webView stringByEvaluatingJavaScript:@"lastInputEvent.inputType"]);
+ EXPECT_WK_STREQ("rgb(0, 255, 0)", [webView stringByEvaluatingJavaScript:@"lastInputEvent.data"]);
+
+ // 4b. This should result in inserting green text.
+ [webView insertText:@"green"];
+ [webView moveWordBackward:nil];
+ [webView selectWord:nil];
+ EXPECT_WK_STREQ("rgba(204, 179, 51, 0.2)", [webView stylePropertyAtSelectionStart:@"color"]);
+ EXPECT_WK_STREQ("rgb(0, 255, 0)", [webView stylePropertyAtSelectionEnd:@"color"]);
+}
+
} // namespace TestWebKitAPI
#endif // PLATFORM(MAC) && WK_API_ENABLED
Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h (235913 => 235914)
--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h 2018-09-11 21:35:23 UTC (rev 235913)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h 2018-09-11 21:56:17 UTC (rev 235914)
@@ -39,6 +39,7 @@
#if PLATFORM(MAC)
- (void)paste:(id)sender;
- (void)changeAttributes:(id)sender;
+- (void)changeColor:(id)sender;
#endif
@end