1 /****************************************************************************
  2  Copyright (c) 2011-2012 cocos2d-x.org
  3  Copyright (c) 2013-2014 Chukong Technologies Inc.
  4 
  5  http://www.cocos2d-x.org
  6 
  7  Permission is hereby granted, free of charge, to any person obtaining a copy
  8  of this software and associated documentation files (the "Software"), to deal
  9  in the Software without restriction, including without limitation the rights
 10  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11  copies of the Software, and to permit persons to whom the Software is
 12  furnished to do so, subject to the following conditions:
 13 
 14  The above copyright notice and this permission notice shall be included in
 15  all copies or substantial portions of the Software.
 16 
 17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23  THE SOFTWARE.
 24  ****************************************************************************/
 25 
 26 /**
 27  * @ignore
 28  */
 29 //it's a private class, it's a renderer of ccui.TextField.
 30 ccui._TextFieldRenderer = cc.TextFieldTTF.extend({
 31     _maxLengthEnabled: false,
 32     _maxLength: 0,
 33     _passwordEnabled: false,
 34     _passwordStyleText: "",
 35     _attachWithIME: false,
 36     _detachWithIME: false,
 37     _insertText: false,
 38     _deleteBackward: false,
 39     _className: "_TextFieldRenderer",
 40 
 41     ctor: function () {
 42         cc.TextFieldTTF.prototype.ctor.call(this);
 43         this._maxLengthEnabled = false;
 44         this._maxLength = 0;
 45         this._passwordEnabled = false;
 46         this._passwordStyleText = "*";
 47         this._attachWithIME = false;
 48         this._detachWithIME = false;
 49         this._insertText = false;
 50         this._deleteBackward = false;
 51     },
 52 
 53     onEnter: function () {
 54         cc.TextFieldTTF.prototype.onEnter.call(this);
 55         cc.TextFieldTTF.prototype.setDelegate.call(this, this);
 56     },
 57 
 58     onTextFieldAttachWithIME: function (sender) {
 59         this.setAttachWithIME(true);
 60         return false;
 61     },
 62 
 63     onTextFieldInsertText: function (sender, text, len) {
 64         if (len === 1 && text === "\n")
 65             return false;
 66 
 67         this.setInsertText(true);
 68         return (this._maxLengthEnabled) && (cc.TextFieldTTF.prototype.getCharCount.call(this) >= this._maxLength);
 69     },
 70 
 71     onTextFieldDeleteBackward: function (sender, delText, nLen) {
 72         this.setDeleteBackward(true);
 73         return false;
 74     },
 75 
 76     onTextFieldDetachWithIME: function (sender) {
 77         this.setDetachWithIME(true);
 78         return false;
 79     },
 80 
 81     insertText: function (text, len) {
 82         var input_text = text;
 83 
 84         if (text !== "\n"){
 85             if (this._maxLengthEnabled){
 86                 var text_count = this.getString().length;
 87                 if (text_count >= this._maxLength){
 88                     // password
 89                     if (this._passwordEnabled)
 90                         this.setPasswordText(this.getString());
 91                     return;
 92                 }
 93             }
 94         }
 95         cc.TextFieldTTF.prototype.insertText.call(this, input_text, len);
 96 
 97         // password
 98         if (this._passwordEnabled && cc.TextFieldTTF.prototype.getCharCount.call(this) > 0)
 99             this.setPasswordText(this.getString());
100     },
101 
102     deleteBackward: function () {
103         cc.TextFieldTTF.prototype.deleteBackward.call(this);
104 
105         if (cc.TextFieldTTF.prototype.getCharCount.call(this) > 0 && this._passwordEnabled)
106             this.setPasswordText(this._inputText);
107     },
108 
109     openIME: function () {
110         cc.TextFieldTTF.prototype.attachWithIME.call(this);
111     },
112 
113     closeIME: function () {
114         cc.TextFieldTTF.prototype.detachWithIME.call(this);
115     },
116 
117     setMaxLengthEnabled: function (enable) {
118         this._maxLengthEnabled = enable;
119     },
120 
121     isMaxLengthEnabled: function () {
122         return this._maxLengthEnabled;
123     },
124 
125     setMaxLength: function (length) {
126         this._maxLength = length;
127     },
128 
129     getMaxLength: function () {
130         return this._maxLength;
131     },
132 
133     getCharCount: function () {
134         return cc.TextFieldTTF.prototype.getCharCount.call(this);
135     },
136 
137     setPasswordEnabled: function (enable) {
138         this._passwordEnabled = enable;
139     },
140 
141     isPasswordEnabled: function () {
142         return this._passwordEnabled;
143     },
144 
145     setPasswordStyleText: function (styleText) {
146         if (styleText.length > 1)
147             return;
148         var header = styleText.charCodeAt(0);
149         if (header < 33 || header > 126)
150             return;
151         this._passwordStyleText = styleText;
152     },
153 
154     setPasswordText: function (text) {
155         var tempStr = "";
156         var text_count = text.length;
157         var max = text_count;
158 
159         if (this._maxLengthEnabled && text_count > this._maxLength)
160             max = this._maxLength;
161 
162         for (var i = 0; i < max; ++i)
163             tempStr += this._passwordStyleText;
164 
165         cc.LabelTTF.prototype.setString.call(this, tempStr);
166     },
167 
168     setAttachWithIME: function (attach) {
169         this._attachWithIME = attach;
170     },
171 
172     getAttachWithIME: function () {
173         return this._attachWithIME;
174     },
175 
176     setDetachWithIME: function (detach) {
177         this._detachWithIME = detach;
178     },
179 
180     getDetachWithIME: function () {
181         return this._detachWithIME;
182     },
183 
184     setInsertText: function (insert) {
185         this._insertText = insert;
186     },
187 
188     getInsertText: function () {
189         return this._insertText;
190     },
191 
192     setDeleteBackward: function (deleteBackward) {
193         this._deleteBackward = deleteBackward;
194     },
195 
196     getDeleteBackward: function () {
197         return this._deleteBackward;
198     },
199 
200     onDraw: function (sender) {
201         return false;
202     }
203 });
204 
205 ccui._TextFieldRenderer.create = function (placeholder, fontName, fontSize) {
206     var ret = new ccui._TextFieldRenderer();
207     if (ret && ret.initWithString("", fontName, fontSize)) {
208         if (placeholder)
209             ret.setPlaceHolder(placeholder);
210         return ret;
211     }
212     return null;
213 };
214 
215 /**
216  *
217  * @class
218  * @extends ccui.Widget
219  *
220  * @property {String}   string              - The content string of the label
221  * @property {String}   placeHolder         - The place holder of the text field
222  * @property {String}   font                - The text field font with a style string: e.g. "18px Verdana"
223  * @property {String}   fontName            - The text field font name
224  * @property {Number}   fontSize            - The text field font size
225  * @property {Boolean}  maxLengthEnabled    - Indicate whether max length limit is enabled
226  * @property {Number}   maxLength           - The max length of the text field
227  * @property {Boolean}  passwordEnabled     - Indicate whether the text field is for entering password
228  */
229 ccui.TextField = ccui.Widget.extend(/** @lends ccui.TextField# */{
230     _textFieldRenderer: null,
231     _touchWidth: 0,
232     _touchHeight: 0,
233     _useTouchArea: false,
234     _textFieldEventListener: null,
235     _textFieldEventSelector: null,
236     _passwordStyleText: "",
237     _textFieldRendererAdaptDirty: true,
238     _fontName: "",
239     _fontSize: 12,
240 
241     _ccEventCallback: null,
242 
243     /**
244      * allocates and initializes a UITextField.
245      * Constructor of ccui.TextField. override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
246      * @param {string} placeholder
247      * @param {string} fontName
248      * @param {Number} fontSize
249      * @example
250      * // example
251      * var uiTextField = new ccui.TextField();
252      */
253     ctor: function (placeholder, fontName, fontSize) {
254         ccui.Widget.prototype.ctor.call(this);
255         if (fontName)
256             this.setFontName(fontName);
257         if (fontSize)
258             this.setFontSize(fontSize);
259         if (placeholder)
260             this.setPlaceHolder(placeholder);
261     },
262 
263     /**
264      * Initializes a ccui.TextField. Please do not call this function by yourself, you should pass the parameters to constructor to initialize it.
265      * @returns {boolean}
266      * @override
267      */
268     init: function(){
269         if(ccui.Widget.prototype.init.call(this)){
270             this.setTouchEnabled(true);
271             return true;
272         }
273         return false;
274     },
275 
276     /**
277      * Calls parent class' onEnter and schedules update function.
278      * @override
279      */
280     onEnter: function () {
281         ccui.Widget.prototype.onEnter.call(this);
282         this.scheduleUpdate();
283     },
284 
285     _initRenderer: function () {
286         this._textFieldRenderer = ccui._TextFieldRenderer.create("input words here", "Thonburi", 20);
287         this.addProtectedChild(this._textFieldRenderer, ccui.TextField.RENDERER_ZORDER, -1);
288     },
289 
290     /**
291      * Sets touch size of ccui.TextField.
292      * @param {cc.Size} size
293      */
294     setTouchSize: function (size) {
295         this._touchWidth = size.width;
296         this._touchHeight = size.height;
297     },
298 
299     /**
300      * Sets whether use touch area.
301      * @param enable
302      */
303     setTouchAreaEnabled: function(enable){
304         this._useTouchArea = enable;
305     },
306 
307     /**
308      * Checks a point if is in ccui.TextField's space
309      * @param {cc.Point} pt
310      * @returns {boolean}
311      */
312     hitTest: function(pt){
313         if (this._useTouchArea) {
314             var nsp = this.convertToNodeSpace(pt);
315             var bb = cc.rect(
316                 -this._touchWidth * this._anchorPoint.x,
317                 -this._touchHeight * this._anchorPoint.y,
318                 this._touchWidth, this._touchHeight
319             );
320 
321             return ( nsp.x >= bb.x && nsp.x <= bb.x + bb.width &&
322                 nsp.y >= bb.y && nsp.y <= bb.y + bb.height );
323         } else
324             return ccui.Widget.prototype.hitTest.call(this, pt);
325     },
326 
327     /**
328      * Returns touch size of ccui.TextField.
329      * @returns {cc.Size}
330      */
331     getTouchSize: function () {
332         return cc.size(this._touchWidth, this._touchHeight);
333     },
334 
335     /**
336      *  Changes the string value of textField.
337      * @deprecated since v3.0, please use setString instead.
338      * @param {String} text
339      */
340     setText: function (text) {
341         cc.log("Please use the setString");
342         this.setString(text);
343     },
344 
345     /**
346      *  Changes the string value of textField.
347      * @param {String} text
348      */
349     setString: function (text) {
350         if (text == null)
351             return;
352 
353         text = String(text);
354         if (this.isMaxLengthEnabled())
355             text = text.substr(0, this.getMaxLength());
356         if (this.isPasswordEnabled()) {
357             this._textFieldRenderer.setPasswordText(text);
358             this._textFieldRenderer.setString("");
359             this._textFieldRenderer.insertText(text, text.length);
360         } else
361             this._textFieldRenderer.setString(text);
362         this._textFieldRendererAdaptDirty = true;
363         this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize());
364     },
365 
366     /**
367      * Sets the placeholder string. <br />
368      * display this string if string equal "".
369      * @param {String} value
370      */
371     setPlaceHolder: function (value) {
372         this._textFieldRenderer.setPlaceHolder(value);
373         this._textFieldRendererAdaptDirty = true;
374         this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize());
375     },
376 
377     /**
378      * Returns the placeholder string.
379      * @returns {String}
380      */
381     getPlaceHolder: function () {
382         return this._textFieldRenderer.getPlaceHolder();
383     },
384 
385     /**
386      * Returns the color of ccui.TextField's place holder.
387      * @returns {cc.Color}
388      */
389     getPlaceHolderColor: function(){
390         return this._textFieldRenderer.getPlaceHolderColor();
391     },
392 
393     /**
394      * Sets the place holder color to ccui.TextField.
395      * @param color
396      */
397     setPlaceHolderColor: function(color){
398         this._textFieldRenderer.setColorSpaceHolder(color);
399     },
400 
401     /**
402      * Sets the text color to ccui.TextField
403      * @param textColor
404      */
405     setTextColor: function(textColor){
406         this._textFieldRenderer.setTextColor(textColor);
407     },
408 
409     /**
410      * Sets font size for ccui.TextField.
411      * @param {Number} size
412      */
413     setFontSize: function (size) {
414         this._textFieldRenderer.setFontSize(size);
415         this._fontSize = size;
416         this._textFieldRendererAdaptDirty = true;
417         this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize());
418     },
419 
420     /**
421      * Gets font size of ccui.TextField.
422      * @return {Number} size
423      */
424     getFontSize: function () {
425         return this._fontSize;
426     },
427 
428     /**
429      * Sets font name for ccui.TextField
430      * @param {String} name
431      */
432     setFontName: function (name) {
433         this._textFieldRenderer.setFontName(name);
434         this._fontName = name;
435         this._textFieldRendererAdaptDirty = true;
436         this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize());
437     },
438 
439     /**
440      * Returns font name of ccui.TextField.
441      * @return {String} font name
442      */
443     getFontName: function () {
444         return this._fontName;
445     },
446 
447     /**
448      * detach with IME
449      */
450     didNotSelectSelf: function () {
451         this._textFieldRenderer.detachWithIME();
452     },
453 
454     /**
455      * Returns textField string value
456      * @deprecated since v3.0, please use getString instead.
457      * @returns {String}
458      */
459     getStringValue: function () {
460         cc.log("Please use the getString");
461         return this.getString();
462     },
463 
464     /**
465      * Returns string value of ccui.TextField.
466      * @returns {String}
467      */
468     getString: function () {
469         return this._textFieldRenderer.getString();
470     },
471 
472     /**
473      * Returns the length of ccui.TextField.
474      * @returns {Number}
475      */
476     getStringLength: function(){
477         return this._textFieldRenderer.getStringLength();
478     },
479 
480     /**
481      * The touch began event callback handler.
482      * @param {cc.Point} touchPoint
483      */
484     onTouchBegan: function (touchPoint, unusedEvent) {
485         var self = this;
486         var pass = ccui.Widget.prototype.onTouchBegan.call(self, touchPoint, unusedEvent);
487         if (self._hit) {
488             setTimeout(function(){
489                 self._textFieldRenderer.attachWithIME();
490             }, 0);
491         }else{
492             setTimeout(function(){
493                 self._textFieldRenderer.detachWithIME();
494             }, 0);
495         }
496         return pass;
497     },
498 
499     /**
500      * Sets Whether to open string length limit for ccui.TextField.
501      * @param {Boolean} enable
502      */
503     setMaxLengthEnabled: function (enable) {
504         this._textFieldRenderer.setMaxLengthEnabled(enable);
505     },
506 
507     /**
508      * Returns Whether to open string length limit.
509      * @returns {Boolean}
510      */
511     isMaxLengthEnabled: function () {
512         return this._textFieldRenderer.isMaxLengthEnabled();
513     },
514 
515     /**
516      * Sets the max length of ccui.TextField. Only when you turn on the string length limit, it is valid.
517      * @param {number} length
518      */
519     setMaxLength: function (length) {
520         this._textFieldRenderer.setMaxLength(length);
521         this.setString(this.getString());
522     },
523 
524     /**
525      * Returns the max length of ccui.TextField.
526      * @returns {number} length
527      */
528     getMaxLength: function () {
529         return this._textFieldRenderer.getMaxLength();
530     },
531 
532     /**
533      * Sets whether to open setting string as password character.
534      * @param {Boolean} enable
535      */
536     setPasswordEnabled: function (enable) {
537         this._textFieldRenderer.setPasswordEnabled(enable);
538     },
539 
540     /**
541      * Returns whether to open setting string as password character.
542      * @returns {Boolean}
543      */
544     isPasswordEnabled: function () {
545         return this._textFieldRenderer.isPasswordEnabled();
546     },
547 
548     /**
549      * Sets the password style character, Only when you turn on setting string as password character, it is valid.
550      * @param styleText
551      */
552     setPasswordStyleText: function(styleText){
553         this._textFieldRenderer.setPasswordStyleText(styleText);
554         this._passwordStyleText = styleText;
555 
556         this.setString(this.getString());
557     },
558 
559     /**
560      * Returns the password style character.
561      * @returns {String}
562      */
563     getPasswordStyleText: function () {
564         return this._passwordStyleText;
565     },
566 
567     update: function (dt) {
568         if (this.getDetachWithIME()) {
569             this._detachWithIMEEvent();
570             this.setDetachWithIME(false);
571         }
572         if (this.getAttachWithIME()) {
573             this._attachWithIMEEvent();
574             this.setAttachWithIME(false);
575         }
576         if (this.getInsertText()) {
577             this._textFieldRendererAdaptDirty = true;
578             this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize());
579 
580             this._insertTextEvent();
581             this.setInsertText(false);
582         }
583         if (this.getDeleteBackward()) {
584             this._textFieldRendererAdaptDirty = true;
585             this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize());
586 
587             this._deleteBackwardEvent();
588             this.setDeleteBackward(false);
589         }
590     },
591 
592     /**
593      * Returns whether attach with IME.
594      * @returns {Boolean}
595      */
596     getAttachWithIME: function () {
597         return this._textFieldRenderer.getAttachWithIME();
598     },
599 
600     /**
601      * Sets attach with IME.
602      * @param {Boolean} attach
603      */
604     setAttachWithIME: function (attach) {
605         this._textFieldRenderer.setAttachWithIME(attach);
606     },
607 
608     /**
609      * Returns whether detach with IME.
610      * @returns {Boolean}
611      */
612     getDetachWithIME: function () {
613         return this._textFieldRenderer.getDetachWithIME();
614     },
615 
616     /**
617      * Sets detach with IME.
618      * @param {Boolean} detach
619      */
620     setDetachWithIME: function (detach) {
621         this._textFieldRenderer.setDetachWithIME(detach);
622     },
623 
624     /**
625      * Returns insertText string of ccui.TextField.
626      * @returns {String}
627      */
628     getInsertText: function () {
629         return this._textFieldRenderer.getInsertText();
630     },
631 
632     /**
633      * Sets insertText string to ccui.TextField.
634      * @param {String} insertText
635      */
636     setInsertText: function (insertText) {
637         this._textFieldRenderer.setInsertText(insertText);
638     },
639 
640     /**
641      * Returns the delete backward of ccui.TextField.
642      * @returns {Boolean}
643      */
644     getDeleteBackward: function () {
645         return this._textFieldRenderer.getDeleteBackward();
646     },
647 
648     /**
649      * Sets the delete backward of ccui.TextField.
650      * @param {Boolean} deleteBackward
651      */
652     setDeleteBackward: function (deleteBackward) {
653         this._textFieldRenderer.setDeleteBackward(deleteBackward);
654     },
655 
656     _attachWithIMEEvent: function () {
657         if(this._textFieldEventSelector){
658             if (this._textFieldEventListener)
659                 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_ATTACH_WITH_IME);
660             else
661                 this._textFieldEventSelector(this, ccui.TextField.EVENT_ATTACH_WITH_IME);
662         }
663         if (this._ccEventCallback){
664             this._ccEventCallback(this, ccui.TextField.EVENT_ATTACH_WITH_IME);
665         }
666     },
667 
668     _detachWithIMEEvent: function () {
669         if(this._textFieldEventSelector){
670             if (this._textFieldEventListener)
671                 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DETACH_WITH_IME);
672             else
673                 this._textFieldEventSelector(this, ccui.TextField.EVENT_DETACH_WITH_IME);
674         }
675         if (this._ccEventCallback)
676             this._ccEventCallback(this, ccui.TextField.EVENT_DETACH_WITH_IME);
677     },
678 
679     _insertTextEvent: function () {
680         if(this._textFieldEventSelector){
681             if (this._textFieldEventListener)
682                 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_INSERT_TEXT);
683             else
684                 this._textFieldEventSelector(this, ccui.TextField.EVENT_INSERT_TEXT);          //eventCallback
685         }
686         if (this._ccEventCallback)
687             this._ccEventCallback(this, ccui.TextField.EVENT_INSERT_TEXT);
688     },
689 
690     _deleteBackwardEvent: function () {
691         if(this._textFieldEventSelector){
692             if (this._textFieldEventListener)
693                 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DELETE_BACKWARD);
694             else
695                 this._textFieldEventSelector(this, ccui.TextField.EVENT_DELETE_BACKWARD);         //eventCallback
696         }
697         if (this._ccEventCallback)
698             this._ccEventCallback(this, ccui.TextField.EVENT_DELETE_BACKWARD);
699     },
700 
701     /**
702      * Adds event listener to cuci.TextField.
703      * @param {Object} [target=]
704      * @param {Function} selector
705      * @deprecated since v3.0, please use addEventListener instead.
706      */
707     addEventListenerTextField: function (selector, target) {
708         this.addEventListener(selector, target);
709     },
710 
711     /**
712      * Adds event listener callback.
713      * @param {Object} [target=]
714      * @param {Function} selector
715      */
716     addEventListener: function(selector, target){
717         this._textFieldEventSelector = selector;        //when target is undefined, _textFieldEventSelector is ccEventCallback.
718         this._textFieldEventListener = target;
719     },
720 
721     _onSizeChanged: function () {
722         ccui.Widget.prototype._onSizeChanged.call(this);
723         this._textFieldRendererAdaptDirty = true;
724     },
725 
726     _adaptRenderers: function(){
727         if (this._textFieldRendererAdaptDirty) {
728             this._textfieldRendererScaleChangedWithSize();
729             this._textFieldRendererAdaptDirty = false;
730         }
731     },
732 
733     _textfieldRendererScaleChangedWithSize: function () {
734         if (!this._ignoreSize)
735             this._textFieldRenderer.setDimensions(this._contentSize);
736         this._textFieldRenderer.setPosition(this._contentSize.width / 2, this._contentSize.height / 2);
737     },
738 
739     //@since v3.3
740     getAutoRenderSize: function(){
741         var virtualSize = this._textFieldRenderer.getContentSize();
742         if (!this._ignoreSize) {
743             this._textFieldRenderer.setDimensions(0, 0);
744             virtualSize = this._textFieldRenderer.getContentSize();
745             this._textFieldRenderer.setDimensions(this._contentSize.width, this._contentSize.height);
746         }
747         return virtualSize;
748     },
749 
750     /**
751      * Returns the ccui.TextField's content size.
752      * @returns {cc.Size}
753      */
754     getVirtualRendererSize: function(){
755         return this._textFieldRenderer.getContentSize();
756     },
757 
758     /**
759      * Returns the renderer of ccui.TextField.
760      * @returns {cc.Node}
761      */
762     getVirtualRenderer: function () {
763         return this._textFieldRenderer;
764     },
765 
766     /**
767      * Returns the "class name" of ccui.TextField.
768      * @returns {string}
769      */
770     getDescription: function () {
771         return "TextField";
772     },
773 
774     /**
775      * Open keyboard and receive input text.
776      * @return {Boolean}
777      */
778     attachWithIME: function () {
779         this._textFieldRenderer.attachWithIME();
780     },
781 
782     _createCloneInstance: function () {
783         return new ccui.TextField();
784     },
785 
786     _copySpecialProperties: function (textField) {
787         this.setString(textField._textFieldRenderer.getString());
788         this.setPlaceHolder(textField.getString());
789         this.setFontSize(textField._textFieldRenderer.getFontSize());
790         this.setFontName(textField._textFieldRenderer.getFontName());
791         this.setMaxLengthEnabled(textField.isMaxLengthEnabled());
792         this.setMaxLength(textField.getMaxLength());
793         this.setPasswordEnabled(textField.isPasswordEnabled());
794         this.setPasswordStyleText(textField._passwordStyleText);
795         this.setAttachWithIME(textField.getAttachWithIME());
796         this.setDetachWithIME(textField.getDetachWithIME());
797         this.setInsertText(textField.getInsertText());
798         this.setDeleteBackward(textField.getDeleteBackward());
799         this._ccEventCallback = textField._ccEventCallback;
800         this._textFieldEventListener = textField._textFieldEventListener;
801         this._textFieldEventSelector = textField._textFieldEventSelector;
802     },
803 
804     /**
805      * Sets the text area size to ccui.TextField.
806      * @param {cc.Size} size
807      */
808     setTextAreaSize: function(size){
809         this.setContentSize(size);
810     },
811 
812     /**
813      * Sets the text horizontal alignment of ccui.TextField.
814      * @param alignment
815      */
816     setTextHorizontalAlignment: function(alignment){
817         this._textFieldRenderer.setHorizontalAlignment(alignment);
818     },
819 
820     /**
821      * Sets the text vertical alignment of ccui.TextField.
822      * @param alignment
823      */
824     setTextVerticalAlignment: function(alignment){
825         this._textFieldRenderer.setVerticalAlignment(alignment);
826     },
827     _setFont: function (font) {
828         this._textFieldRenderer._setFont(font);
829         this._textFieldRendererAdaptDirty = true;
830     },
831 
832     _getFont: function () {
833         return this._textFieldRenderer._getFont();
834     },
835 
836     _changePosition: function(){
837         this._adaptRenderers();
838     }
839 });
840 
841 /**
842  * Creates a ccui.TextField.
843  * @deprecated since v3.0, please use new ccui.TextField() instead.
844  * @param {String} placeholder
845  * @param {String} fontName
846  * @param {Number} fontSize
847  * @returns {ccui.TextField}
848  */
849 ccui.TextField.create = function(placeholder, fontName, fontSize){
850     return new ccui.TextField(placeholder, fontName, fontSize);
851 };
852 
853 var _p = ccui.TextField.prototype;
854 
855 // Extended properties
856 /** @expose */
857 _p.string;
858 cc.defineGetterSetter(_p, "string", _p.getString, _p.setString);
859 /** @expose */
860 _p.placeHolder;
861 cc.defineGetterSetter(_p, "placeHolder", _p.getPlaceHolder, _p.setPlaceHolder);
862 /** @expose */
863 _p.font;
864 cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont);
865 /** @expose */
866 _p.fontSize;
867 cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize);
868 /** @expose */
869 _p.fontName;
870 cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName);
871 /** @expose */
872 _p.maxLengthEnabled;
873 cc.defineGetterSetter(_p, "maxLengthEnabled", _p.isMaxLengthEnabled, _p.setMaxLengthEnabled);
874 /** @expose */
875 _p.maxLength;
876 cc.defineGetterSetter(_p, "maxLength", _p.getMaxLength, _p.setMaxLength);
877 /** @expose */
878 _p.passwordEnabled;
879 cc.defineGetterSetter(_p, "passwordEnabled", _p.isPasswordEnabled, _p.setPasswordEnabled);
880 
881 _p = null;
882 
883 // Constants
884 //TextField event
885 /**
886  * The attach with IME event flag of ccui.TextField
887  * @constant
888  * @type {number}
889  */
890 ccui.TextField.EVENT_ATTACH_WITH_IME = 0;
891 /**
892  * The detach with IME event flag of ccui.TextField
893  * @constant
894  * @type {number}
895  */
896 ccui.TextField.EVENT_DETACH_WITH_IME = 1;
897 /**
898  * The insert text event flag of ccui.TextField
899  * @constant
900  * @type {number}
901  */
902 ccui.TextField.EVENT_INSERT_TEXT = 2;
903 /**
904  * The delete backward event flag of ccui.TextField
905  * @constant
906  * @type {number}
907  */
908 ccui.TextField.EVENT_DELETE_BACKWARD = 3;
909 
910 /**
911  * The zOrder value of ccui.TextField's renderer.
912  * @constant
913  * @type {number}
914  */
915 ccui.TextField.RENDERER_ZORDER = -1;