Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/dom/pattern/allchildren.js
2868 views
1
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview DOM pattern to match any children of a tag.
17
*
18
* @author [email protected] (Robby Walker)
19
*/
20
21
goog.provide('goog.dom.pattern.AllChildren');
22
23
goog.require('goog.dom.pattern.AbstractPattern');
24
goog.require('goog.dom.pattern.MatchType');
25
26
27
28
/**
29
* Pattern object that matches any nodes at or below the current tree depth.
30
*
31
* @constructor
32
* @extends {goog.dom.pattern.AbstractPattern}
33
*/
34
goog.dom.pattern.AllChildren = function() {
35
/**
36
* Tracks the matcher's depth to detect the end of the tag.
37
*
38
* @private {number}
39
*/
40
this.depth_ = 0;
41
};
42
goog.inherits(goog.dom.pattern.AllChildren, goog.dom.pattern.AbstractPattern);
43
44
45
/**
46
* Test whether the given token is on the same level.
47
*
48
* @param {Node} token Token to match against.
49
* @param {goog.dom.TagWalkType} type The type of token.
50
* @return {goog.dom.pattern.MatchType} {@code MATCHING} if the token is on the
51
* same level or deeper and {@code BACKTRACK_MATCH} if not.
52
* @override
53
*/
54
goog.dom.pattern.AllChildren.prototype.matchToken = function(token, type) {
55
this.depth_ += type;
56
57
if (this.depth_ >= 0) {
58
return goog.dom.pattern.MatchType.MATCHING;
59
} else {
60
this.depth_ = 0;
61
return goog.dom.pattern.MatchType.BACKTRACK_MATCH;
62
}
63
};
64
65
66
/**
67
* Reset any internal state this pattern keeps.
68
* @override
69
*/
70
goog.dom.pattern.AllChildren.prototype.reset = function() {
71
this.depth_ = 0;
72
};
73
74