/src/mozilla-central/gfx/layers/FrameMetrics.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "FrameMetrics.h" |
8 | | #include "gfxPrefs.h" |
9 | | #include "nsStyleConsts.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace layers { |
13 | | |
14 | | const FrameMetrics::ViewID FrameMetrics::NULL_SCROLL_ID = 0; |
15 | | |
16 | | void |
17 | | FrameMetrics::RecalculateViewportOffset() |
18 | 0 | { |
19 | 0 | if (!mIsRootContent) { |
20 | 0 | return; |
21 | 0 | } |
22 | 0 | CSSRect visualViewport = GetVisualViewport(); |
23 | 0 | // If the visual viewport is contained within the layout viewport, we don't |
24 | 0 | // need to make any adjustments, so we can exit early. |
25 | 0 | // |
26 | 0 | // Additionally, if the composition bounds changes (due to an orientation |
27 | 0 | // change, window resize, etc.), it may take a few frames for mViewport to |
28 | 0 | // update and during that time, the visual viewport may be larger than the |
29 | 0 | // layout viewport. In such situations, we take an early exit if the visual |
30 | 0 | // viewport contains the layout viewport. |
31 | 0 | if (mViewport.Contains(visualViewport) || visualViewport.Contains(mViewport)) { |
32 | 0 | return; |
33 | 0 | } |
34 | 0 | |
35 | 0 | // If visual viewport size is greater than the layout viewport, move the layout |
36 | 0 | // viewport such that it remains inside the visual viewport. Otherwise, |
37 | 0 | // move the layout viewport such that the visual viewport is contained |
38 | 0 | // inside the layout viewport. |
39 | 0 | if ((mViewport.Width() < visualViewport.Width() && |
40 | 0 | !FuzzyEqualsMultiplicative(mViewport.Width(), visualViewport.Width())) || |
41 | 0 | (mViewport.Height() < visualViewport.Height() && |
42 | 0 | !FuzzyEqualsMultiplicative(mViewport.Height(), visualViewport.Height()))) { |
43 | 0 |
|
44 | 0 | if (mViewport.X() < visualViewport.X()) { |
45 | 0 | // layout viewport moves right |
46 | 0 | mViewport.MoveToX(visualViewport.X()); |
47 | 0 | } else if (visualViewport.XMost() < mViewport.XMost()) { |
48 | 0 | // layout viewport moves left |
49 | 0 | mViewport.MoveByX(visualViewport.XMost() - mViewport.XMost()); |
50 | 0 | } |
51 | 0 | if (mViewport.Y() < visualViewport.Y()) { |
52 | 0 | // layout viewport moves down |
53 | 0 | mViewport.MoveToY(visualViewport.Y()); |
54 | 0 | } else if (visualViewport.YMost() < mViewport.YMost()) { |
55 | 0 | // layout viewport moves up |
56 | 0 | mViewport.MoveByY(visualViewport.YMost() - mViewport.YMost()); |
57 | 0 | } |
58 | 0 | } else { |
59 | 0 |
|
60 | 0 | if (visualViewport.X() < mViewport.X()) { |
61 | 0 | mViewport.MoveToX(visualViewport.X()); |
62 | 0 | } else if (mViewport.XMost() < visualViewport.XMost()) { |
63 | 0 | mViewport.MoveByX(visualViewport.XMost() - mViewport.XMost()); |
64 | 0 | } |
65 | 0 | if (visualViewport.Y() < mViewport.Y()) { |
66 | 0 | mViewport.MoveToY(visualViewport.Y()); |
67 | 0 | } else if (mViewport.YMost() < visualViewport.YMost()) { |
68 | 0 | mViewport.MoveByY(visualViewport.YMost() - mViewport.YMost()); |
69 | 0 | } |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | void |
74 | 0 | ScrollMetadata::SetUsesContainerScrolling(bool aValue) { |
75 | 0 | MOZ_ASSERT_IF(aValue, gfxPrefs::LayoutUseContainersForRootFrames()); |
76 | 0 | mUsesContainerScrolling = aValue; |
77 | 0 | } |
78 | | |
79 | | static OverscrollBehavior |
80 | | ToOverscrollBehavior(StyleOverscrollBehavior aBehavior) |
81 | 0 | { |
82 | 0 | switch (aBehavior) { |
83 | 0 | case StyleOverscrollBehavior::Auto: |
84 | 0 | return OverscrollBehavior::Auto; |
85 | 0 | case StyleOverscrollBehavior::Contain: |
86 | 0 | return OverscrollBehavior::Contain; |
87 | 0 | case StyleOverscrollBehavior::None: |
88 | 0 | return OverscrollBehavior::None; |
89 | 0 | } |
90 | 0 | MOZ_ASSERT_UNREACHABLE("Invalid overscroll behavior"); |
91 | 0 | return OverscrollBehavior::Auto; |
92 | 0 | } |
93 | | |
94 | | OverscrollBehaviorInfo |
95 | | OverscrollBehaviorInfo::FromStyleConstants(StyleOverscrollBehavior aBehaviorX, |
96 | | StyleOverscrollBehavior aBehaviorY) |
97 | 0 | { |
98 | 0 | OverscrollBehaviorInfo result; |
99 | 0 | result.mBehaviorX = ToOverscrollBehavior(aBehaviorX); |
100 | 0 | result.mBehaviorY = ToOverscrollBehavior(aBehaviorY); |
101 | 0 | return result; |
102 | 0 | } |
103 | | |
104 | | StaticAutoPtr<const ScrollMetadata> ScrollMetadata::sNullMetadata; |
105 | | |
106 | | } |
107 | | } |