found!
return [[[DOMHTMLElement alloc] _initWithName:@"#dummy#tr" namespaceURI:nil] autorelease]; // return dummy
}
- (void) _elementDidAwakeFromDocumentRepresentation:(_WebHTMLDocumentRepresentation *) rep;
{
// add to rows collection of table so that we can handle row numbers correctly
[super _elementDidAwakeFromDocumentRepresentation:rep];
}
@end
@implementation DOMHTMLTableCellElement
- (NSString *) _string; { return @"\n"; } // each cell creates a line
- (void) _addAttributesToStyle;
{ // add attributes to style
NSMutableParagraphStyle *paragraph=[[_style objectForKey:NSParagraphStyleAttributeName] mutableCopy];
NSMutableArray *blocks;
NSTextTableBlock *cell;
DOMHTMLTableElement *tableElement;
NSTextTable *table; // the table we belong to
int row, col;
int rowspan, colspan;
tableElement=(DOMHTMLTableElement *) self;
while(tableElement && ![tableElement isKindOfClass:[DOMHTMLTableElement class]])
tableElement=(DOMHTMLTableElement *)[tableElement parentNode]; // go one level up
table=[tableElement _getRow:&row andColumn:&col rowSpan:&rowspan colSpan:&colspan forCell:self]; // ask tableElement for our position
if(!table)
{ // we are not within a table
[paragraph release];
return; // error...
}
if(col+colspan-1 > [table numberOfColumns])
[table setNumberOfColumns:col+colspan-1]; // adjust number of columns of our enclosing table
cell=[[NSClassFromString(@"NSTextTableBlock") alloc] initWithTable:table
startingRow:row
rowSpan:rowspan
startingColumn:col
columnSpan:colspan];
[(NSTextBlock *) cell _setTextBlockAttributes:self paragraph:paragraph];
if([[self nodeName] isEqualToString:@"TH"])
{ // make centered and bold paragraph for header cells
NSFont *f=[_style objectForKey:NSFontAttributeName]; // get current font
f=[[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask];
if(f) [_style setObject:f forKey:NSFontAttributeName];
[paragraph setAlignment:NSCenterTextAlignment]; // modify alignment
}
blocks=(NSMutableArray *) [paragraph textBlocks]; // the text blocks
if(!blocks) // didn't inherit text blocks (i.e. outermost table)
blocks=[[NSMutableArray alloc] initWithCapacity:2]; // rarely needs more nesting
else
blocks=[blocks mutableCopy];
[blocks addObject:cell]; // add to list of text blocks
[paragraph setTextBlocks:blocks]; // add to paragraph style
[cell release];
[blocks release]; // was either mutableCopy or alloc/initWithCapacity
#if 0
NSLog(@"| _style=%@", _style);
#endif
[_style setObject:paragraph forKey:NSParagraphStyleAttributeName];
[paragraph release];
}
@end
@implementation DOMHTMLFormElement
- (id) init
{
if((self = [super init]))
{
elements=[DOMHTMLCollection new];
}
return self;
}
- (void) dealloc
{
[elements release];
[super dealloc];
}
+ (DOMHTMLNestingStyle) _nesting; { return DOMHTMLStandardNesting; }
- (void) _addAttributesToStyle;
{ // add attributes to style
[_style setObject:@"block" forKey:DOMHTMLBlockInlineLevel];
}
- (void) _elementDidAwakeFromDocumentRepresentation:(_WebHTMLDocumentRepresentation *) rep;
{
[[(DOMHTMLDocument *) [self ownerDocument] forms] appendChild:self]; // add to Forms[] DOM Level 0 list
[super _elementDidAwakeFromDocumentRepresentation:rep];
}
- (DOMHTMLCollection *) elements { return elements; }
- (void) _submitForm:(DOMHTMLElement *) clickedElement;
{ // post current request
NSMutableURLRequest *request;
DOMHTMLDocument *htmlDocument;
NSString *action;
NSString *method;
NSString *target;
NSMutableString *r;
NSEnumerator *e;
DOMHTMLElement *element;
BOOL post;
[self _triggerEvent:@"onsubmit"];
// can the trigger abort sending the form? Through an exception?
htmlDocument=(DOMHTMLDocument *) [self ownerDocument]; // may have been changed by the onsubmit script
action=[self valueForKey:@"action"];
method=[self valueForKey:@"method"];
target=[self valueForKey:@"target"];
if(!action)
action=@""; // we simply reuse the current - FIXME: we should remove all ? components
#if 1
NSLog(@"method = %@", method);
#endif
post=(method && [method caseInsensitiveCompare:@"post"] == NSOrderedSame);
r=[NSMutableString stringWithCapacity:100];
e=[[elements valueForKey:@"elements"] objectEnumerator];
while((element=[e nextObject]))
{
NSString *name;
NSString *val=[(DOMHTMLInputElement *) element _formValue]; // should be [element valueForKey:@"value"]; but then we need to handle active elements here
// but we may need anyway since a defines more than one variable!
NSMutableArray *a;
NSEnumerator *e;
NSMutableString *s;
if(!val)
continue;
name=[element valueForKey:@"name"];
if(!name)
continue;
a=[[NSMutableArray alloc] initWithCapacity:10];
e=[[val componentsSeparatedByString:@"+"] objectEnumerator];
while((s=[e nextObject]))
{ // URL-Encode components
#if 1
NSLog(@"percent-escaping: %@ -> %@", s, [s stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding]);
#endif
s=[[s stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding] mutableCopy];
[s replaceOccurrencesOfString:@" " withString:@"+" options:0 range:NSMakeRange(0, [s length])];
// CHECKME: which of these are already converted by stringByAddingPercentEscapesUsingEncoding?
[s replaceOccurrencesOfString:@"&" withString:@"%26" options:0 range:NSMakeRange(0, [s length])];
[s replaceOccurrencesOfString:@"?" withString:@"%3F" options:0 range:NSMakeRange(0, [s length])];
[s replaceOccurrencesOfString:@"-" withString:@"%3D" options:0 range:NSMakeRange(0, [s length])];
[s replaceOccurrencesOfString:@";" withString:@"%3B" options:0 range:NSMakeRange(0, [s length])];
[s replaceOccurrencesOfString:@"," withString:@"%2C" options:0 range:NSMakeRange(0, [s length])];
[a addObject:s];
[s release];
}
val=[a componentsJoinedByString:@"%2B"];
[a release];
[r appendFormat:[r length] > 0?@"&%@=%@":@"%@=%@", name, val]; // separate by &
}
if(!post && [r length] > 0)
{
#if 1
NSLog(@"getURL = %@", r);
#endif
action=[action stringByAppendingFormat:@"?%@", r];
#if 1
NSLog(@"action = %@", action);
#endif
// FIXME: remove any existing ?query part and replace
}
request=(NSMutableURLRequest *)[NSMutableURLRequest requestWithURL:[NSURL URLWithString:action relativeToURL:[[[htmlDocument _webDataSource] response] URL]]];
if(method)
[request setHTTPMethod:[method uppercaseString]]; // will default to "GET" if missing
if(post)
{
#if 1
NSLog(@"post = %@", [r dataUsingEncoding:NSUTF8StringEncoding]);
#endif
[request setHTTPBody:[r dataUsingEncoding:NSUTF8StringEncoding]];
}
#if 1
NSLog(@"submit |