Bug 989337 - 2/3 - Convert Canvas2D to typed enums and EnumeratedArray, auto regex changes - r=Bas
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 25 Apr 2014 22:34:07 -0400
changeset 199946 f05cc8c8c16d65a65968777598288bcd7de02a76
parent 199945 aea9916128c6bce15336b867db6d5db14df0aee1
child 199947 b00d3a5f4b6fd5ae3beec5ca57691d0f37a875aa
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs989337
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 989337 - 2/3 - Convert Canvas2D to typed enums and EnumeratedArray, auto regex changes - r=Bas
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/CanvasRenderingContext2D.h
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -226,41 +226,41 @@ public:
     // not be executed.
     NS_ASSERTION(!mPattern, "ForStyle() should only be called once on CanvasGeneralPattern!");
 
     const ContextState &state = aCtx->CurrentState();
 
     if (state.StyleIsColor(aStyle)) {
       mPattern = new (mColorPattern.addr()) ColorPattern(Color::FromABGR(state.colorStyles[aStyle]));
     } else if (state.gradientStyles[aStyle] &&
-               state.gradientStyles[aStyle]->GetType() == CanvasGradient::LINEAR) {
+               state.gradientStyles[aStyle]->GetType() == CanvasGradient::Type::LINEAR) {
       CanvasLinearGradient *gradient =
         static_cast<CanvasLinearGradient*>(state.gradientStyles[aStyle].get());
 
       mPattern = new (mLinearGradientPattern.addr())
         LinearGradientPattern(gradient->mBegin, gradient->mEnd,
                               gradient->GetGradientStopsForTarget(aRT));
     } else if (state.gradientStyles[aStyle] &&
-               state.gradientStyles[aStyle]->GetType() == CanvasGradient::RADIAL) {
+               state.gradientStyles[aStyle]->GetType() == CanvasGradient::Type::RADIAL) {
       CanvasRadialGradient *gradient =
         static_cast<CanvasRadialGradient*>(state.gradientStyles[aStyle].get());
 
       mPattern = new (mRadialGradientPattern.addr())
         RadialGradientPattern(gradient->mCenter1, gradient->mCenter2, gradient->mRadius1,
                               gradient->mRadius2, gradient->GetGradientStopsForTarget(aRT));
     } else if (state.patternStyles[aStyle]) {
       if (aCtx->mCanvasElement) {
         CanvasUtils::DoDrawImageSecurityCheck(aCtx->mCanvasElement,
                                               state.patternStyles[aStyle]->mPrincipal,
                                               state.patternStyles[aStyle]->mForceWriteOnly,
                                               state.patternStyles[aStyle]->mCORSUsed);
       }
 
       ExtendMode mode;
-      if (state.patternStyles[aStyle]->mRepeat == CanvasPattern::NOREPEAT) {
+      if (state.patternStyles[aStyle]->mRepeat == CanvasPattern::RepeatMode::NOREPEAT) {
         mode = ExtendMode::CLAMP;
       } else {
         mode = ExtendMode::REPEAT;
       }
       mPattern = new (mSurfacePattern.addr())
         SurfacePattern(state.patternStyles[aStyle]->mSurface, mode);
     }
 
@@ -473,31 +473,31 @@ private:
 NS_IMPL_CYCLE_COLLECTING_ADDREF(CanvasRenderingContext2D)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(CanvasRenderingContext2D)
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(CanvasRenderingContext2D)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CanvasRenderingContext2D)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mCanvasElement)
   for (uint32_t i = 0; i < tmp->mStyleStack.Length(); i++) {
-    ImplCycleCollectionUnlink(tmp->mStyleStack[i].patternStyles[STYLE_STROKE]);
-    ImplCycleCollectionUnlink(tmp->mStyleStack[i].patternStyles[STYLE_FILL]);
-    ImplCycleCollectionUnlink(tmp->mStyleStack[i].gradientStyles[STYLE_STROKE]);
-    ImplCycleCollectionUnlink(tmp->mStyleStack[i].gradientStyles[STYLE_FILL]);
+    ImplCycleCollectionUnlink(tmp->mStyleStack[i].patternStyles[Style::STROKE]);
+    ImplCycleCollectionUnlink(tmp->mStyleStack[i].patternStyles[Style::FILL]);
+    ImplCycleCollectionUnlink(tmp->mStyleStack[i].gradientStyles[Style::STROKE]);
+    ImplCycleCollectionUnlink(tmp->mStyleStack[i].gradientStyles[Style::FILL]);
   }
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CanvasRenderingContext2D)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCanvasElement)
   for (uint32_t i = 0; i < tmp->mStyleStack.Length(); i++) {
-    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].patternStyles[STYLE_STROKE], "Stroke CanvasPattern");
-    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].patternStyles[STYLE_FILL], "Fill CanvasPattern");
-    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].gradientStyles[STYLE_STROKE], "Stroke CanvasGradient");
-    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].gradientStyles[STYLE_FILL], "Fill CanvasGradient");
+    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].patternStyles[Style::STROKE], "Stroke CanvasPattern");
+    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].patternStyles[Style::FILL], "Fill CanvasPattern");
+    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].gradientStyles[Style::STROKE], "Stroke CanvasGradient");
+    ImplCycleCollectionTraverse(cb, tmp->mStyleStack[i].gradientStyles[Style::FILL], "Fill CanvasGradient");
   }
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(CanvasRenderingContext2D)
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(CanvasRenderingContext2D)
  if (nsCCUncollectableMarker::sGeneration && tmp->IsBlack()) {
@@ -997,18 +997,18 @@ CanvasRenderingContext2D::ClearTarget()
   mStyleStack.Clear();
   mPathBuilder = nullptr;
   mPath = nullptr;
   mDSPathBuilder = nullptr;
 
   ContextState *state = mStyleStack.AppendElement();
   state->globalAlpha = 1.0;
 
-  state->colorStyles[STYLE_FILL] = NS_RGB(0,0,0);
-  state->colorStyles[STYLE_STROKE] = NS_RGB(0,0,0);
+  state->colorStyles[Style::FILL] = NS_RGB(0,0,0);
+  state->colorStyles[Style::STROKE] = NS_RGB(0,0,0);
   state->shadowColor = NS_RGBA(0,0,0,0);
 }
 
 NS_IMETHODIMP
 CanvasRenderingContext2D::InitializeWithSurface(nsIDocShell *shell,
                                                 gfxASurface *surface,
                                                 int32_t width,
                                                 int32_t height)
