Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6e6d0586ffe342c8870922bcb04c1ae6d937a28b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*******************************************************************************
 * Copyright (c) 2006, 2007 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.property;

import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.w3c.dom.css.CSSValue;
import org.w3c.dom.css.CSSValueList;

/**
 * @author mengbo
 */
public class TextDecorationMeta extends CSSPropertyMeta {
	private static final int NONE = 0;

	/**
	 * 
	 */
	public static final int UNDERLINE = 1;

	/**
	 * 
	 */
	public static final int OVERLINE = 1 << 1;

	/**
	 * 
	 */
	public static final int LINETHROUGH = 1 << 2;

	private static final int BLINK = 1 << 3;

	static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NONE,
			ICSSPropertyID.VAL_UNDERLINE, ICSSPropertyID.VAL_OVERLINE,
			ICSSPropertyID.VAL_LINETHROUGH, ICSSPropertyID.VAL_BLINK };

	/**
	 * Default constructor
	 */
	public TextDecorationMeta() {
		// the spec say text-decoration is not inherited. but the description
		// seemed to make use inherit easier.
		// It seems that the property is inherited in IE and Mozilla.
		super(true, new Integer(NONE));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues()
	 */
	protected String[] getKeywordValues() {
		return KEYWORDS;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue,
	 *      java.lang.String,
	 *      org.eclipse.jst.pagedesigner.css2.property.AbstractStyle)
	 */
	public Object calculateCSSValueResult(CSSValue value, String propertyName,
			ICSSStyle style) {
		String[] decorations = null;
		if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
			CSSValueList valueList = (CSSValueList) value;
			decorations = new String[valueList.getLength()];
			for (int i = 0; i < decorations.length; i++) {
				decorations[i] = valueList.item(i).getCssText();
			}
		} else {
			decorations = new String[1];
			decorations[0] = value.getCssText();
		}

		int intvalue = 0;
		for (int i = 0; i < decorations.length; i++) {
			String key = super.checkKeywordValues(decorations[i]);
			if (key == ICSSPropertyID.VAL_NONE) {
				intvalue = NONE;
			} else if (key == ICSSPropertyID.VAL_UNDERLINE) {
				intvalue |= UNDERLINE;
			} else if (key == ICSSPropertyID.VAL_OVERLINE) {
				intvalue |= OVERLINE;
			} else if (key == ICSSPropertyID.VAL_LINETHROUGH) {
				intvalue |= LINETHROUGH;
			} else if (key == ICSSPropertyID.VAL_BLINK) {
				intvalue |= BLINK;
			}
		}

		return new Integer(intvalue);
	}
}

Back to the top