Browse Source

Detect Chrome on iOS as Chrome + Webkit (#9138)

tags/8.1.0.alpha7
Artur 7 years ago
parent
commit
7bf4f7ade8

+ 4
- 0
client/src/main/java/com/vaadin/client/BrowserInfo.java View File

@@ -253,6 +253,10 @@ public class BrowserInfo {
return browserDetails.isSafari();
}

public boolean isSafariOrIOS() {
return browserDetails.isSafariOrIOS();
}

@Deprecated
public boolean isIE8() {
return isIE() && getBrowserMajorVersion() == 8;

+ 1
- 1
client/src/main/java/com/vaadin/client/ResourceLoader.java View File

@@ -329,7 +329,7 @@ public class ResourceLoader {
linkElement.setType("text/css");
linkElement.setHref(url);

if (BrowserInfo.get().isSafari()) {
if (BrowserInfo.get().isSafariOrIOS()) {
// Safari doesn't fire any events for link elements
// See http://www.phpied.com/when-is-a-stylesheet-really-loaded/
Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {

+ 10
- 10
client/src/main/java/com/vaadin/client/WidgetUtil.java View File

@@ -496,7 +496,7 @@ public class WidgetUtil {
// updated when collapsing/expanding columns
// Also appeared in Safari 5.1 with webkit 534 (#7667)
if ((BrowserInfo.get().isChrome() || (BrowserInfo.get()
.isSafari()
.isSafariOrIOS()
&& BrowserInfo.get().getWebkitVersion() >= 534))
&& (scrollleft > 0 || elem.getScrollLeft() > 0)) {
int scrollvalue = scrollleft;
@@ -794,7 +794,7 @@ public class WidgetUtil {
com.google.gwt.dom.client.Element el, String p)
/*-{
try {
if (el.currentStyle) {
// IE
return el.currentStyle[p];
@@ -809,7 +809,7 @@ public class WidgetUtil {
} catch (e) {
return "";
}
}-*/;

/**
@@ -823,7 +823,7 @@ public class WidgetUtil {
try {
el.focus();
} catch (e) {
}
}-*/;

@@ -1119,7 +1119,7 @@ public class WidgetUtil {
if ($wnd.document.activeElement) {
return $wnd.document.activeElement;
}
return null;
}-*/;

@@ -1190,11 +1190,11 @@ public class WidgetUtil {
/*-{
var top = elem.offsetTop;
var height = elem.offsetHeight;
if (elem.parentNode != elem.offsetParent) {
top -= elem.parentNode.offsetTop;
}
var cur = elem.parentNode;
while (cur && (cur.nodeType == 1)) {
if (top < cur.scrollTop) {
@@ -1203,12 +1203,12 @@ public class WidgetUtil {
if (top + height > cur.scrollTop + cur.clientHeight) {
cur.scrollTop = (top + height) - cur.clientHeight;
}
var offsetTop = cur.offsetTop;
if (cur.parentNode != cur.offsetParent) {
offsetTop -= cur.parentNode.offsetTop;
}
top += offsetTop - cur.scrollTop;
cur = cur.parentNode;
}
@@ -1648,7 +1648,7 @@ public class WidgetUtil {
}
var heightWithoutBorder = cloneElement.offsetHeight;
parentElement.removeChild(cloneElement);
return heightWithBorder - heightWithoutBorder;
}
}-*/;

+ 5
- 4
client/src/main/java/com/vaadin/client/ui/VButton.java View File

@@ -172,9 +172,10 @@ public class VButton extends FocusWidget implements ClickHandler {
// fix for #14632 - on mobile safari 8, if we press the button long
// enough, we might get two click events, so we are suppressing
// second if it is too soon
boolean isPhantomClickPossible = BrowserInfo.get().isSafari()
&& BrowserInfo.get().isTouchDevice()
&& BrowserInfo.get().getBrowserMajorVersion() == 8;
BrowserInfo browserInfo = BrowserInfo.get();
boolean isPhantomClickPossible = browserInfo.isSafariOrIOS()
&& browserInfo.isTouchDevice()
&& browserInfo.getBrowserMajorVersion() == 8;
long clickTime = isPhantomClickPossible ? System.currentTimeMillis()
: 0;
// If clicks are currently disallowed or phantom, keep it from
@@ -328,7 +329,7 @@ public class VButton extends FocusWidget implements ClickHandler {
*/
@Override
public void onClick(ClickEvent event) {
if (BrowserInfo.get().isSafari()) {
if (BrowserInfo.get().isSafariOrIOS()) {
VButton.this.setFocus(true);
}


+ 1
- 1
client/src/main/java/com/vaadin/client/ui/VTabsheet.java View File

@@ -1341,7 +1341,7 @@ public class VTabsheet extends VTabsheetBase
scroller.getStyle().setDisplay(Display.NONE);
}

if (BrowserInfo.get().isSafari()) {
if (BrowserInfo.get().isSafariOrIOS()) {
/*
* another hack for webkits. tabscroller sometimes drops without
* "shaking it" reproducable in

+ 18
- 3
client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java View File

@@ -55,6 +55,7 @@ public class VBrowserDetailsUserAgentParserTest {
private static final String EDGE_WINDOWS_10 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240";

private static final String PHANTOMJS_211_MAC = "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1";
private static final String CHROME_57_ON_IOS_10_3_1 = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/57.0.2987.137 Mobile/14E304 Safari/602.1";

@Test
public void testSafari3() {
@@ -204,6 +205,17 @@ public class VBrowserDetailsUserAgentParserTest {
assertWindows(bd);
}

@Test
public void testChromeIOS() {
VBrowserDetails bd = new VBrowserDetails(CHROME_57_ON_IOS_10_3_1);
assertWebKit(bd);
assertChrome(bd);
assertBrowserMajorVersion(bd, 57);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 602f);
assertIOS(bd, 10, 3);
}

@Test
public void testFirefox3() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX30_WINDOWS);
@@ -349,7 +361,8 @@ public class VBrowserDetailsUserAgentParserTest {

@Test
public void testIE11Windows7CompatibilityViewIE7() {
VBrowserDetails bd = new VBrowserDetails(IE11_WINDOWS_7_COMPATIBILITY_VIEW_IE7);
VBrowserDetails bd = new VBrowserDetails(
IE11_WINDOWS_7_COMPATIBILITY_VIEW_IE7);
assertTrident(bd);
assertEngineVersion(bd, 7);
assertIE(bd);
@@ -360,7 +373,8 @@ public class VBrowserDetailsUserAgentParserTest {

@Test
public void testIE11Windows10CompatibilityViewIE7() {
VBrowserDetails bd = new VBrowserDetails(IE11_WINDOWS_10_COMPATIBILITY_VIEW_IE7);
VBrowserDetails bd = new VBrowserDetails(
IE11_WINDOWS_10_COMPATIBILITY_VIEW_IE7);
assertTrident(bd);
assertEngineVersion(bd, 7);
assertIE(bd);
@@ -371,7 +385,8 @@ public class VBrowserDetailsUserAgentParserTest {

@Test
public void testIE11InitialWindows10CompatibilityViewIE7() {
VBrowserDetails bd = new VBrowserDetails(IE11_INITIAL_WINDOWS_10_COMPATIBILITY_VIEW_IE7);
VBrowserDetails bd = new VBrowserDetails(
IE11_INITIAL_WINDOWS_10_COMPATIBILITY_VIEW_IE7);
assertTrident(bd);
assertEngineVersion(bd, 7);
assertIE(bd);

+ 3
- 4
compatibility-client/src/main/java/com/vaadin/v7/client/ui/VScrollTable.java View File

@@ -5598,7 +5598,7 @@ public class VScrollTable extends FlowPanel
final Element cell = DOM.getChild(getElement(), cellIx);
Style wrapperStyle = cell.getFirstChildElement().getStyle();
int wrapperWidth = width;
if (BrowserInfo.get().isWebkit()
if (BrowserInfo.get().isSafariOrIOS()
|| BrowserInfo.get().isOpera10()) {
/*
* Some versions of Webkit and Opera ignore the width
@@ -7381,11 +7381,10 @@ public class VScrollTable extends FlowPanel

rowRequestHandler.cancel();

if (BrowserInfo.get().isSafari() && event != null && scrollTop == 0) {
if (BrowserInfo.get().isSafariOrIOS() && event != null && scrollTop == 0) {
// due to the webkitoverflowworkaround, top may sometimes report 0
// for webkit, although it really is not. Expecting to have the
// correct
// value available soon.
// correct value available soon.
Scheduler.get().scheduleDeferred(new Command() {

@Override

+ 1
- 1
compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTextArea.java View File

@@ -227,7 +227,7 @@ public class VTextArea extends VTextField implements DragImageModifier {
if (info.isFirefox()) {
return true;
}
if (info.isSafari()) {
if (info.isSafariOrIOS()) {
return true;
}
// Vaadin 8 no longer supports IE10

+ 3
- 1
server/src/main/java/com/vaadin/server/WebBrowser.java View File

@@ -141,7 +141,9 @@ public class WebBrowser implements Serializable {
}

/**
* Tests whether the user is using Safari.
* Tests whether the user is using Safari. Note that Chrome on iOS is not
* detected as Safari but as Chrome although the underlying browser engine
* is the same.
*
* @return true if the user is using Safari, false if the user is not using
* Safari or if no information on the browser is present

+ 18
- 2
shared/src/main/java/com/vaadin/shared/VBrowserDetails.java View File

@@ -79,7 +79,8 @@ public class VBrowserDetails implements Serializable {
isWebKit = !isTrident && userAgent.indexOf("applewebkit") != -1;

// browser name
isChrome = userAgent.indexOf(" chrome/") != -1;
isChrome = userAgent.indexOf(" chrome/") != -1
|| userAgent.indexOf(" crios/") != -1;
isOpera = userAgent.indexOf("opera") != -1;
isIE = userAgent.indexOf("msie") != -1 && !isOpera
&& (userAgent.indexOf("webtv") == -1);
@@ -163,7 +164,12 @@ public class VBrowserDetails implements Serializable {
int i = userAgent.indexOf(" firefox/") + 9;
parseVersionString(safeSubstring(userAgent, i, i + 5));
} else if (isChrome) {
int i = userAgent.indexOf(" chrome/") + 8;
int i = userAgent.indexOf(" chrome/");
if (i != -1) {
i += " chrome/".length();
} else {
i = userAgent.indexOf(" crios/") + " crios/".length();
}
parseVersionString(safeSubstring(userAgent, i, i + 5));
} else if (isSafari) {
int i = userAgent.indexOf(" version/") + 9;
@@ -354,6 +360,16 @@ public class VBrowserDetails implements Serializable {
return isSafari;
}

/**
* Tests if the browser is Safari or runs on IOS (covering also Chrome on
* iOS).
*
* @return true if it is Safari or running on IOS, false otherwise
*/
public boolean isSafariOrIOS() {
return isSafari() || isIOS();
}

/**
* Tests if the browser is Chrome.
*

Loading…
Cancel
Save