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/Frame.h" | |
| 34 #include "core/frame/FrameHost.h" | |
| 35 #include "core/frame/FrameView.h" | |
| 36 #include "core/frame/PageScaleConstraintsSet.h" | |
| 37 #include "core/frame/Settings.h" | |
| 38 #include "core/frame/VisualViewport.h" | |
| 39 #include "core/layout/compositing/PaintLayerCompositor.h" | |
| 40 #include "core/page/Page.h" | |
| 41 #include "core/page/scrolling/ScrollingCoordinator.h" | |
| 42 #include "platform/geometry/FloatSize.h" | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 namespace { | |
| 47 | |
| 48 FrameView* frameViewFromPage(Page* page) | |
| 49 { | |
| 50 if (!page->mainFrame() || !page->mainFrame()->isLocalFrame()) | |
|
bokan
2016/07/04 22:44:09
It might be more clear to make sure that we never
Eric Seckler
2016/07/05 16:46:51
Done.
| |
| 51 return nullptr; | |
| 52 return page->deprecatedLocalMainFrame()->view(); | |
| 53 } | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 // static | |
| 58 PassRefPtr<ScrollAndScaleEmulator> ScrollAndScaleEmulator::create(Page* page) | |
| 59 { | |
| 60 ScrollAndScaleEmulator* emulator = new ScrollAndScaleEmulator(); | |
| 61 | |
| 62 // Force main thread scrolling, because we do not apply scroll position | |
| 63 // overrides in the compositor thread. | |
| 64 emulator->disableThreadedScrolling(page); | |
|
bokan
2016/07/04 22:44:09
Similarly to the UA constraints, store m_originalT
Eric Seckler
2016/07/05 16:46:51
Done.
| |
| 65 | |
| 66 emulator->setOriginalPageScaleConstraints( | |
| 67 page->frameHost().pageScaleConstraintsSet().userAgentConstraints()); | |
| 68 | |
| 69 return adoptRef(emulator); | |
| 70 } | |
| 71 | |
| 72 void ScrollAndScaleEmulator::update(Page* page, const IntPoint& framePosition, c onst DoublePoint& visualViewportPosition, float pageScale) | |
| 73 { | |
| 74 bool changed = false; | |
| 75 | |
| 76 if (m_framePosition != framePosition) { | |
| 77 m_framePosition = framePosition; | |
| 78 changed = true; | |
| 79 } | |
| 80 | |
| 81 if (m_visualViewportPosition != visualViewportPosition) { | |
| 82 m_visualViewportPosition = visualViewportPosition; | |
| 83 changed = true; | |
| 84 } | |
| 85 | |
| 86 if (m_pageScale != pageScale) { | |
| 87 m_pageScale = pageScale; | |
| 88 changed = true; | |
| 89 } | |
| 90 | |
| 91 if (changed) { | |
| 92 if (FrameView* view = frameViewFromPage(page)) | |
| 93 view->setScrollAndScaleEmulator(this); | |
| 94 page->frameHost().setUserAgentPageScaleConstraints(pageScaleConstraints( )); | |
| 95 page->frameHost().visualViewport().setScrollAndScaleEmulator(this); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 void ScrollAndScaleEmulator::clear(Page* page) | |
| 100 { | |
| 101 m_framePosition = IntPoint(-1, -1); | |
| 102 m_visualViewportPosition = DoublePoint(-1, -1); | |
| 103 m_pageScale = 0; | |
| 104 | |
| 105 restoreThreadedScrolling(page); | |
| 106 | |
| 107 if (FrameView* view = frameViewFromPage(page)) | |
| 108 view->setScrollAndScaleEmulator(nullptr); | |
| 109 page->frameHost().setUserAgentPageScaleConstraints(m_originalPageScaleConstr aints); | |
| 110 page->frameHost().visualViewport().setScrollAndScaleEmulator(nullptr); | |
| 111 } | |
| 112 | |
| 113 IntPoint ScrollAndScaleEmulator::applyFramePositionOverride(const IntPoint& posi tion) | |
| 114 { | |
| 115 return applyPositionOverride(position, m_framePosition); | |
| 116 } | |
| 117 | |
| 118 DoublePoint ScrollAndScaleEmulator::applyVisualViewportPositionOverride(const Do ublePoint& position) | |
| 119 { | |
| 120 return applyPositionOverride(position, m_visualViewportPosition); | |
| 121 } | |
| 122 | |
| 123 IntSize ScrollAndScaleEmulator::mainFrameSize(Page* page, const IntSize& webView Size) | |
| 124 { | |
| 125 PageScaleConstraintsSet constraints = page->frameHost().pageScaleConstraints Set(); | |
| 126 constraints.setUserAgentConstraints(m_originalPageScaleConstraints); | |
|
bokan
2016/07/04 22:44:09
Add a short comment as to why this is necessary.
Eric Seckler
2016/07/05 16:46:51
Done.
| |
| 127 constraints.computeFinalConstraints(); | |
| 128 | |
| 129 FloatSize frameSize(webViewSize); | |
| 130 frameSize.scale(1 / constraints.finalConstraints().minimumScale); | |
| 131 return expandedIntSize(frameSize); | |
| 132 } | |
| 133 | |
| 134 ScrollAndScaleEmulator::ScrollAndScaleEmulator() | |
| 135 : m_framePosition(IntPoint(-1, -1)) | |
| 136 , m_visualViewportPosition(DoublePoint(-1, -1)) | |
| 137 , m_pageScale(0) | |
| 138 , m_originalThreadedScrollingEnabled(true) | |
| 139 { | |
| 140 } | |
| 141 | |
| 142 void ScrollAndScaleEmulator::disableThreadedScrolling(Page* page) | |
| 143 { | |
| 144 m_originalThreadedScrollingEnabled = page->settings().threadedScrollingEnabl ed(); | |
| 145 page->settings().setThreadedScrollingEnabled(false); | |
| 146 | |
| 147 // Ensure that the setting is propagated through ScrollingCoordinator::mainT hreadScrollingReasons(). | |
| 148 page->scrollingCoordinator()->notifyGeometryChanged(); | |
|
bokan
2016/07/04 22:44:09
Factor the notifyGeometryChanged and needsComposit
Eric Seckler
2016/07/05 16:46:51
Done.
| |
| 149 | |
| 150 FrameView* view = frameViewFromPage(page); | |
| 151 if (PaintLayerCompositor* compositor = | |
| 152 (view && !view->layoutViewItem().isNull()) | |
| 153 ? view->layoutViewItem().compositor() | |
| 154 : nullptr) | |
| 155 compositor->setNeedsCompositingUpdate(CompositingUpdateAfterCompositingI nputChange); | |
| 156 } | |
| 157 | |
| 158 void ScrollAndScaleEmulator::restoreThreadedScrolling(Page* page) | |
| 159 { | |
| 160 page->settings().setThreadedScrollingEnabled(m_originalThreadedScrollingEnab led); | |
| 161 | |
| 162 // Ensure that the setting is propagated through ScrollingCoordinator::mainT hreadScrollingReasons(). | |
| 163 page->scrollingCoordinator()->notifyGeometryChanged(); | |
| 164 | |
| 165 FrameView* view = frameViewFromPage(page); | |
| 166 if (PaintLayerCompositor* compositor = | |
| 167 (view && !view->layoutViewItem().isNull()) | |
| 168 ? view->layoutViewItem().compositor() | |
| 169 : nullptr) | |
| 170 compositor->setNeedsCompositingUpdate(CompositingUpdateAfterCompositingI nputChange); | |
| 171 } | |
| 172 | |
| 173 PageScaleConstraints ScrollAndScaleEmulator::pageScaleConstraints() | |
| 174 { | |
| 175 if (m_pageScale > 0) | |
| 176 return PageScaleConstraints(m_pageScale, m_pageScale, m_pageScale); | |
| 177 return m_originalPageScaleConstraints; | |
| 178 } | |
| 179 | |
| 180 void ScrollAndScaleEmulator::setOriginalPageScaleConstraints(const PageScaleCons traints& constraints) | |
| 181 { | |
| 182 m_originalPageScaleConstraints = constraints; | |
| 183 } | |
| 184 | |
| 185 template <typename Point> | |
| 186 Point ScrollAndScaleEmulator::applyPositionOverride(const Point& position, const Point& override) | |
| 187 { | |
| 188 Point newPosition = position; | |
| 189 if (override.x() >= 0) | |
| 190 newPosition.setX(override.x()); | |
| 191 if (override.y() >= 0) | |
| 192 newPosition.setY(override.y()); | |
| 193 return newPosition; | |
| 194 } | |
| 195 | |
| 196 } // namespace blink | |
| OLD | NEW |