Danh mục

Creating Applications with Mozilla-Chapter 7. Extending the UI with XBL- P2

Số trang: 11      Loại file: pdf      Dung lượng: 27.25 KB      Lượt xem: 1      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: miễn phí Tải xuống file đầy đủ (11 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu creating applications with mozilla-chapter 7. extending the ui with xbl- p2, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Creating Applications with Mozilla-Chapter 7. Extending the UI with XBL- P2Chapter 7. Extending the UI with XBL- P2The code you see here is not necessary in this binding, but it shows you theformat for executing code in the destructor. Destructors are great to usewhen you have loaded a component in the binding and want to set thevariable representing the component to null to avoid memory leaks. If youhave a lot of bindings that load and then unload components while a Mozillasession is still running, a significant amount of memory can be eaten upunless you take this kind of step.7.2.3.3. PropertiesLike Java properties, an XBL has getters and setters, so theycan behave differently when you read or write data. Here is a subset ofproperties used in this binding: return this.input.value; returnthis.input.inputField.style.backgroundColor; this.input.inputField.style.backgroundColor=val; return val; At this point, the characteristics of properties to watch out for include thereadonly attribute, the getter and setter elements, and the existence of aval keyword that is used internally for accessing a propertys current value.For your reference, this bindings property extracts are used for getting thevalue of the input field, returning an uppercase version of the inputted text,and getting or setting the input fields background color.7.2.3.4. MethodsMethods in XBL are self-contained functions represented by the tag and encapsulated within the element. Theyusually provide a binding object with a specific function like copying andsaving some data or showing and hiding widget controls. Like properties,they can be called from within the binding, from another binding thatsubclasses that binding, and directly from the bound element. this.input.value=; this.input.value=newValue; The method code is contained in a tag, and each method can have 0or more parameters, which gather the values passed into the method whencalled.7.2.4. HandlersHandlers in XBL mimic regular document events like onclick andonmousedown, and provide a means for trapping them within your bindingand carrying out tasks associated with them. this.input.focus( ); Each handler is contained in a tag and the event name isplaced in the event attribute -- minus the on prefix. The handler in thecode shown above places the focus in the inputfield when the mousegoes over it. See the section Event Handling, later in this chapter, for moredetails.7.2.5. StyleThe sample bindings last piece of the puzzle is style. Any XUL elementsused in the content inherit the default styles for those widgets, but if youwant to add more, you can include your own stylesheet like this: Notice the container element, which is a prerequisite forthis feature. The use of stylesheets in bindings is covered more thoroughly atthe end of the chapter in the section Section 7.7.At this point, you should be familiar with the pieces that make up a binding,which, at the top level, are the content, implementation, event handlers, andextra resources. The binding that you have constructed is small, yet it showsall the main concepts involved in structuring a binding. With somepersonalizing, it could be included in potentially any application.7.3. Adding Behavior to BindingsLike XUL widgets, XBL uses JavaScript to provide functionality to bindingsby accessing XPCOM methods via XPConnect. Like binding content,behavior is optional in a binding. Each can exist without the other. At times,you might want only implementations, such as a base binding that containscertain properties that are inherited by other bindings.The element is the container for all other elementsthat make up a bindings behavioral portion. Example 7-1 shows an emptyimplementation shell that highlights the elements contained hierarchy.Example 7-1. XBL implementation element The code in Example 7-1 shows the element havinga constructor, destructor, method, property, and field as possible children.Each component can exist in quantities of zero or more, with the exceptionof the constructor and destructor, of which there can be only zero or one.The rest of this section describes each binding implementation component inmore detail.7.3.1. Binding MethodsBindings can exist solely as content generators, acting passively when theyare drawn. But you can also create bindings that provide new capabilitiesand more interactive functions or that execute routines in your application.In the spirit of self-containment, functions can be added to a binding thatcarry out functionality related to that binding. These functions are thebehavior of a binding. The ideal way to add behavior is to add methods toyour binding with the element. Each parameter for a methoddefined in the element is contained within its own tag. To use the method to print text to the command shell, call the name that isspecified in the name attribute. All methods created in a binding are addedto the binding element object and called as members of that object, as shownhere: Using the Two special methods exist in XBL that allow you to manipulate whathappens when a binding is added or removed from a document. Thesemethods use the native and tags. Aconstructor is valuable, for example, when you need to initialize a bindingobject or prefill the UI based on stored values. Destructors can clean upwhen a binding is discarded.When bindings are attached, their content is inserted into the document atthe point you specify. After insertion -- or, more specifically, after theattachment occurs -- the code in the executes. Similarly,you can use the element to execute functions whe ...

Tài liệu được xem nhiều: