[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:52:32 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 528dbdec9314a98df102237b8a6e3b3fba1fdc2d
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Nov 19 23:19:30 2001 +0000

    Performance tuning tricks.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@464 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/kwq/KWQFontMetrics.mm b/WebCore/kwq/KWQFontMetrics.mm
index d500c65..15d8ba7 100644
--- a/WebCore/kwq/KWQFontMetrics.mm
+++ b/WebCore/kwq/KWQFontMetrics.mm
@@ -27,39 +27,69 @@
 #include <kwqdebug.h>
 #include <qfontmetrics.h>
 
+#import <Cocoa/Cocoa.h>
+#import <KWQMetrics.h>
+#import <KWQTextStorage.h>
+#import <KWQTextContainer.h>
+
+
 #define ROUND_TO_INT(f) ((int)rint((f)))
 const float LargeNumberForText = 1.0e7;
 
- at interface WSMetricsInfo : NSObject
+
+ at implementation KWQLayoutFragment
+- initWithString: (NSString *)str attributes: (NSDictionary *)attrs
 {
-    NSFont *font;
-    NSTextContainer *textContainer;
-    NSLayoutManager *layoutManager;
-    NSDictionary *attributes;
-    NSMutableDictionary *boundingRectCache;
+    [super init];
+
+    textStorage = [[KWQTextStorage alloc] initWithString:str attributes: attrs];
+    //textContainer = [[KWQTextContainer alloc] initWithContainerSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
+    layoutManager = [[NSLayoutManager alloc] init];
+
+    [layoutManager addTextContainer: [KWQTextContainer sharedInstance]];
+    [textStorage addLayoutManager: layoutManager];    
+
+    //[textContainer setLineFragmentPadding:0.0f];
+
+    cachedRect = NO;
+    
+    return self;
 }
 
-+ (WSMetricsInfo *)getMetricsForFont: (NSFont *)aFont;
-+ (void)setMetric: (WSMetricsInfo *)info forFont: (NSFont *)aFont;
-- initWithFont: (NSFont *)aFont;
-- (NSRect)rectForString:(NSString *)string;
+- (NSRect)boundingRect
+{
+    if (!cachedRect){
+        unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
+        boundingRect = [layoutManager boundingRectForGlyphRange: NSMakeRange (0, numberOfGlyphs) inTextContainer: [KWQTextContainer sharedInstance]];
+        cachedRect = YES;
+    }
+    return boundingRect;
+}
 
+- (void)dealloc
+{
+    [textStorage release];
+    //[textContainer release];
+    [layoutManager release];
+    [super dealloc];
+}
 @end
 
+
 static NSMutableDictionary *metricsCache = nil;
 
- at implementation WSMetricsInfo
-+ (WSMetricsInfo *)getMetricsForFont: (NSFont *)aFont
+ at implementation KWQMetricsInfo
++ (KWQMetricsInfo *)getMetricsForFont: (NSFont *)aFont
 {
-    WSMetricsInfo *info = (WSMetricsInfo *)[metricsCache objectForKey: aFont];
+    KWQMetricsInfo *info = (KWQMetricsInfo *)[metricsCache objectForKey: aFont];
     if (info == nil){
-        info = [[WSMetricsInfo alloc] initWithFont: aFont];
-        [WSMetricsInfo setMetric: info forFont: aFont];
+        info = [[KWQMetricsInfo alloc] initWithFont: aFont];
+        [KWQMetricsInfo setMetric: info forFont: aFont];
         [info release];
     }
     return info;
 }
-+ (void)setMetric: (WSMetricsInfo *)info forFont: (NSFont *)aFont
++ (void)setMetric: (KWQMetricsInfo *)info forFont: (NSFont *)aFont
 {
     if (metricsCache == nil)
         metricsCache = [[NSMutableDictionary alloc] init];
@@ -69,54 +99,57 @@ static NSMutableDictionary *metricsCache = nil;
 - initWithFont: (NSFont *)aFont
 {
     [super init];
-    font = [aFont retain];
-    textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
-    layoutManager = [[NSLayoutManager alloc] init];
-    [layoutManager addTextContainer: textContainer];
-    attributes = [[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil] retain];
+    attributes = [[NSMutableDictionary dictionaryWithObjectsAndKeys:aFont, NSFontAttributeName, nil] retain];
     return self;
 }
 
+
+- (NSLayoutManager *)layoutManagerForString: (NSString *)string
+{
+    KWQLayoutFragment *cachedValue;
+
+    if (fragmentCache == nil){
+        fragmentCache = [[NSMutableDictionary alloc] init];
+    }
+
+    cachedValue = [fragmentCache objectForKey: string];
+    if (cachedValue == nil){
+        return nil;
+    }
+
+    return cachedValue->layoutManager;
+}
+
+
 - (NSRect)rectForString:(NSString *)string
  {
-    NSValue *cachedValue;
+    KWQLayoutFragment *cachedFragment, *fragment;
     NSTextStorage *textStorage;
 
-    if (boundingRectCache == nil){
-        boundingRectCache = [[NSMutableDictionary alloc] init];
+    if (fragmentCache == nil){
+        fragmentCache = [[NSMutableDictionary alloc] init];
     }
 
-    cachedValue = [boundingRectCache objectForKey: string];
-    if (cachedValue != nil){
-        return [cachedValue rectValue];
-    }
-    
-    if (textContainer == nil){
-        textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
-        layoutManager = [[NSLayoutManager alloc] init];
-        [layoutManager addTextContainer: textContainer];
-        attributes = [[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil] retain];
+    cachedFragment = [fragmentCache objectForKey: string];
+    if (cachedFragment != nil){
+        return cachedFragment->boundingRect;
     }
 
-    textStorage = [[NSTextStorage alloc] initWithString:string attributes: attributes];
-    [textStorage addLayoutManager: layoutManager];
-    
-    unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
-    NSRect glyphRect = [layoutManager boundingRectForGlyphRange: NSMakeRange (0, numberOfGlyphs) inTextContainer: textContainer];
+    fragment = [[KWQLayoutFragment alloc] initWithString: string attributes: attributes];
+    [fragmentCache setObject: fragment forKey: string];        
 
-    [textStorage removeLayoutManager: layoutManager];
-    [textStorage release];
-    
-    [boundingRectCache setObject: [NSValue valueWithRect: glyphRect] forKey: string];
-        
-    return glyphRect;
+    return [fragment boundingRect];
 }
  
+- (void)setColor: (NSColor *)color
+{
+    [attributes setObject: color forKey: NSForegroundColorAttributeName];
+}
+
 - (void)dealloc
 {
-    [textContainer release];
-    [layoutManager release];
     [attributes release];
+    [super dealloc];
 }
 
 @end
@@ -128,7 +161,7 @@ public:
     QFontMetricsPrivate(NSFont *aFont) 
     {
         font = [aFont retain];
-        info = [[WSMetricsInfo getMetricsForFont: aFont] retain];
+        info = [[KWQMetricsInfo getMetricsForFont: aFont] retain];
     }
     
     ~QFontMetricsPrivate()
@@ -144,7 +177,7 @@ public:
     }
     
 private:
-    WSMetricsInfo *info;
+    KWQMetricsInfo *info;
     NSFont *font;
 };
 
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index e1c9c5c..c40f5cb 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -377,6 +377,11 @@ bool KHTMLPart::onlyLocalReferences() const
     return d->m_onlyLocalReferences;
 }
 
+#ifdef _KWQ_TIMING        
+    static long totalWriteTime = 0;
+#endif
+
+
 
 void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset)
 {
@@ -413,7 +418,7 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset)
     
     d->m_doc->open();    
 
