| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 if (!frame()->host()->settings().inertVisualViewport()) | 969 if (!frame()->host()->settings().inertVisualViewport()) |
| 970 return m_visualViewport->pageX(); | 970 return m_visualViewport->pageX(); |
| 971 | 971 |
| 972 FrameView* view = frame()->view(); | 972 FrameView* view = frame()->view(); |
| 973 if (!view) | 973 if (!view) |
| 974 return 0; | 974 return 0; |
| 975 | 975 |
| 976 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 976 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 977 | 977 |
| 978 double viewportX = | 978 double viewportX = |
| 979 view->layoutViewportScrollableArea()->scrollPositionDouble().x(); | 979 view->layoutViewportScrollableArea()->scrollOffset().width(); |
| 980 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor()); | 980 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor()); |
| 981 } | 981 } |
| 982 | 982 |
| 983 double LocalDOMWindow::scrollY() const { | 983 double LocalDOMWindow::scrollY() const { |
| 984 if (!frame() || !frame()->host()) | 984 if (!frame() || !frame()->host()) |
| 985 return 0; | 985 return 0; |
| 986 | 986 |
| 987 if (!frame()->host()->settings().inertVisualViewport()) | 987 if (!frame()->host()->settings().inertVisualViewport()) |
| 988 return m_visualViewport->pageY(); | 988 return m_visualViewport->pageY(); |
| 989 | 989 |
| 990 FrameView* view = frame()->view(); | 990 FrameView* view = frame()->view(); |
| 991 if (!view) | 991 if (!view) |
| 992 return 0; | 992 return 0; |
| 993 | 993 |
| 994 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 994 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 995 | 995 |
| 996 double viewportY = | 996 double viewportY = |
| 997 view->layoutViewportScrollableArea()->scrollPositionDouble().y(); | 997 view->layoutViewportScrollableArea()->scrollOffset().height(); |
| 998 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor()); | 998 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor()); |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 DOMVisualViewport* LocalDOMWindow::visualViewport() { | 1001 DOMVisualViewport* LocalDOMWindow::visualViewport() { |
| 1002 if (!frame()) | 1002 if (!frame()) |
| 1003 return nullptr; | 1003 return nullptr; |
| 1004 | 1004 |
| 1005 return m_visualViewport; | 1005 return m_visualViewport; |
| 1006 } | 1006 } |
| 1007 | 1007 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 if (!host) | 1113 if (!host) |
| 1114 return; | 1114 return; |
| 1115 | 1115 |
| 1116 x = ScrollableArea::normalizeNonFiniteScroll(x); | 1116 x = ScrollableArea::normalizeNonFiniteScroll(x); |
| 1117 y = ScrollableArea::normalizeNonFiniteScroll(y); | 1117 y = ScrollableArea::normalizeNonFiniteScroll(y); |
| 1118 | 1118 |
| 1119 ScrollableArea* viewport = host->settings().inertVisualViewport() | 1119 ScrollableArea* viewport = host->settings().inertVisualViewport() |
| 1120 ? view->layoutViewportScrollableArea() | 1120 ? view->layoutViewportScrollableArea() |
| 1121 : view->getScrollableArea(); | 1121 : view->getScrollableArea(); |
| 1122 | 1122 |
| 1123 DoublePoint currentOffset = viewport->scrollPositionDouble(); | 1123 ScrollOffset currentOffset = viewport->scrollOffset(); |
| 1124 DoubleSize scaledDelta(x * frame()->pageZoomFactor(), | 1124 ScrollOffset scaledDelta(x * frame()->pageZoomFactor(), |
| 1125 y * frame()->pageZoomFactor()); | 1125 y * frame()->pageZoomFactor()); |
| 1126 | 1126 |
| 1127 viewport->setScrollPosition(currentOffset + scaledDelta, ProgrammaticScroll, | 1127 viewport->setScrollOffset(currentOffset + scaledDelta, ProgrammaticScroll, |
| 1128 scrollBehavior); | 1128 scrollBehavior); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 void LocalDOMWindow::scrollBy(const ScrollToOptions& scrollToOptions) const { | 1131 void LocalDOMWindow::scrollBy(const ScrollToOptions& scrollToOptions) const { |
| 1132 double x = 0.0; | 1132 double x = 0.0; |
| 1133 double y = 0.0; | 1133 double y = 0.0; |
| 1134 if (scrollToOptions.hasLeft()) | 1134 if (scrollToOptions.hasLeft()) |
| 1135 x = scrollToOptions.left(); | 1135 x = scrollToOptions.left(); |
| 1136 if (scrollToOptions.hasTop()) | 1136 if (scrollToOptions.hasTop()) |
| 1137 y = scrollToOptions.top(); | 1137 y = scrollToOptions.top(); |
| 1138 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; | 1138 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1154 return; | 1154 return; |
| 1155 | 1155 |
| 1156 x = ScrollableArea::normalizeNonFiniteScroll(x); | 1156 x = ScrollableArea::normalizeNonFiniteScroll(x); |
| 1157 y = ScrollableArea::normalizeNonFiniteScroll(y); | 1157 y = ScrollableArea::normalizeNonFiniteScroll(y); |
| 1158 | 1158 |
| 1159 // It is only necessary to have an up-to-date layout if the position may be | 1159 // It is only necessary to have an up-to-date layout if the position may be |
| 1160 // clamped, which is never the case for (0, 0). | 1160 // clamped, which is never the case for (0, 0). |
| 1161 if (x || y) | 1161 if (x || y) |
| 1162 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1162 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1163 | 1163 |
| 1164 DoublePoint layoutPos(x * frame()->pageZoomFactor(), | 1164 ScrollOffset layoutOffset(x * frame()->pageZoomFactor(), |
| 1165 y * frame()->pageZoomFactor()); | 1165 y * frame()->pageZoomFactor()); |
| 1166 ScrollableArea* viewport = host->settings().inertVisualViewport() | 1166 ScrollableArea* viewport = host->settings().inertVisualViewport() |
| 1167 ? view->layoutViewportScrollableArea() | 1167 ? view->layoutViewportScrollableArea() |
| 1168 : view->getScrollableArea(); | 1168 : view->getScrollableArea(); |
| 1169 viewport->setScrollPosition(layoutPos, ProgrammaticScroll, | 1169 viewport->setScrollOffset(layoutOffset, ProgrammaticScroll, |
| 1170 ScrollBehaviorAuto); | 1170 ScrollBehaviorAuto); |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const { | 1173 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const { |
| 1174 if (!isCurrentlyDisplayedInFrame()) | 1174 if (!isCurrentlyDisplayedInFrame()) |
| 1175 return; | 1175 return; |
| 1176 | 1176 |
| 1177 FrameView* view = frame()->view(); | 1177 FrameView* view = frame()->view(); |
| 1178 if (!view) | 1178 if (!view) |
| 1179 return; | 1179 return; |
| 1180 | 1180 |
| 1181 FrameHost* host = frame()->host(); | 1181 FrameHost* host = frame()->host(); |
| 1182 if (!host) | 1182 if (!host) |
| 1183 return; | 1183 return; |
| 1184 | 1184 |
| 1185 // It is only necessary to have an up-to-date layout if the position may be | 1185 // It is only necessary to have an up-to-date layout if the position may be |
| 1186 // clamped, which is never the case for (0, 0). | 1186 // clamped, which is never the case for (0, 0). |
| 1187 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() || | 1187 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() || |
| 1188 scrollToOptions.left() || scrollToOptions.top()) { | 1188 scrollToOptions.left() || scrollToOptions.top()) { |
| 1189 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1189 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1190 } | 1190 } |
| 1191 | 1191 |
| 1192 double scaledX = 0.0; | 1192 double scaledX = 0.0; |
| 1193 double scaledY = 0.0; | 1193 double scaledY = 0.0; |
| 1194 | 1194 |
| 1195 ScrollableArea* viewport = host->settings().inertVisualViewport() | 1195 ScrollableArea* viewport = host->settings().inertVisualViewport() |
| 1196 ? view->layoutViewportScrollableArea() | 1196 ? view->layoutViewportScrollableArea() |
| 1197 : view->getScrollableArea(); | 1197 : view->getScrollableArea(); |
| 1198 | 1198 |
| 1199 DoublePoint currentOffset = viewport->scrollPositionDouble(); | 1199 ScrollOffset currentOffset = viewport->scrollOffset(); |
| 1200 scaledX = currentOffset.x(); | 1200 scaledX = currentOffset.width(); |
| 1201 scaledY = currentOffset.y(); | 1201 scaledY = currentOffset.height(); |
| 1202 | 1202 |
| 1203 if (scrollToOptions.hasLeft()) | 1203 if (scrollToOptions.hasLeft()) |
| 1204 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) * | 1204 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) * |
| 1205 frame()->pageZoomFactor(); | 1205 frame()->pageZoomFactor(); |
| 1206 | 1206 |
| 1207 if (scrollToOptions.hasTop()) | 1207 if (scrollToOptions.hasTop()) |
| 1208 scaledY = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.top()) * | 1208 scaledY = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.top()) * |
| 1209 frame()->pageZoomFactor(); | 1209 frame()->pageZoomFactor(); |
| 1210 | 1210 |
| 1211 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; | 1211 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; |
| 1212 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), | 1212 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), |
| 1213 scrollBehavior); | 1213 scrollBehavior); |
| 1214 | 1214 |
| 1215 viewport->setScrollPosition(DoublePoint(scaledX, scaledY), ProgrammaticScroll, | 1215 viewport->setScrollOffset(ScrollOffset(scaledX, scaledY), ProgrammaticScroll, |
| 1216 scrollBehavior); | 1216 scrollBehavior); |
| 1217 } | 1217 } |
| 1218 | 1218 |
| 1219 void LocalDOMWindow::moveBy(int x, int y) const { | 1219 void LocalDOMWindow::moveBy(int x, int y) const { |
| 1220 if (!frame() || !frame()->isMainFrame()) | 1220 if (!frame() || !frame()->isMainFrame()) |
| 1221 return; | 1221 return; |
| 1222 | 1222 |
| 1223 FrameHost* host = frame()->host(); | 1223 FrameHost* host = frame()->host(); |
| 1224 if (!host) | 1224 if (!host) |
| 1225 return; | 1225 return; |
| 1226 | 1226 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1555 | 1555 |
| 1556 LocalFrame* LocalDOMWindow::frame() const { | 1556 LocalFrame* LocalDOMWindow::frame() const { |
| 1557 // If the LocalDOMWindow still has a frame reference, that frame must point | 1557 // If the LocalDOMWindow still has a frame reference, that frame must point |
| 1558 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation | 1558 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation |
| 1559 // where script execution leaks between different LocalDOMWindows. | 1559 // where script execution leaks between different LocalDOMWindows. |
| 1560 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this); | 1560 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this); |
| 1561 return m_frame; | 1561 return m_frame; |
| 1562 } | 1562 } |
| 1563 | 1563 |
| 1564 } // namespace blink | 1564 } // namespace blink |
| OLD | NEW |