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 "bindings/v8/ExceptionMessages.h" | 36 #include "bindings/v8/ExceptionMessages.h" |
37 #include "bindings/v8/ExceptionState.h" | 37 #include "bindings/v8/ExceptionState.h" |
38 #include "bindings/v8/ExceptionStatePlaceholder.h" | 38 #include "bindings/v8/ExceptionStatePlaceholder.h" |
39 #include "core/CSSPropertyNames.h" | 39 #include "core/CSSPropertyNames.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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 m_isContextLost = false; | 158 m_isContextLost = false; |
160 } | 159 } |
161 } | 160 } |
162 } | 161 } |
163 | 162 |
164 void CanvasRenderingContext2D::trace(Visitor* visitor) | 163 void CanvasRenderingContext2D::trace(Visitor* visitor) |
165 { | 164 { |
166 #if ENABLE(OILPAN) | 165 #if ENABLE(OILPAN) |
167 visitor->trace(m_stateStack); | 166 visitor->trace(m_stateStack); |
168 visitor->trace(m_fetchedFonts); | 167 visitor->trace(m_fetchedFonts); |
168 visitor->trace(m_hitRegionManager); | |
169 #endif | 169 #endif |
170 CanvasRenderingContext::trace(visitor); | 170 CanvasRenderingContext::trace(visitor); |
171 } | 171 } |
172 | 172 |
173 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon text2D>*) | 173 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon text2D>*) |
174 { | 174 { |
175 if (contextLostRestoredEventsEnabled()) { | 175 if (contextLostRestoredEventsEnabled()) { |
176 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames ::contextlost); | 176 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames ::contextlost); |
177 canvas()->dispatchEvent(event); | 177 canvas()->dispatchEvent(event); |
178 if (event->defaultPrevented()) { | 178 if (event->defaultPrevented()) { |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 context->setAlphaAsFloat(1); | 1235 context->setAlphaAsFloat(1); |
1236 } | 1236 } |
1237 if (state().m_globalComposite != CompositeSourceOver) { | 1237 if (state().m_globalComposite != CompositeSourceOver) { |
1238 if (!saved) { | 1238 if (!saved) { |
1239 context->save(); | 1239 context->save(); |
1240 saved = true; | 1240 saved = true; |
1241 } | 1241 } |
1242 context->setCompositeOperation(CompositeSourceOver); | 1242 context->setCompositeOperation(CompositeSourceOver); |
1243 } | 1243 } |
1244 context->clearRect(rect); | 1244 context->clearRect(rect); |
1245 if (m_hitRegionManager) | |
1246 m_hitRegionManager->removeHitRegionsInRect(rect, state().m_transform); | |
1245 if (saved) | 1247 if (saved) |
1246 context->restore(); | 1248 context->restore(); |
1247 | 1249 |
1248 validateStateStack(); | 1250 validateStateStack(); |
1249 didDraw(dirtyRect); | 1251 didDraw(dirtyRect); |
1250 } | 1252 } |
1251 | 1253 |
1252 void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei ght) | 1254 void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei ght) |
1253 { | 1255 { |
1254 if (!validateRectForCanvas(x, y, width, height)) | 1256 if (!validateRectForCanvas(x, y, width, height)) |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2350 c->save(); | 2352 c->save(); |
2351 c->setAlphaAsFloat(1.0); | 2353 c->setAlphaAsFloat(1.0); |
2352 c->clearShadow(); | 2354 c->clearShadow(); |
2353 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); | 2355 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); |
2354 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2356 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
2355 c->restore(); | 2357 c->restore(); |
2356 validateStateStack(); | 2358 validateStateStack(); |
2357 didDraw(dirtyRect); | 2359 didDraw(dirtyRect); |
2358 } | 2360 } |
2359 | 2361 |
2362 void CanvasRenderingContext2D::addHitRegion(ExceptionState& exceptionState) | |
2363 { | |
2364 addHitRegion(Dictionary(), exceptionState); | |
2365 } | |
2366 | |
2367 void CanvasRenderingContext2D::addHitRegion(const Dictionary& options, Exception State& exceptionState) | |
2368 { | |
2369 HitRegionOptions passOptions; | |
2370 | |
2371 options.getWithUndefinedOrNullCheck("id", passOptions.id); | |
2372 options.getWithUndefinedOrNullCheck("control", passOptions.control); | |
2373 if (passOptions.id.isEmpty() && !passOptions.control) { | |
2374 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null."); | |
2375 return; | |
2376 } | |
2377 | |
2378 FloatRect clipBounds; | |
2379 GraphicsContext* context = drawingContext(); | |
2380 | |
2381 if (m_path.isEmpty() || !context || !state().m_invertibleCTM | |
2382 || !context->getTransformedClipBounds(&clipBounds)) { | |
2383 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels."); | |
2384 return; | |
2385 } | |
2386 | |
2387 Path specifiedPath = m_path; | |
2388 specifiedPath.transform(state().m_transform); | |
2389 | |
2390 if (context->isClipMode()) { | |
2391 // FIXME: The hit regions should take clipping region into account. | |
zino
2014/06/20 15:31:36
Remove clipping region part and leave comments.
| |
2392 // However, we have no way to get the region from canvas state stack by now. | |
2393 // See http://crbug.com/387057 | |
2394 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels."); | |
2395 } | |
2396 | |
2397 passOptions.path = specifiedPath; | |
2398 addHitRegionInternal(passOptions, exceptionState); | |
2399 } | |
2400 | |
2401 void CanvasRenderingContext2D::addHitRegionInternal(const HitRegionOptions& opti ons, ExceptionState& exceptionState) | |
2402 { | |
2403 if (!m_hitRegionManager) | |
2404 m_hitRegionManager = HitRegionManager::create(); | |
2405 | |
2406 // Remove previous region (with id or control) | |
2407 m_hitRegionManager->removeHitRegionById(options.id); | |
2408 m_hitRegionManager->removeHitRegionByControl(options.control.get()); | |
2409 | |
2410 RefPtrWillBeRawPtr<HitRegion> hitRegion = HitRegion::create(options); | |
2411 hitRegion->updateAccessibility(canvas()); | |
2412 m_hitRegionManager->addHitRegion(hitRegion.release()); | |
2413 } | |
2414 | |
2415 void CanvasRenderingContext2D::removeHitRegion(const String& id) | |
2416 { | |
2417 if (m_hitRegionManager) | |
2418 m_hitRegionManager->removeHitRegionById(id); | |
2419 } | |
2420 | |
2421 void CanvasRenderingContext2D::clearHitRegions() | |
2422 { | |
2423 if (m_hitRegionManager) | |
2424 m_hitRegionManager->removeAllHitRegions(); | |
2425 } | |
2426 | |
2427 HitRegion* CanvasRenderingContext2D::hitRegionAtPoint(const LayoutPoint& point) | |
2428 { | |
2429 if (m_hitRegionManager) | |
2430 return m_hitRegionManager->getHitRegionAtPoint(point); | |
2431 | |
2432 return 0; | |
2433 } | |
2434 | |
2435 unsigned CanvasRenderingContext2D::hitRegionsCount() const | |
2436 { | |
2437 if (m_hitRegionManager) | |
2438 return m_hitRegionManager->getHitRegionsCount(); | |
2439 | |
2440 return 0; | |
2441 } | |
2442 | |
2360 } // namespace WebCore | 2443 } // namespace WebCore |
OLD | NEW |