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 19 matching lines...) Expand all Loading... | |
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 */ | 31 */ |
32 | 32 |
33 #include "config.h" | 33 #include "config.h" |
34 #include "core/html/canvas/CanvasRenderingContext2D.h" | 34 #include "core/html/canvas/CanvasRenderingContext2D.h" |
35 | 35 |
36 #include "CSSPropertyNames.h" | 36 #include "CSSPropertyNames.h" |
37 #include "bindings/v8/ExceptionMessages.h" | 37 #include "bindings/v8/ExceptionMessages.h" |
38 #include "bindings/v8/ExceptionState.h" | 38 #include "bindings/v8/ExceptionState.h" |
39 #include "bindings/v8/ExceptionStatePlaceholder.h" | 39 #include "bindings/v8/ExceptionStatePlaceholder.h" |
40 #include "core/accessibility/AXObjectCache.h" | |
41 #include "core/css/CSSFontSelector.h" | 40 #include "core/css/CSSFontSelector.h" |
42 #include "core/css/parser/BisonCSSParser.h" | 41 #include "core/css/parser/BisonCSSParser.h" |
43 #include "core/css/StylePropertySet.h" | 42 #include "core/css/StylePropertySet.h" |
44 #include "core/css/resolver/StyleResolver.h" | 43 #include "core/css/resolver/StyleResolver.h" |
45 #include "core/dom/ExceptionCode.h" | 44 #include "core/dom/ExceptionCode.h" |
46 #include "core/fetch/ImageResource.h" | 45 #include "core/fetch/ImageResource.h" |
47 #include "core/frame/ImageBitmap.h" | 46 #include "core/frame/ImageBitmap.h" |
48 #include "core/html/HTMLCanvasElement.h" | 47 #include "core/html/HTMLCanvasElement.h" |
49 #include "core/html/HTMLImageElement.h" | 48 #include "core/html/HTMLImageElement.h" |
50 #include "core/html/HTMLMediaElement.h" | 49 #include "core/html/HTMLMediaElement.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 m_isContextLost = false; | 160 m_isContextLost = false; |
162 } | 161 } |
163 } | 162 } |
164 } | 163 } |
165 | 164 |
166 void CanvasRenderingContext2D::trace(Visitor* visitor) | 165 void CanvasRenderingContext2D::trace(Visitor* visitor) |
167 { | 166 { |
168 #if ENABLE(OILPAN) | 167 #if ENABLE(OILPAN) |
169 visitor->trace(m_stateStack); | 168 visitor->trace(m_stateStack); |
170 visitor->trace(m_fetchedFonts); | 169 visitor->trace(m_fetchedFonts); |
170 visitor->trace(m_hitRegionManager); | |
171 #endif | 171 #endif |
172 CanvasRenderingContext::trace(visitor); | 172 CanvasRenderingContext::trace(visitor); |
173 } | 173 } |
174 | 174 |
175 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon text2D>*) | 175 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon text2D>*) |
176 { | 176 { |
177 if (contextLostRestoredEventsEnabled()) { | 177 if (contextLostRestoredEventsEnabled()) { |
178 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames ::contextlost); | 178 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames ::contextlost); |
179 canvas()->dispatchEvent(event); | 179 canvas()->dispatchEvent(event); |
180 if (event->defaultPrevented()) { | 180 if (event->defaultPrevented()) { |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 context->setAlphaAsFloat(1); | 1237 context->setAlphaAsFloat(1); |
1238 } | 1238 } |
1239 if (state().m_globalComposite != CompositeSourceOver) { | 1239 if (state().m_globalComposite != CompositeSourceOver) { |
1240 if (!saved) { | 1240 if (!saved) { |
1241 context->save(); | 1241 context->save(); |
1242 saved = true; | 1242 saved = true; |
1243 } | 1243 } |
1244 context->setCompositeOperation(CompositeSourceOver); | 1244 context->setCompositeOperation(CompositeSourceOver); |
1245 } | 1245 } |
1246 context->clearRect(rect); | 1246 context->clearRect(rect); |
1247 if (m_hitRegionManager) | |
1248 m_hitRegionManager->removeHitRegionsInRect(rect, state().m_transform); | |
1247 if (saved) | 1249 if (saved) |
1248 context->restore(); | 1250 context->restore(); |
1249 | 1251 |
1250 validateStateStack(); | 1252 validateStateStack(); |
1251 didDraw(dirtyRect); | 1253 didDraw(dirtyRect); |
1252 } | 1254 } |
1253 | 1255 |
1254 void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei ght) | 1256 void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei ght) |
1255 { | 1257 { |
1256 if (!validateRectForCanvas(x, y, width, height)) | 1258 if (!validateRectForCanvas(x, y, width, height)) |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2349 c->save(); | 2351 c->save(); |
2350 c->setAlphaAsFloat(1.0); | 2352 c->setAlphaAsFloat(1.0); |
2351 c->clearShadow(); | 2353 c->clearShadow(); |
2352 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); | 2354 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); |
2353 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2355 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
2354 c->restore(); | 2356 c->restore(); |
2355 validateStateStack(); | 2357 validateStateStack(); |
2356 didDraw(dirtyRect); | 2358 didDraw(dirtyRect); |
2357 } | 2359 } |
2358 | 2360 |
2361 void CanvasRenderingContext2D::addHitRegion(ExceptionState& exceptionState) | |
2362 { | |
2363 addHitRegion(Dictionary(), exceptionState); | |
2364 } | |
2365 | |
2366 void CanvasRenderingContext2D::addHitRegion(const Dictionary& options, Exception State& exceptionState) | |
2367 { | |
2368 HitRegionOptions passOptions; | |
2369 | |
2370 options.getWithUndefinedOrNullCheck("id", passOptions.id); | |
2371 options.getWithUndefinedOrNullCheck("control", passOptions.control); | |
2372 if (passOptions.id.isEmpty() && !passOptions.control) { | |
2373 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null."); | |
2374 return; | |
2375 } | |
2376 | |
2377 FloatRect clipBounds; | |
2378 GraphicsContext* context = drawingContext(); | |
2379 | |
2380 if (m_path.isEmpty() || !context || !state().m_invertibleCTM | |
2381 || !context->getTransformedClipBounds(&clipBounds)) { | |
2382 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels."); | |
2383 return; | |
2384 } | |
2385 | |
2386 Path specifiedPath(m_path); | |
2387 specifiedPath.transform(state().m_transform); | |
2388 specifiedPath.intersectPath(context->getCurrentClipPath()); | |
fs
2014/06/10 11:45:15
The path could be "degenerate" after this operatio
zino
2014/06/10 15:40:25
Done.
| |
2389 | |
2390 passOptions.path = specifiedPath; | |
2391 | |
2392 if (passOptions.path.isEmpty()) | |
2393 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels."); | |
2394 else | |
2395 addHitRegionInternal(passOptions, exceptionState); | |
2396 } | |
2397 | |
2398 void CanvasRenderingContext2D::addHitRegionInternal(const HitRegionOptions& opti ons, ExceptionState& exceptionState) | |
2399 { | |
2400 if (!m_hitRegionManager) | |
2401 m_hitRegionManager = HitRegionManager::create(); | |
2402 | |
2403 // Remove previous region (with id or control) | |
2404 m_hitRegionManager->removeHitRegionById(options.id); | |
2405 m_hitRegionManager->removeHitRegionByControl(options.control.get()); | |
2406 | |
2407 RefPtrWillBeRawPtr<HitRegion> hitRegion = HitRegion::create(options); | |
2408 hitRegion->updateAccessibility(canvas()); | |
2409 m_hitRegionManager->addHitRegion(hitRegion.release()); | |
2410 } | |
2411 | |
2412 void CanvasRenderingContext2D::removeHitRegion(const String& id) | |
2413 { | |
2414 if (m_hitRegionManager) | |
2415 m_hitRegionManager->removeHitRegionById(id); | |
2416 } | |
2417 | |
2418 void CanvasRenderingContext2D::clearHitRegions() | |
2419 { | |
2420 if (m_hitRegionManager) | |
2421 m_hitRegionManager->removeAllHitRegions(); | |
2422 } | |
2423 | |
2424 HitRegion* CanvasRenderingContext2D::hitRegionAtPoint(const LayoutPoint& point) | |
2425 { | |
2426 if (m_hitRegionManager) | |
2427 return m_hitRegionManager->getHitRegionAtPoint(point); | |
2428 | |
2429 return 0; | |
2430 } | |
2431 | |
2432 unsigned CanvasRenderingContext2D::hitRegionsCount() const | |
2433 { | |
2434 if (m_hitRegionManager) | |
2435 return m_hitRegionManager->getHitRegionsCount(); | |
2436 | |
2437 return 0; | |
2438 } | |
2439 | |
2359 } // namespace WebCore | 2440 } // namespace WebCore |
OLD | NEW |