Prefer JavaScript clipboard API if available

Modern versions of Chrome support a draft clipboard API from
JavaScript that allows copying without use of a Flash movie.
If the API appears to be available in the browser prefer it
over the Flash movie.

Leave the clippy.swf support in as ancient browsers are still
going to be around for many years and will continue to require
the Flash movie to put text on the clipboard.

Change-Id: I1984801c8fa9c398ea4edf762f700e4a50e1da61
This commit is contained in:
Shawn Pearce
2015-07-20 16:23:02 -07:00
parent 4bb02c907c
commit c4266366ab
10 changed files with 316 additions and 10 deletions

View File

@@ -37,6 +37,7 @@ import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwtexpui.user.client.UserAgent;
import java.util.ArrayList;
import java.util.Arrays;
@@ -136,16 +137,19 @@ public class MyPreferencesScreen extends SettingsScreen {
legacycidInChangeTable = new CheckBox(Util.C.showLegacycidInChangeTable());
muteCommonPathPrefixes = new CheckBox(Util.C.muteCommonPathPrefixes());
final Grid formGrid = new Grid(11, 2);
boolean flashClippy = !UserAgent.hasJavaScriptClipboard() && UserAgent.Flash.isInstalled();
final Grid formGrid = new Grid(10 + (flashClippy ? 1 : 0), 2);
int row = 0;
formGrid.setText(row, labelIdx, "");
formGrid.setWidget(row, fieldIdx, showSiteHeader);
row++;
formGrid.setText(row, labelIdx, "");
formGrid.setWidget(row, fieldIdx, useFlashClipboard);
row++;
if (flashClippy) {
formGrid.setText(row, labelIdx, "");
formGrid.setWidget(row, fieldIdx, useFlashClipboard);
row++;
}
formGrid.setText(row, labelIdx, "");
formGrid.setWidget(row, fieldIdx, copySelfOnEmails);