コード例 #1
0
  /**
   * Tests whether this StyleSheet matches the specified variants. Returns a number indicating the
   * specificity of the match. Zero means there is no match. Larger numbers indicate better matches.
   * The value returned by compareVariants is used to sort style sheets according to precedence.
   *
   * @param mode
   */
  public int compareVariants(
      Locale locale,
      int direction,
      TrinidadAgent agent,
      int mode,
      AccessibilityProfile accessibilityProfile) {
    int localeMatch = _compareLocale(locale);
    if (localeMatch == 0) return 0;

    int directionMatch = _compareDirection(direction);
    if (directionMatch == 0) return 0;

    int browser = agent.getAgentApplication();

    int browserAndVersionMatch = _compareBrowserAndVersion(browser, agent);
    if (browserAndVersionMatch == 0) return 0;
    int modeMatch = _compareMode(mode);
    if (modeMatch == 0) return 0;

    int osMatch = _compareOS(agent.getAgentOS());
    if (osMatch == 0) return 0;

    int accessibilityMatch = _compareAccessibility(accessibilityProfile);
    if (accessibilityMatch == 0) return 0;

    return (localeMatch | browserAndVersionMatch | osMatch | accessibilityMatch);
  }
コード例 #2
0
  // Compares the browser and its version against the supported variants
  private int _compareBrowserAndVersion(int browser, TrinidadAgent agent) {
    // If we don't have a browser specified, we match anything
    if (_agentVersions.isEmpty()) return _BROWSER_UNKNOWN_MATCH;

    // On the other hand, if we do have a browser specified, but
    // the client browser is not known, we don't have a match
    if (browser == TrinidadAgent.APPLICATION_UNKNOWN) return 0;

    // If we have browser exact match, compare versions
    Integer browserNum = Integer.valueOf(browser);
    if (_agentVersions.containsKey(browserNum)) {
      Set<Version> versions = _agentVersions.get(browserNum);
      if (versions.isEmpty()) return _BROWSER_EXACT_MATCH | _VERSION_UNKNOWN_MATCH;

      Version version = new Version(agent.getAgentVersion());

      for (Version av : versions) {
        if (av.compareTo(version) == 0) {
          return _BROWSER_EXACT_MATCH | _VERSION_EXACT_MATCH;
        }
      }

      return 0;
    }

    return 0;
  }