Hack 91. Handle Cross-Platform Differences
Manage the differences among standard Firefox installs on different platforms. Firefox works hard to provide the same user interface and web page displays on all platforms: Windows, Unix/Linux, and Macintosh. A great deal of effort has gone into this, especially with respect to the Gecko layout engine. Where the underlying operating systems are different, or where specific installations are different, differences can sometimes show through. This hack points out the most obvious cases and shows how to manage them. At first, such differences might be irritating or awkward for users, but the consequences are felt mostly in XUL-based user-interface development, where a little care in constructing XUL documents is required. Fundamentally, a single, compiled Firefox program cannot run on all platforms. Therefore, the standard Firefox install is created and customized separately for each platform. Although there is only one source code base, some small parts of it are operating-system-specific. 9.2.1. Handling Obvious Big-Ticket DifferencesHuman Interface Guidelines (HIGs) are standards that encourage all applications in a given desktop environment to provide similar idioms of use. Since HIGs for Apple, Microsoft, and Linux (e.g., GNOME) all differ, a tool that hopes to get a standards tick on every platform must look different on each platform. These are the big-ticket differences and how Firefox handles them:
Firefox obeys all window-management hints or instructions that it receives. Under X11/Gtk, a window cannot be 0 0 pixels in size (it can on Windows). There are no perfectly portable solutions for desktop theme integration [Hack #79], unfortunately, but with a lot of work you can come close. 9.2.2. Handling Widget DifferencesEach operating system provides or supports a GUI library that can be used to draw interactive widgets. Firefox does not draw widgets using these libraries. Firefox uses its own widget-drawing code to draw widgets on a blank canvas supplied by those libraries. So, for example, Firefox for Windows does not depend on COMCTL32.DLL (or .OCX), and replacing that library is therefore of no use. There are two areas of the desktop GUI that Firefox widgets depend upon. One is the theme engine for natively styled widgets [Hack #79] . Not all platforms support all -moz-appearance values, so applying such a style property can do nothing in some instances, but at least that's harmless. The second area is the operating-system accessibility API. This is wrapped up in a portable XPCOM object with the nsIAccessible interface. It is used in the XBL definitions for XUL widgets [Hack #90] . You can't see the equivalent use for HTML tags unless you turn on XHTML tag support. Where there is accessibility support, follow the guidelines at http://www.mozilla.org/access/xul-guidelines for best results in XUL. In general, don't try to lay out XUL or HTML widgets in pixel-perfect style. What looks good on one operating system will be up for debate on another. It is better to pack widgets loosely, using the naturally flowing layout of the page: line boxes and blocks for HTML, boxes for XUL. 9.2.3. Handling Font DifferencesFirefox must source, choose, analyze, resize and lay out font information [Hack #30] before it can ultimately be displayed. On Windows, Firefox uses some low-level features of GDI such as GetTextExtentPoint32 or ExtTextOutW, but ultimately it uses its own layout and font selection algorithms. |