Commit d45e194e authored by rjw's avatar rjw
Browse files

WebKit:

        Reviewed by trey.  This change was actually made by trey.  It
        make the "Empty Cache" menu release the page cache.

        * AppController.m:
        (-[AppController confirmEmptyCache:]):

WebCore:
        Fixed 3116584.  Made letter-spacing, word-spacing, and text-decoration play
        well together.
        Reviewed by hyatt.

        Changes made with trey to enable to release of page cache from the
        "Empty Cache" menu item in Alex.
        Reviewed by trey.

        * khtml/rendering/font.cpp:
        (Font::drawLineForText):
        (Font::drawText):
        * khtml/rendering/font.h:
        * khtml/rendering/render_text.cpp:
        (TextSlave::paintDecoration):
        (RenderText::paintObject):
        * khtml/rendering/render_text.h:
        * kwq/KWQPainter.h:
        * kwq/KWQPainter.mm:
        (QPainter::drawLineForText):
        * kwq/WebCoreBridge.h:
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge dealloc]):
        (-[WebCoreBridge openURL:reload:headers:lastModified:pageCache:]):
        (-[KWQPageState invalidate]):
        (-[KWQPageState dealloc]):
        * kwq/WebCoreTextRenderer.h:

WebKit:
        Changes to fix 3116584.
        Reviewed by hyatt.

        Changes to support emptying the page cache from the
        "Empty Cache" menu.
        Reviewed by trey.

        * ChangeLog:
        * History.subproj/WebBackForwardList.h:
        * History.subproj/WebBackForwardList.m:
        (-[WebBackForwardList clearPageCache]):
        * History.subproj/WebHistoryItem.m:
        (+[WebHistoryItem _scheduleReleaseTimer]):
        (-[WebHistoryItem _scheduleRelease]):
        (+[WebHistoryItem _releasePageCache:]):
        (-[WebHistoryItem setHasPageCache:]):
        * WebCoreSupport.subproj/WebTextRenderer.m:
        * WebView.subproj/WebFramePrivate.m:
        (-[WebFrame _opened]):

Tests:
        * html/letterspacing.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3030 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 36acbb2a
