Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 282575 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java (-10 lines)
Lines 72-87 Link Here
72
		assertEquals(BLUE, folderToTest.getForeground().getRGB());
72
		assertEquals(BLUE, folderToTest.getForeground().getRGB());
73
	}
73
	}
74
74
75
	public void testSelectedPseudo() throws Exception {
76
		CTabFolder folderToTest = createTestCTabFolder(
77
				"CTabFolder { color: #FFFFFF; background-color: #0000FF }\n" +
78
				"CTabFolder:selected { color: #FF0000;  background-color: #00FF00 }");
79
		assertEquals(WHITE, folderToTest.getForeground().getRGB());
80
		assertEquals(BLUE, folderToTest.getBackground().getRGB());
81
		assertEquals(RED, folderToTest.getSelectionForeground().getRGB());
82
		assertEquals(GREEN, folderToTest.getSelectionBackground().getRGB());
83
	}
84
85
	//See GradientTest for testing background gradient
75
	//See GradientTest for testing background gradient
86
76
87
	public void testFontRegular() throws Exception {
77
	public void testFontRegular() throws Exception {
(-)src/org/eclipse/e4/ui/tests/css/swt/GradientTest.java (-10 / +10 lines)
Lines 60-73 Link Here
60
	
60
	
61
	public void testGradients() throws Exception {
61
	public void testGradients() throws Exception {
62
		CTabFolder folderToTest = createTestCTabFolder(
62
		CTabFolder folderToTest = createTestCTabFolder(
63
				"CTabFolder:selected { background-color: #FF0000 #0000FF}");
63
				"CTabItem:selected { background-color: #FF0000 #0000FF}");
64
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
64
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
65
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
65
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
66
	}
66
	}
67
	
67
	
68
	public void testDefaultPercents() throws Exception {
68
	public void testDefaultPercents() throws Exception {
69
		CTabFolder folderToTest = createTestCTabFolder(
69
		CTabFolder folderToTest = createTestCTabFolder(
70
				"CTabFolder:selected { background-color: #FF0000 #0000FF}");
70
				"CTabItem:selected { background-color: #FF0000 #0000FF}");
71
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
71
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
72
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
72
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
73
		assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
73
		assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
Lines 75-93 Link Here
75
75
76
	public void testDefaultManyPercents() throws Exception {
76
	public void testDefaultManyPercents() throws Exception {
77
		CTabFolder folderToTest = createTestCTabFolder(
77
		CTabFolder folderToTest = createTestCTabFolder(
78
				"CTabFolder:selected { background-color: red green blue yellow}");
78
				"CTabItem:selected { background-color: red green blue yellow}");
79
		assertEquals(new int[] {33, 67, 100}, getSelectionGradientPercents(folderToTest)); //default percent
79
		assertEquals(new int[] {33, 67, 100}, getSelectionGradientPercents(folderToTest)); //default percent
80
	}
80
	}
81
	
81
	
82
	public void testSpecifiedPercents() throws Exception {
82
	public void testSpecifiedPercents() throws Exception {
83
		CTabFolder folderToTest = createTestCTabFolder(
83
		CTabFolder folderToTest = createTestCTabFolder(
84
				"CTabFolder:selected { background-color: #FF0000 #0000FF 53%}");
84
				"CTabItem:selected { background-color: #FF0000 #0000FF 53%}");
85
		assertEquals(new int[] {53}, getSelectionGradientPercents(folderToTest)); 
85
		assertEquals(new int[] {53}, getSelectionGradientPercents(folderToTest)); 
86
	}
86
	}
87
87
88
	public void testManyColorsAndSpecifiedManyPercents() throws Exception {
88
	public void testManyColorsAndSpecifiedManyPercents() throws Exception {
89
		CTabFolder folderToTest = createTestCTabFolder(
89
		CTabFolder folderToTest = createTestCTabFolder(
90
				"CTabFolder:selected { background-color: #FF0000 #00FF00 #0000FF 22% 44%}");
90
				"CTabItem:selected { background-color: #FF0000 #00FF00 #0000FF 22% 44%}");
91
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
91
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
92
		assertEquals(GREEN, getSelectionBackground(folderToTest, 1).getRGB()); //2nd gradient 
92
		assertEquals(GREEN, getSelectionBackground(folderToTest, 1).getRGB()); //2nd gradient 
93
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
93
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
Lines 100-106 Link Here
100
	public void testBadPercents() throws Exception {
100
	public void testBadPercents() throws Exception {
101
		//There should be either zero or three percent declarations, otherwise it acts as default
101
		//There should be either zero or three percent declarations, otherwise it acts as default
102
		CTabFolder folderToTest = createTestCTabFolder(
102
		CTabFolder folderToTest = createTestCTabFolder(
103
				"CTabFolder:selected { background-color: red green blue yellow 10%}");
103
				"CTabItem:selected { background-color: red green blue yellow 10%}");
104
		assertEquals(new int[] {33, 67, 100}, getSelectionGradientPercents(folderToTest)); //default percent
104
		assertEquals(new int[] {33, 67, 100}, getSelectionGradientPercents(folderToTest)); //default percent
105
	}
105
	}
106
106
Lines 110-116 Link Here
110
	 */
110
	 */
111
	public void testBadColors() throws Exception {
111
	public void testBadColors() throws Exception {
112
		CTabFolder folderToTest = createTestCTabFolder(
112
		CTabFolder folderToTest = createTestCTabFolder(
113
				"CTabFolder:selected { background-color: #FF0000 notAColor #0000FF}");
113
				"CTabItem:selected { background-color: #FF0000 notAColor #0000FF}");
114
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
114
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
115
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
115
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
116
		assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
116
		assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
Lines 121-127 Link Here
121
	 */
121
	 */
122
	public void testAboveRangePercents() throws Exception {
122
	public void testAboveRangePercents() throws Exception {
123
		CTabFolder folderToTest = createTestCTabFolder(
123
		CTabFolder folderToTest = createTestCTabFolder(
124
				"CTabFolder:selected { background-color: #FF0000 #00FF00 #0000FF 20% 110%}");
124
				"CTabItem:selected { background-color: #FF0000 #00FF00 #0000FF 20% 110%}");
125
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
125
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
126
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
126
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
127
		assertEquals(new int[] {50, 100}, getSelectionGradientPercents(folderToTest)); //default percent
127
		assertEquals(new int[] {50, 100}, getSelectionGradientPercents(folderToTest)); //default percent
Lines 132-138 Link Here
132
	 */
132
	 */
133
	public void testBelowRangePercents() throws Exception {
133
	public void testBelowRangePercents() throws Exception {
134
		CTabFolder folderToTest = createTestCTabFolder(
134
		CTabFolder folderToTest = createTestCTabFolder(
135
				"CTabFolder:selected { background-color: #FF0000 #00FF00 #0000FF -20% 50%}");
135
				"CTabItem:selected { background-color: #FF0000 #00FF00 #0000FF -20% 50%}");
136
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
136
		assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
137
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
137
		assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
138
		assertEquals(new int[] {50, 100}, getSelectionGradientPercents(folderToTest)); //default percent
138
		assertEquals(new int[] {50, 100}, getSelectionGradientPercents(folderToTest)); //default percent
Lines 147-153 Link Here
147
	 */
147
	 */
148
	public void testAltSyntax() throws Exception {
148
	public void testAltSyntax() throws Exception {
149
		CTabFolder folderToTest = createTestCTabFolder(
149
		CTabFolder folderToTest = createTestCTabFolder(
150
				"CTabFolder:selected { background-color: gradient, rgb(140,140,140), rgb(48,48,48), 100%;");
150
				"CTabItem:selected { background-color: gradient, rgb(140,140,140), rgb(48,48,48), 100%;");
151
		assertEquals(new RGB(140,140,140), getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
151
		assertEquals(new RGB(140,140,140), getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin		
152
		assertEquals(new RGB(48,48,48), folderToTest.getSelectionBackground().getRGB()); //gradient end
152
		assertEquals(new RGB(48,48,48), folderToTest.getSelectionBackground().getRGB()); //gradient end
153
		assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
153
		assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
(-)src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java (-12 / +121 lines)
Lines 15-21 Link Here
15
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.custom.CTabFolder;
16
import org.eclipse.swt.custom.CTabFolder;
17
import org.eclipse.swt.custom.CTabItem;
17
import org.eclipse.swt.custom.CTabItem;
18
import org.eclipse.swt.graphics.Color;
18
import org.eclipse.swt.graphics.FontData;
19
import org.eclipse.swt.graphics.FontData;
20
import org.eclipse.swt.graphics.RGB;
19
import org.eclipse.swt.layout.FillLayout;
21
import org.eclipse.swt.layout.FillLayout;
20
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Composite;
Lines 74-81 Link Here
74
		return folderToTest;
76
		return folderToTest;
75
	}
77
	}
76
78
77
	protected CTabFolder createTestTabFolder(String styleSheet) {
79
	private CTabFolder createTestTabFolder(String styleSheet) {
78
		CTabFolder folder = createTestTabFolder();
80
		return createTestTabFolder(styleSheet, true);
81
	}
82
83
	protected CTabFolder createTestTabFolder(String styleSheet, boolean open) {
84
		CTabFolder folder = createTestTabFolder(open);
79
85
80
		engine = createEngine(styleSheet, folder.getDisplay());
86
		engine = createEngine(styleSheet, folder.getDisplay());
81
87
Lines 367-373 Link Here
367
				assertEquals(SWT.NORMAL, data.getStyle());
373
				assertEquals(SWT.NORMAL, data.getStyle());
368
			}
374
			}
369
		}
375
		}
370
		
376
371
		for (int i = 0; i < folder2.getItemCount(); i++) {
377
		for (int i = 0; i < folder2.getItemCount(); i++) {
372
			CTabItem item = folder2.getItem(i);
378
			CTabItem item = folder2.getItem(i);
373
			FontData data = item.getFont().getFontData()[0];
379
			FontData data = item.getFont().getFontData()[0];
Lines 375-381 Link Here
375
			assertEquals(11, data.getHeight());
381
			assertEquals(11, data.getHeight());
376
			assertEquals(SWT.NORMAL, data.getStyle());
382
			assertEquals(SWT.NORMAL, data.getStyle());
377
		}
383
		}
378
		
384
379
		folder2.setSelection(0);
385
		folder2.setSelection(0);
380
		spinEventLoop();
386
		spinEventLoop();
381
387
Lines 425-431 Link Here
425
				assertEquals(SWT.NORMAL, data.getStyle());
431
				assertEquals(SWT.NORMAL, data.getStyle());
426
			}
432
			}
427
		}
433
		}
428
		
434
429
		for (int i = 0; i < folder2.getItemCount(); i++) {
435
		for (int i = 0; i < folder2.getItemCount(); i++) {
430
			CTabItem item = folder2.getItem(i);
436
			CTabItem item = folder2.getItem(i);
431
			FontData data = item.getFont().getFontData()[0];
437
			FontData data = item.getFont().getFontData()[0];
Lines 433-439 Link Here
433
			assertEquals(11, data.getHeight());
439
			assertEquals(11, data.getHeight());
434
			assertEquals(SWT.NORMAL, data.getStyle());
440
			assertEquals(SWT.NORMAL, data.getStyle());
435
		}
441
		}
436
		
442
437
		folder2.setSelection(0);
443
		folder2.setSelection(0);
438
		spinEventLoop();
444
		spinEventLoop();
439
445
Lines 482-488 Link Here
482
			CTabItem item = folder2.getItem(i);
488
			CTabItem item = folder2.getItem(i);
483
			assertTrue(item.getShowClose());
489
			assertTrue(item.getShowClose());
484
		}
490
		}
485
		
491
486
		folder2.setSelection(0);
492
		folder2.setSelection(0);
487
		spinEventLoop();
493
		spinEventLoop();
488
494
Lines 497-506 Link Here
497
		CTabFolder folder2 = createFolder(folder.getShell());
503
		CTabFolder folder2 = createFolder(folder.getShell());
498
504
499
		SWTElement.setCSSClass(folder2, "viewStack");
505
		SWTElement.setCSSClass(folder2, "viewStack");
500
		engine = createEngine("CTabItem { show-close: false }"
506
		engine = createEngine(
501
				+ "CTabItem:selected { show-close: true }"
507
				"CTabItem { show-close: false }"
502
				+ "CTabFolder.viewStack CTabItem { show-close: false }"
508
						+ "CTabItem:selected { show-close: true }"
503
				+ "CTabFolder.viewStack CTabItem.selected { show-close: true }",
509
						+ "CTabFolder.viewStack CTabItem { show-close: false }"
510
						+ "CTabFolder.viewStack CTabItem.selected { show-close: true }",
504
				folder.getDisplay());
511
				folder.getDisplay());
505
		engine.applyStyles(folder.getShell(), true);
512
		engine.applyStyles(folder.getShell(), true);
506
513
Lines 525-531 Link Here
525
			CTabItem item = folder2.getItem(i);
532
			CTabItem item = folder2.getItem(i);
526
			assertFalse(item.getShowClose());
533
			assertFalse(item.getShowClose());
527
		}
534
		}
528
		
535
529
		folder2.setSelection(0);
536
		folder2.setSelection(0);
530
		spinEventLoop();
537
		spinEventLoop();
531
538
Lines 538-541 Link Here
538
			}
545
			}
539
		}
546
		}
