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

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

Issue 2096633002: Adds scroll position/scale emulation to DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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) 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 using blink::GraphicsLayer; 64 using blink::GraphicsLayer;
65 65
66 namespace blink { 66 namespace blink {
67 67
68 VisualViewport::VisualViewport(FrameHost& owner) 68 VisualViewport::VisualViewport(FrameHost& owner)
69 : m_frameHost(&owner) 69 : m_frameHost(&owner)
70 , m_scale(1) 70 , m_scale(1)
71 , m_topControlsAdjustment(0) 71 , m_topControlsAdjustment(0)
72 , m_maxPageScale(-1) 72 , m_maxPageScale(-1)
73 , m_trackPinchZoomStatsForPage(false) 73 , m_trackPinchZoomStatsForPage(false)
74 , m_scaleAndScrollOverrideEnabled(false)
75 , m_scaleAndScrollOverrideScale(0)
74 { 76 {
75 reset(); 77 reset();
76 } 78 }
77 79
78 VisualViewport::~VisualViewport() 80 VisualViewport::~VisualViewport()
79 { 81 {
80 sendUMAMetrics(); 82 sendUMAMetrics();
81 } 83 }
82 84
83 DEFINE_TRACE(VisualViewport) 85 DEFINE_TRACE(VisualViewport)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 void VisualViewport::move(const FloatSize& delta) 205 void VisualViewport::move(const FloatSize& delta)
204 { 206 {
205 setLocation(m_offset + delta); 207 setLocation(m_offset + delta);
206 } 208 }
207 209
208 void VisualViewport::setScale(float scale) 210 void VisualViewport::setScale(float scale)
209 { 211 {
210 setScaleAndLocation(scale, m_offset); 212 setScaleAndLocation(scale, m_offset);
211 } 213 }
212 214
215 void VisualViewport::setScaleAndScrollOverride(float scale, const FloatPoint& lo cation)
216 {
217 m_scaleAndScrollOverrideEnabled = true;
218 m_scaleAndScrollOverrideScale = scale;
219 m_scaleAndScrollOverrideLocation = location;
220
221 setScaleAndLocation(this->scale(), this->location());
222 }
223
224 void VisualViewport::clearScaleAndScrollOverride()
225 {
226 m_scaleAndScrollOverrideEnabled = false;
227 reset();
228 }
229
213 double VisualViewport::scrollLeft() 230 double VisualViewport::scrollLeft()
214 { 231 {
215 if (!mainFrame()) 232 if (!mainFrame())
216 return 0; 233 return 0;
217 234
218 updateStyleAndLayoutIgnorePendingStylesheets(); 235 updateStyleAndLayoutIgnorePendingStylesheets();
219 236
220 return adjustScrollForAbsoluteZoom(visibleRect().x(), mainFrame()->pageZoomF actor()); 237 return adjustScrollForAbsoluteZoom(visibleRect().x(), mainFrame()->pageZoomF actor());
221 } 238 }
222 239
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 return m_scale; 296 return m_scale;
280 } 297 }
281 298
282 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location ) 299 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location )
283 { 300 {
284 if (!mainFrame()) 301 if (!mainFrame())
285 return; 302 return;
286 303
287 bool valuesChanged = false; 304 bool valuesChanged = false;
288 305
289 if (scale != m_scale) { 306 float newScale = applyScaleOverrideToScale(scale);
290 m_scale = scale; 307 if (newScale != m_scale || newScale != scale) {
308 m_scale = newScale;
291 valuesChanged = true; 309 valuesChanged = true;
292 frameHost().chromeClient().pageScaleFactorChanged(); 310 frameHost().chromeClient().pageScaleFactorChanged();
293 } 311 }
294 312
295 FloatPoint clampedOffset(clampOffsetToBoundaries(location)); 313 FloatPoint overriddenLocation(applyScrollOverrideToLocation(location));
314 FloatPoint clampedOffset(clampOffsetToBoundaries(overriddenLocation));
296 315
297 if (clampedOffset != m_offset) { 316 // When location was overridden, re-apply override to counteract potential s croll animations by compositor.
317 if (clampedOffset != m_offset || overriddenLocation != location) {
298 m_offset = clampedOffset; 318 m_offset = clampedOffset;
299 scrollAnimator().setCurrentPosition(m_offset); 319 scrollAnimator().setCurrentPosition(m_offset);
300 320
301 // SVG runs with accelerated compositing disabled so no ScrollingCoordin ator. 321 // SVG runs with accelerated compositing disabled so no ScrollingCoordin ator.
302 if (ScrollingCoordinator* coordinator = frameHost().page().scrollingCoor dinator()) 322 if (ScrollingCoordinator* coordinator = frameHost().page().scrollingCoor dinator())
303 coordinator->scrollableAreaScrollLayerDidChange(this); 323 coordinator->scrollableAreaScrollLayerDidChange(this);
304 324
305 if (!frameHost().settings().inertVisualViewport()) { 325 if (!frameHost().settings().inertVisualViewport()) {
306 if (Document* document = mainFrame()->document()) 326 if (Document* document = mainFrame()->document())
307 document->enqueueScrollEventForNode(document); 327 document->enqueueScrollEventForNode(document);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 clampedOffset = clampedOffset.shrunkTo(FloatPoint(maximumScrollPositionDoubl e())); 704 clampedOffset = clampedOffset.shrunkTo(FloatPoint(maximumScrollPositionDoubl e()));
685 clampedOffset = clampedOffset.expandedTo(FloatPoint(minimumScrollPositionDou ble())); 705 clampedOffset = clampedOffset.expandedTo(FloatPoint(minimumScrollPositionDou ble()));
686 return clampedOffset; 706 return clampedOffset;
687 } 707 }
688 708
689 void VisualViewport::clampToBoundaries() 709 void VisualViewport::clampToBoundaries()
690 { 710 {
691 setLocation(m_offset); 711 setLocation(m_offset);
692 } 712 }
693 713
714 FloatPoint VisualViewport::applyScrollOverrideToLocation(const FloatPoint& locat ion)
715 {
716 FloatPoint newLocation = location;
717 if (m_scaleAndScrollOverrideEnabled) {
718 if (m_scaleAndScrollOverrideLocation.x() >= 0)
Sami 2016/06/23 17:34:03 Ditto.
719 newLocation.setX(m_scaleAndScrollOverrideLocation.x());
720 if (m_scaleAndScrollOverrideLocation.y() >= 0)
721 newLocation.setY(m_scaleAndScrollOverrideLocation.y());
722 }
723 return newLocation;
724 }
725
726 float VisualViewport::applyScaleOverrideToScale(float scale)
727 {
728 if (m_scaleAndScrollOverrideEnabled && m_scaleAndScrollOverrideScale > 0)
729 return m_scaleAndScrollOverrideScale;
730 return scale;
731 }
732
694 FloatRect VisualViewport::viewportToRootFrame(const FloatRect& rectInViewport) c onst 733 FloatRect VisualViewport::viewportToRootFrame(const FloatRect& rectInViewport) c onst
695 { 734 {
696 FloatRect rectInRootFrame = rectInViewport; 735 FloatRect rectInRootFrame = rectInViewport;
697 rectInRootFrame.scale(1 / scale()); 736 rectInRootFrame.scale(1 / scale());
698 rectInRootFrame.moveBy(location()); 737 rectInRootFrame.moveBy(location());
699 return rectInRootFrame; 738 return rectInRootFrame;
700 } 739 }
701 740
702 IntRect VisualViewport::viewportToRootFrame(const IntRect& rectInViewport) const 741 IntRect VisualViewport::viewportToRootFrame(const IntRect& rectInViewport) const
703 { 742 {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 } else if (graphicsLayer == m_rootTransformLayer) { 874 } else if (graphicsLayer == m_rootTransformLayer) {
836 name = "Root Transform Layer"; 875 name = "Root Transform Layer";
837 } else { 876 } else {
838 ASSERT_NOT_REACHED(); 877 ASSERT_NOT_REACHED();
839 } 878 }
840 879
841 return name; 880 return name;
842 } 881 }
843 882
844 } // namespace blink 883 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698