Chromium Code Reviews| Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| index 4eea12475e641bce52e6482f6efa3b73d6060b7e..b86d7cb7f3719cfa8112de03068d2532bdb191f6 100644 |
| --- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| +++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| @@ -83,6 +83,13 @@ static bool contextLostRestoredEventsEnabled() |
| return RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); |
| } |
| +static inline TextDirection inheritedDirection(HTMLCanvasElement& canvasElement) |
| +{ |
| + canvasElement.document().updateRenderTreeIfNeeded(); |
| + RenderStyle* computedStyle = canvasElement.computedStyle(); |
| + return computedStyle ? computedStyle->direction() : LTR; |
| +} |
| + |
| CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, const Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode) |
| : CanvasRenderingContext(canvas) |
| , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) |
| @@ -239,7 +246,7 @@ void CanvasRenderingContext2D::reset() |
| // StrokeData. The default values that StrokeData uses may not the same values |
| // that the canvas 2d spec specifies. Make sure to sync the initial state of the |
| // GraphicsContext in HTMLCanvasElement::createImageBuffer()! |
| -CanvasRenderingContext2D::State::State() |
| +CanvasRenderingContext2D::State::State(Direction direction) |
|
Stephen White
2014/08/21 14:04:38
This seems out of keeping with the other State par
|
| : m_unrealizedSaveCount(0) |
| , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) |
| , m_fillStyle(CanvasStyle::createFromRGBA(Color::black)) |
| @@ -257,6 +264,7 @@ CanvasRenderingContext2D::State::State() |
| , m_imageSmoothingEnabled(true) |
| , m_textAlign(StartTextAlign) |
| , m_textBaseline(AlphabeticTextBaseline) |
| + , m_direction(direction) |
| , m_unparsedFont(defaultFont) |
| , m_realizedFont(false) |
| , m_hasClip(false) |
| @@ -286,6 +294,7 @@ CanvasRenderingContext2D::State::State(const State& other) |
| , m_imageSmoothingEnabled(other.m_imageSmoothingEnabled) |
| , m_textAlign(other.m_textAlign) |
| , m_textBaseline(other.m_textBaseline) |
| + , m_direction(other.m_direction) |
| , m_unparsedFont(other.m_unparsedFont) |
| , m_font(other.m_font) |
| , m_realizedFont(other.m_realizedFont) |
| @@ -325,6 +334,7 @@ CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(cons |
| m_imageSmoothingEnabled = other.m_imageSmoothingEnabled; |
| m_textAlign = other.m_textAlign; |
| m_textBaseline = other.m_textBaseline; |
| + m_direction = other.m_direction; |
| m_unparsedFont = other.m_unparsedFont; |
| m_font = other.m_font; |
| m_realizedFont = other.m_realizedFont; |
| @@ -2016,6 +2026,42 @@ void CanvasRenderingContext2D::setTextBaseline(const String& s) |
| modifiableState().m_textBaseline = baseline; |
| } |
| +String CanvasRenderingContext2D::direction() const |
| +{ |
| + TextDirection direction = LTR; |
| + switch (state().m_direction) { |
| + case DirectionInherit: |
| + direction = inheritedDirection(*canvas()); |
| + break; |
| + case DirectionRTL: |
| + direction = RTL; |
| + break; |
| + case DirectionLTR: |
| + direction = LTR; |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + break; |
| + } |
| + return direction == RTL ? "rtl" : "ltr"; |
| +} |
| + |
| +void CanvasRenderingContext2D::setDirection(const String& directionString) |
| +{ |
| + Direction direction; |
| + if (directionString == "inherit") |
| + direction = DirectionInherit; |
| + else if (directionString == "rtl") |
| + direction = DirectionRTL; |
| + else if (directionString == "ltr") |
| + direction = DirectionLTR; |
| + else |
| + return; |
| + |
| + realizeSaves(); |
| + modifiableState().m_direction = direction; |
| +} |
| + |
| void CanvasRenderingContext2D::fillText(const String& text, float x, float y) |
| { |
| drawTextInternal(text, x, y, true); |
| @@ -2142,8 +2188,24 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo |
| // FIXME: Need to turn off font smoothing. |
| + if (state().m_direction == DirectionInherit) |
| + canvas()->document().updateRenderTreeIfNeeded(); |
| RenderStyle* computedStyle = canvas()->computedStyle(); |
| - TextDirection direction = computedStyle ? computedStyle->direction() : LTR; |
| + TextDirection direction = LTR; |
| + switch (state().m_direction) { |
| + case DirectionInherit: |
| + direction = computedStyle ? computedStyle->direction() : LTR; |
| + break; |
| + case DirectionRTL: |
| + direction = RTL; |
| + break; |
| + case DirectionLTR: |
| + direction = LTR; |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + break; |
| + } |
| bool isRTL = direction == RTL; |
| bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : false; |