-    _logNotYetImplemented();
+    totalWriteTime = 0;
 }
 
 
@@ -447,7 +452,6 @@ void KHTMLPart::write(const char *str, int len)
     */
 
     // begin lines added in lieu of big fixme    
-
     if ( !d->m_decoder ) {
         d->m_decoder = new khtml::Decoder();
         if(d->m_encoding != QString::null)
@@ -462,6 +466,8 @@ void KHTMLPart::write(const char *str, int len)
     if ( len == -1 )
         len = strlen( str );
     
+    long start = _GetMillisecondsSinceEpoch();
+    
     QString decoded = d->m_decoder->decode( str, len );
             
     if(decoded.isEmpty())
@@ -474,6 +480,12 @@ void KHTMLPart::write(const char *str, int len)
     Tokenizer* t = d->m_doc->tokenizer();
     if(t)
         t->write( decoded, true );
+
+#ifdef _KWQ_TIMING        
+    long thisTime = _GetMillisecondsSinceEpoch() - start;
+    totalWriteTime += thisTime;
+    KWQDEBUGLEVEL3 (0x200, "tokenize/parse length = %d, milliseconds = %d, total = %d\n", len, thisTime, totalWriteTime);
+#endif
 }
 
 
diff --git a/WebCore/kwq/KWQKHTMLPartImpl.mm b/WebCore/kwq/KWQKHTMLPartImpl.mm
index e1c9c5c..c40f5cb 100644
--- a/WebCore/kwq/KWQKHTMLPartImpl.mm
+++ b/WebCore/kwq/KWQKHTMLPartImpl.mm
@@ -377,6 +377,11 @@ bool KHTMLPart::onlyLocalReferences() const
     return d->m_onlyLocalReferences;
 }
 
+#ifdef _KWQ_TIMING        
+    static long totalWriteTime = 0;
+#endif
+
+
 
 void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset)
 {
@@ -413,7 +418,7 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset)
     
     d->m_doc->open();    
 
-    _logNotYetImplemented();
+    totalWriteTime = 0;
 }
 
 
@@ -447,7 +452,6 @@ void KHTMLPart::write(const char *str, int len)
     */
 
     // begin lines added in lieu of big fixme    
-
     if ( !d->m_decoder ) {
         d->m_decoder = new khtml::Decoder();
         if(d->m_encoding != QString::null)
@@ -462,6 +466,8 @@ void KHTMLPart::write(const char *str, int len)
     if ( len == -1 )
         len = strlen( str );
     
+    long start = _GetMillisecondsSinceEpoch();
+    
     QString decoded = d->m_decoder->decode( str, len );
             
     if(decoded.isEmpty())
@@ -474,6 +480,12 @@ void KHTMLPart::write(const char *str, int len)
     Tokenizer* t = d->m_doc->tokenizer();
     if(t)
         t->write( decoded, true );
+
+#ifdef _KWQ_TIMING        
+    long thisTime = _GetMillisecondsSinceEpoch() - start;
+    totalWriteTime += thisTime;
+    KWQDEBUGLEVEL3 (0x200, "tokenize/parse length = %d, milliseconds = %d, total = %d\n", len, thisTime, totalWriteTime);
+#endif
 }
 
 
diff --git a/WebCore/kwq/KWQTextArea.h b/WebCore/kwq/KWQMetrics.h
similarity index 64%
copy from WebCore/kwq/KWQTextArea.h
copy to WebCore/kwq/KWQMetrics.h
index 0d32f84..2bc3066 100644
--- a/WebCore/kwq/KWQTextArea.h
+++ b/WebCore/kwq/KWQMetrics.h
@@ -22,43 +22,38 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
- 
-#import <Cocoa/Cocoa.h>
-
-
-class QWidget;
+#ifndef KWQMETRICS_H_
+#define KWQMETRICS_H_
 
+#import <Cocoa/Cocoa.h>
 
- at interface KWQTextArea : NSScrollView
+ at interface KWQMetricsInfo : NSObject
 {
-    NSTextView *textView;
-    QWidget *widget;
-    BOOL wrap;
+    NSMutableDictionary *attributes;
+    NSMutableDictionary *fragmentCache;
 }
-- initWithFrame: (NSRect)r widget: (QWidget *)w; 
-
-// The following methods corresponds to methods required by KDE.
-- (void) setWordWrap: (BOOL)f;
-
-- (BOOL) wordWrap;
-
-- (BOOL) isReadOnly;
-
-- (void) setReadOnly: (BOOL)flag;
-
-- (void) setText: (NSString *)s;
 
-- (NSString *)text;
-
-- (NSString *)textForLine: (int)line;
-
-- (int) numLines;
-
-- (void) selectAll;
-
-- (void) setEditable: (BOOL)flag;
++ (KWQMetricsInfo *)getMetricsForFont: (NSFont *)aFont;
++ (void)setMetric: (KWQMetricsInfo *)info forFont: (NSFont *)aFont;
+- initWithFont: (NSFont *)aFont;
+- (NSRect)rectForString:(NSString *)string;
+- (NSLayoutManager *)layoutManagerForString: (NSString *)string;
+- (void)setColor: (NSColor *)color;
+ at end
 
-- (BOOL)isEditable;
+ at interface KWQLayoutFragment : NSObject
+{
+    NSTextStorage *textStorage;
+    NSTextContainer *textContainer;
+    NSLayoutManager *layoutManager;
+    NSRect boundingRect;
+    BOOL cachedRect;
+}
 
+- initWithString: (NSString *)storage attributes: (NSDictionary *)attrs;
+- (NSRect)boundingRect;
+- (void)dealloc;
 
 @end
