Exemple #1
0
  /**
   * Allows to specify which connectors contain the description for the window. Text contained in
   * the widgets of the connectors will be read by assistive devices when it is opened.
   *
   * <p>When the provided array is empty, an existing description is removed.
   *
   * @param connectors with the connectors of the widgets to use as description
   */
  public void setAssistiveDescription(Connector[] connectors) {
    if (connectors != null) {
      assistiveConnectors = connectors;

      if (connectors.length == 0) {
        Roles.getDialogRole().removeAriaDescribedbyProperty(getElement());
      } else {
        Id[] ids = new Id[connectors.length];
        for (int index = 0; index < connectors.length; index++) {
          if (connectors[index] == null) {
            throw new IllegalArgumentException(
                "All values in parameter description need to be non-null");
          }

          Element element = ((ComponentConnector) connectors[index]).getWidget().getElement();
          AriaHelper.ensureHasId(element);
          ids[index] = Id.of(element);
        }

        Roles.getDialogRole().setAriaDescribedbyProperty(getElement(), ids);
      }
    } else {
      throw new IllegalArgumentException("Parameter description must be non-null");
    }
  }
Exemple #2
0
  public void show(Widget widget, Position position, String style) {
    NotificationConfigurationBean styleSetup = getUiState(style);
    setWaiAriaRole(styleSetup);

    FlowPanel panel = new FlowPanel();
    if (styleSetup.hasAssistivePrefix()) {
      panel.add(new Label(styleSetup.getAssistivePrefix()));
      AriaHelper.setVisibleForAssistiveDevicesOnly(panel.getElement(), true);
    }

    panel.add(widget);

    if (styleSetup.hasAssistivePostfix()) {
      panel.add(new Label(styleSetup.getAssistivePostfix()));
      AriaHelper.setVisibleForAssistiveDevicesOnly(panel.getElement(), true);
    }
    setWidget(panel);
    show(position, style);
  }
Exemple #3
0
  protected void constructDOM() {
    setStyleName(CLASSNAME);

    topTabStop = DOM.createDiv();
    DOM.setElementAttribute(topTabStop, "tabindex", "0");

    header = DOM.createDiv();
    DOM.setElementProperty(header, "className", CLASSNAME + "-outerheader");
    headerText = DOM.createDiv();
    DOM.setElementProperty(headerText, "className", CLASSNAME + "-header");
    contents = DOM.createDiv();
    DOM.setElementProperty(contents, "className", CLASSNAME + "-contents");
    footer = DOM.createDiv();
    DOM.setElementProperty(footer, "className", CLASSNAME + "-footer");
    resizeBox = DOM.createDiv();
    DOM.setElementProperty(resizeBox, "className", CLASSNAME + "-resizebox");
    closeBox = DOM.createDiv();
    maximizeRestoreBox = DOM.createDiv();
    DOM.setElementProperty(maximizeRestoreBox, "className", CLASSNAME + "-maximizebox");
    DOM.setElementAttribute(maximizeRestoreBox, "tabindex", "0");
    DOM.setElementProperty(closeBox, "className", CLASSNAME + "-closebox");
    DOM.setElementAttribute(closeBox, "tabindex", "0");
    DOM.appendChild(footer, resizeBox);

    bottomTabStop = DOM.createDiv();
    DOM.setElementAttribute(bottomTabStop, "tabindex", "0");

    wrapper = DOM.createDiv();
    DOM.setElementProperty(wrapper, "className", CLASSNAME + "-wrap");

    DOM.appendChild(wrapper, topTabStop);
    DOM.appendChild(wrapper, header);
    DOM.appendChild(wrapper, maximizeRestoreBox);
    DOM.appendChild(wrapper, closeBox);
    DOM.appendChild(header, headerText);
    DOM.appendChild(wrapper, contents);
    DOM.appendChild(wrapper, footer);
    DOM.appendChild(wrapper, bottomTabStop);
    DOM.appendChild(super.getContainerElement(), wrapper);

    sinkEvents(
        Event.ONDBLCLICK
            | Event.MOUSEEVENTS
            | Event.TOUCHEVENTS
            | Event.ONCLICK
            | Event.ONLOSECAPTURE);

    setWidget(contentPanel);

    // Make the closebox accessible for assistive devices
    Roles.getButtonRole().set(closeBox);
    Roles.getButtonRole().setAriaLabelProperty(closeBox, "close button");

    // Make the maximizebox accessible for assistive devices
    Roles.getButtonRole().set(maximizeRestoreBox);
    Roles.getButtonRole().setAriaLabelProperty(maximizeRestoreBox, "maximize button");

    // Provide the title to assistive devices
    AriaHelper.ensureHasId(headerText);
    Roles.getDialogRole().setAriaLabelledbyProperty(getElement(), Id.of(headerText));

    // Handlers to Prevent tab to leave the window
    topEventBlocker =
        new NativePreviewHandler() {
          @Override
          public void onPreviewNativeEvent(NativePreviewEvent event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            if (nativeEvent.getEventTarget().cast() == topTabStop
                && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB
                && nativeEvent.getShiftKey()) {
              nativeEvent.preventDefault();
            }
          }
        };

    bottomEventBlocker =
        new NativePreviewHandler() {
          @Override
          public void onPreviewNativeEvent(NativePreviewEvent event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            if (nativeEvent.getEventTarget().cast() == bottomTabStop
                && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB
                && !nativeEvent.getShiftKey()) {
              nativeEvent.preventDefault();
            }
          }
        };
  }