540
	}
547
	}
548
549
	public void testBackground() throws Exception {
550
		CTabFolder folder = createTestTabFolder(
551
				"CTabItem { background-color: #0000ff }", false);
552
		assertEquals(new RGB(0, 0, 255), folder.getBackground().getRGB());
553
554
		for (int i = 0; i < folder.getItemCount(); i++) {
555
			assertEquals("#0000ff", engine.retrieveCSSProperty(folder
556
					.getItem(i), "background-color", null));
557
		}
558
	}
559
560
	public void testBackground2() throws Exception {
561
		CTabFolder folder = createTestTabFolder(false);
562
		Color preStyledSelectionBackground = folder.getSelectionBackground();
563
564
		RGB rgb = new RGB(0, 0, 255);
565
		String colour = "#0000ff";
566
567
		// we want to make sure we pick a unique colour so that we actually test that the selection's colour has not changed
568
		if (rgb.equals(preStyledSelectionBackground.getRGB())) {
569
			rgb = new RGB(0, 255, 0);
570
			colour = "#00ff00";
571
		}
572
573
		CSSEngine engine = createEngine("CTabItem { background-color: " + colour + " }",
574
				folder.getDisplay());
575
		engine.applyStyles(folder, true);
576
577
		assertEquals(rgb, folder.getBackground().getRGB());
578
579
		for (int i = 0; i < folder.getItemCount(); i++) {
580
			assertEquals(colour, engine.retrieveCSSProperty(folder.getItem(i),
581
					"background-color", null));
582
		}
583
584
		assertEquals(preStyledSelectionBackground.getRGB(), folder
585
				.getSelectionBackground().getRGB());
586
	}
587
588
	public void testSelectionBackground() throws Exception {
589
		CTabFolder folder = createTestTabFolder(
590
				"CTabItem:selected { background-color: #00ff00 }", false);
591
		assertEquals(new RGB(0, 255, 0), folder.getSelectionBackground()
592
				.getRGB());
593
594
		for (int i = 0; i < folder.getItemCount(); i++) {
595
			assertEquals("#00ff00", engine.retrieveCSSProperty(folder
596
					.getItem(i), "background-color", "selected"));
597
		}
598
	}
599
600
	public void testForeground() throws Exception {
601
		CTabFolder folder = createTestTabFolder("CTabItem { color: #0000ff }",
602
				false);
603
		assertEquals(new RGB(0, 0, 255), folder.getForeground().getRGB());
604
605
		for (int i = 0; i < folder.getItemCount(); i++) {
606
			assertEquals("#0000ff", engine.retrieveCSSProperty(folder
607
					.getItem(i), "color", null));
608
		}
609
	}
610
611
	public void testForeground2() throws Exception {
612
		CTabFolder folder = createTestTabFolder(false);
613
		Color preStyledSelectionForeground = folder.getSelectionForeground();
614
615
		RGB rgb = new RGB(0, 0, 255);
616
		String colour = "#0000ff";
617
618
		// we want to make sure we pick a unique colour so that we actually test that the selection's colour has not changed
619
		if (rgb.equals(preStyledSelectionForeground.getRGB())) {
620
			rgb = new RGB(0, 255, 0);
621
			colour = "#00ff00";
622
		}
623
624
		CSSEngine engine = createEngine("CTabItem { color: " + colour + " }",
625
				folder.getDisplay());
626
		engine.applyStyles(folder, true);
627
628
		assertEquals(rgb, folder.getForeground().getRGB());
629
630
		for (int i = 0; i < folder.getItemCount(); i++) {
631
			assertEquals(colour, engine.retrieveCSSProperty(folder.getItem(i),
632
					"color", null));
633
		}
634
635
		assertEquals(preStyledSelectionForeground.getRGB(), folder
636
				.getSelectionForeground().getRGB());
637
	}
638
639
	public void testSelectionForeground() throws Exception {
640
		CTabFolder folder = createTestTabFolder(
641
				"CTabItem:selected { color: #00ff00 }", false);
642
		assertEquals(new RGB(0, 255, 0), folder.getSelectionForeground()
643
				.getRGB());
644
645
		for (int i = 0; i < folder.getItemCount(); i++) {
646
			assertEquals("#00ff00", engine.retrieveCSSProperty(folder
647
					.getItem(i), "color", "selected"));
648
		}
649
	}
541
}
650
}
(-)src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyTextSWTHandler.java (-15 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 Angelo Zerr and others.
2
 * Copyright (c) 2008, 2009 Angelo Zerr and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
import org.eclipse.e4.ui.css.swt.CSSSWTConstants;
16
import org.eclipse.e4.ui.css.swt.CSSSWTConstants;
17
import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
17
import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
18
import org.eclipse.swt.custom.CTabFolder;
18
import org.eclipse.swt.custom.CTabFolder;
19
import org.eclipse.swt.custom.CTabItem;
19
import org.eclipse.swt.events.VerifyEvent;
20
import org.eclipse.swt.events.VerifyEvent;
20
import org.eclipse.swt.events.VerifyListener;
21
import org.eclipse.swt.events.VerifyListener;
21
import org.eclipse.swt.graphics.Color;
22
import org.eclipse.swt.graphics.Color;
Lines 23-28 Link Here
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Text;
26
import org.eclipse.swt.widgets.Text;
27
import org.eclipse.swt.widgets.Widget;
26
import org.w3c.dom.css.CSSValue;
28
import org.w3c.dom.css.CSSValue;
27
29
28
public class CSSPropertyTextSWTHandler extends AbstractCSSPropertyTextHandler {
30
public class CSSPropertyTextSWTHandler extends AbstractCSSPropertyTextHandler {
Lines 31-39 Link Here
31
33
32
	public boolean applyCSSProperty(Object element, String property,
34
	public boolean applyCSSProperty(Object element, String property,
33
			CSSValue value, String pseudo, CSSEngine engine) throws Exception {
35
			CSSValue value, String pseudo, CSSEngine engine) throws Exception {
34
		Control control = SWTElementHelpers.getControl(element);
36
		Widget widget = SWTElementHelpers.getWidget(element);
35
		if (control != null) {
37
		if (widget != null) {
36
			super.applyCSSProperty(control, property, value, pseudo, engine);
38
			super.applyCSSProperty(widget, property, value, pseudo, engine);
37
			return true;
39
			return true;
38
		}
40
		}
39
		return false;
41
		return false;
Lines 42-64 Link Here
42
44
43
	public String retrieveCSSProperty(Object element, String property,
45
	public String retrieveCSSProperty(Object element, String property,
44
			String pseudo, CSSEngine engine) throws Exception {
46
			String pseudo, CSSEngine engine) throws Exception {
45
		Control control = SWTElementHelpers.getControl(element);
47
		Widget widget = SWTElementHelpers.getWidget(element);
46
		if (control != null) {
48
		if (widget != null) {
47
			return super.retrieveCSSProperty(control, property, pseudo, engine);
49
			return super.retrieveCSSProperty(widget, property, pseudo, engine);
48
		}
50
		}
49
		return null;
51
		return null;
50
	}
52
	}
51
53
52
	public void applyCSSPropertyColor(Object element, CSSValue value,
54
	public void applyCSSPropertyColor(Object element, CSSValue value,
53
			String pseudo, CSSEngine engine) throws Exception {
55
			String pseudo, CSSEngine engine) throws Exception {
54
		Control control = (Control) element;
56
		Widget widget = (Widget) element;
55
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
57
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
56
			Color newColor = (Color) engine.convert(value, Color.class, control
58
			Color newColor = (Color) engine.convert(value, Color.class, widget
57
					.getDisplay());
59
					.getDisplay());
58
			if (control instanceof CTabFolder && "selected".equals(pseudo)) {
60
			if (widget instanceof CTabItem) {
59
				((CTabFolder) control).setSelectionForeground(newColor);
61
				CTabFolder folder = ((CTabItem) widget).getParent();
60
			} else {
62
				if ("selected".equals(pseudo)) {
61
				control.setForeground(newColor);
63
					folder.setSelectionForeground(newColor);
64
				} else {
65
					folder.setForeground(newColor);
66
				}
67
			} else if (widget instanceof Control) {
68
				((Control) widget).setForeground(newColor);
62
			}
69
			}
63
		}
70
		}
64
	}
71
	}
Lines 116-123 Link Here
116
123
117
	public String retrieveCSSPropertyColor(Object element, String pseudo,
124
	public String retrieveCSSPropertyColor(Object element, String pseudo,
118
			CSSEngine engine) throws Exception {
125
			CSSEngine engine) throws Exception {
119
		Control control = (Control) element;
126
		Widget widget = (Widget) element;
120
		Color color = control.getForeground();
127
		Color color = null;
128
		if (widget instanceof CTabItem) {
129
			if ("selected".equals(pseudo)) {
130
				color = ((CTabItem) widget).getParent().getSelectionForeground();	
131
			} else {
132
				color = ((CTabItem) widget).getParent().getForeground();
133
			}
134
		} else if (widget instanceof Control) {
135
			color = ((Control) widget).getForeground();	
136
		}
121
		return engine.convert(color, Color.class, null);
137
		return engine.convert(color, Color.class, null);
122
	}
138
	}
123
139
(-)src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java (-21 / +38 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 Angelo Zerr and others.
2
 * Copyright (c) 2008, 2009 Angelo Zerr and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 19-28 Link Here
19
import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
19
import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
20
import org.eclipse.e4.ui.css.swt.properties.GradientBackgroundListener;
20
import org.eclipse.e4.ui.css.swt.properties.GradientBackgroundListener;
21
import org.eclipse.swt.custom.CTabFolder;
21
import org.eclipse.swt.custom.CTabFolder;
22
import org.eclipse.swt.custom.CTabItem;
22
import org.eclipse.swt.graphics.Color;
23
import org.eclipse.swt.graphics.Color;
23
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Widget;
26
import org.w3c.dom.css.CSSValue;
28
import org.w3c.dom.css.CSSValue;
27
29
28
public class CSSPropertyBackgroundSWTHandler extends
30
public class CSSPropertyBackgroundSWTHandler extends
Lines 32-40 Link Here
32
34
33
	public boolean applyCSSProperty(Object element, String property,
35
	public boolean applyCSSProperty(Object element, String property,
34
			CSSValue value, String pseudo, CSSEngine engine) throws Exception {
36
			CSSValue value, String pseudo, CSSEngine engine) throws Exception {
35
		Control control = SWTElementHelpers.getControl(element);
37
		Widget widget = SWTElementHelpers.getWidget(element);
36
		if (control != null) {
38
		if (widget != null) {
37
			super.applyCSSProperty(control, property, value, pseudo, engine);
39
			super.applyCSSProperty(widget, property, value, pseudo, engine);
38
			return true;
40
			return true;
39
		}
41
		}
40
		return false;
42
		return false;
Lines 43-51 Link Here
43
45
44
	public String retrieveCSSProperty(Object element, String property,
46
	public String retrieveCSSProperty(Object element, String property,
45
			String pseudo, CSSEngine engine) throws Exception {
47
			String pseudo, CSSEngine engine) throws Exception {
46
		Control control = SWTElementHelpers.getControl(element);
48
		Widget widget = SWTElementHelpers.getWidget(element);
47
		if (control != null) {
49
		if (widget != null) {
48
			return super.retrieveCSSProperty(control, property, pseudo, engine);
50
			return super.retrieveCSSProperty(widget, property, pseudo, engine);
49
		}
51
		}
50
		return null;
52
		return null;
51
	}
53
	}
Lines 59-83 Link Here
59
	 */
61
	 */
60
	public void applyCSSPropertyBackgroundColor(Object element, CSSValue value,
62
	public void applyCSSPropertyBackgroundColor(Object element, CSSValue value,
61
			String pseudo, CSSEngine engine) throws Exception {
63
			String pseudo, CSSEngine engine) throws Exception {
62
		Control control = (Control) element;
64
		Widget widget = (Widget) element;
63
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
65
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
64
			Color newColor = (Color) engine.convert(value, Color.class, control
66
			Color newColor = (Color) engine.convert(value, Color.class, widget
65
					.getDisplay());
67
					.getDisplay());
66
			if (control instanceof CTabFolder && "selected".equals(pseudo)) {
68
			if (widget instanceof CTabItem) {
67
				((CTabFolder) control).setSelectionBackground(newColor);
69
				CTabFolder folder = ((CTabItem) widget).getParent();
68
			} else {
70
				if ("selected".equals(pseudo)) {
69
				control.setBackground(newColor);
71
					folder.setSelectionBackground(newColor);
72
				} else {
73
					folder.setBackground(newColor);
74
				}
75
			} else if (widget instanceof Control) {
76
				((Control) widget).setBackground(newColor);
70
			}
77
			}
71
		} else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
78
		} else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
72
			Gradient grad = (Gradient) engine.convert(value, Gradient.class,
79
			Gradient grad = (Gradient) engine.convert(value, Gradient.class,
73
					control.getDisplay());
80
					widget.getDisplay());
74
			if (control instanceof CTabFolder && "selected".equals(pseudo)) {
81
			if (widget instanceof CTabItem && "selected".equals(pseudo)) {
75
					((CTabFolder) control).setSelectionBackground(
82
				CTabFolder folder = ((CTabItem) widget).getParent();
76
							CSSSWTColorHelper.getSWTColors(grad, control.getDisplay()),
83
					folder.setSelectionBackground(
84
							CSSSWTColorHelper.getSWTColors(grad, folder.getDisplay()),
77
							CSSSWTColorHelper.getPercents(grad),
85
							CSSSWTColorHelper.getPercents(grad),
78
							true);
86
							true);
79
			} else {
87
			} else if (widget instanceof Control) {
80
				GradientBackgroundListener.handle(control, grad);
88
				GradientBackgroundListener.handle((Control) widget, grad);
81
			}
89
			}
82
		}
90
		}
83
	}
91
	}
Lines 121-128 Link Here
121
129
122
	public String retrieveCSSPropertyBackgroundColor(Object element,
130
	public String retrieveCSSPropertyBackgroundColor(Object element,
123
			String pseudo, CSSEngine engine) throws Exception {
131
			String pseudo, CSSEngine engine) throws Exception {
124
		Control control = (Control) element;
132
		Widget widget = (Widget) element;
125
		Color color = control.getBackground();
133
		Color color = null;
134
		if (widget instanceof CTabItem) {
135
			if ("selected".equals(pseudo)) {
136
				color = ((CTabItem) widget).getParent().getSelectionBackground();	
137
			} else {
138
				color = ((CTabItem) widget).getParent().getBackground();				
139
			}
140
		} else if (widget instanceof Control) {
141
			color = ((Control) widget).getBackground();	
142
		}
126
		return engine.convert(color, Color.class, null);
143
		return engine.convert(color, Color.class, null);
127
	}
144
	}
128
145
(-)src/org/eclipse/e4/ui/css/core/impl/engine/AbstractCSSEngine.java (-7 / +37 lines)
Lines 21-30 Link Here
21
import java.util.List;
21
import java.util.List;
22
import java.util.Map;
22
import java.util.Map;
23
23
24
import org.eclipse.e4.ui.css.core.util.impl.resources.ResourcesLocatorManager;
25
import org.eclipse.e4.ui.css.core.util.resources.IResourcesLocatorManager;
26
import org.eclipse.e4.ui.css.core.utils.StringUtils;
27
import org.eclipse.e4.ui.css.core.dom.CSSStylableElement;
24
import org.eclipse.e4.ui.css.core.dom.CSSStylableElement;
25
import org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule;
28
import org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS;
26
import org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS;
29
import org.eclipse.e4.ui.css.core.dom.IElementProvider;
27
import org.eclipse.e4.ui.css.core.dom.IElementProvider;
30
import org.eclipse.e4.ui.css.core.dom.parsers.CSSParser;
28
import org.eclipse.e4.ui.css.core.dom.parsers.CSSParser;
Lines 44-56 Link Here
44
import org.eclipse.e4.ui.css.core.impl.sac.ExtendedSelector;
42
import org.eclipse.e4.ui.css.core.impl.sac.ExtendedSelector;
45
import org.eclipse.e4.ui.css.core.resources.CSSResourcesHelpers;
43
import org.eclipse.e4.ui.css.core.resources.CSSResourcesHelpers;
46
import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry;
44
import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry;
45
import org.eclipse.e4.ui.css.core.util.impl.resources.ResourcesLocatorManager;
46
import org.eclipse.e4.ui.css.core.util.resources.IResourcesLocatorManager;
47
import org.eclipse.e4.ui.css.core.utils.StringUtils;
47
import org.w3c.css.sac.AttributeCondition;
48
import org.w3c.css.sac.AttributeCondition;
48
import org.w3c.css.sac.Condition;
49
import org.w3c.css.sac.Condition;
49
import org.w3c.css.sac.ConditionalSelector;
50
import org.w3c.css.sac.ConditionalSelector;
50
import org.w3c.css.sac.InputSource;
51
import org.w3c.css.sac.InputSource;
51
import org.w3c.css.sac.Selector;
52
import org.w3c.css.sac.Selector;
53
import org.w3c.css.sac.SelectorList;
52
import org.w3c.dom.Element;
54
import org.w3c.dom.Element;
53
import org.w3c.dom.NodeList;
55
import org.w3c.dom.NodeList;
56
import org.w3c.dom.css.CSSRule;
54
import org.w3c.dom.css.CSSStyleDeclaration;
57
import org.w3c.dom.css.CSSStyleDeclaration;
55
import org.w3c.dom.css.CSSStyleSheet;
58
import org.w3c.dom.css.CSSStyleSheet;
56
import org.w3c.dom.css.CSSValue;
59
import org.w3c.dom.css.CSSValue;
Lines 166-172 Link Here
166
		CSSParser parser = makeCSSParser();
169
		CSSParser parser = makeCSSParser();
167
		CSSStyleSheet styleSheet = parser.parseStyleSheet(source);
170
		CSSStyleSheet styleSheet = parser.parseStyleSheet(source);
168
		if (documentCSS instanceof ExtendedDocumentCSS) {
171
		if (documentCSS instanceof ExtendedDocumentCSS) {
169
			((ExtendedDocumentCSS) documentCSS).addStyleSheet(styleSheet);
172
			(documentCSS).addStyleSheet(styleSheet);
170
		}
173
		}
171
		return styleSheet;
174
		return styleSheet;
172
	}
175
	}
Lines 338-346 Link Here
338
						applyDefaultStyleDeclaration(element, false,
341
						applyDefaultStyleDeclaration(element, false,
339
								styleWithPseudoInstance, pseudoInstance);
342
								styleWithPseudoInstance, pseudoInstance);
340
					}
343
					}
344
					
341
					if (styleWithPseudoInstance != null) {
345
					if (styleWithPseudoInstance != null) {
342
						applyStyleDeclaration(element, styleWithPseudoInstance,
346
						CSSRule parentRule = styleWithPseudoInstance.getParentRule();
343
								pseudoInstance);
347
						if (parentRule instanceof ExtendedCSSRule) {
348
							applyConditionalPseudoStyle((ExtendedCSSRule) parentRule, pseudoInstance, element, styleWithPseudoInstance);
349
						} else {
350
							applyStyleDeclaration(element, styleWithPseudoInstance,
351
									pseudoInstance);							
352
						}
344
					}
353
					}
345
				}
354
				}
346
			}
355
			}
Lines 370-375 Link Here
370
		}
379
		}
371
380
372
	}
381
	}
382
	
383
	private void applyConditionalPseudoStyle(ExtendedCSSRule parentRule, String pseudoInstance, Object element, CSSStyleDeclaration styleWithPseudoInstance) {
384
		SelectorList selectorList = parentRule.getSelectorList();
385
		for (int j = 0; j < selectorList.getLength(); j++) {
386
			Selector item = selectorList.item(j);
387
			// search for conditional selectors
388
			if (item instanceof ConditionalSelector) {
389
				Condition condition = ((ConditionalSelector) item).getCondition();
390
				// we're only interested in attribute selector conditions
391
				if (condition instanceof AttributeCondition) {
392
					String value = ((AttributeCondition) condition).getValue();
393
					if (value.equals(pseudoInstance)) {
394
						// if we match the pseudo, apply the style
395
						applyStyleDeclaration(element, styleWithPseudoInstance,
396
								pseudoInstance);
397
						return;
398
					}										
399
				}
400
			}
401
		}
402
	}
373
403
374
	protected String[] getStaticPseudoInstances(Element element) {
404
	protected String[] getStaticPseudoInstances(Element element) {
375
		if (element instanceof CSSStylableElement) {
405
		if (element instanceof CSSStylableElement) {
Lines 878-884 Link Here
878
908
879
	public void reset() {
909
	public void reset() {
880
		// Remove All Style Sheets
910
		// Remove All Style Sheets
881
		((ExtendedDocumentCSS) documentCSS).removeAllStyleSheets();
911
		(documentCSS).removeAllStyleSheets();
882
		if (elementsWithDynamicPseudoClasses != null) {
912
		if (elementsWithDynamicPseudoClasses != null) {
883
			Collection elements = elementsWithDynamicPseudoClasses.values();
913
			Collection elements = elementsWithDynamicPseudoClasses.values();
884
			for (Iterator iterator = elements.iterator(); iterator.hasNext();) {
914
			for (Iterator iterator = elements.iterator(); iterator.hasNext();) {

Return to bug 282575