| 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 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 element, pseudo_id, rules_to_include); | 1173 element, pseudo_id, rules_to_include); |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 double LocalDOMWindow::devicePixelRatio() const { | 1176 double LocalDOMWindow::devicePixelRatio() const { |
| 1177 if (!GetFrame()) | 1177 if (!GetFrame()) |
| 1178 return 0.0; | 1178 return 0.0; |
| 1179 | 1179 |
| 1180 return GetFrame()->DevicePixelRatio(); | 1180 return GetFrame()->DevicePixelRatio(); |
| 1181 } | 1181 } |
| 1182 | 1182 |
| 1183 void LocalDOMWindow::scrollViewportTo(ScrollableArea* viewport, | |
| 1184 const ScrollOffset& offset, | |
| 1185 ScrollBehavior scroll_behavior) const { | |
| 1186 if (SmoothScrollSequencer* sequencer = | |
| 1187 GetFrame()->GetPage()->GetSmoothScrollSequencer()) { | |
| 1188 sequencer->AbortAnimations(); | |
| 1189 if (scroll_behavior == kScrollBehaviorSmooth) { | |
| 1190 sequencer->QueueAnimation(viewport, offset); | |
| 1191 sequencer->RunQueuedAnimations(); | |
| 1192 } else { | |
| 1193 viewport->SetScrollOffset(offset, kProgrammaticScroll, scroll_behavior); | |
| 1194 } | |
| 1195 } | |
| 1196 } | |
| 1197 | |
| 1198 void LocalDOMWindow::scrollBy(double x, | 1183 void LocalDOMWindow::scrollBy(double x, |
| 1199 double y, | 1184 double y, |
| 1200 ScrollBehavior scroll_behavior) const { | 1185 ScrollBehavior scroll_behavior) const { |
| 1201 if (!IsCurrentlyDisplayedInFrame()) | 1186 if (!IsCurrentlyDisplayedInFrame()) |
| 1202 return; | 1187 return; |
| 1203 | 1188 |
| 1204 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 1189 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| 1205 | 1190 |
| 1206 LocalFrameView* view = GetFrame()->View(); | 1191 LocalFrameView* view = GetFrame()->View(); |
| 1207 if (!view) | 1192 if (!view) |
| 1208 return; | 1193 return; |
| 1209 | 1194 |
| 1210 Page* page = GetFrame()->GetPage(); | 1195 Page* page = GetFrame()->GetPage(); |
| 1211 if (!page) | 1196 if (!page) |
| 1212 return; | 1197 return; |
| 1213 | 1198 |
| 1214 x = ScrollableArea::NormalizeNonFiniteScroll(x); | 1199 x = ScrollableArea::NormalizeNonFiniteScroll(x); |
| 1215 y = ScrollableArea::NormalizeNonFiniteScroll(y); | 1200 y = ScrollableArea::NormalizeNonFiniteScroll(y); |
| 1216 | 1201 |
| 1217 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() | 1202 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() |
| 1218 ? view->LayoutViewportScrollableArea() | 1203 ? view->LayoutViewportScrollableArea() |
| 1219 : view->GetScrollableArea(); | 1204 : view->GetScrollableArea(); |
| 1220 | 1205 |
| 1221 ScrollOffset current_offset = viewport->GetScrollOffset(); | 1206 ScrollOffset current_offset = viewport->GetScrollOffset(); |
| 1222 ScrollOffset scaled_delta(x * GetFrame()->PageZoomFactor(), | 1207 ScrollOffset scaled_delta(x * GetFrame()->PageZoomFactor(), |
| 1223 y * GetFrame()->PageZoomFactor()); | 1208 y * GetFrame()->PageZoomFactor()); |
| 1224 | 1209 |
| 1225 scrollViewportTo(viewport, current_offset + scaled_delta, scroll_behavior); | 1210 viewport->SetScrollOffset(current_offset + scaled_delta, kProgrammaticScroll, |
| 1211 scroll_behavior); |
| 1226 } | 1212 } |
| 1227 | 1213 |
| 1228 void LocalDOMWindow::scrollBy(const ScrollToOptions& scroll_to_options) const { | 1214 void LocalDOMWindow::scrollBy(const ScrollToOptions& scroll_to_options) const { |
| 1229 double x = 0.0; | 1215 double x = 0.0; |
| 1230 double y = 0.0; | 1216 double y = 0.0; |
| 1231 if (scroll_to_options.hasLeft()) | 1217 if (scroll_to_options.hasLeft()) |
| 1232 x = scroll_to_options.left(); | 1218 x = scroll_to_options.left(); |
| 1233 if (scroll_to_options.hasTop()) | 1219 if (scroll_to_options.hasTop()) |
| 1234 y = scroll_to_options.top(); | 1220 y = scroll_to_options.top(); |
| 1235 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; | 1221 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1256 // It is only necessary to have an up-to-date layout if the position may be | 1242 // It is only necessary to have an up-to-date layout if the position may be |
| 1257 // clamped, which is never the case for (0, 0). | 1243 // clamped, which is never the case for (0, 0). |
| 1258 if (x || y) | 1244 if (x || y) |
| 1259 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 1245 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| 1260 | 1246 |
| 1261 ScrollOffset layout_offset(x * GetFrame()->PageZoomFactor(), | 1247 ScrollOffset layout_offset(x * GetFrame()->PageZoomFactor(), |
| 1262 y * GetFrame()->PageZoomFactor()); | 1248 y * GetFrame()->PageZoomFactor()); |
| 1263 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() | 1249 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() |
| 1264 ? view->LayoutViewportScrollableArea() | 1250 ? view->LayoutViewportScrollableArea() |
| 1265 : view->GetScrollableArea(); | 1251 : view->GetScrollableArea(); |
| 1266 scrollViewportTo(viewport, layout_offset, kScrollBehaviorAuto); | 1252 viewport->SetScrollOffset(layout_offset, kProgrammaticScroll, |
| 1253 kScrollBehaviorAuto); |
| 1267 } | 1254 } |
| 1268 | 1255 |
| 1269 void LocalDOMWindow::scrollTo(const ScrollToOptions& scroll_to_options) const { | 1256 void LocalDOMWindow::scrollTo(const ScrollToOptions& scroll_to_options) const { |
| 1270 if (!IsCurrentlyDisplayedInFrame()) | 1257 if (!IsCurrentlyDisplayedInFrame()) |
| 1271 return; | 1258 return; |
| 1272 | 1259 |
| 1273 LocalFrameView* view = GetFrame()->View(); | 1260 LocalFrameView* view = GetFrame()->View(); |
| 1274 if (!view) | 1261 if (!view) |
| 1275 return; | 1262 return; |
| 1276 | 1263 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1303 | 1290 |
| 1304 if (scroll_to_options.hasTop()) | 1291 if (scroll_to_options.hasTop()) |
| 1305 scaled_y = | 1292 scaled_y = |
| 1306 ScrollableArea::NormalizeNonFiniteScroll(scroll_to_options.top()) * | 1293 ScrollableArea::NormalizeNonFiniteScroll(scroll_to_options.top()) * |
| 1307 GetFrame()->PageZoomFactor(); | 1294 GetFrame()->PageZoomFactor(); |
| 1308 | 1295 |
| 1309 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; | 1296 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; |
| 1310 ScrollableArea::ScrollBehaviorFromString(scroll_to_options.behavior(), | 1297 ScrollableArea::ScrollBehaviorFromString(scroll_to_options.behavior(), |
| 1311 scroll_behavior); | 1298 scroll_behavior); |
| 1312 | 1299 |
| 1313 scrollViewportTo(viewport, ScrollOffset(scaled_x, scaled_y), scroll_behavior); | 1300 viewport->SetScrollOffset(ScrollOffset(scaled_x, scaled_y), |
| 1301 kProgrammaticScroll, scroll_behavior); |
| 1314 } | 1302 } |
| 1315 | 1303 |
| 1316 void LocalDOMWindow::moveBy(int x, int y) const { | 1304 void LocalDOMWindow::moveBy(int x, int y) const { |
| 1317 if (!GetFrame() || !GetFrame()->IsMainFrame()) | 1305 if (!GetFrame() || !GetFrame()->IsMainFrame()) |
| 1318 return; | 1306 return; |
| 1319 | 1307 |
| 1320 Page* page = GetFrame()->GetPage(); | 1308 Page* page = GetFrame()->GetPage(); |
| 1321 if (!page) | 1309 if (!page) |
| 1322 return; | 1310 return; |
| 1323 | 1311 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1679 DOMWindow::Trace(visitor); | 1667 DOMWindow::Trace(visitor); |
| 1680 Supplementable<LocalDOMWindow>::Trace(visitor); | 1668 Supplementable<LocalDOMWindow>::Trace(visitor); |
| 1681 } | 1669 } |
| 1682 | 1670 |
| 1683 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { | 1671 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { |
| 1684 visitor->TraceWrappers(custom_elements_); | 1672 visitor->TraceWrappers(custom_elements_); |
| 1685 DOMWindow::TraceWrappers(visitor); | 1673 DOMWindow::TraceWrappers(visitor); |
| 1686 } | 1674 } |
| 1687 | 1675 |
| 1688 } // namespace blink | 1676 } // namespace blink |
| OLD | NEW |