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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 135 |
136 void ImageDocumentParser::finish() | 136 void ImageDocumentParser::finish() |
137 { | 137 { |
138 if (!isStopped() && document()->imageElement()) { | 138 if (!isStopped() && document()->imageElement()) { |
139 ImageResource* cachedImage = document()->cachedImage(); | 139 ImageResource* cachedImage = document()->cachedImage(); |
140 cachedImage->finish(); | 140 cachedImage->finish(); |
141 cachedImage->setResponse(document()->frame()->loader().documentLoader()- >response()); | 141 cachedImage->setResponse(document()->frame()->loader().documentLoader()- >response()); |
142 | 142 |
143 // Report the natural image size in the page title, regardless of zoom l evel. | 143 // Report the natural image size in the page title, regardless of zoom l evel. |
144 // At a zoom level of 1 the image is guaranteed to have an integer size. | 144 // At a zoom level of 1 the image is guaranteed to have an integer size. |
145 IntSize size = flooredIntSize(cachedImage->imageSizeForRenderer(document ()->imageElement()->renderer(), 1.0f)); | 145 IntSize size = flooredIntSize(document()->cachedImageSize(1.0f)); |
146 if (size.width()) { | 146 if (size.width()) { |
147 // Compute the title, we use the decoded filename of the resource, f alling | 147 // Compute the title, we use the decoded filename of the resource, f alling |
148 // back on the (decoded) hostname if there is no path. | 148 // back on the (decoded) hostname if there is no path. |
149 String fileName = decodeURLEscapeSequences(document()->url().lastPat hComponent()); | 149 String fileName = decodeURLEscapeSequences(document()->url().lastPat hComponent()); |
150 if (fileName.isEmpty()) | 150 if (fileName.isEmpty()) |
151 fileName = document()->url().host(); | 151 fileName = document()->url().host(); |
152 document()->setTitle(imageTitle(fileName, size)); | 152 document()->setTitle(imageTitle(fileName, size)); |
153 } | 153 } |
154 | 154 |
155 document()->imageUpdated(); | 155 document()->imageUpdated(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 214 |
215 float ImageDocument::scale() const | 215 float ImageDocument::scale() const |
216 { | 216 { |
217 if (!m_imageElement || m_imageElement->document() != this) | 217 if (!m_imageElement || m_imageElement->document() != this) |
218 return 1.0f; | 218 return 1.0f; |
219 | 219 |
220 FrameView* view = frame()->view(); | 220 FrameView* view = frame()->view(); |
221 if (!view) | 221 if (!view) |
222 return 1; | 222 return 1; |
223 | 223 |
224 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m _imageElement->renderer(), pageZoomFactor(this)); | 224 LayoutSize imageSize = cachedImageSize(pageZoomFactor(this)); |
225 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 225 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
226 | 226 |
227 float widthScale = (float)windowSize.width() / imageSize.width(); | 227 float widthScale = (float)windowSize.width() / imageSize.width(); |
228 float heightScale = (float)windowSize.height() / imageSize.height(); | 228 float heightScale = (float)windowSize.height() / imageSize.height(); |
229 | 229 |
230 return min(widthScale, heightScale); | 230 return min(widthScale, heightScale); |
231 } | 231 } |
232 | 232 |
233 void ImageDocument::resizeImageToFit() | 233 void ImageDocument::resizeImageToFit() |
234 { | 234 { |
235 if (!m_imageElement || m_imageElement->document() != this || pageZoomFactor( this) > 1) | 235 if (!m_imageElement || m_imageElement->document() != this || pageZoomFactor( this) > 1) |
236 return; | 236 return; |
237 | 237 |
238 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m _imageElement->renderer(), pageZoomFactor(this)); | 238 LayoutSize imageSize = cachedImageSize(pageZoomFactor(this)); |
239 | 239 |
240 float scale = this->scale(); | 240 float scale = this->scale(); |
241 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); | 241 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); |
242 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); | 242 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); |
243 | 243 |
244 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkitZoom In); | 244 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkitZoom In); |
245 } | 245 } |
246 | 246 |
247 void ImageDocument::imageClicked(int x, int y) | 247 void ImageDocument::imageClicked(int x, int y) |
248 { | 248 { |
(...skipping 18 matching lines...) Expand all Loading... | |
267 } | 267 } |
268 } | 268 } |
269 | 269 |
270 void ImageDocument::imageUpdated() | 270 void ImageDocument::imageUpdated() |
271 { | 271 { |
272 ASSERT(m_imageElement); | 272 ASSERT(m_imageElement); |
273 | 273 |
274 if (m_imageSizeIsKnown) | 274 if (m_imageSizeIsKnown) |
275 return; | 275 return; |
276 | 276 |
277 if (m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->rend erer(), pageZoomFactor(this)).isEmpty()) | 277 if (cachedImageSize(pageZoomFactor(this)).isEmpty()) |
278 return; | 278 return; |
279 | 279 |
280 m_imageSizeIsKnown = true; | 280 m_imageSizeIsKnown = true; |
281 | 281 |
282 if (shouldShrinkToFit()) { | 282 if (shouldShrinkToFit()) { |
283 // Force resizing of the image | 283 // Force resizing of the image |
284 windowSizeChanged(); | 284 windowSizeChanged(); |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 void ImageDocument::restoreImageSize() | 288 void ImageDocument::restoreImageSize() |
289 { | 289 { |
290 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || pageZoomFactor(this) < 1) | 290 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || pageZoomFactor(this) < 1) |
291 return; | 291 return; |
292 | 292 |
293 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m _imageElement->renderer(), 1.0f); | 293 LayoutSize imageSize = cachedImageSize(1.0f); |
294 m_imageElement->setWidth(imageSize.width()); | 294 m_imageElement->setWidth(imageSize.width()); |
295 m_imageElement->setHeight(imageSize.height()); | 295 m_imageElement->setHeight(imageSize.height()); |
296 | 296 |
297 if (imageFitsInWindow()) | 297 if (imageFitsInWindow()) |
298 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 298 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
299 else | 299 else |
300 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkit ZoomOut); | 300 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkit ZoomOut); |
301 | 301 |
302 m_didShrinkImage = false; | 302 m_didShrinkImage = false; |
303 } | 303 } |
304 | 304 |
305 bool ImageDocument::imageFitsInWindow() const | 305 bool ImageDocument::imageFitsInWindow() const |
306 { | 306 { |
307 if (!m_imageElement || m_imageElement->document() != this) | 307 if (!m_imageElement || m_imageElement->document() != this) |
308 return true; | 308 return true; |
309 | 309 |
310 FrameView* view = frame()->view(); | 310 FrameView* view = frame()->view(); |
311 if (!view) | 311 if (!view) |
312 return true; | 312 return true; |
313 | 313 |
314 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m _imageElement->renderer(), pageZoomFactor(this)); | 314 LayoutSize imageSize = cachedImageSize(pageZoomFactor(this)); |
315 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 315 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
316 | 316 |
317 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind owSize.height(); | 317 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind owSize.height(); |
318 } | 318 } |
319 | 319 |
320 void ImageDocument::windowSizeChanged() | 320 void ImageDocument::windowSizeChanged() |
321 { | 321 { |
322 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this) | 322 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this) |
323 return; | 323 return; |
324 | 324 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 { | 362 { |
363 return frame()->settings()->shrinksStandaloneImagesToFit() && frame()->isMai nFrame(); | 363 return frame()->settings()->shrinksStandaloneImagesToFit() && frame()->isMai nFrame(); |
364 } | 364 } |
365 | 365 |
366 void ImageDocument::dispose() | 366 void ImageDocument::dispose() |
367 { | 367 { |
368 m_imageElement = 0; | 368 m_imageElement = 0; |
369 HTMLDocument::dispose(); | 369 HTMLDocument::dispose(); |
370 } | 370 } |
371 | 371 |
372 LayoutSize ImageDocument::cachedImageSize(float zoomFactor) const | |
373 { | |
374 if (!m_imageElement) | |
375 return LayoutSize(); | |
376 | |
377 ImageResource* imageResource = m_imageElement->cachedImage(); | |
378 if (!m_imageElement->renderer() && imageResource->hasImage() && imageResourc e->image()->isBitmapImage()) | |
379 return imageResource->bitmapImageSizeRespectingOrientation(zoomFactor); | |
380 | |
381 return imageResource->imageSizeForRenderer(m_imageElement->renderer(), zoomF actor); | |
abarth-chromium
2014/02/15 18:58:33
Won't this still be broken for non-bitmap images?
| |
382 } | |
383 | |
372 // -------- | 384 // -------- |
373 | 385 |
374 void ImageEventListener::handleEvent(ExecutionContext*, Event* event) | 386 void ImageEventListener::handleEvent(ExecutionContext*, Event* event) |
375 { | 387 { |
376 if (event->type() == EventTypeNames::resize) | 388 if (event->type() == EventTypeNames::resize) |
377 m_doc->windowSizeChanged(); | 389 m_doc->windowSizeChanged(); |
378 else if (event->type() == EventTypeNames::click && event->isMouseEvent()) { | 390 else if (event->type() == EventTypeNames::click && event->isMouseEvent()) { |
379 MouseEvent* mouseEvent = toMouseEvent(event); | 391 MouseEvent* mouseEvent = toMouseEvent(event); |
380 m_doc->imageClicked(mouseEvent->x(), mouseEvent->y()); | 392 m_doc->imageClicked(mouseEvent->x(), mouseEvent->y()); |
381 } | 393 } |
382 } | 394 } |
383 | 395 |
384 bool ImageEventListener::operator==(const EventListener& listener) | 396 bool ImageEventListener::operator==(const EventListener& listener) |
385 { | 397 { |
386 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener)) | 398 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener)) |
387 return m_doc == imageEventListener->m_doc; | 399 return m_doc == imageEventListener->m_doc; |
388 return false; | 400 return false; |
389 } | 401 } |
390 | 402 |
391 } | 403 } |
OLD | NEW |