Commit 15cdfc52 authored by darin's avatar darin
Browse files

Reviewed by John.

	Overall speedup on cvs-base is about 5%.

	- reduce QString use in the tokenizer and tighten up QString implementation for a speedup
	- fix up the QFontFamily implementation, using new QString features too, for a speedup

        * khtml/html/htmltokenizer.h: Take const QString & instead of QString to avoid an extra copy.
        * khtml/html/htmltokenizer.cpp:
        (HTMLTokenizer::begin): Use QString::null instead of "" for QString objects; faster.
        (HTMLTokenizer::scriptHandler): In APPLE_CHANGES, use new prepend that avoids the need to
	create a temporary QString. Use QString::null instead of QString() for a null string, and
	also made other small fixes to avoid temporary QStrings.
	(HTMLTokenizer::setSrc): Take const QString & instead of QString to avoid an extra copy.

        * kwq/KWQFont.h: Rename QFontFamily to KWQFontFamily. Make family() inline, add inline
	familyIsEmpty(). Change KWQFontFamily to store both the QString for the family and the
	NSString instead of only the NSString to avoid constant conversions back and forth.
	Remove type cases in CREATE_FAMILY_ARRAY that could result in copying the font object.
        * kwq/KWQFont.mm:
        (KWQFontFamily::KWQFontFamily): Fix bug where a copied family object would have a random
	ref count instead of a ref count of 0. Also update for NSString change.
        (KWQFontFamily::operator=): Use the ref before deref algorithm instead of the check for
	self-assignment.
        (KWQFontFamily::getNSFamily): Compute the NSString for the family name here. To avoid
	making an NSString every time, use a CFDictionary with QString as a key and NSString as
	a value instead of using an NSSet.
        (KWQFontFamily::setFamily): Invalidate the NSString family when the QString family is
	changed. Moved the code to make things unique to getNSFamily.
        (KWQFontFamily::operator==): Call getNSFamily rather than

        * kwq/KWQString.h: Added a prepend and insert overload that take a QChar pointer and length, for
	use in the tokenizer, and a hash function, for use in CFDictionary. Also added a global set of
	CFDictionaryKeyCallBacks.
        * kwq/KWQString.mm:
        (QString::prepend): New overload calls new insert overload.
        (QString::insert): Old insert slightly tightened by calling detach() only after the early exit
	and removing an extra detach from a function that already does forceUnicode. Added the new insert
	that takes a QChar * and a length.
        (operator==): Rewrite this so that it is efficient and doesn't involve creating a QString temporary
	or doing a function call.
        (QString::hash): Wrote this. Used the same hash algorithm I did in my recent KJS work.
        (retainQString): Added. For use in CFDictionaryKey callback.
        (releaseQString): Added. For use in CFDictionaryKey callback.
        (describeQString): Added. For use in CFDictionaryKey callback.
        (equalQString): Added. For use in CFDictionaryKey callback.
        (hashQString): Added. For use in CFDictionaryKey callback.

        * khtml/rendering/font.h: Change name to KWQFontFamily.
        * khtml/rendering/font.cpp: (Font::update): Call familyIsEmpty() instead of family().isEmpty()
	to avoid making and destroying a QString every time. Also put this batch of KWQFontFamily-specific
	changes inside #if APPLE_CHANGES. Much to my dismay, we have others elsewhere that aren't ifdef'd.

        * khtml/css/cssstyleselector.cpp: (CSSStyleSelector::applyRule): Change name to KWQFontFamily.
	Clearly this code needs some #if APPLE_CHANGES, and changing the class name helps make that clear.

	- change KHTMLSettings so using it doesn't require copying QStrings for a speedup

        * kwq/KWQKHTMLSettings.h: Made all the functions static members to avoid the unnecessary
	overhead of passing a this pointer. Added lots of setXXX functions for use by the WebCoreSettings
	code that gets called by WebKit when settings are changed. Return objects by reference because we
	can and it avoids copying QString objects.
        * kwq/KWQKHTMLSettings.mm: Changed all the functions in here to return the same global object
	each time, and made the set functions update those globals.
        * kwq/WebCoreSettings.mm: All the setters now call through to KHTMLSettings set functions.

        - fixed 3126513 -- crash in KWQKHTMLPart::clearTimers() deallocating KWQPageState
	- did some cleanup in the bridge and the part; part of the process of moving real work out of the bridge

        * kwq/KWQKHTMLPart.h: Rearrange things to be a little more logical. Mark isFrameSet() const.
	added an attributedString function here so it's not inside WebCoreBridge. Added an overload
	of clearTimers that takes a view parameter.
        * kwq/KWQKHTMLPart.cpp: (KWQKHTMLPart::isFrameSet): Mark this const.
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::clearTimers): Add the overload that takes the view parameter.
        (KWQKHTMLPart::attributedString): Moved this code in here from the bridge.

        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge selectedAttributedString]): Call the attributedString function in its new home in
	KWQKHTMLPart.
        (-[WebCoreBridge attributedStringFrom:startOffset:to:endOffset:]): Ditto.
        (-[KWQPageState initWithDocument:URL:windowProperties:locationProperties:]):
	Take a const KURL & instead of a KURL to avoid unnecessary copying.
        (-[KWQPageState dealloc]): Call the new clearTimers that takes a view parameter. This should fix the
	crash in autorelease pool deallocation mentioned above.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3033 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent dda1d1b4
