Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 300223009: Implement basic parts of hit regions on canvas2d. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 28 matching lines...) Expand all
79 static const double TryRestoreContextInterval = 0.5; 78 static const double TryRestoreContextInterval = 0.5;
80 static const unsigned MaxTryRestoreContextAttempts = 4; 79 static const unsigned MaxTryRestoreContextAttempts = 4;
81 80
82 static bool contextLostRestoredEventsEnabled() 81 static bool contextLostRestoredEventsEnabled()
83 { 82 {
84 return RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); 83 return RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled();
85 } 84 }
86 85
87 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co nst Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode) 86 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co nst Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode)
88 : CanvasRenderingContext(canvas) 87 : CanvasRenderingContext(canvas)
88 , m_hitRegionManager(HitRegionManager::create())
Rik 2014/06/02 22:57:40 do you want to do this lazily?
zino 2014/06/06 06:35:15 Done.
89 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) 89 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode)
90 , m_hasAlpha(!attrs || attrs->alpha()) 90 , m_hasAlpha(!attrs || attrs->alpha())
91 , m_isContextLost(false) 91 , m_isContextLost(false)
92 , m_contextRestorable(true) 92 , m_contextRestorable(true)
93 , m_storageMode(!attrs ? PersistentStorage : attrs->parsedStorage()) 93 , m_storageMode(!attrs ? PersistentStorage : attrs->parsedStorage())
94 , m_tryRestoreContextAttemptCount(0) 94 , m_tryRestoreContextAttemptCount(0)
95 , m_dispatchContextLostEventTimer(this, &CanvasRenderingContext2D::dispatchC ontextLostEvent) 95 , m_dispatchContextLostEventTimer(this, &CanvasRenderingContext2D::dispatchC ontextLostEvent)
96 , m_dispatchContextRestoredEventTimer(this, &CanvasRenderingContext2D::dispa tchContextRestoredEvent) 96 , m_dispatchContextRestoredEventTimer(this, &CanvasRenderingContext2D::dispa tchContextRestoredEvent)
97 , m_tryRestoreContextEventTimer(this, &CanvasRenderingContext2D::tryRestoreC ontextEvent) 97 , m_tryRestoreContextEventTimer(this, &CanvasRenderingContext2D::tryRestoreC ontextEvent)
98 { 98 {
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 context->setAlphaAsFloat(1); 1238 context->setAlphaAsFloat(1);
1239 } 1239 }
1240 if (state().m_globalComposite != CompositeSourceOver) { 1240 if (state().m_globalComposite != CompositeSourceOver) {
1241 if (!saved) { 1241 if (!saved) {
1242 context->save(); 1242 context->save();
1243 saved = true; 1243 saved = true;
1244 } 1244 }
1245 context->setCompositeOperation(CompositeSourceOver); 1245 context->setCompositeOperation(CompositeSourceOver);
1246 } 1246 }
1247 context->clearRect(rect); 1247 context->clearRect(rect);
1248 m_hitRegionManager->removeHitRegionsInRect(rect, state().m_transform);
1248 if (saved) 1249 if (saved)
1249 context->restore(); 1250 context->restore();
1250 1251
1251 validateStateStack(); 1252 validateStateStack();
1252 didDraw(dirtyRect); 1253 didDraw(dirtyRect);
1253 } 1254 }
1254 1255
1255 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)
1256 { 1257 {
1257 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
2350 c->save(); 2351 c->save();
2351 c->setAlphaAsFloat(1.0); 2352 c->setAlphaAsFloat(1.0);
2352 c->clearShadow(); 2353 c->clearShadow();
2353 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); 2354 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal);
2354 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2355 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2355 c->restore(); 2356 c->restore();
2356 validateStateStack(); 2357 validateStateStack();
2357 didDraw(dirtyRect); 2358 didDraw(dirtyRect);
2358 } 2359 }
2359 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 bool idIsNull = !(options.getWithUndefinedOrNullCheck("id", passOptions.id)) || passOptions.id.isEmpty();
dmazzoni 2014/06/03 17:26:10 "null" isn't quite accurate since it could be empt
zino 2014/06/06 06:35:16 Done.
2371 bool controlIsNull = !options.getWithUndefinedOrNullCheck("control", passOpt ions.control) || !passOptions.control;
fs 2014/06/03 11:47:01 controlIsNull seems redundant with passOptions.con
2372
2373 if (passOptions.control && !passOptions.control->isDescendantOf(canvas())) {
2374 passOptions.control = nullptr;
Rik 2014/06/02 22:57:40 why are you doing this? It's ok for a control to s
zino 2014/06/06 06:35:15 Done.
2375 controlIsNull = true;
2376 }
2377
2378 if (idIsNull && controlIsNull) {
2379 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null or undefined or invalid type.");
fs 2014/06/03 11:47:01 Suggest you drop " or undefined or invalid type".
dmazzoni 2014/06/03 17:26:10 What about an empty string?
fs 2014/06/04 08:13:40 Empty strings are coerced to null explicitly (addH
zino 2014/06/06 06:35:15 You're right but dictionary.get() can't do check n
fs 2014/06/09 11:06:26 You're not using "plain" get() though, but rather
zino 2014/06/09 20:00:08 Thank you for detailed explanations :) BTW, I was
fs 2014/06/10 07:25:47 I think fixing it would reduce clutter - and in th
zino 2014/06/10 08:21:35 You seems to want the exception message to be modi
fs 2014/06/10 09:05:49 I'm fine with the exception message in its current
2380 return;
2381 }
2382
2383 if (m_path.isEmpty()) {
fs 2014/06/03 11:47:01 IIRC, Path::isEmpty means "does not have any segme
zino 2014/06/06 06:35:15 Done.
2384 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels.");
2385 return;
2386 }
2387
2388 passOptions.path = m_path;
2389 passOptions.path.transform(state().m_transform);
2390
2391 addHitRegionInternal(passOptions, exceptionState);
2392 }
2393
2394 void CanvasRenderingContext2D::addHitRegionInternal(const HitRegionOptions& opti ons, ExceptionState& exceptionState)
2395 {
2396 // Remove previous region (with id or control)
2397 m_hitRegionManager->removeHitRegionById(options.id);
2398 m_hitRegionManager->removeHitRegionByControl(options.control.get());
2399
2400 RefPtrWillBeRawPtr<HitRegion> hitRegion = HitRegion::create(options);
2401 hitRegion->updateAccessibility(canvas());
2402 m_hitRegionManager->addHitRegion(hitRegion.release());
2403 }
2404
2405 void CanvasRenderingContext2D::removeHitRegion(const String& id)
2406 {
2407 m_hitRegionManager->removeHitRegionById(id);
2408 }
2409
2410 void CanvasRenderingContext2D::clearHitRegions()
2411 {
2412 m_hitRegionManager->removeAllHitRegions();
2413 }
2414
2415 unsigned CanvasRenderingContext2D::hitRegionsCount() const
2416 {
2417 return m_hitRegionManager->getHitRegionsCount();
2418 }
2419
2420 HitRegion* CanvasRenderingContext2D::hitRegionAtPoint(const LayoutPoint& point)
2421 {
2422 return m_hitRegionManager->getHitRegionAtPoint(point);
2423 }
2424
2360 } // namespace WebCore 2425 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698