Bug 141777

Summary: [WK2] Add support for font panel on OS X
Product: WebKit Reporter: Enrica Casucci <enrica>
Component: WebKit2Assignee: Enrica Casucci <enrica>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, buildbot, commit-queue, jberlin, rniwa, sam, thorton
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 142015    
Bug Blocks:    
Attachments:
Description Flags
Patch
buildbot: commit-queue-
Archive of layout-test-results from ews104 for mac-mavericks-wk2
none
Patch2
none
Patch3
none
Patch4
none
Patch5 thorton: review+

Description Enrica Casucci 2015-02-18 16:30:31 PST
We need to add the necessary hooks into WKWebView to interact with the font panel.
Comment 1 Enrica Casucci 2015-02-18 16:41:45 PST
Created attachment 246859 [details]
Patch
Comment 2 Tim Horton 2015-02-18 17:00:14 PST
Comment on attachment 246859 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=246859&action=review

> Source/WebCore/editing/mac/EditorMac.mm:689
> +    style->setProperty(CSSPropertyFontStyle, (fontTraits & NSFontItalicTrait) ? String("italic") : String("normal"));
> +    style->setProperty(CSSPropertyFontWeight, (fontTraits & NSFontBoldTrait) ? String("bold") : String("normal"));

I feel like there's a better way to make these Strings from literals.

> Source/WebKit2/ChangeLog:52
> +2015-02-18  Enrica Casucci  <enrica@apple.com>

Duplicate changelog!
Comment 3 Build Bot 2015-02-18 17:33:54 PST
Comment on attachment 246859 [details]
Patch

Attachment 246859 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6609615424847872

