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

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 2096633002: Adds scroll position/scale emulation to DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync changes from patches 2111203004 + 2118773002. 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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "core/events/KeyboardEvent.h" 49 #include "core/events/KeyboardEvent.h"
50 #include "core/events/UIEventWithKeyState.h" 50 #include "core/events/UIEventWithKeyState.h"
51 #include "core/events/WheelEvent.h" 51 #include "core/events/WheelEvent.h"
52 #include "core/fetch/UniqueIdentifier.h" 52 #include "core/fetch/UniqueIdentifier.h"
53 #include "core/frame/EventHandlerRegistry.h" 53 #include "core/frame/EventHandlerRegistry.h"
54 #include "core/frame/FrameHost.h" 54 #include "core/frame/FrameHost.h"
55 #include "core/frame/FrameView.h" 55 #include "core/frame/FrameView.h"
56 #include "core/frame/LocalFrame.h" 56 #include "core/frame/LocalFrame.h"
57 #include "core/frame/PageScaleConstraintsSet.h" 57 #include "core/frame/PageScaleConstraintsSet.h"
58 #include "core/frame/RemoteFrame.h" 58 #include "core/frame/RemoteFrame.h"
59 #include "core/frame/ScrollAndScaleEmulator.h"
59 #include "core/frame/Settings.h" 60 #include "core/frame/Settings.h"
60 #include "core/frame/SmartClip.h" 61 #include "core/frame/SmartClip.h"
61 #include "core/frame/TopControls.h" 62 #include "core/frame/TopControls.h"
62 #include "core/frame/UseCounter.h" 63 #include "core/frame/UseCounter.h"
63 #include "core/frame/VisualViewport.h" 64 #include "core/frame/VisualViewport.h"
64 #include "core/html/HTMLInputElement.h" 65 #include "core/html/HTMLInputElement.h"
65 #include "core/html/HTMLMediaElement.h" 66 #include "core/html/HTMLMediaElement.h"
66 #include "core/html/HTMLPlugInElement.h" 67 #include "core/html/HTMLPlugInElement.h"
67 #include "core/html/HTMLTextAreaElement.h" 68 #include "core/html/HTMLTextAreaElement.h"
68 #include "core/input/EventHandler.h" 69 #include "core/input/EventHandler.h"
(...skipping 3132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3201 DCHECK(page()); 3202 DCHECK(page());
3202 return page()->frameHost().visualViewport().visibleRect().location(); 3203 return page()->frameHost().visualViewport().visibleRect().location();
3203 } 3204 }
3204 3205
3205 WebFloatSize WebViewImpl::visualViewportSize() const 3206 WebFloatSize WebViewImpl::visualViewportSize() const
3206 { 3207 {
3207 DCHECK(page()); 3208 DCHECK(page());
3208 return page()->frameHost().visualViewport().visibleRect().size(); 3209 return page()->frameHost().visualViewport().visibleRect().size();
3209 } 3210 }
3210 3211
3212 void WebViewImpl::setScrollAndScaleOverride(const WebDeviceEmulationParams& para ms)
3213 {
3214 if (!page() || !mainFrameImpl())
3215 return;
3216
3217 FrameView * view = mainFrameImpl()->frameView();
3218 if (!view)
3219 return;
3220
3221 if (!m_scrollAndScaleEmulator) {
3222 m_scrollAndScaleEmulator = ScrollAndScaleEmulator::create();
3223
3224 // Force main thread scrolling, because we do not apply scroll position
3225 // overrides in the compositor thread.
3226 m_scrollAndScaleEmulator->disableThreadedScrolling(page());
3227 }
3228
3229 bool hasChanged = m_scrollAndScaleEmulator->update(
3230 static_cast<IntPoint>(params.scrollPosition),
3231 static_cast<FloatPoint>(params.visualViewportPosition),
3232 params.visualViewportScale);
3233 if (hasChanged) {
3234 view->setScrollAndScaleEmulator(m_scrollAndScaleEmulator);
3235 page()->frameHost().visualViewport().setScrollAndScaleEmulator(m_scrollA ndScaleEmulator);
3236 page()->frameHost().setUserAgentPageScaleConstraints(m_scrollAndScaleEmu lator->pageScaleConstraints());
bokan 2016/07/01 21:05:12 Give the ScrollAndScaleEmulator a ref to the frame
Eric Seckler 2016/07/04 14:33:08 Done. At the moment, I don't keep a reference to t
bokan 2016/07/04 22:44:08 I would actually move the ScrollAndScaleEmulator o
3237 }
3238 }
3239
3240 void WebViewImpl::clearScrollAndScaleOverride()
3241 {
3242 if (!m_scrollAndScaleEmulator || !page() || !mainFrameImpl())
3243 return;
3244
3245 FrameView * view = mainFrameImpl()->frameView();
3246 if (!view)
3247 return;
3248
3249 m_scrollAndScaleEmulator->restoreThreadedScrolling(page());
3250
3251 view->setScrollAndScaleEmulator(nullptr);
3252 page()->frameHost().visualViewport().setScrollAndScaleEmulator(nullptr);
3253 page()->frameHost().setUserAgentPageScaleConstraints(PageScaleConstraints()) ;
bokan 2016/07/01 21:05:12 This will clear existing UA constraints. You shoul
Eric Seckler 2016/07/04 14:33:08 Done.
3254
3255 // TODO(eseckler): For some reason, we seem to need this enforce the cleared
3256 // constraints. Adding it in setScrollAndScaleOverride() makes the override
3257 // ineffective, though.
bokan 2016/07/01 21:05:13 I think you it doesn't work in the setter because
Eric Seckler 2016/07/04 14:33:08 What I'm seeing is that the scale factor is not re
bokan 2016/07/04 22:44:08 Thanks for tracking it down. See my reply in DevTo
3258 page()->frameHost().pageScaleConstraintsSet().computeFinalConstraints();
3259
3260 m_scrollAndScaleEmulator.clear();
3261 resetScrollAndScaleState();
3262 }
3263
3211 void WebViewImpl::scrollAndRescaleViewports(float scaleFactor, 3264 void WebViewImpl::scrollAndRescaleViewports(float scaleFactor,
3212 const IntPoint& mainFrameOrigin, 3265 const IntPoint& mainFrameOrigin,
3213 const FloatPoint& visualViewportOrigin) 3266 const FloatPoint& visualViewportOrigin)
3214 { 3267 {
3215 if (!page()) 3268 if (!page())
3216 return; 3269 return;
3217 3270
3218 if (!mainFrameImpl()) 3271 if (!mainFrameImpl())
3219 return; 3272 return;
3220 3273
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 constraints.maximumScale = pageScaleConstraintsSet().defaultConstraints( ).maximumScale; 3388 constraints.maximumScale = pageScaleConstraintsSet().defaultConstraints( ).maximumScale;
3336 } else { 3389 } else {
3337 constraints.minimumScale = -1; 3390 constraints.minimumScale = -1;
3338 constraints.maximumScale = -1; 3391 constraints.maximumScale = -1;
3339 } 3392 }
3340 page()->frameHost().setUserAgentPageScaleConstraints(constraints); 3393 page()->frameHost().setUserAgentPageScaleConstraints(constraints);
3341 } 3394 }
3342 3395
3343 IntSize WebViewImpl::mainFrameSize() 3396 IntSize WebViewImpl::mainFrameSize()
3344 { 3397 {
3398 FloatSize frameSize(m_size);
3399
3345 // The frame size should match the viewport size at minimum scale, since the 3400 // The frame size should match the viewport size at minimum scale, since the
3346 // viewport must always be contained by the frame. 3401 // viewport must always be contained by the frame. ScrollAndScaleEmulator
3347 FloatSize frameSize(m_size); 3402 // overrides the minimum scale in the userAgentConstraints. These overrides
3403 // should be ignored for this calculation.
3404 if (m_scrollAndScaleEmulator) {
3405 pageScaleConstraintsSet().setUserAgentConstraints(PageScaleConstraints() );
bokan 2016/07/01 21:05:13 I'd add a method to the scrollAndScaleEmulator tha
Eric Seckler 2016/07/04 14:33:08 Done.
3406 pageScaleConstraintsSet().computeFinalConstraints();
3407 }
3348 frameSize.scale(1 / minimumPageScaleFactor()); 3408 frameSize.scale(1 / minimumPageScaleFactor());
3409 if (m_scrollAndScaleEmulator) {
3410 pageScaleConstraintsSet().setUserAgentConstraints(m_scrollAndScaleEmulat or->pageScaleConstraints());
3411 pageScaleConstraintsSet().computeFinalConstraints();
3412 }
3413
3349 return expandedIntSize(frameSize); 3414 return expandedIntSize(frameSize);
3350 } 3415 }
3351 3416
3352 PageScaleConstraintsSet& WebViewImpl::pageScaleConstraintsSet() const 3417 PageScaleConstraintsSet& WebViewImpl::pageScaleConstraintsSet() const
3353 { 3418 {
3354 return page()->frameHost().pageScaleConstraintsSet(); 3419 return page()->frameHost().pageScaleConstraintsSet();
3355 } 3420 }
3356 3421
3357 void WebViewImpl::refreshPageScaleFactorAfterLayout() 3422 void WebViewImpl::refreshPageScaleFactorAfterLayout()
3358 { 3423 {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
3827 m_rootLayerScale = rootLayerScale; 3892 m_rootLayerScale = rootLayerScale;
3828 m_rootLayerOffset = rootLayerOffset; 3893 m_rootLayerOffset = rootLayerOffset;
3829 if (mainFrameImpl()) 3894 if (mainFrameImpl())
3830 mainFrameImpl()->setInputEventsTransformForEmulation(m_rootLayerOffset, m_rootLayerScale); 3895 mainFrameImpl()->setInputEventsTransformForEmulation(m_rootLayerOffset, m_rootLayerScale);
3831 updateRootLayerTransform(); 3896 updateRootLayerTransform();
3832 } 3897 }
3833 3898
3834 void WebViewImpl::enableDeviceEmulation(const WebDeviceEmulationParams& params) 3899 void WebViewImpl::enableDeviceEmulation(const WebDeviceEmulationParams& params)
3835 { 3900 {
3836 m_devToolsEmulator->enableDeviceEmulation(params); 3901 m_devToolsEmulator->enableDeviceEmulation(params);
3902 setScrollAndScaleOverride(params);
3837 } 3903 }
3838 3904
3839 void WebViewImpl::disableDeviceEmulation() 3905 void WebViewImpl::disableDeviceEmulation()
3840 { 3906 {
3907 clearScrollAndScaleOverride();
3841 m_devToolsEmulator->disableDeviceEmulation(); 3908 m_devToolsEmulator->disableDeviceEmulation();
3842 } 3909 }
3843 3910
3844 WebAXObject WebViewImpl::accessibilityObject() 3911 WebAXObject WebViewImpl::accessibilityObject()
3845 { 3912 {
3846 if (!mainFrameImpl()) 3913 if (!mainFrameImpl())
3847 return WebAXObject(); 3914 return WebAXObject();
3848 3915
3849 Document* document = mainFrameImpl()->frame()->document(); 3916 Document* document = mainFrameImpl()->frame()->document();
3850 return WebAXObject(toAXObjectCacheImpl(document->axObjectCache())->root()); 3917 return WebAXObject(toAXObjectCacheImpl(document->axObjectCache())->root());
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
4533 { 4600 {
4534 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4601 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than
4535 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. 4602 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4536 if (!page()) 4603 if (!page())
4537 return 1; 4604 return 1;
4538 4605
4539 return page()->deviceScaleFactor(); 4606 return page()->deviceScaleFactor();
4540 } 4607 }
4541 4608
4542 } // namespace blink 4609 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698