OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
10 * | 10 * |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "core/dom/ExceptionCode.h" | 45 #include "core/dom/ExceptionCode.h" |
46 #include "core/fetch/ImageResource.h" | 46 #include "core/fetch/ImageResource.h" |
47 #include "core/frame/ImageBitmap.h" | 47 #include "core/frame/ImageBitmap.h" |
48 #include "core/html/HTMLCanvasElement.h" | 48 #include "core/html/HTMLCanvasElement.h" |
49 #include "core/html/HTMLImageElement.h" | 49 #include "core/html/HTMLImageElement.h" |
50 #include "core/html/HTMLMediaElement.h" | 50 #include "core/html/HTMLMediaElement.h" |
51 #include "core/html/HTMLVideoElement.h" | 51 #include "core/html/HTMLVideoElement.h" |
52 #include "core/html/ImageData.h" | 52 #include "core/html/ImageData.h" |
53 #include "core/html/TextMetrics.h" | 53 #include "core/html/TextMetrics.h" |
54 #include "core/html/canvas/CanvasGradient.h" | 54 #include "core/html/canvas/CanvasGradient.h" |
| 55 #include "core/html/canvas/CanvasHitRegion.h" |
55 #include "core/html/canvas/CanvasPattern.h" | 56 #include "core/html/canvas/CanvasPattern.h" |
56 #include "core/html/canvas/CanvasStyle.h" | 57 #include "core/html/canvas/CanvasStyle.h" |
57 #include "core/html/canvas/Path2D.h" | 58 #include "core/html/canvas/Path2D.h" |
58 #include "core/rendering/RenderImage.h" | 59 #include "core/rendering/RenderImage.h" |
59 #include "core/rendering/RenderLayer.h" | 60 #include "core/rendering/RenderLayer.h" |
60 #include "core/rendering/RenderTheme.h" | 61 #include "core/rendering/RenderTheme.h" |
61 #include "platform/fonts/FontCache.h" | 62 #include "platform/fonts/FontCache.h" |
62 #include "platform/geometry/FloatQuad.h" | 63 #include "platform/geometry/FloatQuad.h" |
63 #include "platform/graphics/DrawLooperBuilder.h" | 64 #include "platform/graphics/DrawLooperBuilder.h" |
64 #include "platform/graphics/GraphicsContextStateSaver.h" | 65 #include "platform/graphics/GraphicsContextStateSaver.h" |
(...skipping 14 matching lines...) Expand all Loading... |
79 static const double TryRestoreContextInterval = 0.5; | 80 static const double TryRestoreContextInterval = 0.5; |
80 static const unsigned MaxTryRestoreContextAttempts = 4; | 81 static const unsigned MaxTryRestoreContextAttempts = 4; |
81 | 82 |
82 static bool contextLostRestoredEventsEnabled() | 83 static bool contextLostRestoredEventsEnabled() |
83 { | 84 { |
84 return RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); | 85 return RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); |
85 } | 86 } |
86 | 87 |
87 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode) | 88 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode) |
88 : CanvasRenderingContext(canvas) | 89 : CanvasRenderingContext(canvas) |
| 90 , m_hitRegionManager(CanvasHitRegionManager::create()) |
89 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) | 91 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) |
90 , m_hasAlpha(!attrs || attrs->alpha()) | 92 , m_hasAlpha(!attrs || attrs->alpha()) |
91 , m_isContextLost(false) | 93 , m_isContextLost(false) |
92 , m_contextRestorable(true) | 94 , m_contextRestorable(true) |
93 , m_storageMode(!attrs ? PersistentStorage : attrs->parsedStorage()) | 95 , m_storageMode(!attrs ? PersistentStorage : attrs->parsedStorage()) |
94 , m_tryRestoreContextAttemptCount(0) | 96 , m_tryRestoreContextAttemptCount(0) |
95 , m_dispatchContextLostEventTimer(this, &CanvasRenderingContext2D::dispatchC
ontextLostEvent) | 97 , m_dispatchContextLostEventTimer(this, &CanvasRenderingContext2D::dispatchC
ontextLostEvent) |
96 , m_dispatchContextRestoredEventTimer(this, &CanvasRenderingContext2D::dispa
tchContextRestoredEvent) | 98 , m_dispatchContextRestoredEventTimer(this, &CanvasRenderingContext2D::dispa
tchContextRestoredEvent) |
97 , m_tryRestoreContextEventTimer(this, &CanvasRenderingContext2D::tryRestoreC
ontextEvent) | 99 , m_tryRestoreContextEventTimer(this, &CanvasRenderingContext2D::tryRestoreC
ontextEvent) |
98 { | 100 { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 reset(); | 161 reset(); |
160 m_isContextLost = false; | 162 m_isContextLost = false; |
161 } | 163 } |
162 } | 164 } |
163 } | 165 } |
164 | 166 |
165 void CanvasRenderingContext2D::trace(Visitor* visitor) | 167 void CanvasRenderingContext2D::trace(Visitor* visitor) |
166 { | 168 { |
167 #if ENABLE(OILPAN) | 169 #if ENABLE(OILPAN) |
168 visitor->trace(m_stateStack); | 170 visitor->trace(m_stateStack); |
| 171 visitor->trace(m_hitRegionManager); |
169 visitor->trace(m_fetchedFonts); | 172 visitor->trace(m_fetchedFonts); |
170 #endif | 173 #endif |
171 CanvasRenderingContext::trace(visitor); | 174 CanvasRenderingContext::trace(visitor); |
172 } | 175 } |
173 | 176 |
174 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon
text2D>*) | 177 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon
text2D>*) |
175 { | 178 { |
176 if (contextLostRestoredEventsEnabled()) { | 179 if (contextLostRestoredEventsEnabled()) { |
177 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames
::contextlost); | 180 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames
::contextlost); |
178 canvas()->dispatchEvent(event); | 181 canvas()->dispatchEvent(event); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 canvas()->dispatchEvent(event); | 226 canvas()->dispatchEvent(event); |
224 } | 227 } |
225 } | 228 } |
226 | 229 |
227 void CanvasRenderingContext2D::reset() | 230 void CanvasRenderingContext2D::reset() |
228 { | 231 { |
229 unwindStateStack(); | 232 unwindStateStack(); |
230 m_stateStack.resize(1); | 233 m_stateStack.resize(1); |
231 m_stateStack.first() = adoptPtrWillBeNoop(new State()); | 234 m_stateStack.first() = adoptPtrWillBeNoop(new State()); |
232 m_path.clear(); | 235 m_path.clear(); |
| 236 m_hitRegionManager->clear(); |
233 } | 237 } |
234 | 238 |
235 // Important: Several of these properties are also stored in GraphicsContext's | 239 // Important: Several of these properties are also stored in GraphicsContext's |
236 // StrokeData. The default values that StrokeData uses may not the same values | 240 // StrokeData. The default values that StrokeData uses may not the same values |
237 // that the canvas 2d spec specifies. Make sure to sync the initial state of the | 241 // that the canvas 2d spec specifies. Make sure to sync the initial state of the |
238 // GraphicsContext in HTMLCanvasElement::createImageBuffer()! | 242 // GraphicsContext in HTMLCanvasElement::createImageBuffer()! |
239 CanvasRenderingContext2D::State::State() | 243 CanvasRenderingContext2D::State::State() |
240 : m_unrealizedSaveCount(0) | 244 : m_unrealizedSaveCount(0) |
241 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) | 245 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) |
242 , m_fillStyle(CanvasStyle::createFromRGBA(Color::black)) | 246 , m_fillStyle(CanvasStyle::createFromRGBA(Color::black)) |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 if (!context) | 1213 if (!context) |
1210 return; | 1214 return; |
1211 if (!state().m_invertibleCTM) | 1215 if (!state().m_invertibleCTM) |
1212 return; | 1216 return; |
1213 FloatRect rect(x, y, width, height); | 1217 FloatRect rect(x, y, width, height); |
1214 | 1218 |
1215 FloatRect dirtyRect; | 1219 FloatRect dirtyRect; |
1216 if (!computeDirtyRect(rect, &dirtyRect)) | 1220 if (!computeDirtyRect(rect, &dirtyRect)) |
1217 return; | 1221 return; |
1218 | 1222 |
| 1223 m_hitRegionManager->removeEnclosed(rect, state().m_transform); |
| 1224 |
1219 bool saved = false; | 1225 bool saved = false; |
1220 if (shouldDrawShadows()) { | 1226 if (shouldDrawShadows()) { |
1221 context->save(); | 1227 context->save(); |
1222 saved = true; | 1228 saved = true; |
1223 context->clearShadow(); | 1229 context->clearShadow(); |
1224 } | 1230 } |
1225 if (state().m_globalAlpha != 1) { | 1231 if (state().m_globalAlpha != 1) { |
1226 if (!saved) { | 1232 if (!saved) { |
1227 context->save(); | 1233 context->save(); |
1228 saved = true; | 1234 saved = true; |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 c->setImageInterpolationQuality(enabled ? CanvasDefaultInterpolationQual
ity : InterpolationNone); | 2265 c->setImageInterpolationQuality(enabled ? CanvasDefaultInterpolationQual
ity : InterpolationNone); |
2260 } | 2266 } |
2261 | 2267 |
2262 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib
utes() const | 2268 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib
utes() const |
2263 { | 2269 { |
2264 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr
eate(); | 2270 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr
eate(); |
2265 attributes->setAlpha(m_hasAlpha); | 2271 attributes->setAlpha(m_hasAlpha); |
2266 return attributes.release(); | 2272 return attributes.release(); |
2267 } | 2273 } |
2268 | 2274 |
| 2275 void CanvasRenderingContext2D::addHitRegion(ExceptionState& exceptionState) |
| 2276 { |
| 2277 DecodedHitRegionOptions decodedOptions; |
| 2278 decodedOptions.resolvePath(m_path, state().m_transform); |
| 2279 // parentId / id will be null here, so no need to resolve them. |
| 2280 |
| 2281 addHitRegionInternal(decodedOptions, exceptionState); |
| 2282 } |
| 2283 |
| 2284 void CanvasRenderingContext2D::addHitRegion(const Dictionary& options, Exception
State& exceptionState) |
| 2285 { |
| 2286 DecodedHitRegionOptions decodedOptions(options); |
| 2287 decodedOptions.resolvePath(m_path, state().m_transform); |
| 2288 decodedOptions.resolveIds(m_hitRegionManager.get()); |
| 2289 |
| 2290 addHitRegionInternal(decodedOptions, exceptionState); |
| 2291 } |
| 2292 |
| 2293 void CanvasRenderingContext2D::removeHitRegion(const String& id) |
| 2294 { |
| 2295 if (CanvasHitRegion* hitRegion = m_hitRegionManager->getHitRegionById(id)) |
| 2296 m_hitRegionManager->remove(hitRegion); |
| 2297 } |
| 2298 |
| 2299 CanvasHitRegion* CanvasRenderingContext2D::hitRegionAtPoint(const LayoutPoint& p
oint) |
| 2300 { |
| 2301 return m_hitRegionManager->getHitRegionAtPoint(point); |
| 2302 } |
| 2303 |
| 2304 void CanvasRenderingContext2D::addHitRegionInternal(const DecodedHitRegionOption
s& options, ExceptionState& exceptionState) |
| 2305 { |
| 2306 if (!options.validate(exceptionState)) |
| 2307 return; |
| 2308 |
| 2309 RefPtrWillBeRawPtr<CanvasHitRegion> hitRegion = CanvasHitRegion::create(opti
ons); |
| 2310 m_hitRegionManager->remove(options.previousHitRegion.get()); |
| 2311 m_hitRegionManager->add(hitRegion.release()); |
| 2312 } |
| 2313 |
2269 void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element) | 2314 void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element) |
2270 { | 2315 { |
2271 drawFocusIfNeededInternal(m_path, element); | 2316 drawFocusIfNeededInternal(m_path, element); |
2272 } | 2317 } |
2273 | 2318 |
2274 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen
t) | 2319 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen
t) |
2275 { | 2320 { |
2276 drawFocusIfNeededInternal(path2d->path(), element); | 2321 drawFocusIfNeededInternal(path2d->path(), element); |
2277 } | 2322 } |
2278 | 2323 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2370 c->setAlphaAsFloat(1.0); | 2415 c->setAlphaAsFloat(1.0); |
2371 c->clearShadow(); | 2416 c->clearShadow(); |
2372 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); | 2417 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); |
2373 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2418 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
2374 c->restore(); | 2419 c->restore(); |
2375 | 2420 |
2376 didDraw(dirtyRect); | 2421 didDraw(dirtyRect); |
2377 } | 2422 } |
2378 | 2423 |
2379 } // namespace WebCore | 2424 } // namespace WebCore |
OLD | NEW |