[webkit-changes] cvs commit: WebKit/WebView.subproj WebHTMLView.m

David hyatt at opensource.apple.com
Fri Aug 26 17:03:45 PDT 2005


hyatt       05/08/26 17:03:44

  Modified:    .        ChangeLog
               WebCoreSupport.subproj WebImageData.h WebImageData.m
                        WebImageRenderer.m
               WebView.subproj WebHTMLView.m
  Log:
  	Add support for a new scaling and tiling function so that border images from CSS3
  	can be implemented.
  
          Reviewed by darin
  
          * WebCoreSupport.subproj/WebImageData.h:
          * WebCoreSupport.subproj/WebImageData.m:
          (-[WebImageData scaleAndTileInRect:fromRect:withHorizontalTileRule:withVerticalTileRule:context:]):
          * WebCoreSupport.subproj/WebImageRenderer.m:
          (-[WebImageRenderer scaleAndTileInRect:fromRect:withHorizontalTileRule:withVerticalTileRule:context:]):
          (-[WebImageRenderer setAnimationRect:]):
          * WebView.subproj/WebHTMLView.m:
          (-[WebHTMLView updateFocusState]):
  
  Revision  Changes    Path
  1.3307    +16 -0     WebKit/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKit/ChangeLog,v
  retrieving revision 1.3306
  retrieving revision 1.3307
  diff -u -r1.3306 -r1.3307
  --- ChangeLog	26 Aug 2005 22:02:51 -0000	1.3306
  +++ ChangeLog	27 Aug 2005 00:03:33 -0000	1.3307
  @@ -1,3 +1,19 @@
  +2005-08-26  David Hyatt  <hyatt at apple.com>
  +
  +	Add support for a new scaling and tiling function so that border images from CSS3
  +	can be implemented.
  +	
  +        Reviewed by darin
  +
  +        * WebCoreSupport.subproj/WebImageData.h:
  +        * WebCoreSupport.subproj/WebImageData.m:
  +        (-[WebImageData scaleAndTileInRect:fromRect:withHorizontalTileRule:withVerticalTileRule:context:]):
  +        * WebCoreSupport.subproj/WebImageRenderer.m:
  +        (-[WebImageRenderer scaleAndTileInRect:fromRect:withHorizontalTileRule:withVerticalTileRule:context:]):
  +        (-[WebImageRenderer setAnimationRect:]):
  +        * WebView.subproj/WebHTMLView.m:
  +        (-[WebHTMLView updateFocusState]):
  +
   2005-08-26  Adele Peterson  <adele at apple.com>
   
           Reviewed by Beth.
  
  
  
  1.19      +2 -0      WebKit/WebCoreSupport.subproj/WebImageData.h
  
  Index: WebImageData.h
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebImageData.h,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- WebImageData.h	16 Aug 2005 19:03:30 -0000	1.18
  +++ WebImageData.h	27 Aug 2005 00:03:42 -0000	1.19
  @@ -27,6 +27,7 @@
    */
   
   #import <Cocoa/Cocoa.h>
  +#import <WebCore/WebCoreImageRenderer.h>
   
   @class WebImageRenderer;
   
  @@ -69,6 +70,7 @@
   - (void)drawImageAtIndex:(size_t)index inRect:(CGRect)ir fromRect:(CGRect)fr compositeOperation:(NSCompositingOperation)op context:(CGContextRef)aContext;
   - (void)drawImageAtIndex:(size_t)index inRect:(CGRect)ir fromRect:(CGRect)fr adjustedSize:(CGSize)size compositeOperation:(NSCompositingOperation)op context:(CGContextRef)aContext;
   - (void)tileInRect:(CGRect)rect fromPoint:(CGPoint)point context:(CGContextRef)aContext;
  +- (void)scaleAndTileInRect:(CGRect)ir fromRect:(CGRect)fr withHorizontalTileRule:(WebImageTileRule)hRule withVerticalTileRule:(WebImageTileRule)vRule context:(CGContextRef)aContext;
   - (BOOL)isNull;
   - (CGSize)size;
   - (void)animate;
  
  
  
  1.46      +95 -0     WebKit/WebCoreSupport.subproj/WebImageData.m
  
  Index: WebImageData.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebImageData.m,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- WebImageData.m	17 Aug 2005 05:01:29 -0000	1.45
  +++ WebImageData.m	27 Aug 2005 00:03:42 -0000	1.46
  @@ -36,6 +36,7 @@
   #import "WebKitSystemBits.h"
   
   #import <WebKitSystemInterface.h>
  +
   #import <WebCore/WebCoreImageRenderer.h>
   
   // Forward declarations of internal methods.
  @@ -642,6 +643,100 @@
       [decodeLock unlock];
   }
   
  +- (void)scaleAndTileInRect:(CGRect)ir fromRect:(CGRect)fr 
  +    withHorizontalTileRule:(WebImageTileRule)hRule withVerticalTileRule:(WebImageTileRule)vRule context:(CGContextRef)aContext
  +{
  +    ASSERT(aContext);
  +
  +    [decodeLock lock];
  +    
  +    size_t frame = [self currentFrame];
  +    CGImageRef image = [self imageAtIndex:frame];
  +    if (!image) {
  +        [decodeLock unlock];
  +        return;
  +    }
  +
  +    if (frame == 0 && isSolidColor)
  +        [self _fillSolidColorInRect:ir compositeOperation: NSCompositeSourceOver context: aContext];
  +    else {
  +        CGContextSaveGState(aContext);
  +        CGSize tileSize = fr.size;
  +         
  +        // Now scale the slice in the appropriate direction using an affine transform that we will pass into
  +        // the pattern.
  +        float scaleX = 1.0f, scaleY = 1.0f;
  +
  +        if (hRule == WebImageStretch)
  +            scaleX = ir.size.width / fr.size.width;
  +        if (vRule == WebImageStretch)
  +            scaleY = ir.size.height / fr.size.height;
  +        
  +        if (hRule == WebImageRepeat)
  +            scaleX = scaleY;
  +        if (vRule == WebImageRepeat)
  +            scaleY = scaleX;
  +            
  +        if (hRule == WebImageRound) {
  +            // Complicated math ensues.
  +            float imageWidth = fr.size.width * scaleY;
  +            float newWidth = ir.size.width / ceilf(ir.size.width / imageWidth);
  +            scaleX = newWidth / fr.size.width;
  +        }
  +        
  +        if (vRule == WebImageRound) {
  +            // More complicated math ensues.
  +            float imageHeight = fr.size.height * scaleX;
  +            float newHeight = ir.size.height / ceilf(ir.size.height / imageHeight);
  +            scaleY = newHeight / fr.size.height;
  +        }
  +        
  +        CGAffineTransform patternTransform = CGAffineTransformMakeScale(scaleX, scaleY);
  +
  +        // Possible optimization:  We may want to cache the CGPatternRef    
  +        CGPatternRef pattern = CGPatternCreate(self, CGRectMake(fr.origin.x, fr.origin.y, tileSize.width, tileSize.height),
  +                                               patternTransform, tileSize.width, tileSize.height, 
  +                                               kCGPatternTilingConstantSpacing, true, &patternCallbacks);
  +        if (pattern) {
  +            // We want to construct the phase such that the pattern is centered (when stretch is not
  +            // set for a particular rule).
  +            float hPhase = scaleX * fr.origin.x;
  +            float vPhase = scaleY * (tileSize.height - fr.origin.y);
  +            if (hRule == WebImageRepeat)
  +                hPhase -= fmodf(ir.size.width, scaleX * tileSize.width) / 2.0f;
  +            if (vRule == WebImageRepeat)
  +                vPhase -= fmodf(ir.size.height, scaleY * tileSize.height) / 2.0f;
  +            
  +            CGPoint tileOrigin = CGPointMake(ir.origin.x - hPhase, ir.origin.y - vPhase);
  +            CGPoint transformedOrigin = CGPointApplyAffineTransform(tileOrigin, CGContextGetCTM(aContext));
  +            CGContextSetPatternPhase(aContext, CGSizeMake(transformedOrigin.x, transformedOrigin.y));
  +
  +            CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
  +            CGContextSetFillColorSpace(aContext, patternSpace);
  +            CGColorSpaceRelease(patternSpace);
  +
  +            float patternAlpha = 1;
  +            CGContextSetFillPattern(aContext, pattern, &patternAlpha);
  +
  +            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  +            [[NSGraphicsContext graphicsContextWithGraphicsPort:aContext flipped:NO] setCompositingOperation:NSCompositeSourceOver];
  +            [pool release];
  +
  +            CGContextFillRect (aContext, ir);
  +
  +            CGPatternRelease (pattern);
  +        }
  +        else {
  +            ERROR ("unable to create pattern");
  +        }
  +        
  +        CGContextRestoreGState (aContext);
  +    }
  +    
  +    [decodeLock unlock];
  +
  +}
  +
   - (BOOL)isNull
   {
       if (imageSource)
  
  
  
  1.107     +20 -0     WebKit/WebCoreSupport.subproj/WebImageRenderer.m
  
  Index: WebImageRenderer.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebImageRenderer.m,v
  retrieving revision 1.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- WebImageRenderer.m	16 Aug 2005 17:36:37 -0000	1.106
  +++ WebImageRenderer.m	27 Aug 2005 00:03:42 -0000	1.107
  @@ -197,6 +197,20 @@
       [self _startOrContinueAnimationIfNecessary];
   }
   
  +- (void)scaleAndTileInRect:(NSRect)ir fromRect:(NSRect)fr withHorizontalTileRule:(WebImageTileRule)hRule 
  +      withVerticalTileRule:(WebImageTileRule)vRule context:(CGContextRef)context
  +{
  +    if (context == 0)
  +        context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
  +
  +    [imageData scaleAndTileInRect:CGRectMake(ir.origin.x, ir.origin.y, ir.size.width, ir.size.height)
  +            fromRect:CGRectMake(fr.origin.x, fr.origin.y, fr.size.width, fr.size.height) 
  +            withHorizontalTileRule:hRule withVerticalTileRule:vRule context:context];
  +
  +    targetAnimationRect = ir;
  +    [self _startOrContinueAnimationIfNecessary];
  +}
  +
   - (void)_startOrContinueAnimationIfNecessary
   {
       NSView *targetView = [NSView focusView];
  @@ -232,6 +246,12 @@
       return targetAnimationRect;
   }
   
  +- (void)setAnimationRect:(NSRect)r
  +{
  +    targetAnimationRect = r;
  +    [self _startOrContinueAnimationIfNecessary];
  +}
  +
   - (void)increaseUseCount
   {
   }
  
  
  
  1.466     +3 -2      WebKit/WebView.subproj/WebHTMLView.m
  
  Index: WebHTMLView.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebHTMLView.m,v
  retrieving revision 1.465
  retrieving revision 1.466
  diff -u -r1.465 -r1.466
  --- WebHTMLView.m	17 Aug 2005 01:29:10 -0000	1.465
  +++ WebHTMLView.m	27 Aug 2005 00:03:43 -0000	1.466
  @@ -613,14 +613,15 @@
   - (void)updateFocusState
   {
       // This method does the job of updating the view based on the view's firstResponder-ness and
  -    // the window key-ness of the window containing this view. This involves three kinds of 
  +    // the window key-ness of the window containing this view. This involves four kinds of 
       // drawing updates right now, all handled in WebCore in response to the call over the bridge. 
       // 
  -    // The three display attributes are as follows:
  +    // The four display attributes are as follows:
       // 
       // 1. The background color used to draw behind selected content (active | inactive color)
       // 2. Caret blinking (blinks | does not blink)
       // 3. The drawing of a focus ring around links in web pages.
  +    // 4. Changing the tint of controls from clear to aqua/graphite and vice versa
       //
       // Also, this is responsible for letting the bridge know if the window has gained or lost focus
       // so we can send focus and blur events.
  
  
  



More information about the webkit-changes mailing list