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

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

Issue 2490233002: Use unsigned longs in HTMLImageElement idl (Closed)
Patch Set: V3 Created 4 years, 1 month 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) 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 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights
5 * reserved. 5 * reserved.
6 * Copyright (C) 2010 Google Inc. All rights reserved. 6 * Copyright (C) 2010 Google Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 selectSourceURL(ImageLoader::UpdateSizeChanged); 134 selectSourceURL(ImageLoader::UpdateSizeChanged);
135 } 135 }
136 136
137 HTMLImageElement* HTMLImageElement::createForJSConstructor(Document& document) { 137 HTMLImageElement* HTMLImageElement::createForJSConstructor(Document& document) {
138 HTMLImageElement* image = new HTMLImageElement(document); 138 HTMLImageElement* image = new HTMLImageElement(document);
139 image->m_elementCreatedByParser = false; 139 image->m_elementCreatedByParser = false;
140 return image; 140 return image;
141 } 141 }
142 142
143 HTMLImageElement* HTMLImageElement::createForJSConstructor(Document& document, 143 HTMLImageElement* HTMLImageElement::createForJSConstructor(Document& document,
144 int width) { 144 unsigned width) {
145 HTMLImageElement* image = new HTMLImageElement(document); 145 HTMLImageElement* image = new HTMLImageElement(document);
146 image->setWidth(width); 146 image->setWidth(width);
147 image->m_elementCreatedByParser = false; 147 image->m_elementCreatedByParser = false;
148 return image; 148 return image;
149 } 149 }
150 150
151 HTMLImageElement* HTMLImageElement::createForJSConstructor(Document& document, 151 HTMLImageElement* HTMLImageElement::createForJSConstructor(Document& document,
152 int width, 152 unsigned width,
153 int height) { 153 unsigned height) {
154 HTMLImageElement* image = new HTMLImageElement(document); 154 HTMLImageElement* image = new HTMLImageElement(document);
155 image->setWidth(width); 155 image->setWidth(width);
156 image->setHeight(height); 156 image->setHeight(height);
157 image->m_elementCreatedByParser = false; 157 image->m_elementCreatedByParser = false;
158 return image; 158 return image;
159 } 159 }
160 160
161 bool HTMLImageElement::isPresentationAttribute( 161 bool HTMLImageElement::isPresentationAttribute(
162 const QualifiedName& name) const { 162 const QualifiedName& name) const {
163 if (name == widthAttr || name == heightAttr || name == borderAttr || 163 if (name == widthAttr || name == heightAttr || name == borderAttr ||
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 resetFormOwner(); 419 resetFormOwner();
420 if (m_listener) { 420 if (m_listener) {
421 document().mediaQueryMatcher().removeViewportListener(m_listener); 421 document().mediaQueryMatcher().removeViewportListener(m_listener);
422 Node* parent = parentNode(); 422 Node* parent = parentNode();
423 if (parent && isHTMLPictureElement(*parent)) 423 if (parent && isHTMLPictureElement(*parent))
424 toHTMLPictureElement(parent)->removeListenerFromSourceChildren(); 424 toHTMLPictureElement(parent)->removeListenerFromSourceChildren();
425 } 425 }
426 HTMLElement::removedFrom(insertionPoint); 426 HTMLElement::removedFrom(insertionPoint);
427 } 427 }
428 428
429 int HTMLImageElement::width() { 429 unsigned HTMLImageElement::width() {
430 if (inActiveDocument()) 430 if (inActiveDocument())
431 document().updateStyleAndLayoutIgnorePendingStylesheets(); 431 document().updateStyleAndLayoutIgnorePendingStylesheets();
432 432
433 if (!layoutObject()) { 433 if (!layoutObject()) {
434 // check the attribute first for an explicit pixel value 434 // check the attribute first for an explicit pixel value
435 bool ok; 435 unsigned width = 0;
436 int width = getAttribute(widthAttr).toInt(&ok); 436 if (parseHTMLNonNegativeInteger(getAttribute(widthAttr), width))
437 if (ok)
438 return width; 437 return width;
439 438
440 // if the image is available, use its width 439 // if the image is available, use its width
441 if (imageLoader().image()) 440 if (imageLoader().image())
442 return imageLoader() 441 return imageLoader()
443 .image() 442 .image()
444 ->imageSize(LayoutObject::shouldRespectImageOrientation(nullptr), 443 ->imageSize(LayoutObject::shouldRespectImageOrientation(nullptr),
445 1.0f) 444 1.0f)
446 .width() 445 .width()
447 .toInt(); 446 .toUnsigned();
448 } 447 }
449 448
450 LayoutBox* box = layoutBox(); 449 LayoutBox* box = layoutBox();
451 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth(), 450 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth(),
452 box) 451 box)
453 : 0; 452 : 0;
454 } 453 }
455 454
456 int HTMLImageElement::height() { 455 unsigned HTMLImageElement::height() {
457 if (inActiveDocument()) 456 if (inActiveDocument())
458 document().updateStyleAndLayoutIgnorePendingStylesheets(); 457 document().updateStyleAndLayoutIgnorePendingStylesheets();
459 458
460 if (!layoutObject()) { 459 if (!layoutObject()) {
461 // check the attribute first for an explicit pixel value 460 // check the attribute first for an explicit pixel value
462 bool ok; 461 unsigned height = 0;
463 int height = getAttribute(heightAttr).toInt(&ok); 462 if (parseHTMLNonNegativeInteger(getAttribute(heightAttr), height))
464 if (ok)
465 return height; 463 return height;
466 464
467 // if the image is available, use its height 465 // if the image is available, use its height
468 if (imageLoader().image()) 466 if (imageLoader().image())
469 return imageLoader() 467 return imageLoader()
470 .image() 468 .image()
471 ->imageSize(LayoutObject::shouldRespectImageOrientation(nullptr), 469 ->imageSize(LayoutObject::shouldRespectImageOrientation(nullptr),
472 1.0f) 470 1.0f)
473 .height() 471 .height()
474 .toInt(); 472 .toUnsigned();
475 } 473 }
476 474
477 LayoutBox* box = layoutBox(); 475 LayoutBox* box = layoutBox();
478 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight(), 476 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight(),
479 box) 477 box)
480 : 0; 478 : 0;
481 } 479 }
482 480
483 int HTMLImageElement::naturalWidth() const { 481 int HTMLImageElement::naturalWidth() const {
484 if (!imageLoader().image()) 482 if (!imageLoader().image())
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 535
538 const QualifiedName& HTMLImageElement::subResourceAttributeName() const { 536 const QualifiedName& HTMLImageElement::subResourceAttributeName() const {
539 return srcAttr; 537 return srcAttr;
540 } 538 }
541 539
542 bool HTMLImageElement::draggable() const { 540 bool HTMLImageElement::draggable() const {
543 // Image elements are draggable by default. 541 // Image elements are draggable by default.
544 return !equalIgnoringCase(getAttribute(draggableAttr), "false"); 542 return !equalIgnoringCase(getAttribute(draggableAttr), "false");
545 } 543 }
546 544
547 void HTMLImageElement::setHeight(int value) { 545 void HTMLImageElement::setHeight(unsigned value) {
548 setIntegralAttribute(heightAttr, value); 546 setUnsignedIntegralAttribute(heightAttr, value);
549 } 547 }
550 548
551 KURL HTMLImageElement::src() const { 549 KURL HTMLImageElement::src() const {
552 return document().completeURL(getAttribute(srcAttr)); 550 return document().completeURL(getAttribute(srcAttr));
553 } 551 }
554 552
555 void HTMLImageElement::setSrc(const String& value) { 553 void HTMLImageElement::setSrc(const String& value) {
556 setAttribute(srcAttr, AtomicString(value)); 554 setAttribute(srcAttr, AtomicString(value));
557 } 555 }
558 556
559 void HTMLImageElement::setWidth(int value) { 557 void HTMLImageElement::setWidth(unsigned value) {
560 setIntegralAttribute(widthAttr, value); 558 setUnsignedIntegralAttribute(widthAttr, value);
561 } 559 }
562 560
563 int HTMLImageElement::x() const { 561 int HTMLImageElement::x() const {
564 document().updateStyleAndLayoutIgnorePendingStylesheets(); 562 document().updateStyleAndLayoutIgnorePendingStylesheets();
565 LayoutObject* r = layoutObject(); 563 LayoutObject* r = layoutObject();
566 if (!r) 564 if (!r)
567 return 0; 565 return 0;
568 566
569 // FIXME: This doesn't work correctly with transforms. 567 // FIXME: This doesn't work correctly with transforms.
570 FloatPoint absPos = r->localToAbsolute(); 568 FloatPoint absPos = r->localToAbsolute();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 ImageResource* image = cachedImage(); 883 ImageResource* image = cachedImage();
886 if (!image) 884 if (!image)
887 return IntSize(); 885 return IntSize();
888 LayoutSize lSize = image->imageSize( 886 LayoutSize lSize = image->imageSize(
889 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); 887 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f);
890 DCHECK(lSize.fraction().isZero()); 888 DCHECK(lSize.fraction().isZero());
891 return IntSize(lSize.width().toInt(), lSize.height().toInt()); 889 return IntSize(lSize.width().toInt(), lSize.height().toInt());
892 } 890 }
893 891
894 } // namespace blink 892 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698