| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Firefox limits width/height to 32767 pixels, but slows down dramatically befo
re it | 64 // Firefox limits width/height to 32767 pixels, but slows down dramatically befo
re it |
| 65 // reaches that limit. We limit by area instead, giving us larger maximum dimens
ions, | 65 // reaches that limit. We limit by area instead, giving us larger maximum dimens
ions, |
| 66 // in exchange for a smaller maximum canvas size. | 66 // in exchange for a smaller maximum canvas size. |
| 67 static const float MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS p
ixels | 67 static const float MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS p
ixels |
| 68 | 68 |
| 69 //In Skia, we will also limit width/height to 32767. | 69 //In Skia, we will also limit width/height to 32767. |
| 70 static const float MaxSkiaDim = 32767.0F; // Maximum width/height in CSS pixels. | 70 static const float MaxSkiaDim = 32767.0F; // Maximum width/height in CSS pixels. |
| 71 | 71 |
| 72 HTMLCanvasElement::HTMLCanvasElement(const QualifiedName& tagName, Document* doc
ument) | 72 HTMLCanvasElement::HTMLCanvasElement(const QualifiedName& tagName, Document* doc
ument) |
| 73 : HTMLElement(tagName, document) | 73 : HTMLElement(tagName, document) |
| 74 , m_observer(0) | |
| 75 , m_size(DefaultWidth, DefaultHeight) | 74 , m_size(DefaultWidth, DefaultHeight) |
| 76 , m_ignoreReset(false) | 75 , m_ignoreReset(false) |
| 77 , m_pageScaleFactor(document->frame() ? document->frame()->page()->chrome()-
>scaleFactor() : 1) | 76 , m_pageScaleFactor(document->frame() ? document->frame()->page()->chrome()-
>scaleFactor() : 1) |
| 78 , m_originClean(true) | 77 , m_originClean(true) |
| 79 , m_hasCreatedImageBuffer(false) | 78 , m_hasCreatedImageBuffer(false) |
| 80 { | 79 { |
| 81 ASSERT(hasTagName(canvasTag)); | 80 ASSERT(hasTagName(canvasTag)); |
| 82 } | 81 } |
| 83 | 82 |
| 84 PassRefPtr<HTMLCanvasElement> HTMLCanvasElement::create(Document* document) | 83 PassRefPtr<HTMLCanvasElement> HTMLCanvasElement::create(Document* document) |
| 85 { | 84 { |
| 86 return adoptRef(new HTMLCanvasElement(canvasTag, document)); | 85 return adoptRef(new HTMLCanvasElement(canvasTag, document)); |
| 87 } | 86 } |
| 88 | 87 |
| 89 PassRefPtr<HTMLCanvasElement> HTMLCanvasElement::create(const QualifiedName& tag
Name, Document* document) | 88 PassRefPtr<HTMLCanvasElement> HTMLCanvasElement::create(const QualifiedName& tag
Name, Document* document) |
| 90 { | 89 { |
| 91 return adoptRef(new HTMLCanvasElement(tagName, document)); | 90 return adoptRef(new HTMLCanvasElement(tagName, document)); |
| 92 } | 91 } |
| 93 | 92 |
| 94 HTMLCanvasElement::~HTMLCanvasElement() | 93 HTMLCanvasElement::~HTMLCanvasElement() |
| 95 { | 94 { |
| 96 if (m_observer) | 95 HashSet<CanvasObserver*>::iterator end = m_observers.end(); |
| 97 m_observer->canvasDestroyed(this); | 96 for (HashSet<CanvasObserver*>::iterator it = m_observers.begin(); it != end;
++it) |
| 97 (*it)->canvasDestroyed(this); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void HTMLCanvasElement::parseMappedAttribute(Attribute* attr) | 100 void HTMLCanvasElement::parseMappedAttribute(Attribute* attr) |
| 101 { | 101 { |
| 102 const QualifiedName& attrName = attr->name(); | 102 const QualifiedName& attrName = attr->name(); |
| 103 if (attrName == widthAttr || attrName == heightAttr) | 103 if (attrName == widthAttr || attrName == heightAttr) |
| 104 reset(); | 104 reset(); |
| 105 HTMLElement::parseMappedAttribute(attr); | 105 HTMLElement::parseMappedAttribute(attr); |
| 106 } | 106 } |
| 107 | 107 |
| 108 RenderObject* HTMLCanvasElement::createRenderer(RenderArena* arena, RenderStyle*
style) | 108 RenderObject* HTMLCanvasElement::createRenderer(RenderArena* arena, RenderStyle*
style) |
| 109 { | 109 { |
| 110 Frame* frame = document()->frame(); | 110 Frame* frame = document()->frame(); |
| 111 if (frame && frame->script()->canExecuteScripts(NotAboutToExecuteScript)) { | 111 if (frame && frame->script()->canExecuteScripts(NotAboutToExecuteScript)) { |
| 112 m_rendererIsCanvas = true; | 112 m_rendererIsCanvas = true; |
| 113 return new (arena) RenderHTMLCanvas(this); | 113 return new (arena) RenderHTMLCanvas(this); |
| 114 } | 114 } |
| 115 | 115 |
| 116 m_rendererIsCanvas = false; | 116 m_rendererIsCanvas = false; |
| 117 return HTMLElement::createRenderer(arena, style); | 117 return HTMLElement::createRenderer(arena, style); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void HTMLCanvasElement::addObserver(CanvasObserver* observer) |
| 121 { |
| 122 m_observers.add(observer); |
| 123 } |
| 124 |
| 125 void HTMLCanvasElement::removeObserver(CanvasObserver* observer) |
| 126 { |
| 127 m_observers.remove(observer); |
| 128 } |
| 129 |
| 120 void HTMLCanvasElement::setHeight(int value) | 130 void HTMLCanvasElement::setHeight(int value) |
| 121 { | 131 { |
| 122 setAttribute(heightAttr, String::number(value)); | 132 setAttribute(heightAttr, String::number(value)); |
| 123 } | 133 } |
| 124 | 134 |
| 125 void HTMLCanvasElement::setWidth(int value) | 135 void HTMLCanvasElement::setWidth(int value) |
| 126 { | 136 { |
| 127 setAttribute(widthAttr, String::number(value)); | 137 setAttribute(widthAttr, String::number(value)); |
| 128 } | 138 } |
| 129 | 139 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 FloatRect destRect = ro->contentBoxRect(); | 203 FloatRect destRect = ro->contentBoxRect(); |
| 194 FloatRect r = mapRect(rect, FloatRect(0, 0, size().width(), size().heigh
t()), destRect); | 204 FloatRect r = mapRect(rect, FloatRect(0, 0, size().width(), size().heigh
t()), destRect); |
| 195 r.intersect(destRect); | 205 r.intersect(destRect); |
| 196 if (r.isEmpty() || m_dirtyRect.contains(r)) | 206 if (r.isEmpty() || m_dirtyRect.contains(r)) |
| 197 return; | 207 return; |
| 198 | 208 |
| 199 m_dirtyRect.unite(r); | 209 m_dirtyRect.unite(r); |
| 200 ro->repaintRectangle(enclosingIntRect(m_dirtyRect)); | 210 ro->repaintRectangle(enclosingIntRect(m_dirtyRect)); |
| 201 } | 211 } |
| 202 | 212 |
| 203 if (m_observer) | 213 HashSet<CanvasObserver*>::iterator end = m_observers.end(); |
| 204 m_observer->canvasChanged(this, rect); | 214 for (HashSet<CanvasObserver*>::iterator it = m_observers.begin(); it != end;
++it) |
| 215 (*it)->canvasChanged(this, rect); |
| 205 } | 216 } |
| 206 | 217 |
| 207 void HTMLCanvasElement::reset() | 218 void HTMLCanvasElement::reset() |
| 208 { | 219 { |
| 209 if (m_ignoreReset) | 220 if (m_ignoreReset) |
| 210 return; | 221 return; |
| 211 | 222 |
| 212 bool ok; | 223 bool ok; |
| 213 bool hadImageBuffer = hasCreatedImageBuffer(); | 224 bool hadImageBuffer = hasCreatedImageBuffer(); |
| 214 int w = getAttribute(widthAttr).toInt(&ok); | 225 int w = getAttribute(widthAttr).toInt(&ok); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 231 | 242 |
| 232 if (RenderObject* renderer = this->renderer()) { | 243 if (RenderObject* renderer = this->renderer()) { |
| 233 if (m_rendererIsCanvas) { | 244 if (m_rendererIsCanvas) { |
| 234 if (oldSize != size()) | 245 if (oldSize != size()) |
| 235 toRenderHTMLCanvas(renderer)->canvasSizeChanged(); | 246 toRenderHTMLCanvas(renderer)->canvasSizeChanged(); |
| 236 if (hadImageBuffer) | 247 if (hadImageBuffer) |
| 237 renderer->repaint(); | 248 renderer->repaint(); |
| 238 } | 249 } |
| 239 } | 250 } |
| 240 | 251 |
| 241 if (m_observer) | 252 HashSet<CanvasObserver*>::iterator end = m_observers.end(); |
| 242 m_observer->canvasResized(this); | 253 for (HashSet<CanvasObserver*>::iterator it = m_observers.begin(); it != end;
++it) |
| 254 (*it)->canvasResized(this); |
| 243 } | 255 } |
| 244 | 256 |
| 245 void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r) | 257 void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r) |
| 246 { | 258 { |
| 247 // Clear the dirty rect | 259 // Clear the dirty rect |
| 248 m_dirtyRect = FloatRect(); | 260 m_dirtyRect = FloatRect(); |
| 249 | 261 |
| 250 if (context->paintingDisabled()) | 262 if (context->paintingDisabled()) |
| 251 return; | 263 return; |
| 252 | 264 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 FloatSize unscaledSize(width(), height()); | 428 FloatSize unscaledSize(width(), height()); |
| 417 IntSize size = convertLogicalToDevice(unscaledSize); | 429 IntSize size = convertLogicalToDevice(unscaledSize); |
| 418 AffineTransform transform; | 430 AffineTransform transform; |
| 419 if (size.width() && size.height()) | 431 if (size.width() && size.height()) |
| 420 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig
ht() / unscaledSize.height()); | 432 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig
ht() / unscaledSize.height()); |
| 421 transform.multiply(m_imageBuffer->baseTransform()); | 433 transform.multiply(m_imageBuffer->baseTransform()); |
| 422 return transform; | 434 return transform; |
| 423 } | 435 } |
| 424 | 436 |
| 425 } | 437 } |
| OLD | NEW |