Java Code Examples for com.google.gwt.dom.client.Document

The following are top voted examples for showing how to use com.google.gwt.dom.client.Document. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: empiria.player   File: AccessibleCheckBox.java   Source Code and License 7 votes vote down vote up
protected AccessibleCheckBox(Element elem) {
    super(DOM.createSpan());
    inputElem = InputElement.as(elem);
    labelElem = Document.get().createLabelElement();

    getElement().appendChild(inputElem);
    getElement().appendChild(labelElem);

    String uid = DOM.createUniqueId();
    inputElem.setPropertyString("id", uid);
    labelElem.setHtmlFor(uid);

    // Accessibility: setting tab index to be 0 by default, ensuring element
    // appears in tab sequence. FocusWidget's setElement method already
    // calls setTabIndex, which is overridden below. However, at the time
    // that this call is made, inputElem has not been created. So, we have
    // to call setTabIndex again, once inputElem has been created.
    setTabIndex(0);
}
 
Example 2
Project: Mindustry   File: HtmlLauncher.java   Source Code and License 6 votes vote down vote up
@Override
public GwtApplicationConfiguration getConfig() {
    GwtApplicationConfiguration config = new GwtApplicationConfiguration(WIDTH, HEIGHT);

    Element element = Document.get().getElementById("embed-html");
    VerticalPanel panel = new VerticalPanel();
    panel.setWidth("100%");
    panel.setHeight("100%");
    panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    element.appendChild(panel.getElement());
    config.rootPanel = panel;
    config.width = 2000;
    config.height = 2000;

    return config;
}
 
Example 3
Project: empiria.player   File: FlashModule.java   Source Code and License 6 votes vote down vote up
@Override
protected void initModule(Element element) {
    String src = element.getAttribute("src");
    int lastSlash = ((src.lastIndexOf("/") > src.lastIndexOf("\\")) ? src.lastIndexOf("/") : src.lastIndexOf("\\"));
    String basePath = src.substring(0, lastSlash + 1);
    com.google.gwt.dom.client.Element paramNameElement = Document.get().createElement("param");
    paramNameElement.setAttribute("name", "movie");
    paramNameElement.setAttribute("value", src);
    com.google.gwt.dom.client.Element paramBaseElement = Document.get().createElement("param");
    paramBaseElement.setAttribute("name", "base");
    paramBaseElement.setAttribute("value", basePath);
    com.google.gwt.dom.client.Element embedElement = Document.get().createElement("embed");
    embedElement.setAttribute("src", src);
    embedElement.setAttribute("base", basePath);
    panel.getElement().appendChild(paramNameElement);
    panel.getElement().appendChild(paramBaseElement);
    panel.getElement().appendChild(embedElement);

}
 
Example 4
Project: empiria.player   File: VideoExecutorSwf.java   Source Code and License 6 votes vote down vote up
@Override
public void init() {
    FlowPanel flowPanel = new FlowPanel();
    FlashVideo video = FlashVideoFactory.createVideo(source, flowPanel, baseMediaConfiguration.getWidth(), baseMediaConfiguration.getHeight());
    flashMedia = video;
    if (this.mediaWrapper instanceof SwfMediaWrapper) {
        ((SwfMediaWrapper) this.mediaWrapper).setMediaWidget(flowPanel);
    }
    if (baseMediaConfiguration.getNarrationText().trim().length() > 0) {
        final TextTrack textTrack = textTrackFactory.getTextTrack(TextTrackKind.SUBTITLES, mediaWrapper);
        // FIXME do poprawy gdy narrationScript bedzie zawieral informacje o czasie wyswietlania
        // zamiast Double.MAX_VALUE tu powinna sie znalezc wartosc czasowa okreslajaca
        // kiedy napis znika poniewaz w tej chwili narrationScript nie posiada takiej informacji
        // przypisuje najwieksza dostepna wartosc
        textTrack.addCue(new TextTrackCue(Document.get().createUniqueId(), 0, Double.MAX_VALUE, baseMediaConfiguration.getNarrationText()));
        eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_TIME_UPDATE), mediaWrapper, new MediaEventHandler() {

            @Override
            public void onMediaEvent(MediaEvent event) {
                textTrack.setCurrentTime(mediaWrapper.getCurrentTime());
            }
        }, pageScopeFactory.getCurrentPageScope());

    }
    super.init();
}
 
