Chromium Code Reviews| 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 if (m_listener) | 395 if (m_listener) |
| 396 document().mediaQueryMatcher().removeViewportListener(m_listener); | 396 document().mediaQueryMatcher().removeViewportListener(m_listener); |
| 397 HTMLElement::removedFrom(insertionPoint); | 397 HTMLElement::removedFrom(insertionPoint); |
| 398 } | 398 } |
| 399 | 399 |
| 400 int HTMLImageElement::width(bool ignorePendingStylesheets) | 400 int HTMLImageElement::width(bool ignorePendingStylesheets) |
| 401 { | 401 { |
| 402 if (!layoutObject()) { | 402 if (!layoutObject()) { |
| 403 // check the attribute first for an explicit pixel value | 403 // check the attribute first for an explicit pixel value |
| 404 bool ok; | 404 bool ok; |
| 405 // TODO(yoav): That seems buggy when width is provided with a '%'. | |
|
igrigorik
2015/06/17 17:26:28
Per spec, it's CSS px only: http://www.w3.org/html
Mike West
2015/06/18 06:20:04
Is there a bug we could point to here?
Yoav Weiss
2015/06/18 06:30:22
I'll open one, once I make sure this is an actual
Yoav Weiss
2015/06/18 09:19:27
Seems to be returning the calculated width after l
| |
| 405 int width = getAttribute(widthAttr).toInt(&ok); | 406 int width = getAttribute(widthAttr).toInt(&ok); |
| 406 if (ok) | 407 if (ok) |
| 407 return width; | 408 return width; |
| 408 | 409 |
| 409 // if the image is available, use its width | 410 // if the image is available, use its width |
| 410 if (imageLoader().image()) | 411 if (imageLoader().image()) |
| 411 return imageLoader().image()->imageSizeForLayoutObject(layoutObject( ), 1.0f).width(); | 412 return imageLoader().image()->imageSizeForLayoutObject(layoutObject( ), 1.0f).width(); |
| 412 } | 413 } |
| 413 | 414 |
| 414 if (ignorePendingStylesheets) | 415 if (ignorePendingStylesheets) |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 ImageResource* image = cachedImage(); | 624 ImageResource* image = cachedImage(); |
| 624 if (!image) | 625 if (!image) |
| 625 return FloatSize(); | 626 return FloatSize(); |
| 626 LayoutSize size; | 627 LayoutSize size; |
| 627 size = image->imageSizeForLayoutObject(layoutObject(), 1.0f); | 628 size = image->imageSizeForLayoutObject(layoutObject(), 1.0f); |
| 628 if (layoutObject() && layoutObject()->isLayoutImage() && image->image() && ! image->image()->hasRelativeWidth()) | 629 if (layoutObject() && layoutObject()->isLayoutImage() && image->image() && ! image->image()->hasRelativeWidth()) |
| 629 size.scale(toLayoutImage(layoutObject())->imageDevicePixelRatio()); | 630 size.scale(toLayoutImage(layoutObject())->imageDevicePixelRatio()); |
| 630 return FloatSize(size); | 631 return FloatSize(size); |
| 631 } | 632 } |
| 632 | 633 |
| 634 static bool sourceSizeValue(Element& element, Document& currentDocument, float& sourceSize) | |
| 635 { | |
| 636 String sizes = element.fastGetAttribute(sizesAttr); | |
| 637 bool exists = !sizes.isNull(); | |
| 638 if (exists) | |
| 639 UseCounter::count(currentDocument, UseCounter::Sizes); | |
| 640 sourceSize = SizesAttributeParser(MediaValuesDynamic::create(currentDocument ), sizes).length(); | |
| 641 return exists; | |
| 642 } | |
| 643 | |
| 644 int HTMLImageElement::widthAttributeToInt(const String& value, bool& isValid) | |
| 645 { | |
| 646 if (!value.isEmpty() && !value.contains('%') && !value.contains('*')) | |
|
Mike West
2015/06/18 06:20:04
Nit: Could you add a comment here explaining why y
Yoav Weiss
2015/06/18 06:30:22
Will do
| |
| 647 return value.toInt(&isValid); | |
| 648 | |
| 649 isValid = false; | |
| 650 return 0; | |
| 651 } | |
| 652 | |
| 653 FetchRequest::ResourceWidth HTMLImageElement::resourceWidth() | |
| 654 { | |
| 655 FetchRequest::ResourceWidth resourceWidth; | |
| 656 resourceWidth.isSet = sourceSizeValue(*this, document(), resourceWidth.width ); | |
| 657 if (!resourceWidth.isSet) | |
| 658 resourceWidth.width = widthAttributeToInt(fastGetAttribute(widthAttr), r esourceWidth.isSet); | |
| 659 return resourceWidth; | |
| 660 } | |
| 661 | |
| 633 float HTMLImageElement::sourceSize(Element& element) | 662 float HTMLImageElement::sourceSize(Element& element) |
| 634 { | 663 { |
| 635 String sizes = element.fastGetAttribute(sizesAttr); | 664 float value; |
| 636 if (!sizes.isNull()) | 665 // We don't care here if the sizes attribute exists, so we ignore the return value. |
| 637 UseCounter::count(document(), UseCounter::Sizes); | 666 // If it doesn't exist, we just return the default. |
| 638 return SizesAttributeParser(MediaValuesDynamic::create(document()), sizes).l ength(); | 667 sourceSizeValue(element, document(), value); |
| 668 return value; | |
| 639 } | 669 } |
| 640 | 670 |
| 641 void HTMLImageElement::forceReload() const | 671 void HTMLImageElement::forceReload() const |
| 642 { | 672 { |
| 643 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload); | 673 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload); |
| 644 } | 674 } |
| 645 | 675 |
| 646 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior) | 676 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior) |
| 647 { | 677 { |
| 648 if (!document().isActive()) | 678 if (!document().isActive()) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 ensureUserAgentShadowRoot(); | 757 ensureUserAgentShadowRoot(); |
| 728 } | 758 } |
| 729 | 759 |
| 730 bool HTMLImageElement::isOpaque() const | 760 bool HTMLImageElement::isOpaque() const |
| 731 { | 761 { |
| 732 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); | 762 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); |
| 733 return image && image->currentFrameKnownToBeOpaque(); | 763 return image && image->currentFrameKnownToBeOpaque(); |
| 734 } | 764 } |
| 735 | 765 |
| 736 } | 766 } |
| OLD | NEW |