+
+#endif
diff --git a/WebCore/kwq/KWQPainter.mm b/WebCore/kwq/KWQPainter.mm
index 0ce8086..a020c26 100644
--- a/WebCore/kwq/KWQPainter.mm
+++ b/WebCore/kwq/KWQPainter.mm
@@ -34,6 +34,9 @@
 
 #import <Cocoa/Cocoa.h>
 
+#import <KWQMetrics.h>
+
+
 struct QPainterPrivate {
 friend class QPainter;
 public:
@@ -453,6 +456,10 @@ void QPainter::drawTiledPixmap( int x, int y, int w, int h,
     drawTile( this, x, y, w, h, pixmap, sx, sy );
 }
 
+ at interface NSLayoutManager (Private)
+- (char *)_packedGlyphs:(NSMultibyteGlyphPacking)packing range:(NSRange)glyphRange length:(unsigned *)len;
+ at end
+
 
 // y is the baseline
 void QPainter::drawText(int x, int y, const QString &qstring, int len)
@@ -474,7 +481,33 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
     // This will draw the text from the top of the bounding box down.
     // Qt expects to draw from the baseline.
     y = y - (int)([font defaultLineHeightForFont] + [font descender]);
-    [string drawAtPoint:NSMakePoint(x, y) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, data->qpen.color().color, NSForegroundColorAttributeName, nil]];
+    //[string drawAtPoint:NSMakePoint(x, y) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, data->qpen.color().color, NSForegroundColorAttributeName, nil]];
+
+    KWQMetricsInfo *metricsCache = [KWQMetricsInfo getMetricsForFont: font];
+    NSLayoutManager *layoutManager = [metricsCache layoutManagerForString: string];
+    if (layoutManager != nil){
+        unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
+        [metricsCache setColor: data->qpen.color().color];
+        [layoutManager drawGlyphsForGlyphRange:NSMakeRange (0, numberOfGlyphs) atPoint:NSMakePoint(x, y)];
+
+/*
+        [font set];
+        [data->qpen.color().color set];
+        
+        unsigned glyphLen;
+        char *glyphBuf;
+
+        NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
+        BOOL flag = [graphicsContext shouldAntialias];
+        [graphicsContext setShouldAntialias: NO];
+        
+        glyphBuf = [layoutManager _packedGlyphs:[font glyphPacking] range:NSMakeRange (0, numberOfGlyphs) length:&glyphLen];
+        [layoutManager showPackedGlyphs:glyphBuf length:glyphLen glyphRange:NSMakeRange (0, numberOfGlyphs)  atPoint:NSMakePoint(x, y) font:font color:data->qpen.color().color printingAdjustment:NSMakeSize(0.0, 0.0)];
+
+        [graphicsContext setShouldAntialias: flag];
+*/
+    }
+
 
     _unlockFocus();
 }
diff --git a/WebCore/kwq/KWQKWin.mm b/WebCore/kwq/KWQTextContainer.h
similarity index 93%
copy from WebCore/kwq/KWQKWin.mm
copy to WebCore/kwq/KWQTextContainer.h
index 15e3eef..84693c5 100644
--- a/WebCore/kwq/KWQKWin.mm
+++ b/WebCore/kwq/KWQTextContainer.h
@@ -23,11 +23,12 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#include <kwin.h>
-
 #include <kwqdebug.h>
 
-KWin::Info KWin::info(int win)
+
+ at interface KWQTextContainer : NSTextContainer
 {
-    _logNotYetImplemented();
 }
