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 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 } | 904 } |
905 | 905 |
906 bool LocalDOMWindow::offscreenBuffering() const { | 906 bool LocalDOMWindow::offscreenBuffering() const { |
907 return true; | 907 return true; |
908 } | 908 } |
909 | 909 |
910 int LocalDOMWindow::outerHeight() const { | 910 int LocalDOMWindow::outerHeight() const { |
911 if (!frame()) | 911 if (!frame()) |
912 return 0; | 912 return 0; |
913 | 913 |
914 FrameHost* host = frame()->host(); | 914 Page* page = frame()->page(); |
915 if (!host) | 915 if (!page) |
916 return 0; | 916 return 0; |
917 | 917 |
918 ChromeClient& chromeClient = host->chromeClient(); | 918 ChromeClient& chromeClient = page->chromeClient(); |
919 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) | 919 if (page->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
920 return lroundf(chromeClient.rootWindowRect().height() * | 920 return lroundf(chromeClient.rootWindowRect().height() * |
921 chromeClient.screenInfo().deviceScaleFactor); | 921 chromeClient.screenInfo().deviceScaleFactor); |
922 return chromeClient.rootWindowRect().height(); | 922 return chromeClient.rootWindowRect().height(); |
923 } | 923 } |
924 | 924 |
925 int LocalDOMWindow::outerWidth() const { | 925 int LocalDOMWindow::outerWidth() const { |
926 if (!frame()) | 926 if (!frame()) |
927 return 0; | 927 return 0; |
928 | 928 |
929 FrameHost* host = frame()->host(); | 929 Page* page = frame()->page(); |
930 if (!host) | 930 if (!page) |
931 return 0; | 931 return 0; |
932 | 932 |
933 ChromeClient& chromeClient = host->chromeClient(); | 933 ChromeClient& chromeClient = page->chromeClient(); |
934 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) | 934 if (page->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
935 return lroundf(chromeClient.rootWindowRect().width() * | 935 return lroundf(chromeClient.rootWindowRect().width() * |
936 chromeClient.screenInfo().deviceScaleFactor); | 936 chromeClient.screenInfo().deviceScaleFactor); |
937 | 937 |
938 return chromeClient.rootWindowRect().width(); | 938 return chromeClient.rootWindowRect().width(); |
939 } | 939 } |
940 | 940 |
941 FloatSize LocalDOMWindow::getViewportSize( | 941 FloatSize LocalDOMWindow::getViewportSize( |
942 IncludeScrollbarsInRect scrollbarInclusion) const { | 942 IncludeScrollbarsInRect scrollbarInclusion) const { |
943 if (!frame()) | 943 if (!frame()) |
944 return FloatSize(); | 944 return FloatSize(); |
945 | 945 |
946 FrameView* view = frame()->view(); | 946 FrameView* view = frame()->view(); |
947 if (!view) | 947 if (!view) |
948 return FloatSize(); | 948 return FloatSize(); |
949 | 949 |
| 950 Page* page = frame()->page(); |
| 951 if (!page) |
| 952 return FloatSize(); |
| 953 |
| 954 // If we have a Page, we must have a FrameHost. |
950 FrameHost* host = frame()->host(); | 955 FrameHost* host = frame()->host(); |
951 if (!host) | 956 DCHECK(host); |
952 return FloatSize(); | |
953 | 957 |
954 // The main frame's viewport size depends on the page scale. Since the | 958 // The main frame's viewport size depends on the page scale. Since the |
955 // initial page scale depends on the content width and is set after a | 959 // initial page scale depends on the content width and is set after a |
956 // layout, perform one now so queries during page load will use the up to | 960 // layout, perform one now so queries during page load will use the up to |
957 // date viewport. | 961 // date viewport. |
958 if (host->settings().getViewportEnabled() && frame()->isMainFrame()) | 962 if (page->settings().getViewportEnabled() && frame()->isMainFrame()) |
959 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 963 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
960 | 964 |
961 // FIXME: This is potentially too much work. We really only need to know the | 965 // FIXME: This is potentially too much work. We really only need to know the |
962 // dimensions of the parent frame's layoutObject. | 966 // dimensions of the parent frame's layoutObject. |
963 if (Frame* parent = frame()->tree().parent()) { | 967 if (Frame* parent = frame()->tree().parent()) { |
964 if (parent && parent->isLocalFrame()) | 968 if (parent && parent->isLocalFrame()) |
965 toLocalFrame(parent) | 969 toLocalFrame(parent) |
966 ->document() | 970 ->document() |
967 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 971 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
968 } | 972 } |
969 | 973 |
970 return frame()->isMainFrame() && !host->settings().getInertVisualViewport() | 974 return frame()->isMainFrame() && !page->settings().getInertVisualViewport() |
971 ? FloatSize(host->visualViewport().visibleRect().size()) | 975 ? FloatSize(host->visualViewport().visibleRect().size()) |
972 : FloatSize(view->visibleContentRect(scrollbarInclusion).size()); | 976 : FloatSize(view->visibleContentRect(scrollbarInclusion).size()); |
973 } | 977 } |
974 | 978 |
975 int LocalDOMWindow::innerHeight() const { | 979 int LocalDOMWindow::innerHeight() const { |
976 if (!frame()) | 980 if (!frame()) |
977 return 0; | 981 return 0; |
978 | 982 |
979 FloatSize viewportSize = getViewportSize(IncludeScrollbars); | 983 FloatSize viewportSize = getViewportSize(IncludeScrollbars); |
980 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), | 984 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), |
981 frame()->pageZoomFactor()); | 985 frame()->pageZoomFactor()); |
982 } | 986 } |
983 | 987 |
984 int LocalDOMWindow::innerWidth() const { | 988 int LocalDOMWindow::innerWidth() const { |
985 if (!frame()) | 989 if (!frame()) |
986 return 0; | 990 return 0; |
987 | 991 |
988 FloatSize viewportSize = getViewportSize(IncludeScrollbars); | 992 FloatSize viewportSize = getViewportSize(IncludeScrollbars); |
989 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).width(), | 993 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).width(), |
990 frame()->pageZoomFactor()); | 994 frame()->pageZoomFactor()); |
991 } | 995 } |
992 | 996 |
993 int LocalDOMWindow::screenX() const { | 997 int LocalDOMWindow::screenX() const { |
994 if (!frame()) | 998 if (!frame()) |
995 return 0; | 999 return 0; |
996 | 1000 |
997 FrameHost* host = frame()->host(); | 1001 Page* page = frame()->page(); |
998 if (!host) | 1002 if (!page) |
999 return 0; | 1003 return 0; |
1000 | 1004 |
1001 ChromeClient& chromeClient = host->chromeClient(); | 1005 ChromeClient& chromeClient = page->chromeClient(); |
1002 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) | 1006 if (page->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
1003 return lroundf(chromeClient.rootWindowRect().x() * | 1007 return lroundf(chromeClient.rootWindowRect().x() * |
1004 chromeClient.screenInfo().deviceScaleFactor); | 1008 chromeClient.screenInfo().deviceScaleFactor); |
1005 return chromeClient.rootWindowRect().x(); | 1009 return chromeClient.rootWindowRect().x(); |
1006 } | 1010 } |
1007 | 1011 |
1008 int LocalDOMWindow::screenY() const { | 1012 int LocalDOMWindow::screenY() const { |
1009 if (!frame()) | 1013 if (!frame()) |
1010 return 0; | 1014 return 0; |
1011 | 1015 |
1012 FrameHost* host = frame()->host(); | 1016 Page* page = frame()->page(); |
1013 if (!host) | 1017 if (!page) |
1014 return 0; | 1018 return 0; |
1015 | 1019 |
1016 ChromeClient& chromeClient = host->chromeClient(); | 1020 ChromeClient& chromeClient = page->chromeClient(); |
1017 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) | 1021 if (page->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
1018 return lroundf(chromeClient.rootWindowRect().y() * | 1022 return lroundf(chromeClient.rootWindowRect().y() * |
1019 chromeClient.screenInfo().deviceScaleFactor); | 1023 chromeClient.screenInfo().deviceScaleFactor); |
1020 return chromeClient.rootWindowRect().y(); | 1024 return chromeClient.rootWindowRect().y(); |
1021 } | 1025 } |
1022 | 1026 |
1023 double LocalDOMWindow::scrollX() const { | 1027 double LocalDOMWindow::scrollX() const { |
1024 if (!frame() || !frame()->host()) | 1028 if (!frame() || !frame()->page()) |
1025 return 0; | 1029 return 0; |
1026 | 1030 |
1027 if (!frame()->host()->settings().getInertVisualViewport()) | 1031 if (!frame()->page()->settings().getInertVisualViewport()) |
1028 return m_visualViewport->pageX(); | 1032 return m_visualViewport->pageX(); |
1029 | 1033 |
1030 FrameView* view = frame()->view(); | 1034 FrameView* view = frame()->view(); |
1031 if (!view) | 1035 if (!view) |
1032 return 0; | 1036 return 0; |
1033 | 1037 |
1034 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1038 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1035 | 1039 |
1036 double viewportX = | 1040 double viewportX = |
1037 view->layoutViewportScrollableArea()->getScrollOffset().width(); | 1041 view->layoutViewportScrollableArea()->getScrollOffset().width(); |
1038 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor()); | 1042 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor()); |
1039 } | 1043 } |
1040 | 1044 |
1041 double LocalDOMWindow::scrollY() const { | 1045 double LocalDOMWindow::scrollY() const { |
1042 if (!frame() || !frame()->host()) | 1046 if (!frame() || !frame()->page()) |
1043 return 0; | 1047 return 0; |
1044 | 1048 |
1045 if (!frame()->host()->settings().getInertVisualViewport()) | 1049 if (!frame()->page()->settings().getInertVisualViewport()) |
1046 return m_visualViewport->pageY(); | 1050 return m_visualViewport->pageY(); |
1047 | 1051 |
1048 FrameView* view = frame()->view(); | 1052 FrameView* view = frame()->view(); |
1049 if (!view) | 1053 if (!view) |
1050 return 0; | 1054 return 0; |
1051 | 1055 |
1052 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1056 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1053 | 1057 |
1054 double viewportY = | 1058 double viewportY = |
1055 view->layoutViewportScrollableArea()->getScrollOffset().height(); | 1059 view->layoutViewportScrollableArea()->getScrollOffset().height(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 ScrollBehavior scrollBehavior) const { | 1164 ScrollBehavior scrollBehavior) const { |
1161 if (!isCurrentlyDisplayedInFrame()) | 1165 if (!isCurrentlyDisplayedInFrame()) |
1162 return; | 1166 return; |
1163 | 1167 |
1164 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1168 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1165 | 1169 |
1166 FrameView* view = frame()->view(); | 1170 FrameView* view = frame()->view(); |
1167 if (!view) | 1171 if (!view) |
1168 return; | 1172 return; |
1169 | 1173 |
1170 FrameHost* host = frame()->host(); | 1174 Page* page = frame()->page(); |
1171 if (!host) | 1175 if (!page) |
1172 return; | 1176 return; |
1173 | 1177 |
1174 x = ScrollableArea::normalizeNonFiniteScroll(x); | 1178 x = ScrollableArea::normalizeNonFiniteScroll(x); |
1175 y = ScrollableArea::normalizeNonFiniteScroll(y); | 1179 y = ScrollableArea::normalizeNonFiniteScroll(y); |
1176 | 1180 |
1177 ScrollableArea* viewport = host->settings().getInertVisualViewport() | 1181 ScrollableArea* viewport = page->settings().getInertVisualViewport() |
1178 ? view->layoutViewportScrollableArea() | 1182 ? view->layoutViewportScrollableArea() |
1179 : view->getScrollableArea(); | 1183 : view->getScrollableArea(); |
1180 | 1184 |
1181 ScrollOffset currentOffset = viewport->getScrollOffset(); | 1185 ScrollOffset currentOffset = viewport->getScrollOffset(); |
1182 ScrollOffset scaledDelta(x * frame()->pageZoomFactor(), | 1186 ScrollOffset scaledDelta(x * frame()->pageZoomFactor(), |
1183 y * frame()->pageZoomFactor()); | 1187 y * frame()->pageZoomFactor()); |
1184 | 1188 |
1185 viewport->setScrollOffset(currentOffset + scaledDelta, ProgrammaticScroll, | 1189 viewport->setScrollOffset(currentOffset + scaledDelta, ProgrammaticScroll, |
1186 scrollBehavior); | 1190 scrollBehavior); |
1187 } | 1191 } |
(...skipping 12 matching lines...) Expand all Loading... |
1200 } | 1204 } |
1201 | 1205 |
1202 void LocalDOMWindow::scrollTo(double x, double y) const { | 1206 void LocalDOMWindow::scrollTo(double x, double y) const { |
1203 if (!isCurrentlyDisplayedInFrame()) | 1207 if (!isCurrentlyDisplayedInFrame()) |
1204 return; | 1208 return; |
1205 | 1209 |
1206 FrameView* view = frame()->view(); | 1210 FrameView* view = frame()->view(); |
1207 if (!view) | 1211 if (!view) |
1208 return; | 1212 return; |
1209 | 1213 |
1210 FrameHost* host = frame()->host(); | 1214 Page* page = frame()->page(); |
1211 if (!host) | 1215 if (!page) |
1212 return; | 1216 return; |
1213 | 1217 |
1214 x = ScrollableArea::normalizeNonFiniteScroll(x); | 1218 x = ScrollableArea::normalizeNonFiniteScroll(x); |
1215 y = ScrollableArea::normalizeNonFiniteScroll(y); | 1219 y = ScrollableArea::normalizeNonFiniteScroll(y); |
1216 | 1220 |
1217 // It is only necessary to have an up-to-date layout if the position may be | 1221 // It is only necessary to have an up-to-date layout if the position may be |
1218 // clamped, which is never the case for (0, 0). | 1222 // clamped, which is never the case for (0, 0). |
1219 if (x || y) | 1223 if (x || y) |
1220 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1224 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1221 | 1225 |
1222 ScrollOffset layoutOffset(x * frame()->pageZoomFactor(), | 1226 ScrollOffset layoutOffset(x * frame()->pageZoomFactor(), |
1223 y * frame()->pageZoomFactor()); | 1227 y * frame()->pageZoomFactor()); |
1224 ScrollableArea* viewport = host->settings().getInertVisualViewport() | 1228 ScrollableArea* viewport = page->settings().getInertVisualViewport() |
1225 ? view->layoutViewportScrollableArea() | 1229 ? view->layoutViewportScrollableArea() |
1226 : view->getScrollableArea(); | 1230 : view->getScrollableArea(); |
1227 viewport->setScrollOffset(layoutOffset, ProgrammaticScroll, | 1231 viewport->setScrollOffset(layoutOffset, ProgrammaticScroll, |
1228 ScrollBehaviorAuto); | 1232 ScrollBehaviorAuto); |
1229 } | 1233 } |
1230 | 1234 |
1231 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const { | 1235 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const { |
1232 if (!isCurrentlyDisplayedInFrame()) | 1236 if (!isCurrentlyDisplayedInFrame()) |
1233 return; | 1237 return; |
1234 | 1238 |
1235 FrameView* view = frame()->view(); | 1239 FrameView* view = frame()->view(); |
1236 if (!view) | 1240 if (!view) |
1237 return; | 1241 return; |
1238 | 1242 |
1239 FrameHost* host = frame()->host(); | 1243 Page* page = frame()->page(); |
1240 if (!host) | 1244 if (!page) |
1241 return; | 1245 return; |
1242 | 1246 |
1243 // It is only necessary to have an up-to-date layout if the position may be | 1247 // It is only necessary to have an up-to-date layout if the position may be |
1244 // clamped, which is never the case for (0, 0). | 1248 // clamped, which is never the case for (0, 0). |
1245 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() || | 1249 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() || |
1246 scrollToOptions.left() || scrollToOptions.top()) { | 1250 scrollToOptions.left() || scrollToOptions.top()) { |
1247 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1251 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1248 } | 1252 } |
1249 | 1253 |
1250 double scaledX = 0.0; | 1254 double scaledX = 0.0; |
1251 double scaledY = 0.0; | 1255 double scaledY = 0.0; |
1252 | 1256 |
1253 ScrollableArea* viewport = host->settings().getInertVisualViewport() | 1257 ScrollableArea* viewport = page->settings().getInertVisualViewport() |
1254 ? view->layoutViewportScrollableArea() | 1258 ? view->layoutViewportScrollableArea() |
1255 : view->getScrollableArea(); | 1259 : view->getScrollableArea(); |
1256 | 1260 |
1257 ScrollOffset currentOffset = viewport->getScrollOffset(); | 1261 ScrollOffset currentOffset = viewport->getScrollOffset(); |
1258 scaledX = currentOffset.width(); | 1262 scaledX = currentOffset.width(); |
1259 scaledY = currentOffset.height(); | 1263 scaledY = currentOffset.height(); |
1260 | 1264 |
1261 if (scrollToOptions.hasLeft()) | 1265 if (scrollToOptions.hasLeft()) |
1262 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) * | 1266 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) * |
1263 frame()->pageZoomFactor(); | 1267 frame()->pageZoomFactor(); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 DOMWindow::trace(visitor); | 1635 DOMWindow::trace(visitor); |
1632 Supplementable<LocalDOMWindow>::trace(visitor); | 1636 Supplementable<LocalDOMWindow>::trace(visitor); |
1633 } | 1637 } |
1634 | 1638 |
1635 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { | 1639 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { |
1636 visitor->traceWrappers(m_customElements); | 1640 visitor->traceWrappers(m_customElements); |
1637 DOMWindow::traceWrappers(visitor); | 1641 DOMWindow::traceWrappers(visitor); |
1638 } | 1642 } |
1639 | 1643 |
1640 } // namespace blink | 1644 } // namespace blink |
OLD | NEW |