Example 5
Project: empiria.player   File: AccessibleListBox.java   Source Code and License 6 votes vote down vote up
/**
 * Inserts an item into the list box, specifying its direction and an initial value for the item. If the index is less than zero, or greater than or equal
 * to the length of the list, then the item will be appended to the end of the list.
 *
 * @param item  the text of the item to be inserted
 * @param dir   the item's direction. If {@code null}, the item is displayed in the widget's overall direction, or, if a direction estimator has been set, in
 *              the item's estimated direction.
 * @param value the item's value, to be submitted if it is part of a {@link FormPanel}.
 * @param index the index at which to insert it
 */
public void insertItem(String item, Direction dir, String value, int index) {
    SelectElement select = getSelectElement();
    OptionElement option = Document.get().createOptionElement();
    setOptionText(option, item, dir);
    option.setValue(value);

    int itemCount = select.getLength();
    if (index < 0 || index > itemCount) {
        index = itemCount;
    }
    if (index == itemCount) {
        select.add(option, null);
    } else {
        OptionElement before = select.getOptions().getItem(index);
        select.add(option, before);
    }
}
 
Example 6
Project: Charba   File: Injector.java   Source Code and License 6 votes vote down vote up
/**
 * Injects ChartJS if not injected yet.
 */
static void ensureInjected() {
	if (!injected) {
		// gets resource
		Resources res = GWT.create(Resources.class);
		// gets source of ChartJS
		String source = res.chartJsSource().getText();
		// creates a script element
		ScriptElement scriptElement = Document.get().createScriptElement();
		// sets ID
		scriptElement.setId(CHART_JS_SCRIPT_ELEMENT_ID);
		// sets the script content with ChartJS source
		scriptElement.setInnerText(source);
		// appends to the body
		Document.get().getBody().appendChild(scriptElement);
		injected = true;
	}
}
 
Example 7
Project: wt-pdf-viewer   File: WTPdfViewerWidget.java   Source Code and License 6 votes vote down vote up
public WTPdfViewerWidget() {
	Document document = Document.get();
	root = document.createDivElement();
	root.addClassName("loadingInProgress");

	outerContainer = createChildDiv(document, root, "outerContainer");
	createSidebar(document, outerContainer);

	mainContainer = createChildDiv(document, outerContainer, "mainContainer");
	createFindBar(document, mainContainer);
	//the toolbar on the right that opens after click on double arrow on the right
	createSecondaryToolbar(document, mainContainer);
	createMainToolbar(document, mainContainer);

	loadingBar = createChildDiv_withId(document, mainContainer, "loadingBar");
	progress = createChildDiv_withId(document, loadingBar, "progress");

	createViewerContainer(document, mainContainer);
	printContainer = createChildDiv(document, root, "printContainer");

	setElement(root);
	startWebViewerLoad(this);

	setStyleName("wtpdfviewer");
}
 
Example 8
Project: wt-pdf-viewer   File: WTPdfViewerWidget.java   Source Code and License 6 votes vote down vote up
private void createViewerContainer(Document document, DivElement mainContainer) {
	viewerContainer = createChildDiv(document, mainContainer, "viewerContainer");
	viewerContainer.setTabIndex(0); // keyboard scrolling does not work without this tabindex 

	viewer = createChildDiv(document, viewerContainer, "viewer");
	viewer.addClassName("pdfViewer");

	overlayContainer = createChildDiv(document, outerContainer, "overlayContainer");
	overlayContainer.addClassName("hidden");

	passwordOverlay = createChildDiv(document, overlayContainer, "passwordOverlay");
	passwordOverlay.addClassName("container");
	passwordOverlay.addClassName("hidden");

	createDocumentPropertiesOverlay(document, overlayContainer);
	createPrintServiceOverlay(document, overlayContainer);
}
 
Example 9
Project: wt-pdf-viewer   File: WTPdfViewerWidget.java   Source Code and License 6 votes vote down vote up
private void createPrintServiceOverlay(Document document, DivElement parent) {
	printServiceOverlay = createChildDiv(document, parent, "printServiceOverlay");
	printServiceOverlay.addClassName("container");
	printServiceOverlay.addClassName("hidden");

	DivElement dialog = createChildDiv(document, printServiceOverlay, "dialog");
	DivElement row1 = createChildDiv(document, dialog, "row");
	SpanElement message = createChildSpan(document, row1, "");
	message.setInnerText("Preparing document for printing!");

	DivElement row2 = createChildDiv(document, dialog, "row");
	createChildProgress(document, row2, 0, 100);
	SpanElement relativeProgressSpan = createChildSpan(document, row2, "relative-progress");
	relativeProgressSpan.setInnerText("0%");

	DivElement row3 = createChildDiv(document, dialog, "row");
	printCancel = createChildButton(document, row3, "printCancel");
	printCancel.addClassName("overlayButton");
	SpanElement printCancelMessage = createChildSpan(document, printCancel, "");
	printCancelMessage.setInnerText("Cancel");
}
 
