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

sullivan sullivan at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:58:53 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 848076a8d98c8640a4ce074043e7ccf0022f8a30
Author: sullivan <sullivan at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Oct 1 00:38:25 2003 +0000

    WebKit:
    
            - fixed 3045617 -- Make Text Bigger/Smaller doesn't affect non-html documents.
    
            I added an internal protocol inside WebKit to make this work, and implemented
            it for plain text and RTF. I also slightly shuffled the existing code to
            handle this for HTML so that it goes through the new protocol in that case
            also.
    
            Reviewed by NOBODY (OOPS!).
    
            * WebView.subproj/WebDocumentInternal.h: Added.
           	New header file, holds definition of
    	_web_WebDocumentTextSizing protocol.
    
            * WebView.subproj/WebFramePrivate.m:
            (-[WebFrame _textSizeMultiplierChanged]):
            if the document view conforms to the new protocol,
            tell it that the multiplier has changed. Also, don't
            tell the bridge here anymore; let WebHTMLView do that.
    
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLView _updateTextSizeMultiplier]):
            tell the bridge here instead of having WebFrame do so
            (-[WebHTMLView viewDidMoveToSuperview]):
            call _updateTextSizeMultiplier (in case it changed while we were switched out)
            (-[WebHTMLView _web_textSizeMultiplierChanged]):
            call _updateTextSizeMultiplier
    
            * WebView.subproj/WebTextRepresentation.m:
            (-[WebTextRepresentation receivedData:withDataSource:]):
    
            * WebView.subproj/WebTextView.h:
    	now implements _web_WebDocumentTextSizing protocol;
            new ivar for holding local copy of text size multiplier;
            new public method appendReceivedData:fromDataSource:
    
            * WebView.subproj/WebTextView.m:
            (-[WebTextView initWithFrame:]):
            set local copy of text size multiplier to 1.0
            (-[WebTextView _textSizeMultiplierFromWebView]):
            new method, asks the webview's opinion of the text size multiplier
            (-[WebTextView setFixedWidthFont]):
            use the text size multiplier when setting font size
            (-[WebTextView _adjustRichTextFontSizeByRatio:]):
            new method, borrowed from Mail and tweaked, that walks through
            the rich text and adjusts the font sizes
            (-[WebTextView _updateTextSizeMultiplier]):
            new method, updates local copy of text size multiplier to
            match webview's opinion
            (-[WebTextView setDataSource:]):
            set the text size multiplier appropriately before setting the
            fixed-width font; this is too early for the RTF case though
            since the fonts are embedded in the data
            (-[WebTextView appendReceivedData:fromDataSource:]):
            new method. Most of this logic was in WebTextRepresentation, but
            it's a little better encapsulated here, plus now it handles the
            text multiplier for RTF.
            (-[WebTextView defaultsChanged:]):
            added comment
            (-[WebTextView _web_textSizeMultiplierChanged]):
            call updateTextSizeMultiplier
    
            * WebView.subproj/WebView.m:
            (-[WebView canMakeTextSmaller]):
            (-[WebView canMakeTextLarger]):
            return NO if the main frame doesn't support the text sizing protocol. This means
            that if the main frame doesn't support it but a subframe does, you can't adjust
            the text size. This seems fine for now since the only case with subframes is
            HTML, where the main frame does support changing text size.
    
            * WebKit.pbproj/project.pbxproj:
            updated for new file
    
    WebBrowser:
    
            Reviewed by Darin
    
            * HTMLSourceDocument.h:
    	removed unused _textSizeMultiplier ivar
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5097 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 7bc7ee2..0eaace8 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,77 @@
+2003-09-30  John Sullivan  <sullivan at apple.com>
+
+        - fixed 3045617 -- Make Text Bigger/Smaller doesn't affect non-html documents.
+        
+        I added an internal protocol inside WebKit to make this work, and implemented
+        it for plain text and RTF. I also slightly shuffled the existing code to
+        handle this for HTML so that it goes through the new protocol in that case
+        also.
+
+        Reviewed by NOBODY (OOPS!).
+
+        * WebView.subproj/WebDocumentInternal.h: Added.
+       	New header file, holds definition of 
+	_web_WebDocumentTextSizing protocol.
+
+        * WebView.subproj/WebFramePrivate.m:
+        (-[WebFrame _textSizeMultiplierChanged]):
+        if the document view conforms to the new protocol,
+        tell it that the multiplier has changed. Also, don't
+        tell the bridge here anymore; let WebHTMLView do that.
+
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _updateTextSizeMultiplier]):
+        tell the bridge here instead of having WebFrame do so
+        (-[WebHTMLView viewDidMoveToSuperview]):
+        call _updateTextSizeMultiplier (in case it changed while we were switched out)
+        (-[WebHTMLView _web_textSizeMultiplierChanged]):
+        call _updateTextSizeMultiplier
+        
+        * WebView.subproj/WebTextRepresentation.m:
+        (-[WebTextRepresentation receivedData:withDataSource:]):
+        
+        * WebView.subproj/WebTextView.h:
+	now implements _web_WebDocumentTextSizing protocol;
+        new ivar for holding local copy of text size multiplier;
+        new public method appendReceivedData:fromDataSource:
+        
+        * WebView.subproj/WebTextView.m:
+        (-[WebTextView initWithFrame:]):
+        set local copy of text size multiplier to 1.0
+        (-[WebTextView _textSizeMultiplierFromWebView]):
+        new method, asks the webview's opinion of the text size multiplier
+        (-[WebTextView setFixedWidthFont]):
+        use the text size multiplier when setting font size
+        (-[WebTextView _adjustRichTextFontSizeByRatio:]):
+        new method, borrowed from Mail and tweaked, that walks through
+        the rich text and adjusts the font sizes
+        (-[WebTextView _updateTextSizeMultiplier]):
+        new method, updates local copy of text size multiplier to
+        match webview's opinion
+        (-[WebTextView setDataSource:]):
+        set the text size multiplier appropriately before setting the
+        fixed-width font; this is too early for the RTF case though
+        since the fonts are embedded in the data
+        (-[WebTextView appendReceivedData:fromDataSource:]):
+        new method. Most of this logic was in WebTextRepresentation, but
+        it's a little better encapsulated here, plus now it handles the
+        text multiplier for RTF.
+        (-[WebTextView defaultsChanged:]):
+        added comment
+        (-[WebTextView _web_textSizeMultiplierChanged]):
+        call updateTextSizeMultiplier
+        
+        * WebView.subproj/WebView.m:
+        (-[WebView canMakeTextSmaller]):
+        (-[WebView canMakeTextLarger]):
+        return NO if the main frame doesn't support the text sizing protocol. This means
+        that if the main frame doesn't support it but a subframe does, you can't adjust
+        the text size. This seems fine for now since the only case with subframes is
+        HTML, where the main frame does support changing text size.
+        
+        * WebKit.pbproj/project.pbxproj:
+        updated for new file
+
 2003-09-30  Chris Blumenberg  <cblu at apple.com>
 
 	Fixed: <rdar://problem/3428262>: Plugin loads for static files, but not PHP scripts
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index 9ebd7cf..f83a768 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -318,6 +318,7 @@
 				BE07CEAF047538F000CA289C,
 				BE07CEB1047538F000CA289C,
 				BE6DC39B04C62C4E004D0EF6,
