Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions user/src/com/google/gwt/dom/client/DOMImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ public native String getAttribute(Element elem, String name) /*-{
return elem.getAttribute(name) || '';
}-*/;

public native int getBodyOffsetLeft(Document doc) /*-{
return 0;
}-*/;

public native int getBodyOffsetTop(Document doc) /*-{
return 0;
}-*/;

public native JsArray<Touch> getChangedTouches(NativeEvent evt) /*-{
return evt.changedTouches;
}-*/;
Expand Down
232 changes: 13 additions & 219 deletions user/src/com/google/gwt/dom/client/DOMImplMozilla.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,86 +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;
if (doc != null) {
var evt = doc.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, null, 0, 0,
0, 0, 0, false, false, false, false, 0, null);
button.dispatchEvent(evt);
}
}-*/;

@Override
public NativeEvent createKeyCodeEvent(Document doc, String type,
boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey,
Expand All @@ -124,23 +44,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 @@ -153,26 +56,6 @@ public int getAbsoluteTop(Element elem) {
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);
}-*/;

@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);
}-*/;

@Override
public native int getNodeType(Node node) /*-{
try {
Expand All @@ -184,121 +67,32 @@ 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) /*-{
if (!!window.KeyboardEvent) {
return new KeyboardEvent(type, {
ctrlKey: ctrlKey,
altKey: altKey,
shiftKey: shiftKey,
metaKey: metaKey,
keyCode: keyCode,
charCode: charCode,
bubbles: canBubble,
cancelable: cancelable
});
}
var evt = doc.createEvent('KeyboardEvent');
if (evt.initKeyEvent) {
// Gecko
evt.initKeyEvent(type, canBubble, cancelable, null, ctrlKey, altKey,
shiftKey, metaKey, keyCode, charCode);
} else {
// This happens to be IE11+ as of today
if ($wnd.console) {
$wnd.console.error("Synthetic keyboard events are not supported in this browser");
}
}
return evt;
return new KeyboardEvent(type, {
ctrlKey: ctrlKey,
altKey: altKey,
shiftKey: shiftKey,
metaKey: metaKey,
keyCode: keyCode,
charCode: charCode,
bubbles: canBubble,
cancelable: cancelable
});
}-*/;

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
43 changes: 12 additions & 31 deletions user/src/com/google/gwt/dom/client/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -1270,46 +1270,27 @@ public final native BodyElement getBody() /*-{
}-*/;

/**
* Returns the left offset between the absolute coordinate system and the
* body's positioning context. This method is useful for positioning children
* of the body element in absolute coordinates.
* This used to account for the difference between absolute position of elements
* and client coordinates of mouse events, but those are the same in modern browsers.
* Kept for compatibility.
*
* <p>
* For example, to position an element directly under the mouse cursor
* (assuming you are handling a mouse event), do the following:
* </p>
*
* <pre>
* Event event;
* Document doc;
* DivElement child; // assume absolutely-positioned child of the body
*
* // Get the event location in absolute coordinates.
* int absX = event.getClientX() + Window.getScrollLeft();
* int absY = event.getClientY() + Window.getScrollTop();
*
* // Position the child element, adjusting for the difference between the
* // absolute coordinate system and the body's positioning coordinates.
* child.getStyle().setPropertyPx("left", absX - doc.getBodyOffsetLeft());
* child.getStyle().setPropertyPx("top", absY - doc.getBodyOffsetTop());
* </pre>
*
* @return the left offset of the body's positioning coordinate system
* @return 0
* @deprecated can be replaced with constant 0
*/
@Deprecated
public final int getBodyOffsetLeft() {
return DOMImpl.impl.getBodyOffsetLeft(this);
return 0;
}

/**
* Returns the top offset between the absolute coordinate system and the
* body's positioning context. This method is useful for positioning children
* of the body element in absolute coordinates.
* Kept for compatibility, analogous to {@link #getBodyOffsetLeft`()}.
*
* @return the top offset of the body's positioning coordinate system
* @see #getBodyOffsetLeft()
* @return 0
* @deprecated can be replaced with constant 0
*/
@Deprecated
public final int getBodyOffsetTop() {
return DOMImpl.impl.getBodyOffsetTop(this);
return 0;
}

/**
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>
Loading
Loading