Title: [136075] trunk/Source/WebKit2
Revision
136075
Author
timothy_hor...@apple.com
Date
2012-11-28 16:20:17 -0800 (Wed, 28 Nov 2012)

Log Message

[mac] Dictionary lookup bubble loses intrarange formatting
https://bugs.webkit.org/show_bug.cgi?id=103496
<rdar://problem/12762172>

Reviewed by Alexey Proskuryakov.

Pass an NSAttributedString (made via WebHTMLConverter on the WebProcess side) through
when showing dictionary popups, so that we preserve more formatting in the yellow dictionary
highlight. Also, remove the fontInfo member from DictionaryPopupInfo, since we don't need it anymore.

* Shared/DictionaryPopupInfo.cpp:
(WebKit::DictionaryPopupInfo::encode): Don't encode the now-removed fontInfo member.
(WebKit::DictionaryPopupInfo::decode): Don't decode the now-removed fontInfo member.
* Shared/DictionaryPopupInfo.h: Remove the fontInfo member.
* UIProcess/API/mac/PageClientImpl.h:
(PageClientImpl): didPerformDictionaryLookup should take an AttributedString instead of a plain String, and
no longer needs to take the page scale factor.
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::didPerformDictionaryLookup): Use the AttributedString we're handed from the WebProcess
instead of constructing one ourselves; this way, we have all the attributes instead of just a single font.
* UIProcess/PageClient.h:
(PageClient): didPerformDictionaryLookup should take an AttributedString instead of a plain String.
* UIProcess/WebPageProxy.h:
(WebPageProxy): didPerformDictionaryLookup should take an AttributedString instead of a plain String.
* UIProcess/WebPageProxy.messages.in: DidPerformDictionaryLookup should take an AttributedString instead of a plain String.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::didPerformDictionaryLookup): didPerformDictionaryLookup should take an AttributedString instead of a plain String.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupForRange): performDictionaryLookupForRange should hand WebPageProxy an AttributedString
constructed via WebHTMLConverter instead of a plain text string paired with a single font descriptor.
Also, scale the size of every font attribute by the current pageScaleFactor.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (136074 => 136075)


--- trunk/Source/WebKit2/ChangeLog	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/ChangeLog	2012-11-29 00:20:17 UTC (rev 136075)
@@ -1,3 +1,37 @@
+2012-11-28  Tim Horton  <timothy_hor...@apple.com>
+
+        [mac] Dictionary lookup bubble loses intrarange formatting
+        https://bugs.webkit.org/show_bug.cgi?id=103496
+        <rdar://problem/12762172>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Pass an NSAttributedString (made via WebHTMLConverter on the WebProcess side) through
+        when showing dictionary popups, so that we preserve more formatting in the yellow dictionary
+        highlight. Also, remove the fontInfo member from DictionaryPopupInfo, since we don't need it anymore.
+
+        * Shared/DictionaryPopupInfo.cpp:
+        (WebKit::DictionaryPopupInfo::encode): Don't encode the now-removed fontInfo member.
+        (WebKit::DictionaryPopupInfo::decode): Don't decode the now-removed fontInfo member.
+        * Shared/DictionaryPopupInfo.h: Remove the fontInfo member.
+        * UIProcess/API/mac/PageClientImpl.h:
+        (PageClientImpl): didPerformDictionaryLookup should take an AttributedString instead of a plain String, and
+        no longer needs to take the page scale factor.
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::didPerformDictionaryLookup): Use the AttributedString we're handed from the WebProcess
+        instead of constructing one ourselves; this way, we have all the attributes instead of just a single font.
+        * UIProcess/PageClient.h:
+        (PageClient): didPerformDictionaryLookup should take an AttributedString instead of a plain String.
+        * UIProcess/WebPageProxy.h:
+        (WebPageProxy): didPerformDictionaryLookup should take an AttributedString instead of a plain String.
+        * UIProcess/WebPageProxy.messages.in: DidPerformDictionaryLookup should take an AttributedString instead of a plain String.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::didPerformDictionaryLookup): didPerformDictionaryLookup should take an AttributedString instead of a plain String.
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDictionaryLookupForRange): performDictionaryLookupForRange should hand WebPageProxy an AttributedString
+        constructed via WebHTMLConverter instead of a plain text string paired with a single font descriptor.
+        Also, scale the size of every font attribute by the current pageScaleFactor.
+
 2012-11-28  pe...@outlook.com  <pe...@outlook.com>
 
         [WinCairo] Crash when requesting favicon.

