Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2016 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "core/frame/ScrollAndScaleEmulator.h" | |
| 32 | |
| 33 #include "core/frame/PageScaleConstraints.h" | |
| 34 #include "core/frame/Settings.h" | |
| 35 #include "core/page/Page.h" | |
| 36 #include "core/page/scrolling/ScrollingCoordinator.h" | |
| 37 #include "platform/geometry/DoublePoint.h" | |
| 38 #include "public/platform/WebFloatPoint.h" | |
| 39 #include "public/platform/WebPoint.h" | |
| 40 #include "wtf/PassRefPtr.h" | |
| 41 | |
| 42 namespace blink { | |
| 43 | |
| 44 // static | |
| 45 PassRefPtr<ScrollAndScaleEmulator> ScrollAndScaleEmulator::create() | |
| 46 { | |
| 47 return adoptRef(new ScrollAndScaleEmulator); | |
| 48 } | |
| 49 | |
| 50 bool ScrollAndScaleEmulator::update(const IntPoint& framePosition, const DoubleP oint& visualViewportPosition, float pageScale) | |
| 51 { | |
| 52 bool changed = false; | |
| 53 | |
| 54 if (m_framePosition != framePosition) { | |
| 55 m_framePosition = framePosition; | |
| 56 changed |= true; | |
|
bokan
2016/07/01 21:05:12
These can all just be `changed = true`
Eric Seckler
2016/07/04 14:33:08
Done.
| |
| 57 } | |
| 58 | |
| 59 if (m_visualViewportPosition != visualViewportPosition) { | |
| 60 m_visualViewportPosition = visualViewportPosition; | |
| 61 changed |= true; | |
| 62 } | |
| 63 | |
| 64 if (m_pageScale != pageScale) { | |
| 65 m_pageScale = pageScale; | |
| 66 changed |= true; | |
| 67 } | |
| 68 | |
| 69 return changed; | |
| 70 } | |
| 71 | |
| 72 IntPoint ScrollAndScaleEmulator::applyFramePositionOverride(const IntPoint& posi tion, const IntPoint& minimum, const IntPoint& maximum) | |
| 73 { | |
| 74 return applyPositionOverride(position, minimum, maximum, m_framePosition); | |
| 75 } | |
| 76 | |
| 77 DoublePoint ScrollAndScaleEmulator::applyVisualViewportPositionOverride(const Do ublePoint& position, const DoublePoint& minimum, const DoublePoint& maximum) | |
| 78 { | |
| 79 return applyPositionOverride(position, minimum, maximum, m_visualViewportPos ition); | |
| 80 } | |
| 81 | |
| 82 PageScaleConstraints ScrollAndScaleEmulator::pageScaleConstraints() | |
| 83 { | |
| 84 if (m_pageScale > 0) | |
| 85 return PageScaleConstraints(m_pageScale, m_pageScale, m_pageScale); | |
| 86 return PageScaleConstraints(); | |
| 87 } | |
| 88 | |
| 89 void ScrollAndScaleEmulator::disableThreadedScrolling(Page* page) | |
| 90 { | |
| 91 m_threadedScrollingEnabledByDefault = (page->settings().threadedScrollingEna bled()); | |
|
bokan
2016/07/01 21:05:12
nit: no need for wrapping parenthesis here
Eric Seckler
2016/07/04 14:33:08
Done.
| |
| 92 page->settings().setThreadedScrollingEnabled(false); | |
| 93 | |
| 94 // Ensure that the setting is propagated through ScrollingCoordinator::mainT hreadScrollingReasons(). | |
| 95 page->scrollingCoordinator()->notifyGeometryChanged(); | |
|
bokan
2016/07/01 21:05:12
I suspect you'll also need to call setNeedsComposi
Eric Seckler
2016/07/04 14:33:08
I think you're right. We need to make sure that Sc
Ian Vollick
2016/07/04 14:48:13
Whether or not scrolling is updated is, I believe,
Eric Seckler
2016/07/04 15:06:12
Sounds good, changed to ..InputChange. Thanks, Ian
| |
| 96 } | |
| 97 | |
| 98 void ScrollAndScaleEmulator::restoreThreadedScrolling(Page* page) | |
| 99 { | |
| 100 page->settings().setThreadedScrollingEnabled(m_threadedScrollingEnabledByDef ault); | |
| 101 | |
| 102 // Ensure that the setting is propagated through ScrollingCoordinator::mainT hreadScrollingReasons(). | |
| 103 page->scrollingCoordinator()->notifyGeometryChanged(); | |
| 104 } | |
| 105 | |
| 106 ScrollAndScaleEmulator::ScrollAndScaleEmulator() | |
| 107 : m_pageScale(0) | |
| 108 , m_threadedScrollingEnabledByDefault(true) | |
| 109 { | |
| 110 } | |
| 111 | |
| 112 template <typename Point> | |
| 113 Point ScrollAndScaleEmulator::applyPositionOverride(const Point& position, const Point& minimum, const Point& maximum, const Point& override) | |
| 114 { | |
| 115 Point newPosition = position; | |
| 116 if (override.x() >= 0) | |
| 117 newPosition.setX(override.x()); | |
| 118 if (override.y() >= 0) | |
| 119 newPosition.setY(override.y()); | |
| 120 return newPosition.expandedTo(minimum).shrunkTo(maximum); | |
| 121 } | |
| 122 | |
| 123 } // namespace blink | |
| OLD | NEW |