• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
3 * Copyright (C) 2006 Nefaur Khandker <nefaurk@gmail.com>  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#import "DrawTestDocument.h"
28#import "DrawTestView.h"
29#import "DrawTestToolbarController.h"
30#import <WebKit/WebView.h>
31#import <WebKit/WebFrame.h>
32#import <WebKit/WebDataSource.h>
33
34@implementation DrawTestDocument
35
36- (id)initWithType:(NSString *)typeName error:(NSError **)outError
37{
38    if (outError) {
39        NSDictionary *errorInfo = [NSDictionary dictionaryWithObjectsAndKeys:
40            @"No document could be created.", NSLocalizedDescriptionKey,
41            @"New document creation not yet supported.", NSLocalizedFailureReasonErrorKey,
42            nil];
43        *outError = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:errorInfo];
44    }
45    [self release];
46    return nil;
47}
48
49- (void)dealloc
50{
51    [toolbarController release];
52    [super dealloc];
53}
54
55- (NSString *)windowNibName
56{
57    return @"DrawTestDocument";
58}
59
60- (BOOL)readFromFile:(NSString *)filename ofType:(NSString *)docType
61{
62    // TODO: Check the validity of the document before returning YES.
63    return YES;
64}
65
66- (void)windowControllerDidLoadNib:(NSWindowController *)aController
67{
68    [super windowControllerDidLoadNib:aController];
69    toolbarController = [[DrawTestToolbarController alloc] initWithDrawView:drawView];
70    [drawView setDocument:[self fileURL]];
71}
72
73- (IBAction)dumpSVGToConsole:(id)sender
74{
75    WebDataSource* dataSource = [[drawView mainFrame] dataSource];
76    NSLog(@"SVG Markup for file %@:\n%@", [self fileURL], [[dataSource representation] documentSource]);
77}
78
79- (IBAction)openSourceForSelection:(id)sender
80{
81    // TODO: The "path" message (below) will not produce a valid pathname if we are dealing with a remote file.
82    NSString *filename = [[self fileURL] path];
83    [[NSWorkspace sharedWorkspace] openFile:filename withApplication:@"TextEdit"];
84}
85
86- (NSData *)dataRepresentationOfType:(NSString *)aType
87{
88    WebDataSource* dataSource = [[drawView mainFrame] dataSource];
89    return [dataSource data];
90}
91
92#pragma mark -
93#pragma mark Debug Methods
94
95- (IBAction)toggleDebugDrawer:(id)sender
96{
97    [debugDrawer toggle:sender];
98}
99
100- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
101{
102    return nil;
103}
104
105- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
106{
107    return NO;
108}
109
110- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
111{
112    return 0;
113}
114
115- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
116{
117    return nil;
118}
119
120- (IBAction)runWindowResizeTest:(id)sender
121{
122    NSWindow *window = [drawView window];
123    NSScreen *screen = [window screen];
124    float screenHeight = [screen visibleFrame].size.height;
125    NSRect originalFrame = [window frame];
126    // initial setup
127    BOOL toolbarVisible = [[window toolbar] isVisible];
128    if (toolbarVisible) [window toggleToolbarShown:self];
129    [window setFrame:NSMakeRect(0,screenHeight-100,100,100) display:YES];
130
131    // grab time.
132    CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
133
134    // run test
135    for (int x = 0; x < 3; x++) {
136        for (float size = 100; size < 500.f; size += 20.f) {
137            [window setFrame:NSMakeRect(0, screenHeight-size, size, size) display:YES];
138        }
139    }
140
141    double elapsed = CFAbsoluteTimeGetCurrent() - start;
142
143    // log
144    NSLog(@"Window resize test: %fs", elapsed);
145
146    // restore
147    if (toolbarVisible) [window toggleToolbarShown:self];
148    [window setFrame:originalFrame display:YES];
149}
150
151@end
152