2
* Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
3
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
31
#import "DOMExtensions.h"
32
#import "DOMInternal.h"
33
#import "DOMPrivate.h"
34
#import "DocumentFragment.h"
36
#import "HTMLDocument.h"
37
#import "HTMLInputElement.h"
38
#import "HTMLObjectElement.h"
41
#import "RenderTextControl.h"
44
//------------------------------------------------------------------------------------------
47
@implementation DOMHTMLDocument (DOMHTMLDocumentExtensions)
49
- (DOMDocumentFragment *)createDocumentFragmentWithMarkupString:(NSString *)markupString baseURL:(NSURL *)baseURL
51
return [DOMDocumentFragment _wrapDocumentFragment:createFragmentFromMarkup([self _document], markupString, [baseURL absoluteString]).get()];
54
- (DOMDocumentFragment *)createDocumentFragmentWithText:(NSString *)text
56
// FIXME: Since this is not a contextual fragment, it won't handle whitespace properly.
57
return [DOMDocumentFragment _wrapDocumentFragment:createFragmentFromText([self _document]->createRange().get(), text).get()];
62
@implementation DOMHTMLDocument (WebPrivate)
64
- (DOMDocumentFragment *)_createDocumentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString
66
NSURL *baseURL = WebCore::KURL([self _document]->completeURL(WebCore::parseURL(baseURLString)).deprecatedString()).getNSURL();
67
return [self createDocumentFragmentWithMarkupString:markupString baseURL:baseURL];
70
- (DOMDocumentFragment *)_createDocumentFragmentWithText:(NSString *)text
72
return [self createDocumentFragmentWithText:text];
77
#pragma mark DOM EXTENSIONS
79
@implementation DOMHTMLInputElement(FormAutoFillTransition)
83
// We could make this public API as-is, or we could change it into a method that returns whether
84
// the element is a text field or a button or ... ?
85
static NSArray *textInputTypes = nil;
87
static NSArray *nonTextInputTypes = nil;
90
NSString *fieldType = [self type];
92
// No type at all is treated as text type
93
if ([fieldType length] == 0)
96
if (textInputTypes == nil)
97
textInputTypes = [[NSSet alloc] initWithObjects:@"text", @"password", @"search", @"isindex", nil];
99
BOOL isText = [textInputTypes containsObject:[fieldType lowercaseString]];
102
if (nonTextInputTypes == nil)
103
nonTextInputTypes = [[NSSet alloc] initWithObjects:@"checkbox", @"radio", @"submit", @"reset", @"file", @"hidden", @"image", @"button", @"range", nil];
105
// Catch cases where a new input type has been added that's not in these lists.
106
ASSERT(isText || [nonTextInputTypes containsObject:[fieldType lowercaseString]]);
112
- (NSRect)_rectOnScreen
114
// Returns bounding rect of text field, in screen coordinates.
115
NSRect result = [self boundingBox];
116
if (![self _HTMLInputElement]->document()->view())
119
NSView* view = [self _HTMLInputElement]->document()->view()->getDocumentView();
120
result = [view convertRect:result toView:nil];
121
result.origin = [[view window] convertBaseToScreen:result.origin];
125
- (void)_replaceCharactersInRange:(NSRange)targetRange withString:(NSString *)replacementString selectingFromIndex:(int)index
127
WebCore::HTMLInputElement* inputElement = [self _HTMLInputElement];
129
WebCore::String newValue = inputElement->value();
130
newValue.replace(targetRange.location, targetRange.length, replacementString);
131
inputElement->setValue(newValue);
132
inputElement->setSelectionRange(index, newValue.length());
136
- (NSRange)_selectedRange
138
WebCore::HTMLInputElement* inputElement = [self _HTMLInputElement];
140
int start = inputElement->selectionStart();
141
int end = inputElement->selectionEnd();
142
return NSMakeRange(start, end - start);
144
return NSMakeRange(NSNotFound, 0);
147
- (void)_setAutofilled:(BOOL)filled
149
// This notifies the input element that the content has been autofilled
150
// This allows WebKit to obey the -webkit-autofill pseudo style, which
151
// changes the background color.
152
WebCore::HTMLInputElement* inputElement = [self _HTMLInputElement];
154
inputElement->setAutofilled(filled);
159
@implementation DOMHTMLSelectElement(FormAutoFillTransition)
161
- (void)_activateItemAtIndex:(int)index
163
// FIXME: Needs implementation for non-NSView <select>!
168
@implementation DOMHTMLInputElement (FormPromptAdditions)
171
WebCore::RenderObject *renderer = [self _node]->renderer();
172
if (renderer && [self _isTextField])
173
return static_cast<WebCore::RenderTextControl *>(renderer)->isUserEdited();
179
@implementation DOMHTMLTextAreaElement (FormPromptAdditions)
182
WebCore::RenderObject *renderer = [self _node]->renderer();
184
return static_cast<WebCore::RenderTextControl *>(renderer)->isUserEdited();