++ (KWQTextContainer *)sharedInstance;
+
+ at end
diff --git a/WebCore/kwq/KWQTextContainer.mm b/WebCore/kwq/KWQTextContainer.mm
new file mode 100644
index 0000000..dbdd824
--- /dev/null
+++ b/WebCore/kwq/KWQTextContainer.mm
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2001 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#include <kwqdebug.h>
+
+#import <KWQTextContainer.h>
+
+ at implementation KWQTextContainer
+
+const float LargeNumberForText = 1.0e7;
+
+static KWQTextContainer *sharedInstance = nil;
+
++ (KWQTextContainer *)sharedInstance
+{
+    if (sharedInstance == nil)
+        sharedInstance = [[KWQTextContainer alloc] initWithContainerSize: NSMakeSize(0,0)];
+    return sharedInstance;
+}
+
+
+- (id)initWithContainerSize:(NSSize)aSize
+{
+    [super initWithContainerSize:aSize];
+    return self;
+}
+
+- (void)replaceLayoutManager:(NSLayoutManager *)aLayoutManager
+{
+    [NSException raise:@"NOT IMPLEMENTED" format:@"- (void)replaceLayoutManager:(NSLayoutManager *)aLayoutManager"];
+}
+
+- (BOOL)isSimpleRectangularTextContainer
+{
+    return YES;
+}
+
+- (BOOL)containsPoint:(NSPoint)aPoint
+{
+    return YES;
+}
+
+
+- (NSSize)containerSize
+{
+    return NSMakeSize(LargeNumberForText, LargeNumberForText);
+}
+
+
+- (void)setContainerSize:(NSSize)aSize
+{
+    KWQDEBUG ("not implemented\n");
+}
+
+- (void)setHeightTracksTextView:(BOOL)flag
+{
+    KWQDEBUG ("not implemented\n");
+}
+
+- (BOOL)heightTracksTextView
+{
+    KWQDEBUG ("not implemented\n");
+    return NO;
+}
+
+- (void)setWidthTracksTextView:(BOOL)flag
+{
+    KWQDEBUG ("not implemented\n");
+}
+
+- (BOOL)widthTracksTextView
+{
+    KWQDEBUG ("not implemented\n");
+    return NO;
+}
+
+- (void)setLayoutManager:(NSLayoutManager *)aLayoutManager
+{
+}
+
+
+- (NSLayoutManager *)layoutManager
+{
+    [NSException raise:@"NOT IMPLEMENTED" format:@"- (NSLayoutManager *)layoutManager"];
+    return nil;
+}
+
+
+- (void)setLineFragmentPadding:(float)aFloat
+{
+}
+
+
+- (float)lineFragmentPadding
+{
+    return 0.0f;
+}
+
+
+- (void)setTextView:(NSTextView *)aTextView
+{
+}
+
+- (NSTextView *)textView
+{
+    return nil;
+}
+
+- (NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect sweepDirection:(NSLineSweepDirection)sweepDirection movementDirection:(NSLineMovementDirection)movementDirection remainingRect:(NSRect *)remainingRect
+{
+    return proposedRect;
+}
+
+ at end
+
diff --git a/WebCore/kwq/KWQPaintDevice.mm b/WebCore/kwq/KWQTextStorage.h
similarity index 90%
copy from WebCore/kwq/KWQPaintDevice.mm
copy to WebCore/kwq/KWQTextStorage.h
index 925ffbc..573a68b 100644
--- a/WebCore/kwq/KWQPaintDevice.mm
+++ b/WebCore/kwq/KWQTextStorage.h
@@ -22,15 +22,15 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
-#include <qpaintdevice.h>
-#include <kwqdebug.h>
 
-#include <Cocoa/Cocoa.h>
+#include <kwqdebug.h>
 
 
-QPaintDevice::~QPaintDevice()
+ at interface KWQTextStorage : NSTextStorage
 {
-    // This space intentionally left blank.
+    NSString *attrString;
+    NSDictionary *attributes;
+    NSLayoutManager *_layoutManager;
 }
 
-
+ at end
diff --git a/WebCore/kwq/KWQTextStorage.mm b/WebCore/kwq/KWQTextStorage.mm
new file mode 100644
index 0000000..440f257
--- /dev/null
+++ b/WebCore/kwq/KWQTextStorage.mm
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2001 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import <Cocoa/Cocoa.h> 
+
+#include <kwqdebug.h>
+
+#import <KWQTextStorage.h>
+
+ at implementation KWQTextStorage
+
+- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attrs 
+{
+    attrString = [str retain];
+    attributes = [attrs retain];
+    return self;
+}
+
+- (void)dealloc 
+{
+    [attributes release];
+    [attrString release];
+    [super dealloc];
+}
+
+- (void)addLayoutManager:(id)obj {
+    _layoutManager = [obj retain];
+    [obj setTextStorage:self];
+}
+
+- (void)removeLayoutManager:(id)obj {
+    if (obj == _layoutManager){
+        [obj setTextStorage:nil];
+        [obj autorelease];
+    }
+}
+
+- (NSArray *)layoutManagers {
+    return [NSArray arrayWithObjects: _layoutManager, nil];
+}
+
+- (void)edited:(unsigned)mask range:(NSRange)oldRange changeInLength:(int)lengthChange
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (void)ensureAttributesAreFixedInRange:(NSRange)range
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (void)invalidateAttributesInRange:(NSRange)range
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (unsigned)length 
+{
+    return [attrString length];
+}
+
+- (NSString *)string 
+{
+    return attrString;
+}
+
+- (NSDictionary *)attributesAtIndex:(unsigned)location effectiveRange:(NSRangePointer)range 
+{
+    range->location = 0;
+    range->length = [self length];
+    return attributes;
+}
+
+- (NSDictionary *)attributesAtIndex:(unsigned)location longestEffectiveRange:(NSRangePointer)range inRange:(NSRange)rangeLimit
+{
+    range->location = rangeLimit.location;
+    range->length = rangeLimit.length;
+    return attributes;
+}
+
+- (id)attribute:(NSString *)attrName atIndex:(unsigned)location effectiveRange:(NSRangePointer)range 
+{
+    range->location = 0;
+    range->length = [self length];
+    return [attributes objectForKey: attrName];
+}
+
+- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range 
+{
+    KWQDEBUG ("not implemented");
+}
+
+
+- (void)replaceCharactersInRange:(NSRange)range withAttributedString:(NSAttributedString *)str 
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (void)addAttribute:(NSString *)name value:value range:(NSRange)range
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (NSAttributedString *)attributedSubstringFromRange:(NSRange)aRange
+{
+    KWQDEBUG ("not implemented");
+    return nil;
+}
+
+ at end
+
diff --git a/WebCore/kwq/KWQView.mm b/WebCore/kwq/KWQView.mm
index 0758745..f3ce72d 100644
--- a/WebCore/kwq/KWQView.mm
+++ b/WebCore/kwq/KWQView.mm
@@ -31,6 +31,8 @@
 #include <qpainter.h>
 #include <html/html_documentimpl.h>
 
+
+
 @implementation KWQView
 
 - initWithFrame: (NSRect) r widget: (QWidget *)w 
@@ -105,7 +107,6 @@
     return self;
 }
 
-#define DELAY_LAYOUT
 #ifdef DELAY_LAYOUT
 - delayLayout: sender
 {
@@ -137,7 +138,9 @@
     if (((KHTMLView *)widget)->part()->xmlDocImpl() && 
         ((KHTMLView *)widget)->part()->xmlDocImpl()->renderer()){
         if (needsLayout){
+            long start = _GetMillisecondsSinceEpoch();
             ((KHTMLView *)widget)->layout(TRUE);
+            KWQDEBUGLEVEL1 (0x200, "layout time %d\n", _GetMillisecondsSinceEpoch() - start);
             needsLayout = NO;
         }
     }
@@ -159,10 +162,13 @@
         QPainter p(widget);    
         
         [self lockFocus];
+
+        long start = _GetMillisecondsSinceEpoch();
         ((KHTMLView *)widget)->drawContents( &p, (int)rect.origin.x, 
                     (int)rect.origin.y, 
                     (int)rect.size.width, 
                     (int)rect.size.height );
+        KWQDEBUGLEVEL1 (0x200, "draw time %d\n", _GetMillisecondsSinceEpoch() - start);
         [self unlockFocus];
     }
 }
diff --git a/WebCore/kwq/Makefile.in b/WebCore/kwq/Makefile.in
index 559e17f..7dd28e3 100644
--- a/WebCore/kwq/Makefile.in
+++ b/WebCore/kwq/Makefile.in
@@ -109,7 +109,9 @@ MMOBJECTS = \
     KWQString.o \
     KWQStyle.o \
     KWQTextArea.o \
+    KWQTextContainer.o \
     KWQTextEdit.o \
+    KWQTextStorage.o \
     KWQTimer.o \
     KWQToolTip.o \
     KWQVariant.o \
diff --git a/WebCore/kwq/kwqdebug.h b/WebCore/kwq/kwqdebug.h
index 9d9ae5e..21b3f38 100644
--- a/WebCore/kwq/kwqdebug.h
+++ b/WebCore/kwq/kwqdebug.h
@@ -34,6 +34,11 @@
 #undef Rect
 #undef Boolean
 
+/*
+*/
+#define _KWQ_TIMING 1
+long _GetMillisecondsSinceEpoch();
+
 /*-----------------------------------------------------------------------------
  * Logging macros
  */
diff --git a/WebCore/kwq/kwqdebug.mm b/WebCore/kwq/kwqdebug.mm
index 6c4073a..1c77f4c 100644
--- a/WebCore/kwq/kwqdebug.mm
+++ b/WebCore/kwq/kwqdebug.mm
@@ -25,6 +25,35 @@
 
 #include <kwqdebug.h>
 
