Chromium Code Reviews| 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 FloatRect specifiedBounds = specifiedPath.boundingRect(); | |
| 2392 | |
| 2393 if (!specifiedBounds.intersects(clipBounds) | |
| 2394 || !specifiedPath.intersectPath(context->getCurrentClipPath()) | |
|
f(malita)
2014/06/17 17:27:26
I'm not sure getCurrentClipPath() is really needed
zino
2014/06/17 23:46:10
The method sets the intersection path between two
Rik
2014/06/17 23:58:58
Why are you looking at the clipping path? Hit regi
| |
| 2395 || specifiedPath.isEmpty()) { | |
| 2396 exceptionState.throwDOMException(NotSupportedError, "The specified p ath has no pixels."); | |
| 2397 return; | |
| 2398 } | |
| 2399 } | |
| 2400 | |
| 2401 passOptions.path = specifiedPath; | |
| 2402 addHitRegionInternal(passOptions, exceptionState); | |
| 2403 } | |
| 2404 | |
| 2405 void CanvasRenderingContext2D::addHitRegionInternal(const HitRegionOptions& opti ons, ExceptionState& exceptionState) | |
| 2406 { | |
| 2407 if (!m_hitRegionManager) | |
| 2408 m_hitRegionManager = HitRegionManager::create(); | |
| 2409 | |
| 2410 // Remove previous region (with id or control) | |
| 2411 m_hitRegionManager->removeHitRegionById(options.id); | |
| 2412 m_hitRegionManager->removeHitRegionByControl(options.control.get()); | |
| 2413 | |
| 2414 RefPtrWillBeRawPtr<HitRegion> hitRegion = HitRegion::create(options); | |
| 2415 hitRegion->updateAccessibility(canvas()); | |
| 2416 m_hitRegionManager->addHitRegion(hitRegion.release()); | |
| 2417 } | |
| 2418 | |
| 2419 void CanvasRenderingContext2D::removeHitRegion(const String& id) | |
| 2420 { | |
| 2421 if (m_hitRegionManager) | |
| 2422 m_hitRegionManager->removeHitRegionById(id); | |
| 2423 } | |
| 2424 | |
| 2425 void CanvasRenderingContext2D::clearHitRegions() | |
| 2426 { | |
| 2427 if (m_hitRegionManager) | |
| 2428 m_hitRegionManager->removeAllHitRegions(); | |
| 2429 } | |
| 2430 | |
| 2431 HitRegion* CanvasRenderingContext2D::hitRegionAtPoint(const LayoutPoint& point) | |
| 2432 { | |
| 2433 if (m_hitRegionManager) | |
| 2434 return m_hitRegionManager->getHitRegionAtPoint(point); | |
| 2435 | |
| 2436 return 0; | |
| 2437 } | |
| 2438 | |
| 2439 unsigned CanvasRenderingContext2D::hitRegionsCount() const | |
| 2440 { | |
| 2441 if (m_hitRegionManager) | |
| 2442 return m_hitRegionManager->getHitRegionsCount(); | |
| 2443 | |
| 2444 return 0; | |
| 2445 } | |
| 2446 | |
| 2360 } // namespace WebCore | 2447 } // namespace WebCore |
| OLD | NEW |