OLD | NEW |
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 Loading... |
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 |
55 using namespace HTMLNames; | 56 using namespace HTMLNames; |
56 | 57 |
| 58 namespace { |
| 59 |
| 60 RespectImageOrientationEnum shouldRespectImageOrientation(LayoutObject* layoutOb
ject) |
| 61 { |
| 62 if (layoutObject) |
| 63 return layoutObject->shouldRespectImageOrientation(); |
| 64 |
| 65 return DoNotRespectImageOrientation; |
| 66 } |
| 67 |
| 68 } // anonymous namespace |
| 69 |
57 class ImageEventListener : public EventListener { | 70 class ImageEventListener : public EventListener { |
58 public: | 71 public: |
59 static PassRefPtrWillBeRawPtr<ImageEventListener> create(ImageDocument* docu
ment) | 72 static PassRefPtrWillBeRawPtr<ImageEventListener> create(ImageDocument* docu
ment) |
60 { | 73 { |
61 return adoptRefWillBeNoop(new ImageEventListener(document)); | 74 return adoptRefWillBeNoop(new ImageEventListener(document)); |
62 } | 75 } |
63 static const ImageEventListener* cast(const EventListener* listener) | 76 static const ImageEventListener* cast(const EventListener* listener) |
64 { | 77 { |
65 return listener->type() == ImageEventListenerType | 78 return listener->type() == ImageEventListenerType |
66 ? static_cast<const ImageEventListener*>(listener) | 79 ? static_cast<const ImageEventListener*>(listener) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 { | 169 { |
157 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ | 170 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ |
158 ImageResource* cachedImage = document()->cachedImage(); | 171 ImageResource* cachedImage = document()->cachedImage(); |
159 DocumentLoader* loader = document()->loader(); | 172 DocumentLoader* loader = document()->loader(); |
160 cachedImage->setResponse(loader->response()); | 173 cachedImage->setResponse(loader->response()); |
161 cachedImage->setLoadFinishTime(loader->timing().responseEnd()); | 174 cachedImage->setLoadFinishTime(loader->timing().responseEnd()); |
162 cachedImage->finish(); | 175 cachedImage->finish(); |
163 | 176 |
164 // Report the natural image size in the page title, regardless of zoom l
evel. | 177 // 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. | 178 // 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)); | 179 IntSize size = flooredIntSize(cachedImage->imageSize(shouldRespectImageO
rientation(document()->imageElement()->layoutObject()), 1.0f)); |
167 if (size.width()) { | 180 if (size.width()) { |
168 // Compute the title, we use the decoded filename of the resource, f
alling | 181 // Compute the title, we use the decoded filename of the resource, f
alling |
169 // back on the (decoded) hostname if there is no path. | 182 // back on the (decoded) hostname if there is no path. |
170 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); | 183 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); |
171 if (fileName.isEmpty()) | 184 if (fileName.isEmpty()) |
172 fileName = document()->url().host(); | 185 fileName = document()->url().host(); |
173 document()->setTitle(imageTitle(fileName, size)); | 186 document()->setTitle(imageTitle(fileName, size)); |
174 } | 187 } |
175 | 188 |
176 document()->imageUpdated(); | 189 document()->imageUpdated(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 float ImageDocument::scale() const | 269 float ImageDocument::scale() const |
257 { | 270 { |
258 if (!m_imageElement || m_imageElement->document() != this) | 271 if (!m_imageElement || m_imageElement->document() != this) |
259 return 1.0f; | 272 return 1.0f; |
260 | 273 |
261 FrameView* view = frame()->view(); | 274 FrameView* view = frame()->view(); |
262 if (!view) | 275 if (!view) |
263 return 1; | 276 return 1; |
264 | 277 |
265 ASSERT(m_imageElement->cachedImage()); | 278 ASSERT(m_imageElement->cachedImage()); |
266 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje
ct(m_imageElement->layoutObject(), pageZoomFactor(this)); | 279 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(shouldRespec
tImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(this)); |
267 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 280 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
268 | 281 |
269 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat(
); | 282 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat(
); |
270 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo
at(); | 283 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo
at(); |
271 | 284 |
272 return min(widthScale, heightScale); | 285 return min(widthScale, heightScale); |
273 } | 286 } |
274 | 287 |
275 void ImageDocument::resizeImageToFit(ScaleType type) | 288 void ImageDocument::resizeImageToFit(ScaleType type) |
276 { | 289 { |
277 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor
(this) > 1 && type == ScaleOnlyUnzoomedDocument)) | 290 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor
(this) > 1 && type == ScaleOnlyUnzoomedDocument)) |
278 return; | 291 return; |
279 | 292 |
280 ASSERT(m_imageElement->cachedImage()); | 293 ASSERT(m_imageElement->cachedImage()); |
281 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje
ct(m_imageElement->layoutObject(), pageZoomFactor(this)); | 294 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(shouldRespec
tImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(this)); |
282 | 295 |
283 float scale = this->scale(); | 296 float scale = this->scale(); |
284 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); | 297 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); |
285 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); | 298 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); |
286 | 299 |
287 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); | 300 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); |
288 } | 301 } |
289 | 302 |
290 void ImageDocument::imageClicked(int x, int y) | 303 void ImageDocument::imageClicked(int x, int y) |
291 { | 304 { |
(...skipping 21 matching lines...) Expand all Loading... |
313 } | 326 } |
314 | 327 |
315 void ImageDocument::imageUpdated() | 328 void ImageDocument::imageUpdated() |
316 { | 329 { |
317 ASSERT(m_imageElement); | 330 ASSERT(m_imageElement); |
318 | 331 |
319 if (m_imageSizeIsKnown) | 332 if (m_imageSizeIsKnown) |
320 return; | 333 return; |
321 | 334 |
322 updateLayoutTreeIfNeeded(); | 335 updateLayoutTreeIfNeeded(); |
323 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi
zeForLayoutObject(m_imageElement->layoutObject(), pageZoomFactor(this)).isEmpty(
)) | 336 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi
ze(shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor
(this)).isEmpty()) |
324 return; | 337 return; |
325 | 338 |
326 m_imageSizeIsKnown = true; | 339 m_imageSizeIsKnown = true; |
327 | 340 |
328 if (shouldShrinkToFit()) { | 341 if (shouldShrinkToFit()) { |
329 // Force resizing of the image | 342 // Force resizing of the image |
330 windowSizeChanged(ScaleOnlyUnzoomedDocument); | 343 windowSizeChanged(ScaleOnlyUnzoomedDocument); |
331 } | 344 } |
332 } | 345 } |
333 | 346 |
334 void ImageDocument::restoreImageSize(ScaleType type) | 347 void ImageDocument::restoreImageSize(ScaleType type) |
335 { | 348 { |
336 ASSERT(m_shrinkToFitMode == Desktop); | 349 ASSERT(m_shrinkToFitMode == Desktop); |
337 | 350 |
338 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) | 351 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) |
339 return; | 352 return; |
340 | 353 |
341 ASSERT(m_imageElement->cachedImage()); | 354 ASSERT(m_imageElement->cachedImage()); |
342 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje
ct(m_imageElement->layoutObject(), 1.0f); | 355 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(shouldRespec
tImageOrientation(m_imageElement->layoutObject()), 1.0f); |
343 m_imageElement->setWidth(imageSize.width()); | 356 m_imageElement->setWidth(imageSize.width()); |
344 m_imageElement->setHeight(imageSize.height()); | 357 m_imageElement->setHeight(imageSize.height()); |
345 | 358 |
346 if (imageFitsInWindow()) | 359 if (imageFitsInWindow()) |
347 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 360 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
348 else | 361 else |
349 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu
t); | 362 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu
t); |
350 | 363 |
351 m_didShrinkImage = false; | 364 m_didShrinkImage = false; |
352 } | 365 } |
353 | 366 |
354 bool ImageDocument::imageFitsInWindow() const | 367 bool ImageDocument::imageFitsInWindow() const |
355 { | 368 { |
356 ASSERT(m_shrinkToFitMode == Desktop); | 369 ASSERT(m_shrinkToFitMode == Desktop); |
357 | 370 |
358 if (!m_imageElement || m_imageElement->document() != this) | 371 if (!m_imageElement || m_imageElement->document() != this) |
359 return true; | 372 return true; |
360 | 373 |
361 FrameView* view = frame()->view(); | 374 FrameView* view = frame()->view(); |
362 if (!view) | 375 if (!view) |
363 return true; | 376 return true; |
364 | 377 |
365 ASSERT(m_imageElement->cachedImage()); | 378 ASSERT(m_imageElement->cachedImage()); |
366 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForLayoutObje
ct(m_imageElement->layoutObject(), pageZoomFactor(this)); | 379 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(shouldRespec
tImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(this)); |
367 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 380 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
368 | 381 |
369 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); | 382 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); |
370 } | 383 } |
371 | 384 |
372 void ImageDocument::windowSizeChanged(ScaleType type) | 385 void ImageDocument::windowSizeChanged(ScaleType type) |
373 { | 386 { |
374 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this) | 387 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this) |
375 return; | 388 return; |
376 | 389 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 } | 467 } |
455 | 468 |
456 bool ImageEventListener::operator==(const EventListener& listener) const | 469 bool ImageEventListener::operator==(const EventListener& listener) const |
457 { | 470 { |
458 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) | 471 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) |
459 return m_doc == imageEventListener->m_doc; | 472 return m_doc == imageEventListener->m_doc; |
460 return false; | 473 return false; |
461 } | 474 } |
462 | 475 |
463 } | 476 } |
OLD | NEW |