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 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 element, pseudo_id, rules_to_include); | 1203 element, pseudo_id, rules_to_include); |
1204 } | 1204 } |
1205 | 1205 |
1206 double LocalDOMWindow::devicePixelRatio() const { | 1206 double LocalDOMWindow::devicePixelRatio() const { |
1207 if (!GetFrame()) | 1207 if (!GetFrame()) |
1208 return 0.0; | 1208 return 0.0; |
1209 | 1209 |
1210 return GetFrame()->DevicePixelRatio(); | 1210 return GetFrame()->DevicePixelRatio(); |
1211 } | 1211 } |
1212 | 1212 |
| 1213 void LocalDOMWindow::scrollViewportTo(ScrollableArea* viewport, |
| 1214 const ScrollOffset& offset, |
| 1215 ScrollBehavior scroll_behavior) const { |
| 1216 if (SmoothScrollSequencer* sequencer = |
| 1217 GetFrame()->GetPage()->GetSmoothScrollSequencer()) { |
| 1218 sequencer->AbortAnimations(); |
| 1219 if (scroll_behavior == kScrollBehaviorSmooth) { |
| 1220 sequencer->QueueAnimation(viewport, offset); |
| 1221 sequencer->RunQueuedAnimations(); |
| 1222 } else { |
| 1223 viewport->SetScrollOffset(offset, kProgrammaticScroll, scroll_behavior); |
| 1224 } |
| 1225 } |
| 1226 } |
| 1227 |
1213 void LocalDOMWindow::scrollBy(double x, | 1228 void LocalDOMWindow::scrollBy(double x, |
1214 double y, | 1229 double y, |
1215 ScrollBehavior scroll_behavior) const { | 1230 ScrollBehavior scroll_behavior) const { |
1216 if (!IsCurrentlyDisplayedInFrame()) | 1231 if (!IsCurrentlyDisplayedInFrame()) |
1217 return; | 1232 return; |
1218 | 1233 |
1219 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 1234 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
1220 | 1235 |
1221 FrameView* view = GetFrame()->View(); | 1236 FrameView* view = GetFrame()->View(); |
1222 if (!view) | 1237 if (!view) |
1223 return; | 1238 return; |
1224 | 1239 |
1225 Page* page = GetFrame()->GetPage(); | 1240 Page* page = GetFrame()->GetPage(); |
1226 if (!page) | 1241 if (!page) |
1227 return; | 1242 return; |
1228 | 1243 |
1229 x = ScrollableArea::NormalizeNonFiniteScroll(x); | 1244 x = ScrollableArea::NormalizeNonFiniteScroll(x); |
1230 y = ScrollableArea::NormalizeNonFiniteScroll(y); | 1245 y = ScrollableArea::NormalizeNonFiniteScroll(y); |
1231 | 1246 |
1232 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() | 1247 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() |
1233 ? view->LayoutViewportScrollableArea() | 1248 ? view->LayoutViewportScrollableArea() |
1234 : view->GetScrollableArea(); | 1249 : view->GetScrollableArea(); |
1235 | 1250 |
1236 ScrollOffset current_offset = viewport->GetScrollOffset(); | 1251 ScrollOffset current_offset = viewport->GetScrollOffset(); |
1237 ScrollOffset scaled_delta(x * GetFrame()->PageZoomFactor(), | 1252 ScrollOffset scaled_delta(x * GetFrame()->PageZoomFactor(), |
1238 y * GetFrame()->PageZoomFactor()); | 1253 y * GetFrame()->PageZoomFactor()); |
1239 | 1254 |
1240 viewport->SetScrollOffset(current_offset + scaled_delta, kProgrammaticScroll, | 1255 scrollViewportTo(viewport, current_offset + scaled_delta, scroll_behavior); |
1241 scroll_behavior); | |
1242 } | 1256 } |
1243 | 1257 |
1244 void LocalDOMWindow::scrollBy(const ScrollToOptions& scroll_to_options) const { | 1258 void LocalDOMWindow::scrollBy(const ScrollToOptions& scroll_to_options) const { |
1245 double x = 0.0; | 1259 double x = 0.0; |
1246 double y = 0.0; | 1260 double y = 0.0; |
1247 if (scroll_to_options.hasLeft()) | 1261 if (scroll_to_options.hasLeft()) |
1248 x = scroll_to_options.left(); | 1262 x = scroll_to_options.left(); |
1249 if (scroll_to_options.hasTop()) | 1263 if (scroll_to_options.hasTop()) |
1250 y = scroll_to_options.top(); | 1264 y = scroll_to_options.top(); |
1251 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; | 1265 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; |
(...skipping 20 matching lines...) Expand all Loading... |
1272 // It is only necessary to have an up-to-date layout if the position may be | 1286 // It is only necessary to have an up-to-date layout if the position may be |
1273 // clamped, which is never the case for (0, 0). | 1287 // clamped, which is never the case for (0, 0). |
1274 if (x || y) | 1288 if (x || y) |
1275 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 1289 document()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
1276 | 1290 |
1277 ScrollOffset layout_offset(x * GetFrame()->PageZoomFactor(), | 1291 ScrollOffset layout_offset(x * GetFrame()->PageZoomFactor(), |
1278 y * GetFrame()->PageZoomFactor()); | 1292 y * GetFrame()->PageZoomFactor()); |
1279 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() | 1293 ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport() |
1280 ? view->LayoutViewportScrollableArea() | 1294 ? view->LayoutViewportScrollableArea() |
1281 : view->GetScrollableArea(); | 1295 : view->GetScrollableArea(); |
1282 viewport->SetScrollOffset(layout_offset, kProgrammaticScroll, | 1296 scrollViewportTo(viewport, layout_offset, kScrollBehaviorAuto); |
1283 kScrollBehaviorAuto); | |
1284 } | 1297 } |
1285 | 1298 |
1286 void LocalDOMWindow::scrollTo(const ScrollToOptions& scroll_to_options) const { | 1299 void LocalDOMWindow::scrollTo(const ScrollToOptions& scroll_to_options) const { |
1287 if (!IsCurrentlyDisplayedInFrame()) | 1300 if (!IsCurrentlyDisplayedInFrame()) |
1288 return; | 1301 return; |
1289 | 1302 |
1290 FrameView* view = GetFrame()->View(); | 1303 FrameView* view = GetFrame()->View(); |
1291 if (!view) | 1304 if (!view) |
1292 return; | 1305 return; |
1293 | 1306 |
(...skipping 26 matching lines...) Expand all Loading... |
1320 | 1333 |
1321 if (scroll_to_options.hasTop()) | 1334 if (scroll_to_options.hasTop()) |
1322 scaled_y = | 1335 scaled_y = |
1323 ScrollableArea::NormalizeNonFiniteScroll(scroll_to_options.top()) * | 1336 ScrollableArea::NormalizeNonFiniteScroll(scroll_to_options.top()) * |
1324 GetFrame()->PageZoomFactor(); | 1337 GetFrame()->PageZoomFactor(); |
1325 | 1338 |
1326 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; | 1339 ScrollBehavior scroll_behavior = kScrollBehaviorAuto; |
1327 ScrollableArea::ScrollBehaviorFromString(scroll_to_options.behavior(), | 1340 ScrollableArea::ScrollBehaviorFromString(scroll_to_options.behavior(), |
1328 scroll_behavior); | 1341 scroll_behavior); |
1329 | 1342 |
1330 viewport->SetScrollOffset(ScrollOffset(scaled_x, scaled_y), | 1343 scrollViewportTo(viewport, ScrollOffset(scaled_x, scaled_y), scroll_behavior); |
1331 kProgrammaticScroll, scroll_behavior); | |
1332 } | 1344 } |
1333 | 1345 |
1334 void LocalDOMWindow::moveBy(int x, int y) const { | 1346 void LocalDOMWindow::moveBy(int x, int y) const { |
1335 if (!GetFrame() || !GetFrame()->IsMainFrame()) | 1347 if (!GetFrame() || !GetFrame()->IsMainFrame()) |
1336 return; | 1348 return; |
1337 | 1349 |
1338 Page* page = GetFrame()->GetPage(); | 1350 Page* page = GetFrame()->GetPage(); |
1339 if (!page) | 1351 if (!page) |
1340 return; | 1352 return; |
1341 | 1353 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 DOMWindow::Trace(visitor); | 1716 DOMWindow::Trace(visitor); |
1705 Supplementable<LocalDOMWindow>::Trace(visitor); | 1717 Supplementable<LocalDOMWindow>::Trace(visitor); |
1706 } | 1718 } |
1707 | 1719 |
1708 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { | 1720 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { |
1709 visitor->TraceWrappers(custom_elements_); | 1721 visitor->TraceWrappers(custom_elements_); |
1710 DOMWindow::TraceWrappers(visitor); | 1722 DOMWindow::TraceWrappers(visitor); |
1711 } | 1723 } |
1712 | 1724 |
1713 } // namespace blink | 1725 } // namespace blink |
OLD | NEW |