Author: [EMAIL PROTECTED]
Date: Thu Nov 6 21:05:56 2008
New Revision: 3979
Modified:
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/common/EventReporter.java
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/VisualsForSuggestBoxEvents.java
branches/1_6_clean_events/user/src/com/google/gwt/user/client/L.java
branches/1_6_clean_events/user/src/com/google/gwt/user/client/Window.java
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/CheckBox.java
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/HasValue.java
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/L.java
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/SuggestBox.java
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/Widget.java
Log:
Various doc tweaks. Fix HandlerManager#isEventHandled. Nicer
Composite#onAttach. Widget#isOrWasAttached is now protected. Fix
SuggestionBox VisualTest
Modified:
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/common/EventReporter.java
==============================================================================
---
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/common/EventReporter.java
(original)
+++
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/common/EventReporter.java
Thu Nov 6 21:05:56 2008
@@ -35,7 +35,6 @@
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.GwtEvent;
-import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ClickListener;
@@ -72,7 +71,6 @@
*/
public abstract class CheckBoxEvent extends CheckBox implements
ValueChangeHandler<Boolean> {
- protected HandlerRegistration reg;
String name;
public CheckBoxEvent(String name, Panel p) {
@@ -80,7 +78,7 @@
this.setText(name);
p.add(this);
this.addValueChangeHandler(this);
- this.setChecked(true);
+ this.setValue(true, true);
}
public abstract void addHandler();
Modified:
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/VisualsForSuggestBoxEvents.java
==============================================================================
---
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/VisualsForSuggestBoxEvents.java
(original)
+++
branches/1_6_clean_events/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/VisualsForSuggestBoxEvents.java
Thu Nov 6 21:05:56 2008
@@ -18,6 +18,7 @@
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.museum.client.common.AbstractIssue;
import com.google.gwt.museum.client.common.EventReporter;
import com.google.gwt.user.client.ui.CheckBox;
@@ -92,7 +93,7 @@
report);
handler.new CheckBoxEvent("KeyDown", p) {
-
+ HandlerRegistration reg;
@Override
public void addHandler() {
reg = b.addKeyDownHandler(handler);
@@ -101,6 +102,7 @@
@Override
public void removeHandler() {
reg.removeHandler();
+ reg = null;
}
};
Modified:
branches/1_6_clean_events/user/src/com/google/gwt/user/client/L.java
==============================================================================
--- branches/1_6_clean_events/user/src/com/google/gwt/user/client/L.java
(original)
+++ branches/1_6_clean_events/user/src/com/google/gwt/user/client/L.java
Thu Nov 6 21:05:56 2008
@@ -29,8 +29,11 @@
import java.util.EventListener;
/**
- * Root of legacy listener support hierarchy.
+ * Legacy listener support hierarchy for
<code>com.google.gwt.user.client</code>.
+ * Gathers the bulk of the legacy glue code in one place, for easy
deletion when
+ * Listener methods are deleted.
*
+ * @see com.google.gwt.user.L
* @param <T> listener type
*/
@Deprecated
Modified:
branches/1_6_clean_events/user/src/com/google/gwt/user/client/Window.java
==============================================================================
---
branches/1_6_clean_events/user/src/com/google/gwt/user/client/Window.java
(original)
+++
branches/1_6_clean_events/user/src/com/google/gwt/user/client/Window.java
Thu Nov 6 21:05:56 2008
@@ -24,8 +24,8 @@
import com.google.gwt.event.logical.shared.HasResizeHandlers;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
-import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.http.client.URL;
@@ -58,8 +58,8 @@
}
/**
- * The message to display to the user in an attempt to keep them on the
- * page.
+ * The message to display to the user to see whether they really want
to
+ * leave the page.
*/
private String message = null;
Modified:
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/CheckBox.java
==============================================================================
---
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/CheckBox.java
(original)
+++
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/CheckBox.java
Thu Nov 6 21:05:56 2008
@@ -99,7 +99,8 @@
public HandlerRegistration addValueChangeHandler(
ValueChangeHandler<Boolean> handler) {
- // Is this the first value change event? If so, add hooking ability
+ // Is this the first value change event? If so, time to listen to
clicks
+ // on the checkbox
if (!isEventHandled(ValueChangeEvent.getType())) {
this.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
@@ -231,11 +232,11 @@
// wrapper element.
@Override
public void sinkEvents(int eventBitsToAdd) {
- if (eventsToSink == -1) {
+ if (isOrWasAttached()) {
DOM.sinkEvents(inputElem, eventBitsToAdd |
DOM.getEventsSunk(inputElem));
} else {
- eventsToSink |= eventBitsToAdd;
- }
+ super.sinkEvents(eventBitsToAdd);
+ }
}
/**
Modified:
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/HasValue.java
==============================================================================
---
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/HasValue.java
(original)
+++
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/HasValue.java
Thu Nov 6 21:05:56 2008
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Google Inc.
+ * Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
Modified:
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/L.java
==============================================================================
--- branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/L.java
(original)
+++ branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/L.java
Thu Nov 6 21:05:56 2008
@@ -73,18 +73,20 @@
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
-import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.GwtEvent.Type;
import java.util.EventListener;
/**
- * Root of legacy listener support hierarchy.
+ * Legacy listener support hierarchy for
+ * <code>com.google.gwt.user.client.ui</code>. Gathers the bulk of the
legacy
+ * glue code in one place, for easy deletion when Listener methods are
deleted.
*
+ * @see com.google.gwt.user.client.L
* @param <T> listener type
- *
*/
@Deprecated
abstract class L<T> implements EventHandler {
Modified:
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/SuggestBox.java
==============================================================================
---
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/SuggestBox.java
(original)
+++
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/SuggestBox.java
Thu Nov 6 21:05:56 2008
@@ -87,32 +87,31 @@
* <img class='gallery' src='SuggestBox.png'/>
* </p>
*
- * <h3>CSS Style Rules</h3> <ul class='css'> <li>.gwt-SuggestBox { the
suggest
- * box itself }</li> <li>.gwt-SuggestBoxPopup { the suggestion popup
}</li> <li>
- * .gwt-SuggestBoxPopup .item { an unselected suggestion }</li> <li>
- * .gwt-SuggestBoxPopup .item-selected { a selected suggestion }</li> <li>
- * .gwt-SuggestBoxPopup .suggestPopupTopLeft { the top left cell }</li>
<li>
- * .gwt-SuggestBoxPopup .suggestPopupTopLeftInner { the inner element of
the
- * cell }</li> <li>.gwt-SuggestBoxPopup .suggestPopupTopCenter { the top
center
- * cell }</li> <li>.gwt-SuggestBoxPopup .suggestPopupTopCenterInner { the
inner
- * element of the cell }</li>
<li>.gwt-SuggestBoxPopup .suggestPopupTopRight {
- * the top right cell }</li>
<li>.gwt-SuggestBoxPopup .suggestPopupTopRightInner
- * { the inner element of the cell }</li> <li>.gwt-SuggestBoxPopup
- * .suggestPopupMiddleLeft { the middle left cell }</li> <li>
- * .gwt-SuggestBoxPopup .suggestPopupMiddleLeftInner { the inner element
of the
- * cell }</li> <li>.gwt-SuggestBoxPopup .suggestPopupMiddleCenter { the
middle
- * center cell }</li>
<li>.gwt-SuggestBoxPopup .suggestPopupMiddleCenterInner {
- * the inner element of the cell }</li> <li>.gwt-SuggestBoxPopup
- * .suggestPopupMiddleRight { the middle right cell }</li> <li>
- * .gwt-SuggestBoxPopup .suggestPopupMiddleRightInner { the inner element
of the
- * cell }</li> <li>.gwt-SuggestBoxPopup .suggestPopupBottomLeft { the
bottom
- * left cell }</li> <li>.gwt-SuggestBoxPopup .suggestPopupBottomLeftInner
{ the
- * inner element of the cell }</li> <li>.gwt-SuggestBoxPopup
- * .suggestPopupBottomCenter { the bottom center cell }</li> <li>
- * .gwt-SuggestBoxPopup .suggestPopupBottomCenterInner { the inner element
of
- * the cell }</li> <li>.gwt-SuggestBoxPopup .suggestPopupBottomRight { the
- * bottom right cell }</li> <li>.gwt-SuggestBoxPopup
- * .suggestPopupBottomRightInner { the inner element of the cell }</li>
</ul>
+ * <h3>CSS Style Rules</h3>
+ * <ul class='css'>
+ * <li>.gwt-SuggestBox { the suggest
+ * box itself }</li>
+ * <li>.gwt-SuggestBoxPopup { the suggestion popup }</li>
+ * <li>.gwt-SuggestBoxPopup .item { an unselected suggestion }</li>
+ * <li>.gwt-SuggestBoxPopup .item-selected { a selected suggestion }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupTopLeft { the top left cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupTopLeftInner { the inner element
of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupTopCenter { the top center cell
}</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupTopCenterInner { the inner
element of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupTopRight { the top right cell
}</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupTopRightInner { the inner element
of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupMiddleLeft { the middle left cell
}</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupMiddleLeftInner { the inner
element of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupMiddleCenter { the middle center
cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupMiddleCenterInner { the inner
element of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupMiddleRight { the middle right
cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupMiddleRightInner { the inner
element of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupBottomLeft { the bottom left cell
}</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupBottomLeftInner { the inner
element of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupBottomCenter { the bottom center
cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupBottomCenterInner { the inner
element of the cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupBottomRight { the bottom right
cell }</li>
+ * <li>.gwt-SuggestBoxPopup .suggestPopupBottomRightInner { the inner
element of the cell }</li> </ul>
*
* @see SuggestOracle
* @see MultiWordSuggestOracle
Modified:
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/Widget.java
==============================================================================
---
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/Widget.java
(original)
+++
branches/1_6_clean_events/user/src/com/google/gwt/user/client/ui/Widget.java
Thu Nov 6 21:05:56 2008
@@ -17,8 +17,8 @@
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.logical.shared.HasHandlers;
-import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
@@ -33,9 +33,12 @@
public class Widget extends UIObject implements EventListener, HasHandlers
{
/**
* A bit-map of the events that should be sunk when the widget is
attached to
- * the DOM. We delay the sinking of events to improve startup
performance.
+ * the DOM. (We delay the sinking of events to improve startup
performance.)
+ * When the widget is attached, this is set to -1
+ * <p>
+ * Package protected to allow Composite to see it.
*/
- int eventsToSink;
+ int eventsToSink = 0;
private boolean attached;
private Object layoutData;
@@ -72,13 +75,17 @@
}
/**
- * Is the given event handled by this widget?
+ * Returns true if the widget has handlers of the given type. Used by
some
+ * widget implementations to be lazy about initializing dom event
handlers
+ * (e.g. a click handler on a checkbox) until the first relevant logical
event
+ * handler is attached (e.g. in the <code>addValueChangeHandler</code>
+ * method).
*
* @param type the event type
- * @return is it handled?
+ * @return true if the widget has handlers of the give type
*/
public boolean isEventHandled(GwtEvent.Type<?> type) {
- return handlerManager == null || handlerManager.isEventHandled(type);
+ return handlerManager != null && handlerManager.isEventHandled(type);
}
public void onBrowserEvent(Event nativeEvent) {
@@ -101,6 +108,22 @@
}
}
+ /**
+ * Overridden to defer the call to super.sinkEvents until the first time
this
+ * widget is attached to the dom, as a performance enhancement.
Subclasses
+ * wishing to customize sinkEvents can preserve this deferred sink
behavior
+ * by putting their implementation behind a check of [EMAIL PROTECTED]
#isOrWasAttached()}:
+ *
+ * <pre>
+ * [EMAIL PROTECTED] @}Override
+ * public void sinkEvents(int eventBitsToAdd) {
+ * if (isOrWasAttached()) {
+ * /[EMAIL PROTECTED] *} customized sink code goes here [EMAIL
PROTECTED] *}/
+ * } else {
+ * super.sinkEvents(eventBitsToAdd);
+ * }
+ *} </pre>
+ */
@Override
public void sinkEvents(int eventBitsToAdd) {
if (isOrWasAttached()) {
@@ -123,13 +146,7 @@
protected final <H extends EventHandler> HandlerRegistration
addDomHandler(
final H handler, DomEvent.Type<H> type) {
if (type != null) {
- // Manual inline sinkEvents.
- int eventBitsToAdd = type.getEventToSink();
- if (isOrWasAttached()) {
- super.sinkEvents(eventBitsToAdd);
- } else {
- eventsToSink |= eventBitsToAdd;
- }
+ sinkEvents(type.getEventToSink());
}
return ensureHandlers().addHandler(type, handler);
}
@@ -149,7 +166,7 @@
/**
* If a widget implements HasWidgets, it must override this method and
call
- * onAttach() for each of its child widgets.
+ * [EMAIL PROTECTED] #onAttach()} for each of its child widgets.
*
* @see Panel#onAttach()
*/
@@ -188,6 +205,15 @@
}
/**
+ * Has this widget ever been attached?
+ *
+ * @return true if this widget ever been attached to the DOM, false
otherwise
+ */
+ protected final boolean isOrWasAttached() {
+ return eventsToSink == -1;
+ }
+
+ /**
* This method is called when a widget is attached to the browser's
document.
* To receive notification after a Widget has been added to the document,
* override the [EMAIL PROTECTED] #onLoad} method.
@@ -210,7 +236,6 @@
// Event hookup code
DOM.setEventListener(getElement(), this);
-
int bitsToAdd = eventsToSink;
eventsToSink = -1;
if (bitsToAdd > 0) {
@@ -279,15 +304,6 @@
*/
Object getLayoutData() {
return layoutData;
- }
-
- /**
- * Has this widget ever been attached?
- *
- * @return has this widget been attached
- */
- final boolean isOrWasAttached() {
- return eventsToSink == -1;
}
@Override
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---