2002-12-13 Darin Adler <darin@apple.com>
Reviewed by John.
Overall speedup on cvs-base is about 5%.
- reduce QString use in the tokenizer and tighten up QString implementation for a speedup
- fix up the QFontFamily implementation, using new QString features too, for a speedup
* khtml/html/htmltokenizer.h: Take const QString & instead of QString to avoid an extra copy.
* khtml/html/htmltokenizer.cpp:
(HTMLTokenizer::begin): Use QString::null instead of "" for QString objects; faster.
(HTMLTokenizer::scriptHandler): In APPLE_CHANGES, use new prepend that avoids the need to
create a temporary QString. Use QString::null instead of QString() for a null string, and
also made other small fixes to avoid temporary QStrings.
(HTMLTokenizer::setSrc): Take const QString & instead of QString to avoid an extra copy.
* kwq/KWQFont.h: Rename QFontFamily to KWQFontFamily. Make family() inline, add inline
familyIsEmpty(). Change KWQFontFamily to store both the QString for the family and the
NSString instead of only the NSString to avoid constant conversions back and forth.
Remove type cases in CREATE_FAMILY_ARRAY that could result in copying the font object.
* kwq/KWQFont.mm:
(KWQFontFamily::KWQFontFamily): Fix bug where a copied family object would have a random
ref count instead of a ref count of 0. Also update for NSString change.
(KWQFontFamily::operator=): Use the ref before deref algorithm instead of the check for
self-assignment.
(KWQFontFamily::getNSFamily): Compute the NSString for the family name here. To avoid
making an NSString every time, use a CFDictionary with QString as a key and NSString as
a value instead of using an NSSet.
(KWQFontFamily::setFamily): Invalidate the NSString family when the QString family is
changed. Moved the code to make things unique to getNSFamily.
(KWQFontFamily::operator==): Call getNSFamily rather than
* kwq/KWQString.h: Added a prepend and insert overload that take a QChar pointer and length, for
use in the tokenizer, and a hash function, for use in CFDictionary. Also added a global set of
CFDictionaryKeyCallBacks.
* kwq/KWQString.mm:
(QString::prepend): New overload calls new insert overload.
(QString::insert): Old insert slightly tightened by calling detach() only after the early exit
and removing an extra detach from a function that already does forceUnicode. Added the new insert
that takes a QChar * and a length.
(operator==): Rewrite this so that it is efficient and doesn't involve creating a QString temporary
or doing a function call.
(QString::hash): Wrote this. Used the same hash algorithm I did in my recent KJS work.
(retainQString): Added. For use in CFDictionaryKey callback.
(releaseQString): Added. For use in CFDictionaryKey callback.
(describeQString): Added. For use in CFDictionaryKey callback.
(equalQString): Added. For use in CFDictionaryKey callback.
(hashQString): Added. For use in CFDictionaryKey callback.
* khtml/rendering/font.h: Change name to KWQFontFamily.
* khtml/rendering/font.cpp: (Font::update): Call familyIsEmpty() instead of family().isEmpty()
to avoid making and destroying a QString every time. Also put this batch of KWQFontFamily-specific
changes inside #if APPLE_CHANGES. Much to my dismay, we have others elsewhere that aren't ifdef'd.
* khtml/css/cssstyleselector.cpp: (CSSStyleSelector::applyRule): Change name to KWQFontFamily.
Clearly this code needs some #if APPLE_CHANGES, and changing the class name helps make that clear.
- change KHTMLSettings so using it doesn't require copying QStrings for a speedup
* kwq/KWQKHTMLSettings.h: Made all the functions static members to avoid the unnecessary
overhead of passing a this pointer. Added lots of setXXX functions for use by the WebCoreSettings
code that gets called by WebKit when settings are changed. Return objects by reference because we
can and it avoids copying QString objects.
* kwq/KWQKHTMLSettings.mm: Changed all the functions in here to return the same global object
each time, and made the set functions update those globals.
* kwq/WebCoreSettings.mm: All the setters now call through to KHTMLSettings set functions.
- fixed 3126513 -- crash in KWQKHTMLPart::clearTimers() deallocating KWQPageState
- did some cleanup in the bridge and the part; part of the process of moving real work out of the bridge
* kwq/KWQKHTMLPart.h: Rearrange things to be a little more logical. Mark isFrameSet() const.
added an attributedString function here so it's not inside WebCoreBridge. Added an overload
of clearTimers that takes a view parameter.
* kwq/KWQKHTMLPart.cpp: (KWQKHTMLPart::isFrameSet): Mark this const.
* kwq/KWQKHTMLPart.mm:
(KWQKHTMLPart::clearTimers): Add the overload that takes the view parameter.
(KWQKHTMLPart::attributedString): Moved this code in here from the bridge.
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge selectedAttributedString]): Call the attributedString function in its new home in
KWQKHTMLPart.
(-[WebCoreBridge attributedStringFrom:startOffset:to:endOffset:]): Ditto.
(-[KWQPageState initWithDocument:URL:windowProperties:locationProperties:]):
Take a const KURL & instead of a KURL to avoid unnecessary copying.
(-[KWQPageState dealloc]): Call the new clearTimers that takes a view parameter. This should fix the
crash in autorelease pool deallocation mentioned above.
2002-12-13 David Hyatt <hyatt@apple.com>
Fix for 3121865, content missing at disney.com. Make
......
2002-12-13 Darin Adler <darin@apple.com>
Reviewed by John.
Overall speedup on cvs-base is about 5%.
- reduce QString use in the tokenizer and tighten up QString implementation for a speedup
- fix up the QFontFamily implementation, using new QString features too, for a speedup
* khtml/html/htmltokenizer.h: Take const QString & instead of QString to avoid an extra copy.
* khtml/html/htmltokenizer.cpp:
(HTMLTokenizer::begin): Use QString::null instead of "" for QString objects; faster.
(HTMLTokenizer::scriptHandler): In APPLE_CHANGES, use new prepend that avoids the need to
create a temporary QString. Use QString::null instead of QString() for a null string, and
also made other small fixes to avoid temporary QStrings.
(HTMLTokenizer::setSrc): Take const QString & instead of QString to avoid an extra copy.
* kwq/KWQFont.h: Rename QFontFamily to KWQFontFamily. Make family() inline, add inline
familyIsEmpty(). Change KWQFontFamily to store both the QString for the family and the
NSString instead of only the NSString to avoid constant conversions back and forth.
Remove type cases in CREATE_FAMILY_ARRAY that could result in copying the font object.
* kwq/KWQFont.mm:
(KWQFontFamily::KWQFontFamily): Fix bug where a copied family object would have a random
ref count instead of a ref count of 0. Also update for NSString change.
(KWQFontFamily::operator=): Use the ref before deref algorithm instead of the check for
self-assignment.
(KWQFontFamily::getNSFamily): Compute the NSString for the family name here. To avoid
making an NSString every time, use a CFDictionary with QString as a key and NSString as
a value instead of using an NSSet.
(KWQFontFamily::setFamily): Invalidate the NSString family when the QString family is
changed. Moved the code to make things unique to getNSFamily.
(KWQFontFamily::operator==): Call getNSFamily rather than
* kwq/KWQString.h: Added a prepend and insert overload that take a QChar pointer and length, for
use in the tokenizer, and a hash function, for use in CFDictionary. Also added a global set of
CFDictionaryKeyCallBacks.
* kwq/KWQString.mm:
(QString::prepend): New overload calls new insert overload.
(QString::insert): Old insert slightly tightened by calling detach() only after the early exit
and removing an extra detach from a function that already does forceUnicode. Added the new insert
that takes a QChar * and a length.
(operator==): Rewrite this so that it is efficient and doesn't involve creating a QString temporary
or doing a function call.
(QString::hash): Wrote this. Used the same hash algorithm I did in my recent KJS work.
(retainQString): Added. For use in CFDictionaryKey callback.
(releaseQString): Added. For use in CFDictionaryKey callback.
(describeQString): Added. For use in CFDictionaryKey callback.
(equalQString): Added. For use in CFDictionaryKey callback.
(hashQString): Added. For use in CFDictionaryKey callback.
* khtml/rendering/font.h: Change name to KWQFontFamily.
* khtml/rendering/font.cpp: (Font::update): Call familyIsEmpty() instead of family().isEmpty()
to avoid making and destroying a QString every time. Also put this batch of KWQFontFamily-specific
changes inside #if APPLE_CHANGES. Much to my dismay, we have others elsewhere that aren't ifdef'd.
* khtml/css/cssstyleselector.cpp: (CSSStyleSelector::applyRule): Change name to KWQFontFamily.
Clearly this code needs some #if APPLE_CHANGES, and changing the class name helps make that clear.
- change KHTMLSettings so using it doesn't require copying QStrings for a speedup
* kwq/KWQKHTMLSettings.h: Made all the functions static members to avoid the unnecessary
overhead of passing a this pointer. Added lots of setXXX functions for use by the WebCoreSettings
code that gets called by WebKit when settings are changed. Return objects by reference because we
can and it avoids copying QString objects.
* kwq/KWQKHTMLSettings.mm: Changed all the functions in here to return the same global object
each time, and made the set functions update those globals.
* kwq/WebCoreSettings.mm: All the setters now call through to KHTMLSettings set functions.
- fixed 3126513 -- crash in KWQKHTMLPart::clearTimers() deallocating KWQPageState
- did some cleanup in the bridge and the part; part of the process of moving real work out of the bridge
* kwq/KWQKHTMLPart.h: Rearrange things to be a little more logical. Mark isFrameSet() const.
added an attributedString function here so it's not inside WebCoreBridge. Added an overload
of clearTimers that takes a view parameter.
* kwq/KWQKHTMLPart.cpp: (KWQKHTMLPart::isFrameSet): Mark this const.
* kwq/KWQKHTMLPart.mm:
(KWQKHTMLPart::clearTimers): Add the overload that takes the view parameter.
(KWQKHTMLPart::attributedString): Moved this code in here from the bridge.
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge selectedAttributedString]): Call the attributedString function in its new home in
KWQKHTMLPart.
(-[WebCoreBridge attributedStringFrom:startOffset:to:endOffset:]): Ditto.
(-[KWQPageState initWithDocument:URL:windowProperties:locationProperties:]):
Take a const KURL & instead of a KURL to avoid unnecessary copying.
(-[KWQPageState dealloc]): Call the new clearTimers that takes a view parameter. This should fix the
crash in autorelease pool deallocation mentioned above.
2002-12-13 David Hyatt <hyatt@apple.com>
Fix for 3121865, content missing at disney.com. Make
......
......@@ -2533,8 +2533,8 @@ void CSSStyleSelector::applyRule( DOM::CSSProperty *prop )
CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value);
int len = list->length();
QString family;
QFontFamily& firstFamily = fontDef.firstFamily();
QFontFamily* currFamily = 0;
KWQFontFamily &firstFamily = fontDef.firstFamily();
KWQFontFamily *currFamily = 0;
for(int i = 0; i < len; i++) {
CSSValueImpl *item = list->item(i);
......@@ -2600,7 +2600,7 @@ void CSSStyleSelector::applyRule( DOM::CSSProperty *prop )
currFamily = &firstFamily;
}
else {
QFontFamily* newFamily = new QFontFamily;
KWQFontFamily *newFamily = new KWQFontFamily;
newFamily->setFamily(face);
currFamily->appendFamily(newFamily);
currFamily = newFamily;
......
......@@ -284,8 +284,8 @@ void HTMLTokenizer::begin()
searchCount = 0;
Entity = NoEntity;
loadingExtScript = false;
scriptSrc = "";
pendingSrc = "";
scriptSrc = QString::null;
pendingSrc = QString::null;
noMoreData = false;
brokenComments = false;
brokenServer = false;
......@@ -476,7 +476,11 @@ void HTMLTokenizer::scriptHandler()
//kdDebug( 6036 ) << "cachedscript extern!" << endl;
//kdDebug( 6036 ) << "src: *" << QString( src.current(), src.length() ).latin1() << "*" << endl;
//kdDebug( 6036 ) << "pending: *" << pendingSrc.latin1() << "*" << endl;
#if APPLE_CHANGES
pendingSrc.prepend(src.current(), src.length());
#else
pendingSrc.prepend( QString(src.current(), src.length() ) );
#endif
setSrc(QString::null);
scriptCodeSize = scriptCodeResync = 0;
cs->ref(this);
......@@ -485,16 +489,23 @@ void HTMLTokenizer::scriptHandler()
loadingExtScript = true;
}
else if (view && doScriptExec && javascript ) {
#if APPLE_CHANGES
if (!m_executingScript)
pendingSrc.prepend(src.current(), src.length());
else
prependingSrc.setUnicode(src.current(), src.length());
#else
if ( !m_executingScript )
pendingSrc.prepend( QString( src.current(), src.length() ) ); // deep copy - again
else
prependingSrc = QString( src.current(), src.length() ); // deep copy
#endif
setSrc(QString::null);
scriptCodeSize = scriptCodeResync = 0;
//QTime dt;
//dt.start();
scriptExecution( exScript, QString(), scriptStartLineno );
scriptExecution( exScript, QString::null, scriptStartLineno );
//kdDebug( 6036 ) << "script execution time:" << dt.elapsed() << endl;
}
}
......@@ -505,10 +516,13 @@ void HTMLTokenizer::scriptHandler()
if ( !parser->skipMode() ) {
if ( !m_executingScript && !loadingExtScript ) {
// kdDebug( 6036 ) << "adding pending Output to parsed string" << endl;
QString newStr = QString(src.current(), src.length());
newStr += pendingSrc;
setSrc(newStr);
pendingSrc = "";
#if APPLE_CHANGES
pendingSrc.prepend(src.current(), src.length());
#else
pendingSrc.prepend(QString(src.current(), src.length());
#endif
setSrc(pendingSrc);
pendingSrc = QString::null;
}
else if ( !prependingSrc.isEmpty() )
write( prependingSrc, false );
......@@ -1164,7 +1178,8 @@ void HTMLTokenizer::parseTag(DOMStringIt &src)
tagID -= ID_CLOSE_TAG;
else if ( beginTag && tagID == ID_SCRIPT ) {
AttributeImpl* a = 0;
scriptSrc = scriptSrcCharset = "";
scriptSrc = QString::null;
scriptSrcCharset = QString::null;
if ( currToken.attrs && /* potentially have a ATTR_SRC ? */
parser->doc()->view()->part()->jScriptEnabled() && /* jscript allowed at all? */
view /* are we a regular tokenizer or just for innerHTML ? */
......@@ -1554,7 +1569,7 @@ void HTMLTokenizer::write( const QString &str, bool appendData )
++src;
}
}
_src = QString();
_src = QString::null;
if (noMoreData && !loadingExtScript && !m_executingScript )
end(); // this actually causes us to be deleted
......@@ -1744,7 +1759,7 @@ void HTMLTokenizer::notifyFinished(CachedObject */*finishedObj*/)
}
}
void HTMLTokenizer::setSrc(QString source)
void HTMLTokenizer::setSrc(const QString &source)
{
lineno += src.lineCount();
_src = source;
......
......@@ -154,7 +154,7 @@ protected:
void scriptHandler();
void scriptExecution(const QString& script, QString scriptURL = QString(),
int baseLine = 0);
void setSrc(QString source);
void setSrc(const QString &source);
// check if we have enough space in the buffer.
// if not enlarge it
......
......@@ -184,10 +184,14 @@ int Font::width( QChar *chs, int slen, int pos ) const
void Font::update( QPaintDeviceMetrics* devMetrics ) const
{
if (fontDef.family.family().isEmpty())
f.setFamily(KHTMLFactory::defaultHTMLSettings()->stdFontName());
#if APPLE_CHANGES
if (fontDef.family.familyIsEmpty())
f.setFamily(KHTMLFactory::defaultHTMLSettings()->stdFontName());
else
f.setFirstFamily(fontDef.family);
f.setFirstFamily(fontDef.family);
#else
f.setFamily( fontDef.family.isEmpty() ? KHTMLFactory::defaultHTMLSettings()->stdFontName() : fontDef.family );
#endif
f.setItalic( fontDef.italic );
f.setWeight( fontDef.weight );
......
......@@ -56,9 +56,9 @@ public:
void setGenericFamily(unsigned int aGenericFamily) { genericFamily = aGenericFamily; }
QFontFamily& firstFamily() { return family; }
KWQFontFamily &firstFamily() { return family; }
QFontFamily family;
KWQFontFamily family;
short int size;
bool italic : 1;
bool smallCaps : 1;
......
......@@ -26,7 +26,7 @@
#ifndef QFONT_H_
#define QFONT_H_
class QString;
#include "KWQString.h"
#ifdef __OBJC__
@class NSFont;
......@@ -36,39 +36,43 @@ class NSFont;
class NSString;
#endif
class QFontFamily {
class KWQFontFamily {
public:
QFontFamily();
~QFontFamily() { if (_next) _next->deref(); }
KWQFontFamily();
~KWQFontFamily() { if (_next) _next->deref(); }
QFontFamily(const QFontFamily& other);
QFontFamily& operator=(const QFontFamily& other);
KWQFontFamily(const KWQFontFamily &);
KWQFontFamily &operator=(const KWQFontFamily &);
void setFamily(const QString&);
QString family() const;
void setFamily(const QString &);
QString family() const { return _family; }
bool familyIsEmpty() const { return _family.isEmpty(); }
NSString* getNSFamily() const { return _family; }
NSString *getNSFamily() const;
KWQFontFamily *next() { return _next; }
const KWQFontFamily *next() const { return _next; }
QFontFamily* next() { return _next; }
void appendFamily(QFontFamily* family)
{
void appendFamily(KWQFontFamily *family)
{
if (family)
family->ref();
if (_next)
_next->deref();
_next = family;
if (_next)
_next->ref();
}
bool operator==(const QFontFamily &compareFontFamily) const;
bool operator!=(const QFontFamily &x) const { return !(*this == x); }
bool operator==(const KWQFontFamily &) const;
bool operator!=(const KWQFontFamily &x) const { return !(*this == x); }
void ref() { _refCnt++; };
void deref() { _refCnt--; if (_refCnt == 0) delete this; };
void ref() { _refCnt++; }
void deref() { _refCnt--; if (_refCnt == 0) delete this; }
private:
NSString* _family;
QFontFamily* _next;
QString _family;
KWQFontFamily *_next;
int _refCnt;
mutable NSString *_NSFamily;
};
class QFont {
......@@ -81,8 +85,9 @@ public:
void setFamily(const QString &);
QString family() const;
QFontFamily* firstFamily() { return &_family; }
void setFirstFamily(const QFontFamily& family) ;
const KWQFontFamily *firstFamily() const { return &_family; }
KWQFontFamily *firstFamily() { return &_family; }
void setFirstFamily(const KWQFontFamily &family);
void setWeight(int);
int weight() const;
......@@ -102,9 +107,9 @@ public:
float getNSSize() const { return _size; }
NSFont *getNSFont() const;
private:
QFontFamily _family;
KWQFontFamily _family;
int _trait;
float _size;
mutable NSFont *_nsfont;
......@@ -118,21 +123,21 @@ private:
#define CREATE_FAMILY_ARRAY(font,families)\
int __numFamilies = 0;\
{\
QFontFamily *__ff = ((QFont)font).firstFamily();\
const KWQFontFamily *__ff = (font).firstFamily();\
while (__ff)\
{\
__numFamilies++;\
__ff = __ff->next();\
__ff = __ff->next();\
}\
}\
NSString *families[__numFamilies+1];\
{\
int __i = 0;\
QFontFamily *__ff = ((QFont)font).firstFamily();\
const KWQFontFamily *__ff = (font).firstFamily();\
while (__ff)\
{\
families[__i++] = __ff->getNSFamily();\
__ff = __ff->next();\
__ff = __ff->next();\
}\
families[__i] = 0;\
}
......
......@@ -24,67 +24,74 @@
*/
#import "KWQFont.h"
#import "KWQString.h"
#import <Cocoa/Cocoa.h>
#import "KWQString.h"
#import "WebCoreTextRendererFactory.h"
QFontFamily::QFontFamily()
: _family(@"")
, _next(0)
KWQFontFamily::KWQFontFamily()
: _next(0)
, _refCnt(0)
, _NSFamily(0)
{
}
QFontFamily::QFontFamily(const QFontFamily& other)
KWQFontFamily::KWQFontFamily(const KWQFontFamily& other)
: _family(other._family)
, _next(other._next)
, _refCnt(0)
, _NSFamily(other._NSFamily)
{
_next = other._next;
if (_next)
_next->ref();
_family = other._family;
}
QFontFamily& QFontFamily::operator=(const QFontFamily& other) {
if (this != &other) {
if (_next)
_next->deref();
_next = other._next;
if (_next)
_next->ref();
_family = other._family;
}
KWQFontFamily& KWQFontFamily::operator=(const KWQFontFamily& other)
{
if (other._next)
other._next->ref();
if (_next)
_next->deref();
_family = other._family;
_next = other._next;
_NSFamily = other._NSFamily;
return *this;
}
QString QFontFamily::family() const
NSString *KWQFontFamily::getNSFamily() const
{
return QString::fromNSString(_family);
if (!_NSFamily) {
// Use an immutable copy of the name, but keep a set of
// all family names so we don't end up with too many objects.
static CFMutableDictionaryRef families;
if (families == NULL) {
families = CFDictionaryCreateMutable(NULL, 0, &CFDictionaryQStringKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
_NSFamily = (NSString *)CFDictionaryGetValue(families, &_family);
if (!_NSFamily) {
_NSFamily = _family.getNSString();
CFDictionarySetValue(families, &_family, _NSFamily);
}
}
return _NSFamily;
}
void QFontFamily::setFamily(const QString &qfamilyName)
void KWQFontFamily::setFamily(const QString &family)
{
// Use an immutable copy of the name, but keep a set of
// all family names so we don't end up with too many objects.
static NSMutableSet *families;
if (families == nil) {
families = [[NSMutableSet alloc] init];
}
NSString *mutableName = qfamilyName.getNSString();
_family = [families member:mutableName];
if (!_family) {
[families addObject:mutableName];
_family = [families member:mutableName];
if (family == _family) {
return;
}
_family = family;
_NSFamily = nil;
}
bool QFontFamily::operator==(const QFontFamily &compareFontFamily) const
bool KWQFontFamily::operator==(const KWQFontFamily &compareFontFamily) const
{
if ((!_next && compareFontFamily._next) ||
(_next && !compareFontFamily._next) ||
((_next && compareFontFamily._next) && (*_next != *(compareFontFamily._next))))
return false;
return _family == compareFontFamily._family;
return getNSFamily() == compareFontFamily.getNSFamily();
}
QFont::QFont()
......@@ -111,7 +118,7 @@ void QFont::setFamily(const QString &qfamilyName)
_nsfont = 0;
}
void QFont::setFirstFamily(const QFontFamily& family)
void QFont::setFirstFamily(const KWQFontFamily& family)
{
_family = family;
[_nsfont release];
......@@ -185,13 +192,12 @@ bool QFont::operator==(const QFont &compareFont) const
NSFont *QFont::getNSFont() const
{
if (!_nsfont){
if (!_nsfont) {
CREATE_FAMILY_ARRAY(*this, families);
_nsfont = [[[WebCoreTextRendererFactory sharedFactory]
fontWithFamilies:families
traits:getNSTraits()
size:getNSSize()] retain];
traits:getNSTraits()
size:getNSSize()] retain];
}
return _nsfont;
}
......@@ -34,7 +34,7 @@ using DOM::DocumentImpl;
using DOM::HTMLDocumentImpl;
using DOM::NodeImpl;
bool KWQKHTMLPart::isFrameSet()
bool KWQKHTMLPart::isFrameSet() const
{
DocumentImpl *document = d->m_doc;
if (!document || !document->isHTMLDocument())
......@@ -43,8 +43,7 @@ bool KWQKHTMLPart::isFrameSet()
return body && body->renderer() && body->id() == ID_FRAMESET;
}
int KWQKHTMLPart::selectionStartOffset() const { return d->m_startOffset; }
int KWQKHTMLPart::selectionEndOffset() const { return d->m_endOffset; }
DOM::NodeImpl *KWQKHTMLPart::selectionStart() const { return d->m_selectionStart.handle(); }
DOM::NodeImpl *KWQKHTMLPart::selectionEnd() const { return d->m_selectionEnd.handle(); }