+
+#if defined(__MACH__)
+#include <stdlib.h>
+#include <sys/time.h>
+#endif
+#if defined(__WIN32__)
+#import <sys/utime.h>
+#endif
+
+
+long _GetMillisecondsSinceEpoch() {
+    long result;
+    struct timeval tp;
+    struct timezone tzp;
+
+    result = 0;
+    tzp.tz_minuteswest = 0;
+    tzp.tz_dsttime = 0;
+
+    // FIXME: need to ifdef for Win32 at some point, 
+    // or use something from Foundation
+    if (gettimeofday(&tp, &tzp) == 0) {
+        result = (tp.tv_sec * 1000) + (tp.tv_usec / 1000);    
+    }
+  
+    return result;   
+}
+
+
 unsigned int KWQ_LOG_LEVEL = KWQ_LOG_ALL;
 
 
diff --git a/WebCore/src/kwq/KWQFontMetrics.mm b/WebCore/src/kwq/KWQFontMetrics.mm
index d500c65..15d8ba7 100644
--- a/WebCore/src/kwq/KWQFontMetrics.mm
+++ b/WebCore/src/kwq/KWQFontMetrics.mm
@@ -27,39 +27,69 @@
 #include <kwqdebug.h>
 #include <qfontmetrics.h>
 
+#import <Cocoa/Cocoa.h>
+#import <KWQMetrics.h>
+#import <KWQTextStorage.h>
+#import <KWQTextContainer.h>
+
+
 #define ROUND_TO_INT(f) ((int)rint((f)))
 const float LargeNumberForText = 1.0e7;
 
- at interface WSMetricsInfo : NSObject
+
+ at implementation KWQLayoutFragment
+- initWithString: (NSString *)str attributes: (NSDictionary *)attrs
 {
-    NSFont *font;
-    NSTextContainer *textContainer;
-    NSLayoutManager *layoutManager;
-    NSDictionary *attributes;
-    NSMutableDictionary *boundingRectCache;
+    [super init];
+
+    textStorage = [[KWQTextStorage alloc] initWithString:str attributes: attrs];
+    //textContainer = [[KWQTextContainer alloc] initWithContainerSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
+    layoutManager = [[NSLayoutManager alloc] init];
+
+    [layoutManager addTextContainer: [KWQTextContainer sharedInstance]];
+    [textStorage addLayoutManager: layoutManager];    
+
+    //[textContainer setLineFragmentPadding:0.0f];
+
+    cachedRect = NO;
+    
+    return self;
 }
 
-+ (WSMetricsInfo *)getMetricsForFont: (NSFont *)aFont;
-+ (void)setMetric: (WSMetricsInfo *)info forFont: (NSFont *)aFont;
-- initWithFont: (NSFont *)aFont;
-- (NSRect)rectForString:(NSString *)string;
+- (NSRect)boundingRect
+{
+    if (!cachedRect){
+        unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
+        boundingRect = [layoutManager boundingRectForGlyphRange: NSMakeRange (0, numberOfGlyphs) inTextContainer: [KWQTextContainer sharedInstance]];
+        cachedRect = YES;
+    }
+    return boundingRect;
+}
 
+- (void)dealloc
+{
+    [textStorage release];
+    //[textContainer release];
+    [layoutManager release];
+    [super dealloc];
+}
 @end
 
+
 static NSMutableDictionary *metricsCache = nil;
 
- at implementation WSMetricsInfo
-+ (WSMetricsInfo *)getMetricsForFont: (NSFont *)aFont
+ at implementation KWQMetricsInfo
++ (KWQMetricsInfo *)getMetricsForFont: (NSFont *)aFont
 {
-    WSMetricsInfo *info = (WSMetricsInfo *)[metricsCache objectForKey: aFont];
+    KWQMetricsInfo *info = (KWQMetricsInfo *)[metricsCache objectForKey: aFont];
     if (info == nil){
-        info = [[WSMetricsInfo alloc] initWithFont: aFont];
-        [WSMetricsInfo setMetric: info forFont: aFont];
+        info = [[KWQMetricsInfo alloc] initWithFont: aFont];
+        [KWQMetricsInfo setMetric: info forFont: aFont];
         [info release];
     }
     return info;
 }
-+ (void)setMetric: (WSMetricsInfo *)info forFont: (NSFont *)aFont
++ (void)setMetric: (KWQMetricsInfo *)info forFont: (NSFont *)aFont
 {
     if (metricsCache == nil)
         metricsCache = [[NSMutableDictionary alloc] init];
@@ -69,54 +99,57 @@ static NSMutableDictionary *metricsCache = nil;
 - initWithFont: (NSFont *)aFont
 {
     [super init];
-    font = [aFont retain];
-    textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
-    layoutManager = [[NSLayoutManager alloc] init];
-    [layoutManager addTextContainer: textContainer];
-    attributes = [[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil] retain];
+    attributes = [[NSMutableDictionary dictionaryWithObjectsAndKeys:aFont, NSFontAttributeName, nil] retain];
     return self;
 }
 
+
+- (NSLayoutManager *)layoutManagerForString: (NSString *)string
+{
+    KWQLayoutFragment *cachedValue;
+
+    if (fragmentCache == nil){
+        fragmentCache = [[NSMutableDictionary alloc] init];
+    }
+
+    cachedValue = [fragmentCache objectForKey: string];
+    if (cachedValue == nil){
+        return nil;
+    }
+
+    return cachedValue->layoutManager;
+}
+
+
 - (NSRect)rectForString:(NSString *)string
  {
-    NSValue *cachedValue;
+    KWQLayoutFragment *cachedFragment, *fragment;
     NSTextStorage *textStorage;
 
-    if (boundingRectCache == nil){
-        boundingRectCache = [[NSMutableDictionary alloc] init];
+    if (fragmentCache == nil){
+        fragmentCache = [[NSMutableDictionary alloc] init];
     }
 
-    cachedValue = [boundingRectCache objectForKey: string];
-    if (cachedValue != nil){
-        return [cachedValue rectValue];
-    }
-    
-    if (textContainer == nil){
-        textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
-        layoutManager = [[NSLayoutManager alloc] init];
-        [layoutManager addTextContainer: textContainer];
-        attributes = [[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil] retain];
+    cachedFragment = [fragmentCache objectForKey: string];
+    if (cachedFragment != nil){
+        return cachedFragment->boundingRect;
     }
 
-    textStorage = [[NSTextStorage alloc] initWithString:string attributes: attributes];
-    [textStorage addLayoutManager: layoutManager];
-    
-    unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
-    NSRect glyphRect = [layoutManager boundingRectForGlyphRange: NSMakeRange (0, numberOfGlyphs) inTextContainer: textContainer];
+    fragment = [[KWQLayoutFragment alloc] initWithString: string attributes: attributes];
+    [fragmentCache setObject: fragment forKey: string];        
 
-    [textStorage removeLayoutManager: layoutManager];
-    [textStorage release];
-    
-    [boundingRectCache setObject: [NSValue valueWithRect: glyphRect] forKey: string];
-        
-    return glyphRect;
+    return [fragment boundingRect];
 }
  
+- (void)setColor: (NSColor *)color
+{
+    [attributes setObject: color forKey: NSForegroundColorAttributeName];
+}
+
 - (void)dealloc
 {
-    [textContainer release];
-    [layoutManager release];
     [attributes release];
+    [super dealloc];
 }
 
 @end
@@ -128,7 +161,7 @@ public:
     QFontMetricsPrivate(NSFont *aFont) 
     {
         font = [aFont retain];
-        info = [[WSMetricsInfo getMetricsForFont: aFont] retain];
+        info = [[KWQMetricsInfo getMetricsForFont: aFont] retain];
     }
     
     ~QFontMetricsPrivate()
@@ -144,7 +177,7 @@ public:
     }
     
 private:
-    WSMetricsInfo *info;
+    KWQMetricsInfo *info;
     NSFont *font;
 };
 
diff --git a/WebCore/src/kwq/KWQKHTMLPart.mm b/WebCore/src/kwq/KWQKHTMLPart.mm
index e1c9c5c..c40f5cb 100644
--- a/WebCore/src/kwq/KWQKHTMLPart.mm
+++ b/WebCore/src/kwq/KWQKHTMLPart.mm
@@ -377,6 +377,11 @@ bool KHTMLPart::onlyLocalReferences() const
     return d->m_onlyLocalReferences;
 }
 
