Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 if (!frame()->host()->settings().inertVisualViewport()) 962 if (!frame()->host()->settings().inertVisualViewport())
963 return m_visualViewport->pageX(); 963 return m_visualViewport->pageX();
964 964
965 FrameView* view = frame()->view(); 965 FrameView* view = frame()->view();
966 if (!view) 966 if (!view)
967 return 0; 967 return 0;
968 968
969 document()->updateStyleAndLayoutIgnorePendingStylesheets(); 969 document()->updateStyleAndLayoutIgnorePendingStylesheets();
970 970
971 double viewportX = 971 double viewportX =
972 view->layoutViewportScrollableArea()->scrollPositionDouble().x(); 972 view->layoutViewportScrollableArea()->scrollOffset().width();
973 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor()); 973 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor());
974 } 974 }
975 975
976 double LocalDOMWindow::scrollY() const { 976 double LocalDOMWindow::scrollY() const {
977 if (!frame() || !frame()->host()) 977 if (!frame() || !frame()->host())
978 return 0; 978 return 0;
979 979
980 if (!frame()->host()->settings().inertVisualViewport()) 980 if (!frame()->host()->settings().inertVisualViewport())
981 return m_visualViewport->pageY(); 981 return m_visualViewport->pageY();
982 982
983 FrameView* view = frame()->view(); 983 FrameView* view = frame()->view();
984 if (!view) 984 if (!view)
985 return 0; 985 return 0;
986 986
987 document()->updateStyleAndLayoutIgnorePendingStylesheets(); 987 document()->updateStyleAndLayoutIgnorePendingStylesheets();
988 988
989 double viewportY = 989 double viewportY =
990 view->layoutViewportScrollableArea()->scrollPositionDouble().y(); 990 view->layoutViewportScrollableArea()->scrollOffset().height();
991 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor()); 991 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor());
992 } 992 }
993 993
994 DOMVisualViewport* LocalDOMWindow::visualViewport() { 994 DOMVisualViewport* LocalDOMWindow::visualViewport() {
995 if (!frame()) 995 if (!frame())
996 return nullptr; 996 return nullptr;
997 997
998 return m_visualViewport; 998 return m_visualViewport;
999 } 999 }
1000 1000
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 if (!host) 1106 if (!host)
1107 return; 1107 return;
1108 1108
1109 x = ScrollableArea::normalizeNonFiniteScroll(x); 1109 x = ScrollableArea::normalizeNonFiniteScroll(x);
1110 y = ScrollableArea::normalizeNonFiniteScroll(y); 1110 y = ScrollableArea::normalizeNonFiniteScroll(y);
1111 1111
1112 ScrollableArea* viewport = host->settings().inertVisualViewport() 1112 ScrollableArea* viewport = host->settings().inertVisualViewport()
1113 ? view->layoutViewportScrollableArea() 1113 ? view->layoutViewportScrollableArea()
1114 : view->getScrollableArea(); 1114 : view->getScrollableArea();
1115 1115
1116 DoublePoint currentOffset = viewport->scrollPositionDouble(); 1116 ScrollOffset currentOffset = viewport->scrollOffset();
1117 DoubleSize scaledDelta(x * frame()->pageZoomFactor(), 1117 ScrollOffset scaledDelta(x * frame()->pageZoomFactor(),
1118 y * frame()->pageZoomFactor()); 1118 y * frame()->pageZoomFactor());
1119 1119
1120 viewport->setScrollPosition(currentOffset + scaledDelta, ProgrammaticScroll, 1120 viewport->setScrollOffset(currentOffset + scaledDelta, ProgrammaticScroll,
1121 scrollBehavior); 1121 scrollBehavior);
1122 } 1122 }
1123 1123
1124 void LocalDOMWindow::scrollBy(const ScrollToOptions& scrollToOptions) const { 1124 void LocalDOMWindow::scrollBy(const ScrollToOptions& scrollToOptions) const {
1125 double x = 0.0; 1125 double x = 0.0;
1126 double y = 0.0; 1126 double y = 0.0;
1127 if (scrollToOptions.hasLeft()) 1127 if (scrollToOptions.hasLeft())
1128 x = scrollToOptions.left(); 1128 x = scrollToOptions.left();
1129 if (scrollToOptions.hasTop()) 1129 if (scrollToOptions.hasTop())
1130 y = scrollToOptions.top(); 1130 y = scrollToOptions.top();
1131 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; 1131 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
(...skipping 15 matching lines...) Expand all
1147 return; 1147 return;
1148 1148
1149 x = ScrollableArea::normalizeNonFiniteScroll(x); 1149 x = ScrollableArea::normalizeNonFiniteScroll(x);
1150 y = ScrollableArea::normalizeNonFiniteScroll(y); 1150 y = ScrollableArea::normalizeNonFiniteScroll(y);
1151 1151
1152 // It is only necessary to have an up-to-date layout if the position may be cl amped, 1152 // It is only necessary to have an up-to-date layout if the position may be cl amped,
1153 // which is never the case for (0, 0). 1153 // which is never the case for (0, 0).
1154 if (x || y) 1154 if (x || y)
1155 document()->updateStyleAndLayoutIgnorePendingStylesheets(); 1155 document()->updateStyleAndLayoutIgnorePendingStylesheets();
1156 1156
1157 DoublePoint layoutPos(x * frame()->pageZoomFactor(), 1157 ScrollOffset layoutOffset(x * frame()->pageZoomFactor(),
1158 y * frame()->pageZoomFactor()); 1158 y * frame()->pageZoomFactor());
1159 ScrollableArea* viewport = host->settings().inertVisualViewport() 1159 ScrollableArea* viewport = host->settings().inertVisualViewport()
1160 ? view->layoutViewportScrollableArea() 1160 ? view->layoutViewportScrollableArea()
1161 : view->getScrollableArea(); 1161 : view->getScrollableArea();
1162 viewport->setScrollPosition(layoutPos, ProgrammaticScroll, 1162 viewport->setScrollOffset(layoutOffset, ProgrammaticScroll,
1163 ScrollBehaviorAuto); 1163 ScrollBehaviorAuto);
1164 } 1164 }
1165 1165
1166 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const { 1166 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const {
1167 if (!isCurrentlyDisplayedInFrame()) 1167 if (!isCurrentlyDisplayedInFrame())
1168 return; 1168 return;
1169 1169
1170 FrameView* view = frame()->view(); 1170 FrameView* view = frame()->view();
1171 if (!view) 1171 if (!view)
1172 return; 1172 return;
1173 1173
1174 FrameHost* host = frame()->host(); 1174 FrameHost* host = frame()->host();
1175 if (!host) 1175 if (!host)
1176 return; 1176 return;
1177 1177
1178 // It is only necessary to have an up-to-date layout if the position may be cl amped, 1178 // It is only necessary to have an up-to-date layout if the position may be cl amped,
1179 // which is never the case for (0, 0). 1179 // which is never the case for (0, 0).
1180 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() || 1180 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() ||
1181 scrollToOptions.left() || scrollToOptions.top()) { 1181 scrollToOptions.left() || scrollToOptions.top()) {
1182 document()->updateStyleAndLayoutIgnorePendingStylesheets(); 1182 document()->updateStyleAndLayoutIgnorePendingStylesheets();
1183 } 1183 }
1184 1184
1185 double scaledX = 0.0; 1185 double scaledX = 0.0;
1186 double scaledY = 0.0; 1186 double scaledY = 0.0;
1187 1187
1188 ScrollableArea* viewport = host->settings().inertVisualViewport() 1188 ScrollableArea* viewport = host->settings().inertVisualViewport()
1189 ? view->layoutViewportScrollableArea() 1189 ? view->layoutViewportScrollableArea()
1190 : view->getScrollableArea(); 1190 : view->getScrollableArea();
1191 1191
1192 DoublePoint currentOffset = viewport->scrollPositionDouble(); 1192 ScrollOffset currentOffset = viewport->scrollOffset();
1193 scaledX = currentOffset.x(); 1193 scaledX = currentOffset.width();
1194 scaledY = currentOffset.y(); 1194 scaledY = currentOffset.height();
1195 1195
1196 if (scrollToOptions.hasLeft()) 1196 if (scrollToOptions.hasLeft())
1197 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) * 1197 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) *
1198 frame()->pageZoomFactor(); 1198 frame()->pageZoomFactor();
1199 1199
1200 if (scrollToOptions.hasTop()) 1200 if (scrollToOptions.hasTop())
1201 scaledY = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.top()) * 1201 scaledY = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.top()) *
1202 frame()->pageZoomFactor(); 1202 frame()->pageZoomFactor();
1203 1203
1204 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; 1204 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
1205 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), 1205 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(),
1206 scrollBehavior); 1206 scrollBehavior);
1207 1207
1208 viewport->setScrollPosition(DoublePoint(scaledX, scaledY), ProgrammaticScroll, 1208 viewport->setScrollOffset(ScrollOffset(scaledX, scaledY), ProgrammaticScroll,
1209 scrollBehavior); 1209 scrollBehavior);
1210 } 1210 }
1211 1211
1212 void LocalDOMWindow::moveBy(int x, int y) const { 1212 void LocalDOMWindow::moveBy(int x, int y) const {
1213 if (!frame() || !frame()->isMainFrame()) 1213 if (!frame() || !frame()->isMainFrame())
1214 return; 1214 return;
1215 1215
1216 FrameHost* host = frame()->host(); 1216 FrameHost* host = frame()->host();
1217 if (!host) 1217 if (!host)
1218 return; 1218 return;
1219 1219
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 1544
1545 LocalFrame* LocalDOMWindow::frame() const { 1545 LocalFrame* LocalDOMWindow::frame() const {
1546 // If the LocalDOMWindow still has a frame reference, that frame must point 1546 // If the LocalDOMWindow still has a frame reference, that frame must point
1547 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation 1547 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation
1548 // where script execution leaks between different LocalDOMWindows. 1548 // where script execution leaks between different LocalDOMWindows.
1549 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this); 1549 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this);
1550 return m_frame; 1550 return m_frame;
1551 } 1551 }
1552 1552
1553 } // namespace blink 1553 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698