Path: blob/trunk/third_party/closure/goog/dom/pattern/allchildren.js
2868 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview DOM pattern to match any children of a tag.16*17* @author [email protected] (Robby Walker)18*/1920goog.provide('goog.dom.pattern.AllChildren');2122goog.require('goog.dom.pattern.AbstractPattern');23goog.require('goog.dom.pattern.MatchType');24252627/**28* Pattern object that matches any nodes at or below the current tree depth.29*30* @constructor31* @extends {goog.dom.pattern.AbstractPattern}32*/33goog.dom.pattern.AllChildren = function() {34/**35* Tracks the matcher's depth to detect the end of the tag.36*37* @private {number}38*/39this.depth_ = 0;40};41goog.inherits(goog.dom.pattern.AllChildren, goog.dom.pattern.AbstractPattern);424344/**45* Test whether the given token is on the same level.46*47* @param {Node} token Token to match against.48* @param {goog.dom.TagWalkType} type The type of token.49* @return {goog.dom.pattern.MatchType} {@code MATCHING} if the token is on the50* same level or deeper and {@code BACKTRACK_MATCH} if not.51* @override52*/53goog.dom.pattern.AllChildren.prototype.matchToken = function(token, type) {54this.depth_ += type;5556if (this.depth_ >= 0) {57return goog.dom.pattern.MatchType.MATCHING;58} else {59this.depth_ = 0;60return goog.dom.pattern.MatchType.BACKTRACK_MATCH;61}62};636465/**66* Reset any internal state this pattern keeps.67* @override68*/69goog.dom.pattern.AllChildren.prototype.reset = function() {70this.depth_ = 0;71};727374