+#ifdef _KWQ_TIMING        
+    static long totalWriteTime = 0;
+#endif
+
+
 
 void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset)
 {
@@ -413,7 +418,7 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset)
     
     d->m_doc->open();    
 
-    _logNotYetImplemented();
+    totalWriteTime = 0;
 }
 
 
@@ -447,7 +452,6 @@ void KHTMLPart::write(const char *str, int len)
     */
 
     // begin lines added in lieu of big fixme    
-
     if ( !d->m_decoder ) {
         d->m_decoder = new khtml::Decoder();
         if(d->m_encoding != QString::null)
@@ -462,6 +466,8 @@ void KHTMLPart::write(const char *str, int len)
     if ( len == -1 )
         len = strlen( str );
     
+    long start = _GetMillisecondsSinceEpoch();
+    
     QString decoded = d->m_decoder->decode( str, len );
             
     if(decoded.isEmpty())
@@ -474,6 +480,12 @@ void KHTMLPart::write(const char *str, int len)
     Tokenizer* t = d->m_doc->tokenizer();
     if(t)
         t->write( decoded, true );
+
+#ifdef _KWQ_TIMING        
+    long thisTime = _GetMillisecondsSinceEpoch() - start;
+    totalWriteTime += thisTime;
+    KWQDEBUGLEVEL3 (0x200, "tokenize/parse length = %d, milliseconds = %d, total = %d\n", len, thisTime, totalWriteTime);
+#endif
 }
 
 
diff --git a/WebCore/kwq/KWQTextArea.h b/WebCore/src/kwq/KWQMetrics.h
similarity index 64%
copy from WebCore/kwq/KWQTextArea.h
copy to WebCore/src/kwq/KWQMetrics.h
index 0d32f84..2bc3066 100644
--- a/WebCore/kwq/KWQTextArea.h
+++ b/WebCore/src/kwq/KWQMetrics.h
@@ -22,43 +22,38 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
- 
-#import <Cocoa/Cocoa.h>
-
-
-class QWidget;
+#ifndef KWQMETRICS_H_
+#define KWQMETRICS_H_
 
+#import <Cocoa/Cocoa.h>
 
- at interface KWQTextArea : NSScrollView
+ at interface KWQMetricsInfo : NSObject
 {
-    NSTextView *textView;
-    QWidget *widget;
-    BOOL wrap;
+    NSMutableDictionary *attributes;
+    NSMutableDictionary *fragmentCache;
 }
-- initWithFrame: (NSRect)r widget: (QWidget *)w; 
-
-// The following methods corresponds to methods required by KDE.
-- (void) setWordWrap: (BOOL)f;
-
-- (BOOL) wordWrap;
-
-- (BOOL) isReadOnly;
-
-- (void) setReadOnly: (BOOL)flag;
-
-- (void) setText: (NSString *)s;
 
-- (NSString *)text;
-
-- (NSString *)textForLine: (int)line;
-
-- (int) numLines;
-
-- (void) selectAll;
-
-- (void) setEditable: (BOOL)flag;
++ (KWQMetricsInfo *)getMetricsForFont: (NSFont *)aFont;
++ (void)setMetric: (KWQMetricsInfo *)info forFont: (NSFont *)aFont;
+- initWithFont: (NSFont *)aFont;
+- (NSRect)rectForString:(NSString *)string;
+- (NSLayoutManager *)layoutManagerForString: (NSString *)string;
+- (void)setColor: (NSColor *)color;
+ at end
 
-- (BOOL)isEditable;
+ at interface KWQLayoutFragment : NSObject
+{
+    NSTextStorage *textStorage;
+    NSTextContainer *textContainer;
+    NSLayoutManager *layoutManager;
+    NSRect boundingRect;
+    BOOL cachedRect;
+}
 
+- initWithString: (NSString *)storage attributes: (NSDictionary *)attrs;
+- (NSRect)boundingRect;
+- (void)dealloc;
 
 @end
+
+#endif
diff --git a/WebCore/src/kwq/KWQPainter.mm b/WebCore/src/kwq/KWQPainter.mm
index 0ce8086..a020c26 100644
--- a/WebCore/src/kwq/KWQPainter.mm
+++ b/WebCore/src/kwq/KWQPainter.mm
@@ -34,6 +34,9 @@
 
 #import <Cocoa/Cocoa.h>
 
