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

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

Issue 1468023002: Rename imageSizeForLayoutObject() to imageSize() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bring back ps#3 and fix nit Created 5 years 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) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 24 matching lines...) Expand all
35 #include "core/frame/FrameView.h" 35 #include "core/frame/FrameView.h"
36 #include "core/frame/LocalDOMWindow.h" 36 #include "core/frame/LocalDOMWindow.h"
37 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
38 #include "core/frame/Settings.h" 38 #include "core/frame/Settings.h"
39 #include "core/frame/VisualViewport.h" 39 #include "core/frame/VisualViewport.h"
40 #include "core/html/HTMLBodyElement.h" 40 #include "core/html/HTMLBodyElement.h"
41 #include "core/html/HTMLHeadElement.h" 41 #include "core/html/HTMLHeadElement.h"
42 #include "core/html/HTMLHtmlElement.h" 42 #include "core/html/HTMLHtmlElement.h"
43 #include "core/html/HTMLImageElement.h" 43 #include "core/html/HTMLImageElement.h"
44 #include "core/html/HTMLMetaElement.h" 44 #include "core/html/HTMLMetaElement.h"
45 #include "core/layout/LayoutObject.h"
45 #include "core/loader/DocumentLoader.h" 46 #include "core/loader/DocumentLoader.h"
46 #include "core/loader/FrameLoader.h" 47 #include "core/loader/FrameLoader.h"
47 #include "core/loader/FrameLoaderClient.h" 48 #include "core/loader/FrameLoaderClient.h"
48 #include "wtf/text/StringBuilder.h" 49 #include "wtf/text/StringBuilder.h"
49 #include <limits> 50 #include <limits>
50 51
51 using namespace std; 52 using namespace std;
52 53
53 namespace blink { 54 namespace blink {
54 55
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 { 157 {
157 if (!isStopped() && document()->imageElement() && document()->cachedImage()) { 158 if (!isStopped() && document()->imageElement() && document()->cachedImage()) {
158 ImageResource* cachedImage = document()->cachedImage(); 159 ImageResource* cachedImage = document()->cachedImage();
159 DocumentLoader* loader = document()->loader(); 160 DocumentLoader* loader = document()->loader();
160 cachedImage->setResponse(loader->response()); 161 cachedImage->setResponse(loader->response());
161 cachedImage->setLoadFinishTime(loader->timing().responseEnd()); 162 cachedImage->setLoadFinishTime(loader->timing().responseEnd());
162 cachedImage->finish(); 163 cachedImage->finish();
163 164
164 // Report the natural image size in the page title, regardless of zoom l evel. 165 // Report the natural image size in the page title, regardless of zoom l evel.
165 // At a zoom level of 1 the image is guaranteed to have an integer size. 166 // At a zoom level of 1 the image is guaranteed to have an integer size.
166 IntSize size = flooredIntSize(cachedImage->imageSizeForLayoutObject(docu ment()->imageElement()->layoutObject(), 1.0f)); 167 IntSize size = flooredIntSize(cachedImage->imageSize(LayoutObject::shoul dRespectImageOrientation(document()->imageElement()->layoutObject()), 1.0f));
167 if (size.width()) { 168 if (size.width()) {
168 // Compute the title, we use the decoded filename of the resource, f alling 169 // Compute the title, we use the decoded filename of the resource, f alling
169 // back on the (decoded) hostname if there is no path. 170 // back on the (decoded) hostname if there is no path.
170 String fileName = decodeURLEscapeSequences(document()->url().lastPat hComponent()); 171 String fileName = decodeURLEscapeSequences(document()->url().lastPat hComponent());
171 if (fileName.isEmpty()) 172 if (fileName.isEmpty())
172 fileName = document()->url().host(); 173 fileName = document()->url().host();
173 document()->setTitle(imageTitle(fileName, size)); 174 document()->setTitle(imageTitle(fileName, size));
174 } 175 }
175 176
176 document()->imageUpdated(); 177 document()->imageUpdated();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 float ImageDocument::scale() const 257 float ImageDocument::scale() const
257 { 258 {
258 if (!m_imageElement || m_imageElement->document() != this) 259 if (!m_imageElement || m_imageElement->document() != this)
259 return 1.0f; 260 return 1.0f;
260 261
261 FrameView* view = frame()->view(); 262 FrameView* view = frame()->view();
262 if (!view) 263 if (!view)
263 return 1; 264 return 1;
264 265
265 ASSERT(m_imageElement->cachedImage()); 266 ASSERT(m_imageElement->cachedImage());
266 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje ct(m_imageElement->layoutObject(), pageZoomFactor(this)); 267 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this));
267 LayoutSize windowSize = LayoutSize(view->width(), view->height()); 268 LayoutSize windowSize = LayoutSize(view->width(), view->height());
268 269
269 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat( ); 270 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat( );
270 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo at(); 271 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo at();
271 272
272 return min(widthScale, heightScale); 273 return min(widthScale, heightScale);
273 } 274 }
274 275
275 void ImageDocument::resizeImageToFit(ScaleType type) 276 void ImageDocument::resizeImageToFit(ScaleType type)
276 { 277 {
277 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor (this) > 1 && type == ScaleOnlyUnzoomedDocument)) 278 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor (this) > 1 && type == ScaleOnlyUnzoomedDocument))
278 return; 279 return;
279 280
280 ASSERT(m_imageElement->cachedImage()); 281 ASSERT(m_imageElement->cachedImage());
281 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje ct(m_imageElement->layoutObject(), pageZoomFactor(this)); 282 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this));
282 283
283 float scale = this->scale(); 284 float scale = this->scale();
284 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); 285 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale));
285 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); 286 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale));
286 287
287 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); 288 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn);
288 } 289 }
289 290
290 void ImageDocument::imageClicked(int x, int y) 291 void ImageDocument::imageClicked(int x, int y)
291 { 292 {
(...skipping 21 matching lines...) Expand all
313 } 314 }
314 315
315 void ImageDocument::imageUpdated() 316 void ImageDocument::imageUpdated()
316 { 317 {
317 ASSERT(m_imageElement); 318 ASSERT(m_imageElement);
318 319
319 if (m_imageSizeIsKnown) 320 if (m_imageSizeIsKnown)
320 return; 321 return;
321 322
322 updateLayoutTreeIfNeeded(); 323 updateLayoutTreeIfNeeded();
323 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi zeForLayoutObject(m_imageElement->layoutObject(), pageZoomFactor(this)).isEmpty( )) 324 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi ze(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(this)).isEmpty())
324 return; 325 return;
325 326
326 m_imageSizeIsKnown = true; 327 m_imageSizeIsKnown = true;
327 328
328 if (shouldShrinkToFit()) { 329 if (shouldShrinkToFit()) {
329 // Force resizing of the image 330 // Force resizing of the image
330 windowSizeChanged(ScaleOnlyUnzoomedDocument); 331 windowSizeChanged(ScaleOnlyUnzoomedDocument);
331 } 332 }
332 } 333 }
333 334
334 void ImageDocument::restoreImageSize(ScaleType type) 335 void ImageDocument::restoreImageSize(ScaleType type)
335 { 336 {
336 ASSERT(m_shrinkToFitMode == Desktop); 337 ASSERT(m_shrinkToFitMode == Desktop);
337 338
338 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) 339 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument))
339 return; 340 return;
340 341
341 ASSERT(m_imageElement->cachedImage()); 342 ASSERT(m_imageElement->cachedImage());
342 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje ct(m_imageElement->layoutObject(), 1.0f); 343 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), 1.0f);
343 m_imageElement->setWidth(imageSize.width()); 344 m_imageElement->setWidth(imageSize.width());
344 m_imageElement->setHeight(imageSize.height()); 345 m_imageElement->setHeight(imageSize.height());
345 346
346 if (imageFitsInWindow()) 347 if (imageFitsInWindow())
347 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); 348 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor);
348 else 349 else
349 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu t); 350 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu t);
350 351
351 m_didShrinkImage = false; 352 m_didShrinkImage = false;
352 } 353 }
353 354
354 bool ImageDocument::imageFitsInWindow() const 355 bool ImageDocument::imageFitsInWindow() const
355 { 356 {
356 ASSERT(m_shrinkToFitMode == Desktop); 357 ASSERT(m_shrinkToFitMode == Desktop);
357 358
358 if (!m_imageElement || m_imageElement->document() != this) 359 if (!m_imageElement || m_imageElement->document() != this)
359 return true; 360 return true;
360 361
361 FrameView* view = frame()->view(); 362 FrameView* view = frame()->view();
362 if (!view) 363 if (!view)
363 return true; 364 return true;
364 365
365 ASSERT(m_imageElement->cachedImage()); 366 ASSERT(m_imageElement->cachedImage());
366 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje ct(m_imageElement->layoutObject(), pageZoomFactor(this)); 367 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this));
367 LayoutSize windowSize = LayoutSize(view->width(), view->height()); 368 LayoutSize windowSize = LayoutSize(view->width(), view->height());
368 369
369 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind owSize.height(); 370 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind owSize.height();
370 } 371 }
371 372
372 void ImageDocument::windowSizeChanged(ScaleType type) 373 void ImageDocument::windowSizeChanged(ScaleType type)
373 { 374 {
374 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this) 375 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this)
375 return; 376 return;
376 377
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 } 455 }
455 456
456 bool ImageEventListener::operator==(const EventListener& listener) const 457 bool ImageEventListener::operator==(const EventListener& listener) const
457 { 458 {
458 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener)) 459 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener))
459 return m_doc == imageEventListener->m_doc; 460 return m_doc == imageEventListener->m_doc;
460 return false; 461 return false;
461 } 462 }
462 463
463 } 464 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLImageElement.cpp ('k') | third_party/WebKit/Source/core/html/forms/ImageInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698