Example 10
Project: gwt-history   File: HistoryTest.java   Source Code and License 6 votes vote down vote up
@DoNotRunWith(Platform.HtmlUnitUnknown)
public void testClickLink() {
  AnchorElement anchorElement = Document.get().createAnchorElement();
  anchorElement.setHref("#href1");
  Document.get().getBody().appendChild(anchorElement);

  try {
    History.newItem("something_as_base");

    addHistoryListenerImpl(
        event -> {
          assertEquals("href1", event.getValue());
          finishTest();
        });

    delayTestFinish(5000);

    NativeEvent clickEvent =
        Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);

    anchorElement.dispatchEvent(clickEvent);

  } finally {
    Document.get().getBody().removeChild(anchorElement);
  }
}
 
Example 11
Project: Wiab.pro   File: RepairerGwtTest.java   Source Code and License 6 votes vote down vote up
public void testRevertEmptyElement() {
  init();
  initEmptyP();
  c.insertBefore(root, p, null);

  // essentially a noop
  assertTrue(p.isConsistent());
  p.revertImplementation();
  assertTrue(p.isConsistent());

  // add some random text node
  p.getImplNodelet().appendChild(Document.get().createTextNode("blah"));
  p.revertImplementation();
  assertEquals(null, p.getImplNodelet().getFirstChild());

  p.getImplNodelet().appendChild(ca());
  p.revertImplementation();
  assertEquals(null, p.getImplNodelet().getFirstChild());

  p.getImplNodelet().appendChild(ca());
  p.revertImplementation();
  assertEquals(null, p.getImplNodelet().getFirstChild());

  l.check(0, 0); // calls through revertInner, so none reported
}
 
Example 12
Project: GWT-AL   File: AudioDecoder.java   Source Code and License 6 votes vote down vote up
public static boolean isSupported(FileFormat format)
{
    if (tempAudioElement == null)
        tempAudioElement = Document.get().createAudioElement();

    switch (format)
    {
        case MP3:
            return !tempAudioElement.canPlayType(AudioElement.TYPE_MP3).equals(MediaElement.CANNOT_PLAY);

        case WAV:
            return !tempAudioElement.canPlayType(AudioElement.TYPE_WAV).equals(MediaElement.CANNOT_PLAY);

        case OGG:
            return !tempAudioElement.canPlayType(AudioElement.TYPE_OGG).equals(MediaElement.CANNOT_PLAY);

        case WEBM:
            return !tempAudioElement.canPlayType("audio/webm").equals(MediaElement.CANNOT_PLAY);
    }

    return false;
}
 
Example 13
Project: Wiab.pro   File: EventDispatcherPanelGwtTest.java   Source Code and License 6 votes vote down vote up
@Override
protected void gwtSetUp() {
  SafeHtml dom = EscapeUtils.fromSafeConstant("" + // \u2620
      "<div id='base' kind='base'>" + // \u2620
      "  <div>" + // \u2620
      "    <div kind='foo' id='foo'>" + // \u2620
      "      <div kind='unused'>" + // \u2620
      "        <div kind='bar' id='bar'>" + // \u2620
      "          <div id='source'></div>" + // \u2620
      "        </div>" + // \u2620
      "      </div>" + // \u2620
      "    </div>" + // \u2620
      "  </div>" + // \u2620
      "</div>");

  top = load(dom);
  foo = Document.get().getElementById("foo");
  bar = Document.get().getElementById("bar");

  // Register some handlers.
  handlers = new MockHandlers(top);
  fooHandler = new MyHandler();
  barHandler = new MyHandler();
  handlers.register("foo", fooHandler);
  handlers.register("bar", barHandler);
}
 
Example 14
Project: Wiab.pro   File: EditorEventHandlerGwtTest.java   Source Code and License 6 votes vote down vote up
public void testDeleteWithRangeSelectedDeletesRange() {
  FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.DELETE, KeyCodes.KEY_LEFT);

  //Event event = Document.get().createKeyPressEvent(
  //    false, false, false, false, KeyCodes.KEY_BACKSPACE, 0).cast();

  Text input = Document.get().createTextNode("ABCDE");
  ContentNode node = new ContentTextNode(input, null);

  final Point<ContentNode> start = Point.inText(node, 1);
  final Point<ContentNode> end = Point.inText(node, 4);
  FakeEditorInteractor interactor = setupFakeEditorInteractor(
      new FocusedContentRange(start, end));
  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  EditorEventHandler handler = createEditorEventHandler(interactor, subHandler);

  interactor.call(FakeEditorInteractor.DELETE_RANGE).nOf(1).withArgs(
      start, end, false).returns(start);

  handler.handleEvent(fakeEvent);
  interactor.checkExpectations();
}
 
