Beispiel #1
0
 private boolean isResizeHandle(EventTarget eventTarget) {
   if (Element.is(eventTarget)) {
     Element e = Element.as(eventTarget);
     if (e.getClassName().contains("-column-resize-handle")) {
       return true;
     }
   }
   return false;
 }
  private void init() {
    Map<String, Element> containers = contentContainerFactory.list();
    for (String containerName : containers.keySet()) {
      List<String> containerStyles = new ArrayList<String>();
      styles.put(containerName, containerStyles);
      Element element = containers.get(containerName);
      List<JavaScriptRegExp> matchers = new ArrayList<JavaScriptRegExp>();
      if (element.hasAttribute("id")) {
        matchers.add(
            JavaScriptRegExp.create(
                "^\\s*#" + element.getAttribute("id") + "\\s+>?\\s*([^\\s,]+)"));
      }
      String[] cssClasseNames = element.getClassName().trim().split("\\s+");
      for (String cssClassName : cssClasseNames) {
        matchers.add(JavaScriptRegExp.create("^\\s*." + cssClassName + "\\s+>?\\s*([^\\s,]+)"));
      }

      JsArray<StyleSheet> styleSheets = StyleSheet.getAll();
      for (int i = 0; i < styleSheets.length(); i++) {
        StyleSheet styleSheet = styleSheets.get(i);
        if (styleSheet == null) continue;

        // In Chrome, if stylesheet originates from a different domain,
        // ss.cssRules simply won't exist. I believe the same is true for IE, but
        // I haven't tested it.
        //
        // In Firefox, if stylesheet originates from a different domain, trying
        // to access ss.cssRules will throw a SecurityError. Hence, we must use
        // try/catch to detect this condition in Firefox.
        JsArray<CSSStyleRule> cssRules;
        try {
          cssRules = styleSheet.cssRules();
        } catch (JavaScriptException e) {
          cssRules = null;
        }
        if (cssRules == null) continue;
        for (int j = 0; j < cssRules.length(); j++) {
          CSSStyleRule rule = cssRules.get(j);
          if (rule == null) continue;
          if (rule.selectorText() == null) continue;
          String[] selectors = rule.selectorText().split(",");
          for (String selector : selectors) {
            for (JavaScriptRegExp matcher : matchers) {
              JsArrayString matches = matcher.match(selector);
              if (matches != null
                  && matches.length() == 2
                  && !containerStyles.contains(matches.get(1))) {
                containerStyles.add(matches.get(1));
              }
            }
          }
        }
      }
    }
  }
Beispiel #3
0
 public void updateRowVisibility(Set<String> names) {
   if (names.equals(showNames)) return;
   this.showNames = names;
   int row = 0;
   while (row < table.getRowCount()) {
     Element rowEl = rowFormatter.getElement(row);
     String className = rowEl.getClassName().trim();
     rowFormatter.setVisible(row, className.isEmpty() || showNames.contains(className));
     row++;
   }
 }
  private Element getElementByTagAndClassName(String tagName, String className) {
    NodeList<Element> elements = getElement().getElementsByTagName(tagName);

    for (int i = 0; i < elements.getLength(); i++) {
      Element element = elements.getItem(i);
      if (element.getClassName().contains(className)) {
        return element;
      }
    }

    return null;
  }
 @Override
 public void onBrowserEvent(Event event) {
   Element element = DOM.eventGetTarget(event);
   switch (DOM.eventGetType(event)) {
     case Event.ONCLICK:
       {
         if (element.getClassName().equals(ThemeStyles.INSTANCE.menuRightImage()))
           ProjectMRUList.setOpenInNewWindow(true);
       }
   }
   super.onBrowserEvent(event);
 }
 /** Improves splitter visibility. */
 private void tuneSplitter() {
   NodeList<Node> nodes = splitLayoutPanel.getElement().getChildNodes();
   for (int i = 0; i < nodes.getLength(); i++) {
     Node node = nodes.getItem(i);
     if (node.hasChildNodes()) {
       com.google.gwt.dom.client.Element el = node.getFirstChild().cast();
       if ("gwt-SplitLayoutPanel-HDragger".equals(el.getClassName())) {
         tuneSplitter(el);
         return;
       }
     }
   }
 }
