[webkit-changes] cvs commit: WebKit/WebView.subproj
WebHTMLRepresentation.h WebHTMLRepresentation.m
John
sullivan at opensource.apple.com
Fri Jul 29 14:16:57 PDT 2005
sullivan 05/07/29 14:16:56
Modified: . ChangeLog
khtml/html html_formimpl.cpp
kwq DOMHTML.mm DOMPrivate.h WebCoreBridge.h
WebCoreBridge.mm
. ChangeLog
WebView.subproj WebHTMLRepresentation.h
WebHTMLRepresentation.m
Log:
WebCore:
Reviewed by Dave Hyatt.
Test cases added: none, this only affects Safari forms autofill
- WebCore part of <rdar://problem/4187404> Redo form SPI so that it doesn't rely on NSViews
* khtml/html/html_formimpl.cpp:
added a FIXME about a bug I ran into while doing this autofill stuff
* kwq/DOMHTML.mm:
(viewForElement):
Moved this function here (was in WebCoreBridge), and simplified it a little. This will go
away when we have non-NSView ways of implementing all the methods below.
(-[DOMHTMLInputElement _displayedValue]):
moved here from Safari
(-[DOMHTMLInputElement _setDisplayedValue:]):
ditto
(-[DOMHTMLInputElement _rectOnScreen]):
ditto
(-[DOMHTMLInputElement _replaceCharactersInRange:withString:selectingFromIndex:]):
ditto
(-[DOMHTMLInputElement _selectedRange]):
ditto
(-[DOMHTMLInputElement _setBackgroundColor:]):
ditto
(-[DOMHTMLSelectElement _activateItemAtIndex:]):
ditto
(-[DOMHTMLSelectElement _optionLabels]):
ditto
* kwq/DOMPrivate.h:
moved DOMHTMLInputElement and DOMHTMLSelectElement categories here from Safari
* kwq/WebCoreBridge.h:
* kwq/WebCoreBridge.mm:
removed viewForElement:, which had been added as a temporary measure while I did this conversion.
WebKit:
Reviewed by Dave Hyatt.
- WebKit part of <rdar://problem/4187404> Redo form SPI so that it doesn't rely on NSViews
Much of 4187404 was addressed in earlier checkins. This checkin completes the task.
* WebView.subproj/WebHTMLRepresentation.h:
* WebView.subproj/WebHTMLRepresentation.m:
removed viewForElement:, which was the only remaining NSView-related SPI that Safari autofill was
still using. I added viewForElement a week ago as a transitional measure, so removing it won't
affect any other clients.
Revision Changes Path
1.4492 +39 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.4491
retrieving revision 1.4492
diff -u -r1.4491 -r1.4492
--- ChangeLog 29 Jul 2005 20:22:48 -0000 1.4491
+++ ChangeLog 29 Jul 2005 21:16:42 -0000 1.4492
@@ -1,3 +1,42 @@
+2005-07-29 John Sullivan <sullivan at apple.com>
+
+ Reviewed by Dave Hyatt.
+
+ Test cases added: none, this only affects Safari forms autofill
+
+ - WebCore part of <rdar://problem/4187404> Redo form SPI so that it doesn't rely on NSViews
+
+ * khtml/html/html_formimpl.cpp:
+ added a FIXME about a bug I ran into while doing this autofill stuff
+
+ * kwq/DOMHTML.mm:
+ (viewForElement):
+ Moved this function here (was in WebCoreBridge), and simplified it a little. This will go
+ away when we have non-NSView ways of implementing all the methods below.
+ (-[DOMHTMLInputElement _displayedValue]):
+ moved here from Safari
+ (-[DOMHTMLInputElement _setDisplayedValue:]):
+ ditto
+ (-[DOMHTMLInputElement _rectOnScreen]):
+ ditto
+ (-[DOMHTMLInputElement _replaceCharactersInRange:withString:selectingFromIndex:]):
+ ditto
+ (-[DOMHTMLInputElement _selectedRange]):
+ ditto
+ (-[DOMHTMLInputElement _setBackgroundColor:]):
+ ditto
+ (-[DOMHTMLSelectElement _activateItemAtIndex:]):
+ ditto
+ (-[DOMHTMLSelectElement _optionLabels]):
+ ditto
+
+ * kwq/DOMPrivate.h:
+ moved DOMHTMLInputElement and DOMHTMLSelectElement categories here from Safari
+
+ * kwq/WebCoreBridge.h:
+ * kwq/WebCoreBridge.mm:
+ removed viewForElement:, which had been added as a temporary measure while I did this conversion.
+
2005-07-29 Eric Seidel <eseidel at apple.com>
Reviewed by sullivan.
1.180 +2 -0 WebCore/khtml/html/html_formimpl.cpp
Index: html_formimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_formimpl.cpp,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -r1.179 -r1.180
--- html_formimpl.cpp 29 Jul 2005 02:40:40 -0000 1.179
+++ html_formimpl.cpp 29 Jul 2005 21:16:50 -0000 1.180
@@ -2937,6 +2937,8 @@
return optionIndex;
}
+// FIXME 4197997: this method is used by the public API -[DOMHTMLSelectElement options], but always returns
+// an empty list.
HTMLOptionsCollectionImpl *HTMLSelectElementImpl::options()
{
if (!m_options) {
1.23 +137 -0 WebCore/kwq/DOMHTML.mm
Index: DOMHTML.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/DOMHTML.mm,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- DOMHTML.mm 22 Jul 2005 18:09:22 -0000 1.22
+++ DOMHTML.mm 29 Jul 2005 21:16:50 -0000 1.23
@@ -3989,3 +3989,140 @@
}
@end
+
+// These #imports and "usings" are used only by viewForElement and should be deleted
+// when that function goes away.
+#import "render_object.h"
+#import "render_replaced.h"
+using khtml::RenderObject;
+using khtml::RenderWidget;
+
+// This function is used only by the two FormAutoFillTransition categories, and will go away
+// as soon as possible.
+static NSView *viewForElement(DOMElement *element)
+{
+ RenderObject *renderer = [element _elementImpl]->renderer();
+ if (renderer && renderer->isWidget()) {
+ QWidget *widget = static_cast<const RenderWidget *>(renderer)->widget();
+ if (widget) {
+ widget->populate();
+ return widget->getView();
+ }
+ }
+ return nil;
+}
+
+ at implementation DOMHTMLInputElement(FormAutoFillTransition)
+
+- (NSString *)_displayedValue
+{
+ // Seems like we could just call [_element value] here but doing so messes up autofill (when you type in
+ // a form and it autocompletes, the autocompleted part of the text isn't left selected; instead the insertion
+ // point appears between what you typed and the autocompleted part of the text). I think the DOM element's
+ // stored value isn't updated until the text in the field is committed when losing focus or perhaps on Enter.
+ // Maybe when we switch over to not using NSTextField here then [_element value] will be good enough and
+ // we can get rid of this method.
+ return [(NSTextField *)viewForElement(self) stringValue];
+}
+
+- (void)_setDisplayedValue:(NSString *)newValue
+{
+ // This method is used by autofill and needs to work even when the field is currently being edited.
+ NSTextField *field = (NSTextField *)viewForElement(self);
+ NSText *fieldEditor = [field currentEditor];
+ if (fieldEditor != nil) {
+ [fieldEditor setString:newValue];
+ [(NSTextView *)fieldEditor didChangeText];
+ } else {
+ // Not currently being edited, so we can set the string the simple way. Note that we still can't
+ // just use [self setValue:] here because it would break background-color-setting in the current
+ // autofill code. When we've adopted a new way to set the background color to indicate autofilled
+ // fields, then this case at least can probably change to [self setValue:].
+ [field setStringValue:newValue];
+ }
+}
+
+- (NSRect)_rectOnScreen
+{
+ // Returns bounding rect of text field, in screen coordinates.
+ // FIXME: need a way to determine bounding rect for DOMElements before we can convert this code to
+ // not use views. Hyatt says we need to add offsetLeft/offsetTop/width/height to DOMExtensions, but
+ // then callers would need to walk up the offsetParent chain to determine real coordinates. So we
+ // probably need to (also?) add some call(s) to get the absolute origin.
+ NSTextField *field = (NSTextField *)viewForElement(self);
+ ASSERT(field != nil);
+ NSRect result = [field bounds];
+ if ([field isFlipped]) {
+ result.origin.y += result.size.height;
+ }
+ result.origin = [field convertPoint:result.origin toView:nil];
+ result.origin = [[field window] convertBaseToScreen:result.origin];
+ return result;
+}
+
+- (void)_replaceCharactersInRange:(NSRange)targetRange withString:(NSString *)replacementString selectingFromIndex:(int)index
+{
+ NSText *fieldEditor = [(NSTextField *)viewForElement(self) currentEditor];
+ [fieldEditor replaceCharactersInRange:targetRange withString:replacementString];
+
+ NSRange selectRange;
+ selectRange.location = index;
+ selectRange.length = [[self _displayedValue] length] - selectRange.location;
+ [fieldEditor setSelectedRange:selectRange];
+
+ [(NSTextView *)fieldEditor didChangeText];
+}
+
+- (NSRange)_selectedRange
+{
+ NSText *editor = [(NSTextField *)viewForElement(self) currentEditor];
+ if (editor == nil) {
+ return NSMakeRange(NSNotFound, 0);
+ }
+
+ return [editor selectedRange];
+}
+
+- (void)_setBackgroundColor:(NSColor *)color
+{
+ // We currently have no DOM-aware way of setting the background color of a text field.
+ // Safari autofill uses this method, which is fragile because there's no guarantee that
+ // the color set here won't be clobbered by other WebCore code. However, it works OK for
+ // Safari autofill's purposes right now. When we switch over to using DOMElements for
+ // form controls, we'll probably need a CSS pseudoclass to make this work.
+ [(NSTextField *)viewForElement(self) setBackgroundColor:color];
+}
+
+ at end
+
+ at implementation DOMHTMLSelectElement(FormAutoFillTransition)
+
+- (void)_activateItemAtIndex:(int)index
+{
+ NSPopUpButton *popUp = (NSPopUpButton *)viewForElement(self);
+ [popUp selectItemAtIndex:index];
+ // Must do this to simulate same side effect as if user made the choice
+ [NSApp sendAction:[popUp action] to:[popUp target] from:popUp];
+}
+
+- (NSArray *)_optionLabels
+{
+ // FIXME 4197997: This code should work, and when it does we can eliminate this method entirely
+ // and just have the only current caller (in Safari autofill code) embed this code directly.
+ // But at the moment -[DOMHTMLSelectElement options] always returns an empty collection.
+#if 0
+ DOMHTMLOptionsCollection *options = [self options];
+ NSMutableArray *optionLabels = [NSMutableArray array];
+ int itemCount = [options length];
+ int itemIndex;
+ for (itemIndex = 0; itemIndex < itemCount; ++itemIndex) {
+ [optionLabels addObject:[(DOMHTMLOptionElement *)[options item:itemIndex] label]];
+ }
+ return optionLabels;
+#endif
+
+ // Due to the DOM API brokenness, for now we have to get the titles from the view
+ return [(NSPopUpButton *)viewForElement(self) itemTitles];
+}
+
+ at end
1.7 +23 -0 WebCore/kwq/DOMPrivate.h
Index: DOMPrivate.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/DOMPrivate.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DOMPrivate.h 7 Mar 2005 22:04:17 -0000 1.6
+++ DOMPrivate.h 29 Jul 2005 21:16:51 -0000 1.7
@@ -49,3 +49,26 @@
- (DOMDocumentFragment *)_createDocumentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString;
- (DOMDocumentFragment *)_createDocumentFragmentWithText:(NSString *)text;
@end
+
+// All the methods in this category are used by Safari forms autofill and should not be used for any other purpose.
+// They are stopgap measures until we finish transitioning form controls to not use NSView. Each one should become
+// replaceable by public DOM API, and when that happens Safari will switch to implementations using that public API,
+// and these will be deleted.
+ at interface DOMHTMLInputElement(FormsAutoFillTransition)
+- (NSString *)_displayedValue; // the string currently displayed in the field, even when the field is being edited
+- (void)_setDisplayedValue:(NSString *)newValue; // set the value displayed, even when the field is being edited
+- (NSRect)_rectOnScreen; // bounding box of the text field, in screen coordinates
+- (void)_replaceCharactersInRange:(NSRange)targetRange withString:(NSString *)replacementString selectingFromIndex:(int)index;
+- (NSRange)_selectedRange;
+- (void)_setBackgroundColor:(NSColor *)color;
+ at end
+
+// All the methods in this category are used by Safari forms autofill and should not be used for any other purpose.
+// They are stopgap measures until we finish transitioning form controls to not use NSView. Each one should become
+// replaceable by public DOM API, and when that happens Safari will switch to implementations using that public API,
+// and these will be deleted.
+ at interface DOMHTMLSelectElement(FormsAutoFillTransition)
+- (void)_activateItemAtIndex:(int)index;
+- (NSArray *)_optionLabels;
+ at end
+
1.343 +0 -1 WebCore/kwq/WebCoreBridge.h
Index: WebCoreBridge.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/WebCoreBridge.h,v
retrieving revision 1.342
retrieving revision 1.343
diff -u -r1.342 -r1.343
--- WebCoreBridge.h 26 Jul 2005 17:37:21 -0000 1.342
+++ WebCoreBridge.h 29 Jul 2005 21:16:51 -0000 1.343
@@ -285,7 +285,6 @@
- (DOMElement *)elementWithName:(NSString *)name inForm:(DOMElement *)form;
- (DOMElement *)elementForView:(NSView *)view;
-- (NSView *)viewForElement:(DOMElement *)view; // introduced temporarily to ease transition to view-free form SPI
- (BOOL)elementDoesAutoComplete:(DOMElement *)element;
- (BOOL)elementIsPassword:(DOMElement *)element;
- (DOMElement *)formForElement:(DOMElement *)element;
1.406 +0 -18 WebCore/kwq/WebCoreBridge.mm
Index: WebCoreBridge.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/WebCoreBridge.mm,v
retrieving revision 1.405
retrieving revision 1.406
diff -u -r1.405 -r1.406
--- WebCoreBridge.mm 28 Jul 2005 20:47:29 -0000 1.405
+++ WebCoreBridge.mm 29 Jul 2005 21:16:51 -0000 1.406
@@ -895,24 +895,6 @@
return nil;
}
-static NSView *viewForElement(ElementImpl *elementImpl)
-{
- RenderObject *renderer = elementImpl->renderer();
- if (renderer && renderer->isWidget()) {
- QWidget *widget = static_cast<const RenderWidget *>(renderer)->widget();
- if (widget) {
- widget->populate();
- return widget->getView();
- }
- }
- return nil;
-}
-
-- (NSView *)viewForElement:(DOMElement *)element
-{
- return viewForElement([element _elementImpl]);
-}
-
static HTMLInputElementImpl *inputElementFromDOMElement(DOMElement *element)
{
NodeImpl *node = [element _nodeImpl];
1.3266 +14 -0 WebKit/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebKit/ChangeLog,v
retrieving revision 1.3265
retrieving revision 1.3266
diff -u -r1.3265 -r1.3266
--- ChangeLog 29 Jul 2005 21:01:35 -0000 1.3265
+++ ChangeLog 29 Jul 2005 21:16:53 -0000 1.3266
@@ -1,5 +1,19 @@
2005-07-29 John Sullivan <sullivan at apple.com>
+ Reviewed by Dave Hyatt.
+
+ - WebKit part of <rdar://problem/4187404> Redo form SPI so that it doesn't rely on NSViews
+
+ Much of 4187404 was addressed in earlier checkins. This checkin completes the task.
+
+ * WebView.subproj/WebHTMLRepresentation.h:
+ * WebView.subproj/WebHTMLRepresentation.m:
+ removed viewForElement:, which was the only remaining NSView-related SPI that Safari autofill was
+ still using. I added viewForElement a week ago as a transitional measure, so removing it won't
+ affect any other clients.
+
+2005-07-29 John Sullivan <sullivan at apple.com>
+
Reviewed by Chris Blumenberg.
* WebView.subproj/WebFrameView.m:
1.30 +0 -1 WebKit/WebView.subproj/WebHTMLRepresentation.h
Index: WebHTMLRepresentation.h
===================================================================
RCS file: /cvs/root/WebKit/WebView.subproj/WebHTMLRepresentation.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- WebHTMLRepresentation.h 28 Jul 2005 20:30:37 -0000 1.29
+++ WebHTMLRepresentation.h 29 Jul 2005 21:16:56 -0000 1.30
@@ -51,7 +51,6 @@
- (NSAttributedString *)attributedStringFrom:(DOMNode *)startNode startOffset:(int)startOffset to:(DOMNode *)endNode endOffset:(int)endOffset;
- (DOMElement *)elementWithName:(NSString *)name inForm:(DOMElement *)form;
-- (NSView *)viewForElement:(DOMElement *)element; // introduced temporarily to ease transition to view-free form SPI
- (BOOL)elementDoesAutoComplete:(DOMElement *)element;
- (BOOL)elementIsPassword:(DOMElement *)element;
- (DOMElement *)formForElement:(DOMElement *)element;
1.57 +0 -5 WebKit/WebView.subproj/WebHTMLRepresentation.m
Index: WebHTMLRepresentation.m
===================================================================
RCS file: /cvs/root/WebKit/WebView.subproj/WebHTMLRepresentation.m,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- WebHTMLRepresentation.m 28 Jul 2005 20:30:37 -0000 1.56
+++ WebHTMLRepresentation.m 29 Jul 2005 21:16:56 -0000 1.57
@@ -208,11 +208,6 @@
return [_private->bridge elementWithName:name inForm:form];
}
-- (NSView *)viewForElement:(DOMElement *)element
-{
- return [_private->bridge viewForElement:element];
-}
-
- (BOOL)elementDoesAutoComplete:(DOMElement *)element
{
return [_private->bridge elementDoesAutoComplete:element];
More information about the webkit-changes
mailing list