Example 15
Project: walkaround   File: UploadFormPopup.java   Source Code and License 6 votes vote down vote up
/**
 * Creates an upload popup.
 */
public UploadFormPopup() {
  form = BINDER.createAndBindUi(this);

  PopupChrome chrome = PopupChromeFactory.createPopupChrome();
  chrome.enableTitleBar();
  popup = PopupFactory.createPopup(null, new CenterPopupPositioner(), chrome, false);
  popup.getTitleBar().setTitleText("Upload attachment");
  popup.add(form);

  iframe = Document.get().createIFrameElement();
  iframe.setName("_uploadform" + iframeId++);
  // HACK(danilatos): Prevent browser from caching due to whatever reason
  iframe.setSrc("/uploadform?nocache=" + Duration.currentTimeMillis());
  form.getElement().setAttribute("target", iframe.getName());

  onloadRegistration =
      DomHelper.registerEventHandler(iframe, "load", new JavaScriptEventListener() {
        @Override
        public void onJavaScriptEvent(String name, Event event) {
          onIframeLoad();
        }
      });
  UIObject.setVisible(iframe, false);
}
 
Example 16
Project: walkaround   File: Walkaround.java   Source Code and License 6 votes vote down vote up
/** Reveals the log div, and executes a task when done. */
// The async API for this method is intended to support two things: a cool
// spew animation, and also the potential to runAsync the whole LogPanel code.
private static void attachLogPanel() {
  Logs.get().addHandler(domLogger);
  final Panel logHolder = RootPanel.get("logHolder");
  logHolder.setVisible(true);

  // Need one layout and paint cycle after revealing it to start animation.
  // Use high priority to avoid potential starvation by other tasks if a
  // problem is occurring.
  SchedulerInstance.getHighPriorityTimer().scheduleDelayed(new Task() {
    @Override
    public void execute() {
      logHolder.add(domLogger);
      Style waveStyle = Document.get().getElementById(WAVEPANEL_PLACEHOLDER).getStyle();
      Style logStyle = logHolder.getElement().getStyle();
      logStyle.setHeight(250, Unit.PX);
      waveStyle.setBottom(250, Unit.PX);
    }
  }, 50);
}
 
Example 17
Project: Wiab.pro   File: EditorEventHandlerGwtTest.java   Source Code and License 6 votes vote down vote up
/**
 * Ensure that the event handler normalises the selection when necessary
 * Note that this is currently just for firefox.
 */
public void testNormalisesSelection() {
  FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.INPUT, 'a');
  final Point<ContentNode> caret =
      Point.<ContentNode> end(newParaElement());

  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  FakeEditorInteractor interactor = setupFakeEditorInteractor(new FocusedContentRange(caret));
  final Point<ContentNode> newCaret = Point.<ContentNode>inText(
      new ContentTextNode(Document.get().createTextNode("hi"), null), 2);
  interactor.call(FakeEditorInteractor.NORMALIZE_POINT).returns(newCaret);
  interactor.call(FakeEditorInteractor.SET_CARET).nOf(1).withArgs(newCaret);
  interactor.call(FakeEditorInteractor.NOTIFYING_TYPING_EXTRACTOR).nOf(1).withArgs(
      newCaret, false);
  EditorEventHandler handler = createEditorEventHandler(interactor, subHandler);

  handler.handleEvent(fakeEvent);
  interactor.checkExpectations();
}
 
Example 18
Project: Wiab.pro   File: KeyBindingRegistryIntegrationGwtTest.java   Source Code and License 6 votes vote down vote up
/** Ensure that when other keys are pressed, they are not passed to the action. */
public void testAlternativeKeyPress() {
  KeyBindingRegistry bindings = new KeyBindingRegistry();
  callTracker = 0;
  EditorAction testAction =
      new EditorAction() {

        @Override
        public void execute(EditorContext context) {
          callTracker++;
        }
      };
  bindings.registerAction(KeyCombo.CTRL_G, testAction);
  EditorImpl editor = createEditor(bindings);

  // This event is not ORDER_G, it has other accelerators thrown in.
  Event rawEvent = Document.get().createKeyPressEvent(
      true, true, true, false, G_CODE, G_CODE).cast();
  editor.onJavaScriptEvent(JsEvents.KEY_PRESS, rawEvent);
  assertEquals("Callback action called on unregistered keypress", callTracker, 0);
}
 
