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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 domWindow->addEventListener("resize", listener, false); | 195 domWindow->addEventListener("resize", listener, false); |
196 m_imageElement->addEventListener("click", listener.release(), false); | 196 m_imageElement->addEventListener("click", listener.release(), false); |
197 } | 197 } |
198 | 198 |
199 rootElement->appendChild(head); | 199 rootElement->appendChild(head); |
200 rootElement->appendChild(body); | 200 rootElement->appendChild(body); |
201 } | 201 } |
202 | 202 |
203 float ImageDocument::scale() const | 203 float ImageDocument::scale() const |
204 { | 204 { |
205 if (!m_imageElement || m_imageElement->document() != this) | 205 if (!m_imageElement || &m_imageElement->document() != this) |
206 return 1.0f; | 206 return 1.0f; |
207 | 207 |
208 FrameView* view = frame()->view(); | 208 FrameView* view = frame()->view(); |
209 if (!view) | 209 if (!view) |
210 return 1; | 210 return 1; |
211 | 211 |
212 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); | 212 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); |
213 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 213 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
214 | 214 |
215 float widthScale = (float)windowSize.width() / imageSize.width(); | 215 float widthScale = (float)windowSize.width() / imageSize.width(); |
216 float heightScale = (float)windowSize.height() / imageSize.height(); | 216 float heightScale = (float)windowSize.height() / imageSize.height(); |
217 | 217 |
218 return min(widthScale, heightScale); | 218 return min(widthScale, heightScale); |
219 } | 219 } |
220 | 220 |
221 void ImageDocument::resizeImageToFit() | 221 void ImageDocument::resizeImageToFit() |
222 { | 222 { |
223 if (!m_imageElement || m_imageElement->document() != this || pageZoomFactor(
this) > 1) | 223 if (!m_imageElement || &m_imageElement->document() != this || pageZoomFactor
(this) > 1) |
224 return; | 224 return; |
225 | 225 |
226 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); | 226 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); |
227 | 227 |
228 float scale = this->scale(); | 228 float scale = this->scale(); |
229 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); | 229 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); |
230 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); | 230 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); |
231 | 231 |
232 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkitZoom
In); | 232 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkitZoom
In); |
233 } | 233 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 m_imageSizeIsKnown = true; | 268 m_imageSizeIsKnown = true; |
269 | 269 |
270 if (shouldShrinkToFit()) { | 270 if (shouldShrinkToFit()) { |
271 // Force resizing of the image | 271 // Force resizing of the image |
272 windowSizeChanged(); | 272 windowSizeChanged(); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 void ImageDocument::restoreImageSize() | 276 void ImageDocument::restoreImageSize() |
277 { | 277 { |
278 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this || pageZoomFactor(this) < 1) | 278 if (!m_imageElement || !m_imageSizeIsKnown || &m_imageElement->document() !=
this || pageZoomFactor(this) < 1) |
279 return; | 279 return; |
280 | 280 |
281 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), 1.0f); | 281 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), 1.0f); |
282 m_imageElement->setWidth(imageSize.width()); | 282 m_imageElement->setWidth(imageSize.width()); |
283 m_imageElement->setHeight(imageSize.height()); | 283 m_imageElement->setHeight(imageSize.height()); |
284 | 284 |
285 if (imageFitsInWindow()) | 285 if (imageFitsInWindow()) |
286 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 286 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
287 else | 287 else |
288 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkit
ZoomOut); | 288 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkit
ZoomOut); |
289 | 289 |
290 m_didShrinkImage = false; | 290 m_didShrinkImage = false; |
291 } | 291 } |
292 | 292 |
293 bool ImageDocument::imageFitsInWindow() const | 293 bool ImageDocument::imageFitsInWindow() const |
294 { | 294 { |
295 if (!m_imageElement || m_imageElement->document() != this) | 295 if (!m_imageElement || &m_imageElement->document() != this) |
296 return true; | 296 return true; |
297 | 297 |
298 FrameView* view = frame()->view(); | 298 FrameView* view = frame()->view(); |
299 if (!view) | 299 if (!view) |
300 return true; | 300 return true; |
301 | 301 |
302 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); | 302 LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m
_imageElement->renderer(), pageZoomFactor(this)); |
303 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 303 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
304 | 304 |
305 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); | 305 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); |
306 } | 306 } |
307 | 307 |
308 void ImageDocument::windowSizeChanged() | 308 void ImageDocument::windowSizeChanged() |
309 { | 309 { |
310 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this) | 310 if (!m_imageElement || !m_imageSizeIsKnown || &m_imageElement->document() !=
this) |
311 return; | 311 return; |
312 | 312 |
313 bool fitsInWindow = imageFitsInWindow(); | 313 bool fitsInWindow = imageFitsInWindow(); |
314 | 314 |
315 // If the image has been explicitly zoomed in, restore the cursor if the ima
ge fits | 315 // If the image has been explicitly zoomed in, restore the cursor if the ima
ge fits |
316 // and set it to a zoom out cursor if the image doesn't fit | 316 // and set it to a zoom out cursor if the image doesn't fit |
317 if (!m_shouldShrinkImage) { | 317 if (!m_shouldShrinkImage) { |
318 if (fitsInWindow) | 318 if (fitsInWindow) |
319 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 319 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
320 else | 320 else |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } | 370 } |
371 | 371 |
372 bool ImageEventListener::operator==(const EventListener& listener) | 372 bool ImageEventListener::operator==(const EventListener& listener) |
373 { | 373 { |
374 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) | 374 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) |
375 return m_doc == imageEventListener->m_doc; | 375 return m_doc == imageEventListener->m_doc; |
376 return false; | 376 return false; |
377 } | 377 } |
378 | 378 |
379 } | 379 } |
OLD | NEW |