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

Side by Side Diff: third_party/WebKit/Source/core/frame/VisualViewport.cpp

Issue 2768603002: Avoid setting visual viewport location/scale if it's infinite/NaN (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 notifyRootFrameViewport(); 243 notifyRootFrameViewport();
244 } 244 }
245 245
246 bool VisualViewport::didSetScaleOrLocation(float scale, 246 bool VisualViewport::didSetScaleOrLocation(float scale,
247 const FloatPoint& location) { 247 const FloatPoint& location) {
248 if (!mainFrame()) 248 if (!mainFrame())
249 return false; 249 return false;
250 250
251 bool valuesChanged = false; 251 bool valuesChanged = false;
252 252
253 CHECK(!std::isnan(scale)); 253 if (scale != m_scale && !std::isnan(scale) && !std::isinf(scale)) {
254 CHECK(std::isfinite(scale));
255 if (scale != m_scale) {
256 m_scale = scale; 254 m_scale = scale;
257 valuesChanged = true; 255 valuesChanged = true;
258 page().chromeClient().pageScaleFactorChanged(); 256 page().chromeClient().pageScaleFactorChanged();
259 enqueueResizeEvent(); 257 enqueueResizeEvent();
260 } 258 }
261 259
262 ScrollOffset clampedOffset = clampScrollOffset(toScrollOffset(location)); 260 ScrollOffset clampedOffset = clampScrollOffset(toScrollOffset(location));
263 261
264 CHECK(!std::isnan(clampedOffset.width()) && 262 // TODO(bokan): If the offset is invalid, we might end up in an infinite
265 !std::isnan(clampedOffset.height())); 263 // recursion as we reenter this function on clamping. It would be cleaner to
266 CHECK(std::isfinite(clampedOffset.width()) && 264 // avoid reentrancy but for now just prevent the stack overflow.
267 std::isfinite(clampedOffset.height())); 265 // crbug.com/702771.
266 if (std::isnan(clampedOffset.width()) || std::isnan(clampedOffset.height()) ||
267 std::isinf(clampedOffset.width()) || std::isinf(clampedOffset.height()))
268 return false;
269
268 if (clampedOffset != m_offset) { 270 if (clampedOffset != m_offset) {
269 m_offset = clampedOffset; 271 m_offset = clampedOffset;
270 scrollAnimator().setCurrentOffset(m_offset); 272 scrollAnimator().setCurrentOffset(m_offset);
271 273
272 // SVG runs with accelerated compositing disabled so no 274 // SVG runs with accelerated compositing disabled so no
273 // ScrollingCoordinator. 275 // ScrollingCoordinator.
274 if (ScrollingCoordinator* coordinator = page().scrollingCoordinator()) 276 if (ScrollingCoordinator* coordinator = page().scrollingCoordinator())
275 coordinator->scrollableAreaScrollLayerDidChange(this); 277 coordinator->scrollableAreaScrollLayerDidChange(this);
276 278
277 if (!page().settings().getInertVisualViewport()) { 279 if (!page().settings().getInertVisualViewport()) {
(...skipping 23 matching lines...) Expand all
301 const float oldPageScale = scale(); 303 const float oldPageScale = scale();
302 const float newPageScale = page().chromeClient().clampPageScaleFactorToLimits( 304 const float newPageScale = page().chromeClient().clampPageScaleFactorToLimits(
303 magnifyDelta * oldPageScale); 305 magnifyDelta * oldPageScale);
304 if (newPageScale == oldPageScale) 306 if (newPageScale == oldPageScale)
305 return false; 307 return false;
306 if (!mainFrame() || !mainFrame()->view()) 308 if (!mainFrame() || !mainFrame()->view())
307 return false; 309 return false;
308 310
309 // Keep the center-of-pinch anchor in a stable position over the course 311 // Keep the center-of-pinch anchor in a stable position over the course
310 // of the magnify. 312 // of the magnify.
313 // TODO(bokan): Looks lie we call into setScaleAndLocation with infinity for
skobes 2017/03/21 19:06:49 typo: lie -> like
bokan 2017/03/21 19:19:30 Done.
314 // the location so it seems either old or newPageScale is invalid.
315 // crbug.com/702771.
311 FloatPoint anchorAtOldScale = anchor.scaledBy(1.f / oldPageScale); 316 FloatPoint anchorAtOldScale = anchor.scaledBy(1.f / oldPageScale);
312 FloatPoint anchorAtNewScale = anchor.scaledBy(1.f / newPageScale); 317 FloatPoint anchorAtNewScale = anchor.scaledBy(1.f / newPageScale);
313 FloatSize anchorDelta = anchorAtOldScale - anchorAtNewScale; 318 FloatSize anchorDelta = anchorAtOldScale - anchorAtNewScale;
314 319
315 // First try to use the anchor's delta to scroll the FrameView. 320 // First try to use the anchor's delta to scroll the FrameView.
316 FloatSize anchorDeltaUnusedByScroll = anchorDelta; 321 FloatSize anchorDeltaUnusedByScroll = anchorDelta;
317 322
318 // Manually bubble any remaining anchor delta up to the visual viewport. 323 // Manually bubble any remaining anchor delta up to the visual viewport.
319 FloatPoint newLocation(FloatPoint(getScrollOffset()) + 324 FloatPoint newLocation(FloatPoint(getScrollOffset()) +
320 anchorDeltaUnusedByScroll); 325 anchorDeltaUnusedByScroll);
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 } else if (graphicsLayer == m_rootTransformLayer.get()) { 842 } else if (graphicsLayer == m_rootTransformLayer.get()) {
838 name = "Root Transform Layer"; 843 name = "Root Transform Layer";
839 } else { 844 } else {
840 ASSERT_NOT_REACHED(); 845 ASSERT_NOT_REACHED();
841 } 846 }
842 847
843 return name; 848 return name;
844 } 849 }
845 850
846 } // namespace blink 851 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698