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

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

Issue 2661323002: Implement CSSPaintValue and add a layout test. (Closed)
Patch Set: rebase 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"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 m_paint(scriptState->isolate(), paint), 59 m_paint(scriptState->isolate(), paint),
60 m_didCallConstructor(false), 60 m_didCallConstructor(false),
61 m_hasAlpha(hasAlpha) { 61 m_hasAlpha(hasAlpha) {
62 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); 62 m_nativeInvalidationProperties.swap(nativeInvalidationProperties);
63 m_customInvalidationProperties.swap(customInvalidationProperties); 63 m_customInvalidationProperties.swap(customInvalidationProperties);
64 m_inputArgumentTypes.swap(inputArgumentTypes); 64 m_inputArgumentTypes.swap(inputArgumentTypes);
65 } 65 }
66 66
67 CSSPaintDefinition::~CSSPaintDefinition() {} 67 CSSPaintDefinition::~CSSPaintDefinition() {}
68 68
69 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, 69 PassRefPtr<Image> CSSPaintDefinition::paint(
70 const IntSize& size, 70 const LayoutObject& layoutObject,
71 float zoom) { 71 const IntSize& size,
72 float zoom,
73 const CSSStyleValueVector* paintArguments) {
74 DCHECK(paintArguments);
75
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
99 v8::Local<v8::Value> argv[] = { 103 v8::Local<v8::Value> argv[] = {
ikilpatrick 2017/02/21 17:40:36 you'll probably need to surround this with "if (R
renjieliu1 2017/02/22 04:47:54 Done.
100 ToV8(renderingContext, m_scriptState->context()->Global(), isolate), 104 ToV8(renderingContext, m_scriptState->context()->Global(), isolate),
101 ToV8(paintSize, m_scriptState->context()->Global(), isolate), 105 ToV8(paintSize, m_scriptState->context()->Global(), isolate),
102 ToV8(styleMap, m_scriptState->context()->Global(), isolate)}; 106 ToV8(styleMap, m_scriptState->context()->Global(), isolate),
107 ToV8(*paintArguments, m_scriptState->context()->Global(), isolate)};
103 108
104 v8::Local<v8::Function> paint = m_paint.newLocal(isolate); 109 v8::Local<v8::Function> paint = m_paint.newLocal(isolate);
105 110
106 v8::TryCatch block(isolate); 111 v8::TryCatch block(isolate);
107 block.SetVerbose(true); 112 block.SetVerbose(true);
108 113
109 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), 114 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(),
110 instance, 3, argv, isolate); 115 instance, 4, argv, isolate);
111 116
112 // The paint function may have produced an error, in which case produce an 117 // The paint function may have produced an error, in which case produce an
113 // invalid image. 118 // invalid image.
114 if (block.HasCaught()) { 119 if (block.HasCaught()) {
115 return nullptr; 120 return nullptr;
116 } 121 }
117 122
118 return PaintGeneratedImage::create( 123 return PaintGeneratedImage::create(
119 renderingContext->imageBuffer()->getRecord(), specifiedSize); 124 renderingContext->imageBuffer()->getRecord(), specifiedSize);
120 } 125 }
(...skipping 11 matching lines...) Expand all
132 v8::Local<v8::Object> paintInstance; 137 v8::Local<v8::Object> paintInstance;
133 if (V8ObjectConstructor::newInstance(isolate, constructor) 138 if (V8ObjectConstructor::newInstance(isolate, constructor)
134 .ToLocal(&paintInstance)) { 139 .ToLocal(&paintInstance)) {
135 m_instance.set(isolate, paintInstance); 140 m_instance.set(isolate, paintInstance);
136 } 141 }
137 142
138 m_didCallConstructor = true; 143 m_didCallConstructor = true;
139 } 144 }
140 145
141 } // namespace blink 146 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698