You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



You are here: Editor project page > Editor in Text Widgets

The Editor in Text Widgets


Introduction

The editor is also used as in XUL and HTML text widgets in Mozilla. This allows us to have a single codebase for text editing, which handles international text input (IME), and allows for stylability with CSS. However, the requirements for the editor in text widgets is somehwat different to its use in composer, so the editor needs to be flexible enough for use in both situations. The main differences are:

Composer Text widgets
Editor acts on: Whole document Document subtree
Capabilities: Rich HTML editing Plain text only
Hosting code: editor shell Layout frame & content code

In text widgets, the editor is created and hosted by the frame (i.e. layout frame object) for text widgets, which is nsGfxTextControlFrame2. This frame creates and registers an event handler for the editor which feeds it keypress and focus events, and gets and sets the value of the text widget by calling the editor API.

The first implementation of the editor-as-text-widget used a heavy weight approach where each text widget has its own subdocument and associcated data structures, and the editor acted on that subdocument (this was the original nsGfxTextControlFrame). More recently, we adopted an approach (commonly referred to as ender lite) in which the contents of the text widget are actually in the parent document, but are anonymous content. Anonymous content is document content that cannot be reached using the standard DOM APIs, but which is accessible for special uses. With ender-lite, the editor is acting on a subtree of the parent document (either an HTML document, for a form control widget, or a XUL document for a XUL text input field). In this case the editor "knows" the root of the content subtree that it is allowed to mess with.

Editor instantiation

Construction of a frame for text widgets happens when layout constructs frames after seeing an <input type="text"> in HTML, or a <textfield> in XUL (note that this happens on initial page loading, and after anything else that causes frames to be rebuilt, such as stylesheet changes). nsCSSFrameConstructor::ConstructTextControlFrame() makes the text control frame, and soon after, nsGfxTextControlFrame2::ÈB;CreateAnonymousContent() gets called (because nsGfxTextControlFrame2 implements nsIAnonymousContentCreator). This calls is where we build the anonymous content that is to hold the text field contents, and make the editor on it. We make a <div> element which gets inserted into the content tree as an anonymous child of the <input> element.

Event handling

 

Command handling

 

Last modified: July 21 2000

Maintained by the editor team: mozilla-editor@mozilla.org