Archive for the ‘HTML and CSS’ Category

GWT Glass Pane

This code darkens the entire screen, allowing you to create lightbox effects when showing dialogs. For example, here is the normal screen:

Lightbox 1

And here is how the screen looks with a glass pane and dialog:

Lightbox 2

There are GWT component libraries that do this sort of thing, for example GlassPanel, but I prefer to minimize external dependencies. Instead, I decided to try this code example by Evaldas Taroza.

My Changes

I made a few changes to the original code:

  • Since I’m using GWT 1.7, I implement ResizeHandler instead of WindowResizeListener, which is deprecated.
  • I’m removing the -moz-opacity since it is specific to older versions of Mozilla and no longer seems relevant.

The Final Code

First, here is the CSS file:

.gcomp-GlassPanel {
    background-color: black;
    filter: alpha(opacity=50);
    opacity: .50;
}

Next, here is the JavaDoc comment, listed separately because syntax highlighting wasn’t working here on my blog.

/**
 * This panel is positioned absolutely and covers the whole client
 * area of the browser. It can be used to disable everything
 * underneath it with appropriate z-index.
 * <p/>
 * For instance a dialog can attach it to the root panel during
 * opening, and remove it during closing.
 * <p/>
 * CSS:<br>
 * .gcomp-GlassPanel
 * <p/>
 * Example:<br>
 * Add and remove this widget whenever you want, and style it as
 * follows:
 * <pre>
 * .gcomp-GlassPanel{
 *   background-color: black;
 *   filter:alpha(opacity=50);
 *   opacity:.50;
 * }
 * </pre>
 */

And here is the code…

public class GlassPanel extends Composite implements ResizeHandler {
    public static final String STYLE = "gcomp-GlassPanel";

    private SimplePanel panel = new SimplePanel();

    public GlassPanel() {
        initWidget(panel);

        panel.setStylePrimaryName(STYLE);
        Window.addResizeHandler(this);
        resize();
    }

    public void onResize(ResizeEvent event) {
        resize();
    }

    public void show() {
        // Override the styles explicitly, because it's needed
        // every time the widget is detached
        Element elem = panel.getElement();
        DOM.setStyleAttribute(elem, "left", "0");
        DOM.setStyleAttribute(elem, "top", "0");
        DOM.setStyleAttribute(elem, "position", "absolute");
        RootPanel.get().add(this);
    }

    public void hide() {
        RootPanel.get().remove(this);
    }

    private void resize() {
        panel.setSize(Window.getClientWidth() + "px",
                Window.getClientHeight() + "px");
    }
}

I’ve only done minimal testing, on the latest Firefox and IE7.

Firefox 3.5 and the Beach Ball

I’m using Firefox 3.5 on Leopard, and noticing several slowdowns.

When we say Firefox 3.5 is fast, we mean it sometimes slows down. And by “sometimes slows down”, we mean the spinning beach ball of death.

Here are two cases where I see problems.

First, I see a severe slowdown in the Amazon.com search field. The slowdown occurs when I type a few characters and then hit the “:” key. For instance, try searching for “Bitter:Sweet”. Who knows if this is an Amazon or a Firefox problem. I just know it is slow.

The second slowdown was far worse. It occurred as I was creating my previous blog post. Ironically, I wanted to include a link to the HTML 5 specification. So in my first tab I had my blog open, and in the second tab I had the HTML 5 specification open.

I found the section on HTML video, selected the URL, and copied to the clipboard. When I returned to my blog page, Firefox completely locked up and I saw the spinning beach ball of death. I had to kill the process to regain control.

I repeated the above steps, and once again it completely locked up.

I finally managed to create that post, but only without the HTML 5 spec page open. So just now, while typing the previous paragraph, I again opened this URL.

And once again, Firefox became completely unresponsive, showing the beach ball for about 15-30 seconds.

It is mildly amusing that the one page that consistently brings Firefox 3.5 to its knees is the HTML 5 specification page.

One Problem with HTML Video

The HTML 5 video element is a move in the right direction, but it currently doesn’t work in Google Reader. Here is how a YouTube video looks in Reader:

This is on a Mac, using Firefox 3.5. Here is a blog containing the new HTML 5 video tag:

When I go to that blog, it works…just not in Reader.

Chrome Process Notes

I ran through a quick and dirty comparison of Firefox 2.0.0.16 and Chrome 0.2.149.27, running on Windows Vista. I opened each browser side-by-side and added one tab at a time. As I added each tab, I noted the memory usage. I viewed these web pages:

Tab Page
1 google.com
2 cnn.com
3 digg.com
4 reader.google.com
5 stuffthathappens.com/blog
6 amazon.com

Memory Usage

I obtained these numbers from Vista’s task manager. Vista has many different “memory usage” statistics, and I have no idea what each implies. I do not claim these numbers mean anything other than…here are a bunch of numbers.

Here are the numbers from Vista’s “Working Set” column. Note there are multiple numbers for Chrome because each new tab opens one — or more — new processes.

Tabs    Firefox   Chrome
1       51176     11756 24164
2       78120     11756 12992 24852 25260
3       94084     11756 22080 24860 32304 23932
4       102992     6164 11756 22088 24860 20856 40040 23960
5       116008     6164 18820 11756 22088 24860 20860 43628 24868
6       134360     6164 18820 11756 22088 24616 24860 20444 49192 25624
Dropping back down to 1 tab:
1       111240     11760 35856

Note that Vista’s “Private Working Set” reports different, and lower, numbers:

Tabs    Firefox   Chrome
6       111476    1096 10792 4080 13852 16792 16656 12368 31608 18564

I should also note that many numbers were constantly changing, so these are all approximations. Vista’s task manager also shows many other columns:

  • Peak Working Set
  • Working Set Delta
  • Commit Size
  • Paged Pool
  • Non-paged Pool
  • etc…

Lessons Learned?

Not much! I’m no Vista programmer, so I don’t know how to interpret these numbers. Here is what I am comfortable saying:

  • As I added more tabs, Firefox slowed down. Chrome did not.
  • Each new Chrome tab adds one or more processes. It looks like the number of processes depends on what content is on the web site.
  • You’d need more detailed memory analysis tools to truly understand what’s going on.
  • As I closed tabs, Chrome stops the processes within a few seconds, freeing up memory. Firefox seemed to hang on to memory for a longer time. Again, these are just initial impressions with very limited tools at my disposal.

Chrome is fast, I’m writing this post using it, and it seems to work just fine. In the end, I’m happy to see another competitor because this puts more heat on the other browsers to improve performance and compatibility. This is the kind of browser war was can all be happy with.

GWT Has Style

With Twitter unreachable right now, I guess I’ll put this here:

Create good default styles; unify sample styles.

Reset CSS?

I plan to create a new theme for this blog, and am seeking opinions. Should I base my CSS on this Reset Reloaded stylesheet?

What do you do for your own sites?

On Links and IDs

After writing Best. Comment. Ever., I realized comment permalinks were not working on my blog. Clicking the link brought up the page, but failed to scroll to the comment.

Jörg offers this advice:

Firefox does right, and so does safari: You anchors name (”…#comment-7155″) contains a “-”, which is an invalid name. Try something like “#comment7155″, it will work.

While his suggestion served as a catalyst for me to finally investigate the problem, I was not convinced “-” was the cause. So I researched the HTML specification, which has this to say:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (”-”), underscores (”_”), colons (”:”), and periods (”.”)

Dashes are frequently used in URLs, so this cannot be the problem.

The Solution

While my heavily customized WordPress theme defined links, it failed to define anchors or IDs. So the links were going nowhere. I had to edit comments.php and add this ID to a <div> tag:

<div id="comment-<?php comment_ID() ?>" class="comment">

And that fixed the problem. I also re-learned some things about HTML that I probably knew at one point, but forgot:

  • On the receiving end of an anchor-type link, you omit the # character
  • You don’t have to link to <a name=”something”>. As my theme shows, you can link to <div id=”something”>

I suspect WordPress works fine out of the box, but I must have screwed it up when creating this theme.

IE 8 Passes Acid2 Test

Didn’t see this one coming…today the IEBlog breaks the IE 8 cone of silence:

Last week, we achieved an important milestone that should interest web developers. IE8 now renders the “Acid2 Face” correctly in IE8 standards mode.

Here is how Acid2 renders today, under IE7 on Vista:

Acid2 on IE7 Vista

Under IE8 “in standards mode”, the face renders like this:

Acid2 on IE8

Standards Mode or Quirks Mode?

Here is the first line of the Acid2 Browser Test test page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

That line actually puts IE7 into something called “Almost Standards Mode”, according to the Wikipedia Quirks mode article.

Watch the Video

When you visit the Acid2 Browser Test page, will IE8 be in “Almost Standards Mode”, or will it render in “Standards Mode”?

The IEBlog did not make this clear. I found myself wondering if they did this:

  1. Visit the Acid2 Browser Test page
  2. Save the source to a file
  3. Edit the first line of HTML to something that puts IE8 into standards mode
  4. Load that slightly modified file

Fortunately, the Video on Channel 9 clears this up. Fast forward to around 21:30 in the video to see that the smiley face renders correctly on the live site, not on a modified local copy.

This is really good news. Let’s hope they continue improving standards compliance in IE8 and beyond.

Make CSS Work

Microsoft just announced the next version of IE will be called…IE 8.

Add that to my “Wow” list.

My ideas for IE 8:

  • Properly implement CSS, in particular the box model. Consistent page layout across browsers is a huge challenge.
  • Make sure Vista still works even when I have Firefox configured as my default browser.
  • Make standards modes default, not quirks mode.
  • See that search box at the top of my blog? It works in Firefox, but in IE I’d have to use a hack to get that background image to disappear when the box has focus. Fix that.

I guess the last bullet is another CSS issue. The previous bullet is probably more an issue with Microsoft web sites insisting on being IE proprietary, which sucks.

So, to summarize:

Make CSS Work.

GWT First Thoughts

With a sick child at home, I had some time this afternoon to play with Google Web Toolkit (GWT). Learning GWT has been on my “technologies to investigate” list for far too long; today I finally dove in. First impressions:

  • GWT is quite a bit simpler than I thought it would be. I guess all that procrastination was for nothing.
  • Having two monitors really helps the learning process. There are a huge number of getting started articles and tutorials, so having a web browser open on one display to read examples while coding in an IDE on another display is almost essential.
  • Just dive in and start coding. I’ve attended GWT presentations, watched online videos, read (some) docs…but nothing compares to writing code.
  • One of the first things I created was a TabPanel. I was someone surprised by the complete lack of a default style. Until you start messing with CSS, it looks nothing like a tabbed pane. I got completely sidetracked hacking CSS, which took vastly more time than writing the Java code to create the tabbed pane in the first place! :-)
  • It seems like there is an opportunity for talented CSS designers to put together GWT Theme Packs, consisting of ready-to-use CSS and images that give your GWT app a particular look.
  • The biggest surprise (for me) was the fact that GWT still uses Java 1.4 syntax. I guess I just assumed it would be Java 5 based on experience with other Google Java APIs.
  • Other than the CSS, writing a GWT app feels nothing like writing a web app. (this is a very, very good thing…)
  • They’ve done a great job providing a usable development environment out of the box. Far too many other tools leave IDE and app server configuration completely up to the developer. Thus, when starting with most technologies, you spend a great deal of time tracking down JAR files, configuring Tomcat, coming up with a custom development “flow” to compile, deploy, bounce Tomcat, etc. GWT comes with tools to setup the initial project, hot deploy, and test.
  • A bit more on the previous bullet…they’ve also managed to do that without locking you into a particular IDE like Eclipse or NetBeans. I find it disturbing when vendors try to lock me in to a particular IDE by writing tutorials and plugins that assume I only use one specific IDE and app server combination. So far, GWT works great in IDEA. I’m sure I could easily switch to Eclipse and everything would work there as well.
  • I plan to continue this journey.