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

Side by Side Diff: experimental/svg/model/SkSVGValue.h

Issue 2222793002: [SVGDom] Add <svg> viewBox support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: typo Created 4 years, 4 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 | « experimental/svg/model/SkSVGTypes.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 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkSVGValue_DEFINED 8 #ifndef SkSVGValue_DEFINED
9 #define SkSVGValue_DEFINED 9 #define SkSVGValue_DEFINED
10 10
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkMatrix.h" 12 #include "SkMatrix.h"
13 #include "SkPath.h" 13 #include "SkPath.h"
14 #include "SkSVGTypes.h" 14 #include "SkSVGTypes.h"
15 #include "SkTypes.h" 15 #include "SkTypes.h"
16 16
17 class SkSVGValue : public SkNoncopyable { 17 class SkSVGValue : public SkNoncopyable {
18 public: 18 public:
19 enum class Type { 19 enum class Type {
20 kColor, 20 kColor,
21 kLength, 21 kLength,
22 kPath, 22 kPath,
23 kTransform, 23 kTransform,
24 kViewBox,
24 }; 25 };
25 26
26 Type type() const { return fType; } 27 Type type() const { return fType; }
27 28
28 template <typename T> 29 template <typename T>
29 const T* as() const { 30 const T* as() const {
30 return fType == T::TYPE ? static_cast<const T*>(this) : nullptr; 31 return fType == T::TYPE ? static_cast<const T*>(this) : nullptr;
31 } 32 }
32 33
33 protected: 34 protected:
34 SkSVGValue(Type t) : fType(t) { } 35 SkSVGValue(Type t) : fType(t) { }
35 36
36 private: 37 private:
37 Type fType; 38 Type fType;
38 39
39 typedef SkNoncopyable INHERITED; 40 typedef SkNoncopyable INHERITED;
40 }; 41 };
41 42
42 template <typename SkiaType, SkSVGValue::Type ValueType> 43 template <typename T, SkSVGValue::Type ValueType>
43 class SkSVGWrapperValue final : public SkSVGValue { 44 class SkSVGWrapperValue final : public SkSVGValue {
44 public: 45 public:
45 static constexpr Type TYPE = ValueType; 46 static constexpr Type TYPE = ValueType;
46 47
47 explicit SkSVGWrapperValue(const SkiaType& v) 48 explicit SkSVGWrapperValue(const T& v)
48 : INHERITED(ValueType) 49 : INHERITED(ValueType)
49 , fWrappedValue(v) { } 50 , fWrappedValue(v) { }
50 51
51 operator const SkiaType&() const { return fWrappedValue; } 52 operator const T&() const { return fWrappedValue; }
52 53
53 private: 54 private:
54 SkiaType fWrappedValue; 55 // Stack-only
56 void* operator new(size_t) = delete;
57 void* operator new(size_t, void*) = delete;
58
59 const T& fWrappedValue;
55 60
56 typedef SkSVGValue INHERITED; 61 typedef SkSVGValue INHERITED;
57 }; 62 };
58 63
59 using SkSVGColorValue = SkSVGWrapperValue<SkSVGColor , SkSVGValue::Type::kCo lor >; 64 using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type ::kColor >;
60 using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength, SkSVGValue::Type::kLe ngth >; 65 using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength , SkSVGValue::Type ::kLength >;
61 using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type::kPa th >; 66 using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type ::kPath >;
62 using SkSVGTransformValue = SkSVGWrapperValue<SkMatrix , SkSVGValue::Type::kTr ansform>; 67 using SkSVGTransformValue = SkSVGWrapperValue<SkMatrix , SkSVGValue::Type ::kTransform>;
68 using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType, SkSVGValue::Type ::kViewBox >;
63 69
64 #endif // SkSVGValue_DEFINED 70 #endif // SkSVGValue_DEFINED
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698