Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 3 additions & 162 deletions user/src/com/google/gwt/dom/client/DOMImplMozilla.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,75 +20,6 @@
*/
class DOMImplMozilla extends DOMImplStandard {

private static int cachedGeckoVersion = -2;

private static int getGeckoVersion() {
if (cachedGeckoVersion == -2) {
cachedGeckoVersion = getNativeGeckoVersion();
}
return cachedGeckoVersion;
}

private static native int getNativeGeckoVersion() /*-{
var result = /rv:([0-9]+)\.([0-9]+)(\.([0-9]+))?.*?/.exec(navigator.userAgent.toLowerCase());
if (result && result.length >= 3) {
var version = (parseInt(result[1]) * 1000000) + (parseInt(result[2]) * 1000) +
parseInt(result.length >= 5 && !isNaN(result[4]) ? result[4] : 0);
return version;
}
return -1; // not gecko
}-*/;

/**
* Return true if using Gecko 1.9 (Firefox 3) or later.
*
* @return true if using Gecko 1.9 (Firefox 3) or later
*/
private static boolean isGecko19() {
int geckoVersion = getGeckoVersion();
return (geckoVersion != -1) && (geckoVersion >= 1009000);
}

/**
* Return true if using Gecko 1.9.0 (Firefox 3) or earlier.
*
* @return true if using Gecko 1.9.0 (Firefox 3) or earlier
*/
private static boolean isGecko190OrBefore() {
int geckoVersion = getGeckoVersion();
return (geckoVersion != -1) && (geckoVersion <= 1009000);
}

/**
* Return true if using Gecko 1.9.1 (Firefox 3.5) or earlier.
*
* @return true if using Gecko 1.9.1 (Firefox 3.5) or earlier
*/
private static boolean isGecko191OrBefore() {
int geckoVersion = getGeckoVersion();
return (geckoVersion != -1) && (geckoVersion <= 1009001);
}

/**
* Return true if using Gecko 1.9.2 (Firefox 3.6) or earlier.
*
* @return true if using Gecko 1.9.2 (Firefox 3.6) or earlier
*/
private static boolean isGecko192OrBefore() {
int geckoVersion = getGeckoVersion();
return (geckoVersion != -1) && (geckoVersion <= 1009002);
}

/**
* Return true if using Gecko 2.0.0 (Firefox 4.0) or earlier.
*
* @return true if using Gecko 2.0.0 (Firefox 4.0) or earlier
*/
private static boolean isGecko2OrBefore() {
int geckoVersion = getGeckoVersion();
return (geckoVersion != -1) && (geckoVersion < 2000000);
}

@Override
public native void buttonClick(ButtonElement button) /*-{
var doc = button.ownerDocument;
Expand Down Expand Up @@ -124,23 +55,6 @@ public NativeEvent createKeyPressEvent(Document doc, boolean ctrlKey,
shiftKey, metaKey, 0, charCode);
}

@Override
public native EventTarget eventGetRelatedTarget(NativeEvent evt) /*-{
// Hack around Mozilla bug 497780 (relatedTarget sometimes returns XUL
// elements). Trying to access relatedTarget.nodeName will throw an
// exception if it's a XUL element.
var relatedTarget = evt.relatedTarget;
if (!relatedTarget) {
return null;
}
try {
var nodeName = relatedTarget.nodeName;
return relatedTarget;
} catch (e) {
return null;
}
}-*/;

@Override
public int getAbsoluteLeft(Element elem) {
return getAbsoluteLeftImpl(elem.getOwnerDocument().getViewportElement(),
Expand All @@ -156,20 +70,12 @@ public int getAbsoluteTop(Element elem) {
@Override
public native int getBodyOffsetLeft(Document doc) /*-{
var style = $wnd.getComputedStyle(doc.documentElement, null);
if (style == null) {
// Works around https://bugzilla.mozilla.org/show_bug.cgi?id=548397
return 0;
}
return parseInt(style.marginLeft, 10) + parseInt(style.borderLeftWidth, 10);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I think this might be wrong in other browsers - the superclass only returns 0, mozilla is the only impl that actually reads values from the dom. Ditto offsettop below. Probably out of scope here, just seeking to remove this extra null check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FF implementation matches the name, but the WebKit implementation results in more sensible behavior.

  1. go to https://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwBasicPopup
  2. run document.documentElement.style.margin="100px"; in the console
  3. click the image

Expected: popup centered
Actual: popup too far left in FF (but centered in WebKit)

}-*/;

@Override
public native int getBodyOffsetTop(Document doc) /*-{
var style = $wnd.getComputedStyle(doc.documentElement, null);
if (style == null) {
// Works around https://bugzilla.mozilla.org/show_bug.cgi?id=548397
return 0;
}
return parseInt(style.marginTop, 10) + parseInt(style.borderTopWidth, 10);
}-*/;

Expand All @@ -184,47 +90,21 @@ public native int getNodeType(Node node) /*-{
//
// See https://bugzilla.mozilla.org/show_bug.cgi?id=208427
// and http://code.google.com/p/google-web-toolkit/issues/detail?id=1909
// Fixed FF 148, reevaluate once ESR > 148
return 0;
}
}-*/;

@Override
public int getScrollLeft(Element elem) {
if (!isGecko19() && isRTL(elem)) {
return super.getScrollLeft(elem)
- (elem.getScrollWidth() - elem.getClientWidth());
}
return super.getScrollLeft(elem);
}

@Override
public native boolean isOrHasChild(Node parent, Node child) /*-{
// For more information about compareDocumentPosition, see:
// http://www.quirksmode.org/blog/archives/2006/01/contains_for_mo.html
return (parent === child) || !!(parent.compareDocumentPosition(child) & 16);
}-*/;

@Override
public void setScrollLeft(Element elem, int left) {
if (!isGecko19() && isRTL(elem)) {
left += elem.getScrollWidth() - elem.getClientWidth();
}
super.setScrollLeft(elem, left);
}

@Override
public native String toString(Element elem) /*-{
// Basic idea is to use the innerHTML property by copying the node into a
// div and getting the innerHTML
var doc = elem.ownerDocument;
var temp = elem.cloneNode(true);
var tempDiv = doc.createElement("DIV");
tempDiv.appendChild(temp);
outer = tempDiv.innerHTML;
temp.innerHTML = "";
return outer;
}-*/;

private native NativeEvent createKeyEventImpl(Document doc, String type,
boolean canBubble, boolean cancelable, boolean ctrlKey, boolean altKey,
boolean shiftKey, boolean metaKey, int keyCode, int charCode) /*-{
Expand Down Expand Up @@ -255,50 +135,11 @@ private native NativeEvent createKeyEventImpl(Document doc, String type,
}-*/;

private native int getAbsoluteLeftImpl(Element viewport, Element elem) /*-{
// Firefox 3 is actively throwing errors when getBoxObjectFor() is called,
// so we use getBoundingClientRect() whenever possible (but it's not
// supported on older versions). If changing this code, make sure to check
// the museum entry for issue 1932.
// (x) | 0 is used to coerce the value to an integer
if (Element.prototype.getBoundingClientRect) {
return (elem.getBoundingClientRect().left + viewport.scrollLeft) | 0;
} else {
// We cannot use DOMImpl here because offsetLeft/Top return erroneous
// values when overflow is not visible. We have to difference screenX
// here due to a change in getBoxObjectFor which causes inconsistencies
// on whether the calculations are inside or outside of the element's
// border.
// If the element is in a scrollable div, getBoxObjectFor(elem) can return
// a value that varies by 1 pixel.
var doc = elem.ownerDocument;
return doc.getBoxObjectFor(elem).screenX -
doc.getBoxObjectFor(doc.documentElement).screenX;
}
return (elem.getBoundingClientRect().left + viewport.scrollLeft) | 0;
}-*/;

private native int getAbsoluteTopImpl(Element viewport, Element elem) /*-{
// Firefox 3 is actively throwing errors when getBoxObjectFor() is called,
// so we use getBoundingClientRect() whenever possible (but it's not
// supported on older versions). If changing this code, make sure to check
// the museum entry for issue 1932.
// (x) | 0 is used to coerce the value to an integer
if (Element.prototype.getBoundingClientRect) {
return (elem.getBoundingClientRect().top + viewport.scrollTop) | 0;
} else {
// We cannot use DOMImpl here because offsetLeft/Top return erroneous
// values when overflow is not visible. We have to difference screenX
// here due to a change in getBoxObjectFor which causes inconsistencies
// on whether the calculations are inside or outside of the element's
// border.
var doc = elem.ownerDocument;
return doc.getBoxObjectFor(elem).screenY -
doc.getBoxObjectFor(doc.documentElement).screenY;
}
}-*/;

private native boolean isRTL(Element elem) /*-{
var style = elem.ownerDocument.defaultView.getComputedStyle(elem, null);
return style.direction == 'rtl';
return (elem.getBoundingClientRect().top + viewport.scrollTop) | 0;
}-*/;
}

12 changes: 5 additions & 7 deletions user/src/com/google/gwt/dom/client/DOMImplStandardBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private static native double getAbsoluteTopUsingOffsets(Element elem) /*-{
}-*/;

private static native ClientRect getBoundingClientRect(Element element) /*-{
return element.getBoundingClientRect && element.getBoundingClientRect();
return element.getBoundingClientRect();
}-*/;

/**
Expand Down Expand Up @@ -207,18 +207,16 @@ public native EventTarget eventGetCurrentTarget(NativeEvent event) /*-{
@Override
public int getAbsoluteLeft(Element elem) {
ClientRect rect = getBoundingClientRect(elem);
double left = rect != null ? rect.getSubPixelLeft()
+ getScrollLeft(elem.getOwnerDocument())
: getAbsoluteLeftUsingOffsets(elem);
double left = rect.getSubPixelLeft()
+ getScrollLeft(elem.getOwnerDocument());
return toInt32(left);
}

@Override
public int getAbsoluteTop(Element elem) {
ClientRect rect = getBoundingClientRect(elem);
double top = rect != null ? rect.getSubPixelTop()
+ getScrollTop(elem.getOwnerDocument())
: getAbsoluteTopUsingOffsets(elem);
double top = rect.getSubPixelTop()
+ getScrollTop(elem.getOwnerDocument());
return toInt32(top);
}

Expand Down
3 changes: 0 additions & 3 deletions user/src/com/google/gwt/storage/client/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,6 @@ public void removeItem(String key) {
* Storage - Storage.setItem(k,v)</a>
*/
public void setItem(String key, String data) {
// prevent the empty string due to a Firefox bug:
// bugzilla.mozilla.org/show_bug.cgi?id=510849
assert key.length() > 0;
impl.setItem(storage, key, data);
}
}
5 changes: 0 additions & 5 deletions user/src/com/google/gwt/user/Window.gwt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@
<module>
<inherits name="com.google.gwt.core.Core"/>
<inherits name="com.google.gwt.user.UserAgent"/>

<replace-with class="com.google.gwt.user.client.impl.WindowImplMozilla">
<when-type-is class="com.google.gwt.user.client.impl.WindowImpl"/>
<when-property-is name="user.agent" value="gecko1_8"/>
</replace-with>
</module>
8 changes: 0 additions & 8 deletions user/src/com/google/gwt/user/cellview/CellView.gwt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,4 @@
<when-property-is name="user.agent" value="safari"/>
</any>
</replace-with>

<!-- Mozilla-specific CellTable implementation. -->
<replace-with class="com.google.gwt.user.cellview.client.AbstractCellTable.ImplMozilla">
<when-type-is class="com.google.gwt.user.cellview.client.AbstractCellTable.Impl"/>
<any>
<when-property-is name="user.agent" value="gecko1_8"/>
</any>
</replace-with>
</module>
49 changes: 10 additions & 39 deletions user/src/com/google/gwt/user/cellview/client/AbstractCellTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,44 +638,14 @@ protected void replaceAllRowsImpl(AbstractCellTable<?> table, TableSectionElemen
}
}

/**
* Implementation of {@link CellTable} used by Firefox.
*/
@SuppressWarnings("unused")
private static class ImplMozilla extends Impl {
Comment on lines -641 to -645
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking more carefully, maybe we should keep the class with no contents, as the Trident classes, just in case someone has a custom replace-with

/**
* Firefox 3.6 and earlier convert td elements to divs if the tbody is
* removed from the table element.
*/
@Override
protected void detachSectionElement(TableSectionElement section) {
if (isGecko192OrBefore()) {
return;
}
super.detachSectionElement(section);
}

@Override
protected void reattachSectionElement(Element parent, TableSectionElement section,
Element nextSection) {
if (isGecko192OrBefore()) {
return;
}
super.reattachSectionElement(parent, section, nextSection);
}

/**
* Return true if using Gecko 1.9.2 (Firefox 3.6) or earlier.
*/
private native boolean isGecko192OrBefore() /*-{
return @com.google.gwt.dom.client.DOMImplMozilla::isGecko192OrBefore()();
}-*/;
}

/**
* Implementation of {@link AbstractCellTable} used by IE.
*
* @deprecated Unused since 2.10.0, left in place to permit downstream users to continue to
* use it in GWT module files.
*/
@SuppressWarnings("unused")
@Deprecated
private static class ImplTrident extends Impl {

/**
Expand Down Expand Up @@ -1664,7 +1634,7 @@ public void setSkipRowHoverFloatElementCheck(boolean skipRowHoverFloatElementChe
* Sets the skipRowHoverStyleUpdate flag. If set, the CellTable will not update
* the row's style on row-level hover events (MOUSEOVER and MOUSEOUT).
*
* @param skipRowHoverCheck the new flag value
* @param skipRowHoverStyleUpdate the new flag value
*/
public void setSkipRowHoverStyleUpdate(boolean skipRowHoverStyleUpdate) {
this.skipRowHoverStyleUpdate = skipRowHoverStyleUpdate;
Expand Down Expand Up @@ -1949,8 +1919,8 @@ protected void onBrowserEvent2(Event event) {
boolean unhover = true;
if (!skipRowHoverFloatElementCheck) {
// Ignore events happening directly over the hovering row. If there are floating element
// on top of the row, mouseout event should not be triggered. This is to avoid the flickring
// effect if the floating element is shown/hide based on hover event.
// on top of the row, mouseout event should not be triggered. This is to avoid the
// flickering effect if the floating element is shown/hide based on hover event.
int clientX = event.getClientX() + Window.getScrollLeft();
int clientY = event.getClientY() + Window.getScrollTop();
int rowLeft = hoveringRow.getAbsoluteLeft();
Expand All @@ -1959,7 +1929,8 @@ protected void onBrowserEvent2(Event event) {
int rowHeight = hoveringRow.getOffsetHeight();
int rowBottom = rowTop + rowHeight;
int rowRight = rowLeft + rowWidth;
unhover = clientX < rowLeft || clientX > rowRight || clientY < rowTop || clientY > rowBottom;
unhover = clientX < rowLeft || clientX > rowRight
|| clientY < rowTop || clientY > rowBottom;
}
if (unhover) {
setRowHover(hoveringRow, event, false, isRowChange);
Expand Down Expand Up @@ -2587,7 +2558,7 @@ private <C> boolean resetFocusOnCellImpl(Context context, T value, HasCell<T, C>
}

/**
* Set a row's hovering style and fire a {@link RowHoverEvent}
* Set a row's hovering style and fire a {@link RowHoverEvent}.
*
* @param tr the row element
* @param event the original event
Expand Down
16 changes: 3 additions & 13 deletions user/src/com/google/gwt/user/client/impl/WindowImplMozilla.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,10 @@

/**
* Mozilla implementation of {@link com.google.gwt.user.client.impl.WindowImpl}.
* @deprecated This class is no longer used and has no differences from its superclass, and will
* be removed in a future release.
*/
@Deprecated
public class WindowImplMozilla extends WindowImpl {

/**
* For Mozilla, reading from $wnd.location.hash decodes the fragment.
* https://bugzilla.mozilla.org/show_bug.cgi?id=483304
* https://bugzilla.mozilla.org/show_bug.cgi?id=135309
* To avoid this bug, we use location.href instead.
*/
@Override
public native String getHash() /*-{
var href = $wnd.location.href;
var hashLoc = href.indexOf("#");
return (hashLoc > 0) ? href.substring(hashLoc) : "";
}-*/;

}
Loading