Example 19
Project: Wiab.pro   File: KeyBindingRegistryIntegrationGwtTest.java   Source Code and License 6 votes vote down vote up
/**
 * Ensure that new keybindings are used after changing them in the editor.
 */
public void testReregistrationKeyBinding() {
  KeyBindingRegistry bindings = new KeyBindingRegistry();
  callTracker = 0;
  EditorAction testAction =
      new EditorAction() {

        @Override
        public void execute(EditorContext context) {
          callTracker++;
        }
      };
  bindings.registerAction(KeyCombo.CTRL_G, testAction);

  EditorImpl editor = createEditor(bindings);
  Event rawEvent = Document.get().createKeyPressEvent(
      true, false, false, false, G_CODE, G_CODE).cast();
  editor.onJavaScriptEvent(JsEvents.KEY_PRESS, rawEvent);
  // callTracker should be 1 assuming the test above passes

  bindings.removeAction(KeyCombo.CTRL_G);
  initEditor(editor, Editor.ROOT_REGISTRIES, bindings);
  editor.onJavaScriptEvent(JsEvents.KEY_PRESS, rawEvent);
  assertEquals("Callback action called on deregistered keypress", callTracker, 1);
}
 
Example 20
Project: cuba   File: CubaFileDownloaderConnector.java   Source Code and License 6 votes vote down vote up
public void downloadFileById(String resourceId) {
    final String url = getResourceUrl(resourceId);
    if (url != null && !url.isEmpty()) {
        final IFrameElement iframe = Document.get().createIFrameElement();

        Style style = iframe.getStyle();
        style.setVisibility(Style.Visibility.HIDDEN);
        style.setHeight(0, Style.Unit.PX);
        style.setWidth(0, Style.Unit.PX);

        iframe.setFrameBorder(0);
        iframe.setTabIndex(-1);
        iframe.setSrc(url);
        RootPanel.getBodyElement().appendChild(iframe);

        Timer removeTimer = new Timer() {
            @Override
            public void run() {
                iframe.removeFromParent();
            }
        };
        removeTimer.schedule(60 * 1000);
    }
}
 
Example 21
Project: Wiab.pro   File: WebClient.java   Source Code and License 6 votes vote down vote up
private void setupWavePanel() {
  // Hide the frame until waves start getting opened
  UIObject.setVisible(waveFrame.getElement(), false);

  Document.get().getElementById(SIGNOUT_ELEMENT_ID).setInnerText(messages.signout());

  // Handles opening waves.
  ClientEvents.get().addWaveSelectionEventHandler(new WaveSelectionEventHandler() {

    @Override
    public void onSelection(WaveRef waveRef, boolean ctrlDown, boolean altDown) {
      // Ctrl or Alt isn't pressed => open wave with diffs
      closeAndOpenWave(new OpenWaveData(waveRef, false, null, !ctrlDown && !altDown));
    }
  });

  waveFrame.getElement().setId(WAVE_ELEMENT_ID);
}
 
Example 22
Project: Wiab.pro   File: WebClient.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a dialogBox that informs about not saved data.
 */
private DialogActivator getNotSavedDialogActivator() {
  if (notSavedDialogActivator == null) {
    PopupChrome chrome = PopupChromeFactory.createPopupChrome();
    UniversalPopup popup = PopupFactory.createPopup(Document.get().getElementById(APP_ELEMENT_ID),
        new CenterPopupPositioner(), chrome, false);

    Label messageLabel = new Label(messages.changesNotSavedMessage());
    messageLabel.setStyleName(Dialog.getCss().infoLabel());

    DialogBox.create(popup, messages.changesNotSavedTitle(), messageLabel,
        new DialogButton[] { notSavedDialogNo, notSavedDialogYes });

    notSavedDialogActivator = new DialogActivator(popup);
  }
  return notSavedDialogActivator;
}
 
Example 23
Project: Wiab.pro   File: UndercurrentHarness.java   Source Code and License 6 votes vote down vote up
/**
 * Populates the info box. Continuously reports which element has browser
 * focus, and reports timing information for the stage loading.
 *
 * @param timeline timeline to report
 */
private static void showInfo(Timeline timeline) {
  Element timeBox = Document.get().getElementById("timeline");
  timeline.dump(timeBox);

  Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
    private final Element activeBox = Document.get().getElementById("active");

    @Override
    public boolean execute() {
      Element e = getActiveElement();
      String text = (e != null ? e.getTagName() + " id:" + e.getId() : "none");
      activeBox.setInnerText(text);
      return true;
    }

    private native Element getActiveElement() /*-{
      return $doc.activeElement;
    }-*/;
  }, 1000);
}
 
