[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
trey
trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:27:29 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 8b0a3da311d76ce780a2e2fc1b492c801fc86a5d
Author: trey <trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Mar 5 07:18:49 2003 +0000
WebCore:
New support for autofill. We provide a routine that scans backwards in the text
before a given element, looking for a match with a set of labels. In addition,
we provide for a similar match against the element's name.
To implement a few more methods in QRegExp API were implemented.
Reviewed by Maciej.
* kwq/KWQKHTMLPart.h:
* kwq/KWQKHTMLPart.mm:
(scanForForm): Remove redundant call to a helper function.
(regExpForLabels): Return a regexp used to search for the set of labels.
(KWQKHTMLPart::searchForLabelsBeforeElement): Walk the DOM to scan backwards
in the text before the element, apply regexp to the text we find.
(KWQKHTMLPart::matchLabelsAgainstElement): Get the element name, use regexp
to check it for any of the labels.
* kwq/KWQRegExp.h:
* kwq/KWQRegExp.mm:
(QRegExp::KWQRegExpPrivate::KWQRegExpPrivate): Init two new ivars.
(RegExpFromPattern): Massage a non-glob expression before handing to Darwin.
(QRegExp::KWQRegExpPrivate::compile): Call RegExpFromPattern.
(QRegExp::match): Set new ivars based on match result.
(QRegExp::search): New API, just call match.
(QRegExp::searchRev): New API, call match repeatedly to (weakly) simulate a
reverse search.
(QRegExp::pos): Return info from last result.
(QRegExp::matchedLength): Return info from last result.
* kwq/WebCoreBridge.h:
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge searchForLabels:beforeElement:]): Call straight through to part.
(-[WebCoreBridge matchLabels:againstElement:]): Call straight through to part.
WebKit:
Support for autofill. These are just two new glue routines
that call down through the bridge. They allow regexp driven
binding of AB data to form elements.
Reviewed by Maciej.
* WebView.subproj/WebHTMLRepresentation.h:
* WebView.subproj/WebHTMLRepresentation.m:
(-[WebHTMLRepresentation searchForLabels:beforeElement:]):
Call straight to bridge.
(-[WebHTMLRepresentation matchLabels:againstElement:]):
Call straight to bridge.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 8200913..22eb0ed 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,37 @@
+2003-03-04 Trey Matteson <trey at apple.com>
+
+ New support for autofill. We provide a routine that scans backwards in the text
+ before a given element, looking for a match with a set of labels. In addition,
+ we provide for a similar match against the element's name.
+
+ To implement a few more methods in QRegExp API were implemented.
+
+ Reviewed by Maciej.
+
+ * kwq/KWQKHTMLPart.h:
+ * kwq/KWQKHTMLPart.mm:
+ (scanForForm): Remove redundant call to a helper function.
+ (regExpForLabels): Return a regexp used to search for the set of labels.
+ (KWQKHTMLPart::searchForLabelsBeforeElement): Walk the DOM to scan backwards
+ in the text before the element, apply regexp to the text we find.
+ (KWQKHTMLPart::matchLabelsAgainstElement): Get the element name, use regexp
+ to check it for any of the labels.
+ * kwq/KWQRegExp.h:
+ * kwq/KWQRegExp.mm:
+ (QRegExp::KWQRegExpPrivate::KWQRegExpPrivate): Init two new ivars.
+ (RegExpFromPattern): Massage a non-glob expression before handing to Darwin.
+ (QRegExp::KWQRegExpPrivate::compile): Call RegExpFromPattern.
+ (QRegExp::match): Set new ivars based on match result.
+ (QRegExp::search): New API, just call match.
+ (QRegExp::searchRev): New API, call match repeatedly to (weakly) simulate a
+ reverse search.
+ (QRegExp::pos): Return info from last result.
+ (QRegExp::matchedLength): Return info from last result.
+ * kwq/WebCoreBridge.h:
+ * kwq/WebCoreBridge.mm:
+ (-[WebCoreBridge searchForLabels:beforeElement:]): Call straight through to part.
+ (-[WebCoreBridge matchLabels:againstElement:]): Call straight through to part.
+
2003-03-04 Darin Adler <darin at apple.com>
Reviewed by Maciej.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 8200913..22eb0ed 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,37 @@
+2003-03-04 Trey Matteson <trey at apple.com>
+
+ New support for autofill. We provide a routine that scans backwards in the text
+ before a given element, looking for a match with a set of labels. In addition,
+ we provide for a similar match against the element's name.
+
+ To implement a few more methods in QRegExp API were implemented.
+
+ Reviewed by Maciej.
+
+ * kwq/KWQKHTMLPart.h:
+ * kwq/KWQKHTMLPart.mm:
+ (scanForForm): Remove redundant call to a helper function.
+ (regExpForLabels): Return a regexp used to search for the set of labels.
+ (KWQKHTMLPart::searchForLabelsBeforeElement): Walk the DOM to scan backwards
+ in the text before the element, apply regexp to the text we find.
+ (KWQKHTMLPart::matchLabelsAgainstElement): Get the element name, use regexp
+ to check it for any of the labels.
+ * kwq/KWQRegExp.h:
+ * kwq/KWQRegExp.mm:
+ (QRegExp::KWQRegExpPrivate::KWQRegExpPrivate): Init two new ivars.
+ (RegExpFromPattern): Massage a non-glob expression before handing to Darwin.
+ (QRegExp::KWQRegExpPrivate::compile): Call RegExpFromPattern.
+ (QRegExp::match): Set new ivars based on match result.
+ (QRegExp::search): New API, just call match.
+ (QRegExp::searchRev): New API, call match repeatedly to (weakly) simulate a
+ reverse search.
+ (QRegExp::pos): Return info from last result.
+ (QRegExp::matchedLength): Return info from last result.
+ * kwq/WebCoreBridge.h:
+ * kwq/WebCoreBridge.mm:
+ (-[WebCoreBridge searchForLabels:beforeElement:]): Call straight through to part.
+ (-[WebCoreBridge matchLabels:againstElement:]): Call straight through to part.
+
2003-03-04 Darin Adler <darin at apple.com>
Reviewed by Maciej.
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index 5cb89c1..a5811ce 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -51,6 +51,8 @@ namespace KJS {
@class NSView;
@class WebCoreBridge;
@class KWQPageState;
+ at class NSString;
+ at class NSArray;
@class NSMutableDictionary;
@class WebCoreDOMElement;
#else
@@ -60,6 +62,8 @@ class NSResponder;
class NSView;
class WebCoreBridge;
class KWQPageState;
+class NSString;
+class NSArray;
class NSMutableDictionary;
class WebCoreDOMElement;
#endif
@@ -181,7 +185,10 @@ public:
void clearRecordedFormValues();
void recordFormValue(const QString &name, const QString &value, DOM::HTMLFormElementImpl *element);
DOM::HTMLFormElementImpl *currentForm() const;
-
+
+ NSString *searchForLabelsBeforeElement(NSArray *labels, DOM::ElementImpl *element);
+ NSString *matchLabelsAgainstElement(NSArray *labels, DOM::ElementImpl *element);
+
void setSettings (KHTMLSettings *s);
private:
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 3a4c7de..90c1f73 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -33,6 +33,7 @@
#import "khtmlpart_p.h"
#import "khtmlview.h"
#import "kjs_window.h"
+#import "misc/htmlattrs.h"
#import "WebCoreBridge.h"
#import "WebCoreViewFactory.h"
@@ -205,7 +206,7 @@ static HTMLFormElementImpl *scanForForm(NodeImpl *start)
NodeImpl *n;
for (n = start; n; n = n->traverseNextNode()) {
NodeImpl::Id nodeID = idFromNode(n);
- if (idFromNode(n) == ID_FORM) {
+ if (nodeID == ID_FORM) {
return static_cast<HTMLFormElementImpl *>(n);
} else if (n->isHTMLElement()
&& static_cast<HTMLElementImpl *>(n)->isGenericFormElement()) {
@@ -248,6 +249,132 @@ HTMLFormElementImpl *KWQKHTMLPart::currentForm() const
return scanForForm(start);
}
+// Either get cached regexp or build one that matches any of the labels.
+// The regexp we build is of the form: \b(STR1|STR2|STRN)\b
+QRegExp *regExpForLabels(NSArray *labels)
+{
+ // Parallel arrays that we use to cache regExps. In practice the number of expressions
+ // that the app will use is equal to the number of locales is used in searching.
+ static const unsigned int regExpCacheSize = 4;
+ static NSMutableArray *regExpLabels = nil;
+ static QPtrList <QRegExp> regExps;
+
+ QRegExp *result;
+ if (!regExpLabels) {
+ regExpLabels = [[NSMutableArray alloc] initWithCapacity:regExpCacheSize];
+ }
+ unsigned int cacheHit = [regExpLabels indexOfObject:labels];
+ if (cacheHit != NSNotFound) {
+ result = regExps.at(cacheHit);
+ } else {
+ QString pattern("\\b(");
+ unsigned int numLabels = [labels count];
+ unsigned int i;
+ for (i = 0; i < numLabels; i++) {
+ QString label = QString::fromNSString([labels objectAtIndex:i]);
+ if (i != 0) {
+ pattern.append("|");
+ }
+ pattern.append(label);
+ }
+ pattern.append(")\\b");
+ result = new QRegExp(pattern, false);
+ }
+
+ // add regexp to the cache, making sure it is at the front for LRU ordering
+ if (cacheHit != 0) {
+ if (cacheHit != NSNotFound) {
+ // remove from old spot
+ [regExpLabels removeObjectAtIndex:cacheHit];
+ regExps.remove(cacheHit);
+ }
+ // add to start
+ [regExpLabels insertObject:labels atIndex:0];
+ regExps.insert(0, result);
+ // trim if too big
+ if ([regExpLabels count] > regExpCacheSize) {
+ [regExpLabels removeObjectAtIndex:regExpCacheSize];
+ QRegExp *last = regExps.last();
+ regExps.removeLast();
+ delete last;
+ }
+ }
+ return result;
+}
+
+
+NSString *KWQKHTMLPart::searchForLabelsBeforeElement(NSArray *labels, DOM::ElementImpl *element)
+{
+ QRegExp *regExp = regExpForLabels(labels);
+ // We stop searching after we've seen this many chars
+ const unsigned int charsSearchedThreshold = 500;
+ // This is the absolute max we search. We allow a little more slop, to
+ // make it more likely that we'll search whole nodes
+ const unsigned int maxCharsSearched = 600;
+
+ // walk backwards in the node tree, until another element, or form, or end of tree
+ int unsigned lengthSearched = 0;
+ NodeImpl *n;
+ for (n = element->traversePreviousNode();
+ n && lengthSearched < charsSearchedThreshold;
+ n = n->traversePreviousNode())
+ {
+ NodeImpl::Id nodeID = idFromNode(n);
+ if (nodeID == ID_FORM
+ || (n->isHTMLElement()
+ && static_cast<HTMLElementImpl *>(n)->isGenericFormElement()))
+ {
+ // We hit another form element or the start of the form - bail out
+ break;
+ } else if (nodeID == ID_TEXT) {
+ // For each text chunk, run the regexp
+ //??? CDATA_SECTION_NODE too? See html_formimpl.cpp:2323
+ //??? must we have a renderer? See khtml_part.cpp:2036
+ QString nodeString = n->nodeValue().string();
+ // add 100 for slop, to make it more likely that we'll search whole nodes
+ if (lengthSearched + nodeString.length() > maxCharsSearched) {
+ nodeString = nodeString.right(charsSearchedThreshold - lengthSearched);
+ }
+ int pos = regExp->searchRev(nodeString);
+ if (pos >= 0) {
+ return nodeString.mid(pos, regExp->matchedLength()).getNSString();
+ } else {
+ lengthSearched += nodeString.length();
+ }
+ }
+ }
+ return nil;
+}
+
+NSString *KWQKHTMLPart::matchLabelsAgainstElement(NSArray *labels, DOM::ElementImpl *element)
+{
+ QString name = element->getAttribute(ATTR_NAME).string();
+ QRegExp *regExp = regExpForLabels(labels);
+ // Use the largest match we can find in the whole name string
+ int pos;
+ int length;
+ int bestPos = -1;
+ int bestLength = -1;
+ int start = 0;
+ do {
+ pos = regExp->search(name, start);
+ if (pos != -1) {
+ length = regExp->matchedLength();
+ if (length >= bestLength) {
+ bestPos = pos;
+ bestLength = length;
+ }
+ start = pos+1;
+ }
+ } while (pos != -1);
+
+ if (bestPos != -1) {
+ return name.mid(bestPos, bestLength).getNSString();
+ } else {
+ return nil;
+ }
+}
+
void KWQKHTMLPart::clearRecordedFormValues()
{
[_formValuesAboutToBeSubmitted release];
diff --git a/WebCore/kwq/KWQRegExp.h b/WebCore/kwq/KWQRegExp.h
index 42703ff..acd391c 100644
--- a/WebCore/kwq/KWQRegExp.h
+++ b/WebCore/kwq/KWQRegExp.h
@@ -43,6 +43,12 @@ public:
QString pattern() const;
int match(const QString &, int startFrom = 0, int *matchLength = 0, bool treatStartAsStartOfInput = true) const;
+ int search(const QString &, int startFrom = 0) const;
+ int searchRev(const QString &, int startFrom = -1) const;
+
+ int pos(int n = 0);
+ int matchedLength() const;
+
private:
class KWQRegExpPrivate;
KWQRefPtr<KWQRegExpPrivate> d;
diff --git a/WebCore/kwq/KWQRegExp.mm b/WebCore/kwq/KWQRegExp.mm
index 1da69cc..81e302a 100644
--- a/WebCore/kwq/KWQRegExp.mm
+++ b/WebCore/kwq/KWQRegExp.mm
@@ -25,6 +25,7 @@
#import "KWQRegExp.h"
+#import "KWQLogging.h"
#import <sys/types.h>
#import <regex.h>
@@ -43,6 +44,9 @@ public:
regex_t regex;
uint refCount;
+
+ int lastMatchPos;
+ int lastMatchLength;
};
QRegExp::KWQRegExpPrivate::KWQRegExpPrivate() : pattern(""), refCount(0)
@@ -50,7 +54,7 @@ QRegExp::KWQRegExpPrivate::KWQRegExpPrivate() : pattern(""), refCount(0)
compile(true, false);
}
-QRegExp::KWQRegExpPrivate::KWQRegExpPrivate(QString p, bool caseSensitive, bool glob) : pattern(p), refCount(0)
+QRegExp::KWQRegExpPrivate::KWQRegExpPrivate(QString p, bool caseSensitive, bool glob) : pattern(p), refCount(0), lastMatchPos(-1), lastMatchLength(-1)
{
compile(caseSensitive, glob);
}
@@ -78,6 +82,31 @@ static QString RegExpFromGlob(QString glob)
return result;
}
+static QString RegExpFromPattern(QString pattern)
+{
+ // map word boundary QRegExp assertion to RegEx beginning and end of word boundaries
+ // FIXME: Not sure how we would deal with \b appearing within a string.
+ int length = pattern.length();
+ if (length < 2) {
+ return pattern;
+ }
+
+ bool fixStart = (pattern[0] == '\\' && pattern[1] == 'b');
+ bool fixEnd = (pattern[length-2] == '\\' && pattern[length-1] == 'b');
+ if (fixStart || fixEnd) {
+ QString result = pattern;
+ if (fixStart) {
+ result.replace(0, 2, "[[:<:]]");
+ }
+ if (fixEnd) {
+ result.replace(result.length()-2, 2, "[[:>:]]");
+ }
+ return result;
+ } else {
+ return pattern;
+ }
+}
+
void QRegExp::KWQRegExpPrivate::compile(bool caseSensitive, bool glob)
{
QString p;
@@ -85,7 +114,7 @@ void QRegExp::KWQRegExpPrivate::compile(bool caseSensitive, bool glob)
if (glob) {
p = RegExpFromGlob(pattern);
} else {
- p = pattern;
+ p = RegExpFromPattern(pattern);
}
const char *cpattern = p.latin1();
@@ -150,11 +179,59 @@ int QRegExp::match(const QString &str, int startFrom, int *matchLength, bool tre
int result = regexec(&d->regex, cstring, 1, match, flags);
if (result != 0) {
+ d->lastMatchPos = -1;
+ d->lastMatchLength = -1;
return -1;
} else {
+ d->lastMatchPos = startFrom + match[0].rm_so;
+ d->lastMatchLength = match[0].rm_eo - match[0].rm_so;
if (matchLength != NULL) {
- *matchLength = match[0].rm_eo - match[0].rm_so;
+ *matchLength = d->lastMatchLength;
}
- return startFrom + match[0].rm_so;
+ return d->lastMatchPos;
}
}
+
+int QRegExp::search(const QString &str, int startFrom) const
+{
+ if (startFrom < 0) {
+ startFrom = str.length() - startFrom;
+ }
+ return match(str, startFrom, NULL, false);
+}
+
+int QRegExp::searchRev(const QString &str, int startFrom) const
+{
+ ASSERT(startFrom == -1);
+ // FIXME: Total hack for now. Search forward, return the last, greedy match
+ int start = 0;
+ int pos;
+ int lastPos = -1;
+ int lastMatchLength = -1;
+ do {
+ int matchLength;
+ pos = match(str, startFrom, &matchLength, start == 0);
+ if (pos >= 0) {
+ if ((pos+matchLength) > (lastPos+lastMatchLength)) {
+ // replace last match if this one is later and not a subset of the last match
+ lastPos = pos;
+ lastMatchLength = matchLength;
+ }
+ startFrom = pos + 1;
+ }
+ } while (pos != -1);
+ d->lastMatchPos = lastPos;
+ d->lastMatchLength = lastMatchLength;
+ return lastPos;
+}
+
+int QRegExp::pos(int n)
+{
+ ASSERT(n == 0);
+ return d->lastMatchPos;
+}
+
+int QRegExp::matchedLength() const
+{
+ return d->lastMatchLength;
+}
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index 9a4a0af..3e3500a 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -164,6 +164,8 @@ enum FrameBorderStyle {
- (id <WebDOMElement>)formForElement:(id <WebDOMElement>)element;
- (id <WebDOMElement>)currentForm;
- (NSArray *)controlsInForm:(id <WebDOMElement>)form;
+- (NSString *)searchForLabels:(NSArray *)labels beforeElement:(id <WebDOMElement>)element;
+- (NSString *)matchLabels:(NSArray *)labels againstElement:(id <WebDOMElement>)element;
- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag;
- (void)jumpToSelection;
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index ea3520b..0bab3ac 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -540,6 +540,18 @@ static HTMLFormElementImpl *formElementFromDOMElement(id <WebDOMElement>element)
return results;
}
+- (NSString *)searchForLabels:(NSArray *)labels beforeElement:(id <WebDOMElement>)element
+{
+ ASSERT([(NSObject *)element isKindOfClass:[WebCoreDOMElement class]]);
+ return _part->searchForLabelsBeforeElement(labels, [(WebCoreDOMElement *)element elementImpl]);
+}
+
+- (NSString *)matchLabels:(NSArray *)labels againstElement:(id <WebDOMElement>)element
+{
+ ASSERT([(NSObject *)element isKindOfClass:[WebCoreDOMElement class]]);
+ return _part->matchLabelsAgainstElement(labels, [(WebCoreDOMElement *)element elementImpl]);
+}
+
- (NSDictionary *)elementAtPoint:(NSPoint)point
{
RenderObject *renderer = _part->renderer();
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 51f3932..08452fa 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,18 @@
+2003-03-04 Trey Matteson <trey at apple.com>
+
+ Support for autofill. These are just two new glue routines
+ that call down through the bridge. They allow regexp driven
+ binding of AB data to form elements.
+
+ Reviewed by Maciej.
+
+ * WebView.subproj/WebHTMLRepresentation.h:
+ * WebView.subproj/WebHTMLRepresentation.m:
+ (-[WebHTMLRepresentation searchForLabels:beforeElement:]):
+ Call straight to bridge.
+ (-[WebHTMLRepresentation matchLabels:againstElement:]):
+ Call straight to bridge.
+
2003-03-04 Maciej Stachowiak <mjs at apple.com>
Reinstate missing part of last checking.
diff --git a/WebKit/WebView.subproj/WebHTMLRepresentation.h b/WebKit/WebView.subproj/WebHTMLRepresentation.h
index 88e3ba7..b84205d 100644
--- a/WebKit/WebView.subproj/WebHTMLRepresentation.h
+++ b/WebKit/WebView.subproj/WebHTMLRepresentation.h
@@ -57,5 +57,6 @@
- (id <WebDOMElement>)formForElement:(id <WebDOMElement>)element;
- (id <WebDOMElement>)currentForm;
- (NSArray *)controlsInForm:(id <WebDOMElement>)form;
-
+- (NSString *)searchForLabels:(NSArray *)labels beforeElement:(id <WebDOMElement>)element;
+- (NSString *)matchLabels:(NSArray *)labels againstElement:(id <WebDOMElement>)element;
@end
diff --git a/WebKit/WebView.subproj/WebHTMLRepresentation.m b/WebKit/WebView.subproj/WebHTMLRepresentation.m
index a3301a7..dc7e875 100644
--- a/WebKit/WebView.subproj/WebHTMLRepresentation.m
+++ b/WebKit/WebView.subproj/WebHTMLRepresentation.m
@@ -143,4 +143,14 @@
return [_private->bridge controlsInForm:form];
}
+- (NSString *)searchForLabels:(NSArray *)labels beforeElement:(id <WebDOMElement>)element
+{
+ return [_private->bridge searchForLabels:labels beforeElement:element];
+}
+
+- (NSString *)matchLabels:(NSArray *)labels againstElement:(id <WebDOMElement>)element
+{
+ return [_private->bridge matchLabels:labels againstElement:element];
+}
+
@end
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list