OLD | NEW |
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" |
| 12 #include "core/css/cssom/FilteredComputedStylePropertyMap.h" |
11 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/layout/LayoutObject.h" |
12 #include "modules/csspaint/Geometry.h" | 15 #include "modules/csspaint/Geometry.h" |
13 #include "modules/csspaint/PaintRenderingContext2D.h" | 16 #include "modules/csspaint/PaintRenderingContext2D.h" |
14 #include "platform/graphics/ImageBuffer.h" | 17 #include "platform/graphics/ImageBuffer.h" |
15 #include "platform/graphics/PaintGeneratedImage.h" | 18 #include "platform/graphics/PaintGeneratedImage.h" |
16 #include "platform/graphics/RecordingImageBufferSurface.h" | 19 #include "platform/graphics/RecordingImageBufferSurface.h" |
17 | 20 |
18 namespace blink { | 21 namespace blink { |
19 | 22 |
20 CSSPaintDefinition* CSSPaintDefinition::create(ScriptState* scriptState, v8::Loc
al<v8::Function> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyI
D>& nativeInvalidationProperties, Vector<AtomicString>& customInvalidationProper
ties) | 23 CSSPaintDefinition* CSSPaintDefinition::create(ScriptState* scriptState, v8::Loc
al<v8::Function> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyI
D>& nativeInvalidationProperties, Vector<AtomicString>& customInvalidationProper
ties) |
21 { | 24 { |
22 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid
ationProperties, customInvalidationProperties); | 25 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid
ationProperties, customInvalidationProperties); |
23 } | 26 } |
24 | 27 |
25 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F
unction> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyID>& nati
veInvalidationProperties, Vector<AtomicString>& customInvalidationProperties) | 28 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F
unction> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyID>& nati
veInvalidationProperties, Vector<AtomicString>& customInvalidationProperties) |
26 : m_scriptState(scriptState) | 29 : m_scriptState(scriptState) |
27 , m_constructor(scriptState->isolate(), constructor) | 30 , m_constructor(scriptState->isolate(), constructor) |
28 , m_paint(scriptState->isolate(), paint) | 31 , m_paint(scriptState->isolate(), paint) |
29 { | 32 { |
30 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); | 33 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); |
31 m_customInvalidationProperties.swap(customInvalidationProperties); | 34 m_customInvalidationProperties.swap(customInvalidationProperties); |
32 } | 35 } |
33 | 36 |
34 CSSPaintDefinition::~CSSPaintDefinition() | 37 CSSPaintDefinition::~CSSPaintDefinition() |
35 { | 38 { |
36 } | 39 } |
37 | 40 |
38 PassRefPtr<Image> CSSPaintDefinition::paint(const IntSize& size) | 41 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, co
nst IntSize& size) |
39 { | 42 { |
40 ScriptState::Scope scope(m_scriptState.get()); | 43 ScriptState::Scope scope(m_scriptState.get()); |
41 | 44 |
42 maybeCreatePaintInstance(); | 45 maybeCreatePaintInstance(); |
43 | 46 |
44 v8::Isolate* isolate = m_scriptState->isolate(); | 47 v8::Isolate* isolate = m_scriptState->isolate(); |
45 v8::Local<v8::Object> instance = m_instance.newLocal(isolate); | 48 v8::Local<v8::Object> instance = m_instance.newLocal(isolate); |
46 | 49 |
47 // We may have failed to create an instance class, in which case produce an | 50 // We may have failed to create an instance class, in which case produce an |
48 // invalid image. | 51 // invalid image. |
49 if (isUndefinedOrNull(instance)) | 52 if (isUndefinedOrNull(instance)) |
50 return nullptr; | 53 return nullptr; |
51 | 54 |
| 55 DCHECK(layoutObject.node()); |
| 56 |
52 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create( | 57 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create( |
53 ImageBuffer::create(adoptPtr(new RecordingImageBufferSurface(size)))); | 58 ImageBuffer::create(adoptPtr(new RecordingImageBufferSurface(size)))); |
54 Geometry* geometry = Geometry::create(size); | 59 Geometry* geometry = Geometry::create(size); |
| 60 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create( |
| 61 CSSComputedStyleDeclaration::create(layoutObject.node()), |
| 62 m_nativeInvalidationProperties, m_customInvalidationProperties); |
55 | 63 |
56 v8::Local<v8::Value> argv[] = { | 64 v8::Local<v8::Value> argv[] = { |
57 toV8(renderingContext, m_scriptState->context()->Global(), isolate), | 65 toV8(renderingContext, m_scriptState->context()->Global(), isolate), |
58 toV8(geometry, m_scriptState->context()->Global(), isolate) | 66 toV8(geometry, m_scriptState->context()->Global(), isolate), |
| 67 toV8(styleMap, m_scriptState->context()->Global(), isolate) |
59 }; | 68 }; |
60 | 69 |
61 v8::Local<v8::Function> paint = m_paint.newLocal(isolate); | 70 v8::Local<v8::Function> paint = m_paint.newLocal(isolate); |
62 | 71 |
63 v8::TryCatch block(isolate); | 72 v8::TryCatch block(isolate); |
64 block.SetVerbose(true); | 73 block.SetVerbose(true); |
65 | 74 |
66 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), in
stance, 2, argv, isolate); | 75 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), in
stance, 3, argv, isolate); |
67 | 76 |
68 // The paint function may have produced an error, in which case produce an | 77 // The paint function may have produced an error, in which case produce an |
69 // invalid image. | 78 // invalid image. |
70 if (block.HasCaught()) { | 79 if (block.HasCaught()) { |
71 return nullptr; | 80 return nullptr; |
72 } | 81 } |
73 | 82 |
74 return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPictu
re(), size); | 83 return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPictu
re(), size); |
75 } | 84 } |
76 | 85 |
(...skipping 10 matching lines...) Expand all Loading... |
87 | 96 |
88 v8::Local<v8::Object> paintInstance; | 97 v8::Local<v8::Object> paintInstance; |
89 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns
tance)) { | 98 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns
tance)) { |
90 m_instance.set(isolate, paintInstance); | 99 m_instance.set(isolate, paintInstance); |
91 } | 100 } |
92 | 101 |
93 m_didCallConstructor = true; | 102 m_didCallConstructor = true; |
94 } | 103 } |
95 | 104 |
96 } // namespace blink | 105 } // namespace blink |
OLD | NEW |