Commit 2194a86a authored by enrica@apple.com's avatar enrica@apple.com
Browse files

Upstream changes to WebHTMLConverter to support HTML

to NSAttributedString conversion on both iOS and OS X.

Reviewed by Benjamin Poulain.

* platform/mac/HTMLConverter.h:
* platform/mac/HTMLConverter.mm:
(WebDefaultFont):
(_fontForNameAndSize):
(+[WebHTMLConverter defaultParagraphStyle]):
(-[WebHTMLConverter _computedStyleForElement:]):
(-[WebHTMLConverter _specifiedStyleForElement:]):
(-[WebHTMLConverter _computedStringForNode:property:]):
(-[WebHTMLConverter _stringForNode:property:]):
(-[WebHTMLConverter _getComputedFloat:forNode:property:]):
(-[WebHTMLConverter _getFloat:forNode:property:]):
(_NSFirstPathForDirectoriesInDomains):
(_NSSystemLibraryPath):
(-[WebHTMLConverter _webKitBundle]):
(_colorForRGBColor):
(_shadowForShadowStyle):
(-[WebHTMLConverter _elementIsBlockLevel:]):
(-[WebHTMLConverter _elementHasOwnBackgroundColor:]):
(-[WebHTMLConverter _computedColorForNode:property:]):
(-[WebHTMLConverter _colorForNode:property:]):
(-[WebHTMLConverter _computedAttributesForElement:]):
(-[WebHTMLConverter _attributesForElement:]):
(-[WebHTMLConverter _newParagraphForElement:tag:allowEmpty:suppressTrailingSpace:]):
(-[WebHTMLConverter _newLineForElement:]):
(-[WebHTMLConverter _newTabForElement:]):
(-[WebHTMLConverter _WebMessageDocumentClass]):
(-[WebHTMLConverter _addAttachmentForElement:URL:needsParagraph:usePlaceholder:]):
(-[WebHTMLConverter _addQuoteForElement:opening:level:]):
(-[WebHTMLConverter _addValue:forElement:]):
(-[WebHTMLConverter _fillInBlock:forElement:backgroundColor:extraMargin:extraPadding:isTable:]):
(_dateForString):
(_colCompare):
(-[WebHTMLConverter _processMetaElementWithName:content:]):
(-[WebHTMLConverter _processHeadElement:]):
(-[WebHTMLConverter _enterElement:tag:display:embedded:]):
(-[WebHTMLConverter _addTableForElement:]):
(-[WebHTMLConverter _addTableCellForElement:]):
(-[WebHTMLConverter _processElement:tag:display:depth:]):
(-[WebHTMLConverter _addMarkersToList:range:]):
(-[WebHTMLConverter _exitElement:tag:display:depth:startIndex:]):
(-[WebHTMLConverter _processText:]):
(-[WebHTMLConverter _traverseNode:depth:embedded:]):
(-[WebHTMLConverter _traverseFooterNode:depth:]):
(-[WebHTMLConverter _loadFromDOMRange]):
(-[WebHTMLConverter dealloc]):
(-[WebHTMLConverter init]):
(-[WebHTMLConverter initWithDOMRange:]):
(-[WebHTMLConverter attributedString]):
(+[WebHTMLConverter editingAttributedStringFromRange:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156001 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8b741e10
2013-09-17 Enrica Casucci <enrica@apple.com>
Upstream changes to WebHTMLConverter to support HTML
to NSAttributedString conversion on both iOS and OS X.
Reviewed by Benjamin Poulain.
* platform/mac/HTMLConverter.h:
* platform/mac/HTMLConverter.mm:
(WebDefaultFont):
(_fontForNameAndSize):
(+[WebHTMLConverter defaultParagraphStyle]):
(-[WebHTMLConverter _computedStyleForElement:]):
(-[WebHTMLConverter _specifiedStyleForElement:]):
(-[WebHTMLConverter _computedStringForNode:property:]):
(-[WebHTMLConverter _stringForNode:property:]):
(-[WebHTMLConverter _getComputedFloat:forNode:property:]):
(-[WebHTMLConverter _getFloat:forNode:property:]):
(_NSFirstPathForDirectoriesInDomains):
(_NSSystemLibraryPath):
(-[WebHTMLConverter _webKitBundle]):
(_colorForRGBColor):
(_shadowForShadowStyle):
(-[WebHTMLConverter _elementIsBlockLevel:]):
(-[WebHTMLConverter _elementHasOwnBackgroundColor:]):
(-[WebHTMLConverter _computedColorForNode:property:]):
(-[WebHTMLConverter _colorForNode:property:]):
(-[WebHTMLConverter _computedAttributesForElement:]):
(-[WebHTMLConverter _attributesForElement:]):
(-[WebHTMLConverter _newParagraphForElement:tag:allowEmpty:suppressTrailingSpace:]):
(-[WebHTMLConverter _newLineForElement:]):
(-[WebHTMLConverter _newTabForElement:]):
(-[WebHTMLConverter _WebMessageDocumentClass]):
(-[WebHTMLConverter _addAttachmentForElement:URL:needsParagraph:usePlaceholder:]):
(-[WebHTMLConverter _addQuoteForElement:opening:level:]):
(-[WebHTMLConverter _addValue:forElement:]):
(-[WebHTMLConverter _fillInBlock:forElement:backgroundColor:extraMargin:extraPadding:isTable:]):
(_dateForString):
(_colCompare):
(-[WebHTMLConverter _processMetaElementWithName:content:]):
(-[WebHTMLConverter _processHeadElement:]):
(-[WebHTMLConverter _enterElement:tag:display:embedded:]):
(-[WebHTMLConverter _addTableForElement:]):
(-[WebHTMLConverter _addTableCellForElement:]):
(-[WebHTMLConverter _processElement:tag:display:depth:]):
(-[WebHTMLConverter _addMarkersToList:range:]):
(-[WebHTMLConverter _exitElement:tag:display:depth:startIndex:]):
(-[WebHTMLConverter _processText:]):
(-[WebHTMLConverter _traverseNode:depth:embedded:]):
(-[WebHTMLConverter _traverseFooterNode:depth:]):
(-[WebHTMLConverter _loadFromDOMRange]):
(-[WebHTMLConverter dealloc]):
(-[WebHTMLConverter init]):
(-[WebHTMLConverter initWithDOMRange:]):
(-[WebHTMLConverter attributedString]):
(+[WebHTMLConverter editingAttributedStringFromRange:]):
2013-09-17 Sam Weinig <sam@webkit.org>
 
Add make_unique and start using it
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
* Copyright (C) 2010-2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -33,6 +33,7 @@ namespace WebCore {
@interface WebHTMLConverter : NSObject {
NSMutableAttributedString *_attrStr;
NSMutableDictionary *_documentAttrs;
NSURL *_baseURL;
DOMDocument *_document;
DOMRange *_domRange;
......@@ -83,7 +84,8 @@ namespace WebCore {
- (id)initWithDOMRange:(DOMRange *)domRange;
- (NSAttributedString *)attributedString;
#if !PLATFORM(IOS)
+ (NSAttributedString *)editingAttributedStringFromRange:(WebCore::Range*)range;
#endif
@end
......@@ -40,21 +40,348 @@
#import "Font.h"
#import "Frame.h"
#import "FrameLoader.h"
#import "HTMLImageElement.h"
#import "HTMLNames.h"
#import "HTMLParserIdioms.h"
#import "HTMLTableElement.h"
#import "LoaderNSURLExtras.h"
#import "RenderImage.h"
#import "SoftLinking.h"
#import "TextIterator.h"
#import <objc/runtime.h>
#import <wtf/ASCIICType.h>
#if PLATFORM(IOS)
SOFT_LINK_FRAMEWORK(UIKit)
SOFT_LINK_CLASS(UIKit, UIColor)
SOFT_LINK_PRIVATE_FRAMEWORK(UIFoundation)
SOFT_LINK_CLASS(UIFoundation, UIFont)
SOFT_LINK_CLASS(UIFoundation, NSColor)
SOFT_LINK_CLASS(UIFoundation, NSShadow)
SOFT_LINK_CLASS(UIFoundation, NSTextAttachment)
SOFT_LINK_CLASS(UIFoundation, NSMutableParagraphStyle)
SOFT_LINK_CLASS(UIFoundation, NSParagraphStyle)
SOFT_LINK_CLASS(UIFoundation, NSTextList)
SOFT_LINK_CLASS(UIFoundation, NSTextBlock)
SOFT_LINK_CLASS(UIFoundation, NSTextTableBlock)
SOFT_LINK_CLASS(UIFoundation, NSTextTable)
SOFT_LINK_CLASS(UIFoundation, NSTextTab)
SOFT_LINK_CONSTANT(UIFoundation, NSFontAttributeName, NSString *)
#define NSFontAttributeName getNSFontAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSForegroundColorAttributeName, NSString *)
#define NSForegroundColorAttributeName getNSForegroundColorAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSBackgroundColorAttributeName, NSString *)
#define NSBackgroundColorAttributeName getNSBackgroundColorAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSStrokeColorAttributeName, NSString *)
#define NSStrokeColorAttributeName getNSStrokeColorAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSStrokeWidthAttributeName, NSString *)
#define NSStrokeWidthAttributeName getNSStrokeWidthAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSShadowAttributeName, NSString *)
#define NSShadowAttributeName getNSShadowAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSKernAttributeName, NSString *)
#define NSKernAttributeName getNSKernAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSLigatureAttributeName, NSString *)
#define NSLigatureAttributeName getNSLigatureAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSUnderlineStyleAttributeName, NSString *)
#define NSUnderlineStyleAttributeName getNSUnderlineStyleAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSSuperscriptAttributeName, NSString *)
#define NSSuperscriptAttributeName getNSSuperscriptAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSStrikethroughStyleAttributeName, NSString *)
#define NSStrikethroughStyleAttributeName getNSStrikethroughStyleAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSBaselineOffsetAttributeName, NSString *)
#define NSBaselineOffsetAttributeName getNSBaselineOffsetAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSWritingDirectionAttributeName, NSString *)
#define NSWritingDirectionAttributeName getNSWritingDirectionAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSParagraphStyleAttributeName, NSString *)
#define NSParagraphStyleAttributeName getNSParagraphStyleAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSAttachmentAttributeName, NSString *)
#define NSAttachmentAttributeName getNSAttachmentAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSLinkAttributeName, NSString *)
#define NSLinkAttributeName getNSLinkAttributeName()
SOFT_LINK_CONSTANT(UIFoundation, NSAuthorDocumentAttribute, NSString *)
#define NSAuthorDocumentAttribute getNSAuthorDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSEditorDocumentAttribute, NSString *)
#define NSEditorDocumentAttribute getNSEditorDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSGeneratorDocumentAttribute, NSString *)
#define NSGeneratorDocumentAttribute getNSGeneratorDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSCompanyDocumentAttribute, NSString *)
#define NSCompanyDocumentAttribute getNSCompanyDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSDisplayNameDocumentAttribute, NSString *)
#define NSDisplayNameDocumentAttribute getNSDisplayNameDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSCopyrightDocumentAttribute, NSString *)
#define NSCopyrightDocumentAttribute getNSCopyrightDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSSubjectDocumentAttribute, NSString *)
#define NSSubjectDocumentAttribute getNSSubjectDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSCommentDocumentAttribute, NSString *)
#define NSCommentDocumentAttribute getNSCommentDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSNoIndexDocumentAttribute, NSString *)
#define NSNoIndexDocumentAttribute getNSNoIndexDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSKeywordsDocumentAttribute, NSString *)
#define NSKeywordsDocumentAttribute getNSKeywordsDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSCreationTimeDocumentAttribute, NSString *)
#define NSCreationTimeDocumentAttribute getNSCreationTimeDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSModificationTimeDocumentAttribute, NSString *)
#define NSModificationTimeDocumentAttribute getNSModificationTimeDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSConvertedDocumentAttribute, NSString *)
#define NSConvertedDocumentAttribute getNSConvertedDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSCocoaVersionDocumentAttribute, NSString *)
#define NSCocoaVersionDocumentAttribute getNSCocoaVersionDocumentAttribute()
#define PlatformNSShadow getNSShadowClass()
#define PlatformNSTextAttachment getNSTextAttachmentClass()
#define PlatformNSParagraphStyle getNSParagraphStyleClass()
#define PlatformNSTextList getNSTextListClass()
#define PlatformNSTextTableBlock getNSTextTableBlockClass()
#define PlatformNSTextTable getNSTextTableClass()
#define PlatformNSTextTab getNSTextTabClass()
#define PlatformColor UIColor
#define PlatformColorClass getUIColorClass()
#define PlatformFont UIFont
#define PlatformFontClass getUIFontClass()
#else
#define PlatformNSShadow NSShadow
#define PlatformNSTextAttachment NSTextAttachment
#define PlatformNSParagraphStyle NSParagraphStyle
#define PlatformNSTextList NSTextList
#define PlatformNSTextTableBlock NSTextTableBlock
#define PlatformNSTextTable NSTextTable
#define PlatformNSTextTab NSTextTab
#define PlatformColor NSColor
#define PlatformColorClass NSColor
#define PlatformFont NSFont
#define PlatformFontClass NSFont
#define NSTextAlignmentLeft NSLeftTextAlignment
#define NSTextAlignmentRight NSRightTextAlignment
#define NSTextAlignmentCenter NSCenterTextAlignment
#define NSTextAlignmentJustified NSJustifiedTextAlignment
#endif
using namespace WebCore;
using namespace HTMLNames;
#if PLATFORM(IOS)
typedef enum {
UIFontTraitPlain = 0x00000000,
UIFontTraitItalic = 0x00000001, // 1 << 0
UIFontTraitBold = 0x00000002, // 1 << 1
UIFontTraitThin = (1 << 2),
UIFontTraitLight = (1 << 3),
UIFontTraitUltraLight = (1 << 4)
} UIFontTrait;
typedef NS_ENUM(NSInteger, NSUnderlineStyle) {
NSUnderlineStyleNone = 0x00,
NSUnderlineStyleSingle = 0x01,
NSUnderlineStyleThick NS_ENUM_AVAILABLE_IOS(7_0) = 0x02,
NSUnderlineStyleDouble NS_ENUM_AVAILABLE_IOS(7_0) = 0x09,
NSUnderlinePatternSolid NS_ENUM_AVAILABLE_IOS(7_0) = 0x0000,
NSUnderlinePatternDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0100,
NSUnderlinePatternDash NS_ENUM_AVAILABLE_IOS(7_0) = 0x0200,
NSUnderlinePatternDashDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0300,
NSUnderlinePatternDashDotDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0400,
NSUnderlineByWord NS_ENUM_AVAILABLE_IOS(7_0) = 0x8000
};
enum {
NSTextBlockAbsoluteValueType = 0, // Absolute value in points
NSTextBlockPercentageValueType = 1 // Percentage value (out of 100)
};
typedef NSUInteger NSTextBlockValueType;
enum {
NSTextBlockWidth = 0,
NSTextBlockMinimumWidth = 1,
NSTextBlockMaximumWidth = 2,
NSTextBlockHeight = 4,
NSTextBlockMinimumHeight = 5,
NSTextBlockMaximumHeight = 6
};
typedef NSUInteger NSTextBlockDimension;
enum {
NSTextBlockPadding = -1,
NSTextBlockBorder = 0,
NSTextBlockMargin = 1
};
typedef NSInteger NSTextBlockLayer;
enum {
NSTextTableAutomaticLayoutAlgorithm = 0,
NSTextTableFixedLayoutAlgorithm = 1
};
typedef NSUInteger NSTextTableLayoutAlgorithm;
enum {
NSTextBlockTopAlignment = 0,
NSTextBlockMiddleAlignment = 1,
NSTextBlockBottomAlignment = 2,
NSTextBlockBaselineAlignment = 3
};
typedef NSUInteger NSTextBlockVerticalAlignment;
typedef NS_ENUM(NSInteger, NSTextAlignment) {
NSTextAlignmentLeft = 0, // Visually left aligned
NSTextAlignmentCenter = 1, // Visually centered
NSTextAlignmentRight = 2, // Visually right aligned
NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.
NSTextAlignmentNatural = 4, // Indicates the default alignment for script
} NS_ENUM_AVAILABLE_IOS(6_0);
typedef NS_ENUM(NSInteger, NSWritingDirection) {
NSWritingDirectionNatural = -1, // Determines direction using the Unicode Bidi Algorithm rules P2 and P3
NSWritingDirectionLeftToRight = 0, // Left to right writing direction
NSWritingDirectionRightToLeft = 1 // Right to left writing direction
} NS_ENUM_AVAILABLE_IOS(6_0);
typedef NS_ENUM(NSInteger, NSTextWritingDirection) {
NSTextWritingDirectionEmbedding = (0 << 1),
NSTextWritingDirectionOverride = (1 << 1)
} NS_ENUM_AVAILABLE_IOS(7_0);
enum {
NSEnterCharacter = 0x0003,
NSBackspaceCharacter = 0x0008,
NSTabCharacter = 0x0009,
NSNewlineCharacter = 0x000a,
NSFormFeedCharacter = 0x000c,
NSCarriageReturnCharacter = 0x000d,
NSBackTabCharacter = 0x0019,
NSDeleteCharacter = 0x007f,
NSLineSeparatorCharacter = 0x2028,
NSParagraphSeparatorCharacter = 0x2029,
NSAttachmentCharacter = 0xFFFC // Replacement character is used for attachments
};
enum {
NSLeftTabStopType = 0,
NSRightTabStopType,
NSCenterTabStopType,
NSDecimalTabStopType
};
typedef NSUInteger NSTextTabType;
@interface UIColor : NSObject
+ (UIColor *)clearColor;
- (CGFloat)alphaComponent;
+ (UIColor *)_disambiguated_due_to_CIImage_colorWithCGColor:(CGColorRef)cgColor;
@end
@interface NSColor : UIColor
+ (id)colorWithCalibratedRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
+ (id)colorWithCalibratedWhite:(CGFloat)white alpha:(CGFloat)alpha;
@end
@interface UIFont
+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize;
+ (UIFont *)fontWithFamilyName:(NSString *)familyName traits:(UIFontTrait)traits size:(CGFloat)fontSize;
- (NSString *)familyName;
- (CGFloat)pointSize;
- (UIFont *)fontWithSize:(CGFloat)fontSize;
+ (NSArray *)familyNames;
+ (NSArray *)fontNamesForFamilyName:(NSString *)familyName;
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize;
@end
@interface NSTextTab
- (id)initWithType:(NSTextTabType)type location:(CGFloat)loc;
- (id)initWithTextAlignment:(NSTextAlignment)alignment location:(CGFloat)loc options:(NSDictionary *)options;
- (CGFloat)location;
- (void)release;
@end
@interface NSParagraphStyle : NSObject
+ (NSParagraphStyle *)defaultParagraphStyle;
- (void)setAlignment:(NSTextAlignment)alignment;
- (void)setBaseWritingDirection:(NSWritingDirection)writingDirection;
- (void)setHeadIndent:(CGFloat)aFloat;
- (CGFloat)headIndent;
- (void)setHeaderLevel:(NSInteger)level;
- (void)setFirstLineHeadIndent:(CGFloat)aFloat;
- (void)setTailIndent:(CGFloat)aFloat;
- (void)setParagraphSpacing:(CGFloat)paragraphSpacing;
- (void)setTextLists:(NSArray *)array;
- (void)setTextBlocks:(NSArray *)array;
- (void)setMinimumLineHeight:(CGFloat)aFloat;
- (NSArray *)textLists;
- (void)removeTabStop:(NSTextTab *)anObject;
- (void)addTabStop:(NSTextTab *)anObject;
- (NSArray *)tabStops;
- (void)setHyphenationFactor:(float)aFactor;
@end
@interface NSShadow
- (void)setShadowOffset:(CGSize)size;
- (void)setShadowBlurRadius:(CGFloat)radius;
- (void)setShadowColor:(UIColor *)color;
@end
@interface NSTextBlock : NSObject
- (void)setValue:(CGFloat)val type:(NSTextBlockValueType)type forDimension:(NSTextBlockDimension)dimension;
- (void)setWidth:(CGFloat)val type:(NSTextBlockValueType)type forLayer:(NSTextBlockLayer)layer edge:(NSRectEdge)edge;
- (void)setBackgroundColor:(UIColor *)color;
- (UIColor *)backgroundColor;
- (void)setBorderColor:(UIColor *)color forEdge:(NSRectEdge)edge;
- (void)setBorderColor:(UIColor *)color; // Convenience method sets all edges at once
- (void)setVerticalAlignment:(NSTextBlockVerticalAlignment)alignment;
@end
@interface NSTextList
- (id)initWithMarkerFormat:(NSString *)format options:(NSUInteger)mask;
- (void)setStartingItemNumber:(NSInteger)itemNum;
- (NSInteger)startingItemNumber;
- (NSString *)markerForItemNumber:(NSInteger)itemNum;
- (void)release;
@end
@interface NSMutableParagraphStyle : NSParagraphStyle
- (void)setDefaultTabInterval:(CGFloat)aFloat;
- (void)setTabStops:(NSArray *)array;
@end
@interface NSTextAttachment : NSObject
- (id)initWithFileWrapper:(NSFileWrapper *)fileWrapper;
#if PLATFORM(IOS)
- (void)setBounds:(CGRect)bounds;
#endif
- (void)release;
@end
@interface NSTextTable : NSTextBlock
- (void)setNumberOfColumns:(NSUInteger)numCols;
- (void)setCollapsesBorders:(BOOL)flag;
- (void)setHidesEmptyCells:(BOOL)flag;
- (void)setLayoutAlgorithm:(NSTextTableLayoutAlgorithm)algorithm;
- (NSUInteger)numberOfColumns;
- (void)release;
@end
@interface NSTextTableBlock : NSTextBlock
- (id)initWithTable:(NSTextTable *)table startingRow:(NSInteger)row rowSpan:(NSInteger)rowSpan startingColumn:(NSInteger)col columnSpan:(NSInteger)colSpan; // Designated initializer
- (NSInteger)startingColumn;
- (NSInteger)startingRow;
- (NSUInteger)numberOfColumns;
- (NSInteger)columnSpan;
- (NSInteger)rowSpan;
@end
#else
static NSFileWrapper *fileWrapperForURL(DocumentLoader *, NSURL *);
static NSFileWrapper *fileWrapperForElement(Element*);
@interface NSTextAttachment (WebCoreNSTextAttachment)
- (void)setIgnoresOrientation:(BOOL)flag;
- (void)setBounds:(CGRect)bounds;
- (BOOL)ignoresOrientation;
@end
#endif
// Additional control Unicode characters
const unichar WebNextLineCharacter = 0x0085;
......@@ -62,62 +389,86 @@ const unichar WebNextLineCharacter = 0x0085;
+ (NSDictionary *)_standardMarkerAttributesForAttributes:(NSDictionary *)attrs;
@end
@interface NSTextAttachment (NSIgnoreOrientation)
- (void)setIgnoresOrientation:(BOOL)flag;
- (BOOL)ignoresOrientation;
@end
@interface NSURL (WebCoreNSURLDetails)
// FIXME: What is the reason to use this Foundation method, and not +[NSURL URLWithString:relativeToURL:]?
+ (NSURL *)_web_URLWithString:(NSString *)string relativeToURL:(NSURL *)baseURL;
@end
@interface NSObject(WebMessageDocumentSimulation)
+ (void)document:(NSObject **)outDocument attachment:(NSTextAttachment **)outAttachment forURL:(NSURL *)url;
@end
@interface WebHTMLConverter(WebHTMLConverterInternal)
- (NSString *)_stringForNode:(DOMNode *)node property:(NSString *)key;
- (NSColor *)_colorForNode:(DOMNode *)node property:(NSString *)key;
- (PlatformColor *)_colorForNode:(DOMNode *)node property:(NSString *)key;
- (BOOL)_getFloat:(CGFloat *)val forNode:(DOMNode *)node property:(NSString *)key;
- (void)_traverseNode:(DOMNode *)node depth:(NSInteger)depth embedded:(BOOL)embedded;
- (void)_traverseFooterNode:(DOMNode *)node depth:(NSInteger)depth;
@end
@implementation WebHTMLConverter
#if !PLATFORM(IOS)
// Returns the font to be used if the NSFontAttributeName doesn't exist
static NSFont *WebDefaultFont()
{
static NSFont *defaultFont = nil;
if (defaultFont)
return defaultFont;
NSFont *font = [NSFont fontWithName:@"Helvetica" size:12];
NSFont *font = [NSFont fontWithName:@"Helvetica" size:12];
if (!font)
font = [NSFont systemFontOfSize:12];
defaultFont = [font retain];
return defaultFont;
}
#endif
@implementation WebHTMLConverter
static NSFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDictionary *cache)
static PlatformFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDictionary *cache)
{
NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSFont *font = [cache objectForKey:fontName];
PlatformFont *font = [cache objectForKey:fontName];
#if PLATFORM(IOS)
if (font)
return [font fontWithSize:size];
font = [PlatformFontClass fontWithName:fontName size:size];
#else
NSFontManager *fontManager = [NSFontManager sharedFontManager];
if (font) {
font = [fontManager convertFont:font toSize:size];
return font;
}
font = [fontManager fontWithFamily:fontName traits:0 weight:0 size:size];
#endif
if (!font) {
#if PLATFORM(IOS)
NSArray *availableFamilyNames = [PlatformFontClass familyNames];
#else
NSArray *availableFamilyNames = [fontManager availableFontFamilies];
NSRange dividingRange, dividingSpaceRange = [fontName rangeOfString:@" " options:NSBackwardsSearch], dividingDashRange = [fontName rangeOfString:@"-" options:NSBackwardsSearch];
#endif
NSRange dividingRange;
NSRange dividingSpaceRange = [fontName rangeOfString:@" " options:NSBackwardsSearch];
NSRange dividingDashRange = [fontName rangeOfString:@"-" options:NSBackwardsSearch];
dividingRange = (0 < dividingSpaceRange.length && 0 < dividingDashRange.length) ? (dividingSpaceRange.location > dividingDashRange.location ? dividingSpaceRange : dividingDashRange) : (0 < dividingSpaceRange.length ? dividingSpaceRange : dividingDashRange);
while (0 < dividingRange.length) {
while (dividingRange.length > 0) {
NSString *familyName = [fontName substringToIndex:dividingRange.location];
if ([availableFamilyNames containsObject:familyName]) {
#if PLATFORM(IOS)
NSString *faceName = [fontName substringFromIndex:(dividingRange.location + dividingRange.length)];
NSArray *familyMemberFaceNames = [PlatformFontClass fontNamesForFamilyName:familyName];
for (NSString *familyMemberFaceName in familyMemberFaceNames) {
if ([familyMemberFaceName compare:faceName options:NSCaseInsensitiveSearch] == NSOrderedSame) {
font = [PlatformFontClass fontWithName:familyMemberFaceName size:size];
break;
}
}
if (!font && [familyMemberFaceNames count])
font = [getUIFontClass() fontWithName:familyName size:size];
#else
NSArray *familyMemberArray;
NSString *faceName = [fontName substringFromIndex:(dividingRange.location + dividingRange.length)];
NSArray *familyMemberArrays = [fontManager availableMembersOfFontFamily:familyName];
......@@ -139,6 +490,7 @@ static NSFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDi
font = [fontManager fontWithFamily:familyName traits:traits weight:weight size:size];
}
}
#endif
break;
} else {
dividingSpaceRange = [familyName rangeOfString:@" " options:NSBackwardsSearch];
......@@ -147,11 +499,21 @@ static NSFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDi
}
}
}
if (!font) font = [NSFont fontWithName:@"Times" size:size];
if (!font) font = [NSFont userFontOfSize:size];
if (!font) font = [fontManager convertFont:WebDefaultFont() toSize:size];
if (!font) font = WebDefaultFont();
#if PLATFORM(IOS)
if (!font)
font = [PlatformFontClass systemFontOfSize:size];
#else
if (!font)
font = [NSFont fontWithName:@"Times" size:size];
if (!font)
font = [NSFont userFontOfSize:size];
if (!font)
font = [fontManager convertFont:WebDefaultFont() toSize:size];
if (!font)
font = WebDefaultFont();
#endif
[cache setObject:font forKey:fontName];
return font;
}
......@@ -159,7 +521,7 @@ static NSFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDi
{
static NSMutableParagraphStyle *defaultParagraphStyle = nil;
if (!defaultParagraphStyle) {
defaultParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
defaultParagraphStyle = [[PlatformNSParagraphStyle defaultParagraphStyle] mutableCopy];
[defaultParagraphStyle setDefaultTabInterval:36];
[defaultParagraphStyle setTabStops:[NSArray array]];
}
......@@ -183,7 +545,8 @@ static NSFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDi
DOMCSSStyleDeclaration *result = nil;
result = [_computedStylesForElements objectForKey:element];
if (result) {
if ([[NSNull null] isEqual:result]) result = nil;
if ([result isEqual:[NSNull null]])
result = nil;
} else {
result = [document getComputedStyle:element pseudoElement:@""] ;
[_computedStylesForElements setObject:(result ? (id)result : (id)[NSNull null]) forKey:element];
......@@ -195,7 +558,8 @@ static NSFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDi
{