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

Side by Side Diff: third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp

Issue 2661323002: Implement CSSPaintValue and add a layout test. (Closed)
Patch Set: fix indent Created 3 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/csspaint/CSSPaintDefinition.h" 5 #include "modules/csspaint/CSSPaintDefinition.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8BindingMacros.h" 9 #include "bindings/core/v8/V8BindingMacros.h"
10 #include "bindings/core/v8/V8ObjectConstructor.h" 10 #include "bindings/core/v8/V8ObjectConstructor.h"
11 #include "core/css/CSSComputedStyleDeclaration.h" 11 #include "core/css/CSSComputedStyleDeclaration.h"
12 #include "core/css/CSSVariableData.h"
12 #include "core/css/cssom/FilteredComputedStylePropertyMap.h" 13 #include "core/css/cssom/FilteredComputedStylePropertyMap.h"
14 #include "core/css/cssom/StyleValueFactory.h"
13 #include "core/dom/ExecutionContext.h" 15 #include "core/dom/ExecutionContext.h"
14 #include "core/layout/LayoutObject.h" 16 #include "core/layout/LayoutObject.h"
15 #include "modules/csspaint/PaintRenderingContext2D.h" 17 #include "modules/csspaint/PaintRenderingContext2D.h"
16 #include "modules/csspaint/PaintSize.h" 18 #include "modules/csspaint/PaintSize.h"
17 #include "platform/graphics/ImageBuffer.h" 19 #include "platform/graphics/ImageBuffer.h"
18 #include "platform/graphics/PaintGeneratedImage.h" 20 #include "platform/graphics/PaintGeneratedImage.h"
19 #include "platform/graphics/RecordingImageBufferSurface.h" 21 #include "platform/graphics/RecordingImageBufferSurface.h"
20 #include "wtf/PtrUtil.h" 22 #include "wtf/PtrUtil.h"
21 23
22 namespace blink { 24 namespace blink {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 m_paint(scriptState->isolate(), paint), 61 m_paint(scriptState->isolate(), paint),
60 m_didCallConstructor(false), 62 m_didCallConstructor(false),
61 m_hasAlpha(hasAlpha) { 63 m_hasAlpha(hasAlpha) {
62 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); 64 m_nativeInvalidationProperties.swap(nativeInvalidationProperties);
63 m_customInvalidationProperties.swap(customInvalidationProperties); 65 m_customInvalidationProperties.swap(customInvalidationProperties);
64 m_inputArgumentTypes.swap(inputArgumentTypes); 66 m_inputArgumentTypes.swap(inputArgumentTypes);
65 } 67 }
66 68
67 CSSPaintDefinition::~CSSPaintDefinition() {} 69 CSSPaintDefinition::~CSSPaintDefinition() {}
68 70
69 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, 71 PassRefPtr<Image> CSSPaintDefinition::paint(
70 const IntSize& size, 72 const LayoutObject& layoutObject,
71 float zoom) { 73 const IntSize& size,
74 float zoom,
75 const Vector<RefPtr<CSSVariableData>>& variableData) {
72 const IntSize specifiedSize = getSpecifiedSize(size, zoom); 76 const IntSize specifiedSize = getSpecifiedSize(size, zoom);
73 77
74 ScriptState::Scope scope(m_scriptState.get()); 78 ScriptState::Scope scope(m_scriptState.get());
75 79
76 maybeCreatePaintInstance(); 80 maybeCreatePaintInstance();
77 81
78 v8::Isolate* isolate = m_scriptState->isolate(); 82 v8::Isolate* isolate = m_scriptState->isolate();
79 v8::Local<v8::Object> instance = m_instance.newLocal(isolate); 83 v8::Local<v8::Object> instance = m_instance.newLocal(isolate);
80 84
81 // We may have failed to create an instance class, in which case produce an 85 // We may have failed to create an instance class, in which case produce an
82 // invalid image. 86 // invalid image.
83 if (isUndefinedOrNull(instance)) 87 if (isUndefinedOrNull(instance))
84 return nullptr; 88 return nullptr;
85 89
86 DCHECK(layoutObject.node()); 90 DCHECK(layoutObject.node());
87 91
88 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create( 92 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create(
89 ImageBuffer::create(WTF::wrapUnique( 93 ImageBuffer::create(WTF::wrapUnique(
90 new RecordingImageBufferSurface(size, nullptr /* fallbackFactory */, 94 new RecordingImageBufferSurface(size, nullptr /* fallbackFactory */,
91 m_hasAlpha ? NonOpaque : Opaque))), 95 m_hasAlpha ? NonOpaque : Opaque))),
92 m_hasAlpha, zoom); 96 m_hasAlpha, zoom);
93 PaintSize* paintSize = PaintSize::create(specifiedSize); 97 PaintSize* paintSize = PaintSize::create(specifiedSize);
94 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create( 98 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create(
95 CSSComputedStyleDeclaration::create(layoutObject.node()), 99 CSSComputedStyleDeclaration::create(layoutObject.node()),
96 m_nativeInvalidationProperties, m_customInvalidationProperties, 100 m_nativeInvalidationProperties, m_customInvalidationProperties,
97 layoutObject.node()); 101 layoutObject.node());
98 102
103 // Parse arguments.
104 CSSStyleValueVector paintArguments;
105 if (RuntimeEnabledFeatures::cssPaintAPIArgumentsEnabled()) {
106 if (variableData.size() != m_inputArgumentTypes.size()) {
107 return nullptr;
108 }
109 for (size_t i = 0; i < variableData.size(); ++i) {
110 const CSSValue* parsedValue =
111 variableData[i].get()->parseForSyntax(m_inputArgumentTypes[i]);
ikilpatrick 2017/02/16 03:19:36 this feels too late to parse the data? I think you
renjieliu1 2017/02/16 04:11:14 good suggestion! however parse the CSSVariableData
112 if (!parsedValue)
113 return nullptr;
114 paintArguments.appendVector(
115 StyleValueFactory::cssValueToStyleValueVector(*parsedValue));
116 }
117 }
99 v8::Local<v8::Value> argv[] = { 118 v8::Local<v8::Value> argv[] = {
100 ToV8(renderingContext, m_scriptState->context()->Global(), isolate), 119 ToV8(renderingContext, m_scriptState->context()->Global(), isolate),
101 ToV8(paintSize, m_scriptState->context()->Global(), isolate), 120 ToV8(paintSize, m_scriptState->context()->Global(), isolate),
102 ToV8(styleMap, m_scriptState->context()->Global(), isolate)}; 121 ToV8(styleMap, m_scriptState->context()->Global(), isolate),
122 ToV8(paintArguments, m_scriptState->context()->Global(), isolate)};
103 123
104 v8::Local<v8::Function> paint = m_paint.newLocal(isolate); 124 v8::Local<v8::Function> paint = m_paint.newLocal(isolate);
105 125
106 v8::TryCatch block(isolate); 126 v8::TryCatch block(isolate);
107 block.SetVerbose(true); 127 block.SetVerbose(true);
108 128
109 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), 129 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(),
110 instance, 3, argv, isolate); 130 instance, 4, argv, isolate);
111 131
112 // The paint function may have produced an error, in which case produce an 132 // The paint function may have produced an error, in which case produce an
113 // invalid image. 133 // invalid image.
114 if (block.HasCaught()) { 134 if (block.HasCaught()) {
115 return nullptr; 135 return nullptr;
116 } 136 }
117 137
118 return PaintGeneratedImage::create( 138 return PaintGeneratedImage::create(
119 renderingContext->imageBuffer()->getRecord(), specifiedSize); 139 renderingContext->imageBuffer()->getRecord(), specifiedSize);
120 } 140 }
(...skipping 11 matching lines...) Expand all
132 v8::Local<v8::Object> paintInstance; 152 v8::Local<v8::Object> paintInstance;
133 if (V8ObjectConstructor::newInstance(isolate, constructor) 153 if (V8ObjectConstructor::newInstance(isolate, constructor)
134 .ToLocal(&paintInstance)) { 154 .ToLocal(&paintInstance)) {
135 m_instance.set(isolate, paintInstance); 155 m_instance.set(isolate, paintInstance);
136 } 156 }
137 157
138 m_didCallConstructor = true; 158 m_didCallConstructor = true;
139 } 159 }
140 160
141 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698