2002-12-12 Richard Williamson <rjw@apple.com>
Fixed 3116584. Made letter-spacing, word-spacing, and text-decoration play
well together.
Reviewed by hyatt.
Changes made with trey to enable to release of page cache from the
"Empty Cache" menu item in Alex.
Reviewed by trey.
* khtml/rendering/font.cpp:
(Font::drawLineForText):
(Font::drawText):
* khtml/rendering/font.h:
* khtml/rendering/render_text.cpp:
(TextSlave::paintDecoration):
(RenderText::paintObject):
* khtml/rendering/render_text.h:
* kwq/KWQPainter.h:
* kwq/KWQPainter.mm:
(QPainter::drawLineForText):
* kwq/WebCoreBridge.h:
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge dealloc]):
(-[WebCoreBridge openURL:reload:headers:lastModified:pageCache:]):
(-[KWQPageState invalidate]):
(-[KWQPageState dealloc]):
* kwq/WebCoreTextRenderer.h:
2002-12-12 Ken Kocienda <kocienda@apple.com>
Reviewed by Maciej and Darin
......
2002-12-12 Richard Williamson <rjw@apple.com>
Fixed 3116584. Made letter-spacing, word-spacing, and text-decoration play
well together.
Reviewed by hyatt.
Changes made with trey to enable to release of page cache from the
"Empty Cache" menu item in Alex.
Reviewed by trey.
* khtml/rendering/font.cpp:
(Font::drawLineForText):
(Font::drawText):
* khtml/rendering/font.h:
* khtml/rendering/render_text.cpp:
(TextSlave::paintDecoration):
(RenderText::paintObject):
* khtml/rendering/render_text.h:
* kwq/KWQPainter.h:
* kwq/KWQPainter.mm:
(QPainter::drawLineForText):
* kwq/WebCoreBridge.h:
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge dealloc]):
(-[WebCoreBridge openURL:reload:headers:lastModified:pageCache:]):
(-[KWQPageState invalidate]):
(-[KWQPageState dealloc]):
* kwq/WebCoreTextRenderer.h:
2002-12-12 Ken Kocienda <kocienda@apple.com>
Reviewed by Maciej and Darin
......
......@@ -37,8 +37,16 @@
using namespace khtml;
#ifdef APPLE_CHANGES
void Font::drawLineForText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len,
int toAdd, int yOffset, QPainter::TextDirection d) const
{
p->drawLineForText(x, y, str + pos, std::min(slen - pos, len), toAdd, yOffset, d, letterSpacing, wordSpacing);
}
#endif
void Font::drawText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len,
int toAdd, QPainter::TextDirection d, int from, int to, QColor bg ) const
int toAdd, QPainter::TextDirection d, int from, int to, QColor bg ) const
{
#if APPLE_CHANGES
p->drawText(x, y, str + pos, std::min(slen - pos, len), from, to, toAdd, bg, d, letterSpacing, wordSpacing);
......
......@@ -87,10 +87,13 @@ public:
void update( QPaintDeviceMetrics *devMetrics ) const;
void drawText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len, int width,
QPainter::TextDirection d, int from=-1, int to=-1, QColor bg=QColor() ) const;
#if APPLE_CHANGES
void drawLineForText( QPainter *p, int x, int y, QChar *str, int slen, int pos, int len, int toAdd, int yOffset,
QPainter::TextDirection d) const;
float floatWidth( QChar *str, int slen, int pos, int len ) const;
void floatCharacterWidths( QChar *str, int slen, int pos, int len, int toAdd, float *buffer) const;
#endif
......
......@@ -84,7 +84,7 @@ void TextSlave::paintSelection(const Font *f, RenderText *text, QPainter *p, Ren
p->restore();
}
void TextSlave::paintDecoration( QPainter *pt, RenderText* p, int _tx, int _ty, int deco, bool begin, bool end)
void TextSlave::paintDecoration( QPainter *pt, const Font *f, RenderText* p, int _tx, int _ty, int deco, bool begin, bool end)
{
_tx += m_x;
_ty += m_y;
......@@ -99,8 +99,16 @@ void TextSlave::paintDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
#if APPLE_CHANGES
// Use a special function for underlines to get the positioning exactly right.
if(deco & UNDERLINE)
pt->drawUnderlineForText(_tx, _ty + m_baseline, p->str->s + m_start, m_len);
if(deco & UNDERLINE){
f->drawLineForText(pt, _tx, _ty, p->str->s, p->str->l, m_start, m_len,
m_toAdd, m_baseline, m_reversed ? QPainter::RTL : QPainter::LTR);
}
if(deco & OVERLINE)
f->drawLineForText(pt, _tx, _ty, p->str->s, p->str->l, m_start, m_len,
m_toAdd, 0, m_reversed ? QPainter::RTL : QPainter::LTR);
if(deco & LINE_THROUGH)
f->drawLineForText(pt, _tx, _ty, p->str->s, p->str->l, m_start, m_len,
m_toAdd, 2*m_baseline/3, m_reversed ? QPainter::RTL : QPainter::LTR);
#else
int underlineOffset = ( pt->fontMetrics().height() + m_baseline ) / 2;
if(underlineOffset <= m_baseline) underlineOffset = m_baseline+1;
......@@ -108,11 +116,11 @@ void TextSlave::paintDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
if(deco & UNDERLINE){
pt->drawLine(_tx, _ty + underlineOffset, _tx + width, _ty + underlineOffset );
}
#endif
if(deco & OVERLINE)
pt->drawLine(_tx, _ty, _tx + width, _ty );
if(deco & LINE_THROUGH)
pt->drawLine(_tx, _ty + 2*m_baseline/3, _tx + width, _ty + 2*m_baseline/3 );
#endif
// NO! Do NOT add BLINK! It is the most annouing feature of Netscape, and IE has a reason not to
// support it. Lars
}
......@@ -651,7 +659,7 @@ void RenderText::paintObject(QPainter *p, int /*x*/, int y, int /*w*/, int h,
if(d != TDNONE)
{
p->setPen(_style->textDecorationColor());
s->paintDecoration(p, this, tx, ty, d, si == 0, si == ( int ) m_lines.count()-1);
s->paintDecoration(p, font, this, tx, ty, d, si == 0, si == ( int ) m_lines.count()-1);
}
#if APPLE_CHANGES
......
......@@ -72,7 +72,11 @@ private:
public:
#ifdef APPLE_CHANGES
void paintDecoration( QPainter *pt, const Font *, RenderText* p, int _tx, int _ty, int decoration, bool begin, bool end);
#else
void paintDecoration( QPainter *pt, RenderText* p, int _tx, int _ty, int decoration, bool begin, bool end);
#endif
void paintBoxDecorations(QPainter *p, RenderStyle* style, RenderText *parent, int _tx, int _ty, bool begin, bool end);
void paintSelection(const Font *f, RenderText *text, QPainter *p, RenderStyle* style, int tx, int ty, int startPos, int endPos);
......
......@@ -92,7 +92,7 @@ public:
void drawText(int x, int y, int, int, int alignmentFlags, const QString &);
void drawText(int x, int y, const QChar *, int length, int from, int to, int toAdd, const QColor& backgroundColor, QPainter::TextDirection d, int letterSpacing, int wordSpacing);
void drawUnderlineForText(int x, int y, const QChar *, int length);
void drawLineForText(int x, int y, const QChar *, int length, int toAdd, int yOffset, QPainter::TextDirection d, int letterSpacing, int wordSpacing);
static QColor selectedTextBackgroundColor();
bool paintingDisabled() const;
......
......@@ -417,7 +417,7 @@ void QPainter::drawText(int x, int y, const QChar *str, int len, int from, int t
fontFamilies: families];
}
void QPainter::drawUnderlineForText(int x, int y, const QChar *str, int len)
void QPainter::drawLineForText(int x, int y, const QChar *str, int length, int toAdd, int yOffset, QPainter::TextDirection d, int letterSpacing, int wordSpacing)
{
if (data->state.paintingDisabled)
return;
......@@ -426,8 +426,18 @@ void QPainter::drawUnderlineForText(int x, int y, const QChar *str, int len)
_updateRenderer(families);
[data->lastTextRenderer drawUnderlineForCharacters:(const UniChar *)str stringLength:len
atPoint:NSMakePoint(x,y) withColor:data->state.pen.color().getNSColor()];
[data->lastTextRenderer
drawLineForCharacters:(const UniChar *)str stringLength:length
fromCharacterPosition:0
toCharacterPosition:length
atPoint:NSMakePoint(x, y)
yOffset:(float)yOffset
withPadding: toAdd
withColor:data->state.pen.color().getNSColor()
rightToLeft: d == RTL ? true : false
letterSpacing: letterSpacing
wordSpacing: wordSpacing
fontFamilies: families];
}
QColor QPainter::selectedTextBackgroundColor()
......
......@@ -85,7 +85,6 @@ enum FrameBorderStyle {
{
KWQKHTMLPart *_part;
KHTMLRenderPart *_renderPart;
id _currentPageCache;
}
- (void)setRenderPart:(KHTMLRenderPart *)renderPart;
......
......@@ -94,6 +94,7 @@ NSString *WebCoreElementStringKey = @"WebElementString";
- (SavedProperties *)windowProperties;
- (SavedProperties *)locationProperties;
- (RenderObject *)renderer;
- (void)invalidate;
@end
@implementation WebCoreBridge
......@@ -117,9 +118,7 @@ NSString *WebCoreElementStringKey = @"WebElementString";
}
_part->setBridge(nil);
_part->deref();
[_currentPageCache release];
[super dealloc];
}
......@@ -151,14 +150,10 @@ NSString *WebCoreElementStringKey = @"WebElementString";
{
if (pageCache) {
KWQPageState *state = [pageCache objectForKey:@"WebCorePageState"];
_currentPageCache = [pageCache retain];
_part->openURLFromPageCache([state document], [state renderer], [state URL], [state windowProperties], [state locationProperties]);
[state invalidate];
return;
}
else if (_currentPageCache){
[_currentPageCache release];
_currentPageCache = 0;
}
// arguments
......@@ -848,24 +843,55 @@ static NSAttributedString *attributedString(NodeImpl *_startNode, int startOffse
return self;
}
- (void)dealloc
// Called when the KWQPageState is restored. It should relinquish ownership
// of objects to core.
- (void)invalidate
{
KHTMLView *view = document->view();
KWQ(view->part())->clearTimers();
// Should only ever invalidate once.
ASSERT (document);
document->setInPageCache(NO);
document->detach();
document->deref();
document = 0;
view->clearPart();
delete view;
delete URL;
URL = 0;
delete windowProperties;
windowProperties = 0;
delete locationProperties;
locationProperties = 0;
}
- (void)dealloc
{
if (document){
KHTMLView *view = document->view();
KWQ(view->part())->clearTimers();
document->setInPageCache(NO);
document->detach();
document->deref();
document = 0;
view->clearPart();
delete view;
}
if (URL){
delete URL;
URL = 0;
}
if (windowProperties){
delete windowProperties;
windowProperties = 0;
}
if (locationProperties){
delete locationProperties;
locationProperties = 0;
}
[super dealloc];
}
......
......@@ -42,6 +42,6 @@
// drawing
- (void)drawCharacters:(const UniChar *)characters stringLength:(unsigned)length fromCharacterPosition:(int)from toCharacterPosition:(int)to atPoint:(NSPoint)point withPadding: (int)padding withTextColor:(NSColor *)textColor backgroundColor:(NSColor *)backgroundColor rightToLeft: (BOOL)rtl letterSpacing: (int)letterSpacing wordSpacing: (int)wordSpacing fontFamilies: (NSString **)families;
- (void)drawUnderlineForCharacters:(const UniChar *)characters stringLength:(unsigned)length atPoint:(NSPoint)point withColor:(NSColor *)color;
- (void)drawLineForCharacters:(const UniChar *)characters stringLength:(unsigned)length fromCharacterPosition:(int)from toCharacterPosition:(int)to atPoint:(NSPoint)point yOffset:(float)yOffset withPadding: (int)padding withColor:(NSColor *)color rightToLeft: (BOOL)rtl letterSpacing: (int)letterSpacing wordSpacing: (int)wordSpacing fontFamilies: (NSString **)families;
@end
2002-12-12 Richard Williamson <rjw@apple.com>
Changes to fix 3116584.
Reviewed by hyatt.
Changes to support emptying the page cache from the
"Empty Cache" menu.
Reviewed by trey.
* ChangeLog:
* History.subproj/WebBackForwardList.h:
* History.subproj/WebBackForwardList.m:
(-[WebBackForwardList clearPageCache]):
* History.subproj/WebHistoryItem.m:
(+[WebHistoryItem _scheduleReleaseTimer]):
(-[WebHistoryItem _scheduleRelease]):
(+[WebHistoryItem _releasePageCache:]):
(-[WebHistoryItem setHasPageCache:]):
* WebCoreSupport.subproj/WebTextRenderer.m:
* WebView.subproj/WebFramePrivate.m:
(-[WebFrame _opened]):
2002-12-12 Richard Williamson <rjw@apple.com>
Fixed 3119693. Restore scroll position when going back
to item in b/f cache.
Reviewed by trey.
* WebView.subproj/WebFramePrivate.m:
(-[WebFrame _opened]):
=== Alexander-36 ===
2002-12-12 Richard Williamson <rjw@apple.com>
......
......@@ -49,6 +49,12 @@
*/
+ (unsigned)pageCacheSize;
/*!
@method clearPageCache
@discussion Clears all items in the page cache.
*/
- (void)clearPageCache;
/*!
@method addEntry:
@abstract Adds an entry to the list.
......
......@@ -185,6 +185,14 @@ -(NSString *)description
return result;
}
- (void)clearPageCache
{
int i;
for (i = 0; i < (int)[_entries count]; i++) {
[[_entries objectAtIndex:i] setHasPageCache:NO];
}
}
static BOOL pageCacheSizeModified = NO;
static unsigned pageCacheSize = 4;
......
......@@ -486,21 +486,25 @@ + (void)_invalidateReleaseTimer
}
}
- (void)_scheduleRelease
+ (void)_scheduleReleaseTimer
{
LOG (PageCache, "Scheduling release of %@", [self URLString]);
if (!_pageCacheReleaseTimer){
_pageCacheReleaseTimer = [[NSTimer scheduledTimerWithTimeInterval: 2.5 target:self selector:@selector(_releasePageCache:) userInfo:nil repeats:NO] retain];
if (_pendingPageCacheToRelease == nil){
_pendingPageCacheToRelease = [[NSMutableSet alloc] init];
}
}
// Only add the pageCache on first scheduled attempt.
}
- (void)_scheduleRelease
{
LOG (PageCache, "Scheduling release of %@", [self URLString]);
[WebHistoryItem _scheduleReleaseTimer];
if (pageCache){
[_pendingPageCacheToRelease addObject: pageCache];
[pageCache release]; // Last reference held by _pendingPageCacheToRelease.
pageCache = 0;
pageCache = nil;
}
if (!_windowWatcher){
......@@ -517,7 +521,7 @@ + (void)_releaseAllPendingPageCaches
[_pendingPageCacheToRelease removeAllObjects];
}
- (void)_releasePageCache: (NSTimer *)timer
+ (void)_releasePageCache: (NSTimer *)timer
{
CGSRealTimeDelta userDelta;
CFAbsoluteTime loadDelta;
......@@ -530,15 +534,13 @@ - (void)_releasePageCache: (NSTimer *)timer
if ((userDelta < 0.5 || loadDelta < 1.25) && [_pendingPageCacheToRelease count] < 42){
LOG (PageCache, "postponing again because not quiescent for more than a second (%f since last input, %f since last load).", userDelta, loadDelta);
[self _scheduleRelease];
[self _scheduleReleaseTimer];
return;
}
else
LOG (PageCache, "releasing, quiescent for more than a second (%f since last input, %f since last load).", userDelta, loadDelta);
[WebHistoryItem _releaseAllPendingPageCaches];
LOG (PageCache, "Done releasing %p %@", self, [self URLString]);
}
- (void)setHasPageCache: (BOOL)f
......@@ -547,7 +549,6 @@ - (void)setHasPageCache: (BOOL)f
pageCache = [[NSMutableDictionary alloc] init];
if (!f && pageCache){
[self _scheduleRelease];
pageCache = 0;
}
}
......
......@@ -707,13 +707,29 @@ - (void)drawCharacters:(const UniChar *)characters stringLength: (unsigned int)l
}
- (void)drawUnderlineForCharacters:(const UniChar *)characters stringLength:(unsigned)length atPoint:(NSPoint)point withColor:(NSColor *)color
- (void)drawLineForCharacters:(const UniChar *)characters stringLength:(unsigned)length fromCharacterPosition:(int)from toCharacterPosition:(int)to atPoint:(NSPoint)point yOffset:(float)yOffset withPadding: (int)padding withColor:(NSColor *)color rightToLeft: (BOOL)rtl letterSpacing: (int)letterSpacing wordSpacing: (int)wordSpacing fontFamilies: (NSString **)families;
{
NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
int width = [self widthForCharacters:characters length:length];
int width;
CGContextRef cgContext;
float lineWidth;
width = ROUND_TO_INT([self _floatWidthForCharacters:characters
stringLength:length
fromCharacterPosition: 0
numberOfCharacters: length
withPadding: padding
applyRounding: YES
attemptFontSubstitution: YES
widths: 0
fonts: 0
glyphs: 0
numGlyphs: 0
letterSpacing: letterSpacing
wordSpacing: wordSpacing
fontFamilies: families]);
// This will draw the text from the top of the bounding box down.
// Qt expects to draw from the baseline.
// Remember that descender is negative.
......@@ -732,8 +748,8 @@ - (void)drawUnderlineForCharacters:(const UniChar *)characters stringLength:(uns
lineWidth = size.width;
}
CGContextSetLineWidth(cgContext, lineWidth);
CGContextMoveToPoint(cgContext, point.x, point.y + [font defaultLineHeightForFont] + 1.5 - [self descent]);
CGContextAddLineToPoint(cgContext, point.x + width, point.y + [font defaultLineHeightForFont] + 1.5 - [self descent]);
CGContextMoveToPoint(cgContext, point.x, point.y + [font defaultLineHeightForFont] + 1.5 - [self descent] + yOffset);
CGContextAddLineToPoint(cgContext, point.x + width, point.y + [font defaultLineHeightForFont] + 1.5 - [self descent] + yOffset);
CGContextStrokePath(cgContext);
[graphicsContext setShouldAntialias: flag];
......
......@@ -738,6 +738,13 @@ - (void)_opened
[_private->bridge reapplyStyles];
[[[self webView] documentView] setNeedsLayout: YES];
[[[self webView] documentView] layout];
[self _restoreScrollPosition];
// Release the resources kept in the page cache. They will be
// reset when we leave this page. The core side of the page cache
// will have already been invalidated by the bridge to prevent
// premature release.
[[_private currentItem] setHasPageCache: NO];
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment