Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: Source/core/svg/SVGPaint.cpp

Issue 189913012: Merge SVGColor into SVGPaint (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix system color test Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/svg/SVGPaint.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "config.h" 22 #include "config.h"
23 #include "core/svg/SVGPaint.h" 23 #include "core/svg/SVGPaint.h"
24 24
25 #include "bindings/v8/ExceptionMessages.h" 25 #include "bindings/v8/ExceptionMessages.h"
26 #include "bindings/v8/ExceptionState.h" 26 #include "bindings/v8/ExceptionState.h"
27 #include "core/css/RGBColor.h"
28 #include "core/css/parser/BisonCSSParser.h"
27 29
28 namespace WebCore { 30 namespace WebCore {
29 31
30 static inline SVGColor::SVGColorType colorTypeForPaintType(const SVGPaint::SVGPa intType& paintType)
31 {
32 switch (paintType) {
33 case SVGPaint::SVG_PAINTTYPE_NONE:
34 case SVGPaint::SVG_PAINTTYPE_UNKNOWN:
35 case SVGPaint::SVG_PAINTTYPE_URI:
36 case SVGPaint::SVG_PAINTTYPE_URI_NONE:
37 return SVGColor::SVG_COLORTYPE_UNKNOWN;
38 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR:
39 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR:
40 return SVGColor::SVG_COLORTYPE_RGBCOLOR;
41 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
42 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
43 return SVGColor::SVG_COLORTYPE_RGBCOLOR_ICCCOLOR;
44 case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR:
45 case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR:
46 return SVGColor::SVG_COLORTYPE_CURRENTCOLOR;
47 }
48
49 ASSERT_NOT_REACHED();
50 return SVGColor::SVG_COLORTYPE_UNKNOWN;
51 }
52
53 SVGPaint::SVGPaint(const SVGPaintType& paintType, const String& uri) 32 SVGPaint::SVGPaint(const SVGPaintType& paintType, const String& uri)
54 : SVGColor(SVGPaintClass, colorTypeForPaintType(paintType)) 33 : CSSValue(SVGPaintClass)
55 , m_paintType(paintType) 34 , m_paintType(paintType)
56 , m_uri(uri) 35 , m_uri(uri)
57 { 36 {
58 } 37 }
59 38
60 String SVGPaint::customCSSText() const 39 String SVGPaint::customCSSText() const
61 { 40 {
62 switch (m_paintType) { 41 switch (m_paintType) {
63 case SVG_PAINTTYPE_UNKNOWN: 42 case SVG_PAINTTYPE_UNKNOWN:
64 return String(); 43 return String();
65 case SVG_PAINTTYPE_RGBCOLOR: 44 case SVG_PAINTTYPE_RGBCOLOR:
66 case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: 45 case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
46 return m_color.serializedAsCSSComponentValue();
67 case SVG_PAINTTYPE_CURRENTCOLOR: 47 case SVG_PAINTTYPE_CURRENTCOLOR:
68 return SVGColor::customCSSText(); 48 return "currentColor";
69 case SVG_PAINTTYPE_NONE: 49 case SVG_PAINTTYPE_NONE:
70 return "none"; 50 return "none";
71 case SVG_PAINTTYPE_URI_NONE: 51 case SVG_PAINTTYPE_URI_NONE:
72 return m_uri + " none"; 52 return m_uri + " none";
73 case SVG_PAINTTYPE_URI_CURRENTCOLOR: 53 case SVG_PAINTTYPE_URI_CURRENTCOLOR:
54 return "url(" + m_uri + ") currentColor";
74 case SVG_PAINTTYPE_URI_RGBCOLOR: 55 case SVG_PAINTTYPE_URI_RGBCOLOR:
75 case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: { 56 case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: {
76 String color = SVGColor::customCSSText(); 57 return "url(" + m_uri + ") " + m_color.serializedAsCSSComponentValue();
77 if (color.isEmpty())
78 return m_uri;
79 return "url(" + m_uri + ") " + color;
80 } 58 }
81 case SVG_PAINTTYPE_URI: 59 case SVG_PAINTTYPE_URI:
82 return "url(" + m_uri + ')'; 60 return "url(" + m_uri + ')';
83 }; 61 };
84 62
85 ASSERT_NOT_REACHED(); 63 ASSERT_NOT_REACHED();
86 return String(); 64 return String();
87 } 65 }
88 66
89 SVGPaint::SVGPaint(const SVGPaint& cloneFrom) 67 SVGPaint::SVGPaint(const SVGPaint& cloneFrom)
90 : SVGColor(SVGPaintClass, cloneFrom) 68 : CSSValue(SVGPaintClass, /*isCSSOMSafe*/ true)
91 , m_paintType(cloneFrom.m_paintType) 69 , m_paintType(cloneFrom.m_paintType)
70 , m_color(cloneFrom.m_color)
92 , m_uri(cloneFrom.m_uri) 71 , m_uri(cloneFrom.m_uri)
93 { 72 {
94 } 73 }
95 74
96 PassRefPtrWillBeRawPtr<SVGPaint> SVGPaint::cloneForCSSOM() const 75 PassRefPtrWillBeRawPtr<SVGPaint> SVGPaint::cloneForCSSOM() const
97 { 76 {
98 return adoptRefWillBeRefCountedGarbageCollected(new SVGPaint(*this)); 77 return adoptRefWillBeRefCountedGarbageCollected(new SVGPaint(*this));
99 } 78 }
100 79
101 bool SVGPaint::equals(const SVGPaint& other) const 80 bool SVGPaint::equals(const SVGPaint& other) const
102 { 81 {
103 return m_paintType == other.m_paintType && m_uri == other.m_uri && SVGColor: :equals(other); 82 return m_paintType == other.m_paintType && m_uri == other.m_uri && m_color = = other.m_color;
83 }
84
85 StyleColor SVGPaint::colorFromRGBColorString(const String& colorString)
86 {
87 // FIXME: Rework css parser so it is more SVG aware.
88 RGBA32 color;
89 if (BisonCSSParser::parseColor(color, colorString.stripWhiteSpace()))
90 return StyleColor(color);
91 // FIXME: This branch catches the string currentColor, but we should error i f we have an illegal color value.
92 return StyleColor::currentColor();
104 } 93 }
105 94
106 } 95 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGPaint.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698