@@ -1422,26 +1422,26 @@ CanvasRenderingContext2D::CreateRadialGr
 }
 
 already_AddRefed<CanvasPattern>
 CanvasRenderingContext2D::CreatePattern(const HTMLImageOrCanvasOrVideoElement& element,
                                         const nsAString& repeat,
                                         ErrorResult& error)
 {
   CanvasPattern::RepeatMode repeatMode =
-    CanvasPattern::NOREPEAT;
+    CanvasPattern::RepeatMode::NOREPEAT;
 
   if (repeat.IsEmpty() || repeat.EqualsLiteral("repeat")) {
-    repeatMode = CanvasPattern::REPEAT;
+    repeatMode = CanvasPattern::RepeatMode::REPEAT;
   } else if (repeat.EqualsLiteral("repeat-x")) {
-    repeatMode = CanvasPattern::REPEATX;
+    repeatMode = CanvasPattern::RepeatMode::REPEATX;
   } else if (repeat.EqualsLiteral("repeat-y")) {
-    repeatMode = CanvasPattern::REPEATY;
+    repeatMode = CanvasPattern::RepeatMode::REPEATY;
   } else if (repeat.EqualsLiteral("no-repeat")) {
-    repeatMode = CanvasPattern::NOREPEAT;
+    repeatMode = CanvasPattern::RepeatMode::NOREPEAT;
   } else {
     error.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     return nullptr;
   }
 
   Element* htmlElement;
   if (element.IsHTMLCanvasElement()) {
     HTMLCanvasElement* canvas = &element.GetAsHTMLCanvasElement();
@@ -1522,25 +1522,25 @@ CanvasRenderingContext2D::ClearRect(doub
 }
 
 void
 CanvasRenderingContext2D::FillRect(double x, double y, double w,
                                    double h)
 {
   const ContextState &state = CurrentState();
 
-  if (state.patternStyles[STYLE_FILL]) {
+  if (state.patternStyles[Style::FILL]) {
     CanvasPattern::RepeatMode repeat =
-      state.patternStyles[STYLE_FILL]->mRepeat;
+      state.patternStyles[Style::FILL]->mRepeat;
     // In the FillRect case repeat modes are easy to deal with.
-    bool limitx = repeat == CanvasPattern::NOREPEAT || repeat == CanvasPattern::REPEATY;
-    bool limity = repeat == CanvasPattern::NOREPEAT || repeat == CanvasPattern::REPEATX;
+    bool limitx = repeat == CanvasPattern::RepeatMode::NOREPEAT || repeat == CanvasPattern::RepeatMode::REPEATY;
+    bool limity = repeat == CanvasPattern::RepeatMode::NOREPEAT || repeat == CanvasPattern::RepeatMode::REPEATX;
 
     IntSize patternSize =
-      state.patternStyles[STYLE_FILL]->mSurface->GetSize();
+      state.patternStyles[Style::FILL]->mSurface->GetSize();
 
     // We always need to execute painting for non-over operators, even if
     // we end up with w/h = 0.
     if (limitx) {
       if (x < 0) {
         w += x;
         if (w < 0) {
           w = 0;
@@ -1578,17 +1578,17 @@ CanvasRenderingContext2D::FillRect(doubl
   EnsureTarget();
   if (NeedToDrawShadow()) {
     bounds = mgfx::Rect(x, y, w, h);
     bounds = mTarget->GetTransform().TransformBounds(bounds);
   }
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
     FillRect(mgfx::Rect(x, y, w, h),
-             CanvasGeneralPattern().ForStyle(this, STYLE_FILL, mTarget),
+             CanvasGeneralPattern().ForStyle(this, Style::FILL, mTarget),
              DrawOptions(state.globalAlpha, UsedOperation()));
 
   RedrawUser(gfxRect(x, y, w, h));
 }
 
 void
 CanvasRenderingContext2D::StrokeRect(double x, double y, double w,
                                      double h)
@@ -1614,46 +1614,46 @@ CanvasRenderingContext2D::StrokeRect(dou
 
   if (!h) {
     CapStyle cap = CapStyle::BUTT;
     if (state.lineJoin == JoinStyle::ROUND) {
       cap = CapStyle::ROUND;
     }
     AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
       StrokeLine(Point(x, y), Point(x + w, y),
-                  CanvasGeneralPattern().ForStyle(this, STYLE_STROKE, mTarget),
+                  CanvasGeneralPattern().ForStyle(this, Style::STROKE, mTarget),
                   StrokeOptions(state.lineWidth, state.lineJoin,
                                 cap, state.miterLimit,
                                 state.dash.Length(),
                                 state.dash.Elements(),
                                 state.dashOffset),
                   DrawOptions(state.globalAlpha, UsedOperation()));
     return;
   }
 
   if (!w) {
     CapStyle cap = CapStyle::BUTT;
     if (state.lineJoin == JoinStyle::ROUND) {
       cap = CapStyle::ROUND;
     }
     AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
       StrokeLine(Point(x, y), Point(x, y + h),
-                  CanvasGeneralPattern().ForStyle(this, STYLE_STROKE, mTarget),
+                  CanvasGeneralPattern().ForStyle(this, Style::STROKE, mTarget),
                   StrokeOptions(state.lineWidth, state.lineJoin,
                                 cap, state.miterLimit,
                                 state.dash.Length(),
                                 state.dash.Elements(),
                                 state.dashOffset),
                   DrawOptions(state.globalAlpha, UsedOperation()));
     return;
   }
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
     StrokeRect(mgfx::Rect(x, y, w, h),
-                CanvasGeneralPattern().ForStyle(this, STYLE_STROKE, mTarget),
+                CanvasGeneralPattern().ForStyle(this, Style::STROKE, mTarget),
                 StrokeOptions(state.lineWidth, state.lineJoin,
                               state.lineCap, state.miterLimit,
                               state.dash.Length(),
                               state.dash.Elements(),
                               state.dashOffset),
                 DrawOptions(state.globalAlpha, UsedOperation()));
 
   Redraw();
@@ -1683,17 +1683,17 @@ CanvasRenderingContext2D::Fill(const Can
 
   mgfx::Rect bounds;
 
   if (NeedToDrawShadow()) {
     bounds = mPath->GetBounds(mTarget->GetTransform());
   }
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
-    Fill(mPath, CanvasGeneralPattern().ForStyle(this, STYLE_FILL, mTarget),
+    Fill(mPath, CanvasGeneralPattern().ForStyle(this, Style::FILL, mTarget),
          DrawOptions(CurrentState().globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
 void CanvasRenderingContext2D::Fill(const CanvasPath& path, const CanvasWindingRule& winding)
 {
   EnsureTarget();
@@ -1706,17 +1706,17 @@ void CanvasRenderingContext2D::Fill(cons
 
   mgfx::Rect bounds;
 
   if (NeedToDrawShadow()) {
     bounds = gfxpath->GetBounds(mTarget->GetTransform());
   }
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
-    Fill(gfxpath, CanvasGeneralPattern().ForStyle(this, STYLE_FILL, mTarget),
+    Fill(gfxpath, CanvasGeneralPattern().ForStyle(this, Style::FILL, mTarget),
          DrawOptions(CurrentState().globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
 void
 CanvasRenderingContext2D::Stroke()
 {
@@ -1735,17 +1735,17 @@ CanvasRenderingContext2D::Stroke()
 
   mgfx::Rect bounds;
   if (NeedToDrawShadow()) {
     bounds =
       mPath->GetStrokedBounds(strokeOptions, mTarget->GetTransform());
   }
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
-    Stroke(mPath, CanvasGeneralPattern().ForStyle(this, STYLE_STROKE, mTarget),
+    Stroke(mPath, CanvasGeneralPattern().ForStyle(this, Style::STROKE, mTarget),
            strokeOptions, DrawOptions(state.globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
 void
 CanvasRenderingContext2D::Stroke(const CanvasPath& path)
 {
@@ -1766,17 +1766,17 @@ CanvasRenderingContext2D::Stroke(const C
 
   mgfx::Rect bounds;
   if (NeedToDrawShadow()) {
     bounds =
       gfxpath->GetStrokedBounds(strokeOptions, mTarget->GetTransform());
   }
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
-    Stroke(gfxpath, CanvasGeneralPattern().ForStyle(this, STYLE_STROKE, mTarget),
+    Stroke(gfxpath, CanvasGeneralPattern().ForStyle(this, Style::STROKE, mTarget),
            strokeOptions, DrawOptions(state.globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
 void CanvasRenderingContext2D::DrawFocusIfNeeded(mozilla::dom::Element& aElement)
 {
   EnsureUserSpacePath();
@@ -1798,27 +1798,27 @@ void CanvasRenderingContext2D::DrawFocus
 
     state.lineCap = CapStyle::BUTT;
     state.lineJoin = mozilla::gfx::JoinStyle::MITER_OR_BEVEL;
     state.lineWidth = 1;
     CurrentState().dash.Clear();
 
     // color and style of the rings is the same as for image maps
     // set the background focus color
-    CurrentState().SetColorStyle(STYLE_STROKE, NS_RGBA(255, 255, 255, 255));
+    CurrentState().SetColorStyle(Style::STROKE, NS_RGBA(255, 255, 255, 255));
     // draw the focus ring
     Stroke();
 
     // set dashing for foreground
     FallibleTArray<mozilla::gfx::Float>& dash = CurrentState().dash;
     dash.AppendElement(1);
     dash.AppendElement(1);
 
     // set the foreground focus color
-    CurrentState().SetColorStyle(STYLE_STROKE, NS_RGBA(0,0,0, 255));
+    CurrentState().SetColorStyle(Style::STROKE, NS_RGBA(0,0,0, 255));
     // draw the focus ring
     Stroke();
 
     Restore();
   }
 }
 
 bool CanvasRenderingContext2D::DrawCustomFocusRing(mozilla::dom::Element& aElement)
@@ -2286,88 +2286,88 @@ CanvasRenderingContext2D::SetFont(const 
   // longer seems to be required.)
   declaration->GetValue(eCSSProperty_font, CurrentState().font);
 }
 
 void
 CanvasRenderingContext2D::SetTextAlign(const nsAString& ta)
 {
   if (ta.EqualsLiteral("start"))
-    CurrentState().textAlign = TEXT_ALIGN_START;
+    CurrentState().textAlign = TextAlign::START;
   else if (ta.EqualsLiteral("end"))
-    CurrentState().textAlign = TEXT_ALIGN_END;
+    CurrentState().textAlign = TextAlign::END;
   else if (ta.EqualsLiteral("left"))
-    CurrentState().textAlign = TEXT_ALIGN_LEFT;
+    CurrentState().textAlign = TextAlign::LEFT;
   else if (ta.EqualsLiteral("right"))
-    CurrentState().textAlign = TEXT_ALIGN_RIGHT;
+    CurrentState().textAlign = TextAlign::RIGHT;
   else if (ta.EqualsLiteral("center"))
-    CurrentState().textAlign = TEXT_ALIGN_CENTER;
+    CurrentState().textAlign = TextAlign::CENTER;
 }
 
 void
 CanvasRenderingContext2D::GetTextAlign(nsAString& ta)
 {
   switch (CurrentState().textAlign)
   {
-  case TEXT_ALIGN_START:
+  case TextAlign::START:
     ta.AssignLiteral("start");
     break;
-  case TEXT_ALIGN_END:
+  case TextAlign::END:
     ta.AssignLiteral("end");
     break;
-  case TEXT_ALIGN_LEFT:
+  case TextAlign::LEFT:
     ta.AssignLiteral("left");
     break;
-  case TEXT_ALIGN_RIGHT:
+  case TextAlign::RIGHT:
     ta.AssignLiteral("right");
     break;
-  case TEXT_ALIGN_CENTER:
+  case TextAlign::CENTER:
     ta.AssignLiteral("center");
     break;
   }
 }
 
 void
 CanvasRenderingContext2D::SetTextBaseline(const nsAString& tb)
 {
   if (tb.EqualsLiteral("top"))
-    CurrentState().textBaseline = TEXT_BASELINE_TOP;
+    CurrentState().textBaseline = TextBaseline::TOP;
   else if (tb.EqualsLiteral("hanging"))
-    CurrentState().textBaseline = TEXT_BASELINE_HANGING;
+    CurrentState().textBaseline = TextBaseline::HANGING;
   else if (tb.EqualsLiteral("middle"))
-    CurrentState().textBaseline = TEXT_BASELINE_MIDDLE;
+    CurrentState().textBaseline = TextBaseline::MIDDLE;
   else if (tb.EqualsLiteral("alphabetic"))
-    CurrentState().textBaseline = TEXT_BASELINE_ALPHABETIC;
+    CurrentState().textBaseline = TextBaseline::ALPHABETIC;
   else if (tb.EqualsLiteral("ideographic"))
-    CurrentState().textBaseline = TEXT_BASELINE_IDEOGRAPHIC;
+    CurrentState().textBaseline = TextBaseline::IDEOGRAPHIC;
   else if (tb.EqualsLiteral("bottom"))
-    CurrentState().textBaseline = TEXT_BASELINE_BOTTOM;
+    CurrentState().textBaseline = TextBaseline::BOTTOM;
 }
 
 void
 CanvasRenderingContext2D::GetTextBaseline(nsAString& tb)
 {
   switch (CurrentState().textBaseline)
   {
-  case TEXT_BASELINE_TOP:
+  case TextBaseline::TOP:
     tb.AssignLiteral("top");
     break;
-  case TEXT_BASELINE_HANGING:
+  case TextBaseline::HANGING:
     tb.AssignLiteral("hanging");
     break;
-  case TEXT_BASELINE_MIDDLE:
+  case TextBaseline::MIDDLE:
     tb.AssignLiteral("middle");
     break;
-  case TEXT_BASELINE_ALPHABETIC:
+  case TextBaseline::ALPHABETIC:
     tb.AssignLiteral("alphabetic");
     break;
-  case TEXT_BASELINE_IDEOGRAPHIC:
+  case TextBaseline::IDEOGRAPHIC:
     tb.AssignLiteral("ideographic");
     break;
-  case TEXT_BASELINE_BOTTOM:
+  case TextBaseline::BOTTOM:
     tb.AssignLiteral("bottom");
     break;
   }
 }
 
 /*
  * Helper function that replaces the whitespace characters in a string
  * with U+0020 SPACE. The whitespace characters are defined as U+0020 SPACE,
@@ -2382,35 +2382,35 @@ TextReplaceWhitespaceCharacters(nsAutoSt
 }
 
 void
 CanvasRenderingContext2D::FillText(const nsAString& text, double x,
                                    double y,
                                    const Optional<double>& maxWidth,
                                    ErrorResult& error)
 {
-  error = DrawOrMeasureText(text, x, y, maxWidth, TEXT_DRAW_OPERATION_FILL, nullptr);
+  error = DrawOrMeasureText(text, x, y, maxWidth, TextDrawOperation::FILL, nullptr);
 }
 
 void
 CanvasRenderingContext2D::StrokeText(const nsAString& text, double x,
                                      double y,
                                      const Optional<double>& maxWidth,
                                      ErrorResult& error)
 {
-  error = DrawOrMeasureText(text, x, y, maxWidth, TEXT_DRAW_OPERATION_STROKE, nullptr);
+  error = DrawOrMeasureText(text, x, y, maxWidth, TextDrawOperation::STROKE, nullptr);
 }
 
 TextMetrics*
 CanvasRenderingContext2D::MeasureText(const nsAString& rawText,
                                       ErrorResult& error)
 {
   float width;
   Optional<double> maxWidth;
-  error = DrawOrMeasureText(rawText, 0, 0, maxWidth, TEXT_DRAW_OPERATION_MEASURE, &width);
+  error = DrawOrMeasureText(rawText, 0, 0, maxWidth, TextDrawOperation::MEASURE, &width);
   if (error.Failed()) {
     return nullptr;
   }
 
   return new TextMetrics(width);
 }
 
 void
@@ -2634,38 +2634,38 @@ struct MOZ_STACK_CLASS CanvasBidiProcess
       }
 
       buffer.mGlyphs = &glyphBuf.front();
       buffer.mNumGlyphs = glyphBuf.size();
 
       Rect bounds = mCtx->mTarget->GetTransform().
         TransformBounds(Rect(mBoundingBox.x, mBoundingBox.y,
                              mBoundingBox.width, mBoundingBox.height));
-      if (mOp == CanvasRenderingContext2D::TEXT_DRAW_OPERATION_FILL) {
+      if (mOp == CanvasRenderingContext2D::TextDrawOperation::FILL) {
         AdjustedTarget(mCtx, &bounds)->
           FillGlyphs(scaledFont, buffer,
                      CanvasGeneralPattern().
-                       ForStyle(mCtx, CanvasRenderingContext2D::STYLE_FILL, mCtx->mTarget),
+                       ForStyle(mCtx, CanvasRenderingContext2D::Style::FILL, mCtx->mTarget),
                      DrawOptions(mState->globalAlpha, mCtx->UsedOperation()),
                      renderingOptions);
-      } else if (mOp == CanvasRenderingContext2D::TEXT_DRAW_OPERATION_STROKE) {
+      } else if (mOp == CanvasRenderingContext2D::TextDrawOperation::STROKE) {
         // stroke glyphs one at a time to avoid poor CoreGraphics performance
         // when stroking a path with a very large number of points
         buffer.mGlyphs = &glyphBuf.front();
         buffer.mNumGlyphs = 1;
         const ContextState& state = *mState;
         AdjustedTarget target(mCtx, &bounds);
         const StrokeOptions strokeOpts(state.lineWidth, state.lineJoin,
                                        state.lineCap, state.miterLimit,
                                        state.dash.Length(),
                                        state.dash.Elements(),
                                        state.dashOffset);
         CanvasGeneralPattern cgp;
         const Pattern& patForStyle
-          (cgp.ForStyle(mCtx, CanvasRenderingContext2D::STYLE_STROKE, mCtx->mTarget));
+          (cgp.ForStyle(mCtx, CanvasRenderingContext2D::Style::STROKE, mCtx->mTarget));
         const DrawOptions drawOpts(state.globalAlpha, mCtx->UsedOperation());
 
         for (unsigned i = glyphBuf.size(); i > 0; --i) {
           RefPtr<Path> path = scaledFont->GetPathForGlyphs(buffer, mCtx->mTarget);
           target->Stroke(path, patForStyle, strokeOpts, drawOpts);
           buffer.mGlyphs++;
         }
       }
@@ -2814,58 +2814,58 @@ CanvasRenderingContext2D::DrawOrMeasureT
   }
 
   float totalWidth = float(totalWidthCoord) / processor.mAppUnitsPerDevPixel;
   if (aWidth) {
     *aWidth = totalWidth;
   }
 
   // if only measuring, don't need to do any more work
-  if (aOp==TEXT_DRAW_OPERATION_MEASURE) {
+  if (aOp==TextDrawOperation::MEASURE) {
     return NS_OK;
   }
 
   // offset pt.x based on text align
   gfxFloat anchorX;
 
-  if (state.textAlign == TEXT_ALIGN_CENTER) {
+  if (state.textAlign == TextAlign::CENTER) {
     anchorX = .5;
-  } else if (state.textAlign == TEXT_ALIGN_LEFT ||
-            (!isRTL && state.textAlign == TEXT_ALIGN_START) ||
-            (isRTL && state.textAlign == TEXT_ALIGN_END)) {
+  } else if (state.textAlign == TextAlign::LEFT ||
+            (!isRTL && state.textAlign == TextAlign::START) ||
+            (isRTL && state.textAlign == TextAlign::END)) {
     anchorX = 0;
   } else {
     anchorX = 1;
   }
 
   processor.mPt.x -= anchorX * totalWidth;
 
   // offset pt.y based on text baseline
   processor.mFontgrp->UpdateFontList(); // ensure user font generation is current
   NS_ASSERTION(processor.mFontgrp->FontListLength()>0, "font group contains no fonts");
   const gfxFont::Metrics& fontMetrics = processor.mFontgrp->GetFontAt(0)->GetMetrics();
 
   gfxFloat anchorY;
 
   switch (state.textBaseline)
   {
-  case TEXT_BASELINE_HANGING:
+  case TextBaseline::HANGING:
       // fall through; best we can do with the information available
-  case TEXT_BASELINE_TOP:
+  case TextBaseline::TOP:
     anchorY = fontMetrics.emAscent;
     break;
-  case TEXT_BASELINE_MIDDLE:
+  case TextBaseline::MIDDLE:
     anchorY = (fontMetrics.emAscent - fontMetrics.emDescent) * .5f;
     break;
-  case TEXT_BASELINE_IDEOGRAPHIC:
+  case TextBaseline::IDEOGRAPHIC:
     // fall through; best we can do with the information available
-  case TEXT_BASELINE_ALPHABETIC:
+  case TextBaseline::ALPHABETIC:
     anchorY = 0;
     break;
-  case TEXT_BASELINE_BOTTOM:
+  case TextBaseline::BOTTOM:
     anchorY = -fontMetrics.emDescent;
     break;
   default:
     MOZ_CRASH("unexpected TextBaseline");
   }
 
   processor.mPt.y += anchorY;
 
@@ -2909,17 +2909,17 @@ CanvasRenderingContext2D::DrawOrMeasureT
                                     nullptr,
                                     0,
                                     nullptr,
                                     &bidiEngine);
 
 
   mTarget->SetTransform(oldTransform);
 
-  if (aOp == CanvasRenderingContext2D::TEXT_DRAW_OPERATION_FILL &&
+  if (aOp == CanvasRenderingContext2D::TextDrawOperation::FILL &&
       !doDrawShadow) {
     RedrawUser(boundingBox);
     return NS_OK;
   }
 
   Redraw();
   return NS_OK;
 }
--- a/content/canvas/src/CanvasRenderingContext2D.h
+++ b/content/canvas/src/CanvasRenderingContext2D.h
@@ -153,32 +153,32 @@ public:
   }
 
   void GetGlobalCompositeOperation(nsAString& op, mozilla::ErrorResult& error);
   void SetGlobalCompositeOperation(const nsAString& op,
                                    mozilla::ErrorResult& error);
 
   void GetStrokeStyle(OwningStringOrCanvasGradientOrCanvasPattern& value)
   {
-    GetStyleAsUnion(value, STYLE_STROKE);
+    GetStyleAsUnion(value, Style::STROKE);
   }
 
   void SetStrokeStyle(const StringOrCanvasGradientOrCanvasPattern& value)
   {
-    SetStyleFromUnion(value, STYLE_STROKE);
+    SetStyleFromUnion(value, Style::STROKE);
   }
 
   void GetFillStyle(OwningStringOrCanvasGradientOrCanvasPattern& value)
   {
-    GetStyleAsUnion(value, STYLE_FILL);
+    GetStyleAsUnion(value, Style::FILL);
   }
 
   void SetFillStyle(const StringOrCanvasGradientOrCanvasPattern& value)
   {
-    SetStyleFromUnion(value, STYLE_FILL);
+    SetStyleFromUnion(value, Style::FILL);
   }
 
   already_AddRefed<CanvasGradient>
     CreateLinearGradient(double x0, double y0, double x1, double y1);
   already_AddRefed<CanvasGradient>
     CreateRadialGradient(double x0, double y0, double r0, double x1, double y1,
                          double r1, ErrorResult& aError);
   already_AddRefed<CanvasPattern>
@@ -849,18 +849,18 @@ protected:
                              float y,
                              const Optional<double>& maxWidth,
                              TextDrawOperation op,
                              float* aWidth);
 
   // state stack handling
   class ContextState {
   public:
-    ContextState() : textAlign(TEXT_ALIGN_START),
-                     textBaseline(TEXT_BASELINE_ALPHABETIC),
+    ContextState() : textAlign(TextAlign::START),
+                     textBaseline(TextBaseline::ALPHABETIC),
                      lineWidth(1.0f),
                      miterLimit(10.0f),
                      globalAlpha(1.0f),
                      shadowBlur(0.0),
                      dashOffset(0.0f),
                      op(mozilla::gfx::CompositionOp::OP_OVER),
                      fillRule(mozilla::gfx::FillRule::FILL_WINDING),
                      lineCap(mozilla::gfx::CapStyle::BUTT),
@@ -883,17 +883,17 @@ protected:
           dash(other.dash),
           dashOffset(other.dashOffset),
           op(other.op),
           fillRule(other.fillRule),
           lineCap(other.lineCap),
           lineJoin(other.lineJoin),
           imageSmoothingEnabled(other.imageSmoothingEnabled)
     {
-      for (int i = 0; i < STYLE_MAX; i++) {
+      for (int i = 0; i < Style::MAX; i++) {
         colorStyles[i] = other.colorStyles[i];
         gradientStyles[i] = other.gradientStyles[i];
         patternStyles[i] = other.patternStyles[i];
       }
     }
 
     void SetColorStyle(Style whichStyle, nscolor color)
     {
@@ -921,24 +921,24 @@ protected:
     {
       return !(patternStyles[whichStyle] || gradientStyles[whichStyle]);
     }
 
 
     std::vector<mozilla::RefPtr<mozilla::gfx::Path> > clipsPushed;
 
     nsRefPtr<gfxFontGroup> fontGroup;
-    nsRefPtr<CanvasGradient> gradientStyles[STYLE_MAX];
-    nsRefPtr<CanvasPattern> patternStyles[STYLE_MAX];
+    nsRefPtr<CanvasGradient> gradientStyles[Style::MAX];
+    nsRefPtr<CanvasPattern> patternStyles[Style::MAX];
 
     nsString font;
     TextAlign textAlign;
     TextBaseline textBaseline;
 
-    nscolor colorStyles[STYLE_MAX];
+    nscolor colorStyles[Style::MAX];
     nscolor shadowColor;
 
     mozilla::gfx::Matrix transform;
     mozilla::gfx::Point shadowOffset;
     mozilla::gfx::Float lineWidth;
     mozilla::gfx::Float miterLimit;
     mozilla::gfx::Float globalAlpha;
     mozilla::gfx::Float shadowBlur;