Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1070)

Side by Side Diff: Source/core/frame/FrameView.cpp

Issue 82843003: Fire overflowchanged events at raf timing (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add a test Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/frame/FrameView.h ('k') | Source/core/page/EventHandler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 , m_canHaveScrollbars(true) 167 , m_canHaveScrollbars(true)
168 , m_slowRepaintObjectCount(0) 168 , m_slowRepaintObjectCount(0)
169 , m_layoutTimer(this, &FrameView::layoutTimerFired) 169 , m_layoutTimer(this, &FrameView::layoutTimerFired)
170 , m_layoutRoot(0) 170 , m_layoutRoot(0)
171 , m_inSynchronousPostLayout(false) 171 , m_inSynchronousPostLayout(false)
172 , m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired) 172 , m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired)
173 , m_updateWidgetsTimer(this, &FrameView::updateWidgetsTimerFired) 173 , m_updateWidgetsTimer(this, &FrameView::updateWidgetsTimerFired)
174 , m_isTransparent(false) 174 , m_isTransparent(false)
175 , m_baseBackgroundColor(Color::white) 175 , m_baseBackgroundColor(Color::white)
176 , m_mediaType("screen") 176 , m_mediaType("screen")
177 , m_overflowEventSuspendCount(0)
178 , m_overflowStatusDirty(true) 177 , m_overflowStatusDirty(true)
179 , m_viewportRenderer(0) 178 , m_viewportRenderer(0)
180 , m_wasScrolledByUser(false) 179 , m_wasScrolledByUser(false)
181 , m_inProgrammaticScroll(false) 180 , m_inProgrammaticScroll(false)
182 , m_safeToPropagateScrollToParent(true) 181 , m_safeToPropagateScrollToParent(true)
183 , m_deferredRepaintTimer(this, &FrameView::deferredRepaintTimerFired) 182 , m_deferredRepaintTimer(this, &FrameView::deferredRepaintTimerFired)
184 , m_isTrackingRepaints(false) 183 , m_isTrackingRepaints(false)
185 , m_shouldUpdateWhileOffscreen(true) 184 , m_shouldUpdateWhileOffscreen(true)
186 , m_deferSetNeedsLayouts(0) 185 , m_deferSetNeedsLayouts(0)
187 , m_setNeedsLayoutWasDeferred(false) 186 , m_setNeedsLayoutWasDeferred(false)
(...skipping 29 matching lines...) Expand all
217 RefPtr<FrameView> view = adoptRef(new FrameView(frame)); 216 RefPtr<FrameView> view = adoptRef(new FrameView(frame));
218 view->Widget::setFrameRect(IntRect(view->location(), initialSize)); 217 view->Widget::setFrameRect(IntRect(view->location(), initialSize));
219 view->setLayoutSizeInternal(initialSize); 218 view->setLayoutSizeInternal(initialSize);
220 219
221 view->show(); 220 view->show();
222 return view.release(); 221 return view.release();
223 } 222 }
224 223
225 FrameView::~FrameView() 224 FrameView::~FrameView()
226 { 225 {
227 if (m_postLayoutTasksTimer.isActive()) { 226 if (m_postLayoutTasksTimer.isActive())
228 m_postLayoutTasksTimer.stop(); 227 m_postLayoutTasksTimer.stop();
229 m_overflowEventQueue.clear();
230 }
231 228
232 removeFromAXObjectCache(); 229 removeFromAXObjectCache();
233 resetScrollbars(); 230 resetScrollbars();
234 231
235 // Custom scrollbars should already be destroyed at this point 232 // Custom scrollbars should already be destroyed at this point
236 ASSERT(!horizontalScrollbar() || !horizontalScrollbar()->isCustomScrollbar() ); 233 ASSERT(!horizontalScrollbar() || !horizontalScrollbar()->isCustomScrollbar() );
237 ASSERT(!verticalScrollbar() || !verticalScrollbar()->isCustomScrollbar()); 234 ASSERT(!verticalScrollbar() || !verticalScrollbar()->isCustomScrollbar());
238 235
239 setHasHorizontalScrollbar(false); // Remove native scrollbars now before we lose the connection to the HostWindow. 236 setHasHorizontalScrollbar(false); // Remove native scrollbars now before we lose the connection to the HostWindow.
240 setHasVerticalScrollbar(false); 237 setHasVerticalScrollbar(false);
241 238
242 ASSERT(!m_scrollCorner); 239 ASSERT(!m_scrollCorner);
243 ASSERT(m_overflowEventQueue.isEmpty());
244 240
245 ASSERT(m_frame); 241 ASSERT(m_frame);
246 ASSERT(m_frame->view() != this || !m_frame->contentRenderer()); 242 ASSERT(m_frame->view() != this || !m_frame->contentRenderer());
247 RenderPart* renderer = m_frame->ownerRenderer(); 243 RenderPart* renderer = m_frame->ownerRenderer();
248 if (renderer && renderer->widget() == this) 244 if (renderer && renderer->widget() == this)
249 renderer->setWidget(0); 245 renderer->setWidget(0);
250 } 246 }
251 247
252 void FrameView::reset() 248 void FrameView::reset()
253 { 249 {
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 } 914 }
919 915
920 m_inLayout = false; 916 m_inLayout = false;
921 917
922 if (inSubtreeLayout) 918 if (inSubtreeLayout)
923 rootForThisLayout->view()->popLayoutState(rootForThisLayout); 919 rootForThisLayout->view()->popLayoutState(rootForThisLayout);
924 } 920 }
925 921
926 void FrameView::scheduleOrPerformPostLayoutTasks() 922 void FrameView::scheduleOrPerformPostLayoutTasks()
927 { 923 {
928 if (m_postLayoutTasksTimer.isActive()) { 924 if (m_postLayoutTasksTimer.isActive())
929 resumeOverflowEvents();
930 return; 925 return;
931 }
932 926
933 // Partial layouts should not happen with synchronous post layouts. 927 // Partial layouts should not happen with synchronous post layouts.
934 ASSERT(!(m_inSynchronousPostLayout && partialLayout().isStopping())); 928 ASSERT(!(m_inSynchronousPostLayout && partialLayout().isStopping()));
935 929
936 if (!m_inSynchronousPostLayout) { 930 if (!m_inSynchronousPostLayout) {
937 if (frame().document()->shouldDisplaySeamlesslyWithParent()) { 931 if (frame().document()->shouldDisplaySeamlesslyWithParent()) {
938 if (RenderView* renderView = this->renderView()) 932 if (RenderView* renderView = this->renderView())
939 renderView->updateWidgetPositions(); 933 renderView->updateWidgetPositions();
940 } else { 934 } else {
941 m_inSynchronousPostLayout = true; 935 m_inSynchronousPostLayout = true;
942 // Calls resumeScheduledEvents() 936 // Calls resumeScheduledEvents()
943 performPostLayoutTasks(); 937 performPostLayoutTasks();
944 m_inSynchronousPostLayout = false; 938 m_inSynchronousPostLayout = false;
945 } 939 }
946 } 940 }
947 941
948 if (!m_postLayoutTasksTimer.isActive() && (needsLayout() || m_inSynchronousP ostLayout || frame().document()->shouldDisplaySeamlesslyWithParent())) { 942 if (!m_postLayoutTasksTimer.isActive() && (needsLayout() || m_inSynchronousP ostLayout || frame().document()->shouldDisplaySeamlesslyWithParent())) {
949 // If we need layout or are already in a synchronous call to postLayoutT asks(), 943 // If we need layout or are already in a synchronous call to postLayoutT asks(),
950 // defer widget updates and event dispatch until after we return. postLa youtTasks() 944 // defer widget updates and event dispatch until after we return. postLa youtTasks()
951 // can make us need to update again, and we can get stuck in a nasty cyc le unless 945 // can make us need to update again, and we can get stuck in a nasty cyc le unless
952 // we call it through the timer here. 946 // we call it through the timer here.
953 m_postLayoutTasksTimer.startOneShot(0); 947 m_postLayoutTasksTimer.startOneShot(0);
954 if (!partialLayout().isStopping() && needsLayout()) { 948 if (!partialLayout().isStopping() && needsLayout())
955 suspendOverflowEvents();
956 layout(); 949 layout();
957 }
958 } 950 }
959 } 951 }
960 952
961 void FrameView::layout(bool allowSubtree) 953 void FrameView::layout(bool allowSubtree)
962 { 954 {
963 // We should never layout a Document which is not in a Frame. 955 // We should never layout a Document which is not in a Frame.
964 ASSERT(m_frame); 956 ASSERT(m_frame);
965 ASSERT(m_frame->view() == this); 957 ASSERT(m_frame->view() == this);
966 ASSERT(m_frame->page()); 958 ASSERT(m_frame->page());
967 959
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 if (bodyRenderer && bodyRenderer->stretchesToViewport()) 1071 if (bodyRenderer && bodyRenderer->stretchesToViewport())
1080 bodyRenderer->setChildNeedsLayout(); 1072 bodyRenderer->setChildNeedsLayout();
1081 else if (rootRenderer && rootRenderer->stretchesToViewport() ) 1073 else if (rootRenderer && rootRenderer->stretchesToViewport() )
1082 rootRenderer->setChildNeedsLayout(); 1074 rootRenderer->setChildNeedsLayout();
1083 } 1075 }
1084 } 1076 }
1085 } 1077 }
1086 1078
1087 layer = rootForThisLayout->enclosingLayer(); 1079 layer = rootForThisLayout->enclosingLayer();
1088 1080
1089 suspendOverflowEvents();
1090
1091 performLayout(rootForThisLayout, inSubtreeLayout); 1081 performLayout(rootForThisLayout, inSubtreeLayout);
1092 1082
1093 m_layoutRoot = 0; 1083 m_layoutRoot = 0;
1094 } // Reset m_layoutSchedulingEnabled to its previous value. 1084 } // Reset m_layoutSchedulingEnabled to its previous value.
1095 1085
1096 bool neededFullRepaint = m_doFullRepaint; 1086 bool neededFullRepaint = m_doFullRepaint;
1097 1087
1098 if (!inSubtreeLayout && !isPartialLayout && !toRenderView(rootForThisLayout) ->document().printing()) 1088 if (!inSubtreeLayout && !isPartialLayout && !toRenderView(rootForThisLayout) ->document().printing())
1099 adjustViewSize(); 1089 adjustViewSize();
1100 1090
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 m_shouldUpdateWhileOffscreen = shouldUpdateWhileOffscreen; 2110 m_shouldUpdateWhileOffscreen = shouldUpdateWhileOffscreen;
2121 } 2111 }
2122 2112
2123 bool FrameView::shouldUpdate() const 2113 bool FrameView::shouldUpdate() const
2124 { 2114 {
2125 if (isOffscreen() && !shouldUpdateWhileOffscreen()) 2115 if (isOffscreen() && !shouldUpdateWhileOffscreen())
2126 return false; 2116 return false;
2127 return true; 2117 return true;
2128 } 2118 }
2129 2119
2130 void FrameView::suspendOverflowEvents()
2131 {
2132 ++m_overflowEventSuspendCount;
2133 }
2134
2135 void FrameView::resumeOverflowEvents()
2136 {
2137 // FIXME: We should assert here but it makes several tests fail. See http:// crbug.com/299788
2138 // ASSERT(m_overflowEventSuspendCount > 0);
2139
2140 if (--m_overflowEventSuspendCount)
2141 return;
2142
2143 Vector<RefPtr<OverflowEvent> > events;
2144 m_overflowEventQueue.swap(events);
2145
2146 for (Vector<RefPtr<OverflowEvent> >::iterator it = events.begin(); it != eve nts.end(); ++it) {
2147 Node* target = (*it)->target()->toNode();
2148 if (target->inDocument())
2149 target->dispatchEvent(*it, IGNORE_EXCEPTION);
2150 }
2151 }
2152
2153 void FrameView::scheduleOverflowEvent(PassRefPtr<OverflowEvent> event)
2154 {
2155 m_overflowEventQueue.append(event);
2156 }
2157
2158 void FrameView::scrollToAnchor() 2120 void FrameView::scrollToAnchor()
2159 { 2121 {
2160 RefPtr<Node> anchorNode = m_maintainScrollPositionAnchor; 2122 RefPtr<Node> anchorNode = m_maintainScrollPositionAnchor;
2161 if (!anchorNode) 2123 if (!anchorNode)
2162 return; 2124 return;
2163 2125
2164 if (!anchorNode->renderer()) 2126 if (!anchorNode->renderer())
2165 return; 2127 return;
2166 2128
2167 LayoutRect rect; 2129 LayoutRect rect;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2262 { 2224 {
2263 if (m_postLayoutTasksTimer.isActive()) 2225 if (m_postLayoutTasksTimer.isActive())
2264 performPostLayoutTasks(); 2226 performPostLayoutTasks();
2265 if (m_updateWidgetsTimer.isActive()) 2227 if (m_updateWidgetsTimer.isActive())
2266 updateWidgetsTimerFired(0); 2228 updateWidgetsTimerFired(0);
2267 } 2229 }
2268 2230
2269 void FrameView::performPostLayoutTasks() 2231 void FrameView::performPostLayoutTasks()
2270 { 2232 {
2271 TRACE_EVENT0("webkit", "FrameView::performPostLayoutTasks"); 2233 TRACE_EVENT0("webkit", "FrameView::performPostLayoutTasks");
2272 // FontFaceSet::didLayout() and resumeOverflowEvents() calls below can blow 2234 // FontFaceSet::didLayout() calls below can blow us away from underneath.
2273 // us away from underneath.
2274 // FIXME: We should not run any JavaScript code in this function. 2235 // FIXME: We should not run any JavaScript code in this function.
2275 RefPtr<FrameView> protect(this); 2236 RefPtr<FrameView> protect(this);
2276 2237
2277 m_postLayoutTasksTimer.stop(); 2238 m_postLayoutTasksTimer.stop();
2278 2239
2279 m_frame->selection().setCaretRectNeedsUpdate(); 2240 m_frame->selection().setCaretRectNeedsUpdate();
2280 m_frame->selection().updateAppearance(); 2241 m_frame->selection().updateAppearance();
2281 2242
2282 if (m_nestedLayoutCount <= 1) { 2243 if (m_nestedLayoutCount <= 1) {
2283 if (m_firstLayoutCallbackPending) { 2244 if (m_firstLayoutCallbackPending) {
(...skipping 22 matching lines...) Expand all
2306 2267
2307 m_updateWidgetsTimer.startOneShot(0); 2268 m_updateWidgetsTimer.startOneShot(0);
2308 2269
2309 if (Page* page = m_frame->page()) { 2270 if (Page* page = m_frame->page()) {
2310 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordina tor()) 2271 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordina tor())
2311 scrollingCoordinator->notifyLayoutUpdated(); 2272 scrollingCoordinator->notifyLayoutUpdated();
2312 } 2273 }
2313 2274
2314 scrollToAnchor(); 2275 scrollToAnchor();
2315 2276
2316 resumeOverflowEvents();
2317
2318 sendResizeEventIfNeeded(); 2277 sendResizeEventIfNeeded();
2319 } 2278 }
2320 2279
2321 void FrameView::sendResizeEventIfNeeded() 2280 void FrameView::sendResizeEventIfNeeded()
2322 { 2281 {
2323 ASSERT(m_frame); 2282 ASSERT(m_frame);
2324 2283
2325 RenderView* renderView = this->renderView(); 2284 RenderView* renderView = this->renderView();
2326 if (!renderView || renderView->document().printing()) 2285 if (!renderView || renderView->document().printing())
2327 return; 2286 return;
2328 2287
2329 IntSize currentSize = layoutSize(IncludeScrollbars); 2288 IntSize currentSize = layoutSize(IncludeScrollbars);
2330 float currentZoomFactor = renderView->style()->zoom(); 2289 float currentZoomFactor = renderView->style()->zoom();
2331 2290
2332 bool shouldSendResizeEvent = currentSize != m_lastViewportSize || currentZoo mFactor != m_lastZoomFactor; 2291 bool shouldSendResizeEvent = currentSize != m_lastViewportSize || currentZoo mFactor != m_lastZoomFactor;
2333 2292
2334 m_lastViewportSize = currentSize; 2293 m_lastViewportSize = currentSize;
2335 m_lastZoomFactor = currentZoomFactor; 2294 m_lastZoomFactor = currentZoomFactor;
2336 2295
2337 if (!shouldSendResizeEvent) 2296 if (!shouldSendResizeEvent)
2338 return; 2297 return;
2339 2298
2340 m_frame->eventHandler().sendResizeEvent(); 2299 m_frame->document()->enqueueResizeEvent();
2341 2300
2342 if (isMainFrame()) 2301 if (isMainFrame())
2343 InspectorInstrumentation::didResizeMainFrame(m_frame->page()); 2302 InspectorInstrumentation::didResizeMainFrame(m_frame->page());
2344 } 2303 }
2345 2304
2346 void FrameView::postLayoutTimerFired(Timer<FrameView>*) 2305 void FrameView::postLayoutTimerFired(Timer<FrameView>*)
2347 { 2306 {
2348 performPostLayoutTasks(); 2307 performPostLayoutTasks();
2349 } 2308 }
2350 2309
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 2432
2474 bool horizontalOverflowChanged = (m_horizontalOverflow != horizontalOverflow ); 2433 bool horizontalOverflowChanged = (m_horizontalOverflow != horizontalOverflow );
2475 bool verticalOverflowChanged = (m_verticalOverflow != verticalOverflow); 2434 bool verticalOverflowChanged = (m_verticalOverflow != verticalOverflow);
2476 2435
2477 if (horizontalOverflowChanged || verticalOverflowChanged) { 2436 if (horizontalOverflowChanged || verticalOverflowChanged) {
2478 m_horizontalOverflow = horizontalOverflow; 2437 m_horizontalOverflow = horizontalOverflow;
2479 m_verticalOverflow = verticalOverflow; 2438 m_verticalOverflow = verticalOverflow;
2480 2439
2481 RefPtr<OverflowEvent> event = OverflowEvent::create(horizontalOverflowCh anged, horizontalOverflow, verticalOverflowChanged, verticalOverflow); 2440 RefPtr<OverflowEvent> event = OverflowEvent::create(horizontalOverflowCh anged, horizontalOverflow, verticalOverflowChanged, verticalOverflow);
2482 event->setTarget(m_viewportRenderer->node()); 2441 event->setTarget(m_viewportRenderer->node());
2483 scheduleOverflowEvent(event); 2442 m_frame->document()->enqueueAnimationFrameEvent(event.release());
2484 } 2443 }
2485 2444
2486 } 2445 }
2487 2446
2488 const Pagination& FrameView::pagination() const 2447 const Pagination& FrameView::pagination() const
2489 { 2448 {
2490 if (m_pagination != Pagination()) 2449 if (m_pagination != Pagination())
2491 return m_pagination; 2450 return m_pagination;
2492 2451
2493 if (isMainFrame()) 2452 if (isMainFrame())
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
3511 void FrameView::willRemoveScrollbar(Scrollbar* scrollbar, ScrollbarOrientation o rientation) 3470 void FrameView::willRemoveScrollbar(Scrollbar* scrollbar, ScrollbarOrientation o rientation)
3512 { 3471 {
3513 ScrollableArea::willRemoveScrollbar(scrollbar, orientation); 3472 ScrollableArea::willRemoveScrollbar(scrollbar, orientation);
3514 if (AXObjectCache* cache = axObjectCache()) { 3473 if (AXObjectCache* cache = axObjectCache()) {
3515 cache->remove(scrollbar); 3474 cache->remove(scrollbar);
3516 cache->handleScrollbarUpdate(this); 3475 cache->handleScrollbarUpdate(this);
3517 } 3476 }
3518 } 3477 }
3519 3478
3520 } // namespace WebCore 3479 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/frame/FrameView.h ('k') | Source/core/page/EventHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698