Skip to content
Permalink
Browse files
Simplify the HTMLConverter interface (Part 2)
https://bugs.webkit.org/show_bug.cgi?id=130654

Reviewed by Darin Adler.

../WebCore:

Switch HTMLConverter from using an Objective-C interface to C functions.

* WebCore.exp.in:
* editing/ios/EditorIOS.mm:
(WebCore::Editor::writeSelectionToPasteboard):
* editing/mac/EditorMac.mm:
(WebCore::Editor::dataSelectionForPasteboard):
(WebCore::Editor::writeSelectionToPasteboard):
* platform/ios/PasteboardIOS.mm:
* platform/mac/HTMLConverter.h:
* platform/mac/HTMLConverter.mm:
(WebCore::attributedStringFromRange):
(WebCore::editingAttributedStringFromRange):
* platform/mac/PasteboardMac.mm:

../WebKit/mac:

* WebView/WebHTMLRepresentation.mm:
(-[WebHTMLRepresentation attributedStringFrom:startOffset:to:endOffset:]):
* WebView/WebHTMLView.mm:
(-[WebHTMLView attributedSubstringFromRange:]):
(-[WebHTMLView attributedString]):
(-[WebHTMLView selectedAttributedString]):

../WebKit2:

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::performDictionaryLookupForRange):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::getAttributedSubstringFromRange):
(WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
(WebKit::WebPage::performDictionaryLookupAtLocation):
(WebKit::WebPage::performDictionaryLookupForSelection):
(WebKit::WebPage::performDictionaryLookupForRange):


Canonical link: https://commits.webkit.org/148681@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166145 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
weinig committed Mar 23, 2014
1 parent 69d8481 commit a8b8a9f620b9386330c38579a16b8b7c32080139
Showing 15 changed files with 160 additions and 95 deletions.
@@ -1,3 +1,25 @@
2014-03-23 Sam Weinig <sam@webkit.org>

Simplify the HTMLConverter interface (Part 2)
https://bugs.webkit.org/show_bug.cgi?id=130654

Reviewed by Darin Adler.

Switch HTMLConverter from using an Objective-C interface to C functions.

* WebCore.exp.in:
* editing/ios/EditorIOS.mm:
(WebCore::Editor::writeSelectionToPasteboard):
* editing/mac/EditorMac.mm:
(WebCore::Editor::dataSelectionForPasteboard):
(WebCore::Editor::writeSelectionToPasteboard):
* platform/ios/PasteboardIOS.mm:
* platform/mac/HTMLConverter.h:
* platform/mac/HTMLConverter.mm:
(WebCore::attributedStringFromRange):
(WebCore::editingAttributedStringFromRange):
* platform/mac/PasteboardMac.mm:

2014-03-23 Darin Adler <darin@apple.com>

Remove code in HTMLObjectElement attribute parsing that forces style resolution and layout
@@ -2109,7 +2109,6 @@ __ZN7WebCore36initializeLoggingChannelsIfNecessaryEv
.objc_class_name_WebCoreFullScreenWarningView
.objc_class_name_WebCoreFullScreenWindow
.objc_class_name_WebFontCache
.objc_class_name_WebHTMLConverter
.objc_class_name_WebWindowFadeAnimation
.objc_class_name_WebWindowScaleAnimation
__ZN7WebCore10FloatPointC1ERK8_NSPoint
@@ -2195,6 +2194,7 @@ __ZN7WebCore31contextMenuItemTagStartSpeakingEv
__ZN7WebCore32applicationIsAOLInstantMessengerEv
__ZN7WebCore32contextMenuItemTagInspectElementEv
__ZN7WebCore32contextMenuItemTagSmartCopyPasteEv
__ZN7WebCore32editingAttributedStringFromRangeERNS_5RangeE
__ZN7WebCore32useBlockedPlugInContextMenuTitleEv
__ZN7WebCore33contextMenuItemTagTextReplacementEv
__ZN7WebCore33postScriptDocumentTypeDescriptionEv
@@ -297,12 +297,6 @@ - (BOOL)containsAttachments;
applyStyleToSelection(defaultStyle.get(), EditActionChangeAttributes);
}

