| 1 | /* |
| 2 | * Copyright (C) 2011, 2012 Nokia Corporation and/or its subsidiary(-ies) |
| 3 | * Copyright (C) 2011 Benjamin Poulain <benjamin@webkit.org> |
| 4 | * Copyright (C) 2014 Igalia S.L. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this program; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #if USE(COORDINATED_GRAPHICS) |
| 25 | |
| 26 | #include <WebCore/FloatPoint.h> |
| 27 | #include <WebCore/FloatRect.h> |
| 28 | #include <WebCore/FloatSize.h> |
| 29 | #include <WebCore/IntRect.h> |
| 30 | #include <WebCore/IntSize.h> |
| 31 | #include <WebCore/ViewportArguments.h> |
| 32 | #include <wtf/Noncopyable.h> |
| 33 | |
| 34 | namespace WebKit { |
| 35 | |
| 36 | class SimpleViewportController { |
| 37 | WTF_MAKE_NONCOPYABLE(SimpleViewportController); |
| 38 | public: |
| 39 | SimpleViewportController(const WebCore::IntSize&); |
| 40 | |
| 41 | void didChangeViewportSize(const WebCore::IntSize&); |
| 42 | void didChangeContentsSize(const WebCore::IntSize&); |
| 43 | void didChangeViewportAttributes(WebCore::ViewportAttributes&&); |
| 44 | void didScroll(const WebCore::IntPoint&); |
| 45 | |
| 46 | WebCore::FloatRect visibleContentsRect() const; |
| 47 | float pageScaleFactor() const { return m_pageScaleFactor; } |
| 48 | |
| 49 | private: |
| 50 | WebCore::FloatSize visibleContentsSize() const; |
| 51 | |
| 52 | void applyScaleAfterRenderingContents(float scale); |
| 53 | void applyPositionAfterRenderingContents(const WebCore::FloatPoint& pos); |
| 54 | |
| 55 | WebCore::FloatPoint boundContentsPosition(const WebCore::FloatPoint&) const; |
| 56 | WebCore::FloatPoint boundContentsPositionAtScale(const WebCore::FloatPoint&, float scale) const; |
| 57 | |
| 58 | bool updateMinimumScaleToFit(); |
| 59 | float innerBoundedViewportScale(float) const; |
| 60 | |
| 61 | void resetViewportToDefaultState(); |
| 62 | |
| 63 | WebCore::IntPoint m_contentsPosition; |
| 64 | WebCore::FloatSize m_contentsSize; |
| 65 | WebCore::FloatSize m_viewportSize; |
| 66 | float m_pageScaleFactor { 1 }; |
| 67 | |
| 68 | bool m_allowsUserScaling { false }; |
| 69 | float m_minimumScaleToFit { 1 }; |
| 70 | bool m_initiallyFitToViewport { false }; |
| 71 | |
| 72 | bool m_hasViewportAttribute { false }; |
| 73 | WebCore::ViewportAttributes m_rawAttributes; |
| 74 | }; |
| 75 | |
| 76 | } // namespace WebKit |
| 77 | |
| 78 | #endif // USE(COORDINATED_GRAPHICS) |
| 79 | |