Chromium Code Reviews

Side by Side Diff: Source/core/html/HTMLImageElement.cpp

Issue 320253002: Oilpan: Prepare to move ImageLoader and its subclasses to Oilpan heap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed.
5 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2010 Google Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 33 matching lines...)
44 #include "platform/MIMETypeRegistry.h" 44 #include "platform/MIMETypeRegistry.h"
45 45
46 using namespace std; 46 using namespace std;
47 47
48 namespace WebCore { 48 namespace WebCore {
49 49
50 using namespace HTMLNames; 50 using namespace HTMLNames;
51 51
52 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo ol createdByParser) 52 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo ol createdByParser)
53 : HTMLElement(imgTag, document) 53 : HTMLElement(imgTag, document)
54 , m_imageLoader(this) 54 , m_imageLoader(HTMLImageLoader::create(this))
55 , m_compositeOperator(CompositeSourceOver) 55 , m_compositeOperator(CompositeSourceOver)
56 , m_imageDevicePixelRatio(1.0f) 56 , m_imageDevicePixelRatio(1.0f)
57 , m_formWasSetByParser(false) 57 , m_formWasSetByParser(false)
58 , m_elementCreatedByParser(createdByParser) 58 , m_elementCreatedByParser(createdByParser)
59 { 59 {
60 ScriptWrappable::init(this); 60 ScriptWrappable::init(this);
61 if (form && form->inDocument()) { 61 if (form && form->inDocument()) {
62 #if ENABLE(OILPAN) 62 #if ENABLE(OILPAN)
63 m_form = form; 63 m_form = form;
64 #else 64 #else
(...skipping 18 matching lines...)
83 HTMLImageElement::~HTMLImageElement() 83 HTMLImageElement::~HTMLImageElement()
84 { 84 {
85 #if !ENABLE(OILPAN) 85 #if !ENABLE(OILPAN)
86 if (m_form) 86 if (m_form)
87 m_form->disassociate(*this); 87 m_form->disassociate(*this);
88 #endif 88 #endif
89 } 89 }
90 90
91 void HTMLImageElement::trace(Visitor* visitor) 91 void HTMLImageElement::trace(Visitor* visitor)
92 { 92 {
93 visitor->trace(m_imageLoader);
93 visitor->trace(m_form); 94 visitor->trace(m_form);
94 HTMLElement::trace(visitor); 95 HTMLElement::trace(visitor);
95 } 96 }
96 97
97 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo r(Document& document, int width, int height) 98 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo r(Document& document, int width, int height)
98 { 99 {
99 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeRefCountedGarbage Collected(new HTMLImageElement(document)); 100 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeRefCountedGarbage Collected(new HTMLImageElement(document));
100 if (width) 101 if (width)
101 image->setWidth(width); 102 image->setWidth(width);
102 if (height) 103 if (height)
(...skipping 186 matching lines...)
289 HTMLElement::attach(context); 290 HTMLElement::attach(context);
290 291
291 if (renderer() && renderer()->isImage()) { 292 if (renderer() && renderer()->isImage()) {
292 RenderImage* renderImage = toRenderImage(renderer()); 293 RenderImage* renderImage = toRenderImage(renderer());
293 RenderImageResource* renderImageResource = renderImage->imageResource(); 294 RenderImageResource* renderImageResource = renderImage->imageResource();
294 if (renderImageResource->hasImage()) 295 if (renderImageResource->hasImage())
295 return; 296 return;
296 297
297 // If we have no image at all because we have no src attribute, set 298 // If we have no image at all because we have no src attribute, set
298 // image height and width for the alt text instead. 299 // image height and width for the alt text instead.
299 if (!m_imageLoader.image() && !renderImageResource->cachedImage()) 300 if (!imageLoader().image() && !renderImageResource->cachedImage())
300 renderImage->setImageSizeForAltText(); 301 renderImage->setImageSizeForAltText();
301 else 302 else
302 renderImageResource->setImageResource(m_imageLoader.image()); 303 renderImageResource->setImageResource(imageLoader().image());
303 304
304 } 305 }
305 } 306 }
306 307
307 Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode* insertionPoint) 308 Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode* insertionPoint)
308 { 309 {
309 if (!m_formWasSetByParser || insertionPoint->highestAncestorOrSelf() != m_fo rm->highestAncestorOrSelf()) 310 if (!m_formWasSetByParser || insertionPoint->highestAncestorOrSelf() != m_fo rm->highestAncestorOrSelf())
310 resetFormOwner(); 311 resetFormOwner();
311 312
312 bool imageWasModified = false; 313 bool imageWasModified = false;
313 if (RuntimeEnabledFeatures::pictureEnabled()) { 314 if (RuntimeEnabledFeatures::pictureEnabled()) {
314 ImageCandidate candidate = findBestFitImageFromPictureParent(); 315 ImageCandidate candidate = findBestFitImageFromPictureParent();
315 if (!candidate.isEmpty()) { 316 if (!candidate.isEmpty()) {
316 setBestFitURLAndDPRFromImageCandidate(candidate); 317 setBestFitURLAndDPRFromImageCandidate(candidate);
317 imageWasModified = true; 318 imageWasModified = true;
318 } 319 }
319 } 320 }
320 321
321 // If we have been inserted from a renderer-less document, 322 // If we have been inserted from a renderer-less document,
322 // our loader may have not fetched the image, so do it now. 323 // our loader may have not fetched the image, so do it now.
323 if ((insertionPoint->inDocument() && !m_imageLoader.image()) || imageWasModi fied) 324 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi fied)
324 m_imageLoader.updateFromElement(m_elementCreatedByParser ? ImageLoader:: ForceLoadImmediately : ImageLoader::LoadNormally); 325 imageLoader().updateFromElement(m_elementCreatedByParser ? ImageLoader:: ForceLoadImmediately : ImageLoader::LoadNormally);
325 326
326 return HTMLElement::insertedInto(insertionPoint); 327 return HTMLElement::insertedInto(insertionPoint);
327 } 328 }
328 329
329 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) 330 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint)
330 { 331 {
331 if (!m_form || m_form->highestAncestorOrSelf() != highestAncestorOrSelf()) 332 if (!m_form || m_form->highestAncestorOrSelf() != highestAncestorOrSelf())
332 resetFormOwner(); 333 resetFormOwner();
333 HTMLElement::removedFrom(insertionPoint); 334 HTMLElement::removedFrom(insertionPoint);
334 } 335 }
335 336
336 int HTMLImageElement::width(bool ignorePendingStylesheets) 337 int HTMLImageElement::width(bool ignorePendingStylesheets)
337 { 338 {
338 if (!renderer()) { 339 if (!renderer()) {
339 // check the attribute first for an explicit pixel value 340 // check the attribute first for an explicit pixel value
340 bool ok; 341 bool ok;
341 int width = getAttribute(widthAttr).toInt(&ok); 342 int width = getAttribute(widthAttr).toInt(&ok);
342 if (ok) 343 if (ok)
343 return width; 344 return width;
344 345
345 // if the image is available, use its width 346 // if the image is available, use its width
346 if (m_imageLoader.image()) 347 if (imageLoader().image())
347 return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f) .width(); 348 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f) .width();
348 } 349 }
349 350
350 if (ignorePendingStylesheets) 351 if (ignorePendingStylesheets)
351 document().updateLayoutIgnorePendingStylesheets(); 352 document().updateLayoutIgnorePendingStylesheets();
352 else 353 else
353 document().updateLayout(); 354 document().updateLayout();
354 355
355 RenderBox* box = renderBox(); 356 RenderBox* box = renderBox();
356 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth() , box) : 0; 357 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth() , box) : 0;
357 } 358 }
358 359
359 int HTMLImageElement::height(bool ignorePendingStylesheets) 360 int HTMLImageElement::height(bool ignorePendingStylesheets)
360 { 361 {
361 if (!renderer()) { 362 if (!renderer()) {
362 // check the attribute first for an explicit pixel value 363 // check the attribute first for an explicit pixel value
363 bool ok; 364 bool ok;
364 int height = getAttribute(heightAttr).toInt(&ok); 365 int height = getAttribute(heightAttr).toInt(&ok);
365 if (ok) 366 if (ok)
366 return height; 367 return height;
367 368
368 // if the image is available, use its height 369 // if the image is available, use its height
369 if (m_imageLoader.image()) 370 if (imageLoader().image())
370 return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f) .height(); 371 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f) .height();
371 } 372 }
372 373
373 if (ignorePendingStylesheets) 374 if (ignorePendingStylesheets)
374 document().updateLayoutIgnorePendingStylesheets(); 375 document().updateLayoutIgnorePendingStylesheets();
375 else 376 else
376 document().updateLayout(); 377 document().updateLayout();
377 378
378 RenderBox* box = renderBox(); 379 RenderBox* box = renderBox();
379 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight( ), box) : 0; 380 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight( ), box) : 0;
380 } 381 }
381 382
382 int HTMLImageElement::naturalWidth() const 383 int HTMLImageElement::naturalWidth() const
383 { 384 {
384 if (!m_imageLoader.image()) 385 if (!imageLoader().image())
385 return 0; 386 return 0;
386 387
387 return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f).width() ; 388 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f).width() ;
388 } 389 }
389 390
390 int HTMLImageElement::naturalHeight() const 391 int HTMLImageElement::naturalHeight() const
391 { 392 {
392 if (!m_imageLoader.image()) 393 if (!imageLoader().image())
393 return 0; 394 return 0;
394 395
395 return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f).height( ); 396 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f).height( );
396 } 397 }
397 398
398 const AtomicString& HTMLImageElement::currentSrc() const 399 const AtomicString& HTMLImageElement::currentSrc() const
399 { 400 {
400 return m_currentSrc; 401 return m_currentSrc;
401 } 402 }
402 403
403 bool HTMLImageElement::isURLAttribute(const Attribute& attribute) const 404 bool HTMLImageElement::isURLAttribute(const Attribute& attribute) const
404 { 405 {
405 return attribute.name() == srcAttr 406 return attribute.name() == srcAttr
(...skipping 61 matching lines...)
467 if (!r) 468 if (!r)
468 return 0; 469 return 0;
469 470
470 // FIXME: This doesn't work correctly with transforms. 471 // FIXME: This doesn't work correctly with transforms.
471 FloatPoint absPos = r->localToAbsolute(); 472 FloatPoint absPos = r->localToAbsolute();
472 return absPos.y(); 473 return absPos.y();
473 } 474 }
474 475
475 bool HTMLImageElement::complete() const 476 bool HTMLImageElement::complete() const
476 { 477 {
477 return m_imageLoader.imageComplete(); 478 return imageLoader().imageComplete();
478 } 479 }
479 480
480 void HTMLImageElement::didMoveToNewDocument(Document& oldDocument) 481 void HTMLImageElement::didMoveToNewDocument(Document& oldDocument)
481 { 482 {
482 m_imageLoader.elementDidMoveToNewDocument(); 483 imageLoader().elementDidMoveToNewDocument();
483 HTMLElement::didMoveToNewDocument(oldDocument); 484 HTMLElement::didMoveToNewDocument(oldDocument);
484 } 485 }
485 486
486 bool HTMLImageElement::isServerMap() const 487 bool HTMLImageElement::isServerMap() const
487 { 488 {
488 if (!fastHasAttribute(ismapAttr)) 489 if (!fastHasAttribute(ismapAttr))
489 return false; 490 return false;
490 491
491 const AtomicString& usemap = fastGetAttribute(usemapAttr); 492 const AtomicString& usemap = fastGetAttribute(usemapAttr);
492 493
493 // If the usemap attribute starts with '#', it refers to a map element in th e document. 494 // If the usemap attribute starts with '#', it refers to a map element in th e document.
494 if (usemap.string()[0] == '#') 495 if (usemap.string()[0] == '#')
495 return false; 496 return false;
496 497
497 return document().completeURL(stripLeadingAndTrailingHTMLSpaces(usemap)).isE mpty(); 498 return document().completeURL(stripLeadingAndTrailingHTMLSpaces(usemap)).isE mpty();
498 } 499 }
499 500
500 Image* HTMLImageElement::imageContents() 501 Image* HTMLImageElement::imageContents()
501 { 502 {
502 if (!m_imageLoader.imageComplete()) 503 if (!imageLoader().imageComplete())
503 return 0; 504 return 0;
504 505
505 return m_imageLoader.image()->image(); 506 return imageLoader().image()->image();
506 } 507 }
507 508
508 bool HTMLImageElement::isInteractiveContent() const 509 bool HTMLImageElement::isInteractiveContent() const
509 { 510 {
510 return fastHasAttribute(usemapAttr); 511 return fastHasAttribute(usemapAttr);
511 } 512 }
512 513
513 PassRefPtr<Image> HTMLImageElement::getSourceImageForCanvas(SourceImageMode, Sou rceImageStatus* status) const 514 PassRefPtr<Image> HTMLImageElement::getSourceImageForCanvas(SourceImageMode, Sou rceImageStatus* status) const
514 { 515 {
515 if (!complete() || !cachedImage()) { 516 if (!complete() || !cachedImage()) {
(...skipping 59 matching lines...)
575 } 576 }
576 577
577 if (!foundURL) { 578 if (!foundURL) {
578 unsigned effectiveSize = 0; 579 unsigned effectiveSize = 0;
579 if (RuntimeEnabledFeatures::pictureSizesEnabled()) 580 if (RuntimeEnabledFeatures::pictureSizesEnabled())
580 effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttri bute(sizesAttr), MediaValuesCached::create(document())); 581 effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttri bute(sizesAttr), MediaValuesCached::create(document()));
581 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src setAttr)); 582 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src setAttr));
582 setBestFitURLAndDPRFromImageCandidate(candidate); 583 setBestFitURLAndDPRFromImageCandidate(candidate);
583 } 584 }
584 if (behavior == UpdateIgnorePreviousError) 585 if (behavior == UpdateIgnorePreviousError)
585 m_imageLoader.updateFromElementIgnoringPreviousError(); 586 imageLoader().updateFromElementIgnoringPreviousError();
586 else 587 else
587 m_imageLoader.updateFromElement(); 588 imageLoader().updateFromElement();
588 } 589 }
589 590
590 const KURL& HTMLImageElement::sourceURL() const 591 const KURL& HTMLImageElement::sourceURL() const
591 { 592 {
592 return cachedImage()->response().url(); 593 return cachedImage()->response().url();
593 } 594 }
594 595
595 } 596 }
OLDNEW

Powered by Google App Engine