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