Example 24
Project: Wiab.pro   File: CheckBox.java   Source Code and License 6 votes vote down vote up
@Override
public Element createDomImpl(Renderable element) {
  InputElement inputElem = Document.get().createCheckInputElement();
  inputElem.setClassName(CheckConstants.css.check());

  // Wrap in non-editable span- Firefox does not fire events for checkboxes
  // inside contentEditable region.
  SpanElement nonEditableSpan = Document.get().createSpanElement();
  DomHelper.setContentEditable(nonEditableSpan, false, false);
  nonEditableSpan.appendChild(inputElem);

  return nonEditableSpan;
}
 
Example 25
Project: Wiab.pro   File: CajolerFacade.java   Source Code and License 6 votes vote down vote up
private void appendToDocument(HTML target, PluginContext pluginContext, CajolerResponse response) {
  DivElement domitaVdocElement = Document.get().createDivElement();
  domitaVdocElement.setClassName("innerHull");

  target.getElement().setInnerHTML("");
  target.getElement().setClassName("outerHull");
  target.getElement().appendChild(domitaVdocElement);

  initializeDoodadEnvironment(
      cajaFrame, domitaVdocElement, pluginContext.getJSOInterface());

  // Render HTML
  domitaVdocElement.setInnerHTML(response.getHtml());

  // Inject JS
  Document cajaFrameDoc = cajaFrame.getContentDocument();
  cajaFrameDoc.getBody().appendChild(cajaFrameDoc.createScriptElement(response.getJs()));
}
 
Example 26
Project: Wiab.pro   File: DynamicDomRenderer.java   Source Code and License 6 votes vote down vote up
private void setFlapPanelVisible(boolean visible) {
  if (flapPanelVisible != visible) {
    if (flapPanel == null) {
      flapPanel = Document.get().createDivElement();
    }
    flapPanel.setClassName(getCss().flap() + " " +
        (visible ? getCss().opaque() : getCss().transparent()) );
    if (visible) {
      DomUtil.putCover(flapPanel, getScrollPanel());
      DomUtil.setProgressCursor(flapPanel);
    } else {
      getTimer().scheduleDelayed(hideFlapPanelTask, HIDE_FLAP_PANEL_DELAY_MS);
    }
    flapPanelVisible = visible;
  }
}
 
Example 27
Project: Wiab.pro   File: DomLogger.java   Source Code and License 6 votes vote down vote up
/**
 * Appends an entry to the log panel.
 * @param formatted
 * @param level
 */
public static void appendEntry(String formatted, Level level) {
  DivElement entry = Document.get().createDivElement();
  entry.setClassName(RESOURCES.css().entry());
  entry.setInnerHTML(formatted);

  // Add the style name associated with the log level.
  switch (level) {
    case ERROR:
      entry.addClassName(RESOURCES.css().error());
      break;
    case FATAL:
      entry.addClassName(RESOURCES.css().fatal());
      break;
    case TRACE:
      entry.addClassName(RESOURCES.css().trace());
      break;
  }

  // Make fatals detectable by WebDriver, so that tests can early out on
  // failure:
  if (level.equals(Level.FATAL)) {
    latestFatalError = formatted;
  }
  writeOrCacheOutput(entry);
}
 
Example 28
Project: Wiab.pro   File: KeyBindingRegistryIntegrationGwtTest.java   Source Code and License 6 votes vote down vote up
/**
 * Ensure that an action bound to ORDER_G is executed when the appropriate JS keypress
 * event is fired at the editor.
 */
public void testKeyBinding() {
  KeyBindingRegistry bindings = new KeyBindingRegistry();
  callTracker = 0;
  EditorAction testAction =
      new EditorAction() {

        @Override
        public void execute(EditorContext context) {
          callTracker++;
        }
      };
  bindings.registerAction(KeyCombo.CTRL_G, testAction);
  EditorImpl editor = createEditor(bindings);

  // 103 = g, this event = CTRL_G which is bound to ORDER_G by the EventWrapper
  Event rawEvent = Document.get().createKeyPressEvent(
      true, false, false, false, G_CODE, G_CODE).cast();
  editor.onJavaScriptEvent(JsEvents.KEY_PRESS, rawEvent);
  assertEquals("Callback action not called on registered keypress", callTracker, 1);
}
 
Example 29
Project: Wiab.pro   File: FocusManager.java   Source Code and License 6 votes vote down vote up
/**
 * Installs a key handler for key events on this window.
 *
 * @param handler handler to receive key events.
 */