// FIXME: the following fuctions should be shared between Mac and iOS.
static NSAttributedString *attributedStringForRange(Range& range)
{
return [WebHTMLConverter attributedStringFromRange:&range];
}

static PassRefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *string)
{
NSUInteger length = [string length];
@@ -330,7 +324,7 @@ - (BOOL)containsAttachments;

void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
{
NSAttributedString *attributedString = attributedStringForRange(*selectedRange());
NSAttributedString *attributedString = attributedStringFromRange(selectedRange());

PasteboardWebContent content;
content.canSmartCopyOrDelete = canSmartCopyOrDelete();
@@ -303,12 +303,7 @@
range->setStart(enclosingAnchor, 0, IGNORE_EXCEPTION);
return range;
}

static NSAttributedString *attributedStringForRange(Range& range)
{
return [WebHTMLConverter attributedStringFromRange:&range];
}


static PassRefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *string)
{
NSUInteger length = [string length];
@@ -335,10 +330,10 @@
return selectionInWebArchiveFormat();

if (pasteboardType == String(NSRTFDPboardType))
return dataInRTFDFormat(attributedStringForRange(*adjustedSelectionRange()));
return dataInRTFDFormat(attributedStringFromRange(*adjustedSelectionRange()));

if (pasteboardType == String(NSRTFPboardType)) {
NSAttributedString* attributedString = attributedStringForRange(*adjustedSelectionRange());
NSAttributedString* attributedString = attributedStringFromRange(*adjustedSelectionRange());
// FIXME: Why is this attachment character stripping needed here, but not needed in writeSelectionToPasteboard?
if ([attributedString containsAttachments])
attributedString = attributedStringByStrippingAttachmentCharacters(attributedString);
@@ -350,7 +345,7 @@

void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
{
NSAttributedString *attributedString = attributedStringForRange(*selectedRange());
NSAttributedString *attributedString = attributedStringFromRange(*selectedRange());

PasteboardWebContent content;
content.canSmartCopyOrDelete = canSmartCopyOrDelete();
@@ -35,7 +35,6 @@
#import "Frame.h"
#import "FrameLoader.h"
#import "FrameLoaderClient.h"
#import "HTMLConverter.h"
#import "HTMLElement.h"
#import "HTMLNames.h"
#import "HTMLParserIdioms.h"
@@ -23,66 +23,20 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

@class DOMDocument;
@class DOMRange;
#ifndef HTMLConverter_h
#define HTMLConverter_h

namespace WebCore {
class DocumentLoader;
class Range;
}

class HTMLConverterCaches;
OBJC_CLASS NSAttributedString;

@interface WebHTMLConverter : NSObject {
NSMutableAttributedString *_attrStr;
NSMutableDictionary *_documentAttrs;
NSURL *_baseURL;
DOMDocument *_document;
DOMRange *_domRange;
NSMutableArray *_domStartAncestors;
WebCore::DocumentLoader *_dataSource;
NSString *_standardFontFamily;
CGFloat _textSizeMultiplier;
CGFloat _webViewTextSizeMultiplier;
CGFloat _defaultTabInterval;
CGFloat _defaultFontSize;
CGFloat _minimumFontSize;
NSMutableArray *_textLists;
NSMutableArray *_textBlocks;
NSMutableArray *_textTables;
NSMutableDictionary *_textTableFooters;
NSMutableArray *_textTableSpacings;
NSMutableArray *_textTablePaddings;
NSMutableArray *_textTableRows;
NSMutableArray *_textTableRowArrays;
NSMutableArray *_textTableRowBackgroundColors;
NSMutableDictionary *_colorsForNodes;
NSMutableDictionary *_attributesForElements;
NSMutableDictionary *_fontCache;
NSMutableArray *_writingDirectionArray;
NSUInteger _domRangeStartIndex;
NSInteger _indexingLimit;
NSUInteger _thumbnailLimit;
NSInteger _errorCode;
NSInteger _quoteLevel;

std::unique_ptr<HTMLConverterCaches> _caches;

struct {
unsigned int isSoft:1;
unsigned int reachedStart:1;
unsigned int reachedEnd:1;
unsigned int isIndexing:1;
unsigned int isTesting:1;
unsigned int hasTrailingNewline:1;
unsigned int pad:26;
} _flags;
}


+ (NSAttributedString *)attributedStringFromRange:(WebCore::Range*)range;
namespace WebCore {

class Range;

NSAttributedString *attributedStringFromRange(Range&);
#if !PLATFORM(IOS)
+ (NSAttributedString *)editingAttributedStringFromRange:(WebCore::Range*)range;
NSAttributedString *editingAttributedStringFromRange(Range&);
#endif
@end

}

#endif // HTMLConverter_h
@@ -428,6 +428,58 @@ @interface NSObject(WebMessageDocumentSimulation)
+ (void)document:(NSObject **)outDocument attachment:(NSTextAttachment **)outAttachment forURL:(NSURL *)url;
@end

@interface WebHTMLConverter : NSObject {
NSMutableAttributedString *_attrStr;
NSMutableDictionary *_documentAttrs;
NSURL *_baseURL;
DOMDocument *_document;
DOMRange *_domRange;
NSMutableArray *_domStartAncestors;
WebCore::DocumentLoader *_dataSource;
NSString *_standardFontFamily;
CGFloat _textSizeMultiplier;
CGFloat _webViewTextSizeMultiplier;
CGFloat _defaultTabInterval;
CGFloat _defaultFontSize;
CGFloat _minimumFontSize;
NSMutableArray *_textLists;
NSMutableArray *_textBlocks;
NSMutableArray *_textTables;
NSMutableDictionary *_textTableFooters;
NSMutableArray *_textTableSpacings;
NSMutableArray *_textTablePaddings;
NSMutableArray *_textTableRows;
NSMutableArray *_textTableRowArrays;
NSMutableArray *_textTableRowBackgroundColors;
NSMutableDictionary *_colorsForNodes;
NSMutableDictionary *_attributesForElements;
NSMutableDictionary *_fontCache;
NSMutableArray *_writingDirectionArray;
NSUInteger _domRangeStartIndex;
NSInteger _indexingLimit;
NSUInteger _thumbnailLimit;
NSInteger _errorCode;
NSInteger _quoteLevel;

std::unique_ptr<HTMLConverterCaches> _caches;

struct {
unsigned int isSoft:1;
unsigned int reachedStart:1;
unsigned int reachedEnd:1;
unsigned int isIndexing:1;
unsigned int isTesting:1;
unsigned int hasTrailingNewline:1;
unsigned int pad:26;
} _flags;
}

+ (NSAttributedString *)attributedStringFromRange:(Range*)range;
#if !PLATFORM(IOS)
+ (NSAttributedString *)editingAttributedStringFromRange:(Range*)range;
#endif
@end

@interface WebHTMLConverter(WebHTMLConverterInternal)

- (id)init;
@@ -2578,3 +2630,19 @@ + (NSAttributedString *)editingAttributedStringFromRange:(Range*)range
}

#endif

namespace WebCore {

NSAttributedString *attributedStringFromRange(Range& range)
{
return [WebHTMLConverter attributedStringFromRange:&range];
}

#if !PLATFORM(IOS)
NSAttributedString *editingAttributedStringFromRange(Range& range)
{
return [WebHTMLConverter editingAttributedStringFromRange:&range];
}
#endif

}
@@ -41,7 +41,6 @@
#import "FrameLoaderClient.h"
#import "HitTestResult.h"
#import "HTMLAnchorElement.h"
#import "HTMLConverter.h"
#import "htmlediting.h"
#import "HTMLNames.h"
#import "Image.h"
@@ -1,3 +1,17 @@
2014-03-23 Sam Weinig <sam@webkit.org>

Simplify the HTMLConverter interface (Part 2)
https://bugs.webkit.org/show_bug.cgi?id=130654

Reviewed by Darin Adler.

* WebView/WebHTMLRepresentation.mm:
(-[WebHTMLRepresentation attributedStringFrom:startOffset:to:endOffset:]):
* WebView/WebHTMLView.mm:
(-[WebHTMLView attributedSubstringFromRange:]):
(-[WebHTMLView attributedString]):
(-[WebHTMLView selectedAttributedString]):

2014-03-23 Darin Adler <darin@apple.com>

Remove code in HTMLObjectElement attribute parsing that forces style resolution and layout
@@ -277,7 +277,7 @@ - (NSAttributedString *)attributedText

- (NSAttributedString *)attributedStringFrom:(DOMNode *)startNode startOffset:(int)startOffset to:(DOMNode *)endNode endOffset:(int)endOffset
{
return [WebHTMLConverter editingAttributedStringFromRange:Range::create(core(startNode)->document(), core(startNode), startOffset, core(endNode), endOffset).get()];
return editingAttributedStringFromRange(*Range::create(core(startNode)->document(), core(startNode), startOffset, core(endNode), endOffset).get());
}
#endif

@@ -6170,9 +6170,9 @@ - (NSAttributedString *)attributedSubstringFromRange:(NSRange)nsRange
return nil;
}

NSAttributedString *result = [WebHTMLConverter editingAttributedStringFromRange:range.get()];
NSAttributedString *result = editingAttributedStringFromRange(*range);

// [WebHTMLConverter editingAttributedStringFromRange:] insists on inserting a trailing
// WebCore::editingAttributedStringFromRange() insists on inserting a trailing
// whitespace at the end of the string which breaks the ATOK input method. <rdar://problem/5400551>
// To work around this we truncate the resultant string to the correct length.
if ([result length] > nsRange.length) {
@@ -6642,7 +6642,7 @@ - (NSAttributedString *)attributedString
NSAttributedString *attributedString = [self _attributeStringFromDOMRange:[document _documentRange]];
if (!attributedString) {
Document* coreDocument = core(document);
attributedString = [WebHTMLConverter editingAttributedStringFromRange:Range::create(*coreDocument, coreDocument, 0, coreDocument, coreDocument->childNodeCount()).get()];
attributedString = editingAttributedStringFromRange(*Range::create(*coreDocument, coreDocument, 0, coreDocument, coreDocument->childNodeCount()).get());
}
return attributedString;
}
@@ -6661,7 +6661,10 @@ - (NSAttributedString *)selectedAttributedString
Frame* coreFrame = core([self _frame]);
if (coreFrame) {
RefPtr<Range> range = coreFrame->selection().selection().toNormalizedRange();
attributedString = [WebHTMLConverter editingAttributedStringFromRange:range.get()];
if (range)
attributedString = editingAttributedStringFromRange(*range);
else
attributedString = [[[NSAttributedString alloc] init] autorelease];
}
}
return attributedString;
@@ -1,3 +1,20 @@
2014-03-23 Sam Weinig <sam@webkit.org>

