Skip to content

Commit

Permalink
Bug 1517786 - Implement the getContextAttributes() method for CanvasR…
Browse files Browse the repository at this point in the history
…enderingContext2D. r=gfx-reviewers,lsalzman,emilio

This has been in the HTML spec for a while now (see https://html.spec.whatwg.org/multipage/canvas.html#2dcontext),
so we should probably go ahead and implement it.

Differential Revision: https://phabricator.services.mozilla.com/D184499
  • Loading branch information
jfkthame committed Jul 26, 2023
1 parent 84d736b commit 68ad20d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
13 changes: 12 additions & 1 deletion dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,17 @@ JSObject* CanvasRenderingContext2D::WrapObject(
return CanvasRenderingContext2D_Binding::Wrap(aCx, this, aGivenProto);
}

void CanvasRenderingContext2D::GetContextAttributes(
CanvasRenderingContext2DSettings& aSettings) const {
aSettings = CanvasRenderingContext2DSettings();

aSettings.mAlpha = mContextAttributesHasAlpha;
aSettings.mWillReadFrequently = mWillReadFrequently;

// We don't support the 'desynchronized' and 'colorSpace' attributes, so
// those just keep their default values.
}

CanvasRenderingContext2D::ColorStyleCacheEntry
CanvasRenderingContext2D::ParseColorSlow(const nsACString& aString) {
ColorStyleCacheEntry result{nsCString(aString)};
Expand Down Expand Up @@ -1881,7 +1892,7 @@ CanvasRenderingContext2D::SetContextOptions(JSContext* aCx,
// drawtarget yet
MOZ_ASSERT(!mTarget);

ContextAttributes2D attributes;
CanvasRenderingContext2DSettings attributes;
if (!attributes.Init(aCx, aOptions)) {
aRvForDictionaryInit.Throw(NS_ERROR_UNEXPECTED);
return NS_ERROR_UNEXPECTED;
Expand Down
2 changes: 2 additions & 0 deletions dom/canvas/CanvasRenderingContext2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class CanvasRenderingContext2D : public nsICanvasRenderingContextInternal,
return mCanvasElement->GetOriginalCanvas();
}

void GetContextAttributes(CanvasRenderingContext2DSettings& aSettings) const;

void OnMemoryPressure() override;
void OnBeforePaintTransaction() override;
void OnDidPaintTransaction() override;
Expand Down
13 changes: 10 additions & 3 deletions dom/webidl/CanvasRenderingContext2D.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ enum CanvasFontVariantCaps { "normal", "small-caps", "all-small-caps", "petite-c
enum CanvasTextRendering { "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision" };

[GenerateInit]
dictionary ContextAttributes2D {
// whether or not we're planning to do a lot of readback operations
boolean willReadFrequently = false;
dictionary CanvasRenderingContext2DSettings {
// signal if the canvas contains an alpha channel
boolean alpha = true;

boolean desynchronized = false;

PredefinedColorSpace colorSpace = "srgb";

// whether or not we're planning to do a lot of readback operations
boolean willReadFrequently = false;
};

dictionary HitRegionOptions {
Expand All @@ -54,6 +59,8 @@ interface CanvasRenderingContext2D {
// associated with a canvas.
readonly attribute HTMLCanvasElement? canvas;

CanvasRenderingContext2DSettings getContextAttributes();

// Show the caret if appropriate when drawing
[Func="CanvasUtils::HasDrawWindowPrivilege"]
const unsigned long DRAWWINDOW_DRAW_CARET = 0x01;
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions testing/web-platform/meta/html/dom/idlharness.https.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featu
[AudioTrackList interface: operation getTrackById(DOMString)]
expected: FAIL

[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "getContextAttributes()" with the proper type]
expected: FAIL

[VideoTrackList interface object length]
expected: FAIL

Expand Down Expand Up @@ -87,9 +84,6 @@ prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featu
[VideoTrackList interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL

[CanvasRenderingContext2D interface: operation getContextAttributes()]
expected: FAIL

[VideoTrack interface: attribute label]
expected: FAIL

Expand Down

0 comments on commit 68ad20d

Please sign in to comment.