static void install(KeySignalHandler handler) {
  //
  // NOTE: There are three potential candidate elements for sinking keyboard
  // events: the window, the document, and the document body. IE7 does not
  // fire events on the window element, and GWT's RootPanel is already a
  // listener on the body, leaving the document as the only cross-browser
  // whole-window event-sinking 'element'.
  //
  DocumentPanel panel = new DocumentPanel(handler);
  panel.setElement(Document.get().<Element>cast());
  panel.addDomHandler(panel, KeyDownEvent.getType());
  panel.addDomHandler(panel, KeyPressEvent.getType());
  panel.addDomHandler(panel, KeyUpEvent.getType());
  RootPanel.detachOnWindowClose(panel);
  panel.onAttach();
}
 
Example 30
Project: Wiab.pro   File: ParagraphHelperBr.java   Source Code and License 6 votes vote down vote up
/**
 * Get the spacer for the given paragraph.
 * Lazily creates & registers one if not present.
 * If there's one that the browser created, registers it as our own.
 * If the browser put a different one in to the one that we were already
 * using, replace ours with the browser's.
 * @param paragraph
 * @return The spacer
 */
protected BRElement getSpacer(Element paragraph) {
  Node last = paragraph.getLastChild();
  BRElement spacer = paragraph.getPropertyJSO(BR_REF).cast();
  if (spacer == null) {
    // Register our spacer, using one the browser put in if present
    spacer = isSpacer(last) ? last.<BRElement>cast() : Document.get().createBRElement();
    setupSpacer(paragraph, spacer);
  } else if (isSpacer(last) && last != spacer) {
    // The browser put a different one in by itself, so let's use that one
    if (spacer.hasParentElement()) {
      spacer.removeFromParent();
    }
    spacer = last.<BRElement>cast();
    setupSpacer(paragraph, spacer);
  }
  return spacer;
}
 
Example 31
Project: Wiab.pro   File: ContentTextNode.java   Source Code and License 6 votes vote down vote up
void setRendering(boolean isRendering) {
  /**
   * TODO(akaplanov) Return optimization (lines below) when successive updates of some node will correct.
   * (Remove and insert of one character in one aggregated operation).
   * if ((getImplNodelet() != null) == isRendering) {
   *   return;
   * }
   * if (isRendering) {
   *   setImplNodelet(Document.get().createTextNode(data));
   * } else {
   *   setImplNodelet(null);
   * }
   */
   if (isRendering) {
     if (getImplNodelet() != null) {
       getImplNodelet().setData(data);
     } else {
      setImplNodelet(Document.get().createTextNode(data));
     }
   } else {
     setImplNodelet(null);
   }
}
 
Example 32
Project: Wiab.pro   File: TestEditors.java   Source Code and License 6 votes vote down vote up
/** For testing purposes only. */
public static ContentDocument createTestDocument() {
  ContentDocument doc = new ContentDocument(DocumentSchema.NO_SCHEMA_CONSTRAINTS);
  Registries registries = Editor.ROOT_REGISTRIES.createExtension();
  for (String t : new String[] {"q", "a", "b", "c", "x"}) {
    final String tag = t;
    registries.getElementHandlerRegistry().registerRenderer(tag,
        new Renderer() {
          @Override
          public Element createDomImpl(Renderable element) {
            return element.setAutoAppendContainer(Document.get().createElement(tag));
          }
        });
  }
  doc.setRegistries(registries);
  Editor editor = getMinimalEditor();
  editor.setContent(doc);
  return doc;
}
 
Example 33
Project: Wiab.pro   File: ContentTextNodeGwtTest.java   Source Code and License 6 votes vote down vote up
public void testImplDataSumsTextNodes() throws HtmlMissing {
  ContentDocument dom = TestEditors.createTestDocument();
  c = dom.debugGetRawDocument();
  ContentElement root = c.getDocumentElement();

  ContentTextNode t1 = c.createTextNode("hello", root, null);
  Text txt = t1.getImplNodelet();

  assertEquals("hello", t1.getImplData());
  Text txt3 = Document.get().createTextNode(" there");
  txt.getParentNode().insertAfter(txt3, txt);
  assertEquals("hello there", t1.getImplData());
  Text txt2 = txt.splitText(2);
  assertEquals("hello there", t1.getImplData());
  assertSame(txt3, txt.getNextSibling().getNextSibling());
  assertTrue(t1.owns(txt) && t1.owns(txt2) && t1.owns(txt3));

  ContentTextNode t2 = c.createTextNode("before", root, t1);

  assertEquals("before", t2.getImplData());
  Text t2_2 = t2.getImplNodelet().splitText(3);
  assertEquals("before", t2.getImplData());
  assertTrue(t2.owns(t2_2));
}
 
