+2006-01-10 Nefaur Khandker <nefaurk@gmail.com>
+
+ Reviewed by eseidel. Committed by eseidel.
+
+ DrawTestView now subclasses WebView instead of DrawView.
+
+ * DrawTest/DrawTest.xcodeproj/project.pbxproj:
+ * DrawTest/DrawTestDocument.h:
+ * DrawTest/DrawTestDocument.m:
+ (-[DrawTestDocument dealloc]):
+ (-[DrawTestDocument readFromFile:ofType:]):
+ (-[DrawTestDocument windowControllerDidLoadNib:]):
+ (-[DrawTestDocument dumpSVGToConsole:]):
+ (-[DrawTestDocument openSourceForSelection:]):
+ (-[DrawTestDocument dataRepresentationOfType:]):
+ * DrawTest/DrawTestToolbarController.h:
+ * DrawTest/DrawTestToolbarController.m:
+ (-[DrawTestToolbarController initWithDrawView:]):
+ (-[DrawTestToolbarController clickedToolbarItem:]):
+ (-[DrawTestToolbarController validateToolbarItem:]):
+ * DrawTest/DrawTestView.h:
+ * DrawTest/DrawTestView.m:
+ (-[DrawTestView initWithFrame:]):
+ (-[DrawTestView setDocument:]):
+ * DrawTest/SVGTest.h:
+ * DrawTest/SVGTest.m:
+ (+[SVGTest sharedDrawView]):
+ (-[SVGTest generateCompositeIfNecessary]):
+ * DrawTest/TestController.h:
+ * DrawTest/TestController.m:
+ (-[TestController awakeFromNib]):
+ (-[TestController setSelectedTest:]):
+ (-[TestController openTestViewerForSelection:]):
+ (-[TestController toggleViewersScaleRule:]):
+ * DrawTest/TestViewerSplitView.m:
+ (-[TestViewerSplitView drawRect:]):
+
2006-01-10 Anders Carlsson <andersca@mac.com>
Reviewed by Timothy.
objects = {
/* Begin PBXBuildFile section */
+ 78662E6D096B4E1600907EA7 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78662E6C096B4E1600907EA7 /* WebKit.framework */; };
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
A8C006F3089865E900BA5114 /* DrawTestDocument.nib in Resources */ = {isa = PBXBuildFile; fileRef = A8C006ED089865E900BA5114 /* DrawTestDocument.nib */; };
A8C006F4089865E900BA5114 /* Inspector.nib in Resources */ = {isa = PBXBuildFile; fileRef = A8C006EF089865E900BA5114 /* Inspector.nib */; };
A8C006F5089865E900BA5114 /* TestViewer.nib in Resources */ = {isa = PBXBuildFile; fileRef = A8C006F1089865E900BA5114 /* TestViewer.nib */; };
- A8C006FA0898665200BA5114 /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A8C006F90898665200BA5114 /* WebCore.framework */; };
/* End PBXBuildFile section */
/* Begin PBXBuildStyle section */
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* DrawTest_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawTest_Prefix.pch; sourceTree = "<group>"; };
+ 78662E6C096B4E1600907EA7 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* DrawTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DrawTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
A8C006AF0898634600BA5114 /* TestController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestController.h; sourceTree = "<group>"; };
A8C006EE089865E900BA5114 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/DrawTestDocument.nib; sourceTree = "<group>"; };
A8C006F0089865E900BA5114 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/Inspector.nib; sourceTree = "<group>"; };
A8C006F2089865E900BA5114 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/TestViewer.nib; sourceTree = "<group>"; };
- A8C006F90898665200BA5114 /* WebCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
buildActionMask = 2147483647;
files = (
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
- A8C006FA0898665200BA5114 /* WebCore.framework in Frameworks */,
+ 78662E6D096B4E1600907EA7 /* WebKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
- A8C006F90898665200BA5114 /* WebCore.framework */,
+ 78662E6C096B4E1600907EA7 /* WebKit.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import <Cocoa/Cocoa.h>
-@class DrawDocument;
@class DrawTestView;
@class DrawTestToolbarController;
IBOutlet DrawTestView *drawView;
IBOutlet NSDrawer *debugDrawer;
- DrawDocument *document;
DrawTestToolbarController *toolbarController;
}
-- (void)setDrawDocument:(DrawDocument *)drawDocument;
-- (DrawDocument *)drawDocument;
-
-// debug menu.
+// Debug menu
- (IBAction)dumpSVGToConsole:(id)sender;
- (IBAction)toggleDebugDrawer:(id)sender;
- (IBAction)runWindowResizeTest:(id)sender;
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "DrawTestDocument.h"
#import "DrawTestView.h"
#import "DrawTestToolbarController.h"
-
-#import <WebCore/DrawDocumentPrivate.h>
+#import <WebKit/WebView.h>
+#import <WebKit/WebFrame.h>
+#import <WebKit/WebDataSource.h>
@implementation DrawTestDocument
- (void)dealloc
{
[toolbarController release];
- [document release];
[super dealloc];
}
return @"DrawTestDocument";
}
-- (IBAction)dumpSVGToConsole:(id)sender
-{
- NSLog(@"SVG: %@", [document svgText]);
-}
-
-- (void)sizeWindowToFitCanvas
+- (BOOL)readFromFile:(NSString *)filename ofType:(NSString *)docType
{
- NSSize canvasSize = [document canvasSize];
- if ((canvasSize.width > 10) && (canvasSize.height > 10)) {
- NSWindow *window = [drawView window];
- //canvasSize.height += [drawView frame].origin.y; // to accomidate the tool pallette
- NSRect newFrame = [window frameRectForContentRect:NSMakeRect(0,0,canvasSize.width, canvasSize.height)];
- newFrame = [window constrainFrameRect:newFrame toScreen:[window screen]];
- // we really should not show margins here.
- [window setFrame:newFrame display:YES];
- }
+ // TODO: Check the validity of the document before returning YES.
+ return YES;
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
toolbarController = [[DrawTestToolbarController alloc] initWithDrawView:drawView];
- [drawView setDocument:[self drawDocument]];
- [self sizeWindowToFitCanvas];
+ [drawView setDocument:[self fileURL]];
}
-- (IBAction)openSourceForSelection:(id)sender
+- (IBAction)dumpSVGToConsole:(id)sender
{
- [[NSWorkspace sharedWorkspace] openFile:[self fileName] withApplication:@"TextEdit"];
+ WebDataSource* dataSource = [[drawView mainFrame] dataSource];
+ NSLog(@"SVG Markup for file %@:\n%@", [self fileURL], [[dataSource representation] documentSource]);
}
-- (IBAction)zoomToContent:(id)sender
+- (IBAction)openSourceForSelection:(id)sender
{
- [document sizeCanvasToFitContent];
- [drawView setNeedsDisplay:YES];
- [self sizeWindowToFitCanvas];
+ // TODO: The "path" message (below) will not produce a valid pathname if we are dealing with a remote file.
+ NSString *filename = [[self fileURL] path];
+ [[NSWorkspace sharedWorkspace] openFile:filename withApplication:@"TextEdit"];
}
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
- return [[document svgText] dataUsingEncoding:NSUTF8StringEncoding];
-}
-
-- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
-{
- [self setDrawDocument:[DrawDocument documentWithSVGData:data]];
- return YES;
-}
-
-- (void)setDrawDocument:(DrawDocument *)drawDocument
-{
- id oldDoc = document;
- document = [drawDocument retain];
- [oldDoc release];
-}
-
-- (DrawDocument *)drawDocument
-{
- //if (!document) document = [[DrawDocument alloc] init];
- return document;
+ WebDataSource* dataSource = [[drawView mainFrame] dataSource];
+ return [dataSource data];
}
#pragma mark -
#import <Cocoa/Cocoa.h>
-@class DrawView;
+@class WebView;
@interface DrawTestToolbarController : NSObject {
- DrawView *_drawView;
+ WebView *_drawView;
NSMutableDictionary *_toolbarItems;
}
-- (id)initWithDrawView:(DrawView *)drawView;
+- (id)initWithDrawView:(WebView *)drawView;
@end
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "DrawTestToolbarController.h"
-#import <WebCore/DrawViewPrivate.h>
-
enum
{
ToolbarBrowseToolTag = 0,
@implementation DrawTestToolbarController
-- (id)initWithDrawView:(DrawView *)drawView
+- (id)initWithDrawView:(WebView *)drawView
{
if (self = [super init]){
_drawView = [drawView retain];
int tag = [sender tag];
switch(tag) {
+#if 0
case ToolbarBrowseToolTag:
[_drawView setToolMode:DrawViewToolBrowse];
break;
case ToolbarDeleteSelectionTag:
[_drawView deleteSelection:sender];
break;
+#endif
default:
NSLog(@"Toolbar item: %i not implemented!", tag);
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
BOOL enabled = YES;
-
+
+#if 0
switch([theItem tag]) {
case ToolbarMoveForwardTag:
case ToolbarMoveBackwardTag:
case ToolbarDeleteSelectionTag:
enabled = ([[_drawView selectedCanvasItems] count] != 0);
}
+#endif
return enabled;
}
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import <Cocoa/Cocoa.h>
-#import <WebCore/DrawView.h>
+#import <WebKit/WebView.h>
+@interface DrawTestView : WebView
+{
-@interface DrawTestView : DrawView
-{
- BOOL _showDebugString;
- BOOL _showDebugAxes;
}
-- (IBAction)toggleShowDebugString:(id)sender;
-- (IBAction)toggleShowDebugAxes:(id)sender;
+- (void)setDocument:(NSURL *)documentURL;
@end
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#import "DrawTestView.h"
+#import <WebKit/WebFrame.h>
-#import <WebCore/DrawViewPrivate.h>
-#import <WebCore/DrawDocumentPrivate.h>
+#import "DrawTestView.h"
@implementation DrawTestView
-- (id)initWithFrame:(NSRect)frame
-{
- if (self = [super initWithFrame:frame]) {
- //[self setValue:[NSNumber numberWithBool:YES] forKey:@"showDebugString"];
- //[self setValue:[NSNumber numberWithBool:YES] forKey:@"showDebugAxes"];
- }
- return self;
-}
-
-- (void)drawAxes:(float)length
-{
- NSBezierPath *xAxis = [NSBezierPath bezierPath];
- [xAxis moveToPoint:NSMakePoint(-.5 * length, 0)];
- [xAxis lineToPoint:NSMakePoint(length, 0)];
- [[NSColor redColor] set];
- [xAxis stroke];
-
- NSBezierPath *yAxis = [NSBezierPath bezierPath];
- [yAxis moveToPoint:NSMakePoint(0, -.5 * length)];
- [yAxis lineToPoint:NSMakePoint(0, length)];
- [[NSColor greenColor] set];
- [yAxis stroke];
-}
-
-- (void)drawRect:(NSRect)dirtyRect
-{
- [super drawRect:dirtyRect];
-
- if (_showDebugString) {
- // draw the current zoom/pan
- NSString *infoString = [NSString stringWithFormat:@"viewport origin: %@ canvas size: %@ zoom: %f",
- NSStringFromPoint([self canvasVisibleOrigin]),
- NSStringFromSize([[self document] canvasSize]), [self canvasZoom]];
- [infoString drawAtPoint:NSMakePoint(5, 13) withAttributes:nil];
- }
-
- if (_showDebugAxes) {
- CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- CGContextSaveGState(context);
- CGContextConcatCTM(context, CGAffineTransformInvert([self transformFromViewToCanvas]));
- [self drawAxes:100];
- CGContextRestoreGState(context);
- }
-}
-
-- (IBAction)toggleShowDebugString:(id)sender
-{
- [self setValue:[NSNumber numberWithBool:!_showDebugString] forKey:@"showDebugString"];
- [self setNeedsDisplay:YES];
-}
-
-- (IBAction)toggleShowDebugAxes:(id)sender
-{
- [self setValue:[NSNumber numberWithBool:!_showDebugAxes] forKey:@"showDebugAxes"];
- [self setNeedsDisplay:YES];
-}
-
-- (IBAction)toggleFilterSupport:(id)sender
+- (void)setDocument:(NSURL *)documentURL
{
- [DrawView setFilterSupportEnabled:![DrawView isFilterSupportEnabled]];
- [self setNeedsDisplay:YES];
+ [[self mainFrame] loadRequest:[NSURLRequest requestWithURL:documentURL]];
}
- (BOOL)acceptsFirstResponder
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import <Cocoa/Cocoa.h>
-@class DrawDocument;
-
@interface SVGTest : NSObject {
NSString *_svgPath;
NSString *_imagePath;
- DrawDocument *_svgDocument;
NSImage *_image;
NSImage *_compositeImage;
BOOL _hasPassed;
- (NSString *)svgPath;
- (NSImage *)image;
-- (DrawDocument *)svgDocument;
- (NSImage *)compositeImage;
- (NSString *)name;
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "SVGTest.h"
-#import <WebCore/DrawView.h>
-#import <WebCore/DrawDocument.h>
+#import <WebKit/WebView.h>
@implementation SVGTest
return [test autorelease];
}
-static DrawView *__sharedDrawView = nil;
-+ (DrawView *)sharedDrawView
+static WebView *__sharedDrawView = nil;
++ (WebView *)sharedDrawView
{
if (!__sharedDrawView) {
- __sharedDrawView = [[DrawView alloc] initWithFrame:NSMakeRect(0,0,0,0)];
+ __sharedDrawView = [[WebView alloc] initWithFrame:NSMakeRect(0,0,0,0)];
}
return __sharedDrawView;
}
return _image;
}
-- (DrawDocument *)svgDocument
-{
- if (!_svgDocument && _svgPath) {
- _svgDocument = [[DrawDocument alloc] initWithContentsOfFile:_svgPath];
- }
- return _svgDocument;
-}
-
- (NSString *)name
{
NSMutableString *name = [[[[_svgPath lastPathComponent] stringByDeletingPathExtension] mutableCopy] autorelease];
- (void)generateCompositeIfNecessary
{
if (!_compositeImage) {
- DrawView *view = [SVGTest sharedDrawView];
- [view setDocument:[self svgDocument]];
- [view sizeToFitViewBox];
+ WebView *view = [SVGTest sharedDrawView];
NSSize svgSize = [view bounds].size;
NSImage *image = [self image];
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import <Cocoa/Cocoa.h>
-@class DrawView;
+@class DrawTestView;
@class SVGTest;
@class TestViewerSplitView;
NSArray *_tests;
SVGTest *_selectedTest;
- DrawView *_drawView;
+ DrawTestView *_drawView;
NSImageView *_imageView;
}
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "SVGTest.h"
#import "TestViewerSplitView.h"
#import "ScalingImageView.h"
+#import "DrawTestView.h"
-#import <WebCore/DrawView.h>
+#import <WebKit/WebView.h>
@interface NSArray (TestControllerAdditions)
- (id)firstObject;
{
[_testsTableView setTarget:self];
[_testsTableView setDoubleAction:@selector(openTestViewerForSelection:)];
- _drawView = [[DrawView alloc] initWithFrame:NSZeroRect];
+ _drawView = [[DrawTestView alloc] initWithFrame:NSZeroRect];
_imageView = [[ScalingImageView alloc] initWithFrame:NSZeroRect];
[_splitView addSubview:_drawView];
[_splitView addSubview:_imageView];
if ([_testWindow isVisible]) {
[_testWindow setTitle:[NSString stringWithFormat:@"Test Viewer - %@", [_selectedTest name]]];
- [_drawView setDocument:[_selectedTest svgDocument]];
+ [_drawView setDocument:[NSURL fileURLWithPath:[_selectedTest svgPath]]];
[_imageView setImage:[_selectedTest image]];
if ([_compositeWindow isVisible])
[_compositeImageView setImage:[_selectedTest compositeImage]];
- (IBAction)openTestViewerForSelection:(id)sender
{
[self showTestWindow:sender];
- [_drawView setDocument:[_selectedTest svgDocument]];
+ [_drawView setDocument:[NSURL fileURLWithPath:[_selectedTest svgPath]]];
[_imageView setImage:[_selectedTest image]];
}
- (IBAction)toggleViewersScaleRule:(id)sender
{
+#if 0
if ([_drawView imageScaling] == NSScaleProportionally) {
[_drawView setImageScaling:NSScaleNone];
[_imageView setImageScaling:NSScaleNone];
[_drawView setImageScaling:NSScaleProportionally];
[_imageView setImageScaling:NSScaleProportionally];
}
+#endif
}
@end
for (int x=0; x < subviewCount; x++) {
NSView *subview = [subviews objectAtIndex:x];
[subview drawRect:rect];
-// NSString *label = [subviewLabels objectAtIndex:0];
-// [label drawAtPoint:[subview frame].origin withAttributes:NULL];
+#if 0
+ NSString *label = [subviewLabels objectAtIndex:0];
+ [label drawAtPoint:[subview frame].origin withAttributes:NULL];
+#endif
}
}