+#import <KWQMetrics.h>
+
+
 struct QPainterPrivate {
 friend class QPainter;
 public:
@@ -453,6 +456,10 @@ void QPainter::drawTiledPixmap( int x, int y, int w, int h,
     drawTile( this, x, y, w, h, pixmap, sx, sy );
 }
 
+ at interface NSLayoutManager (Private)
+- (char *)_packedGlyphs:(NSMultibyteGlyphPacking)packing range:(NSRange)glyphRange length:(unsigned *)len;
+ at end
+
 
 // y is the baseline
 void QPainter::drawText(int x, int y, const QString &qstring, int len)
@@ -474,7 +481,33 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
     // This will draw the text from the top of the bounding box down.
     // Qt expects to draw from the baseline.
     y = y - (int)([font defaultLineHeightForFont] + [font descender]);
-    [string drawAtPoint:NSMakePoint(x, y) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, data->qpen.color().color, NSForegroundColorAttributeName, nil]];
+    //[string drawAtPoint:NSMakePoint(x, y) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, data->qpen.color().color, NSForegroundColorAttributeName, nil]];
+
+    KWQMetricsInfo *metricsCache = [KWQMetricsInfo getMetricsForFont: font];
+    NSLayoutManager *layoutManager = [metricsCache layoutManagerForString: string];
+    if (layoutManager != nil){
+        unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
+        [metricsCache setColor: data->qpen.color().color];
+        [layoutManager drawGlyphsForGlyphRange:NSMakeRange (0, numberOfGlyphs) atPoint:NSMakePoint(x, y)];
+
+/*
+        [font set];
+        [data->qpen.color().color set];
+        
+        unsigned glyphLen;
+        char *glyphBuf;
+
+        NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
+        BOOL flag = [graphicsContext shouldAntialias];
+        [graphicsContext setShouldAntialias: NO];
+        
+        glyphBuf = [layoutManager _packedGlyphs:[font glyphPacking] range:NSMakeRange (0, numberOfGlyphs) length:&glyphLen];
+        [layoutManager showPackedGlyphs:glyphBuf length:glyphLen glyphRange:NSMakeRange (0, numberOfGlyphs)  atPoint:NSMakePoint(x, y) font:font color:data->qpen.color().color printingAdjustment:NSMakeSize(0.0, 0.0)];
+
+        [graphicsContext setShouldAntialias: flag];
+*/
+    }
+
 
     _unlockFocus();
 }
diff --git a/WebCore/kwq/KWQKWin.mm b/WebCore/src/kwq/KWQTextContainer.h
similarity index 93%
copy from WebCore/kwq/KWQKWin.mm
copy to WebCore/src/kwq/KWQTextContainer.h
index 15e3eef..84693c5 100644
--- a/WebCore/kwq/KWQKWin.mm
+++ b/WebCore/src/kwq/KWQTextContainer.h
@@ -23,11 +23,12 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#include <kwin.h>
-
 #include <kwqdebug.h>
 
-KWin::Info KWin::info(int win)
+
+ at interface KWQTextContainer : NSTextContainer
 {
-    _logNotYetImplemented();
 }
++ (KWQTextContainer *)sharedInstance;
+
+ at end
diff --git a/WebCore/src/kwq/KWQTextContainer.mm b/WebCore/src/kwq/KWQTextContainer.mm
new file mode 100644
index 0000000..dbdd824
--- /dev/null
+++ b/WebCore/src/kwq/KWQTextContainer.mm
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2001 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#include <kwqdebug.h>
+
+#import <KWQTextContainer.h>
+
+ at implementation KWQTextContainer
+
+const float LargeNumberForText = 1.0e7;
+
+static KWQTextContainer *sharedInstance = nil;
+
++ (KWQTextContainer *)sharedInstance
+{
+    if (sharedInstance == nil)
+        sharedInstance = [[KWQTextContainer alloc] initWithContainerSize: NSMakeSize(0,0)];
+    return sharedInstance;
+}
+
+
+- (id)initWithContainerSize:(NSSize)aSize
+{
+    [super initWithContainerSize:aSize];
+    return self;
+}
+
+- (void)replaceLayoutManager:(NSLayoutManager *)aLayoutManager
+{
+    [NSException raise:@"NOT IMPLEMENTED" format:@"- (void)replaceLayoutManager:(NSLayoutManager *)aLayoutManager"];
+}
+
+- (BOOL)isSimpleRectangularTextContainer
+{
+    return YES;
+}
+
+- (BOOL)containsPoint:(NSPoint)aPoint
+{
+    return YES;
+}
+
+
+- (NSSize)containerSize
+{
+    return NSMakeSize(LargeNumberForText, LargeNumberForText);
+}
+
+
+- (void)setContainerSize:(NSSize)aSize
+{
+    KWQDEBUG ("not implemented\n");
+}
+
+- (void)setHeightTracksTextView:(BOOL)flag
+{
+    KWQDEBUG ("not implemented\n");
+}
+
+- (BOOL)heightTracksTextView
+{
+    KWQDEBUG ("not implemented\n");
+    return NO;
+}
+
+- (void)setWidthTracksTextView:(BOOL)flag
+{
+    KWQDEBUG ("not implemented\n");
+}
+
+- (BOOL)widthTracksTextView
+{
+    KWQDEBUG ("not implemented\n");
+    return NO;
+}
+
+- (void)setLayoutManager:(NSLayoutManager *)aLayoutManager
+{
+}
+
+
+- (NSLayoutManager *)layoutManager
+{
+    [NSException raise:@"NOT IMPLEMENTED" format:@"- (NSLayoutManager *)layoutManager"];
+    return nil;
+}
+
+
+- (void)setLineFragmentPadding:(float)aFloat
+{
+}
+
+
+- (float)lineFragmentPadding
+{
+    return 0.0f;
+}
+
+
+- (void)setTextView:(NSTextView *)aTextView
+{
+}
+
+- (NSTextView *)textView
+{
+    return nil;
+}
+
+- (NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect sweepDirection:(NSLineSweepDirection)sweepDirection movementDirection:(NSLineMovementDirection)movementDirection remainingRect:(NSRect *)remainingRect
+{
+    return proposedRect;
+}
+
+ at end
+
diff --git a/WebCore/kwq/KWQPaintDevice.mm b/WebCore/src/kwq/KWQTextStorage.h
similarity index 90%
copy from WebCore/kwq/KWQPaintDevice.mm
copy to WebCore/src/kwq/KWQTextStorage.h
index 925ffbc..573a68b 100644
--- a/WebCore/kwq/KWQPaintDevice.mm
+++ b/WebCore/src/kwq/KWQTextStorage.h
@@ -22,15 +22,15 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
-#include <qpaintdevice.h>
-#include <kwqdebug.h>
 
-#include <Cocoa/Cocoa.h>
+#include <kwqdebug.h>
 
 
-QPaintDevice::~QPaintDevice()
+ at interface KWQTextStorage : NSTextStorage
 {
-    // This space intentionally left blank.
+    NSString *attrString;
+    NSDictionary *attributes;
+    NSLayoutManager *_layoutManager;
 }
 
-
+ at end
diff --git a/WebCore/src/kwq/KWQTextStorage.mm b/WebCore/src/kwq/KWQTextStorage.mm
new file mode 100644
index 0000000..440f257
--- /dev/null
+++ b/WebCore/src/kwq/KWQTextStorage.mm
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2001 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import <Cocoa/Cocoa.h> 
+
+#include <kwqdebug.h>
+
+#import <KWQTextStorage.h>
+
+ at implementation KWQTextStorage
+
+- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attrs 
+{
+    attrString = [str retain];
+    attributes = [attrs retain];
+    return self;
+}
+
+- (void)dealloc 
+{
+    [attributes release];
+    [attrString release];
+    [super dealloc];
+}
+
+- (void)addLayoutManager:(id)obj {
+    _layoutManager = [obj retain];
+    [obj setTextStorage:self];
+}
+
+- (void)removeLayoutManager:(id)obj {
+    if (obj == _layoutManager){
+        [obj setTextStorage:nil];
+        [obj autorelease];
+    }
+}
+
+- (NSArray *)layoutManagers {
+    return [NSArray arrayWithObjects: _layoutManager, nil];
+}
+
+- (void)edited:(unsigned)mask range:(NSRange)oldRange changeInLength:(int)lengthChange
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (void)ensureAttributesAreFixedInRange:(NSRange)range
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (void)invalidateAttributesInRange:(NSRange)range
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (unsigned)length 
+{
+    return [attrString length];
+}
+
+- (NSString *)string 
+{
+    return attrString;
+}
+
+- (NSDictionary *)attributesAtIndex:(unsigned)location effectiveRange:(NSRangePointer)range 
+{
+    range->location = 0;
+    range->length = [self length];
+    return attributes;
+}
+
+- (NSDictionary *)attributesAtIndex:(unsigned)location longestEffectiveRange:(NSRangePointer)range inRange:(NSRange)rangeLimit
+{
+    range->location = rangeLimit.location;
+    range->length = rangeLimit.length;
+    return attributes;
+}
+
+- (id)attribute:(NSString *)attrName atIndex:(unsigned)location effectiveRange:(NSRangePointer)range 
+{
+    range->location = 0;
+    range->length = [self length];
+    return [attributes objectForKey: attrName];
+}
+
+- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range 
+{
+    KWQDEBUG ("not implemented");
+}
+
+
+- (void)replaceCharactersInRange:(NSRange)range withAttributedString:(NSAttributedString *)str 
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (void)addAttribute:(NSString *)name value:value range:(NSRange)range
+{
+    KWQDEBUG ("not implemented");
+}
+
+- (NSAttributedString *)attributedSubstringFromRange:(NSRange)aRange
+{
+    KWQDEBUG ("not implemented");
+    return nil;
+}
+
+ at end
+
diff --git a/WebCore/src/kwq/KWQView.mm b/WebCore/src/kwq/KWQView.mm
index 0758745..f3ce72d 100644
--- a/WebCore/src/kwq/KWQView.mm
+++ b/WebCore/src/kwq/KWQView.mm
@@ -31,6 +31,8 @@
 #include <qpainter.h>
 #include <html/html_documentimpl.h>
 
+
+
 @implementation KWQView
 
 - initWithFrame: (NSRect) r widget: (QWidget *)w 
@@ -105,7 +107,6 @@
     return self;
 }
 
