src/share/classes/javax/swing/text/html/StyleSheet.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 100  * </code></pre>
 101  * <p>
 102  * The semantics for when a CSS style should overide visual attributes
 103  * defined by an element are not well defined. For example, the html
 104  * <code>&lt;body bgcolor=red&gt;</code> makes the body have a red
 105  * background. But if the html file also contains the CSS rule
 106  * <code>body { background: blue }</code> it becomes less clear as to
 107  * what color the background of the body should be. The current
 108  * implementation gives visual attributes defined in the element the
 109  * highest precedence, that is they are always checked before any styles.
 110  * Therefore, in the previous example the background would have a
 111  * red color as the body element defines the background color to be red.
 112  * <p>
 113  * As already mentioned this supports CSS. We don't support the full CSS
 114  * spec. Refer to the javadoc of the CSS class to see what properties
 115  * we support. The two major CSS parsing related
 116  * concepts we do not currently
 117  * support are pseudo selectors, such as <code>A:link { color: red }</code>,
 118  * and the <code>important</code> modifier.
 119  * <p>
 120  * <font color="red">Note: This implementation is currently
 121  * incomplete.  It can be replaced with alternative implementations
 122  * that are complete.  Future versions of this class will provide
 123  * better CSS support.</font>
 124  *
 125  * @author  Timothy Prinzing
 126  * @author  Sunita Mani
 127  * @author  Sara Swanson
 128  * @author  Jill Nakata
 129  */
 130 public class StyleSheet extends StyleContext {
 131     // As the javadoc states, this class maintains a mapping between
 132     // a CSS selector (such as p.bar) and a Style.
 133     // This consists of a number of parts:
 134     // . Each selector is broken down into its constituent simple selectors,
 135     //   and stored in an inverted graph, for example:
 136     //     p { color: red } ol p { font-size: 10pt } ul p { font-size: 12pt }
 137     //   results in the graph:
 138     //          root
 139     //           |
 140     //           p
 141     //          / \
 142     //         ol ul
 143     //   each node (an instance of SelectorMapping) has an associated


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 100  * </code></pre>
 101  * <p>
 102  * The semantics for when a CSS style should overide visual attributes
 103  * defined by an element are not well defined. For example, the html
 104  * <code>&lt;body bgcolor=red&gt;</code> makes the body have a red
 105  * background. But if the html file also contains the CSS rule
 106  * <code>body { background: blue }</code> it becomes less clear as to
 107  * what color the background of the body should be. The current
 108  * implementation gives visual attributes defined in the element the
 109  * highest precedence, that is they are always checked before any styles.
 110  * Therefore, in the previous example the background would have a
 111  * red color as the body element defines the background color to be red.
 112  * <p>
 113  * As already mentioned this supports CSS. We don't support the full CSS
 114  * spec. Refer to the javadoc of the CSS class to see what properties
 115  * we support. The two major CSS parsing related
 116  * concepts we do not currently
 117  * support are pseudo selectors, such as <code>A:link { color: red }</code>,
 118  * and the <code>important</code> modifier.
 119  * <p>
 120  * @implNote This implementation is currently
 121  * incomplete.  It can be replaced with alternative implementations
 122  * that are complete.  Future versions of this class will provide
 123  * better CSS support.
 124  *
 125  * @author  Timothy Prinzing
 126  * @author  Sunita Mani
 127  * @author  Sara Swanson
 128  * @author  Jill Nakata
 129  */
 130 public class StyleSheet extends StyleContext {
 131     // As the javadoc states, this class maintains a mapping between
 132     // a CSS selector (such as p.bar) and a Style.
 133     // This consists of a number of parts:
 134     // . Each selector is broken down into its constituent simple selectors,
 135     //   and stored in an inverted graph, for example:
 136     //     p { color: red } ol p { font-size: 10pt } ul p { font-size: 12pt }
 137     //   results in the graph:
 138     //          root
 139     //           |
 140     //           p
 141     //          / \
 142     //         ol ul
 143     //   each node (an instance of SelectorMapping) has an associated