| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 unsigned LocalDOMWindow::pendingUnloadEventListeners() const { | 256 unsigned LocalDOMWindow::pendingUnloadEventListeners() const { |
| 257 return windowsWithUnloadEventListeners().count( | 257 return windowsWithUnloadEventListeners().count( |
| 258 const_cast<LocalDOMWindow*>(this)); | 258 const_cast<LocalDOMWindow*>(this)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) { | 261 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) { |
| 262 if (UserGestureIndicator::utilizeUserGesture()) | 262 if (UserGestureIndicator::utilizeUserGesture()) |
| 263 return true; | 263 return true; |
| 264 | 264 |
| 265 Settings* settings = firstFrame.settings(); | 265 Settings* settings = firstFrame.settings(); |
| 266 return settings && settings->javaScriptCanOpenWindowsAutomatically(); | 266 return settings && settings->getJavaScriptCanOpenWindowsAutomatically(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool LocalDOMWindow::allowPopUp() { | 269 bool LocalDOMWindow::allowPopUp() { |
| 270 return frame() && allowPopUp(*frame()); | 270 return frame() && allowPopUp(*frame()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 LocalDOMWindow::LocalDOMWindow(LocalFrame& frame) | 273 LocalDOMWindow::LocalDOMWindow(LocalFrame& frame) |
| 274 : m_frame(&frame), | 274 : m_frame(&frame), |
| 275 m_visualViewport(DOMVisualViewport::create(this)), | 275 m_visualViewport(DOMVisualViewport::create(this)), |
| 276 m_unusedPreloadsTimer(this, &LocalDOMWindow::warnUnusedPreloads), | 276 m_unusedPreloadsTimer(this, &LocalDOMWindow::warnUnusedPreloads), |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 | 853 |
| 854 int LocalDOMWindow::outerHeight() const { | 854 int LocalDOMWindow::outerHeight() const { |
| 855 if (!frame()) | 855 if (!frame()) |
| 856 return 0; | 856 return 0; |
| 857 | 857 |
| 858 FrameHost* host = frame()->host(); | 858 FrameHost* host = frame()->host(); |
| 859 if (!host) | 859 if (!host) |
| 860 return 0; | 860 return 0; |
| 861 | 861 |
| 862 ChromeClient& chromeClient = host->chromeClient(); | 862 ChromeClient& chromeClient = host->chromeClient(); |
| 863 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 863 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
| 864 return lroundf(chromeClient.rootWindowRect().height() * | 864 return lroundf(chromeClient.rootWindowRect().height() * |
| 865 chromeClient.screenInfo().deviceScaleFactor); | 865 chromeClient.screenInfo().deviceScaleFactor); |
| 866 return chromeClient.rootWindowRect().height(); | 866 return chromeClient.rootWindowRect().height(); |
| 867 } | 867 } |
| 868 | 868 |
| 869 int LocalDOMWindow::outerWidth() const { | 869 int LocalDOMWindow::outerWidth() const { |
| 870 if (!frame()) | 870 if (!frame()) |
| 871 return 0; | 871 return 0; |
| 872 | 872 |
| 873 FrameHost* host = frame()->host(); | 873 FrameHost* host = frame()->host(); |
| 874 if (!host) | 874 if (!host) |
| 875 return 0; | 875 return 0; |
| 876 | 876 |
| 877 ChromeClient& chromeClient = host->chromeClient(); | 877 ChromeClient& chromeClient = host->chromeClient(); |
| 878 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 878 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
| 879 return lroundf(chromeClient.rootWindowRect().width() * | 879 return lroundf(chromeClient.rootWindowRect().width() * |
| 880 chromeClient.screenInfo().deviceScaleFactor); | 880 chromeClient.screenInfo().deviceScaleFactor); |
| 881 | 881 |
| 882 return chromeClient.rootWindowRect().width(); | 882 return chromeClient.rootWindowRect().width(); |
| 883 } | 883 } |
| 884 | 884 |
| 885 FloatSize LocalDOMWindow::getViewportSize( | 885 FloatSize LocalDOMWindow::getViewportSize( |
| 886 IncludeScrollbarsInRect scrollbarInclusion) const { | 886 IncludeScrollbarsInRect scrollbarInclusion) const { |
| 887 if (!frame()) | 887 if (!frame()) |
| 888 return FloatSize(); | 888 return FloatSize(); |
| 889 | 889 |
| 890 FrameView* view = frame()->view(); | 890 FrameView* view = frame()->view(); |
| 891 if (!view) | 891 if (!view) |
| 892 return FloatSize(); | 892 return FloatSize(); |
| 893 | 893 |
| 894 FrameHost* host = frame()->host(); | 894 FrameHost* host = frame()->host(); |
| 895 if (!host) | 895 if (!host) |
| 896 return FloatSize(); | 896 return FloatSize(); |
| 897 | 897 |
| 898 // The main frame's viewport size depends on the page scale. Since the | 898 // The main frame's viewport size depends on the page scale. Since the |
| 899 // initial page scale depends on the content width and is set after a | 899 // initial page scale depends on the content width and is set after a |
| 900 // layout, perform one now so queries during page load will use the up to | 900 // layout, perform one now so queries during page load will use the up to |
| 901 // date viewport. | 901 // date viewport. |
| 902 if (host->settings().viewportEnabled() && frame()->isMainFrame()) | 902 if (host->settings().getViewportEnabled() && frame()->isMainFrame()) |
| 903 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 903 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 904 | 904 |
| 905 // FIXME: This is potentially too much work. We really only need to know the | 905 // FIXME: This is potentially too much work. We really only need to know the |
| 906 // dimensions of the parent frame's layoutObject. | 906 // dimensions of the parent frame's layoutObject. |
| 907 if (Frame* parent = frame()->tree().parent()) { | 907 if (Frame* parent = frame()->tree().parent()) { |
| 908 if (parent && parent->isLocalFrame()) | 908 if (parent && parent->isLocalFrame()) |
| 909 toLocalFrame(parent) | 909 toLocalFrame(parent) |
| 910 ->document() | 910 ->document() |
| 911 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 911 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 912 } | 912 } |
| 913 | 913 |
| 914 return frame()->isMainFrame() && !host->settings().inertVisualViewport() | 914 return frame()->isMainFrame() && !host->settings().getInertVisualViewport() |
| 915 ? FloatSize(host->visualViewport().visibleRect().size()) | 915 ? FloatSize(host->visualViewport().visibleRect().size()) |
| 916 : FloatSize(view->visibleContentRect(scrollbarInclusion).size()); | 916 : FloatSize(view->visibleContentRect(scrollbarInclusion).size()); |
| 917 } | 917 } |
| 918 | 918 |
| 919 int LocalDOMWindow::innerHeight() const { | 919 int LocalDOMWindow::innerHeight() const { |
| 920 if (!frame()) | 920 if (!frame()) |
| 921 return 0; | 921 return 0; |
| 922 | 922 |
| 923 FloatSize viewportSize = getViewportSize(IncludeScrollbars); | 923 FloatSize viewportSize = getViewportSize(IncludeScrollbars); |
| 924 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), | 924 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 936 | 936 |
| 937 int LocalDOMWindow::screenX() const { | 937 int LocalDOMWindow::screenX() const { |
| 938 if (!frame()) | 938 if (!frame()) |
| 939 return 0; | 939 return 0; |
| 940 | 940 |
| 941 FrameHost* host = frame()->host(); | 941 FrameHost* host = frame()->host(); |
| 942 if (!host) | 942 if (!host) |
| 943 return 0; | 943 return 0; |
| 944 | 944 |
| 945 ChromeClient& chromeClient = host->chromeClient(); | 945 ChromeClient& chromeClient = host->chromeClient(); |
| 946 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 946 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
| 947 return lroundf(chromeClient.rootWindowRect().x() * | 947 return lroundf(chromeClient.rootWindowRect().x() * |
| 948 chromeClient.screenInfo().deviceScaleFactor); | 948 chromeClient.screenInfo().deviceScaleFactor); |
| 949 return chromeClient.rootWindowRect().x(); | 949 return chromeClient.rootWindowRect().x(); |
| 950 } | 950 } |
| 951 | 951 |
| 952 int LocalDOMWindow::screenY() const { | 952 int LocalDOMWindow::screenY() const { |
| 953 if (!frame()) | 953 if (!frame()) |
| 954 return 0; | 954 return 0; |
| 955 | 955 |
| 956 FrameHost* host = frame()->host(); | 956 FrameHost* host = frame()->host(); |
| 957 if (!host) | 957 if (!host) |
| 958 return 0; | 958 return 0; |
| 959 | 959 |
| 960 ChromeClient& chromeClient = host->chromeClient(); | 960 ChromeClient& chromeClient = host->chromeClient(); |
| 961 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 961 if (host->settings().getReportScreenSizeInPhysicalPixelsQuirk()) |
| 962 return lroundf(chromeClient.rootWindowRect().y() * | 962 return lroundf(chromeClient.rootWindowRect().y() * |
| 963 chromeClient.screenInfo().deviceScaleFactor); | 963 chromeClient.screenInfo().deviceScaleFactor); |
| 964 return chromeClient.rootWindowRect().y(); | 964 return chromeClient.rootWindowRect().y(); |
| 965 } | 965 } |
| 966 | 966 |
| 967 double LocalDOMWindow::scrollX() const { | 967 double LocalDOMWindow::scrollX() const { |
| 968 if (!frame() || !frame()->host()) | 968 if (!frame() || !frame()->host()) |
| 969 return 0; | 969 return 0; |
| 970 | 970 |
| 971 if (!frame()->host()->settings().inertVisualViewport()) | 971 if (!frame()->host()->settings().getInertVisualViewport()) |
| 972 return m_visualViewport->pageX(); | 972 return m_visualViewport->pageX(); |
| 973 | 973 |
| 974 FrameView* view = frame()->view(); | 974 FrameView* view = frame()->view(); |
| 975 if (!view) | 975 if (!view) |
| 976 return 0; | 976 return 0; |
| 977 | 977 |
| 978 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 978 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 979 | 979 |
| 980 double viewportX = | 980 double viewportX = |
| 981 view->layoutViewportScrollableArea()->getScrollOffset().width(); | 981 view->layoutViewportScrollableArea()->getScrollOffset().width(); |
| 982 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor()); | 982 return adjustScrollForAbsoluteZoom(viewportX, frame()->pageZoomFactor()); |
| 983 } | 983 } |
| 984 | 984 |
| 985 double LocalDOMWindow::scrollY() const { | 985 double LocalDOMWindow::scrollY() const { |
| 986 if (!frame() || !frame()->host()) | 986 if (!frame() || !frame()->host()) |
| 987 return 0; | 987 return 0; |
| 988 | 988 |
| 989 if (!frame()->host()->settings().inertVisualViewport()) | 989 if (!frame()->host()->settings().getInertVisualViewport()) |
| 990 return m_visualViewport->pageY(); | 990 return m_visualViewport->pageY(); |
| 991 | 991 |
| 992 FrameView* view = frame()->view(); | 992 FrameView* view = frame()->view(); |
| 993 if (!view) | 993 if (!view) |
| 994 return 0; | 994 return 0; |
| 995 | 995 |
| 996 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 996 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 997 | 997 |
| 998 double viewportY = | 998 double viewportY = |
| 999 view->layoutViewportScrollableArea()->getScrollOffset().height(); | 999 view->layoutViewportScrollableArea()->getScrollOffset().height(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 if (!view) | 1111 if (!view) |
| 1112 return; | 1112 return; |
| 1113 | 1113 |
| 1114 FrameHost* host = frame()->host(); | 1114 FrameHost* host = frame()->host(); |
| 1115 if (!host) | 1115 if (!host) |
| 1116 return; | 1116 return; |
| 1117 | 1117 |
| 1118 x = ScrollableArea::normalizeNonFiniteScroll(x); | 1118 x = ScrollableArea::normalizeNonFiniteScroll(x); |
| 1119 y = ScrollableArea::normalizeNonFiniteScroll(y); | 1119 y = ScrollableArea::normalizeNonFiniteScroll(y); |
| 1120 | 1120 |
| 1121 ScrollableArea* viewport = host->settings().inertVisualViewport() | 1121 ScrollableArea* viewport = host->settings().getInertVisualViewport() |
| 1122 ? view->layoutViewportScrollableArea() | 1122 ? view->layoutViewportScrollableArea() |
| 1123 : view->getScrollableArea(); | 1123 : view->getScrollableArea(); |
| 1124 | 1124 |
| 1125 ScrollOffset currentOffset = viewport->getScrollOffset(); | 1125 ScrollOffset currentOffset = viewport->getScrollOffset(); |
| 1126 ScrollOffset scaledDelta(x * frame()->pageZoomFactor(), | 1126 ScrollOffset scaledDelta(x * frame()->pageZoomFactor(), |
| 1127 y * frame()->pageZoomFactor()); | 1127 y * frame()->pageZoomFactor()); |
| 1128 | 1128 |
| 1129 viewport->setScrollOffset(currentOffset + scaledDelta, ProgrammaticScroll, | 1129 viewport->setScrollOffset(currentOffset + scaledDelta, ProgrammaticScroll, |
| 1130 scrollBehavior); | 1130 scrollBehavior); |
| 1131 } | 1131 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1158 x = ScrollableArea::normalizeNonFiniteScroll(x); | 1158 x = ScrollableArea::normalizeNonFiniteScroll(x); |
| 1159 y = ScrollableArea::normalizeNonFiniteScroll(y); | 1159 y = ScrollableArea::normalizeNonFiniteScroll(y); |
| 1160 | 1160 |
| 1161 // It is only necessary to have an up-to-date layout if the position may be | 1161 // It is only necessary to have an up-to-date layout if the position may be |
| 1162 // clamped, which is never the case for (0, 0). | 1162 // clamped, which is never the case for (0, 0). |
| 1163 if (x || y) | 1163 if (x || y) |
| 1164 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1164 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1165 | 1165 |
| 1166 ScrollOffset layoutOffset(x * frame()->pageZoomFactor(), | 1166 ScrollOffset layoutOffset(x * frame()->pageZoomFactor(), |
| 1167 y * frame()->pageZoomFactor()); | 1167 y * frame()->pageZoomFactor()); |
| 1168 ScrollableArea* viewport = host->settings().inertVisualViewport() | 1168 ScrollableArea* viewport = host->settings().getInertVisualViewport() |
| 1169 ? view->layoutViewportScrollableArea() | 1169 ? view->layoutViewportScrollableArea() |
| 1170 : view->getScrollableArea(); | 1170 : view->getScrollableArea(); |
| 1171 viewport->setScrollOffset(layoutOffset, ProgrammaticScroll, | 1171 viewport->setScrollOffset(layoutOffset, ProgrammaticScroll, |
| 1172 ScrollBehaviorAuto); | 1172 ScrollBehaviorAuto); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const { | 1175 void LocalDOMWindow::scrollTo(const ScrollToOptions& scrollToOptions) const { |
| 1176 if (!isCurrentlyDisplayedInFrame()) | 1176 if (!isCurrentlyDisplayedInFrame()) |
| 1177 return; | 1177 return; |
| 1178 | 1178 |
| 1179 FrameView* view = frame()->view(); | 1179 FrameView* view = frame()->view(); |
| 1180 if (!view) | 1180 if (!view) |
| 1181 return; | 1181 return; |
| 1182 | 1182 |
| 1183 FrameHost* host = frame()->host(); | 1183 FrameHost* host = frame()->host(); |
| 1184 if (!host) | 1184 if (!host) |
| 1185 return; | 1185 return; |
| 1186 | 1186 |
| 1187 // It is only necessary to have an up-to-date layout if the position may be | 1187 // It is only necessary to have an up-to-date layout if the position may be |
| 1188 // clamped, which is never the case for (0, 0). | 1188 // clamped, which is never the case for (0, 0). |
| 1189 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() || | 1189 if (!scrollToOptions.hasLeft() || !scrollToOptions.hasTop() || |
| 1190 scrollToOptions.left() || scrollToOptions.top()) { | 1190 scrollToOptions.left() || scrollToOptions.top()) { |
| 1191 document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1191 document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 double scaledX = 0.0; | 1194 double scaledX = 0.0; |
| 1195 double scaledY = 0.0; | 1195 double scaledY = 0.0; |
| 1196 | 1196 |
| 1197 ScrollableArea* viewport = host->settings().inertVisualViewport() | 1197 ScrollableArea* viewport = host->settings().getInertVisualViewport() |
| 1198 ? view->layoutViewportScrollableArea() | 1198 ? view->layoutViewportScrollableArea() |
| 1199 : view->getScrollableArea(); | 1199 : view->getScrollableArea(); |
| 1200 | 1200 |
| 1201 ScrollOffset currentOffset = viewport->getScrollOffset(); | 1201 ScrollOffset currentOffset = viewport->getScrollOffset(); |
| 1202 scaledX = currentOffset.width(); | 1202 scaledX = currentOffset.width(); |
| 1203 scaledY = currentOffset.height(); | 1203 scaledY = currentOffset.height(); |
| 1204 | 1204 |
| 1205 if (scrollToOptions.hasLeft()) | 1205 if (scrollToOptions.hasLeft()) |
| 1206 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) * | 1206 scaledX = ScrollableArea::normalizeNonFiniteScroll(scrollToOptions.left()) * |
| 1207 frame()->pageZoomFactor(); | 1207 frame()->pageZoomFactor(); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 | 1570 |
| 1571 LocalFrame* LocalDOMWindow::frame() const { | 1571 LocalFrame* LocalDOMWindow::frame() const { |
| 1572 // If the LocalDOMWindow still has a frame reference, that frame must point | 1572 // If the LocalDOMWindow still has a frame reference, that frame must point |
| 1573 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation | 1573 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation |
| 1574 // where script execution leaks between different LocalDOMWindows. | 1574 // where script execution leaks between different LocalDOMWindows. |
| 1575 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this); | 1575 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this); |
| 1576 return m_frame; | 1576 return m_frame; |
| 1577 } | 1577 } |
| 1578 | 1578 |
| 1579 } // namespace blink | 1579 } // namespace blink |
| OLD | NEW |