1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585 |
- goog.provide('goog.ui.Control');
- goog.require('goog.Disposable');
- goog.require('goog.array');
- goog.require('goog.dom');
- goog.require('goog.events.BrowserEvent');
- goog.require('goog.events.Event');
- goog.require('goog.events.EventHandler');
- goog.require('goog.events.EventType');
- goog.require('goog.events.KeyCodes');
- goog.require('goog.events.KeyHandler');
- goog.require('goog.string');
- goog.require('goog.ui.Component');
- goog.require('goog.ui.ControlContent');
- goog.require('goog.ui.ControlRenderer');
- goog.require('goog.ui.registry');
- goog.require('goog.userAgent');
- goog.ui.Control = function(opt_content, opt_renderer, opt_domHelper) {
- goog.ui.Component.call(this, opt_domHelper);
- this.renderer_ =
- opt_renderer || goog.ui.registry.getDefaultRenderer(this.constructor);
- this.setContentInternal(goog.isDef(opt_content) ? opt_content : null);
-
- this.ariaLabel_ = null;
-
- this.ieMouseEventSequenceSimulator_;
- };
- goog.inherits(goog.ui.Control, goog.ui.Component);
- goog.tagUnsealableClass(goog.ui.Control);
- goog.ui.Control.registerDecorator = goog.ui.registry.setDecoratorByClassName;
- goog.ui.Control.getDecorator =
- (
- goog.ui.registry.getDecorator);
- goog.ui.Control.prototype.renderer_;
- goog.ui.Control.prototype.content_ = null;
- goog.ui.Control.prototype.state_ = 0x00;
- goog.ui.Control.prototype.supportedStates_ = goog.ui.Component.State.DISABLED |
- goog.ui.Component.State.HOVER | goog.ui.Component.State.ACTIVE |
- goog.ui.Component.State.FOCUSED;
- goog.ui.Control.prototype.autoStates_ = goog.ui.Component.State.ALL;
- goog.ui.Control.prototype.statesWithTransitionEvents_ = 0x00;
- goog.ui.Control.prototype.visible_ = true;
- goog.ui.Control.prototype.keyHandler_;
- goog.ui.Control.prototype.extraClassNames_ = null;
- goog.ui.Control.prototype.handleMouseEvents_ = true;
- goog.ui.Control.prototype.allowTextSelection_ = false;
- goog.ui.Control.prototype.preferredAriaRole_ = null;
- goog.ui.Control.prototype.isHandleMouseEvents = function() {
- return this.handleMouseEvents_;
- };
- goog.ui.Control.prototype.setHandleMouseEvents = function(enable) {
- if (this.isInDocument() && enable != this.handleMouseEvents_) {
-
- this.enableMouseEventHandling_(enable);
- }
- this.handleMouseEvents_ = enable;
- };
- goog.ui.Control.prototype.getKeyEventTarget = function() {
-
- return this.renderer_.getKeyEventTarget(this);
- };
- goog.ui.Control.prototype.getKeyHandler = function() {
- return this.keyHandler_ || (this.keyHandler_ = new goog.events.KeyHandler());
- };
- goog.ui.Control.prototype.getRenderer = function() {
- return this.renderer_;
- };
- goog.ui.Control.prototype.setRenderer = function(renderer) {
- if (this.isInDocument()) {
-
- throw Error(goog.ui.Component.Error.ALREADY_RENDERED);
- }
- if (this.getElement()) {
-
-
-
- this.setElementInternal(null);
- }
- this.renderer_ = renderer;
- };
- goog.ui.Control.prototype.getExtraClassNames = function() {
- return this.extraClassNames_;
- };
- goog.ui.Control.prototype.addClassName = function(className) {
- if (className) {
- if (this.extraClassNames_) {
- if (!goog.array.contains(this.extraClassNames_, className)) {
- this.extraClassNames_.push(className);
- }
- } else {
- this.extraClassNames_ = [className];
- }
- this.renderer_.enableExtraClassName(this, className, true);
- }
- };
- goog.ui.Control.prototype.removeClassName = function(className) {
- if (className && this.extraClassNames_ &&
- goog.array.remove(this.extraClassNames_, className)) {
- if (this.extraClassNames_.length == 0) {
- this.extraClassNames_ = null;
- }
- this.renderer_.enableExtraClassName(this, className, false);
- }
- };
- goog.ui.Control.prototype.enableClassName = function(className, enable) {
- if (enable) {
- this.addClassName(className);
- } else {
- this.removeClassName(className);
- }
- };
- goog.ui.Control.prototype.createDom = function() {
- var element = this.renderer_.createDom(this);
- this.setElementInternal(element);
-
- this.renderer_.setAriaRole(element, this.getPreferredAriaRole());
-
- if (!this.isAllowTextSelection()) {
-
-
- this.renderer_.setAllowTextSelection(element, false);
- }
-
- if (!this.isVisible()) {
-
-
- this.renderer_.setVisible(element, false);
- }
- };
- goog.ui.Control.prototype.getPreferredAriaRole = function() {
- return this.preferredAriaRole_;
- };
- goog.ui.Control.prototype.setPreferredAriaRole = function(role) {
- this.preferredAriaRole_ = role;
- };
- goog.ui.Control.prototype.getAriaLabel = function() {
- return this.ariaLabel_;
- };
- goog.ui.Control.prototype.setAriaLabel = function(label) {
- this.ariaLabel_ = label;
- var element = this.getElement();
- if (element) {
- this.renderer_.setAriaLabel(element, label);
- }
- };
- goog.ui.Control.prototype.getContentElement = function() {
-
- return this.renderer_.getContentElement(this.getElement());
- };
- goog.ui.Control.prototype.canDecorate = function(element) {
-
- return this.renderer_.canDecorate(element);
- };
- goog.ui.Control.prototype.decorateInternal = function(element) {
- element = this.renderer_.decorate(this, element);
- this.setElementInternal(element);
-
- this.renderer_.setAriaRole(element, this.getPreferredAriaRole());
-
- if (!this.isAllowTextSelection()) {
-
-
- this.renderer_.setAllowTextSelection(element, false);
- }
-
- this.visible_ = element.style.display != 'none';
- };
- goog.ui.Control.prototype.enterDocument = function() {
- goog.ui.Control.superClass_.enterDocument.call(this);
-
- this.renderer_.setAriaStates(this, this.getElementStrict());
-
-
- this.renderer_.initializeDom(this);
-
-
- if (this.supportedStates_ & ~goog.ui.Component.State.DISABLED) {
-
-
-
- if (this.isHandleMouseEvents()) {
- this.enableMouseEventHandling_(true);
- }
-
-
-
- if (this.isSupportedState(goog.ui.Component.State.FOCUSED)) {
- var keyTarget = this.getKeyEventTarget();
- if (keyTarget) {
- var keyHandler = this.getKeyHandler();
- keyHandler.attach(keyTarget);
- this.getHandler()
- .listen(
- keyHandler, goog.events.KeyHandler.EventType.KEY,
- this.handleKeyEvent)
- .listen(keyTarget, goog.events.EventType.FOCUS, this.handleFocus)
- .listen(keyTarget, goog.events.EventType.BLUR, this.handleBlur);
- }
- }
- }
- };
- goog.ui.Control.prototype.enableMouseEventHandling_ = function(enable) {
- var handler = this.getHandler();
- var element = this.getElement();
- if (enable) {
- handler
- .listen(element, goog.events.EventType.MOUSEOVER, this.handleMouseOver)
- .listen(element, goog.events.EventType.MOUSEDOWN, this.handleMouseDown)
- .listen(element, goog.events.EventType.MOUSEUP, this.handleMouseUp)
- .listen(element, goog.events.EventType.MOUSEOUT, this.handleMouseOut);
- if (this.handleContextMenu != goog.nullFunction) {
- handler.listen(
- element, goog.events.EventType.CONTEXTMENU, this.handleContextMenu);
- }
- if (goog.userAgent.IE) {
-
-
-
- if (!goog.userAgent.isVersionOrHigher(9)) {
- handler.listen(
- element, goog.events.EventType.DBLCLICK, this.handleDblClick);
- }
- if (!this.ieMouseEventSequenceSimulator_) {
- this.ieMouseEventSequenceSimulator_ =
- new goog.ui.Control.IeMouseEventSequenceSimulator_(this);
- this.registerDisposable(this.ieMouseEventSequenceSimulator_);
- }
- }
- } else {
- handler
- .unlisten(
- element, goog.events.EventType.MOUSEOVER, this.handleMouseOver)
- .unlisten(
- element, goog.events.EventType.MOUSEDOWN, this.handleMouseDown)
- .unlisten(element, goog.events.EventType.MOUSEUP, this.handleMouseUp)
- .unlisten(element, goog.events.EventType.MOUSEOUT, this.handleMouseOut);
- if (this.handleContextMenu != goog.nullFunction) {
- handler.unlisten(
- element, goog.events.EventType.CONTEXTMENU, this.handleContextMenu);
- }
- if (goog.userAgent.IE) {
- if (!goog.userAgent.isVersionOrHigher(9)) {
- handler.unlisten(
- element, goog.events.EventType.DBLCLICK, this.handleDblClick);
- }
- goog.dispose(this.ieMouseEventSequenceSimulator_);
- this.ieMouseEventSequenceSimulator_ = null;
- }
- }
- };
- goog.ui.Control.prototype.exitDocument = function() {
- goog.ui.Control.superClass_.exitDocument.call(this);
- if (this.keyHandler_) {
- this.keyHandler_.detach();
- }
- if (this.isVisible() && this.isEnabled()) {
- this.renderer_.setFocusable(this, false);
- }
- };
- goog.ui.Control.prototype.disposeInternal = function() {
- goog.ui.Control.superClass_.disposeInternal.call(this);
- if (this.keyHandler_) {
- this.keyHandler_.dispose();
- delete this.keyHandler_;
- }
- delete this.renderer_;
- this.content_ = null;
- this.extraClassNames_ = null;
- this.ieMouseEventSequenceSimulator_ = null;
- };
- goog.ui.Control.prototype.getContent = function() {
- return this.content_;
- };
- goog.ui.Control.prototype.setContent = function(content) {
-
- this.renderer_.setContent(this.getElement(), content);
-
-
- this.setContentInternal(content);
- };
- goog.ui.Control.prototype.setContentInternal = function(content) {
- this.content_ = content;
- };
- goog.ui.Control.prototype.getCaption = function() {
- var content = this.getContent();
- if (!content) {
- return '';
- }
- var caption = goog.isString(content) ?
- content :
- goog.isArray(content) ?
- goog.array.map(content, goog.dom.getRawTextContent).join('') :
- goog.dom.getTextContent( (content));
- return goog.string.collapseBreakingSpaces(caption);
- };
- goog.ui.Control.prototype.setCaption = function(caption) {
- this.setContent(caption);
- };
- goog.ui.Control.prototype.setRightToLeft = function(rightToLeft) {
-
- goog.ui.Control.superClass_.setRightToLeft.call(this, rightToLeft);
- var element = this.getElement();
- if (element) {
- this.renderer_.setRightToLeft(element, rightToLeft);
- }
- };
- goog.ui.Control.prototype.isAllowTextSelection = function() {
- return this.allowTextSelection_;
- };
- goog.ui.Control.prototype.setAllowTextSelection = function(allow) {
- this.allowTextSelection_ = allow;
- var element = this.getElement();
- if (element) {
- this.renderer_.setAllowTextSelection(element, allow);
- }
- };
- goog.ui.Control.prototype.isVisible = function() {
- return this.visible_;
- };
- goog.ui.Control.prototype.setVisible = function(visible, opt_force) {
- if (opt_force || (this.visible_ != visible &&
- this.dispatchEvent(
- visible ? goog.ui.Component.EventType.SHOW :
- goog.ui.Component.EventType.HIDE))) {
- var element = this.getElement();
- if (element) {
- this.renderer_.setVisible(element, visible);
- }
- if (this.isEnabled()) {
- this.renderer_.setFocusable(this, visible);
- }
- this.visible_ = visible;
- return true;
- }
- return false;
- };
- goog.ui.Control.prototype.isEnabled = function() {
- return !this.hasState(goog.ui.Component.State.DISABLED);
- };
- goog.ui.Control.prototype.isParentDisabled_ = function() {
- var parent = this.getParent();
- return !!parent && typeof parent.isEnabled == 'function' &&
- !parent.isEnabled();
- };
- goog.ui.Control.prototype.setEnabled = function(enable) {
- if (!this.isParentDisabled_() &&
- this.isTransitionAllowed(goog.ui.Component.State.DISABLED, !enable)) {
- if (!enable) {
- this.setActive(false);
- this.setHighlighted(false);
- }
- if (this.isVisible()) {
- this.renderer_.setFocusable(this, enable);
- }
- this.setState(goog.ui.Component.State.DISABLED, !enable, true);
- }
- };
- goog.ui.Control.prototype.isHighlighted = function() {
- return this.hasState(goog.ui.Component.State.HOVER);
- };
- goog.ui.Control.prototype.setHighlighted = function(highlight) {
- if (this.isTransitionAllowed(goog.ui.Component.State.HOVER, highlight)) {
- this.setState(goog.ui.Component.State.HOVER, highlight);
- }
- };
- goog.ui.Control.prototype.isActive = function() {
- return this.hasState(goog.ui.Component.State.ACTIVE);
- };
- goog.ui.Control.prototype.setActive = function(active) {
- if (this.isTransitionAllowed(goog.ui.Component.State.ACTIVE, active)) {
- this.setState(goog.ui.Component.State.ACTIVE, active);
- }
- };
- goog.ui.Control.prototype.isSelected = function() {
- return this.hasState(goog.ui.Component.State.SELECTED);
- };
- goog.ui.Control.prototype.setSelected = function(select) {
- if (this.isTransitionAllowed(goog.ui.Component.State.SELECTED, select)) {
- this.setState(goog.ui.Component.State.SELECTED, select);
- }
- };
- goog.ui.Control.prototype.isChecked = function() {
- return this.hasState(goog.ui.Component.State.CHECKED);
- };
- goog.ui.Control.prototype.setChecked = function(check) {
- if (this.isTransitionAllowed(goog.ui.Component.State.CHECKED, check)) {
- this.setState(goog.ui.Component.State.CHECKED, check);
- }
- };
- goog.ui.Control.prototype.isFocused = function() {
- return this.hasState(goog.ui.Component.State.FOCUSED);
- };
- goog.ui.Control.prototype.setFocused = function(focused) {
- if (this.isTransitionAllowed(goog.ui.Component.State.FOCUSED, focused)) {
- this.setState(goog.ui.Component.State.FOCUSED, focused);
- }
- };
- goog.ui.Control.prototype.isOpen = function() {
- return this.hasState(goog.ui.Component.State.OPENED);
- };
- goog.ui.Control.prototype.setOpen = function(open) {
- if (this.isTransitionAllowed(goog.ui.Component.State.OPENED, open)) {
- this.setState(goog.ui.Component.State.OPENED, open);
- }
- };
- goog.ui.Control.prototype.getState = function() {
- return this.state_;
- };
- goog.ui.Control.prototype.hasState = function(state) {
- return !!(this.state_ & state);
- };
- goog.ui.Control.prototype.setState = function(state, enable, opt_calledFrom) {
- if (!opt_calledFrom && state == goog.ui.Component.State.DISABLED) {
- this.setEnabled(!enable);
- return;
- }
- if (this.isSupportedState(state) && enable != this.hasState(state)) {
-
- this.renderer_.setState(this, state, enable);
- this.state_ = enable ? this.state_ | state : this.state_ & ~state;
- }
- };
- goog.ui.Control.prototype.setStateInternal = function(state) {
- this.state_ = state;
- };
- goog.ui.Control.prototype.isSupportedState = function(state) {
- return !!(this.supportedStates_ & state);
- };
- goog.ui.Control.prototype.setSupportedState = function(state, support) {
- if (this.isInDocument() && this.hasState(state) && !support) {
-
- throw Error(goog.ui.Component.Error.ALREADY_RENDERED);
- }
- if (!support && this.hasState(state)) {
-
- this.setState(state, false);
- }
- this.supportedStates_ =
- support ? this.supportedStates_ | state : this.supportedStates_ & ~state;
- };
- goog.ui.Control.prototype.isAutoState = function(state) {
- return !!(this.autoStates_ & state) && this.isSupportedState(state);
- };
- goog.ui.Control.prototype.setAutoStates = function(states, enable) {
- this.autoStates_ =
- enable ? this.autoStates_ | states : this.autoStates_ & ~states;
- };
- goog.ui.Control.prototype.isDispatchTransitionEvents = function(state) {
- return !!(this.statesWithTransitionEvents_ & state) &&
- this.isSupportedState(state);
- };
- goog.ui.Control.prototype.setDispatchTransitionEvents = function(
- states, enable) {
- this.statesWithTransitionEvents_ = enable ?
- this.statesWithTransitionEvents_ | states :
- this.statesWithTransitionEvents_ & ~states;
- };
- goog.ui.Control.prototype.isTransitionAllowed = function(state, enable) {
- return this.isSupportedState(state) && this.hasState(state) != enable &&
- (!(this.statesWithTransitionEvents_ & state) ||
- this.dispatchEvent(
- goog.ui.Component.getStateTransitionEvent(state, enable))) &&
- !this.isDisposed();
- };
- goog.ui.Control.prototype.handleMouseOver = function(e) {
-
- if (!goog.ui.Control.isMouseEventWithinElement_(e, this.getElement()) &&
- this.dispatchEvent(goog.ui.Component.EventType.ENTER) &&
- this.isEnabled() && this.isAutoState(goog.ui.Component.State.HOVER)) {
- this.setHighlighted(true);
- }
- };
- goog.ui.Control.prototype.handleMouseOut = function(e) {
- if (!goog.ui.Control.isMouseEventWithinElement_(e, this.getElement()) &&
- this.dispatchEvent(goog.ui.Component.EventType.LEAVE)) {
- if (this.isAutoState(goog.ui.Component.State.ACTIVE)) {
-
- this.setActive(false);
- }
- if (this.isAutoState(goog.ui.Component.State.HOVER)) {
- this.setHighlighted(false);
- }
- }
- };
- goog.ui.Control.prototype.handleContextMenu = goog.nullFunction;
- goog.ui.Control.isMouseEventWithinElement_ = function(e, elem) {
-
-
-
- return !!e.relatedTarget && goog.dom.contains(elem, e.relatedTarget);
- };
- goog.ui.Control.prototype.handleMouseDown = function(e) {
- if (this.isEnabled()) {
-
- if (this.isAutoState(goog.ui.Component.State.HOVER)) {
- this.setHighlighted(true);
- }
-
-
- if (e.isMouseActionButton()) {
- if (this.isAutoState(goog.ui.Component.State.ACTIVE)) {
- this.setActive(true);
- }
- if (this.renderer_ && this.renderer_.isFocusable(this)) {
- this.getKeyEventTarget().focus();
- }
- }
- }
-
- if (!this.isAllowTextSelection() && e.isMouseActionButton()) {
- e.preventDefault();
- }
- };
- goog.ui.Control.prototype.handleMouseUp = function(e) {
- if (this.isEnabled()) {
- if (this.isAutoState(goog.ui.Component.State.HOVER)) {
- this.setHighlighted(true);
- }
- if (this.isActive() && this.performActionInternal(e) &&
- this.isAutoState(goog.ui.Component.State.ACTIVE)) {
- this.setActive(false);
- }
- }
- };
- goog.ui.Control.prototype.handleDblClick = function(e) {
- if (this.isEnabled()) {
- this.performActionInternal(e);
- }
- };
- goog.ui.Control.prototype.performActionInternal = function(e) {
- if (this.isAutoState(goog.ui.Component.State.CHECKED)) {
- this.setChecked(!this.isChecked());
- }
- if (this.isAutoState(goog.ui.Component.State.SELECTED)) {
- this.setSelected(true);
- }
- if (this.isAutoState(goog.ui.Component.State.OPENED)) {
- this.setOpen(!this.isOpen());
- }
- var actionEvent =
- new goog.events.Event(goog.ui.Component.EventType.ACTION, this);
- if (e) {
- actionEvent.altKey = e.altKey;
- actionEvent.ctrlKey = e.ctrlKey;
- actionEvent.metaKey = e.metaKey;
- actionEvent.shiftKey = e.shiftKey;
- actionEvent.platformModifierKey = e.platformModifierKey;
- }
- return this.dispatchEvent(actionEvent);
- };
- goog.ui.Control.prototype.handleFocus = function(e) {
- if (this.isAutoState(goog.ui.Component.State.FOCUSED)) {
- this.setFocused(true);
- }
- };
- goog.ui.Control.prototype.handleBlur = function(e) {
- if (this.isAutoState(goog.ui.Component.State.ACTIVE)) {
- this.setActive(false);
- }
- if (this.isAutoState(goog.ui.Component.State.FOCUSED)) {
- this.setFocused(false);
- }
- };
- goog.ui.Control.prototype.handleKeyEvent = function(e) {
- if (this.isVisible() && this.isEnabled() && this.handleKeyEventInternal(e)) {
- e.preventDefault();
- e.stopPropagation();
- return true;
- }
- return false;
- };
- goog.ui.Control.prototype.handleKeyEventInternal = function(e) {
- return e.keyCode == goog.events.KeyCodes.ENTER &&
- this.performActionInternal(e);
- };
- goog.ui.registry.setDefaultRenderer(goog.ui.Control, goog.ui.ControlRenderer);
- goog.ui.registry.setDecoratorByClassName(
- goog.ui.ControlRenderer.CSS_CLASS,
- function() { return new goog.ui.Control(null); });
- goog.ui.Control.IeMouseEventSequenceSimulator_ = function(control) {
- goog.ui.Control.IeMouseEventSequenceSimulator_.base(this, 'constructor');
-
- this.control_ = control;
-
- this.clickExpected_ = false;
-
- this.handler_ = new goog.events.EventHandler(this);
- this.registerDisposable(this.handler_);
- var element = this.control_.getElementStrict();
- this.handler_
- .listen(element, goog.events.EventType.MOUSEDOWN, this.handleMouseDown_)
- .listen(element, goog.events.EventType.MOUSEUP, this.handleMouseUp_)
- .listen(element, goog.events.EventType.CLICK, this.handleClick_);
- };
- goog.inherits(goog.ui.Control.IeMouseEventSequenceSimulator_, goog.Disposable);
- goog.ui.Control.IeMouseEventSequenceSimulator_.SYNTHETIC_EVENTS_ =
- !goog.userAgent.IE || goog.userAgent.isDocumentModeOrHigher(9);
- goog.ui.Control.IeMouseEventSequenceSimulator_.prototype.handleMouseDown_ =
- function() {
- this.clickExpected_ = false;
- };
- goog.ui.Control.IeMouseEventSequenceSimulator_.prototype.handleMouseUp_ =
- function() {
- this.clickExpected_ = true;
- };
- goog.ui.Control.IeMouseEventSequenceSimulator_.makeLeftMouseEvent_ = function(
- e, typeArg) {
- 'use strict';
- if (!goog.ui.Control.IeMouseEventSequenceSimulator_.SYNTHETIC_EVENTS_) {
-
-
-
-
- e.button = goog.events.BrowserEvent.MouseButton.LEFT;
- e.type = typeArg;
- return e;
- }
- var event = (document.createEvent('MouseEvents'));
- event.initMouseEvent(
- typeArg, e.bubbles, e.cancelable,
- e.view || null,
- e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey,
- e.shiftKey, e.metaKey, goog.events.BrowserEvent.MouseButton.LEFT,
- e.relatedTarget || null);
- return event;
- };
- goog.ui.Control.IeMouseEventSequenceSimulator_.prototype.handleClick_ =
- function(e) {
- if (this.clickExpected_) {
-
-
- this.clickExpected_ = false;
- return;
- }
-
-
-
- var browserEvent = (e);
- var event = (browserEvent.getBrowserEvent());
- var origEventButton = event.button;
- var origEventType = event.type;
- var down = goog.ui.Control.IeMouseEventSequenceSimulator_.makeLeftMouseEvent_(
- event, goog.events.EventType.MOUSEDOWN);
- this.control_.handleMouseDown(
- new goog.events.BrowserEvent(down, browserEvent.currentTarget));
- var up = goog.ui.Control.IeMouseEventSequenceSimulator_.makeLeftMouseEvent_(
- event, goog.events.EventType.MOUSEUP);
- this.control_.handleMouseUp(
- new goog.events.BrowserEvent(up, browserEvent.currentTarget));
- if (goog.ui.Control.IeMouseEventSequenceSimulator_.SYNTHETIC_EVENTS_) {
-
-
-
- return;
- }
-
- event.button = origEventButton;
- event.type = origEventType;
- };
- goog.ui.Control.IeMouseEventSequenceSimulator_.prototype.disposeInternal =
- function() {
- this.control_ = null;
- goog.ui.Control.IeMouseEventSequenceSimulator_.base(this, 'disposeInternal');
- };
|