Number of test failures exceeded the failure limit.
Comment 4 Build Bot 2015-02-18 17:33:58 PST
Created attachment 246863 [details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 5 Tim Horton 2015-02-18 17:53:17 PST
Something bad happening here:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000040

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.apple.WebKit              	0x000000010eb3939a WebKit::WebPage::platformEditorState(WebCore::Frame&, WebKit::EditorState&) const + 42 (FontPlatformData.h:127)
1   com.apple.WebKit              	0x000000010eb29075 WebKit::WebPage::editorState() const + 219 (WebPage.cpp:768)
2   com.apple.WebKit              	0x000000010eb2fe6d WebKit::WebPage::didChangeSelection() + 29 (tuple:263)
3   com.apple.WebCore             	0x000000011014638d WebCore::Editor::respondToChangedSelection(WebCore::VisibleSelection const&, unsigned int) + 45 (Editor.h:523)
4   com.apple.WebCore             	0x00000001101f2c76 WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance(WebCore::VisibleSelection const&, unsigned int, WebCore::FrameSelection::CursorAlignOnScroll, WebCore::TextGranularity) + 1014 (FrameSelection.cpp:318)
5   com.apple.WebCore             	0x00000001101f17c8 WebCore::FrameSelection::setSelection(WebCore::VisibleSelection const&, unsigned int, WebCore::FrameSelection::CursorAlignOnScroll, WebCore::TextGranularity) + 24 (FrameSelection.cpp:325)
6   com.apple.WebCore             	0x00000001101f4a6e WebCore::FrameSelection::textWasReplaced(WebCore::CharacterData*, unsigned int, unsigned int, unsigned int) + 1390 (VisibleSelection.h:39)
7   com.apple.WebCore             	0x000000010ff74f88 WebCore::CharacterData::setDataAndUpdate(WTF::String const&, unsigned int, unsigned int, unsigned int) + 168 (Node.h:410)
8   com.apple.WebCore             	0x000000010ff7540e WebCore::CharacterData::deleteData(unsigned int, unsigned int, int&) + 142 (Node.h:410)
9   com.apple.WebCore             	0x000000011008354a WebCore::DeleteFromTextNodeCommand::doApply() + 218 (DeleteFromTextNodeCommand.cpp:64)
10  com.apple.WebCore             	0x000000010ff8b13b
Comment 6 Enrica Casucci 2015-02-19 13:24:38 PST
Created attachment 246912 [details]
Patch2

Fixes build failures and crashing tests.
Comment 7 Enrica Casucci 2015-02-19 14:14:52 PST
(In reply to comment #2)
> Comment on attachment 246859 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=246859&action=review
> 
> > Source/WebCore/editing/mac/EditorMac.mm:689
> > +    style->setProperty(CSSPropertyFontStyle, (fontTraits & NSFontItalicTrait) ? String("italic") : String("normal"));
> > +    style->setProperty(CSSPropertyFontWeight, (fontTraits & NSFontBoldTrait) ? String("bold") : String("normal"));
> 
> I feel like there's a better way to make these Strings from literals.
> 
> > Source/WebKit2/ChangeLog:52
> > +2015-02-18  Enrica Casucci  <enrica@apple.com>
> 
> Duplicate changelog!

Actually, I spoke with Chris Dumez and he showed me a better way to do this. I'll post a new patch shortly.
Comment 8 Enrica Casucci 2015-02-19 14:17:11 PST
Created attachment 246921 [details]
Patch3

Including suggestions from Chris Dumez on how to set the CSSS properties in EditorMac.
Comment 9 WebKit Commit Bot 2015-02-19 14:18:35 PST
Attachment 246921 [details] did not pass style-queue:


ERROR: Source/WebCore/editing/mac/EditorMac.mm:32:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 1 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 Chris Dumez 2015-02-19 14:21:12 PST
Comment on attachment 246921 [details]
Patch3

View in context: https://bugs.webkit.org/attachment.cgi?id=246921&action=review

> Source/WebCore/editing/mac/EditorMac.mm:688
> +    style->setProperty(CSSPropertyFontFamily, fontFamily);

nit: Could be cssValuePool().createFontFamilyValue(fontFamily) to avoid calling the CSSParser.

> Source/WebCore/editing/mac/EditorMac.mm:691
> +    style->setProperty(CSSPropertyFontSize, CSSPrimitiveValue::create(fontSize, CSSPrimitiveValue::CSS_PX));

nit: Could leverage the CSSValuePool too: cssValuePool().createValue(fontSize, CSSPrimitiveValue::CSS_PX)
Comment 11 Chris Dumez 2015-02-19 14:22:46 PST
Comment on attachment 246921 [details]
Patch3

View in context: https://bugs.webkit.org/attachment.cgi?id=246921&action=review

> Source/WebCore/editing/mac/EditorMac.mm:687
> +    RefPtr<MutableStyleProperties> style = MutableStyleProperties::create();

nit: This is actually a Ref<MutableStyleProperties> nowadays.

> Source/WebCore/editing/mac/EditorMac.mm:692
> +    applyStyleToSelection(style.get(), EditActionSetFont);

style.ptr() if you use a Ref<>.
Comment 12 Chris Dumez 2015-02-19 14:38:55 PST
Comment on attachment 246921 [details]
Patch3

View in context: https://bugs.webkit.org/attachment.cgi?id=246921&action=review

> Source/WebCore/editing/mac/EditorMac.mm:689
> +    style->setProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue((fontTraits & NSFontItalicTrait) ? CSSValueItalic : CSSValueNormal));

nit: style->setProperty(fontTraits & NSFontItalicTrait ? CSSValueItalic : CSSValueNormal); would be equivalent.
Comment 13 Enrica Casucci 2015-02-20 12:04:32 PST
Created attachment 246983 [details]
Patch4

Addresses some more comments.
Comment 14 Enrica Casucci 2015-02-20 12:18:15 PST
Comment on attachment 246983 [details]
Patch4

Removing review. I think I've figured out why it doesn't build Release.
Comment 15 Enrica Casucci 2015-02-20 14:00:37 PST
Created attachment 246999 [details]
Patch5

Hopefully.
Comment 16 Tim Horton 2015-02-20 14:34:51 PST
Comment on attachment 246999 [details]
Patch5

View in context: https://bugs.webkit.org/attachment.cgi?id=246999&action=review

> Source/WebKit2/Shared/EditorState.cpp:45
> +#if PLATFORM(MAC)

Sam was saying something this morning about this patch wrt. "consistent encoding of font descriptions" but I don't know what he meant. You should ask him.

> Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm:129
> +        result.fontName = [nsFont fontName];

dots?
Comment 17 Enrica Casucci 2015-02-20 16:10:41 PST
Committed revision 180465.
Comment 18 Jessie Berlin 2015-02-20 19:00:31 PST
Attempted build fix in http://trac.webkit.org/changeset/180473
Comment 19 Alexey Proskuryakov 2015-02-25 21:23:13 PST
It is super unfortunate that we extend EditorState. It just has no way of being accurate enough of the time.