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

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

Issue 468483003: Implement canvas2d direction attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for landing! Created 6 years, 4 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 , m_shadowBlur(0) 250 , m_shadowBlur(0)
251 , m_shadowColor(Color::transparent) 251 , m_shadowColor(Color::transparent)
252 , m_globalAlpha(1) 252 , m_globalAlpha(1)
253 , m_globalComposite(CompositeSourceOver) 253 , m_globalComposite(CompositeSourceOver)
254 , m_globalBlend(blink::WebBlendModeNormal) 254 , m_globalBlend(blink::WebBlendModeNormal)
255 , m_invertibleCTM(true) 255 , m_invertibleCTM(true)
256 , m_lineDashOffset(0) 256 , m_lineDashOffset(0)
257 , m_imageSmoothingEnabled(true) 257 , m_imageSmoothingEnabled(true)
258 , m_textAlign(StartTextAlign) 258 , m_textAlign(StartTextAlign)
259 , m_textBaseline(AlphabeticTextBaseline) 259 , m_textBaseline(AlphabeticTextBaseline)
260 , m_direction(Inherit)
260 , m_unparsedFont(defaultFont) 261 , m_unparsedFont(defaultFont)
261 , m_realizedFont(false) 262 , m_realizedFont(false)
262 , m_hasClip(false) 263 , m_hasClip(false)
263 { 264 {
264 } 265 }
265 266
266 CanvasRenderingContext2D::State::State(const State& other) 267 CanvasRenderingContext2D::State::State(const State& other)
267 : CSSFontSelectorClient() 268 : CSSFontSelectorClient()
268 , m_unrealizedSaveCount(other.m_unrealizedSaveCount) 269 , m_unrealizedSaveCount(other.m_unrealizedSaveCount)
269 , m_unparsedStrokeColor(other.m_unparsedStrokeColor) 270 , m_unparsedStrokeColor(other.m_unparsedStrokeColor)
270 , m_unparsedFillColor(other.m_unparsedFillColor) 271 , m_unparsedFillColor(other.m_unparsedFillColor)
271 , m_strokeStyle(other.m_strokeStyle) 272 , m_strokeStyle(other.m_strokeStyle)
272 , m_fillStyle(other.m_fillStyle) 273 , m_fillStyle(other.m_fillStyle)
273 , m_lineWidth(other.m_lineWidth) 274 , m_lineWidth(other.m_lineWidth)
274 , m_lineCap(other.m_lineCap) 275 , m_lineCap(other.m_lineCap)
275 , m_lineJoin(other.m_lineJoin) 276 , m_lineJoin(other.m_lineJoin)
276 , m_miterLimit(other.m_miterLimit) 277 , m_miterLimit(other.m_miterLimit)
277 , m_shadowOffset(other.m_shadowOffset) 278 , m_shadowOffset(other.m_shadowOffset)
278 , m_shadowBlur(other.m_shadowBlur) 279 , m_shadowBlur(other.m_shadowBlur)
279 , m_shadowColor(other.m_shadowColor) 280 , m_shadowColor(other.m_shadowColor)
280 , m_globalAlpha(other.m_globalAlpha) 281 , m_globalAlpha(other.m_globalAlpha)
281 , m_globalComposite(other.m_globalComposite) 282 , m_globalComposite(other.m_globalComposite)
282 , m_globalBlend(other.m_globalBlend) 283 , m_globalBlend(other.m_globalBlend)
283 , m_transform(other.m_transform) 284 , m_transform(other.m_transform)
284 , m_invertibleCTM(other.m_invertibleCTM) 285 , m_invertibleCTM(other.m_invertibleCTM)
285 , m_lineDashOffset(other.m_lineDashOffset) 286 , m_lineDashOffset(other.m_lineDashOffset)
286 , m_imageSmoothingEnabled(other.m_imageSmoothingEnabled) 287 , m_imageSmoothingEnabled(other.m_imageSmoothingEnabled)
287 , m_textAlign(other.m_textAlign) 288 , m_textAlign(other.m_textAlign)
288 , m_textBaseline(other.m_textBaseline) 289 , m_textBaseline(other.m_textBaseline)
290 , m_direction(other.m_direction)
289 , m_unparsedFont(other.m_unparsedFont) 291 , m_unparsedFont(other.m_unparsedFont)
290 , m_font(other.m_font) 292 , m_font(other.m_font)
291 , m_realizedFont(other.m_realizedFont) 293 , m_realizedFont(other.m_realizedFont)
292 , m_hasClip(other.m_hasClip) 294 , m_hasClip(other.m_hasClip)
293 { 295 {
294 if (m_realizedFont) 296 if (m_realizedFont)
295 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid ationCallbacks(this); 297 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid ationCallbacks(this);
296 } 298 }
297 299
298 CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(cons t State& other) 300 CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(cons t State& other)
(...skipping 19 matching lines...) Expand all
318 m_shadowBlur = other.m_shadowBlur; 320 m_shadowBlur = other.m_shadowBlur;
319 m_shadowColor = other.m_shadowColor; 321 m_shadowColor = other.m_shadowColor;
320 m_globalAlpha = other.m_globalAlpha; 322 m_globalAlpha = other.m_globalAlpha;
321 m_globalComposite = other.m_globalComposite; 323 m_globalComposite = other.m_globalComposite;
322 m_globalBlend = other.m_globalBlend; 324 m_globalBlend = other.m_globalBlend;
323 m_transform = other.m_transform; 325 m_transform = other.m_transform;
324 m_invertibleCTM = other.m_invertibleCTM; 326 m_invertibleCTM = other.m_invertibleCTM;
325 m_imageSmoothingEnabled = other.m_imageSmoothingEnabled; 327 m_imageSmoothingEnabled = other.m_imageSmoothingEnabled;
326 m_textAlign = other.m_textAlign; 328 m_textAlign = other.m_textAlign;
327 m_textBaseline = other.m_textBaseline; 329 m_textBaseline = other.m_textBaseline;
330 m_direction = other.m_direction;
328 m_unparsedFont = other.m_unparsedFont; 331 m_unparsedFont = other.m_unparsedFont;
329 m_font = other.m_font; 332 m_font = other.m_font;
330 m_realizedFont = other.m_realizedFont; 333 m_realizedFont = other.m_realizedFont;
331 m_hasClip = other.m_hasClip; 334 m_hasClip = other.m_hasClip;
332 335
333 if (m_realizedFont) 336 if (m_realizedFont)
334 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid ationCallbacks(this); 337 static_cast<CSSFontSelector*>(m_font.fontSelector())->registerForInvalid ationCallbacks(this);
335 338
336 return *this; 339 return *this;
337 } 340 }
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 { 2012 {
2010 TextBaseline baseline; 2013 TextBaseline baseline;
2011 if (!parseTextBaseline(s, baseline)) 2014 if (!parseTextBaseline(s, baseline))
2012 return; 2015 return;
2013 if (state().m_textBaseline == baseline) 2016 if (state().m_textBaseline == baseline)
2014 return; 2017 return;
2015 realizeSaves(); 2018 realizeSaves();
2016 modifiableState().m_textBaseline = baseline; 2019 modifiableState().m_textBaseline = baseline;
2017 } 2020 }
2018 2021
2022 TextDirection CanvasRenderingContext2D::toTextDirection(Direction direction, Ren derStyle*& computedStyle, bool updateRenderTree) const
Stephen White 2014/08/22 17:45:35 I'm not fond of non-const references, although the
Justin Novosad 2014/08/22 18:15:02 Does Blink really need to have an additional enum
vivekg 2014/08/26 11:31:52 We wanted to be explicit with "inherit" hence ende
vivekg 2014/08/26 11:31:52 Done.
2023 {
2024 if (updateRenderTree)
2025 canvas()->document().updateRenderTreeIfNeeded();
2026 computedStyle = canvas()->computedStyle();
2027 switch (direction) {
2028 case Inherit:
2029 return computedStyle ? computedStyle->direction() : LTR;
2030 case Rtl:
2031 return RTL;
2032 case Ltr:
2033 return LTR;
2034 }
2035 ASSERT_NOT_REACHED();
2036 return LTR;
2037 }
2038
2039 String CanvasRenderingContext2D::direction() const
2040 {
2041 RenderStyle* computedStyle = nullptr;
2042 return toTextDirection(state().m_direction, computedStyle) == RTL ? "rtl" : "ltr";
2043 }
2044
2045 void CanvasRenderingContext2D::setDirection(const String& directionString)
2046 {
2047 Direction direction;
2048 if (directionString == "inherit")
2049 direction = Inherit;
2050 else if (directionString == "rtl")
Justin Novosad 2014/08/22 18:15:02 This literal is in more than one place. A constant
vivekg 2014/08/26 11:31:52 Done.
2051 direction = Rtl;
2052 else if (directionString == "ltr")
2053 direction = Ltr;
2054 else
2055 return;
2056
2057 realizeSaves();
2058 modifiableState().m_direction = direction;
2059 }
2060
2019 void CanvasRenderingContext2D::fillText(const String& text, float x, float y) 2061 void CanvasRenderingContext2D::fillText(const String& text, float x, float y)
2020 { 2062 {
2021 drawTextInternal(text, x, y, true); 2063 drawTextInternal(text, x, y, true);
2022 } 2064 }
2023 2065
2024 void CanvasRenderingContext2D::fillText(const String& text, float x, float y, fl oat maxWidth) 2066 void CanvasRenderingContext2D::fillText(const String& text, float x, float y, fl oat maxWidth)
2025 { 2067 {
2026 drawTextInternal(text, x, y, true, maxWidth, true); 2068 drawTextInternal(text, x, y, true, maxWidth, true);
2027 } 2069 }
2028 2070
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 return; 2177 return;
2136 2178
2137 FontCachePurgePreventer fontCachePurgePreventer; 2179 FontCachePurgePreventer fontCachePurgePreventer;
2138 2180
2139 const Font& font = accessFont(); 2181 const Font& font = accessFont();
2140 const FontMetrics& fontMetrics = font.fontMetrics(); 2182 const FontMetrics& fontMetrics = font.fontMetrics();
2141 String normalizedText = normalizeSpaces(text); 2183 String normalizedText = normalizeSpaces(text);
2142 2184
2143 // FIXME: Need to turn off font smoothing. 2185 // FIXME: Need to turn off font smoothing.
2144 2186
2145 RenderStyle* computedStyle = canvas()->computedStyle(); 2187 RenderStyle* computedStyle = nullptr;
2146 TextDirection direction = computedStyle ? computedStyle->direction() : LTR; 2188 TextDirection direction = toTextDirection(state().m_direction, computedStyle , false);
Stephen White 2014/08/22 17:45:35 Passing a boolean constant is not self-documenting
vivekg 2014/08/26 11:31:52 Done.
2147 bool isRTL = direction == RTL; 2189 bool isRTL = direction == RTL;
2148 bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : f alse; 2190 bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : f alse;
2149 2191
2150 TextRun textRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direc tion, override, true); 2192 TextRun textRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direc tion, override, true);
2151 // Draw the item text at the correct point. 2193 // Draw the item text at the correct point.
2152 FloatPoint location(x, y + getFontBaseline(fontMetrics)); 2194 FloatPoint location(x, y + getFontBaseline(fontMetrics));
2153 2195
2154 float fontWidth = font.width(TextRun(normalizedText, 0, 0, TextRun::AllowTra ilingExpansion, direction, override)); 2196 float fontWidth = font.width(TextRun(normalizedText, 0, 0, TextRun::AllowTra ilingExpansion, direction, override));
2155 2197
2156 useMaxWidth = (useMaxWidth && maxWidth < fontWidth); 2198 useMaxWidth = (useMaxWidth && maxWidth < fontWidth);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 2486
2445 unsigned CanvasRenderingContext2D::hitRegionsCount() const 2487 unsigned CanvasRenderingContext2D::hitRegionsCount() const
2446 { 2488 {
2447 if (m_hitRegionManager) 2489 if (m_hitRegionManager)
2448 return m_hitRegionManager->getHitRegionsCount(); 2490 return m_hitRegionManager->getHitRegionsCount();
2449 2491
2450 return 0; 2492 return 0;
2451 } 2493 }
2452 2494
2453 } // namespace blink 2495 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/canvas/CanvasRenderingContext2D.h ('k') | Source/core/html/canvas/CanvasRenderingContext2D.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698