Beispiel #7
0
  public void testBundle() {
    assertEquals(getCenter(), widgetUi.bundledLabel.getParent());
    assertEquals(new FakeBundle().helloText(), widgetUi.bundledLabel.getText());
    WidgetBasedUiExternalResources resources = GWT.create(WidgetBasedUiExternalResources.class);
    assertEquals(resources.style().prettyText(), widgetUi.bundledLabel.getStyleName());

    Element pretty = DOM.getElementById("prettyPara");
    assertEquals(resources.style().prettyText(), pretty.getClassName());

    ArbitraryPojo pojo = new ArbitraryPojo();
    FooLabel foo = new FooLabel();
    foo.setPojo(pojo);
    assertEquals(foo.getText(), widgetUi.theFoo.getText());
  }
 private JsNodeArray getNotPseudo(
     JsNodeArray previousMatch, String pseudoValue, JsNodeArray matchingElms) {
   if (new JsRegexp("(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
     matchingElms =
         subtractArray(
             previousMatch, getElementsByPseudo(previousMatch, pseudoValue.substring(1), ""));
   } else {
     pseudoValue = pseudoValue.replace("^\\[#([\\w\\u00C0-\\uFFFF\\-\\_]+)\\]$", "[id=$1]");
     JsObjectArray<String> notTag = new JsRegexp("^(\\w+)").exec(pseudoValue);
     JsObjectArray<String> notClass =
         new JsRegexp("^\\.([\\w\u00C0-\uFFFF\\-_]+)").exec(pseudoValue);
     JsObjectArray<String> notAttr =
         new JsRegexp("\\[(\\w+)(\\^|\\$|\\*|\\||~)?=?([\\w\\u00C0-\\uFFFF\\s\\-_\\.]+)?\\]")
             .exec(pseudoValue);
     JsRegexp notRegExp =
         new JsRegexp(
             "(^|\\s)"
                 + (JsUtils.truth(notTag)
                     ? notTag.get(1)
                     : JsUtils.truth(notClass) ? notClass.get(1) : "")
                 + "(\\s|$)",
             "i");
     if (JsUtils.truth(notAttr)) {
       String notAttribute =
           JsUtils.truth(notAttr.get(3)) ? notAttr.get(3).replace("\\.", "\\.") : null;
       String notMatchingAttrVal = attrToRegExp(notAttribute, notAttr.get(2));
       notRegExp = new JsRegexp(notMatchingAttrVal, "i");
     }
     for (int v = 0, vlen = previousMatch.size(); v < vlen; v++) {
       Element notElm = previousMatch.getElement(v);
       Element addElm = null;
       if (JsUtils.truth(notTag) && !notRegExp.test(notElm.getNodeName())) {
         addElm = notElm;
       } else if (JsUtils.truth(notClass) && !notRegExp.test(notElm.getClassName())) {
         addElm = notElm;
       } else if (JsUtils.truth(notAttr)) {
         String att = getAttr(notElm, notAttr.get(1));
         if (!JsUtils.truth(att) || !notRegExp.test(att)) {
           addElm = notElm;
         }
       }
       if (JsUtils.truth(addElm) && !isAdded(addElm)) {
         setAdded(addElm, true);
         matchingElms.addNode(addElm);
       }
     }
   }
   return matchingElms;
 }
    private void commitPosition(int pos) {
      lastElementX_ = pos;

      // check to see if we're overlapping with another tab
      for (int i = 0; i < dragTabsHost_.getChildCount(); i++) {
        // skip non-element DOM nodes
        Node node = dragTabsHost_.getChild(i);
        if (node.getNodeType() != Node.ELEMENT_NODE) {
          continue;
        }

        // skip the current candidate (no point in testing it for swap)
        if (i == candidatePos_) {
          continue;
        }

        // skip the element we're dragging and elements that are not tabs
        Element ele = (Element) node;
        if (ele == dragElement_ || ele.getClassName().indexOf("gwt-TabLayoutPanelTab") < 0) {
          continue;
        }

        int left = DomUtils.leftRelativeTo(dragTabsHost_, ele);
        int right = left + ele.getClientWidth();
        int minOverlap = Math.min(initDragWidth_ / 2, ele.getClientWidth() / 2);

        // a little complicated: compute the number of overlapping pixels
        // with this element; if the overlap is more than half of our width
        // (or the width of the candidate), it's swapping time
        if (Math.min(lastElementX_ + initDragWidth_, right) - Math.max(lastElementX_, left)
            >= minOverlap) {
          dragTabsHost_.removeChild(dragPlaceholder_);
          if (candidatePos_ > i) {
            dragTabsHost_.insertBefore(dragPlaceholder_, ele);
          } else {
            dragTabsHost_.insertAfter(dragPlaceholder_, ele);
          }
          candidatePos_ = i;

          // account for the extra element when moving to the right of the
          // original location
          if (dragElement_ != null && startPos_ != null) {
            destPos_ = startPos_ <= candidatePos_ ? candidatePos_ - 1 : candidatePos_;
          } else {
            destPos_ = candidatePos_;
          }
        }
      }
    }
  /** {@inheritDoc} */
  @Override
  public void showLocationDetails(
      final String name, final String htmlTitle, final String htmlContent) {
    final MQAPoi point = getMarker(name);
    if (point != null) {
      point.setInfoTitleHTML(htmlTitle);
      point.setInfoContentHTML(htmlContent);
      point.showInfoWindow();

      final NodeList<Element> elements = Document.get().getElementsByTagName("div");
      for (int i = 0; i < elements.getLength(); i++) {
        final Element e = elements.getItem(i);
        if (e.getClassName().equals("mqpoicontenttext")) {
          final Style s = e.getStyle();
          s.setOverflow(Overflow.HIDDEN);
          break;
        }
      }
    }
  }
  public NodeList<Element> select(String sel, Node ctx) {
    String selectors[] = sel.replace("\\s*(,)\\s*", "$1").split(",");
    boolean identical = false;
    JsNodeArray elm = JsNodeArray.create();
    for (int a = 0, len = selectors.length; a < len; a++) {
      if (a > 0) {
        identical = false;
        for (int b = 0, bl = a; b < bl; b++) {
          if (JsUtils.eq(selectors[a], selectors[b])) {
            identical = true;
            break;
          }
        }
        if (identical) {
          continue;
        }
      }
      String currentRule = selectors[a];
      JsObjectArray<String> cssSelectors = selectorSplitRegExp.match(currentRule);
      JsNodeArray prevElem = JsNodeArray.create(ctx);
      for (int i = 0, slen = cssSelectors.length(); i < slen; i++) {
        JsNodeArray matchingElms = JsNodeArray.create();
        String rule = cssSelectors.get(i);
        if (i > 0 && childOrSiblingRefRegExp.test(rule)) {
          JsObjectArray<String> childOrSiblingRef = childOrSiblingRefRegExp.exec(rule);
          if (JsUtils.truth(childOrSiblingRef)) {
            JsObjectArray<String> nextTag = new JsRegexp("^\\w+").exec(cssSelectors.get(i + 1));
            JsRegexp nextRegExp = null;
            String nextTagStr = null;
            if (JsUtils.truth(nextTag)) {
              nextTagStr = nextTag.get(0);
              nextRegExp = new JsRegexp("(^|\\s)" + nextTagStr + "(\\s|$)", "i");
            }
            for (int j = 0, jlen = prevElem.size(); j < jlen; j++) {
              Node prevRef = prevElem.getNode(j);
              String ref = childOrSiblingRef.get(0);
              if (JsUtils.eq(">", ref)) {
                getDescendantNodes(matchingElms, nextTagStr, prevRef);
              } else if (JsUtils.eq("+", ref)) {
                getSiblingNodes(matchingElms, nextTag, nextRegExp, prevRef);
              } else if (JsUtils.eq("~", ref)) {
                getGeneralSiblingNodes(matchingElms, nextTag, nextRegExp, prevRef);
              }
            }
            prevElem = matchingElms;
            clearAdded(prevElem);
            rule = cssSelectors.get(++i);
            if (new JsRegexp("^\\w+$").test(rule)) {
              continue;
            }
            setSkipTag(prevElem, true);
          }
        }
        JsObjectArray<String> cssSelector = cssSelectorRegExp.exec(rule);
        SplitRule splitRule =
            new SplitRule(
                !JsUtils.truth(cssSelector.get(1)) || JsUtils.eq(cssSelector.get(3), "*")
                    ? "*"
                    : cssSelector.get(1),
                !JsUtils.eq(cssSelector.get(3), "*") ? cssSelector.get(2) : null,
                cssSelector.get(4),
                cssSelector.get(6),
                cssSelector.get(10));
        if (JsUtils.truth(splitRule.id)) {
          Element domelem = Document.get().getElementById(splitRule.id.substring(1));
          if (JsUtils.truth(domelem)) {
            matchingElms = JsNodeArray.create(domelem);
          }
          prevElem = matchingElms;
        } else if (JsUtils.truth(splitRule.tag) && !isSkipped(prevElem)) {
          if (i == 0 && matchingElms.size() == 0 && prevElem.size() == 1) {
            prevElem =
                matchingElms =
                    JsNodeArray.create(getElementsByTagName(splitRule.tag, prevElem.getNode(0)));
          } else {
            NodeList<Element> tagCollectionMatches;
            for (int l = 0, ll = prevElem.size(); l < ll; l++) {
              tagCollectionMatches = getElementsByTagName(splitRule.tag, prevElem.getNode(l));
              for (int m = 0, mlen = tagCollectionMatches.getLength(); m < mlen; m++) {
                Node tagMatch = tagCollectionMatches.getItem(m);

                if (!isAdded(tagMatch)) {
                  setAdded(tagMatch, true);
                  matchingElms.addNode(tagMatch);
                }
              }
            }
            prevElem = matchingElms;
            clearAdded(prevElem);
          }
          if (matchingElms.size() == 0) {
            break;
          }
          setSkipTag(prevElem, false);
          if (JsUtils.truth(splitRule.allClasses)) {
            String[] allClasses = splitRule.allClasses.replaceFirst("^\\.", "").split("\\.");
            JsRegexp[] regExpClassNames = new JsRegexp[allClasses.length];
            for (int n = 0, nl = allClasses.length; n < nl; n++) {
              regExpClassNames[n] = new JsRegexp("(^|\\s)" + allClasses[n] + "(\\s|$)");
            }
            JsNodeArray matchingClassElms = JsNodeArray.create();
            for (int o = 0, olen = prevElem.size(); o < olen; o++) {
              Element current = prevElem.getElement(o);
              String elmClass = current.getClassName();
              boolean addElm = false;
              if (JsUtils.truth(elmClass) && !isAdded(current)) {
                for (int p = 0, pl = regExpClassNames.length; p < pl; p++) {
                  addElm = regExpClassNames[p].test(elmClass);
                  if (!addElm) {
                    break;
                  }
                }
                if (addElm) {
                  setAdded(current, true);
                  matchingClassElms.addNode(current);
                }
              }
            }
            clearAdded(prevElem);
            prevElem = matchingElms = matchingClassElms;
          }
          if (JsUtils.truth(splitRule.allAttr)) {
            JsObjectArray<String> allAttr = JsRegexp.match("\\[[^\\]]+\\]", "g", splitRule.allAttr);
            JsRegexp[] regExpAttributes = new JsRegexp[allAttr.length()];
            String[] regExpAttributesStr = new String[allAttr.length()];
            JsRegexp attributeMatchRegExp =
                new JsRegexp("(\\w+)(\\^|\\$|\\*|\\||~)?=?[\"']?([\\w\u00C0-\uFFFF\\s\\-_\\.]+)?");
            for (int q = 0, ql = allAttr.length(); q < ql; q++) {
              JsObjectArray<String> attributeMatch = attributeMatchRegExp.exec(allAttr.get(q));
              String attributeValue =
                  JsUtils.truth(attributeMatch.get(3))
                      ? attributeMatch.get(3).replaceAll("\\.", "\\.")
                      : null;
              String attrVal =
                  attrToRegExp(attributeValue, (JsUtils.or(attributeMatch.get(2), null)));
              regExpAttributes[q] = (JsUtils.truth(attrVal) ? new JsRegexp(attrVal) : null);
              regExpAttributesStr[q] = attributeMatch.get(1);
            }
            JsNodeArray matchingAttributeElms = JsNodeArray.create();

            for (int r = 0, rlen = matchingElms.size(); r < rlen; r++) {
              Element current = matchingElms.getElement(r);
              boolean addElm = false;
              for (int s = 0, sl = regExpAttributes.length; s < sl; s++) {
                addElm = false;
                JsRegexp attributeRegexp = regExpAttributes[s];
                String currentAttr = getAttr(current, regExpAttributesStr[s]);
                if (JsUtils.truth(currentAttr) && currentAttr.length() != 0) {
                  if (attributeRegexp == null || attributeRegexp.test(currentAttr)) {
                    addElm = true;
                  }
                }
                if (!addElm) {
                  break;
                }
              }
              if (addElm) {
                matchingAttributeElms.addNode(current);
              }
            }
            prevElem = matchingElms = matchingAttributeElms;
          }
          if (JsUtils.truth(splitRule.allPseudos)) {
            JsRegexp pseudoSplitRegExp = new JsRegexp(":(\\w[\\w\\-]*)(\\(([^\\)]+)\\))?");

            JsObjectArray<String> allPseudos =
                JsRegexp.match("(:\\w+[\\w\\-]*)(\\([^\\)]+\\))?", "g", splitRule.allPseudos);
            for (int t = 0, tl = allPseudos.length(); t < tl; t++) {
              JsObjectArray<String> pseudo = pseudoSplitRegExp.match(allPseudos.get(t));
              String pseudoClass =
                  JsUtils.truth(pseudo.get(1)) ? pseudo.get(1).toLowerCase() : null;
              String pseudoValue = JsUtils.truth(pseudo.get(3)) ? pseudo.get(3) : null;
              matchingElms = getElementsByPseudo(matchingElms, pseudoClass, pseudoValue);
              clearAdded(matchingElms);
            }
            prevElem = matchingElms;
          }
        }
      }
      elm.pushAll(prevElem);
    }

    return JsUtils.unique(elm.<JsArray<Element>>cast()).cast();
  }
Beispiel #12
0
 /**
  * Returns true if the group is expanded.
  *
  * @param group the group
  * @return true if expanded
  */
 public boolean isExpanded(Element group) {
   return group.getClassName().indexOf("x-grid-group-collapsed") == -1;
 }
    @Override
    public void onBrowserEvent(Event event) {
      if (event.getType() == "dragenter") {
        if (dropPoint_ != null
            && event.getClientX() == dropPoint_.getX()
            && event.getClientY() == dropPoint_.getY()) {
          // Very occasionally (~5%?), dropping a tab will generate a
          // superfluous "dragenter" event immediately after the drop event
          // at exactly the same coordinates. We want to ignore this since
          // it will send us into dragging state; to do so, we cache the
          // coordinates when a tab is dropped and suppress entering drag
          // mode from those coordinates very briefly (note that this won't
          // keep the user from immediately dragging the tab around since
          // you need to move the cursor in some way to initiate a drag,
          // invalidating the coordinates.)
          dropPoint_ = null;
          return;
        }

        if (curState_ == STATE_EXTERNAL) {
          // element that was being dragged around outside boundaries
          // has come back in; clear it and treat like a new drag
          dragElement_.getStyle().clearOpacity();
          dragElement_ = null;
          curState_ = STATE_NONE;
        }
        if (curState_ == STATE_NONE) {
          beginDrag(event);
        }
        event.preventDefault();
      } else if (event.getType() == "dragover") {
        if (curState_ == STATE_DRAGGING) drag(event);
        event.preventDefault();
      } else if (event.getType() == "drop") {
        endDrag(event, ACTION_COMMIT);
        event.preventDefault();

        // cache the drop point for 250ms (see comments in event handler for
        // dragenter)
        dropPoint_ = new Point(event.getClientX(), event.getClientY());
        Scheduler.get()
            .scheduleFixedDelay(
                new Scheduler.RepeatingCommand() {
                  @Override
                  public boolean execute() {
                    dropPoint_ = null;
                    return false;
                  }
                },
                250);
      } else if (event.getType() == "dragend") {
        if (curState_ != STATE_NONE) {
          endDrag(event, ACTION_CANCEL);
        }
        event.preventDefault();
      } else if (event.getType() == "dragleave") {
        if (curState_ == STATE_NONE) return;

        // when a drag leaves the window entirely, we get a dragleave event
        // at 0, 0 (which we always want to treat as a cancel)
        if (!(event.getClientX() == 0 && event.getClientY() == 0)) {
          // look at where the cursor is now--if it's inside the tab panel,
          // do nothing, but if it's outside the tab panel, treat that as
          // a cancel
          Element ele = DomUtils.elementFromPoint(event.getClientX(), event.getClientY());
          while (ele != null && ele != Document.get().getBody()) {
            if (ele.getClassName().contains("gwt-TabLayoutPanelTabs")) {
              return;
            }
            ele = ele.getParentElement();
          }
        }

        if (dragElement_ != null) {
          // dim the element being drag to hint that it'll be moved
          endDrag(event, ACTION_EXTERNAL);
        } else {
          // if this wasn't our element, we can cancel the drag entirely
          endDrag(event, ACTION_CANCEL);
        }
      }
    }
Beispiel #14
0
 public void testDomAccessAndComputedAttributeOnPlaceholderedElement() {
   WidgetBasedUiExternalResources resources = GWT.create(WidgetBasedUiExternalResources.class);
   Element elem = DOM.getElementById("placeholdersSpan");
   assertEquals("bold", elem.getStyle().getProperty("fontWeight"));
   assertEquals(resources.style().prettyText(), elem.getClassName());
 }