<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[171015] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/171015">171015</a></dd>
<dt>Author</dt> <dd>enrica@apple.com</dd>
<dt>Date</dt> <dd>2014-07-11 16:24:24 -0700 (Fri, 11 Jul 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Implement textStylingAtPosition in WK2.
https://bugs.webkit.org/show_bug.cgi?id=134843
<rdar://problem/17614981>
Source/WebCore:
Reviewed by Benjamin Poulain.
Adding some exports and making styleForSelectionStart public.
* WebCore.exp.in:
* editing/Editor.h:
Source/WebKit2:
Reviewed by Benjamin Poulain.
Adding information about typing attributes to EditorState so
that we can implement textStylingAtPosition.
* Shared/EditorState.cpp:
(WebKit::EditorState::encode):
(WebKit::EditorState::decode):
* Shared/EditorState.h:
(WebKit::EditorState::EditorState):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView textStylingAtPosition:inDirection:]):
(-[WKContentView canPerformAction:withSender:]):
(-[WKContentView toggleBoldface:]):
(-[WKContentView toggleItalics:]):
(-[WKContentView toggleUnderline:]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorh">trunk/Source/WebCore/editing/Editor.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedEditorStatecpp">trunk/Source/WebKit2/Shared/EditorState.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedEditorStateh">trunk/Source/WebKit2/Shared/EditorState.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebCore/ChangeLog        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-07-11 Enrica Casucci <enrica@apple.com>
+
+ Implement textStylingAtPosition in WK2.
+ https://bugs.webkit.org/show_bug.cgi?id=134843
+ <rdar://problem/17614981>
+
+ Reviewed by Benjamin Poulain.
+
+ Adding some exports and making styleForSelectionStart public.
+
+ * WebCore.exp.in:
+ * editing/Editor.h:
+
</ins><span class="cx"> 2014-07-11 Zalan Bujtas <zalan@apple.com>
</span><span class="cx">
</span><span class="cx"> REGRESSION (r168868): eBay 'see all' links fail due to different JS bindings conversion behavior.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -1091,6 +1091,7 @@
</span><span class="cx"> __ZN7WebCore4Node17stopIgnoringLeaksEv
</span><span class="cx"> __ZN7WebCore4Node18startIgnoringLeaksEv
</span><span class="cx"> __ZN7WebCore4Node19setNeedsStyleRecalcENS_15StyleChangeTypeE
</span><ins>+__ZN7WebCore4Node6removeERi
</ins><span class="cx"> __ZN7WebCore4Page10findStringERKN3WTF6StringEh
</span><span class="cx"> __ZN7WebCore4Page11PageClientsC1Ev
</span><span class="cx"> __ZN7WebCore4Page11PageClientsD1Ev
</span><span class="lines">@@ -1204,6 +1205,7 @@
</span><span class="cx"> __ZN7WebCore6Editor19deleteWithDirectionENS_18SelectionDirectionENS_15TextGranularityEbb
</span><span class="cx"> __ZN7WebCore6Editor19insertUnorderedListEv
</span><span class="cx"> __ZN7WebCore6Editor21applyStyleToSelectionEPNS_15StylePropertiesENS_10EditActionE
</span><ins>+__ZN7WebCore6Editor22styleForSelectionStartEPNS_5FrameERPNS_4NodeE
</ins><span class="cx"> __ZN7WebCore6Editor22writeImageToPasteboardERNS_10PasteboardERNS_7ElementERKNS_3URLERKN3WTF6StringE
</span><span class="cx"> __ZN7WebCore6Editor23setBaseWritingDirectionE16WritingDirection
</span><span class="cx"> __ZN7WebCore6Editor24computeAndSetTypingStyleEPNS_15StylePropertiesENS_10EditActionE
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.h (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.h        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebCore/editing/Editor.h        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -427,6 +427,7 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><ins>+ static RenderStyle* styleForSelectionStart(Frame* , Node *&nodeToRemove);
</ins><span class="cx"> bool insertParagraphSeparatorInQuotedContent();
</span><span class="cx"> const SimpleFontData* fontForSelection(bool&) const;
</span><span class="cx"> NSDictionary* fontAttributesForSelectionStart() const;
</span><span class="lines">@@ -489,8 +490,6 @@
</span><span class="cx"> PassRefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(PassRefPtr<ArchiveResource>);
</span><span class="cx"> PassRefPtr<DocumentFragment> createFragmentAndAddResources(NSAttributedString *);
</span><span class="cx"> void fillInUserVisibleForm(PasteboardURL&);
</span><del>-
- static RenderStyle* styleForSelectionStart(Frame* , Node *&nodeToRemove);
</del><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> Frame& m_frame;
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebKit2/ChangeLog        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2014-07-11 Enrica Casucci <enrica@apple.com>
+
+ Implement textStylingAtPosition in WK2.
+ https://bugs.webkit.org/show_bug.cgi?id=134843
+ <rdar://problem/17614981>
+
+ Reviewed by Benjamin Poulain.
+
+ Adding information about typing attributes to EditorState so
+ that we can implement textStylingAtPosition.
+
+ * Shared/EditorState.cpp:
+ (WebKit::EditorState::encode):
+ (WebKit::EditorState::decode):
+ * Shared/EditorState.h:
+ (WebKit::EditorState::EditorState):
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView textStylingAtPosition:inDirection:]):
+ (-[WKContentView canPerformAction:withSender:]):
+ (-[WKContentView toggleBoldface:]):
+ (-[WKContentView toggleItalics:]):
+ (-[WKContentView toggleUnderline:]):
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::editorState):
+
</ins><span class="cx"> 2014-07-11 Oliver Hunt <oliver@apple.com>
</span><span class="cx">
</span><span class="cx"> Tighten WebContent sandbox
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedEditorStatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/EditorState.cpp (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/EditorState.cpp        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebKit2/Shared/EditorState.cpp        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx"> encoder << firstMarkedRect;
</span><span class="cx"> encoder << lastMarkedRect;
</span><span class="cx"> encoder << markedText;
</span><ins>+ encoder << typingAttributes;
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="lines">@@ -117,6 +118,8 @@
</span><span class="cx"> return false;
</span><span class="cx"> if (!decoder.decode(result.markedText))
</span><span class="cx"> return false;
</span><ins>+ if (!decoder.decode(result.typingAttributes))
+ return false;
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(GTK)
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedEditorStateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/EditorState.h (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/EditorState.h        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebKit2/Shared/EditorState.h        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -36,6 +36,13 @@
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><ins>+enum TypingAttributes {
+ AttributeNone = 0,
+ AttributeBold = 1,
+ AttributeItalics = 2,
+ AttributeUnderline = 4
+};
+
</ins><span class="cx"> struct EditorState {
</span><span class="cx"> EditorState()
</span><span class="cx"> : shouldIgnoreCompositionSelectionChange(false)
</span><span class="lines">@@ -52,6 +59,7 @@
</span><span class="cx"> , characterBeforeSelection(0)
</span><span class="cx"> , twoCharacterBeforeSelection(0)
</span><span class="cx"> , selectedTextLength(0)
</span><ins>+ , typingAttributes(AttributeNone)
</ins><span class="cx"> #endif
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -79,6 +87,7 @@
</span><span class="cx"> WebCore::IntRect firstMarkedRect;
</span><span class="cx"> WebCore::IntRect lastMarkedRect;
</span><span class="cx"> String markedText;
</span><ins>+ uint32_t typingAttributes;
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(GTK)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> #import "WebProcessProxy.h"
</span><span class="cx"> #import "_WKFormDelegate.h"
</span><span class="cx"> #import "_WKFormInputSession.h"
</span><ins>+#import <CoreText/CTFontDescriptor.h>
</ins><span class="cx"> #import <DataDetectorsUI/DDDetectionController.h>
</span><span class="cx"> #import <TextInput/TI_NSStringExtras.h>
</span><span class="cx"> #import <UIKit/UIApplication_Private.h>
</span><span class="lines">@@ -1190,6 +1191,36 @@
</span><span class="cx"> [[UIKeyboardImpl sharedInstance] replaceText:sender];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (NSDictionary *)textStylingAtPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction
+{
+ if (!position || !_page->editorState().isContentRichlyEditable)
+ return nil;
+
+ NSMutableDictionary* result = [NSMutableDictionary dictionary];
+
+ CTFontSymbolicTraits symbolicTraits = 0;
+ if (_page->editorState().typingAttributes & AttributeBold)
+ symbolicTraits |= kCTFontBoldTrait;
+ if (_page->editorState().typingAttributes & AttributeItalics)
+ symbolicTraits |= kCTFontTraitItalic;
+
+ // We chose a random font family and size.
+ // What matters are the traits but the caller expects a font object
+ // in the dictionary for NSFontAttributeName.
+ RetainPtr<CTFontDescriptorRef> fontDescriptor = adoptCF(CTFontDescriptorCreateWithNameAndSize(CFSTR("Helvetica"), 10));
+ if (symbolicTraits)
+ fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithSymbolicTraits(fontDescriptor.get(), symbolicTraits, symbolicTraits));
+
+ RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 10, nullptr));
+ if (font)
+ [result setObject:(id)font.get() forKey:NSFontAttributeName];
+
+ if (_page->editorState().typingAttributes & AttributeUnderline)
+ [result setObject:[NSNumber numberWithInt:NSUnderlineStyleSingle] forKey:NSUnderlineStyleAttributeName];
+
+ return result;
+}
+
</ins><span class="cx"> - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
</span><span class="cx"> {
</span><span class="cx"> BOOL hasWebSelection = _webSelectionAssistant && !CGRectIsEmpty(_webSelectionAssistant.get().selectionFrame);
</span><span class="lines">@@ -1198,6 +1229,8 @@
</span><span class="cx"> return _page->editorState().isContentRichlyEditable && _page->editorState().selectionIsRange && !_showingTextStyleOptions;
</span><span class="cx"> if (_showingTextStyleOptions)
</span><span class="cx"> return (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:));
</span><ins>+ if (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:))
+ return _page->editorState().isContentRichlyEditable;
</ins><span class="cx"> if (action == @selector(cut:))
</span><span class="cx"> return !_page->editorState().isInPasswordField && _page->editorState().isContentEditable && _page->editorState().selectionIsRange;
</span><span class="cx">
</span><span class="lines">@@ -1336,7 +1369,7 @@
</span><span class="cx"> if (!_page->editorState().isContentRichlyEditable)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- _page->executeEditCommand(ASCIILiteral("toggleBold"));
</del><ins>+ [self executeEditCommandWithCallback:@"toggleBold"];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)toggleItalics:(id)sender
</span><span class="lines">@@ -1344,7 +1377,7 @@
</span><span class="cx"> if (!_page->editorState().isContentRichlyEditable)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- _page->executeEditCommand(ASCIILiteral("toggleItalic"));
</del><ins>+ [self executeEditCommandWithCallback:@"toggleItalic"];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)toggleUnderline:(id)sender
</span><span class="lines">@@ -1352,7 +1385,7 @@
</span><span class="cx"> if (!_page->editorState().isContentRichlyEditable)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- _page->executeEditCommand(ASCIILiteral("toggleUnderline"));
</del><ins>+ [self executeEditCommandWithCallback:@"toggleUnderline"];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)_showTextStyleOptions:(id)sender
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (171014 => 171015)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-07-11 22:36:14 UTC (rev 171014)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-07-11 23:24:24 UTC (rev 171015)
</span><span class="lines">@@ -192,6 +192,8 @@
</span><span class="cx"> #include "RemoteLayerTreeDrawingArea.h"
</span><span class="cx"> #include "WebVideoFullscreenManager.h"
</span><span class="cx"> #include <CoreGraphics/CoreGraphics.h>
</span><ins>+#include <CoreText/CTFontDescriptorPriv.h>
+#include <CoreText/CTFontPriv.h>
</ins><span class="cx"> #include <WebCore/Icon.h>
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="lines">@@ -744,6 +746,24 @@
</span><span class="cx"> if (selectedText.length() <= maxSelectedTextLength)
</span><span class="cx"> result.wordAtSelection = selectedText;
</span><span class="cx"> }
</span><ins>+ if (!selection.isNone()) {
+ Node* nodeToRemove;
+ if (RenderStyle* style = Editor::styleForSelectionStart(&frame, nodeToRemove)) {
+ CTFontRef font = style->font().primaryFont()->getCTFont();
+ CTFontSymbolicTraits traits = font ? CTFontGetSymbolicTraits(font) : 0;
+
+ if (traits & kCTFontTraitBold)
+ result.typingAttributes |= AttributeBold;
+ if (traits & kCTFontTraitItalic)
+ result.typingAttributes |= AttributeItalics;
+
+ if (style->textDecorationsInEffect() & TextDecorationUnderline)
+ result.typingAttributes |= AttributeUnderline;
+
+ if (nodeToRemove)
+ nodeToRemove->remove(ASSERT_NO_EXCEPTION);
+ }
+ }
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(GTK)
</span></span></pre>
</div>
</div>
</body>
</html>