-#define DELAY_LAYOUT
 #ifdef DELAY_LAYOUT
 - delayLayout: sender
 {
@@ -137,7 +138,9 @@
     if (((KHTMLView *)widget)->part()->xmlDocImpl() && 
         ((KHTMLView *)widget)->part()->xmlDocImpl()->renderer()){
         if (needsLayout){
+            long start = _GetMillisecondsSinceEpoch();
             ((KHTMLView *)widget)->layout(TRUE);
+            KWQDEBUGLEVEL1 (0x200, "layout time %d\n", _GetMillisecondsSinceEpoch() - start);
             needsLayout = NO;
         }
     }
@@ -159,10 +162,13 @@
         QPainter p(widget);    
         
         [self lockFocus];
+
+        long start = _GetMillisecondsSinceEpoch();
         ((KHTMLView *)widget)->drawContents( &p, (int)rect.origin.x, 
                     (int)rect.origin.y, 
                     (int)rect.size.width, 
                     (int)rect.size.height );
+        KWQDEBUGLEVEL1 (0x200, "draw time %d\n", _GetMillisecondsSinceEpoch() - start);
         [self unlockFocus];
     }
 }
diff --git a/WebCore/src/kwq/Makefile.in b/WebCore/src/kwq/Makefile.in
index 559e17f..7dd28e3 100644
--- a/WebCore/src/kwq/Makefile.in
+++ b/WebCore/src/kwq/Makefile.in
@@ -109,7 +109,9 @@ MMOBJECTS = \
     KWQString.o \
     KWQStyle.o \
     KWQTextArea.o \
+    KWQTextContainer.o \
     KWQTextEdit.o \
+    KWQTextStorage.o \
     KWQTimer.o \
     KWQToolTip.o \
     KWQVariant.o \
diff --git a/WebCore/src/kwq/kwqdebug.h b/WebCore/src/kwq/kwqdebug.h
index 9d9ae5e..21b3f38 100644
--- a/WebCore/src/kwq/kwqdebug.h
+++ b/WebCore/src/kwq/kwqdebug.h
@@ -34,6 +34,11 @@
 #undef Rect
 #undef Boolean
 
+/*
+*/
+#define _KWQ_TIMING 1
+long _GetMillisecondsSinceEpoch();
+
 /*-----------------------------------------------------------------------------
  * Logging macros
  */
diff --git a/WebCore/src/kwq/kwqdebug.mm b/WebCore/src/kwq/kwqdebug.mm
index 6c4073a..1c77f4c 100644
--- a/WebCore/src/kwq/kwqdebug.mm
+++ b/WebCore/src/kwq/kwqdebug.mm
@@ -25,6 +25,35 @@
 
 #include <kwqdebug.h>
 
+
+#if defined(__MACH__)
+#include <stdlib.h>
+#include <sys/time.h>
+#endif
+#if defined(__WIN32__)
+#import <sys/utime.h>
+#endif
+
+
+long _GetMillisecondsSinceEpoch() {
+    long result;
+    struct timeval tp;
+    struct timezone tzp;
+
+    result = 0;
+    tzp.tz_minuteswest = 0;
+    tzp.tz_dsttime = 0;
+
+    // FIXME: need to ifdef for Win32 at some point, 
+    // or use something from Foundation
+    if (gettimeofday(&tp, &tzp) == 0) {
+        result = (tp.tv_sec * 1000) + (tp.tv_usec / 1000);    
+    }
+  
+    return result;   
+}
+
+
 unsigned int KWQ_LOG_LEVEL = KWQ_LOG_ALL;
 
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list