193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/*
293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved.
393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * modification, are permitted provided that the following conditions are
693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * met:
793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * in the documentation and/or other materials provided with the
1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * distribution.
1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * this software without specific prior written permission.
1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) */
3093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#ifndef PageScaleConstraintsSet_h
3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define PageScaleConstraintsSet_h
3393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "PageScaleConstraints.h"
3593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/dom/ViewportArguments.h"
3693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/platform/graphics/IntSize.h"
3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)namespace WebCore {
3993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// This class harmonizes the viewport (particularly page scale) constraints from
4193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// the meta viewport tag and other sources.
4293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class PageScaleConstraintsSet {
4393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)public:
4493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    PageScaleConstraintsSet();
4593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    PageScaleConstraints defaultConstraints() const;
4793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Settings defined in the website's viewport tag, if viewport tag support
4993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // is enabled.
5093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const PageScaleConstraints& pageDefinedConstraints() const { return m_pageDefinedConstraints; }
5193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void updatePageDefinedConstraints(const ViewportArguments&, IntSize viewSize, int layoutFallbackWidth);
52646fe2d7c64a42a490afacc3ad4851b9911c695dTorne (Richard Coles)    void adjustForAndroidWebViewQuirks(const ViewportArguments&, IntSize viewSize, int layoutFallbackWidth, float deviceScaleFactor, bool supportTargetDensityDPI, bool wideViewportQuirkEnabled, bool useWideViewport, bool loadWithOverviewMode);
5393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Constraints may also be set from Chromium -- this overrides any
5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // page-defined values.
5693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const PageScaleConstraints& userAgentConstraints() const { return m_userAgentConstraints; }
5793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void setUserAgentConstraints(const PageScaleConstraints&);
5893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Actual computed values, taking into account the above plus the current
6093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // viewport size and document width.
6193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const PageScaleConstraints& finalConstraints() const { return m_finalConstraints; }
6293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void computeFinalConstraints();
6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void adjustFinalConstraintsToContentsSize(IntSize viewSize, IntSize contentsSize, int nonOverlayScrollbarWidth);
6493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
6593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void didChangeContentsSize(IntSize contentsSize, float pageScaleFactor);
6693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
6793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // This should be set to true on each page load to note that the page scale
6893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // factor needs to be reset to its initial value.
6993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void setNeedsReset(bool);
7093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool needsReset() const { return m_needsReset; }
7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // This is set when one of the inputs to finalConstraints changes.
7393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool constraintsDirty() const { return m_constraintsDirty; }
7493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)private:
76967c603b7d25a9715865ef349860323081912ff6Alexandre Elias    PageScaleConstraints computeConstraintsStack() const;
77967c603b7d25a9715865ef349860323081912ff6Alexandre Elias
7893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    PageScaleConstraints m_pageDefinedConstraints;
7993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    PageScaleConstraints m_userAgentConstraints;
8093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    PageScaleConstraints m_finalConstraints;
8193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    int m_lastContentsWidth;
8393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool m_needsReset;
8593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool m_constraintsDirty;
8693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)};
8793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} // namespace WebCore
8993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif // PageScaleConstraintsSet_h
91