Modified: trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp (136074 => 136075)


--- trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp	2012-11-29 00:20:17 UTC (rev 136075)
@@ -37,7 +37,6 @@
 void DictionaryPopupInfo::encode(CoreIPC::ArgumentEncoder& encoder) const
 {
     encoder << origin;
-    encoder << fontInfo;
     encoder.encodeEnum(type);
 
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
@@ -52,8 +51,6 @@
 {
     if (!decoder->decode(result.origin))
         return false;
-    if (!decoder->decode(result.fontInfo))
-        return false;
     if (!decoder->decodeEnum(result.type))
         return false;
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070

Modified: trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h (136074 => 136075)


--- trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h	2012-11-29 00:20:17 UTC (rev 136075)
@@ -26,7 +26,6 @@
 #ifndef DictionaryPopupInfo_h
 #define DictionaryPopupInfo_h
 
-#include "FontInfo.h"
 #include <WebCore/FloatPoint.h>
 
 #if PLATFORM(MAC)
@@ -50,7 +49,6 @@
     };
 
     WebCore::FloatPoint origin;
-    FontInfo fontInfo;
     Type type;
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     RetainPtr<CFDictionaryRef> options;

Modified: trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h (136074 => 136075)


--- trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h	2012-11-29 00:20:17 UTC (rev 136075)
@@ -128,7 +128,7 @@
 
     virtual void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects);
 
-    virtual void didPerformDictionaryLookup(const String&, double scaleFactor, const DictionaryPopupInfo&);
+    virtual void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&);
     virtual void dismissDictionaryLookupPanel();
 
     virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);

Modified: trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm (136074 => 136075)


--- trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm	2012-11-29 00:20:17 UTC (rev 136075)
@@ -29,6 +29,7 @@
 #if USE(DICTATION_ALTERNATIVES)
 #import <AppKit/NSTextAlternatives.h>
 #endif
+#import "AttributedString.h"
 #import "ColorSpaceData.h"
 #import "DataReference.h"
 #import "DictionaryPopupInfo.h"
@@ -471,14 +472,9 @@
     notImplemented();
 }
 
-void PageClientImpl::didPerformDictionaryLookup(const String& text, double scaleFactor, const DictionaryPopupInfo& dictionaryPopupInfo)
+void PageClientImpl::didPerformDictionaryLookup(const AttributedString& text, const DictionaryPopupInfo& dictionaryPopupInfo)
 {
-    NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:(NSDictionary *)dictionaryPopupInfo.fontInfo.fontAttributeDictionary.get()];
-    NSFont *font = [NSFont fontWithDescriptor:fontDescriptor size:((scaleFactor != 1) ? [fontDescriptor pointSize] * scaleFactor : 0)];
-
-    RetainPtr<NSMutableAttributedString> attributedString(AdoptNS, [[NSMutableAttributedString alloc] initWithString:nsStringFromWebCoreString(text)]);
-    [attributedString.get() addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [attributedString.get() length])];
-
+    RetainPtr<NSAttributedString> attributedString = text.string;
     NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (136074 => 136075)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2012-11-29 00:20:17 UTC (rev 136075)
@@ -211,7 +211,7 @@
     virtual void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus) = 0;
     virtual void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState) = 0;
     virtual CGContextRef containingWindowGraphicsContext() = 0;
-    virtual void didPerformDictionaryLookup(const String&, double scaleFactor, const DictionaryPopupInfo&) = 0;
+    virtual void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&) = 0;
     virtual void dismissDictionaryLookupPanel() = 0;
     virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) = 0;
     virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText) = 0;

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (136074 => 136075)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2012-11-29 00:20:17 UTC (rev 136075)
@@ -949,7 +949,7 @@
     void searchWithSpotlight(const String&);
 
     // Dictionary.
-    void didPerformDictionaryLookup(const String&, const DictionaryPopupInfo&);
+    void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&);
 #endif
 
     // Spelling and grammar.

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (136074 => 136075)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2012-11-29 00:20:17 UTC (rev 136075)
@@ -271,7 +271,7 @@
 
 #if PLATFORM(MAC)
     # Dictionary support.