Simplify the HTMLConverter interface (Part 2)
https://bugs.webkit.org/show_bug.cgi?id=130654

Reviewed by Darin Adler.

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::performDictionaryLookupForRange):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::getAttributedSubstringFromRange):
(WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
(WebKit::WebPage::performDictionaryLookupAtLocation):
(WebKit::WebPage::performDictionaryLookupForSelection):
(WebKit::WebPage::performDictionaryLookupForRange):

2014-03-23 David Kilzer <ddkilzer@apple.com>

WebKit::resistanceForDelta() truncates 'scaleDistance' to integer value using abs()
@@ -882,7 +882,7 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP

#if PLATFORM(COCOA)
void performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
void performDictionaryLookupForRange(WebCore::Frame*, WebCore::Range*, NSDictionary *options);
void performDictionaryLookupForRange(WebCore::Frame*, WebCore::Range&, NSDictionary *options);

void windowAndViewFramesChanged(const WebCore::FloatRect& windowFrameInScreenCoordinates, const WebCore::FloatRect& windowFrameInUnflippedScreenCoordinates, const WebCore::FloatRect& viewFrameInWindowCoordinates, const WebCore::FloatPoint& accessibilityViewCoordinates);

@@ -171,7 +171,7 @@
notImplemented();
}

void WebPage::performDictionaryLookupForRange(Frame*, Range*, NSDictionary *)
void WebPage::performDictionaryLookupForRange(Frame*, Range&, NSDictionary *)
{
notImplemented();
}

0 comments on commit a8b8a9f

Please sign in to comment.