Example 34
Project: Mindustry   File: HtmlLauncher.java   Source Code and License 5 votes vote down vote up
void scaleCanvas() {
    Element element = Document.get().getElementById("embed-html");
    int innerWidth = getWindowInnerWidth();
    int innerHeight = getWindowInnerHeight();
    int newWidth = innerWidth;
    int newHeight = innerHeight;
    float ratio = innerWidth / (float) innerHeight;
    float viewRatio = WIDTH / (float) HEIGHT;

    if (ratio > viewRatio) {
        newWidth = (int) (innerHeight * viewRatio);
    } else {
        newHeight = (int) (innerWidth / viewRatio);
    }

    NodeList<Element> nl = element.getElementsByTagName("canvas");

    if (nl != null && nl.getLength() > 0) {
        Element canvas = nl.getItem(0);
        canvas.setAttribute("width", "" + newWidth + "px");
        canvas.setAttribute("height", "" + newHeight + "px");
        canvas.getStyle().setWidth(newWidth, Style.Unit.PX);
        canvas.getStyle().setHeight(newHeight, Style.Unit.PX);
        canvas.getStyle().setTop((int) ((innerHeight - newHeight) * 0.5f), Style.Unit.PX);
        canvas.getStyle().setLeft((int) ((innerWidth - newWidth) * 0.5f), Style.Unit.PX);
        canvas.getStyle().setPosition(Style.Position.ABSOLUTE);
    }
}
 
Example 35
Project: empiria.player   File: GroupModuleBase.java   Source Code and License 5 votes vote down vote up
@Override
protected String getModuleId() {
    if (super.getModuleId() == null || "".equals(super.getModuleId().trim())) {
        if (moduleId == null)
            moduleId = Document.get().createUniqueId();
        return moduleId;
    }
    return super.getModuleId();
}
 
Example 36
Project: empiria.player   File: FlashLocalMediaImpl.java   Source Code and License 5 votes vote down vote up
public FlashLocalMediaImpl(String name) {
    elementId = Document.get().createUniqueId();
    panelMain = new FlowPanel();
    panelMain.setStyleName("qp-" + name + "-flash-local");
    panelContent = new FlowPanel();
    panelContent.getElement().setId(elementId);
    panelMain.add(panelContent);

    initWidget(panelMain);
}
 
Example 37
Project: empiria.player   File: VideoPlayer.java   Source Code and License 5 votes vote down vote up
@Inject
public VideoPlayer(@Assisted VideoElementWrapper videoElementWrapper, VideoPlayerNative nativePlayer, UserAgentUtil userAgentUtil) {
    this.nativePlayer = nativePlayer;
    this.videoElementWrapper = videoElementWrapper;
    this.userAgentUtil = userAgentUtil;
    divElement = Document.get().createDivElement();
    setElement(divElement);
}
 
Example 38
Project: empiria.player   File: VideoElementWrapperProvider.java   Source Code and License 5 votes vote down vote up
@Override
public VideoElementWrapper get() {
    String playerId = Document.get().createUniqueId();
    VideoElement videoElem = Document.get().createVideoElement();
    videoElem.setId(playerId);
    videoElem.addClassName(CLASS_NAME);
    return new VideoElementWrapper(videoElem);
}
 
Example 39
Project: empiria.player   File: MetaDescriptionManager.java   Source Code and License 5 votes vote down vote up
public void processDocument(com.google.gwt.xml.client.Document document) {
    if (document != null) {
        Element metaDescriptionNode = XMLUtils.getFirstElementWithTagName(document.getDocumentElement(), "metaDescription");
        if (metaDescriptionNode != null) {
            NodeList metaNodes = metaDescriptionNode.getElementsByTagName("meta");
            com.google.gwt.dom.client.Element htmlHeadNode = Document.get().getElementsByTagName("head").getItem(0);
            for (int n = 0; n < metaNodes.getLength(); n++) {
                com.google.gwt.dom.client.Element currElement = convertToDomElement((Element) metaNodes.item(n));
                htmlHeadNode.appendChild(currElement);
            }
        }
    }
}
 
Example 40
Project: empiria.player   File: MetaDescriptionManager.java   Source Code and License 5 votes vote down vote up
private com.google.gwt.dom.client.Element convertToDomElement(Element xmlElement) {
    com.google.gwt.dom.client.Element domElement = Document.get().createElement(xmlElement.getNodeName());
    for (int a = 0; a < xmlElement.getAttributes().getLength(); a++) {
        Node currAttr = xmlElement.getAttributes().item(a);
        domElement.setAttribute(currAttr.getNodeName(), currAttr.getNodeValue());
    }
    return domElement;
}