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

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

Issue 2258033002: Replace ASSERT()s with DCHECK*() in core/html/*.{cpp,h}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace ASSERT()s with DCHECK*() in core/html/*.{cpp,h}. Created 4 years, 4 months 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 float ImageDocument::scale() const 246 float ImageDocument::scale() const
247 { 247 {
248 if (!m_imageElement || m_imageElement->document() != this) 248 if (!m_imageElement || m_imageElement->document() != this)
249 return 1.0f; 249 return 1.0f;
250 250
251 FrameView* view = frame()->view(); 251 FrameView* view = frame()->view();
252 if (!view) 252 if (!view)
253 return 1; 253 return 1;
254 254
255 ASSERT(m_imageElement->cachedImage()); 255 DCHECK(m_imageElement->cachedImage());
256 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this)); 256 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this));
257 LayoutSize windowSize = LayoutSize(view->width(), view->height()); 257 LayoutSize windowSize = LayoutSize(view->width(), view->height());
258 258
259 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat( ); 259 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat( );
260 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo at(); 260 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo at();
261 261
262 return min(widthScale, heightScale); 262 return min(widthScale, heightScale);
263 } 263 }
264 264
265 void ImageDocument::resizeImageToFit(ScaleType type) 265 void ImageDocument::resizeImageToFit(ScaleType type)
266 { 266 {
267 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor (this) > 1 && type == ScaleOnlyUnzoomedDocument)) 267 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor (this) > 1 && type == ScaleOnlyUnzoomedDocument))
268 return; 268 return;
269 269
270 ASSERT(m_imageElement->cachedImage()); 270 DCHECK(m_imageElement->cachedImage());
271 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this)); 271 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this));
272 272
273 float scale = this->scale(); 273 float scale = this->scale();
274 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); 274 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale));
275 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); 275 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale));
276 276
277 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); 277 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn);
278 } 278 }
279 279
280 void ImageDocument::imageClicked(int x, int y) 280 void ImageDocument::imageClicked(int x, int y)
281 { 281 {
282 ASSERT(m_shrinkToFitMode == Desktop); 282 DCHECK_EQ(m_shrinkToFitMode, Desktop);
283 283
284 if (!m_imageSizeIsKnown || imageFitsInWindow()) 284 if (!m_imageSizeIsKnown || imageFitsInWindow())
285 return; 285 return;
286 286
287 m_shouldShrinkImage = !m_shouldShrinkImage; 287 m_shouldShrinkImage = !m_shouldShrinkImage;
288 288
289 if (m_shouldShrinkImage) { 289 if (m_shouldShrinkImage) {
290 windowSizeChanged(ScaleZoomedDocument); 290 windowSizeChanged(ScaleZoomedDocument);
291 } else { 291 } else {
292 restoreImageSize(ScaleZoomedDocument); 292 restoreImageSize(ScaleZoomedDocument);
293 293
294 updateStyleAndLayout(); 294 updateStyleAndLayout();
295 295
296 double scale = this->scale(); 296 double scale = this->scale();
297 297
298 double scrollX = x / scale - static_cast<double>(frame()->view()->width( )) / 2; 298 double scrollX = x / scale - static_cast<double>(frame()->view()->width( )) / 2;
299 double scrollY = y / scale - static_cast<double>(frame()->view()->height ()) / 2; 299 double scrollY = y / scale - static_cast<double>(frame()->view()->height ()) / 2;
300 300
301 frame()->view()->setScrollPosition(DoublePoint(scrollX, scrollY), Progra mmaticScroll); 301 frame()->view()->setScrollPosition(DoublePoint(scrollX, scrollY), Progra mmaticScroll);
302 } 302 }
303 } 303 }
304 304
305 void ImageDocument::imageUpdated() 305 void ImageDocument::imageUpdated()
306 { 306 {
307 ASSERT(m_imageElement); 307 DCHECK(m_imageElement);
308 308
309 if (m_imageSizeIsKnown) 309 if (m_imageSizeIsKnown)
310 return; 310 return;
311 311
312 updateStyleAndLayoutTree(); 312 updateStyleAndLayoutTree();
313 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi ze(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(this)).isEmpty()) 313 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi ze(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(this)).isEmpty())
314 return; 314 return;
315 315
316 m_imageSizeIsKnown = true; 316 m_imageSizeIsKnown = true;
317 317
318 if (shouldShrinkToFit()) { 318 if (shouldShrinkToFit()) {
319 // Force resizing of the image 319 // Force resizing of the image
320 windowSizeChanged(ScaleOnlyUnzoomedDocument); 320 windowSizeChanged(ScaleOnlyUnzoomedDocument);
321 } 321 }
322 } 322 }
323 323
324 void ImageDocument::restoreImageSize(ScaleType type) 324 void ImageDocument::restoreImageSize(ScaleType type)
325 { 325 {
326 ASSERT(m_shrinkToFitMode == Desktop); 326 DCHECK_EQ(m_shrinkToFitMode, Desktop);
327 327
328 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) 328 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument))
329 return; 329 return;
330 330
331 ASSERT(m_imageElement->cachedImage()); 331 DCHECK(m_imageElement->cachedImage());
332 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), 1.0f); 332 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), 1.0f);
333 m_imageElement->setWidth(imageSize.width()); 333 m_imageElement->setWidth(imageSize.width());
334 m_imageElement->setHeight(imageSize.height()); 334 m_imageElement->setHeight(imageSize.height());
335 335
336 if (imageFitsInWindow()) 336 if (imageFitsInWindow())
337 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); 337 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor);
338 else 338 else
339 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu t); 339 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu t);
340 340
341 m_didShrinkImage = false; 341 m_didShrinkImage = false;
342 } 342 }
343 343
344 bool ImageDocument::imageFitsInWindow() const 344 bool ImageDocument::imageFitsInWindow() const
345 { 345 {
346 ASSERT(m_shrinkToFitMode == Desktop); 346 DCHECK_EQ(m_shrinkToFitMode, Desktop);
347 347
348 if (!m_imageElement || m_imageElement->document() != this) 348 if (!m_imageElement || m_imageElement->document() != this)
349 return true; 349 return true;
350 350
351 FrameView* view = frame()->view(); 351 FrameView* view = frame()->view();
352 if (!view) 352 if (!view)
353 return true; 353 return true;
354 354
355 ASSERT(m_imageElement->cachedImage()); 355 DCHECK(m_imageElement->cachedImage());
356 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this)); 356 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject ::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor( this));
357 LayoutSize windowSize = LayoutSize(view->width(), view->height()); 357 LayoutSize windowSize = LayoutSize(view->width(), view->height());
358 358
359 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind owSize.height(); 359 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind owSize.height();
360 } 360 }
361 361
362 void ImageDocument::windowSizeChanged(ScaleType type) 362 void ImageDocument::windowSizeChanged(ScaleType type)
363 { 363 {
364 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this) 364 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this)
365 return; 365 return;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 440 }
441 441
442 bool ImageEventListener::operator==(const EventListener& listener) const 442 bool ImageEventListener::operator==(const EventListener& listener) const
443 { 443 {
444 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener)) 444 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener))
445 return m_doc == imageEventListener->m_doc; 445 return m_doc == imageEventListener->m_doc;
446 return false; 446 return false;
447 } 447 }
448 448
449 } // namespace blink 449 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageData.cpp ('k') | third_party/WebKit/Source/core/html/LabelsNodeList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698