+				ED21B9820528F7AA003299AC,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -2515,6 +2516,7 @@
 				515E27CF0458CA4B00CA2D3A,
 				515E27D00458CA4B00CA2D3A,
 				35081DAE02B6D4F50ACA2ACA,
+				ED21B9810528F7AA003299AC,
 				3944606B020F50ED0ECA1767,
 				3944606C020F50ED0ECA1767,
 				2D81DAB203EB0B2D00A80166,
@@ -2893,6 +2895,20 @@
 //ED2
 //ED3
 //ED4
+		ED21B9810528F7AA003299AC = {
+			expectedFileType = sourcecode.c.h;
+			fileEncoding = 4;
+			isa = PBXFileReference;
+			path = WebDocumentInternal.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		ED21B9820528F7AA003299AC = {
+			fileRef = ED21B9810528F7AA003299AC;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		ED2B2474033A2DA800C1A526 = {
 			expectedFileType = sourcecode.c.h;
 			fileEncoding = 4;
diff --git a/WebKit/WebView.subproj/WebDocumentInternal.h b/WebKit/WebView.subproj/WebDocumentInternal.h
new file mode 100644
index 0000000..20dcffd
--- /dev/null
+++ b/WebKit/WebView.subproj/WebDocumentInternal.h
@@ -0,0 +1,19 @@
+/*	
+ WebDocumentInternal.h
+ Copyright (C) 2003 Apple Computer, Inc. All rights reserved.    
+*/
+
+#import <Cocoa/Cocoa.h>
+
+/*!
+ at protocol _web_WebDocumentTextSizing
+ at discussion Optional protocol for making text larger and smaller 
+*/
+ at protocol _web_WebDocumentTextSizing <NSObject>
+
+/*!
+ at method _web_textSizeMultiplierChanged
+ at abstract Called when the text size multiplier has been changed. -[WebView textSizeMultiplier] returns the current value.
+*/
+- (void)_web_textSizeMultiplierChanged;
+ at end
diff --git a/WebKit/WebView.subproj/WebFramePrivate.m b/WebKit/WebView.subproj/WebFramePrivate.m
index 1931b02..da2218b 100644
--- a/WebKit/WebView.subproj/WebFramePrivate.m
+++ b/WebKit/WebView.subproj/WebFramePrivate.m
@@ -13,6 +13,7 @@
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDefaultUIDelegate.h>
 #import <WebKit/WebDocument.h>
+#import <WebKit/WebDocumentInternal.h>
 #import <WebKit/WebDynamicScrollBarsView.h>
 #import <WebKit/WebFormDelegate.h>
 #import <WebKit/WebFrameLoadDelegate.h>
@@ -1900,7 +1901,11 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
 
 - (void)_textSizeMultiplierChanged
 {
-    [_private->bridge setTextSizeMultiplier:[[self webView] textSizeMultiplier]];
+    NSView <WebDocumentView> *view = [[self frameView] documentView];
+    if ([view conformsToProtocol:@protocol(_web_WebDocumentTextSizing)]) {
+        [(NSView <_web_WebDocumentTextSizing> *)view _web_textSizeMultiplierChanged];
+    }
+
     [[self childFrames] makeObjectsPerformSelector:@selector(_textSizeMultiplierChanged)];
 }
 
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index cb2fa14..7f06850 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -8,6 +8,7 @@
 #import <WebKit/WebBridge.h>
 #import <WebKit/WebClipView.h>
 #import <WebKit/WebDataSourcePrivate.h>
+#import <WebKit/WebDocumentInternal.h>
 #import <WebKit/WebDOMDocument.h>
 #import <WebKit/WebException.h>
 #import <WebKit/WebFrame.h>
@@ -29,6 +30,10 @@
 
 @interface WebHTMLView (WebHTMLViewPrivate)
 - (void)_setPrinting:(BOOL)printing pageWidth:(float)pageWidth adjustViewSize:(BOOL)adjustViewSize;
+- (void)_updateTextSizeMultiplier;
+ at end
+
+ at interface WebHTMLView (TextSizing) <_web_WebDocumentTextSizing>
 @end
 
 @interface NSArray (WebHTMLView)
@@ -238,6 +243,9 @@
 
 - (void)viewDidMoveToSuperview
 {
+    // Do this here in case the text size multiplier changed when a non-HTML
+    // view was installed.
+    [self _updateTextSizeMultiplier];
     [self addSuperviewObservers];
 }
 
@@ -845,6 +853,11 @@
     [[self window] setAutodisplay:YES];
 }
 
+- (void)_updateTextSizeMultiplier
+{
+    [[self _bridge] setTextSizeMultiplier:[[self _webView] textSizeMultiplier]];    
+}
+
 - (void)keyDown:(NSEvent *)event
 {
     if (![[self _bridge] interceptKeyEvent:event toView:self]) {
@@ -861,6 +874,15 @@
 
 @end
 
+ at implementation WebHTMLView (TextSizing)
+
+- (void)_web_textSizeMultiplierChanged
+{
+    [self _updateTextSizeMultiplier];
+}
+
+ at end
+
 @implementation NSArray (WebHTMLView)
 
 - (void)_web_makePluginViewsPerformSelector:(SEL)selector withObject:(id)object
diff --git a/WebKit/WebView.subproj/WebTextRepresentation.m b/WebKit/WebView.subproj/WebTextRepresentation.m
index dd13c70..35661fc 100644
--- a/WebKit/WebView.subproj/WebTextRepresentation.m
+++ b/WebKit/WebView.subproj/WebTextRepresentation.m
@@ -34,15 +34,7 @@
 {
     WebTextView *view = (WebTextView *)[[[dataSource webFrame] frameView] documentView];
     ASSERT([view isKindOfClass:[WebTextView class]]);
-    
-    if ([view isRichText]) {
-        // FIXME: We should try to progressively load RTF.
-        [view replaceCharactersInRange:NSMakeRange(0, [[view string] length])
-                               withRTF:[dataSource data]];
-    } else {
-        [view replaceCharactersInRange:NSMakeRange([[view string] length], 0)
-                            withString:[dataSource _stringWithData:data]];
-    }
+    [view appendReceivedData:data fromDataSource:dataSource];
 }
 
 - (void)receivedError:(NSError *)error withDataSource:(WebDataSource *)dataSource
diff --git a/WebKit/WebView.subproj/WebTextView.h b/WebKit/WebView.subproj/WebTextView.h
index f25f1cf..6cc023f 100644
--- a/WebKit/WebView.subproj/WebTextView.h
+++ b/WebKit/WebView.subproj/WebTextView.h
@@ -6,15 +6,19 @@
 #import <Cocoa/Cocoa.h>
 #import "WebSearchableTextView.h"
 
+ at class WebDataSource;
 @protocol WebDocumentView;
 @protocol WebDocumentDragSettings;
 @protocol WebDocumentText;
 
 @interface WebTextView : WebSearchableTextView <WebDocumentView, WebDocumentText>
 {
+    float _textSizeMultiplier;
 }
 
 + (NSArray *)unsupportedTextMIMETypes;
 - (void)setFixedWidthFont;
 
+- (void)appendReceivedData:(NSData *)data fromDataSource:(WebDataSource *)dataSource;
+
 @end
diff --git a/WebKit/WebView.subproj/WebTextView.m b/WebKit/WebView.subproj/WebTextView.m
index b6a8307..fde91e0 100644
--- a/WebKit/WebView.subproj/WebTextView.m
+++ b/WebKit/WebView.subproj/WebTextView.m
@@ -10,11 +10,19 @@
 
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDocument.h>
+#import <WebKit/WebDocumentInternal.h>
 #import <WebKit/WebFrameViewPrivate.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebPreferences.h>
 #import <WebKit/WebViewPrivate.h>
 
+ at interface WebTextView (ForwardDeclarations)
+- (void)_updateTextSizeMultiplier;
+ at end
+
+ at interface WebTextView (TextSizing) <_web_WebDocumentTextSizing>
+ at end
+
 @implementation WebTextView
 
 + (NSArray *)unsupportedTextMIMETypes
@@ -34,6 +42,7 @@
 {
     self = [super initWithFrame:frame];
     if (self) {
+        _textSizeMultiplier = 1.0;
         [self setAutoresizingMask:NSViewWidthSizable];
         [self setEditable:NO];
         [[NSNotificationCenter defaultCenter] addObserver:self
@@ -50,24 +59,97 @@
     [super dealloc];
 }
 
+- (float)_textSizeMultiplierFromWebView
+{
+    // Note that we are not guaranteed to be the subview of a webView at any given time.
+    WebView *webView = [[self _web_parentWebFrameView] _webView];
+    return webView ? [webView textSizeMultiplier] : 1.0;
+}
+
 - (void)setFixedWidthFont
 {
     WebPreferences *preferences = [WebPreferences standardPreferences];
     NSFont *font = [NSFont fontWithName:[preferences fixedFontFamily]
-        size:[preferences defaultFixedFontSize]];
+                                   size:[preferences defaultFixedFontSize]*_textSizeMultiplier];
     [self setFont:font];
 }
 
-- (void)setDataSource:(WebDataSource *)dataSource
+// This method was borrowed from Mail and changed to use ratios rather than deltas.
+// Also, I removed the isEditable clause since RTF displayed in WebKit is never editable.
+- (void)_adjustRichTextFontSizeByRatio:(float)ratio 
 {
-    if ([[[dataSource response] MIMEType] isEqualToString:@"text/rtf"]) {
-        [self setRichText:YES];
+    NSTextStorage *storage = [self textStorage];
+    NSRange remainingRange = NSMakeRange(0, [storage length]);
+    
+    while (remainingRange.length > 0) {
+        NSRange effectiveRange;
+        NSFont *font = [storage attribute:NSFontAttributeName atIndex:remainingRange.location longestEffectiveRange:&effectiveRange inRange:remainingRange];
+        
+        if (font) {
+            font = [[NSFontManager sharedFontManager] convertFont:font toSize:[font pointSize]*ratio];
+            [storage addAttribute:NSFontAttributeName value:font range:effectiveRange];
+        }
+        if (NSMaxRange(effectiveRange) < NSMaxRange(remainingRange)) {
+            remainingRange.length = NSMaxRange(remainingRange) - NSMaxRange(effectiveRange);
+            remainingRange.location = NSMaxRange(effectiveRange);
+        } else {
+            break;
+        }
+    }
+}
+
+- (void)_updateTextSizeMultiplier
+{
+    float newMultiplier = [self _textSizeMultiplierFromWebView];
+    if (newMultiplier == _textSizeMultiplier) {
+        return;
+    }
+    
+    float oldMultiplier = _textSizeMultiplier;
+    _textSizeMultiplier = newMultiplier;
+    
+    if ([self isRichText]) {
+        [self _adjustRichTextFontSizeByRatio:newMultiplier/oldMultiplier];
     } else {
-        [self setRichText:NO];
         [self setFixedWidthFont];
     }
 }
 
+- (void)setDataSource:(WebDataSource *)dataSource
+{
+    [self setRichText:[[[dataSource response] MIMEType] isEqualToString:@"text/rtf"]];
+    
+    float oldMultiplier = _textSizeMultiplier;
+    [self _updateTextSizeMultiplier];
+    // If the multiplier didn't change, we still need to update the fixed-width font.
+    // If the multiplier did change, this was already handled.
+    if (_textSizeMultiplier != oldMultiplier && ![self isRichText]) {
+        [self setFixedWidthFont];
+    }
+
+}
+
+// We handle incoming data here rather than in dataSourceUpdated because we
+// need to distinguish the last hunk of received data from the whole glob
+// of data received so far. This is a bad design in that it requires
+// WebTextRepresentation to know that it's view is a WebTextView, but this
+// bad design already existed.
+- (void)appendReceivedData:(NSData *)data fromDataSource:(WebDataSource *)dataSource;
+{
+    if ([self isRichText]) {
+        // FIXME: We should try to progressively load RTF.
+        [self replaceCharactersInRange:NSMakeRange(0, [[self string] length])
+                               withRTF:[dataSource data]];
+        if (_textSizeMultiplier != 1.0) {
+            [self _adjustRichTextFontSizeByRatio:_textSizeMultiplier];
+        }
+    } else {
+        [self replaceCharactersInRange:NSMakeRange([[self string] length], 0)
+                            withString:[dataSource _stringWithData:data]];
+    }
+}
+
+
 - (void)dataSourceUpdated:(WebDataSource *)dataSource
 {
 }
@@ -100,6 +182,8 @@
 
 - (void)defaultsChanged:(NSNotification *)notification
 {
+    // We use the default fixed-width font, but rich text
+    // pages specify their own fonts
     if (![self isRichText]) {
         [self setFixedWidthFont];
     }
@@ -200,3 +284,12 @@
 }
 
 @end
+
+ at implementation WebTextView (TextSizing)
+
+- (void)_web_textSizeMultiplierChanged
+{
+    [self _updateTextSizeMultiplier];
+}
+
+ at end
diff --git a/WebKit/WebView.subproj/WebView.m b/WebKit/WebView.subproj/WebView.m
index 515d8d3..5bef728 100644
--- a/WebKit/WebView.subproj/WebView.m
+++ b/WebKit/WebView.subproj/WebView.m
@@ -8,6 +8,7 @@
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDefaultPolicyDelegate.h>
 #import <WebKit/WebDocument.h>
+#import <WebKit/WebDocumentInternal.h>
 #import <WebKit/WebDynamicScrollBarsView.h>
 #import <WebKit/WebException.h>
 #import <WebKit/WebFrame.h>
@@ -742,6 +743,10 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
     if ([[self mainFrame] dataSource] == nil) {
         return NO;
     }
+    // FIXME: This will prevent text sizing in subframes if the main frame doesn't support it
+    if (![[[[self mainFrame] frameView] documentView] conformsToProtocol:@protocol(_web_WebDocumentTextSizing)]) {
+        return NO;
+    }
     if ([self textSizeMultiplier]/TextSizeMultiplierRatio < MinimumTextSizeMultiplier) {
         return NO;
     }
@@ -753,6 +758,10 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
     if ([[self mainFrame] dataSource] == nil) {
         return NO;
     }
+    // FIXME: This will prevent text sizing in subframes if the main frame doesn't support it
+    if (![[[[self mainFrame] frameView] documentView] conformsToProtocol:@protocol(_web_WebDocumentTextSizing)]) {
+        return NO;
+    }
     if ([self textSizeMultiplier]*TextSizeMultiplierRatio > MaximumTextSizeMultiplier) {
         return NO;
     }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list