| OLD | NEW |
| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 m_bestFitImageURL = candidate.url(); | 243 m_bestFitImageURL = candidate.url(); |
| 244 float candidateDensity = candidate.density(); | 244 float candidateDensity = candidate.density(); |
| 245 if (candidateDensity >= 0) | 245 if (candidateDensity >= 0) |
| 246 m_imageDevicePixelRatio = 1.0 / candidateDensity; | 246 m_imageDevicePixelRatio = 1.0 / candidateDensity; |
| 247 if (candidate.resourceWidth() > 0) { | 247 if (candidate.resourceWidth() > 0) { |
| 248 m_intrinsicSizingViewportDependant = true; | 248 m_intrinsicSizingViewportDependant = true; |
| 249 UseCounter::count(document(), UseCounter::SrcsetWDescriptor); | 249 UseCounter::count(document(), UseCounter::SrcsetWDescriptor); |
| 250 } else if (!candidate.srcOrigin()) { | 250 } else if (!candidate.srcOrigin()) { |
| 251 UseCounter::count(document(), UseCounter::SrcsetXDescriptor); | 251 UseCounter::count(document(), UseCounter::SrcsetXDescriptor); |
| 252 } | 252 } |
| 253 if (renderer() && renderer()->isImage()) | 253 if (layoutObject() && layoutObject()->isImage()) |
| 254 toLayoutImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRa
tio); | 254 toLayoutImage(layoutObject())->setImageDevicePixelRatio(m_imageDevicePix
elRatio); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) | 257 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) |
| 258 { | 258 { |
| 259 if (name == altAttr || name == titleAttr) { | 259 if (name == altAttr || name == titleAttr) { |
| 260 if (closedShadowRoot()) { | 260 if (closedShadowRoot()) { |
| 261 Element* text = closedShadowRoot()->getElementById("alttext"); | 261 Element* text = closedShadowRoot()->getElementById("alttext"); |
| 262 String value = altText(); | 262 String value = altText(); |
| 263 if (text && text->textContent() != value) | 263 if (text && text->textContent() != value) |
| 264 text->setTextContent(altText()); | 264 text->setTextContent(altText()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 LayoutImage* image = new LayoutImage(this); | 344 LayoutImage* image = new LayoutImage(this); |
| 345 image->setImageResource(LayoutImageResource::create()); | 345 image->setImageResource(LayoutImageResource::create()); |
| 346 image->setImageDevicePixelRatio(m_imageDevicePixelRatio); | 346 image->setImageDevicePixelRatio(m_imageDevicePixelRatio); |
| 347 return image; | 347 return image; |
| 348 } | 348 } |
| 349 | 349 |
| 350 void HTMLImageElement::attach(const AttachContext& context) | 350 void HTMLImageElement::attach(const AttachContext& context) |
| 351 { | 351 { |
| 352 HTMLElement::attach(context); | 352 HTMLElement::attach(context); |
| 353 | 353 |
| 354 if (renderer() && renderer()->isImage()) { | 354 if (layoutObject() && layoutObject()->isImage()) { |
| 355 LayoutImage* layoutImage = toLayoutImage(renderer()); | 355 LayoutImage* layoutImage = toLayoutImage(layoutObject()); |
| 356 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); | 356 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); |
| 357 if (m_isFallbackImage) { | 357 if (m_isFallbackImage) { |
| 358 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->fram
e()); | 358 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->fram
e()); |
| 359 pair<Image*, float> brokenImageAndImageScaleFactor = ImageResource::
brokenImage(deviceScaleFactor); | 359 pair<Image*, float> brokenImageAndImageScaleFactor = ImageResource::
brokenImage(deviceScaleFactor); |
| 360 ImageResource* newImageResource = new ImageResource(brokenImageAndIm
ageScaleFactor.first); | 360 ImageResource* newImageResource = new ImageResource(brokenImageAndIm
ageScaleFactor.first); |
| 361 layoutImage->imageResource()->setImageResource(newImageResource); | 361 layoutImage->imageResource()->setImageResource(newImageResource); |
| 362 } | 362 } |
| 363 if (layoutImageResource->hasImage()) | 363 if (layoutImageResource->hasImage()) |
| 364 return; | 364 return; |
| 365 | 365 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 { | 397 { |
| 398 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr
aversal::highestAncestorOrSelf(*this)) | 398 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr
aversal::highestAncestorOrSelf(*this)) |
| 399 resetFormOwner(); | 399 resetFormOwner(); |
| 400 if (m_listener) | 400 if (m_listener) |
| 401 document().mediaQueryMatcher().removeViewportListener(m_listener); | 401 document().mediaQueryMatcher().removeViewportListener(m_listener); |
| 402 HTMLElement::removedFrom(insertionPoint); | 402 HTMLElement::removedFrom(insertionPoint); |
| 403 } | 403 } |
| 404 | 404 |
| 405 int HTMLImageElement::width(bool ignorePendingStylesheets) | 405 int HTMLImageElement::width(bool ignorePendingStylesheets) |
| 406 { | 406 { |
| 407 if (!renderer()) { | 407 if (!layoutObject()) { |
| 408 // check the attribute first for an explicit pixel value | 408 // check the attribute first for an explicit pixel value |
| 409 bool ok; | 409 bool ok; |
| 410 int width = getAttribute(widthAttr).toInt(&ok); | 410 int width = getAttribute(widthAttr).toInt(&ok); |
| 411 if (ok) | 411 if (ok) |
| 412 return width; | 412 return width; |
| 413 | 413 |
| 414 // if the image is available, use its width | 414 // if the image is available, use its width |
| 415 if (imageLoader().image()) | 415 if (imageLoader().image()) |
| 416 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f)
.width(); | 416 return imageLoader().image()->imageSizeForRenderer(layoutObject(), 1
.0f).width(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 if (ignorePendingStylesheets) | 419 if (ignorePendingStylesheets) |
| 420 document().updateLayoutIgnorePendingStylesheets(); | 420 document().updateLayoutIgnorePendingStylesheets(); |
| 421 else | 421 else |
| 422 document().updateLayout(); | 422 document().updateLayout(); |
| 423 | 423 |
| 424 LayoutBox* box = layoutBox(); | 424 LayoutBox* box = layoutBox(); |
| 425 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth()
, box) : 0; | 425 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth()
, box) : 0; |
| 426 } | 426 } |
| 427 | 427 |
| 428 int HTMLImageElement::height(bool ignorePendingStylesheets) | 428 int HTMLImageElement::height(bool ignorePendingStylesheets) |
| 429 { | 429 { |
| 430 if (!renderer()) { | 430 if (!layoutObject()) { |
| 431 // check the attribute first for an explicit pixel value | 431 // check the attribute first for an explicit pixel value |
| 432 bool ok; | 432 bool ok; |
| 433 int height = getAttribute(heightAttr).toInt(&ok); | 433 int height = getAttribute(heightAttr).toInt(&ok); |
| 434 if (ok) | 434 if (ok) |
| 435 return height; | 435 return height; |
| 436 | 436 |
| 437 // if the image is available, use its height | 437 // if the image is available, use its height |
| 438 if (imageLoader().image()) | 438 if (imageLoader().image()) |
| 439 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f)
.height(); | 439 return imageLoader().image()->imageSizeForRenderer(layoutObject(), 1
.0f).height(); |
| 440 } | 440 } |
| 441 | 441 |
| 442 if (ignorePendingStylesheets) | 442 if (ignorePendingStylesheets) |
| 443 document().updateLayoutIgnorePendingStylesheets(); | 443 document().updateLayoutIgnorePendingStylesheets(); |
| 444 else | 444 else |
| 445 document().updateLayout(); | 445 document().updateLayout(); |
| 446 | 446 |
| 447 LayoutBox* box = layoutBox(); | 447 LayoutBox* box = layoutBox(); |
| 448 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight(
), box) : 0; | 448 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight(
), box) : 0; |
| 449 } | 449 } |
| 450 | 450 |
| 451 int HTMLImageElement::naturalWidth() const | 451 int HTMLImageElement::naturalWidth() const |
| 452 { | 452 { |
| 453 if (!imageLoader().image()) | 453 if (!imageLoader().image()) |
| 454 return 0; | 454 return 0; |
| 455 | 455 |
| 456 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f, ImageRe
source::IntrinsicSize).width(); | 456 return imageLoader().image()->imageSizeForRenderer(layoutObject(), 1.0f, Ima
geResource::IntrinsicSize).width(); |
| 457 } | 457 } |
| 458 | 458 |
| 459 int HTMLImageElement::naturalHeight() const | 459 int HTMLImageElement::naturalHeight() const |
| 460 { | 460 { |
| 461 if (!imageLoader().image()) | 461 if (!imageLoader().image()) |
| 462 return 0; | 462 return 0; |
| 463 | 463 |
| 464 return imageLoader().image()->imageSizeForRenderer(renderer(), 1.0f, ImageRe
source::IntrinsicSize).height(); | 464 return imageLoader().image()->imageSizeForRenderer(layoutObject(), 1.0f, Ima
geResource::IntrinsicSize).height(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 const String& HTMLImageElement::currentSrc() const | 467 const String& HTMLImageElement::currentSrc() const |
| 468 { | 468 { |
| 469 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#do
m-img-currentsrc | 469 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#do
m-img-currentsrc |
| 470 // The currentSrc IDL attribute must return the img element's current reques
t's current URL. | 470 // The currentSrc IDL attribute must return the img element's current reques
t's current URL. |
| 471 // Initially, the pending request turns into current request when it is eith
er available or broken. | 471 // Initially, the pending request turns into current request when it is eith
er available or broken. |
| 472 // We use the image's dimensions as a proxy to it being in any of these stat
es. | 472 // We use the image's dimensions as a proxy to it being in any of these stat
es. |
| 473 if (!imageLoader().image() || !imageLoader().image()->image() || !imageLoade
r().image()->image()->width()) | 473 if (!imageLoader().image() || !imageLoader().image()->image() || !imageLoade
r().image()->image()->width()) |
| 474 return emptyAtom; | 474 return emptyAtom; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 517 } |
| 518 | 518 |
| 519 void HTMLImageElement::setWidth(int value) | 519 void HTMLImageElement::setWidth(int value) |
| 520 { | 520 { |
| 521 setIntegralAttribute(widthAttr, value); | 521 setIntegralAttribute(widthAttr, value); |
| 522 } | 522 } |
| 523 | 523 |
| 524 int HTMLImageElement::x() const | 524 int HTMLImageElement::x() const |
| 525 { | 525 { |
| 526 document().updateLayoutIgnorePendingStylesheets(); | 526 document().updateLayoutIgnorePendingStylesheets(); |
| 527 LayoutObject* r = renderer(); | 527 LayoutObject* r = layoutObject(); |
| 528 if (!r) | 528 if (!r) |
| 529 return 0; | 529 return 0; |
| 530 | 530 |
| 531 // FIXME: This doesn't work correctly with transforms. | 531 // FIXME: This doesn't work correctly with transforms. |
| 532 FloatPoint absPos = r->localToAbsolute(); | 532 FloatPoint absPos = r->localToAbsolute(); |
| 533 return absPos.x(); | 533 return absPos.x(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 int HTMLImageElement::y() const | 536 int HTMLImageElement::y() const |
| 537 { | 537 { |
| 538 document().updateLayoutIgnorePendingStylesheets(); | 538 document().updateLayoutIgnorePendingStylesheets(); |
| 539 LayoutObject* r = renderer(); | 539 LayoutObject* r = layoutObject(); |
| 540 if (!r) | 540 if (!r) |
| 541 return 0; | 541 return 0; |
| 542 | 542 |
| 543 // FIXME: This doesn't work correctly with transforms. | 543 // FIXME: This doesn't work correctly with transforms. |
| 544 FloatPoint absPos = r->localToAbsolute(); | 544 FloatPoint absPos = r->localToAbsolute(); |
| 545 return absPos.y(); | 545 return absPos.y(); |
| 546 } | 546 } |
| 547 | 547 |
| 548 bool HTMLImageElement::complete() const | 548 bool HTMLImageElement::complete() const |
| 549 { | 549 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 if (!complete() || !cachedImage()) { | 589 if (!complete() || !cachedImage()) { |
| 590 *status = IncompleteSourceImageStatus; | 590 *status = IncompleteSourceImageStatus; |
| 591 return nullptr; | 591 return nullptr; |
| 592 } | 592 } |
| 593 | 593 |
| 594 if (cachedImage()->errorOccurred()) { | 594 if (cachedImage()->errorOccurred()) { |
| 595 *status = UndecodableSourceImageStatus; | 595 *status = UndecodableSourceImageStatus; |
| 596 return nullptr; | 596 return nullptr; |
| 597 } | 597 } |
| 598 | 598 |
| 599 RefPtr<Image> sourceImage = cachedImage()->imageForRenderer(renderer()); | 599 RefPtr<Image> sourceImage = cachedImage()->imageForRenderer(layoutObject()); |
| 600 | 600 |
| 601 // We need to synthesize a container size if a renderer is not available to
provide one. | 601 // We need to synthesize a container size if a renderer is not available to
provide one. |
| 602 if (!renderer() && sourceImage->usesContainerSize()) | 602 if (!layoutObject() && sourceImage->usesContainerSize()) |
| 603 sourceImage->setContainerSize(sourceImage->size()); | 603 sourceImage->setContainerSize(sourceImage->size()); |
| 604 | 604 |
| 605 *status = NormalSourceImageStatus; | 605 *status = NormalSourceImageStatus; |
| 606 return sourceImage->imageForDefaultFrame(); | 606 return sourceImage->imageForDefaultFrame(); |
| 607 } | 607 } |
| 608 | 608 |
| 609 bool HTMLImageElement::wouldTaintOrigin(SecurityOrigin* destinationSecurityOrigi
n) const | 609 bool HTMLImageElement::wouldTaintOrigin(SecurityOrigin* destinationSecurityOrigi
n) const |
| 610 { | 610 { |
| 611 ImageResource* image = cachedImage(); | 611 ImageResource* image = cachedImage(); |
| 612 if (!image) | 612 if (!image) |
| 613 return false; | 613 return false; |
| 614 return !image->isAccessAllowed(&document(), destinationSecurityOrigin); | 614 return !image->isAccessAllowed(&document(), destinationSecurityOrigin); |
| 615 } | 615 } |
| 616 | 616 |
| 617 FloatSize HTMLImageElement::sourceSize() const | 617 FloatSize HTMLImageElement::sourceSize() const |
| 618 { | 618 { |
| 619 ImageResource* image = cachedImage(); | 619 ImageResource* image = cachedImage(); |
| 620 if (!image) | 620 if (!image) |
| 621 return FloatSize(); | 621 return FloatSize(); |
| 622 | 622 |
| 623 return FloatSize(image->imageSizeForRenderer(renderer(), 1.0f)); | 623 return FloatSize(image->imageSizeForRenderer(layoutObject(), 1.0f)); |
| 624 } | 624 } |
| 625 | 625 |
| 626 FloatSize HTMLImageElement::defaultDestinationSize() const | 626 FloatSize HTMLImageElement::defaultDestinationSize() const |
| 627 { | 627 { |
| 628 ImageResource* image = cachedImage(); | 628 ImageResource* image = cachedImage(); |
| 629 if (!image) | 629 if (!image) |
| 630 return FloatSize(); | 630 return FloatSize(); |
| 631 LayoutSize size; | 631 LayoutSize size; |
| 632 size = image->imageSizeForRenderer(renderer(), 1.0f); | 632 size = image->imageSizeForRenderer(layoutObject(), 1.0f); |
| 633 if (renderer() && renderer()->isLayoutImage() && image->image() && !image->i
mage()->hasRelativeWidth()) | 633 if (layoutObject() && layoutObject()->isLayoutImage() && image->image() && !
image->image()->hasRelativeWidth()) |
| 634 size.scale(toLayoutImage(renderer())->imageDevicePixelRatio()); | 634 size.scale(toLayoutImage(layoutObject())->imageDevicePixelRatio()); |
| 635 return FloatSize(size); | 635 return FloatSize(size); |
| 636 } | 636 } |
| 637 | 637 |
| 638 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be
havior) | 638 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be
havior) |
| 639 { | 639 { |
| 640 if (!document().isActive()) | 640 if (!document().isActive()) |
| 641 return; | 641 return; |
| 642 | 642 |
| 643 bool foundURL = false; | 643 bool foundURL = false; |
| 644 if (RuntimeEnabledFeatures::pictureEnabled()) { | 644 if (RuntimeEnabledFeatures::pictureEnabled()) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 ensureClosedShadowRoot(); | 726 ensureClosedShadowRoot(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 bool HTMLImageElement::isOpaque() const | 729 bool HTMLImageElement::isOpaque() const |
| 730 { | 730 { |
| 731 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); | 731 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); |
| 732 return image && image->currentFrameKnownToBeOpaque(); | 732 return image && image->currentFrameKnownToBeOpaque(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 } | 735 } |
| OLD | NEW |