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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 void ImageDocumentParser::finish() | 143 void ImageDocumentParser::finish() |
144 { | 144 { |
145 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ | 145 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ |
146 ImageResource* cachedImage = document()->cachedImage(); | 146 ImageResource* cachedImage = document()->cachedImage(); |
147 cachedImage->finish(); | 147 cachedImage->finish(); |
148 cachedImage->setResponse(document()->frame()->loader().documentLoader()-
>response()); | 148 cachedImage->setResponse(document()->frame()->loader().documentLoader()-
>response()); |
149 | 149 |
150 // Report the natural image size in the page title, regardless of zoom l
evel. | 150 // Report the natural image size in the page title, regardless of zoom l
evel. |
151 // At a zoom level of 1 the image is guaranteed to have an integer size. | 151 // At a zoom level of 1 the image is guaranteed to have an integer size. |
152 IntSize size = flooredIntSize(cachedImage->imageSizeForRenderer(document
()->imageElement()->renderer(), 1.0f)); | 152 IntSize size = flooredIntSize(cachedImage->imageSizeForRenderer(document
()->imageElement()->layoutObject(), 1.0f)); |
153 if (size.width()) { | 153 if (size.width()) { |
154 // Compute the title, we use the decoded filename of the resource, f
alling | 154 // Compute the title, we use the decoded filename of the resource, f
alling |
155 // back on the (decoded) hostname if there is no path. | 155 // back on the (decoded) hostname if there is no path. |
156 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); | 156 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); |
157 if (fileName.isEmpty()) | 157 if (fileName.isEmpty()) |
158 fileName = document()->url().host(); | 158 fileName = document()->url().host(); |
159 document()->setTitle(imageTitle(fileName, size)); | 159 document()->setTitle(imageTitle(fileName, size)); |
160 } | 160 } |
161 | 161 |
162 document()->imageUpdated(); | 162 document()->imageUpdated(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 221 |
222 float ImageDocument::scale() const | 222 float ImageDocument::scale() const |
223 { | 223 { |
224 if (!m_imageElement || m_imageElement->document() != this) | 224 if (!m_imageElement || m_imageElement->document() != this) |
225 return 1.0f; | 225 return 1.0f; |
226 | 226 |
227 FrameView* view = frame()->view(); | 227 FrameView* view = frame()->view(); |
228 if (!view) | 228 if (!view) |
229 return 1; | 229 return 1; |
230 | 230 |
231 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); | 231 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->layoutObject(), pageZoomFactor(this)); |
232 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 232 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
233 | 233 |
234 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat(
); | 234 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat(
); |
235 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo
at(); | 235 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo
at(); |
236 | 236 |
237 return min(widthScale, heightScale); | 237 return min(widthScale, heightScale); |
238 } | 238 } |
239 | 239 |
240 void ImageDocument::resizeImageToFit(ScaleType type) | 240 void ImageDocument::resizeImageToFit(ScaleType type) |
241 { | 241 { |
242 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor
(this) > 1 && type == ScaleOnlyUnzoomedDocument)) | 242 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor
(this) > 1 && type == ScaleOnlyUnzoomedDocument)) |
243 return; | 243 return; |
244 | 244 |
245 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); | 245 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->layoutObject(), pageZoomFactor(this)); |
246 | 246 |
247 float scale = this->scale(); | 247 float scale = this->scale(); |
248 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); | 248 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); |
249 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); | 249 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); |
250 | 250 |
251 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); | 251 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); |
252 } | 252 } |
253 | 253 |
254 void ImageDocument::imageClicked(int x, int y) | 254 void ImageDocument::imageClicked(int x, int y) |
255 { | 255 { |
(...skipping 18 matching lines...) Expand all Loading... |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 void ImageDocument::imageUpdated() | 277 void ImageDocument::imageUpdated() |
278 { | 278 { |
279 ASSERT(m_imageElement); | 279 ASSERT(m_imageElement); |
280 | 280 |
281 if (m_imageSizeIsKnown) | 281 if (m_imageSizeIsKnown) |
282 return; | 282 return; |
283 | 283 |
284 if (m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->rend
erer(), pageZoomFactor(this)).isEmpty()) | 284 if (m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->layo
utObject(), pageZoomFactor(this)).isEmpty()) |
285 return; | 285 return; |
286 | 286 |
287 m_imageSizeIsKnown = true; | 287 m_imageSizeIsKnown = true; |
288 | 288 |
289 if (shouldShrinkToFit()) { | 289 if (shouldShrinkToFit()) { |
290 // Force resizing of the image | 290 // Force resizing of the image |
291 windowSizeChanged(ScaleOnlyUnzoomedDocument); | 291 windowSizeChanged(ScaleOnlyUnzoomedDocument); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 void ImageDocument::restoreImageSize(ScaleType type) | 295 void ImageDocument::restoreImageSize(ScaleType type) |
296 { | 296 { |
297 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) | 297 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) |
298 return; | 298 return; |
299 | 299 |
300 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), 1.0f); | 300 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->layoutObject(), 1.0f); |
301 m_imageElement->setWidth(imageSize.width()); | 301 m_imageElement->setWidth(imageSize.width()); |
302 m_imageElement->setHeight(imageSize.height()); | 302 m_imageElement->setHeight(imageSize.height()); |
303 | 303 |
304 if (imageFitsInWindow()) | 304 if (imageFitsInWindow()) |
305 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 305 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
306 else | 306 else |
307 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu
t); | 307 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu
t); |
308 | 308 |
309 m_didShrinkImage = false; | 309 m_didShrinkImage = false; |
310 } | 310 } |
311 | 311 |
312 bool ImageDocument::imageFitsInWindow() const | 312 bool ImageDocument::imageFitsInWindow() const |
313 { | 313 { |
314 if (!m_imageElement || m_imageElement->document() != this) | 314 if (!m_imageElement || m_imageElement->document() != this) |
315 return true; | 315 return true; |
316 | 316 |
317 FrameView* view = frame()->view(); | 317 FrameView* view = frame()->view(); |
318 if (!view) | 318 if (!view) |
319 return true; | 319 return true; |
320 | 320 |
321 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); | 321 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->layoutObject(), pageZoomFactor(this)); |
322 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 322 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
323 | 323 |
324 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); | 324 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); |
325 } | 325 } |
326 | 326 |
327 void ImageDocument::windowSizeChanged(ScaleType type) | 327 void ImageDocument::windowSizeChanged(ScaleType type) |
328 { | 328 { |
329 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this) | 329 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this) |
330 return; | 330 return; |
331 | 331 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 } | 397 } |
398 | 398 |
399 bool ImageEventListener::operator==(const EventListener& listener) | 399 bool ImageEventListener::operator==(const EventListener& listener) |
400 { | 400 { |
401 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) | 401 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) |
402 return m_doc == imageEventListener->m_doc; | 402 return m_doc == imageEventListener->m_doc; |
403 return false; | 403 return false; |
404 } | 404 } |
405 | 405 |
406 } | 406 } |
OLD | NEW |