-    DidPerformDictionaryLookup(WTF::String text, WebKit::DictionaryPopupInfo dictionaryPopupInfo)
+    DidPerformDictionaryLookup(WebKit::AttributedString text, WebKit::DictionaryPopupInfo dictionaryPopupInfo)
 
     # Keyboard input support messages
     InterpretQueuedKeyEvent(WebKit::EditorState state) -> (bool handled, Vector<WebCore::KeypressCommand> savedCommands)

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (136074 => 136075)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2012-11-29 00:20:17 UTC (rev 136075)
@@ -400,9 +400,9 @@
     process()->send(Messages::WebPage::SetSmartInsertDeleteEnabled(isSmartInsertDeleteEnabled), m_pageID);
 }
 
-void WebPageProxy::didPerformDictionaryLookup(const String& text, const DictionaryPopupInfo& dictionaryPopupInfo)
+void WebPageProxy::didPerformDictionaryLookup(const AttributedString& text, const DictionaryPopupInfo& dictionaryPopupInfo)
 {
-    m_pageClient->didPerformDictionaryLookup(text, m_pageScaleFactor, dictionaryPopupInfo);
+    m_pageClient->didPerformDictionaryLookup(text, dictionaryPopupInfo);
 }
     
 void WebPageProxy::registerWebProcessAccessibilityToken(const CoreIPC::DataReference& data)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (136074 => 136075)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2012-11-29 00:14:52 UTC (rev 136074)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2012-11-29 00:20:17 UTC (rev 136075)
@@ -545,39 +545,48 @@
 
 void WebPage::performDictionaryLookupForRange(DictionaryPopupInfo::Type type, Frame* frame, Range* range, NSDictionary *options)
 {
-    String rangeText = range->text();
-    if (rangeText.stripWhiteSpace().isEmpty())
+    if (range->text().stripWhiteSpace().isEmpty())
         return;
     
     RenderObject* renderer = range->startContainer()->renderer();
     RenderStyle* style = renderer->style();
-    NSFont *font = style->font().primaryFont()->getNSFont();
-    
-    // We won't be able to get an NSFont in the case that a Web Font is being used, so use
-    // the default system font at the same size instead.
-    if (!font)
-        font = [NSFont systemFontOfSize:style->font().primaryFont()->platformData().size()];
 
-    CFDictionaryRef fontDescriptorAttributes = (CFDictionaryRef)[[font fontDescriptor] fontAttributes];
-    if (!fontDescriptorAttributes)
-        return;
-
     Vector<FloatQuad> quads;
     range->textQuads(quads);
     if (quads.isEmpty())
         return;
-    
+
     IntRect rangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
     
     DictionaryPopupInfo dictionaryPopupInfo;
     dictionaryPopupInfo.type = type;
     dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + (style->fontMetrics().ascent() * pageScaleFactor()));
-    dictionaryPopupInfo.fontInfo.fontAttributeDictionary = fontDescriptorAttributes;
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     dictionaryPopupInfo.options = (CFDictionaryRef)options;
 #endif
 
-    send(Messages::WebPageProxy::DidPerformDictionaryLookup(rangeText, dictionaryPopupInfo));
+    NSAttributedString *nsAttributedString = [WebHTMLConverter editingAttributedStringFromRange:range];
+
+    RetainPtr<NSMutableAttributedString> scaledNSAttributedString(AdoptNS, [[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
+
+    NSFontManager *fontManager = [NSFontManager sharedFontManager];
+
+    [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
+        RetainPtr<NSMutableDictionary> scaledAttributes(AdoptNS, [attributes mutableCopy]);
+
+        NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
+        if (font) {
+            font = [fontManager convertFont:font toSize:[font pointSize] * pageScaleFactor()];
+            [scaledAttributes setObject:font forKey:NSFontAttributeName];
+        }
+
+        [scaledNSAttributedString.get() addAttributes:scaledAttributes.get() range:range];
+    }];
+
+    AttributedString attributedString;
+    attributedString.string = scaledNSAttributedString;
+
+    send(Messages::WebPageProxy::DidPerformDictionaryLookup(attributedString, dictionaryPopupInfo));
 }
 
 bool WebPage::performNonEditingBehaviorForSelector(const String& selector)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to