author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 0 | 1918ee327afb |
child 10 | b5b118452c7d |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> |
|
3 |
* 1999 Lars Knoll <knoll@kde.org> |
|
4 |
* 1999 Antti Koivisto <koivisto@kde.org> |
|
5 |
* 2000 Dirk Mueller <mueller@kde.org> |
|
6 |
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
|
7 |
* (C) 2006 Graham Dennis (graham.dennis@gmail.com) |
|
8 |
* (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
|
9 |
* Copyright (C) 2009 Google Inc. All rights reserved. |
|
10 |
* |
|
11 |
* This library is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU Library General Public |
|
13 |
* License as published by the Free Software Foundation; either |
|
14 |
* version 2 of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This library is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
* Library General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU Library General Public License |
|
22 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
23 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
24 |
* Boston, MA 02110-1301, USA. |
|
25 |
*/ |
|
26 |
||
27 |
#include "config.h" |
|
28 |
#include "FrameView.h" |
|
29 |
||
30 |
#include "AXObjectCache.h" |
|
31 |
#include "CSSStyleSelector.h" |
|
32 |
#include "ChromeClient.h" |
|
33 |
#include "DocLoader.h" |
|
34 |
#include "EventHandler.h" |
|
35 |
#include "FloatRect.h" |
|
36 |
#include "FocusController.h" |
|
37 |
#include "Frame.h" |
|
38 |
#include "FrameLoader.h" |
|
39 |
#include "FrameLoaderClient.h" |
|
40 |
#include "FrameTree.h" |
|
41 |
#include "GraphicsContext.h" |
|
42 |
#include "HTMLDocument.h" |
|
43 |
#include "HTMLFrameElement.h" |
|
44 |
#include "HTMLFrameSetElement.h" |
|
45 |
#include "HTMLNames.h" |
|
46 |
#include "InspectorTimelineAgent.h" |
|
47 |
#include "OverflowEvent.h" |
|
48 |
#include "RenderPart.h" |
|
49 |
#include "RenderPartObject.h" |
|
50 |
#include "RenderScrollbar.h" |
|
51 |
#include "RenderScrollbarPart.h" |
|
52 |
#include "RenderTheme.h" |
|
53 |
#include "RenderView.h" |
|
54 |
#include "Settings.h" |
|
55 |
#include "TextResourceDecoder.h" |
|
56 |
#include <wtf/CurrentTime.h> |
|
57 |
||
58 |
#if USE(ACCELERATED_COMPOSITING) |
|
59 |
#include "RenderLayerCompositor.h" |
|
60 |
#endif |
|
61 |
||
62 |
#if ENABLE(SVG) |
|
63 |
#include "SVGDocument.h" |
|
64 |
#include "SVGLocatable.h" |
|
65 |
#include "SVGNames.h" |
|
66 |
#include "SVGPreserveAspectRatio.h" |
|
67 |
#include "SVGSVGElement.h" |
|
68 |
#include "SVGViewElement.h" |
|
69 |
#include "SVGViewSpec.h" |
|
70 |
#endif |
|
71 |
||
72 |
||
73 |
namespace WebCore { |
|
74 |
||
75 |
using namespace HTMLNames; |
|
76 |
||
77 |
double FrameView::sCurrentPaintTimeStamp = 0.0; |
|
78 |
||
79 |
#if ENABLE(REPAINT_THROTTLING) |
|
80 |
// Normal delay |
|
81 |
static const double deferredRepaintDelay = 0.025; |
|
82 |
// Negative value would mean that first few repaints happen without a delay |
|
83 |
static const double initialDeferredRepaintDelayDuringLoading = 0; |
|
84 |
// The delay grows on each repaint to this maximum value |
|
85 |
static const double maxDeferredRepaintDelayDuringLoading = 2.5; |
|
86 |
// On each repaint the delay increses by this amount |
|
87 |
static const double deferredRepaintDelayIncrementDuringLoading = 0.5; |
|
88 |
#else |
|
89 |
// FIXME: Repaint throttling could be good to have on all platform. |
|
90 |
// The balance between CPU use and repaint frequency will need some tuning for desktop. |
|
91 |
// More hooks may be needed to reset the delay on things like GIF and CSS animations. |
|
92 |
static const double deferredRepaintDelay = 0; |
|
93 |
static const double initialDeferredRepaintDelayDuringLoading = 0; |
|
94 |
static const double maxDeferredRepaintDelayDuringLoading = 0; |
|
95 |
static const double deferredRepaintDelayIncrementDuringLoading = 0; |
|
96 |
#endif |
|
97 |
||
98 |
// The maximum number of updateWidgets iterations that should be done before returning. |
|
99 |
static const unsigned maxUpdateWidgetsIterations = 2; |
|
100 |
||
101 |
struct ScheduledEvent { |
|
102 |
RefPtr<Event> m_event; |
|
103 |
RefPtr<Node> m_eventTarget; |
|
104 |
}; |
|
105 |
||
106 |
FrameView::FrameView(Frame* frame) |
|
107 |
: m_frame(frame) |
|
108 |
, m_slowRepaintObjectCount(0) |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
, m_fixedObjectCount(0) |
0 | 110 |
, m_layoutTimer(this, &FrameView::layoutTimerFired) |
111 |
, m_layoutRoot(0) |
|
112 |
, m_postLayoutTasksTimer(this, &FrameView::postLayoutTimerFired) |
|
113 |
, m_isTransparent(false) |
|
114 |
, m_baseBackgroundColor(Color::white) |
|
115 |
, m_mediaType("screen") |
|
116 |
, m_enqueueEvents(0) |
|
117 |
, m_overflowStatusDirty(true) |
|
118 |
, m_viewportRenderer(0) |
|
119 |
, m_wasScrolledByUser(false) |
|
120 |
, m_inProgrammaticScroll(false) |
|
121 |
, m_deferredRepaintTimer(this, &FrameView::deferredRepaintTimerFired) |
|
122 |
, m_shouldUpdateWhileOffscreen(true) |
|
123 |
, m_deferSetNeedsLayouts(0) |
|
124 |
, m_setNeedsLayoutWasDeferred(false) |
|
125 |
, m_scrollCorner(0) |
|
126 |
{ |
|
127 |
init(); |
|
128 |
} |
|
129 |
||
130 |
PassRefPtr<FrameView> FrameView::create(Frame* frame) |
|
131 |
{ |
|
132 |
RefPtr<FrameView> view = adoptRef(new FrameView(frame)); |
|
133 |
view->show(); |
|
134 |
return view.release(); |
|
135 |
} |
|
136 |
||
137 |
PassRefPtr<FrameView> FrameView::create(Frame* frame, const IntSize& initialSize) |
|
138 |
{ |
|
139 |
RefPtr<FrameView> view = adoptRef(new FrameView(frame)); |
|
140 |
view->Widget::setFrameRect(IntRect(view->pos(), initialSize)); |
|
141 |
view->show(); |
|
142 |
return view.release(); |
|
143 |
} |
|
144 |
||
145 |
FrameView::~FrameView() |
|
146 |
{ |
|
147 |
if (m_postLayoutTasksTimer.isActive()) { |
|
148 |
m_postLayoutTasksTimer.stop(); |
|
149 |
m_scheduledEvents.clear(); |
|
150 |
m_enqueueEvents = 0; |
|
151 |
} |
|
152 |
||
153 |
resetScrollbars(); |
|
154 |
||
155 |
// Custom scrollbars should already be destroyed at this point |
|
156 |
ASSERT(!horizontalScrollbar() || !horizontalScrollbar()->isCustomScrollbar()); |
|
157 |
ASSERT(!verticalScrollbar() || !verticalScrollbar()->isCustomScrollbar()); |
|
158 |
||
159 |
setHasHorizontalScrollbar(false); // Remove native scrollbars now before we lose the connection to the HostWindow. |
|
160 |
setHasVerticalScrollbar(false); |
|
161 |
||
162 |
ASSERT(!m_scrollCorner); |
|
163 |
ASSERT(m_scheduledEvents.isEmpty()); |
|
164 |
ASSERT(!m_enqueueEvents); |
|
165 |
||
166 |
if (m_frame) { |
|
167 |
ASSERT(m_frame->view() != this || !m_frame->contentRenderer()); |
|
168 |
RenderPart* renderer = m_frame->ownerRenderer(); |
|
169 |
if (renderer && renderer->widget() == this) |
|
170 |
renderer->setWidget(0); |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
void FrameView::reset() |
|
175 |
{ |
|
176 |
m_useSlowRepaints = false; |
|
177 |
m_isOverlapped = false; |
|
178 |
m_contentIsOpaque = false; |
|
179 |
m_borderX = 30; |
|
180 |
m_borderY = 30; |
|
181 |
m_layoutTimer.stop(); |
|
182 |
m_layoutRoot = 0; |
|
183 |
m_delayedLayout = false; |
|
184 |
m_doFullRepaint = true; |
|
185 |
m_layoutSchedulingEnabled = true; |
|
186 |
m_midLayout = false; |
|
187 |
m_layoutCount = 0; |
|
188 |
m_nestedLayoutCount = 0; |
|
189 |
m_postLayoutTasksTimer.stop(); |
|
190 |
m_firstLayout = true; |
|
191 |
m_firstLayoutCallbackPending = false; |
|
192 |
m_wasScrolledByUser = false; |
|
193 |
m_lastLayoutSize = IntSize(); |
|
194 |
m_lastZoomFactor = 1.0f; |
|
195 |
m_deferringRepaints = 0; |
|
196 |
m_repaintCount = 0; |
|
197 |
m_repaintRects.clear(); |
|
198 |
m_deferredRepaintDelay = initialDeferredRepaintDelayDuringLoading; |
|
199 |
m_deferredRepaintTimer.stop(); |
|
200 |
m_lastPaintTime = 0; |
|
201 |
m_paintRestriction = PaintRestrictionNone; |
|
202 |
m_isPainting = false; |
|
203 |
m_isVisuallyNonEmpty = false; |
|
204 |
m_firstVisuallyNonEmptyLayoutCallbackPending = true; |
|
205 |
m_maintainScrollPositionAnchor = 0; |
|
206 |
} |
|
207 |
||
208 |
bool FrameView::isFrameView() const |
|
209 |
{ |
|
210 |
return true; |
|
211 |
} |
|
212 |
||
213 |
void FrameView::clearFrame() |
|
214 |
{ |
|
215 |
m_frame = 0; |
|
216 |
} |
|
217 |
||
218 |
void FrameView::resetScrollbars() |
|
219 |
{ |
|
220 |
// Reset the document's scrollbars back to our defaults before we yield the floor. |
|
221 |
m_firstLayout = true; |
|
222 |
setScrollbarsSuppressed(true); |
|
223 |
setScrollbarModes(ScrollbarAuto, ScrollbarAuto); |
|
224 |
setScrollbarsSuppressed(false); |
|
225 |
} |
|
226 |
||
227 |
void FrameView::init() |
|
228 |
{ |
|
229 |
reset(); |
|
230 |
||
231 |
m_margins = IntSize(-1, -1); // undefined |
|
232 |
m_size = IntSize(); |
|
233 |
||
234 |
// Propagate the marginwidth/height and scrolling modes to the view. |
|
235 |
Element* ownerElement = m_frame && m_frame->document() ? m_frame->document()->ownerElement() : 0; |
|
236 |
if (ownerElement && (ownerElement->hasTagName(frameTag) || ownerElement->hasTagName(iframeTag))) { |
|
237 |
HTMLFrameElement* frameElt = static_cast<HTMLFrameElement*>(ownerElement); |
|
238 |
if (frameElt->scrollingMode() == ScrollbarAlwaysOff) |
|
239 |
setCanHaveScrollbars(false); |
|
240 |
int marginWidth = frameElt->getMarginWidth(); |
|
241 |
int marginHeight = frameElt->getMarginHeight(); |
|
242 |
if (marginWidth != -1) |
|
243 |
setMarginWidth(marginWidth); |
|
244 |
if (marginHeight != -1) |
|
245 |
setMarginHeight(marginHeight); |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
void FrameView::detachCustomScrollbars() |
|
250 |
{ |
|
251 |
if (!m_frame) |
|
252 |
return; |
|
253 |
||
254 |
Scrollbar* horizontalBar = horizontalScrollbar(); |
|
255 |
if (horizontalBar && horizontalBar->isCustomScrollbar() && !toRenderScrollbar(horizontalBar)->owningRenderer()->isRenderPart()) |
|
256 |
setHasHorizontalScrollbar(false); |
|
257 |
||
258 |
Scrollbar* verticalBar = verticalScrollbar(); |
|
259 |
if (verticalBar && verticalBar->isCustomScrollbar() && !toRenderScrollbar(verticalBar)->owningRenderer()->isRenderPart()) |
|
260 |
setHasVerticalScrollbar(false); |
|
261 |
||
262 |
if (m_scrollCorner) { |
|
263 |
m_scrollCorner->destroy(); |
|
264 |
m_scrollCorner = 0; |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
void FrameView::clear() |
|
269 |
{ |
|
270 |
setCanBlitOnScroll(true); |
|
271 |
||
272 |
reset(); |
|
273 |
||
274 |
if (m_frame) { |
|
275 |
if (RenderPart* renderer = m_frame->ownerRenderer()) |
|
276 |
renderer->viewCleared(); |
|
277 |
} |
|
278 |
||
279 |
setScrollbarsSuppressed(true); |
|
280 |
} |
|
281 |
||
282 |
bool FrameView::didFirstLayout() const |
|
283 |
{ |
|
284 |
return !m_firstLayout; |
|
285 |
} |
|
286 |
||
287 |
void FrameView::invalidateRect(const IntRect& rect) |
|
288 |
{ |
|
289 |
if (!parent()) { |
|
290 |
if (hostWindow()) |
|
291 |
hostWindow()->repaint(rect, true); |
|
292 |
return; |
|
293 |
} |
|
294 |
||
295 |
if (!m_frame) |
|
296 |
return; |
|
297 |
||
298 |
RenderPart* renderer = m_frame->ownerRenderer(); |
|
299 |
if (!renderer) |
|
300 |
return; |
|
301 |
||
302 |
IntRect repaintRect = rect; |
|
303 |
repaintRect.move(renderer->borderLeft() + renderer->paddingLeft(), |
|
304 |
renderer->borderTop() + renderer->paddingTop()); |
|
305 |
renderer->repaintRectangle(repaintRect); |
|
306 |
} |
|
307 |
||
308 |
void FrameView::setMarginWidth(int w) |
|
309 |
{ |
|
310 |
// make it update the rendering area when set |
|
311 |
m_margins.setWidth(w); |
|
312 |
} |
|
313 |
||
314 |
void FrameView::setMarginHeight(int h) |
|
315 |
{ |
|
316 |
// make it update the rendering area when set |
|
317 |
m_margins.setHeight(h); |
|
318 |
} |
|
319 |
||
320 |
PassRefPtr<Scrollbar> FrameView::createScrollbar(ScrollbarOrientation orientation) |
|
321 |
{ |
|
322 |
// FIXME: We need to update the scrollbar dynamically as documents change (or as doc elements and bodies get discovered that have custom styles). |
|
323 |
Document* doc = m_frame->document(); |
|
324 |
||
325 |
// Try the <body> element first as a scrollbar source. |
|
326 |
Element* body = doc ? doc->body() : 0; |
|
327 |
if (body && body->renderer() && body->renderer()->style()->hasPseudoStyle(SCROLLBAR)) |
|
328 |
return RenderScrollbar::createCustomScrollbar(this, orientation, body->renderBox()); |
|
329 |
||
330 |
// If the <body> didn't have a custom style, then the root element might. |
|
331 |
Element* docElement = doc ? doc->documentElement() : 0; |
|
332 |
if (docElement && docElement->renderer() && docElement->renderer()->style()->hasPseudoStyle(SCROLLBAR)) |
|
333 |
return RenderScrollbar::createCustomScrollbar(this, orientation, docElement->renderBox()); |
|
334 |
||
335 |
// If we have an owning iframe/frame element, then it can set the custom scrollbar also. |
|
336 |
RenderPart* frameRenderer = m_frame->ownerRenderer(); |
|
337 |
if (frameRenderer && frameRenderer->style()->hasPseudoStyle(SCROLLBAR)) |
|
338 |
return RenderScrollbar::createCustomScrollbar(this, orientation, frameRenderer); |
|
339 |
||
340 |
// Nobody set a custom style, so we just use a native scrollbar. |
|
341 |
return ScrollView::createScrollbar(orientation); |
|
342 |
} |
|
343 |
||
344 |
void FrameView::setContentsSize(const IntSize& size) |
|
345 |
{ |
|
346 |
m_deferSetNeedsLayouts++; |
|
347 |
||
348 |
ScrollView::setContentsSize(size); |
|
349 |
||
350 |
Page* page = frame() ? frame()->page() : 0; |
|
351 |
if (!page) |
|
352 |
return; |
|
353 |
||
354 |
page->chrome()->contentsSizeChanged(frame(), size); //notify only |
|
355 |
||
356 |
m_deferSetNeedsLayouts--; |
|
357 |
||
358 |
if (!m_deferSetNeedsLayouts) |
|
359 |
m_setNeedsLayoutWasDeferred = false; // FIXME: Find a way to make the deferred layout actually happen. |
|
360 |
} |
|
361 |
||
362 |
void FrameView::adjustViewSize() |
|
363 |
{ |
|
364 |
ASSERT(m_frame->view() == this); |
|
365 |
RenderView* root = m_frame->contentRenderer(); |
|
366 |
if (!root) |
|
367 |
return; |
|
368 |
setContentsSize(IntSize(root->rightLayoutOverflow(), root->bottomLayoutOverflow())); |
|
369 |
} |
|
370 |
||
371 |
void FrameView::applyOverflowToViewport(RenderObject* o, ScrollbarMode& hMode, ScrollbarMode& vMode) |
|
372 |
{ |
|
373 |
// Handle the overflow:hidden/scroll case for the body/html elements. WinIE treats |
|
374 |
// overflow:hidden and overflow:scroll on <body> as applying to the document's |
|
375 |
// scrollbars. The CSS2.1 draft states that HTML UAs should use the <html> or <body> element and XML/XHTML UAs should |
|
376 |
// use the root element. |
|
377 |
switch (o->style()->overflowX()) { |
|
378 |
case OHIDDEN: |
|
379 |
hMode = ScrollbarAlwaysOff; |
|
380 |
break; |
|
381 |
case OSCROLL: |
|
382 |
hMode = ScrollbarAlwaysOn; |
|
383 |
break; |
|
384 |
case OAUTO: |
|
385 |
hMode = ScrollbarAuto; |
|
386 |
break; |
|
387 |
default: |
|
388 |
// Don't set it at all. |
|
389 |
; |
|
390 |
} |
|
391 |
||
392 |
switch (o->style()->overflowY()) { |
|
393 |
case OHIDDEN: |
|
394 |
vMode = ScrollbarAlwaysOff; |
|
395 |
break; |
|
396 |
case OSCROLL: |
|
397 |
vMode = ScrollbarAlwaysOn; |
|
398 |
break; |
|
399 |
case OAUTO: |
|
400 |
vMode = ScrollbarAuto; |
|
401 |
break; |
|
402 |
default: |
|
403 |
// Don't set it at all. |
|
404 |
; |
|
405 |
} |
|
406 |
||
407 |
m_viewportRenderer = o; |
|
408 |
} |
|
409 |
||
410 |
#if USE(ACCELERATED_COMPOSITING) |
|
411 |
void FrameView::updateCompositingLayers() |
|
412 |
{ |
|
413 |
RenderView* view = m_frame->contentRenderer(); |
|
414 |
if (!view) |
|
415 |
return; |
|
416 |
||
417 |
// This call will make sure the cached hasAcceleratedCompositing is updated from the pref |
|
418 |
view->compositor()->cacheAcceleratedCompositingEnabledFlag(); |
|
419 |
||
420 |
if (!view->usesCompositing()) |
|
421 |
return; |
|
422 |
||
423 |
view->compositor()->updateCompositingLayers(); |
|
424 |
} |
|
425 |
||
426 |
void FrameView::setNeedsOneShotDrawingSynchronization() |
|
427 |
{ |
|
428 |
Page* page = frame() ? frame()->page() : 0; |
|
429 |
if (page) |
|
430 |
page->chrome()->client()->setNeedsOneShotDrawingSynchronization(); |
|
431 |
} |
|
432 |
#endif // USE(ACCELERATED_COMPOSITING) |
|
433 |
||
434 |
bool FrameView::syncCompositingStateRecursive() |
|
435 |
{ |
|
436 |
#if USE(ACCELERATED_COMPOSITING) |
|
437 |
ASSERT(m_frame->view() == this); |
|
438 |
RenderView* contentRenderer = m_frame->contentRenderer(); |
|
439 |
if (!contentRenderer) |
|
440 |
return true; // We don't want to keep trying to update layers if we have no renderer. |
|
441 |
||
442 |
if (m_layoutTimer.isActive()) { |
|
443 |
// Don't sync layers if there's a layout pending. |
|
444 |
return false; |
|
445 |
} |
|
446 |
||
447 |
if (GraphicsLayer* rootLayer = contentRenderer->compositor()->rootPlatformLayer()) |
|
448 |
rootLayer->syncCompositingState(); |
|
449 |
||
450 |
bool allSubframesSynced = true; |
|
451 |
const HashSet<RefPtr<Widget> >* viewChildren = children(); |
|
452 |
HashSet<RefPtr<Widget> >::const_iterator end = viewChildren->end(); |
|
453 |
for (HashSet<RefPtr<Widget> >::const_iterator current = viewChildren->begin(); current != end; ++current) { |
|
454 |
Widget* widget = (*current).get(); |
|
455 |
if (widget->isFrameView()) { |
|
456 |
bool synced = static_cast<FrameView*>(widget)->syncCompositingStateRecursive(); |
|
457 |
allSubframesSynced &= synced; |
|
458 |
} |
|
459 |
} |
|
460 |
return allSubframesSynced; |
|
461 |
#endif // USE(ACCELERATED_COMPOSITING) |
|
462 |
return true; |
|
463 |
} |
|
464 |
||
465 |
void FrameView::didMoveOnscreen() |
|
466 |
{ |
|
467 |
RenderView* view = m_frame->contentRenderer(); |
|
468 |
if (view) |
|
469 |
view->didMoveOnscreen(); |
|
470 |
} |
|
471 |
||
472 |
void FrameView::willMoveOffscreen() |
|
473 |
{ |
|
474 |
RenderView* view = m_frame->contentRenderer(); |
|
475 |
if (view) |
|
476 |
view->willMoveOffscreen(); |
|
477 |
} |
|
478 |
||
479 |
RenderObject* FrameView::layoutRoot(bool onlyDuringLayout) const |
|
480 |
{ |
|
481 |
return onlyDuringLayout && layoutPending() ? 0 : m_layoutRoot; |
|
482 |
} |
|
483 |
||
484 |
void FrameView::layout(bool allowSubtree) |
|
485 |
{ |
|
486 |
if (m_midLayout) |
|
487 |
return; |
|
488 |
||
489 |
m_layoutTimer.stop(); |
|
490 |
m_delayedLayout = false; |
|
491 |
m_setNeedsLayoutWasDeferred = false; |
|
492 |
||
493 |
// Protect the view from being deleted during layout (in recalcStyle) |
|
494 |
RefPtr<FrameView> protector(this); |
|
495 |
||
496 |
if (!m_frame) { |
|
497 |
// FIXME: Do we need to set m_size.width here? |
|
498 |
// FIXME: Should we set m_size.height here too? |
|
499 |
m_size.setWidth(layoutWidth()); |
|
500 |
return; |
|
501 |
} |
|
502 |
||
503 |
// we shouldn't enter layout() while painting |
|
504 |
ASSERT(!isPainting()); |
|
505 |
if (isPainting()) |
|
506 |
return; |
|
507 |
||
508 |
#if ENABLE(INSPECTOR) |
|
509 |
InspectorTimelineAgent* timelineAgent = inspectorTimelineAgent(); |
|
510 |
if (timelineAgent) |
|
511 |
timelineAgent->willLayout(); |
|
512 |
#endif |
|
513 |
||
514 |
if (!allowSubtree && m_layoutRoot) { |
|
515 |
m_layoutRoot->markContainingBlocksForLayout(false); |
|
516 |
m_layoutRoot = 0; |
|
517 |
} |
|
518 |
||
519 |
ASSERT(m_frame->view() == this); |
|
520 |
// This early return should be removed when rdar://5598072 is resolved. In the meantime, there is a |
|
521 |
// gigantic CrashTracer because of this issue, and the early return will hopefully cause graceful |
|
522 |
// failure instead. |
|
523 |
if (m_frame->view() != this) |
|
524 |
return; |
|
525 |
||
526 |
Document* document = m_frame->document(); |
|
527 |
||
528 |
m_layoutSchedulingEnabled = false; |
|
529 |
||
530 |
if (!m_nestedLayoutCount && m_postLayoutTasksTimer.isActive()) { |
|
531 |
// This is a new top-level layout. If there are any remaining tasks from the previous |
|
532 |
// layout, finish them now. |
|
533 |
m_postLayoutTasksTimer.stop(); |
|
534 |
performPostLayoutTasks(); |
|
535 |
} |
|
536 |
||
537 |
// Viewport-dependent media queries may cause us to need completely different style information. |
|
538 |
// Check that here. |
|
539 |
if (document->styleSelector()->affectedByViewportChange()) |
|
540 |
document->updateStyleSelector(); |
|
541 |
||
542 |
// Always ensure our style info is up-to-date. This can happen in situations where |
|
543 |
// the layout beats any sort of style recalc update that needs to occur. |
|
544 |
if (m_frame->needsReapplyStyles()) |
|
545 |
m_frame->reapplyStyles(); |
|
546 |
else if (document->childNeedsStyleRecalc()) |
|
547 |
document->recalcStyle(); |
|
548 |
||
549 |
bool subtree = m_layoutRoot; |
|
550 |
||
551 |
// If there is only one ref to this view left, then its going to be destroyed as soon as we exit, |
|
552 |
// so there's no point to continuing to layout |
|
553 |
if (protector->hasOneRef()) |
|
554 |
return; |
|
555 |
||
556 |
RenderObject* root = subtree ? m_layoutRoot : document->renderer(); |
|
557 |
if (!root) { |
|
558 |
// FIXME: Do we need to set m_size here? |
|
559 |
m_layoutSchedulingEnabled = true; |
|
560 |
return; |
|
561 |
} |
|
562 |
||
563 |
m_nestedLayoutCount++; |
|
564 |
||
565 |
ScrollbarMode hMode; |
|
566 |
ScrollbarMode vMode; |
|
567 |
scrollbarModes(hMode, vMode); |
|
568 |
||
569 |
if (!subtree) { |
|
570 |
RenderObject* rootRenderer = document->documentElement() ? document->documentElement()->renderer() : 0; |
|
571 |
Node* body = document->body(); |
|
572 |
if (body && body->renderer()) { |
|
573 |
if (body->hasTagName(framesetTag)) { |
|
574 |
body->renderer()->setChildNeedsLayout(true); |
|
575 |
vMode = ScrollbarAlwaysOff; |
|
576 |
hMode = ScrollbarAlwaysOff; |
|
577 |
} else if (body->hasTagName(bodyTag)) { |
|
578 |
if (!m_firstLayout && m_size.height() != layoutHeight() |
|
579 |
&& toRenderBox(body->renderer())->stretchesToViewHeight()) |
|
580 |
body->renderer()->setChildNeedsLayout(true); |
|
581 |
// It's sufficient to just check the X overflow, |
|
582 |
// since it's illegal to have visible in only one direction. |
|
583 |
RenderObject* o = rootRenderer->style()->overflowX() == OVISIBLE && document->documentElement()->hasTagName(htmlTag) ? body->renderer() : rootRenderer; |
|
584 |
applyOverflowToViewport(o, hMode, vMode); |
|
585 |
} |
|
586 |
} else if (rootRenderer) |
|
587 |
applyOverflowToViewport(rootRenderer, hMode, vMode); |
|
588 |
#ifdef INSTRUMENT_LAYOUT_SCHEDULING |
|
589 |
if (m_firstLayout && !document->ownerElement()) |
|
590 |
printf("Elapsed time before first layout: %d\n", document->elapsedTime()); |
|
591 |
#endif |
|
592 |
} |
|
593 |
||
594 |
m_doFullRepaint = !subtree && (m_firstLayout || toRenderView(root)->printing()); |
|
595 |
||
596 |
if (!subtree) { |
|
597 |
// Now set our scrollbar state for the layout. |
|
598 |
ScrollbarMode currentHMode = horizontalScrollbarMode(); |
|
599 |
ScrollbarMode currentVMode = verticalScrollbarMode(); |
|
600 |
||
601 |
if (m_firstLayout || (hMode != currentHMode || vMode != currentVMode)) { |
|
602 |
setScrollbarsSuppressed(true); |
|
603 |
if (m_firstLayout) { |
|
604 |
m_firstLayout = false; |
|
605 |
m_firstLayoutCallbackPending = true; |
|
606 |
m_lastLayoutSize = IntSize(width(), height()); |
|
607 |
m_lastZoomFactor = root->style()->zoom(); |
|
608 |
||
609 |
// Set the initial vMode to AlwaysOn if we're auto. |
|
610 |
if (vMode == ScrollbarAuto) |
|
611 |
setVerticalScrollbarMode(ScrollbarAlwaysOn); // This causes a vertical scrollbar to appear. |
|
612 |
// Set the initial hMode to AlwaysOff if we're auto. |
|
613 |
if (hMode == ScrollbarAuto) |
|
614 |
setHorizontalScrollbarMode(ScrollbarAlwaysOff); // This causes a horizontal scrollbar to disappear. |
|
615 |
} |
|
616 |
setScrollbarModes(hMode, vMode); |
|
617 |
setScrollbarsSuppressed(false, true); |
|
618 |
} |
|
619 |
||
620 |
IntSize oldSize = m_size; |
|
621 |
||
622 |
m_size = IntSize(layoutWidth(), layoutHeight()); |
|
623 |
||
624 |
if (oldSize != m_size) |
|
625 |
m_doFullRepaint = true; |
|
626 |
} |
|
627 |
||
628 |
RenderLayer* layer = root->enclosingLayer(); |
|
629 |
||
630 |
pauseScheduledEvents(); |
|
631 |
||
632 |
if (subtree) |
|
633 |
root->view()->pushLayoutState(root); |
|
634 |
||
635 |
m_midLayout = true; |
|
636 |
beginDeferredRepaints(); |
|
637 |
root->layout(); |
|
638 |
endDeferredRepaints(); |
|
639 |
m_midLayout = false; |
|
640 |
||
641 |
if (subtree) |
|
642 |
root->view()->popLayoutState(); |
|
643 |
m_layoutRoot = 0; |
|
644 |
||
645 |
m_frame->invalidateSelection(); |
|
646 |
||
647 |
m_layoutSchedulingEnabled = true; |
|
648 |
||
649 |
if (!subtree && !toRenderView(root)->printing()) |
|
650 |
adjustViewSize(); |
|
651 |
||
652 |
// Now update the positions of all layers. |
|
653 |
beginDeferredRepaints(); |
|
654 |
layer->updateLayerPositions((m_doFullRepaint ? RenderLayer::DoFullRepaint : 0) |
|
655 |
| RenderLayer::CheckForRepaint |
|
656 |
| RenderLayer::IsCompositingUpdateRoot |
|
657 |
| RenderLayer::UpdateCompositingLayers); |
|
658 |
endDeferredRepaints(); |
|
659 |
||
660 |
#if USE(ACCELERATED_COMPOSITING) |
|
661 |
updateCompositingLayers(); |
|
662 |
#endif |
|
663 |
||
664 |
m_layoutCount++; |
|
665 |
||
666 |
#if PLATFORM(MAC) |
|
667 |
if (AXObjectCache::accessibilityEnabled()) |
|
668 |
root->document()->axObjectCache()->postNotification(root, AXObjectCache::AXLayoutComplete, true); |
|
669 |
#endif |
|
670 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
671 |
updateDashboardRegions(); |
|
672 |
#endif |
|
673 |
||
674 |
ASSERT(!root->needsLayout()); |
|
675 |
||
676 |
setCanBlitOnScroll(!useSlowRepaints()); |
|
677 |
||
678 |
if (document->hasListenerType(Document::OVERFLOWCHANGED_LISTENER)) |
|
679 |
updateOverflowStatus(layoutWidth() < contentsWidth(), |
|
680 |
layoutHeight() < contentsHeight()); |
|
681 |
||
682 |
if (!m_postLayoutTasksTimer.isActive()) { |
|
683 |
// Calls resumeScheduledEvents() |
|
684 |
performPostLayoutTasks(); |
|
685 |
||
686 |
if (!m_postLayoutTasksTimer.isActive() && needsLayout()) { |
|
687 |
// Post-layout widget updates or an event handler made us need layout again. |
|
688 |
// Lay out again, but this time defer widget updates and event dispatch until after |
|
689 |
// we return. |
|
690 |
m_postLayoutTasksTimer.startOneShot(0); |
|
691 |
pauseScheduledEvents(); |
|
692 |
layout(); |
|
693 |
} |
|
694 |
} else { |
|
695 |
resumeScheduledEvents(); |
|
696 |
ASSERT(m_enqueueEvents); |
|
697 |
} |
|
698 |
||
699 |
#if ENABLE(INSPECTOR) |
|
700 |
if (timelineAgent) |
|
701 |
timelineAgent->didLayout(); |
|
702 |
#endif |
|
703 |
||
704 |
m_nestedLayoutCount--; |
|
705 |
} |
|
706 |
||
707 |
void FrameView::addWidgetToUpdate(RenderPartObject* object) |
|
708 |
{ |
|
709 |
if (!m_widgetUpdateSet) |
|
710 |
m_widgetUpdateSet.set(new HashSet<RenderPartObject*>); |
|
711 |
||
712 |
m_widgetUpdateSet->add(object); |
|
713 |
} |
|
714 |
||
715 |
void FrameView::removeWidgetToUpdate(RenderPartObject* object) |
|
716 |
{ |
|
717 |
if (!m_widgetUpdateSet) |
|
718 |
return; |
|
719 |
||
720 |
m_widgetUpdateSet->remove(object); |
|
721 |
} |
|
722 |
||
723 |
void FrameView::setMediaType(const String& mediaType) |
|
724 |
{ |
|
725 |
m_mediaType = mediaType; |
|
726 |
} |
|
727 |
||
728 |
String FrameView::mediaType() const |
|
729 |
{ |
|
730 |
// See if we have an override type. |
|
731 |
String overrideType = m_frame->loader()->client()->overrideMediaType(); |
|
732 |
if (!overrideType.isNull()) |
|
733 |
return overrideType; |
|
734 |
return m_mediaType; |
|
735 |
} |
|
736 |
||
737 |
bool FrameView::useSlowRepaints() const |
|
738 |
{ |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
739 |
return m_useSlowRepaints || m_slowRepaintObjectCount > 0 || (platformWidget() && m_fixedObjectCount > 0) || m_isOverlapped || !m_contentIsOpaque; |
0 | 740 |
} |
741 |
||
742 |
void FrameView::setUseSlowRepaints() |
|
743 |
{ |
|
744 |
m_useSlowRepaints = true; |
|
745 |
setCanBlitOnScroll(false); |
|
746 |
} |
|
747 |
||
748 |
void FrameView::addSlowRepaintObject() |
|
749 |
{ |
|
750 |
if (!m_slowRepaintObjectCount) |
|
751 |
setCanBlitOnScroll(false); |
|
752 |
m_slowRepaintObjectCount++; |
|
753 |
} |
|
754 |
||
755 |
void FrameView::removeSlowRepaintObject() |
|
756 |
{ |
|
757 |
ASSERT(m_slowRepaintObjectCount > 0); |
|
758 |
m_slowRepaintObjectCount--; |
|
759 |
if (!m_slowRepaintObjectCount) |
|
760 |
setCanBlitOnScroll(!useSlowRepaints()); |
|
761 |
} |
|
762 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
void FrameView::addFixedObject() |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
{ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
if (!m_fixedObjectCount && platformWidget()) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
setCanBlitOnScroll(false); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
++m_fixedObjectCount; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
void FrameView::removeFixedObject() |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
{ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
ASSERT(m_fixedObjectCount > 0); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
m_fixedObjectCount--; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
if (!m_fixedObjectCount) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
setCanBlitOnScroll(!useSlowRepaints()); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
776 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
778 |
void FrameView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
{ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
780 |
const size_t fixedObjectThreshold = 5; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
782 |
ListHashSet<RenderBox*>* positionedObjects = 0; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
if (RenderView* root = m_frame->contentRenderer()) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
784 |
positionedObjects = root->positionedObjects(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
785 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
786 |
if (!positionedObjects || positionedObjects->isEmpty()) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
787 |
hostWindow()->scroll(scrollDelta, rectToScroll, clipRect); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
788 |
return; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
789 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
790 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
791 |
// Get the rects of the fixed objects visible in the rectToScroll |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
792 |
Vector<IntRect, fixedObjectThreshold> subRectToUpdate; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
793 |
bool updateInvalidatedSubRect = true; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
794 |
ListHashSet<RenderBox*>::const_iterator end = positionedObjects->end(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
795 |
for (ListHashSet<RenderBox*>::const_iterator it = positionedObjects->begin(); it != end; ++it) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
796 |
RenderBox* renderBox = *it; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
797 |
if (renderBox->style()->position() != FixedPosition) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
798 |
continue; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
799 |
IntRect topLevelRect; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
800 |
IntRect updateRect = renderBox->paintingRootRect(topLevelRect); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
801 |
updateRect.move(-scrollX(), -scrollY()); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
802 |
updateRect.intersect(rectToScroll); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
803 |
if (!updateRect.isEmpty()) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
804 |
if (subRectToUpdate.size() >= fixedObjectThreshold) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
805 |
updateInvalidatedSubRect = false; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
806 |
break; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
807 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
808 |
subRectToUpdate.append(updateRect); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
809 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
810 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
811 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
812 |
// Scroll the view |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
813 |
if (updateInvalidatedSubRect) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
814 |
// 1) scroll |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
815 |
hostWindow()->scroll(scrollDelta, rectToScroll, clipRect); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
816 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
817 |
// 2) update the area of fixed objets that has been invalidated |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
818 |
size_t fixObjectsCount = subRectToUpdate.size(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
819 |
for (size_t i = 0; i < fixObjectsCount; ++i) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
820 |
IntRect updateRect = subRectToUpdate[i]; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
821 |
IntRect scrolledRect = updateRect; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
822 |
scrolledRect.move(scrollDelta); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
823 |
updateRect.unite(scrolledRect); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
824 |
updateRect.intersect(rectToScroll); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
825 |
hostWindow()->repaint(updateRect, true, false, true); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
826 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
827 |
} else { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
828 |
// the number of fixed objects exceed the threshold, so we repaint everything. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
829 |
IntRect updateRect = clipRect; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
830 |
updateRect.intersect(rectToScroll); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
831 |
hostWindow()->repaint(updateRect, true, false, true); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
832 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
833 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
834 |
|
0 | 835 |
void FrameView::setIsOverlapped(bool isOverlapped) |
836 |
{ |
|
837 |
if (isOverlapped == m_isOverlapped) |
|
838 |
return; |
|
839 |
||
840 |
m_isOverlapped = isOverlapped; |
|
841 |
setCanBlitOnScroll(!useSlowRepaints()); |
|
842 |
} |
|
843 |
||
844 |
void FrameView::setContentIsOpaque(bool contentIsOpaque) |
|
845 |
{ |
|
846 |
if (contentIsOpaque == m_contentIsOpaque) |
|
847 |
return; |
|
848 |
||
849 |
m_contentIsOpaque = contentIsOpaque; |
|
850 |
setCanBlitOnScroll(!useSlowRepaints()); |
|
851 |
} |
|
852 |
||
853 |
void FrameView::restoreScrollbar() |
|
854 |
{ |
|
855 |
setScrollbarsSuppressed(false); |
|
856 |
} |
|
857 |
||
858 |
bool FrameView::scrollToFragment(const KURL& url) |
|
859 |
{ |
|
860 |
// If our URL has no ref, then we have no place we need to jump to. |
|
861 |
// OTOH If CSS target was set previously, we want to set it to 0, recalc |
|
862 |
// and possibly repaint because :target pseudo class may have been |
|
863 |
// set (see bug 11321). |
|
864 |
if (!url.hasFragmentIdentifier() && !m_frame->document()->cssTarget()) |
|
865 |
return false; |
|
866 |
||
867 |
String fragmentIdentifier = url.fragmentIdentifier(); |
|
868 |
if (scrollToAnchor(fragmentIdentifier)) |
|
869 |
return true; |
|
870 |
||
871 |
// Try again after decoding the ref, based on the document's encoding. |
|
872 |
if (TextResourceDecoder* decoder = m_frame->document()->decoder()) |
|
873 |
return scrollToAnchor(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding())); |
|
874 |
||
875 |
return false; |
|
876 |
} |
|
877 |
||
878 |
bool FrameView::scrollToAnchor(const String& name) |
|
879 |
{ |
|
880 |
ASSERT(m_frame->document()); |
|
881 |
||
882 |
if (!m_frame->document()->haveStylesheetsLoaded()) { |
|
883 |
m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(true); |
|
884 |
return false; |
|
885 |
} |
|
886 |
||
887 |
m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(false); |
|
888 |
||
889 |
Element* anchorNode = m_frame->document()->findAnchor(name); |
|
890 |
||
891 |
#if ENABLE(SVG) |
|
892 |
if (m_frame->document()->isSVGDocument()) { |
|
893 |
if (name.startsWith("xpointer(")) { |
|
894 |
// We need to parse the xpointer reference here |
|
895 |
} else if (name.startsWith("svgView(")) { |
|
896 |
RefPtr<SVGSVGElement> svg = static_cast<SVGDocument*>(m_frame->document())->rootElement(); |
|
897 |
if (!svg->currentView()->parseViewSpec(name)) |
|
898 |
return false; |
|
899 |
svg->setUseCurrentView(true); |
|
900 |
} else { |
|
901 |
if (anchorNode && anchorNode->hasTagName(SVGNames::viewTag)) { |
|
902 |
RefPtr<SVGViewElement> viewElement = anchorNode->hasTagName(SVGNames::viewTag) ? static_cast<SVGViewElement*>(anchorNode) : 0; |
|
903 |
if (viewElement.get()) { |
|
904 |
RefPtr<SVGSVGElement> svg = static_cast<SVGSVGElement*>(SVGLocatable::nearestViewportElement(viewElement.get())); |
|
905 |
svg->inheritViewAttributes(viewElement.get()); |
|
906 |
} |
|
907 |
} |
|
908 |
} |
|
909 |
// FIXME: need to decide which <svg> to focus on, and zoom to that one |
|
910 |
// FIXME: need to actually "highlight" the viewTarget(s) |
|
911 |
} |
|
912 |
#endif |
|
913 |
||
914 |
m_frame->document()->setCSSTarget(anchorNode); // Setting to null will clear the current target. |
|
915 |
||
916 |
// Implement the rule that "" and "top" both mean top of page as in other browsers. |
|
917 |
if (!anchorNode && !(name.isEmpty() || equalIgnoringCase(name, "top"))) |
|
918 |
return false; |
|
919 |
||
920 |
maintainScrollPositionAtAnchor(anchorNode ? static_cast<Node*>(anchorNode) : m_frame->document()); |
|
921 |
return true; |
|
922 |
} |
|
923 |
||
924 |
void FrameView::maintainScrollPositionAtAnchor(Node* anchorNode) |
|
925 |
{ |
|
926 |
m_maintainScrollPositionAnchor = anchorNode; |
|
927 |
if (!m_maintainScrollPositionAnchor) |
|
928 |
return; |
|
929 |
||
930 |
// We need to update the layout before scrolling, otherwise we could |
|
931 |
// really mess things up if an anchor scroll comes at a bad moment. |
|
932 |
m_frame->document()->updateStyleIfNeeded(); |
|
933 |
// Only do a layout if changes have occurred that make it necessary. |
|
934 |
if (m_frame->contentRenderer() && m_frame->contentRenderer()->needsLayout()) |
|
935 |
layout(); |
|
936 |
else |
|
937 |
scrollToAnchor(); |
|
938 |
} |
|
939 |
||
940 |
void FrameView::scrollRectIntoViewRecursively(const IntRect& r) |
|
941 |
{ |
|
942 |
bool wasInProgrammaticScroll = m_inProgrammaticScroll; |
|
943 |
m_inProgrammaticScroll = true; |
|
944 |
m_maintainScrollPositionAnchor = 0; |
|
945 |
ScrollView::scrollRectIntoViewRecursively(r); |
|
946 |
m_inProgrammaticScroll = wasInProgrammaticScroll; |
|
947 |
} |
|
948 |
||
949 |
void FrameView::setScrollPosition(const IntPoint& scrollPoint) |
|
950 |
{ |
|
951 |
bool wasInProgrammaticScroll = m_inProgrammaticScroll; |
|
952 |
m_inProgrammaticScroll = true; |
|
953 |
m_maintainScrollPositionAnchor = 0; |
|
954 |
ScrollView::setScrollPosition(scrollPoint); |
|
955 |
m_inProgrammaticScroll = wasInProgrammaticScroll; |
|
956 |
} |
|
957 |
||
958 |
void FrameView::scrollPositionChanged() |
|
959 |
{ |
|
960 |
frame()->eventHandler()->sendScrollEvent(); |
|
961 |
||
962 |
#if USE(ACCELERATED_COMPOSITING) |
|
963 |
// We need to update layer positions after scrolling to account for position:fixed layers. |
|
964 |
Document* document = m_frame->document(); |
|
965 |
if (!document) |
|
966 |
return; |
|
967 |
||
968 |
RenderLayer* layer = document->renderer() ? document->renderer()->enclosingLayer() : 0; |
|
969 |
if (layer) |
|
970 |
layer->updateLayerPositions(RenderLayer::UpdateCompositingLayers); |
|
971 |
#endif |
|
972 |
} |
|
973 |
||
974 |
HostWindow* FrameView::hostWindow() const |
|
975 |
{ |
|
976 |
Page* page = frame() ? frame()->page() : 0; |
|
977 |
if (!page) |
|
978 |
return 0; |
|
979 |
return page->chrome(); |
|
980 |
} |
|
981 |
||
982 |
const unsigned cRepaintRectUnionThreshold = 25; |
|
983 |
||
984 |
void FrameView::repaintContentRectangle(const IntRect& r, bool immediate) |
|
985 |
{ |
|
986 |
ASSERT(!m_frame->document()->ownerElement()); |
|
987 |
||
988 |
double delay = adjustedDeferredRepaintDelay(); |
|
989 |
if ((m_deferringRepaints || m_deferredRepaintTimer.isActive() || delay) && !immediate) { |
|
990 |
IntRect visibleContent = visibleContentRect(); |
|
991 |
visibleContent.intersect(r); |
|
992 |
if (visibleContent.isEmpty()) |
|
993 |
return; |
|
994 |
if (m_repaintCount == cRepaintRectUnionThreshold) { |
|
995 |
IntRect unionedRect; |
|
996 |
for (unsigned i = 0; i < cRepaintRectUnionThreshold; ++i) |
|
997 |
unionedRect.unite(m_repaintRects[i]); |
|
998 |
m_repaintRects.clear(); |
|
999 |
m_repaintRects.append(unionedRect); |
|
1000 |
} |
|
1001 |
if (m_repaintCount < cRepaintRectUnionThreshold) |
|
1002 |
m_repaintRects.append(visibleContent); |
|
1003 |
else |
|
1004 |
m_repaintRects[0].unite(visibleContent); |
|
1005 |
m_repaintCount++; |
|
1006 |
||
1007 |
if (!m_deferringRepaints && !m_deferredRepaintTimer.isActive()) |
|
1008 |
m_deferredRepaintTimer.startOneShot(delay); |
|
1009 |
return; |
|
1010 |
} |
|
1011 |
||
1012 |
if (!immediate && isOffscreen() && !shouldUpdateWhileOffscreen()) |
|
1013 |
return; |
|
1014 |
||
1015 |
ScrollView::repaintContentRectangle(r, immediate); |
|
1016 |
} |
|
1017 |
||
1018 |
void FrameView::visibleContentsResized() |
|
1019 |
{ |
|
1020 |
// We check to make sure the view is attached to a frame() as this method can |
|
1021 |
// be triggered before the view is attached by Frame::createView(...) setting |
|
1022 |
// various values such as setScrollBarModes(...) for example. An ASSERT is |
|
1023 |
// triggered when a view is layout before being attached to a frame(). |
|
1024 |
if (!frame()->view()) |
|
1025 |
return; |
|
1026 |
||
1027 |
if (needsLayout()) |
|
1028 |
layout(); |
|
1029 |
} |
|
1030 |
||
1031 |
void FrameView::beginDeferredRepaints() |
|
1032 |
{ |
|
1033 |
Page* page = m_frame->page(); |
|
1034 |
if (page->mainFrame() != m_frame) |
|
1035 |
return page->mainFrame()->view()->beginDeferredRepaints(); |
|
1036 |
||
1037 |
m_deferringRepaints++; |
|
1038 |
} |
|
1039 |
||
1040 |
||
1041 |
void FrameView::endDeferredRepaints() |
|
1042 |
{ |
|
1043 |
Page* page = m_frame->page(); |
|
1044 |
if (page->mainFrame() != m_frame) |
|
1045 |
return page->mainFrame()->view()->endDeferredRepaints(); |
|
1046 |
||
1047 |
ASSERT(m_deferringRepaints > 0); |
|
1048 |
||
1049 |
if (--m_deferringRepaints) |
|
1050 |
return; |
|
1051 |
||
1052 |
if (m_deferredRepaintTimer.isActive()) |
|
1053 |
return; |
|
1054 |
||
1055 |
if (double delay = adjustedDeferredRepaintDelay()) { |
|
1056 |
m_deferredRepaintTimer.startOneShot(delay); |
|
1057 |
return; |
|
1058 |
} |
|
1059 |
||
1060 |
doDeferredRepaints(); |
|
1061 |
} |
|
1062 |
||
1063 |
void FrameView::checkStopDelayingDeferredRepaints() |
|
1064 |
{ |
|
1065 |
if (!m_deferredRepaintTimer.isActive()) |
|
1066 |
return; |
|
1067 |
||
1068 |
Document* document = m_frame->document(); |
|
1069 |
if (document && (document->parsing() || document->docLoader()->requestCount())) |
|
1070 |
return; |
|
1071 |
||
1072 |
m_deferredRepaintTimer.stop(); |
|
1073 |
||
1074 |
doDeferredRepaints(); |
|
1075 |
} |
|
1076 |
||
1077 |
void FrameView::doDeferredRepaints() |
|
1078 |
{ |
|
1079 |
ASSERT(!m_deferringRepaints); |
|
1080 |
if (isOffscreen() && !shouldUpdateWhileOffscreen()) { |
|
1081 |
m_repaintRects.clear(); |
|
1082 |
m_repaintCount = 0; |
|
1083 |
return; |
|
1084 |
} |
|
1085 |
unsigned size = m_repaintRects.size(); |
|
1086 |
for (unsigned i = 0; i < size; i++) |
|
1087 |
ScrollView::repaintContentRectangle(m_repaintRects[i], false); |
|
1088 |
m_repaintRects.clear(); |
|
1089 |
m_repaintCount = 0; |
|
1090 |
||
1091 |
updateDeferredRepaintDelay(); |
|
1092 |
} |
|
1093 |
||
1094 |
void FrameView::updateDeferredRepaintDelay() |
|
1095 |
{ |
|
1096 |
Document* document = m_frame->document(); |
|
1097 |
if (!document || (!document->parsing() && !document->docLoader()->requestCount())) { |
|
1098 |
m_deferredRepaintDelay = deferredRepaintDelay; |
|
1099 |
return; |
|
1100 |
} |
|
1101 |
if (m_deferredRepaintDelay < maxDeferredRepaintDelayDuringLoading) { |
|
1102 |
m_deferredRepaintDelay += deferredRepaintDelayIncrementDuringLoading; |
|
1103 |
if (m_deferredRepaintDelay > maxDeferredRepaintDelayDuringLoading) |
|
1104 |
m_deferredRepaintDelay = maxDeferredRepaintDelayDuringLoading; |
|
1105 |
} |
|
1106 |
} |
|
1107 |
||
1108 |
void FrameView::resetDeferredRepaintDelay() |
|
1109 |
{ |
|
1110 |
m_deferredRepaintDelay = 0; |
|
1111 |
if (m_deferredRepaintTimer.isActive()) { |
|
1112 |
m_deferredRepaintTimer.stop(); |
|
1113 |
if (!m_deferringRepaints) |
|
1114 |
doDeferredRepaints(); |
|
1115 |
} |
|
1116 |
} |
|
1117 |
||
1118 |
double FrameView::adjustedDeferredRepaintDelay() const |
|
1119 |
{ |
|
1120 |
if (!m_deferredRepaintDelay) |
|
1121 |
return 0; |
|
1122 |
double timeSinceLastPaint = currentTime() - m_lastPaintTime; |
|
1123 |
return max(0., m_deferredRepaintDelay - timeSinceLastPaint); |
|
1124 |
} |
|
1125 |
||
1126 |
void FrameView::deferredRepaintTimerFired(Timer<FrameView>*) |
|
1127 |
{ |
|
1128 |
doDeferredRepaints(); |
|
1129 |
} |
|
1130 |
||
1131 |
void FrameView::layoutTimerFired(Timer<FrameView>*) |
|
1132 |
{ |
|
1133 |
#ifdef INSTRUMENT_LAYOUT_SCHEDULING |
|
1134 |
if (!m_frame->document()->ownerElement()) |
|
1135 |
printf("Layout timer fired at %d\n", m_frame->document()->elapsedTime()); |
|
1136 |
#endif |
|
1137 |
layout(); |
|
1138 |
} |
|
1139 |
||
1140 |
void FrameView::scheduleRelayout() |
|
1141 |
{ |
|
1142 |
// FIXME: We should assert the page is not in the page cache, but that is causing |
|
1143 |
// too many false assertions. See <rdar://problem/7218118>. |
|
1144 |
ASSERT(m_frame->view() == this); |
|
1145 |
||
1146 |
if (m_layoutRoot) { |
|
1147 |
m_layoutRoot->markContainingBlocksForLayout(false); |
|
1148 |
m_layoutRoot = 0; |
|
1149 |
} |
|
1150 |
if (!m_layoutSchedulingEnabled) |
|
1151 |
return; |
|
1152 |
if (!needsLayout()) |
|
1153 |
return; |
|
1154 |
if (!m_frame->document()->shouldScheduleLayout()) |
|
1155 |
return; |
|
1156 |
||
1157 |
int delay = m_frame->document()->minimumLayoutDelay(); |
|
1158 |
if (m_layoutTimer.isActive() && m_delayedLayout && !delay) |
|
1159 |
unscheduleRelayout(); |
|
1160 |
if (m_layoutTimer.isActive()) |
|
1161 |
return; |
|
1162 |
||
1163 |
m_delayedLayout = delay != 0; |
|
1164 |
||
1165 |
#ifdef INSTRUMENT_LAYOUT_SCHEDULING |
|
1166 |
if (!m_frame->document()->ownerElement()) |
|
1167 |
printf("Scheduling layout for %d\n", delay); |
|
1168 |
#endif |
|
1169 |
||
1170 |
m_layoutTimer.startOneShot(delay * 0.001); |
|
1171 |
} |
|
1172 |
||
1173 |
static bool isObjectAncestorContainerOf(RenderObject* ancestor, RenderObject* descendant) |
|
1174 |
{ |
|
1175 |
for (RenderObject* r = descendant; r; r = r->container()) { |
|
1176 |
if (r == ancestor) |
|
1177 |
return true; |
|
1178 |
} |
|
1179 |
return false; |
|
1180 |
} |
|
1181 |
||
1182 |
void FrameView::scheduleRelayoutOfSubtree(RenderObject* relayoutRoot) |
|
1183 |
{ |
|
1184 |
ASSERT(m_frame->view() == this); |
|
1185 |
||
1186 |
if (!m_layoutSchedulingEnabled || (m_frame->contentRenderer() |
|
1187 |
&& m_frame->contentRenderer()->needsLayout())) { |
|
1188 |
if (relayoutRoot) |
|
1189 |
relayoutRoot->markContainingBlocksForLayout(false); |
|
1190 |
return; |
|
1191 |
} |
|
1192 |
||
1193 |
if (layoutPending()) { |
|
1194 |
if (m_layoutRoot != relayoutRoot) { |
|
1195 |
if (isObjectAncestorContainerOf(m_layoutRoot, relayoutRoot)) { |
|
1196 |
// Keep the current root |
|
1197 |
relayoutRoot->markContainingBlocksForLayout(false, m_layoutRoot); |
|
1198 |
} else if (m_layoutRoot && isObjectAncestorContainerOf(relayoutRoot, m_layoutRoot)) { |
|
1199 |
// Re-root at relayoutRoot |
|
1200 |
m_layoutRoot->markContainingBlocksForLayout(false, relayoutRoot); |
|
1201 |
m_layoutRoot = relayoutRoot; |
|
1202 |
} else { |
|
1203 |
// Just do a full relayout |
|
1204 |
if (m_layoutRoot) |
|
1205 |
m_layoutRoot->markContainingBlocksForLayout(false); |
|
1206 |
m_layoutRoot = 0; |
|
1207 |
relayoutRoot->markContainingBlocksForLayout(false); |
|
1208 |
} |
|
1209 |
} |
|
1210 |
} else { |
|
1211 |
int delay = m_frame->document()->minimumLayoutDelay(); |
|
1212 |
m_layoutRoot = relayoutRoot; |
|
1213 |
m_delayedLayout = delay != 0; |
|
1214 |
m_layoutTimer.startOneShot(delay * 0.001); |
|
1215 |
} |
|
1216 |
} |
|
1217 |
||
1218 |
bool FrameView::layoutPending() const |
|
1219 |
{ |
|
1220 |
return m_layoutTimer.isActive(); |
|
1221 |
} |
|
1222 |
||
1223 |
bool FrameView::needsLayout() const |
|
1224 |
{ |
|
1225 |
// This can return true in cases where the document does not have a body yet. |
|
1226 |
// Document::shouldScheduleLayout takes care of preventing us from scheduling |
|
1227 |
// layout in that case. |
|
1228 |
if (!m_frame) |
|
1229 |
return false; |
|
1230 |
RenderView* root = m_frame->contentRenderer(); |
|
1231 |
Document* document = m_frame->document(); |
|
1232 |
return layoutPending() |
|
1233 |
|| (root && root->needsLayout()) |
|
1234 |
|| m_layoutRoot |
|
1235 |
|| (document && document->childNeedsStyleRecalc()) // can occur when using WebKit ObjC interface |
|
1236 |
|| m_frame->needsReapplyStyles() |
|
1237 |
|| (m_deferSetNeedsLayouts && m_setNeedsLayoutWasDeferred); |
|
1238 |
} |
|
1239 |
||
1240 |
void FrameView::setNeedsLayout() |
|
1241 |
{ |
|
1242 |
if (m_deferSetNeedsLayouts) { |
|
1243 |
m_setNeedsLayoutWasDeferred = true; |
|
1244 |
return; |
|
1245 |
} |
|
1246 |
RenderView* root = m_frame->contentRenderer(); |
|
1247 |
if (root) |
|
1248 |
root->setNeedsLayout(true); |
|
1249 |
} |
|
1250 |
||
1251 |
void FrameView::unscheduleRelayout() |
|
1252 |
{ |
|
1253 |
if (!m_layoutTimer.isActive()) |
|
1254 |
return; |
|
1255 |
||
1256 |
#ifdef INSTRUMENT_LAYOUT_SCHEDULING |
|
1257 |
if (!m_frame->document()->ownerElement()) |
|
1258 |
printf("Layout timer unscheduled at %d\n", m_frame->document()->elapsedTime()); |
|
1259 |
#endif |
|
1260 |
||
1261 |
m_layoutTimer.stop(); |
|
1262 |
m_delayedLayout = false; |
|
1263 |
} |
|
1264 |
||
1265 |
bool FrameView::isTransparent() const |
|
1266 |
{ |
|
1267 |
return m_isTransparent; |
|
1268 |
} |
|
1269 |
||
1270 |
void FrameView::setTransparent(bool isTransparent) |
|
1271 |
{ |
|
1272 |
m_isTransparent = isTransparent; |
|
1273 |
} |
|
1274 |
||
1275 |
Color FrameView::baseBackgroundColor() const |
|
1276 |
{ |
|
1277 |
return m_baseBackgroundColor; |
|
1278 |
} |
|
1279 |
||
1280 |
void FrameView::setBaseBackgroundColor(Color bc) |
|
1281 |
{ |
|
1282 |
if (!bc.isValid()) |
|
1283 |
bc = Color::white; |
|
1284 |
m_baseBackgroundColor = bc; |
|
1285 |
} |
|
1286 |
||
1287 |
void FrameView::updateBackgroundRecursively(const Color& backgroundColor, bool transparent) |
|
1288 |
{ |
|
1289 |
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext(m_frame.get())) { |
|
1290 |
FrameView* view = frame->view(); |
|
1291 |
if (!view) |
|
1292 |
continue; |
|
1293 |
||
1294 |
view->setTransparent(transparent); |
|
1295 |
view->setBaseBackgroundColor(backgroundColor); |
|
1296 |
} |
|
1297 |
} |
|
1298 |
||
1299 |
bool FrameView::shouldUpdateWhileOffscreen() const |
|
1300 |
{ |
|
1301 |
return m_shouldUpdateWhileOffscreen; |
|
1302 |
} |
|
1303 |
||
1304 |
void FrameView::setShouldUpdateWhileOffscreen(bool shouldUpdateWhileOffscreen) |
|
1305 |
{ |
|
1306 |
m_shouldUpdateWhileOffscreen = shouldUpdateWhileOffscreen; |
|
1307 |
} |
|
1308 |
||
1309 |
void FrameView::scheduleEvent(PassRefPtr<Event> event, PassRefPtr<Node> eventTarget) |
|
1310 |
{ |
|
1311 |
if (!m_enqueueEvents) { |
|
1312 |
ExceptionCode ec = 0; |
|
1313 |
eventTarget->dispatchEvent(event, ec); |
|
1314 |
return; |
|
1315 |
} |
|
1316 |
||
1317 |
ScheduledEvent* scheduledEvent = new ScheduledEvent; |
|
1318 |
scheduledEvent->m_event = event; |
|
1319 |
scheduledEvent->m_eventTarget = eventTarget; |
|
1320 |
m_scheduledEvents.append(scheduledEvent); |
|
1321 |
} |
|
1322 |
||
1323 |
void FrameView::pauseScheduledEvents() |
|
1324 |
{ |
|
1325 |
ASSERT(m_scheduledEvents.isEmpty() || m_enqueueEvents); |
|
1326 |
m_enqueueEvents++; |
|
1327 |
} |
|
1328 |
||
1329 |
void FrameView::resumeScheduledEvents() |
|
1330 |
{ |
|
1331 |
m_enqueueEvents--; |
|
1332 |
if (!m_enqueueEvents) |
|
1333 |
dispatchScheduledEvents(); |
|
1334 |
ASSERT(m_scheduledEvents.isEmpty() || m_enqueueEvents); |
|
1335 |
} |
|
1336 |
||
1337 |
void FrameView::scrollToAnchor() |
|
1338 |
{ |
|
1339 |
RefPtr<Node> anchorNode = m_maintainScrollPositionAnchor; |
|
1340 |
if (!anchorNode) |
|
1341 |
return; |
|
1342 |
||
1343 |
if (!anchorNode->renderer()) |
|
1344 |
return; |
|
1345 |
||
1346 |
IntRect rect; |
|
1347 |
if (anchorNode != m_frame->document()) |
|
1348 |
rect = anchorNode->getRect(); |
|
1349 |
||
1350 |
// Scroll nested layers and frames to reveal the anchor. |
|
1351 |
// Align to the top and to the closest side (this matches other browsers). |
|
1352 |
anchorNode->renderer()->enclosingLayer()->scrollRectToVisible(rect, true, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways); |
|
1353 |
||
1354 |
if (AXObjectCache::accessibilityEnabled()) |
|
1355 |
m_frame->document()->axObjectCache()->handleScrolledToAnchor(anchorNode.get()); |
|
1356 |
||
1357 |
// scrollRectToVisible can call into scrollRectIntoViewRecursively(), which resets m_maintainScrollPositionAnchor. |
|
1358 |
m_maintainScrollPositionAnchor = anchorNode; |
|
1359 |
} |
|
1360 |
||
1361 |
bool FrameView::updateWidgets() |
|
1362 |
{ |
|
1363 |
if (m_nestedLayoutCount > 1 || !m_widgetUpdateSet || m_widgetUpdateSet->isEmpty()) |
|
1364 |
return true; |
|
1365 |
||
1366 |
Vector<RenderPartObject*> objectVector; |
|
1367 |
copyToVector(*m_widgetUpdateSet, objectVector); |
|
1368 |
size_t size = objectVector.size(); |
|
1369 |
for (size_t i = 0; i < size; ++i) { |
|
1370 |
RenderPartObject* object = objectVector[i]; |
|
1371 |
object->updateWidget(false); |
|
1372 |
||
1373 |
// updateWidget() can destroy the RenderPartObject, so we need to make sure it's |
|
1374 |
// alive by checking if it's still in m_widgetUpdateSet. |
|
1375 |
if (m_widgetUpdateSet->contains(object)) { |
|
1376 |
object->updateWidgetPosition(); |
|
1377 |
m_widgetUpdateSet->remove(object); |
|
1378 |
} |
|
1379 |
} |
|
1380 |
||
1381 |
return m_widgetUpdateSet->isEmpty(); |
|
1382 |
} |
|
1383 |
||
1384 |
void FrameView::performPostLayoutTasks() |
|
1385 |
{ |
|
1386 |
if (m_firstLayoutCallbackPending) { |
|
1387 |
m_firstLayoutCallbackPending = false; |
|
1388 |
m_frame->loader()->didFirstLayout(); |
|
1389 |
} |
|
1390 |
||
1391 |
if (m_isVisuallyNonEmpty && m_firstVisuallyNonEmptyLayoutCallbackPending) { |
|
1392 |
m_firstVisuallyNonEmptyLayoutCallbackPending = false; |
|
1393 |
m_frame->loader()->didFirstVisuallyNonEmptyLayout(); |
|
1394 |
} |
|
1395 |
||
1396 |
RenderView* root = m_frame->contentRenderer(); |
|
1397 |
||
1398 |
root->updateWidgetPositions(); |
|
1399 |
||
1400 |
for (unsigned i = 0; i < maxUpdateWidgetsIterations; i++) { |
|
1401 |
if (updateWidgets()) |
|
1402 |
break; |
|
1403 |
} |
|
1404 |
||
1405 |
scrollToAnchor(); |
|
1406 |
||
1407 |
resumeScheduledEvents(); |
|
1408 |
||
1409 |
if (!root->printing()) { |
|
1410 |
IntSize currentSize = IntSize(width(), height()); |
|
1411 |
float currentZoomFactor = root->style()->zoom(); |
|
1412 |
bool resized = !m_firstLayout && (currentSize != m_lastLayoutSize || currentZoomFactor != m_lastZoomFactor); |
|
1413 |
m_lastLayoutSize = currentSize; |
|
1414 |
m_lastZoomFactor = currentZoomFactor; |
|
1415 |
if (resized) |
|
1416 |
m_frame->eventHandler()->sendResizeEvent(); |
|
1417 |
} |
|
1418 |
} |
|
1419 |
||
1420 |
void FrameView::postLayoutTimerFired(Timer<FrameView>*) |
|
1421 |
{ |
|
1422 |
performPostLayoutTasks(); |
|
1423 |
} |
|
1424 |
||
1425 |
void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow) |
|
1426 |
{ |
|
1427 |
if (!m_viewportRenderer) |
|
1428 |
return; |
|
1429 |
||
1430 |
if (m_overflowStatusDirty) { |
|
1431 |
m_horizontalOverflow = horizontalOverflow; |
|
1432 |
m_verticalOverflow = verticalOverflow; |
|
1433 |
m_overflowStatusDirty = false; |
|
1434 |
return; |
|
1435 |
} |
|
1436 |
||
1437 |
bool horizontalOverflowChanged = (m_horizontalOverflow != horizontalOverflow); |
|
1438 |
bool verticalOverflowChanged = (m_verticalOverflow != verticalOverflow); |
|
1439 |
||
1440 |
if (horizontalOverflowChanged || verticalOverflowChanged) { |
|
1441 |
m_horizontalOverflow = horizontalOverflow; |
|
1442 |
m_verticalOverflow = verticalOverflow; |
|
1443 |
||
1444 |
scheduleEvent(OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow, |
|
1445 |
verticalOverflowChanged, verticalOverflow), |
|
1446 |
m_viewportRenderer->node()); |
|
1447 |
} |
|
1448 |
||
1449 |
} |
|
1450 |
||
1451 |
void FrameView::dispatchScheduledEvents() |
|
1452 |
{ |
|
1453 |
if (m_scheduledEvents.isEmpty()) |
|
1454 |
return; |
|
1455 |
||
1456 |
Vector<ScheduledEvent*> scheduledEventsCopy = m_scheduledEvents; |
|
1457 |
m_scheduledEvents.clear(); |
|
1458 |
||
1459 |
Vector<ScheduledEvent*>::iterator end = scheduledEventsCopy.end(); |
|
1460 |
for (Vector<ScheduledEvent*>::iterator it = scheduledEventsCopy.begin(); it != end; ++it) { |
|
1461 |
ScheduledEvent* scheduledEvent = *it; |
|
1462 |
||
1463 |
ExceptionCode ec = 0; |
|
1464 |
||
1465 |
// Only dispatch events to nodes that are in the document |
|
1466 |
if (scheduledEvent->m_eventTarget->inDocument()) |
|
1467 |
scheduledEvent->m_eventTarget->dispatchEvent(scheduledEvent->m_event, ec); |
|
1468 |
||
1469 |
delete scheduledEvent; |
|
1470 |
} |
|
1471 |
} |
|
1472 |
||
1473 |
IntRect FrameView::windowClipRect(bool clipToContents) const |
|
1474 |
{ |
|
1475 |
ASSERT(m_frame->view() == this); |
|
1476 |
||
1477 |
// Set our clip rect to be our contents. |
|
1478 |
IntRect clipRect = contentsToWindow(visibleContentRect(!clipToContents)); |
|
1479 |
if (!m_frame || !m_frame->document()->ownerElement()) |
|
1480 |
return clipRect; |
|
1481 |
||
1482 |
// Take our owner element and get the clip rect from the enclosing layer. |
|
1483 |
Element* elt = m_frame->document()->ownerElement(); |
|
1484 |
RenderLayer* layer = elt->renderer()->enclosingLayer(); |
|
1485 |
// FIXME: layer should never be null, but sometimes seems to be anyway. |
|
1486 |
if (!layer) |
|
1487 |
return clipRect; |
|
1488 |
FrameView* parentView = elt->document()->view(); |
|
1489 |
clipRect.intersect(parentView->windowClipRectForLayer(layer, true)); |
|
1490 |
return clipRect; |
|
1491 |
} |
|
1492 |
||
1493 |
IntRect FrameView::windowClipRectForLayer(const RenderLayer* layer, bool clipToLayerContents) const |
|
1494 |
{ |
|
1495 |
// If we have no layer, just return our window clip rect. |
|
1496 |
if (!layer) |
|
1497 |
return windowClipRect(); |
|
1498 |
||
1499 |
// Apply the clip from the layer. |
|
1500 |
IntRect clipRect; |
|
1501 |
if (clipToLayerContents) |
|
1502 |
clipRect = layer->childrenClipRect(); |
|
1503 |
else |
|
1504 |
clipRect = layer->selfClipRect(); |
|
1505 |
clipRect = contentsToWindow(clipRect); |
|
1506 |
return intersection(clipRect, windowClipRect()); |
|
1507 |
} |
|
1508 |
||
1509 |
bool FrameView::isActive() const |
|
1510 |
{ |
|
1511 |
Page* page = frame()->page(); |
|
1512 |
return page && page->focusController()->isActive(); |
|
1513 |
} |
|
1514 |
||
1515 |
void FrameView::valueChanged(Scrollbar* bar) |
|
1516 |
{ |
|
1517 |
// Figure out if we really moved. |
|
1518 |
IntSize offset = scrollOffset(); |
|
1519 |
ScrollView::valueChanged(bar); |
|
1520 |
if (offset != scrollOffset()) |
|
1521 |
frame()->eventHandler()->sendScrollEvent(); |
|
1522 |
} |
|
1523 |
||
1524 |
void FrameView::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect) |
|
1525 |
{ |
|
1526 |
// Add in our offset within the FrameView. |
|
1527 |
IntRect dirtyRect = rect; |
|
1528 |
dirtyRect.move(scrollbar->x(), scrollbar->y()); |
|
1529 |
invalidateRect(dirtyRect); |
|
1530 |
} |
|
1531 |
||
1532 |
void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const |
|
1533 |
{ |
|
1534 |
tickmarks = frame()->document()->renderedRectsForMarkers(DocumentMarker::TextMatch); |
|
1535 |
} |
|
1536 |
||
1537 |
IntRect FrameView::windowResizerRect() const |
|
1538 |
{ |
|
1539 |
Page* page = frame() ? frame()->page() : 0; |
|
1540 |
if (!page) |
|
1541 |
return IntRect(); |
|
1542 |
return page->chrome()->windowResizerRect(); |
|
1543 |
} |
|
1544 |
||
1545 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
1546 |
void FrameView::updateDashboardRegions() |
|
1547 |
{ |
|
1548 |
Document* document = m_frame->document(); |
|
1549 |
if (!document->hasDashboardRegions()) |
|
1550 |
return; |
|
1551 |
Vector<DashboardRegionValue> newRegions; |
|
1552 |
document->renderBox()->collectDashboardRegions(newRegions); |
|
1553 |
if (newRegions == document->dashboardRegions()) |
|
1554 |
return; |
|
1555 |
document->setDashboardRegions(newRegions); |
|
1556 |
Page* page = m_frame->page(); |
|
1557 |
if (!page) |
|
1558 |
return; |
|
1559 |
page->chrome()->client()->dashboardRegionsChanged(); |
|
1560 |
} |
|
1561 |
#endif |
|
1562 |
||
1563 |
void FrameView::invalidateScrollCorner() |
|
1564 |
{ |
|
1565 |
invalidateRect(scrollCornerRect()); |
|
1566 |
} |
|
1567 |
||
1568 |
void FrameView::updateScrollCorner() |
|
1569 |
{ |
|
1570 |
RenderObject* renderer = 0; |
|
1571 |
RefPtr<RenderStyle> cornerStyle; |
|
1572 |
||
1573 |
if (!scrollCornerRect().isEmpty()) { |
|
1574 |
// Try the <body> element first as a scroll corner source. |
|
1575 |
Document* doc = m_frame->document(); |
|
1576 |
Element* body = doc ? doc->body() : 0; |
|
1577 |
if (body && body->renderer()) { |
|
1578 |
renderer = body->renderer(); |
|
1579 |
cornerStyle = renderer->getUncachedPseudoStyle(SCROLLBAR_CORNER, renderer->style()); |
|
1580 |
} |
|
1581 |
||
1582 |
if (!cornerStyle) { |
|
1583 |
// If the <body> didn't have a custom style, then the root element might. |
|
1584 |
Element* docElement = doc ? doc->documentElement() : 0; |
|
1585 |
if (docElement && docElement->renderer()) { |
|
1586 |
renderer = docElement->renderer(); |
|
1587 |
cornerStyle = renderer->getUncachedPseudoStyle(SCROLLBAR_CORNER, renderer->style()); |
|
1588 |
} |
|
1589 |
} |
|
1590 |
||
1591 |
if (!cornerStyle) { |
|
1592 |
// If we have an owning iframe/frame element, then it can set the custom scrollbar also. |
|
1593 |
if (RenderPart* renderer = m_frame->ownerRenderer()) |
|
1594 |
cornerStyle = renderer->getUncachedPseudoStyle(SCROLLBAR_CORNER, renderer->style()); |
|
1595 |
} |
|
1596 |
} |
|
1597 |
||
1598 |
if (cornerStyle) { |
|
1599 |
if (!m_scrollCorner) |
|
1600 |
m_scrollCorner = new (renderer->renderArena()) RenderScrollbarPart(renderer->document()); |
|
1601 |
m_scrollCorner->setStyle(cornerStyle.release()); |
|
1602 |
invalidateRect(scrollCornerRect()); |
|
1603 |
} else if (m_scrollCorner) { |
|
1604 |
m_scrollCorner->destroy(); |
|
1605 |
m_scrollCorner = 0; |
|
1606 |
} |
|
1607 |
} |
|
1608 |
||
1609 |
void FrameView::paintScrollCorner(GraphicsContext* context, const IntRect& cornerRect) |
|
1610 |
{ |
|
1611 |
if (context->updatingControlTints()) { |
|
1612 |
updateScrollCorner(); |
|
1613 |
return; |
|
1614 |
} |
|
1615 |
||
1616 |
if (m_scrollCorner) { |
|
1617 |
m_scrollCorner->paintIntoRect(context, cornerRect.x(), cornerRect.y(), cornerRect); |
|
1618 |
return; |
|
1619 |
} |
|
1620 |
||
1621 |
ScrollView::paintScrollCorner(context, cornerRect); |
|
1622 |
} |
|
1623 |
||
1624 |
bool FrameView::hasCustomScrollbars() const |
|
1625 |
{ |
|
1626 |
const HashSet<RefPtr<Widget> >* viewChildren = children(); |
|
1627 |
HashSet<RefPtr<Widget> >::const_iterator end = viewChildren->end(); |
|
1628 |
for (HashSet<RefPtr<Widget> >::const_iterator current = viewChildren->begin(); current != end; ++current) { |
|
1629 |
Widget* widget = current->get(); |
|
1630 |
if (widget->isFrameView()) { |
|
1631 |
if (static_cast<FrameView*>(widget)->hasCustomScrollbars()) |
|
1632 |
return true; |
|
1633 |
} else if (widget->isScrollbar()) { |
|
1634 |
Scrollbar* scrollbar = static_cast<Scrollbar*>(widget); |
|
1635 |
if (scrollbar->isCustomScrollbar()) |
|
1636 |
return true; |
|
1637 |
} |
|
1638 |
} |
|
1639 |
||
1640 |
return false; |
|
1641 |
} |
|
1642 |
||
1643 |
void FrameView::updateControlTints() |
|
1644 |
{ |
|
1645 |
// This is called when control tints are changed from aqua/graphite to clear and vice versa. |
|
1646 |
// We do a "fake" paint, and when the theme gets a paint call, it can then do an invalidate. |
|
1647 |
// This is only done if the theme supports control tinting. It's up to the theme and platform |
|
1648 |
// to define when controls get the tint and to call this function when that changes. |
|
1649 |
||
1650 |
// Optimize the common case where we bring a window to the front while it's still empty. |
|
1651 |
if (!m_frame || m_frame->loader()->url().isEmpty()) |
|
1652 |
return; |
|
1653 |
||
1654 |
if ((m_frame->contentRenderer() && m_frame->contentRenderer()->theme()->supportsControlTints()) || hasCustomScrollbars()) { |
|
1655 |
if (needsLayout()) |
|
1656 |
layout(); |
|
1657 |
PlatformGraphicsContext* const noContext = 0; |
|
1658 |
GraphicsContext context(noContext); |
|
1659 |
context.setUpdatingControlTints(true); |
|
1660 |
if (platformWidget()) |
|
1661 |
paintContents(&context, visibleContentRect()); |
|
1662 |
else |
|
1663 |
paint(&context, frameRect()); |
|
1664 |
} |
|
1665 |
} |
|
1666 |
||
1667 |
bool FrameView::wasScrolledByUser() const |
|
1668 |
{ |
|
1669 |
return m_wasScrolledByUser; |
|
1670 |
} |
|
1671 |
||
1672 |
void FrameView::setWasScrolledByUser(bool wasScrolledByUser) |
|
1673 |
{ |
|
1674 |
if (m_inProgrammaticScroll) |
|
1675 |
return; |
|
1676 |
m_maintainScrollPositionAnchor = 0; |
|
1677 |
m_wasScrolledByUser = wasScrolledByUser; |
|
1678 |
} |
|
1679 |
||
1680 |
void FrameView::paintContents(GraphicsContext* p, const IntRect& rect) |
|
1681 |
{ |
|
1682 |
if (!frame()) |
|
1683 |
return; |
|
1684 |
||
1685 |
#if ENABLE(INSPECTOR) |
|
1686 |
InspectorTimelineAgent* timelineAgent = inspectorTimelineAgent(); |
|
1687 |
if (timelineAgent) |
|
1688 |
timelineAgent->willPaint(); |
|
1689 |
#endif |
|
1690 |
||
1691 |
Document* document = frame()->document(); |
|
1692 |
||
1693 |
#ifndef NDEBUG |
|
1694 |
bool fillWithRed; |
|
1695 |
if (document->printing()) |
|
1696 |
fillWithRed = false; // Printing, don't fill with red (can't remember why). |
|
1697 |
else if (document->ownerElement()) |
|
1698 |
fillWithRed = false; // Subframe, don't fill with red. |
|
1699 |
else if (isTransparent()) |
|
1700 |
fillWithRed = false; // Transparent, don't fill with red. |
|
1701 |
else if (m_paintRestriction == PaintRestrictionSelectionOnly || m_paintRestriction == PaintRestrictionSelectionOnlyBlackText) |
|
1702 |
fillWithRed = false; // Selections are transparent, don't fill with red. |
|
1703 |
else if (m_nodeToDraw) |
|
1704 |
fillWithRed = false; // Element images are transparent, don't fill with red. |
|
1705 |
else |
|
1706 |
fillWithRed = true; |
|
1707 |
||
1708 |
if (fillWithRed) |
|
1709 |
p->fillRect(rect, Color(0xFF, 0, 0)); |
|
1710 |
#endif |
|
1711 |
||
1712 |
bool isTopLevelPainter = !sCurrentPaintTimeStamp; |
|
1713 |
if (isTopLevelPainter) |
|
1714 |
sCurrentPaintTimeStamp = currentTime(); |
|
1715 |
||
1716 |
RenderView* contentRenderer = frame()->contentRenderer(); |
|
1717 |
if (!contentRenderer) { |
|
1718 |
LOG_ERROR("called Frame::paint with nil renderer"); |
|
1719 |
return; |
|
1720 |
} |
|
1721 |
||
1722 |
ASSERT(!needsLayout()); |
|
1723 |
if (needsLayout()) |
|
1724 |
return; |
|
1725 |
||
1726 |
#if USE(ACCELERATED_COMPOSITING) |
|
1727 |
if (!p->paintingDisabled()) { |
|
1728 |
if (GraphicsLayer* rootLayer = contentRenderer->compositor()->rootPlatformLayer()) |
|
1729 |
rootLayer->syncCompositingState(); |
|
1730 |
} |
|
1731 |
#endif |
|
1732 |
||
1733 |
ASSERT(!m_isPainting); |
|
1734 |
||
1735 |
m_isPainting = true; |
|
1736 |
||
1737 |
// m_nodeToDraw is used to draw only one element (and its descendants) |
|
1738 |
RenderObject* eltRenderer = m_nodeToDraw ? m_nodeToDraw->renderer() : 0; |
|
1739 |
if (m_paintRestriction == PaintRestrictionNone) |
|
1740 |
document->invalidateRenderedRectsForMarkersInRect(rect); |
|
1741 |
contentRenderer->layer()->paint(p, rect, m_paintRestriction, eltRenderer); |
|
1742 |
||
1743 |
m_isPainting = false; |
|
1744 |
m_lastPaintTime = currentTime(); |
|
1745 |
||
1746 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
1747 |
// Regions may have changed as a result of the visibility/z-index of element changing. |
|
1748 |
if (document->dashboardRegionsDirty()) |
|
1749 |
updateDashboardRegions(); |
|
1750 |
#endif |
|
1751 |
||
1752 |
if (isTopLevelPainter) |
|
1753 |
sCurrentPaintTimeStamp = 0; |
|
1754 |
||
1755 |
#if ENABLE(INSPECTOR) |
|
1756 |
if (timelineAgent) |
|
1757 |
timelineAgent->didPaint(); |
|
1758 |
#endif |
|
1759 |
} |
|
1760 |
||
1761 |
void FrameView::setPaintRestriction(PaintRestriction pr) |
|
1762 |
{ |
|
1763 |
m_paintRestriction = pr; |
|
1764 |
} |
|
1765 |
||
1766 |
bool FrameView::isPainting() const |
|
1767 |
{ |
|
1768 |
return m_isPainting; |
|
1769 |
} |
|
1770 |
||
1771 |
void FrameView::setNodeToDraw(Node* node) |
|
1772 |
{ |
|
1773 |
m_nodeToDraw = node; |
|
1774 |
} |
|
1775 |
||
1776 |
void FrameView::layoutIfNeededRecursive() |
|
1777 |
{ |
|
1778 |
// We have to crawl our entire tree looking for any FrameViews that need |
|
1779 |
// layout and make sure they are up to date. |
|
1780 |
// Mac actually tests for intersection with the dirty region and tries not to |
|
1781 |
// update layout for frames that are outside the dirty region. Not only does this seem |
|
1782 |
// pointless (since those frames will have set a zero timer to layout anyway), but |
|
1783 |
// it is also incorrect, since if two frames overlap, the first could be excluded from the dirty |
|
1784 |
// region but then become included later by the second frame adding rects to the dirty region |
|
1785 |
// when it lays out. |
|
1786 |
||
1787 |
if (needsLayout()) |
|
1788 |
layout(); |
|
1789 |
||
1790 |
const HashSet<RefPtr<Widget> >* viewChildren = children(); |
|
1791 |
HashSet<RefPtr<Widget> >::const_iterator end = viewChildren->end(); |
|
1792 |
for (HashSet<RefPtr<Widget> >::const_iterator current = viewChildren->begin(); current != end; ++current) { |
|
1793 |
Widget* widget = (*current).get(); |
|
1794 |
if (widget->isFrameView()) |
|
1795 |
static_cast<FrameView*>(widget)->layoutIfNeededRecursive(); |
|
1796 |
} |
|
1797 |
||
1798 |
// layoutIfNeededRecursive is called when we need to make sure layout is up-to-date before |
|
1799 |
// painting, so we need to flush out any deferred repaints too. |
|
1800 |
flushDeferredRepaints(); |
|
1801 |
} |
|
1802 |
||
1803 |
void FrameView::flushDeferredRepaints() |
|
1804 |
{ |
|
1805 |
if (!m_deferredRepaintTimer.isActive()) |
|
1806 |
return; |
|
1807 |
m_deferredRepaintTimer.stop(); |
|
1808 |
doDeferredRepaints(); |
|
1809 |
} |
|
1810 |
||
1811 |
void FrameView::forceLayout(bool allowSubtree) |
|
1812 |
{ |
|
1813 |
layout(allowSubtree); |
|
1814 |
// We cannot unschedule a pending relayout, since the force can be called with |
|
1815 |
// a tiny rectangle from a drawRect update. By unscheduling we in effect |
|
1816 |
// "validate" and stop the necessary full repaint from occurring. Basically any basic |
|
1817 |
// append/remove DHTML is broken by this call. For now, I have removed the optimization |
|
1818 |
// until we have a better invalidation stategy. -dwh |
|
1819 |
//unscheduleRelayout(); |
|
1820 |
} |
|
1821 |
||
1822 |
void FrameView::forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth, bool _adjustViewSize) |
|
1823 |
{ |
|
1824 |
// Dumping externalRepresentation(m_frame->renderer()).ascii() is a good trick to see |
|
1825 |
// the state of things before and after the layout |
|
1826 |
RenderView *root = toRenderView(m_frame->document()->renderer()); |
|
1827 |
if (root) { |
|
1828 |
// This magic is basically copied from khtmlview::print |
|
1829 |
int pageW = (int)ceilf(minPageWidth); |
|
1830 |
root->setWidth(pageW); |
|
1831 |
root->setNeedsLayoutAndPrefWidthsRecalc(); |
|
1832 |
forceLayout(); |
|
1833 |
||
1834 |
// If we don't fit in the minimum page width, we'll lay out again. If we don't fit in the |
|
1835 |
// maximum page width, we will lay out to the maximum page width and clip extra content. |
|
1836 |
// FIXME: We are assuming a shrink-to-fit printing implementation. A cropping |
|
1837 |
// implementation should not do this! |
|
1838 |
int rightmostPos = root->rightmostPosition(); |
|
1839 |
if (rightmostPos > minPageWidth) { |
|
1840 |
pageW = std::min(rightmostPos, (int)ceilf(maxPageWidth)); |
|
1841 |
root->setWidth(pageW); |
|
1842 |
root->setNeedsLayoutAndPrefWidthsRecalc(); |
|
1843 |
forceLayout(); |
|
1844 |
} |
|
1845 |
} |
|
1846 |
||
1847 |
if (_adjustViewSize) |
|
1848 |
adjustViewSize(); |
|
1849 |
} |
|
1850 |
||
1851 |
void FrameView::adjustPageHeight(float *newBottom, float oldTop, float oldBottom, float /*bottomLimit*/) |
|
1852 |
{ |
|
1853 |
RenderView* root = m_frame->contentRenderer(); |
|
1854 |
if (root) { |
|
1855 |
// Use a context with painting disabled. |
|
1856 |
GraphicsContext context((PlatformGraphicsContext*)0); |
|
1857 |
root->setTruncatedAt((int)floorf(oldBottom)); |
|
1858 |
IntRect dirtyRect(0, (int)floorf(oldTop), root->rightLayoutOverflow(), (int)ceilf(oldBottom - oldTop)); |
|
1859 |
root->layer()->paint(&context, dirtyRect); |
|
1860 |
*newBottom = root->bestTruncatedAt(); |
|
1861 |
if (*newBottom == 0) |
|
1862 |
*newBottom = oldBottom; |
|
1863 |
} else |
|
1864 |
*newBottom = oldBottom; |
|
1865 |
} |
|
1866 |
||
1867 |
IntRect FrameView::convertFromRenderer(const RenderObject* renderer, const IntRect& rendererRect) const |
|
1868 |
{ |
|
1869 |
IntRect rect = renderer->localToAbsoluteQuad(FloatRect(rendererRect)).enclosingBoundingBox(); |
|
1870 |
||
1871 |
// Convert from page ("absolute") to FrameView coordinates. |
|
1872 |
rect.move(-scrollX(), -scrollY()); |
|
1873 |
||
1874 |
return rect; |
|
1875 |
} |
|
1876 |
||
1877 |
IntRect FrameView::convertToRenderer(const RenderObject* renderer, const IntRect& viewRect) const |
|
1878 |
{ |
|
1879 |
IntRect rect = viewRect; |
|
1880 |
||
1881 |
// Convert from FrameView coords into page ("absolute") coordinates. |
|
1882 |
rect.move(scrollX(), scrollY()); |
|
1883 |
||
1884 |
// FIXME: we don't have a way to map an absolute rect down to a local quad, so just |
|
1885 |
// move the rect for now. |
|
1886 |
rect.setLocation(roundedIntPoint(renderer->absoluteToLocal(rect.location(), false, true /* use transforms */))); |
|
1887 |
return rect; |
|
1888 |
} |
|
1889 |
||
1890 |
IntPoint FrameView::convertFromRenderer(const RenderObject* renderer, const IntPoint& rendererPoint) const |
|
1891 |
{ |
|
1892 |
IntPoint point = roundedIntPoint(renderer->localToAbsolute(rendererPoint, false, true /* use transforms */)); |
|
1893 |
||
1894 |
// Convert from page ("absolute") to FrameView coordinates. |
|
1895 |
point.move(-scrollX(), -scrollY()); |
|
1896 |
return point; |
|
1897 |
} |
|
1898 |
||
1899 |
IntPoint FrameView::convertToRenderer(const RenderObject* renderer, const IntPoint& viewPoint) const |
|
1900 |
{ |
|
1901 |
IntPoint point = viewPoint; |
|
1902 |
||
1903 |
// Convert from FrameView coords into page ("absolute") coordinates. |
|
1904 |
point += IntSize(scrollX(), scrollY()); |
|
1905 |
||
1906 |
return roundedIntPoint(renderer->absoluteToLocal(point, false, true /* use transforms */)); |
|
1907 |
} |
|
1908 |
||
1909 |
IntRect FrameView::convertToContainingView(const IntRect& localRect) const |
|
1910 |
{ |
|
1911 |
if (const ScrollView* parentScrollView = parent()) { |
|
1912 |
if (parentScrollView->isFrameView()) { |
|
1913 |
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView); |
|
1914 |
// Get our renderer in the parent view |
|
1915 |
RenderPart* renderer = m_frame->ownerRenderer(); |
|
1916 |
if (!renderer) |
|
1917 |
return localRect; |
|
1918 |
||
1919 |
IntRect rect(localRect); |
|
1920 |
// Add borders and padding?? |
|
1921 |
rect.move(renderer->borderLeft() + renderer->paddingLeft(), |
|
1922 |
renderer->borderTop() + renderer->paddingTop()); |
|
1923 |
return parentView->convertFromRenderer(renderer, rect); |
|
1924 |
} |
|
1925 |
||
1926 |
return Widget::convertToContainingView(localRect); |
|
1927 |
} |
|
1928 |
||
1929 |
return localRect; |
|
1930 |
} |
|
1931 |
||
1932 |
IntRect FrameView::convertFromContainingView(const IntRect& parentRect) const |
|
1933 |
{ |
|
1934 |
if (const ScrollView* parentScrollView = parent()) { |
|
1935 |
if (parentScrollView->isFrameView()) { |
|
1936 |
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView); |
|
1937 |
||
1938 |
// Get our renderer in the parent view |
|
1939 |
RenderPart* renderer = m_frame->ownerRenderer(); |
|
1940 |
if (!renderer) |
|
1941 |
return parentRect; |
|
1942 |
||
1943 |
IntRect rect = parentView->convertToRenderer(renderer, parentRect); |
|
1944 |
// Subtract borders and padding |
|
1945 |
rect.move(-renderer->borderLeft() - renderer->paddingLeft(), |
|
1946 |
-renderer->borderTop() - renderer->paddingTop()); |
|
1947 |
return rect; |
|
1948 |
} |
|
1949 |
||
1950 |
return Widget::convertFromContainingView(parentRect); |
|
1951 |
} |
|
1952 |
||
1953 |
return parentRect; |
|
1954 |
} |
|
1955 |
||
1956 |
IntPoint FrameView::convertToContainingView(const IntPoint& localPoint) const |
|
1957 |
{ |
|
1958 |
if (const ScrollView* parentScrollView = parent()) { |
|
1959 |
if (parentScrollView->isFrameView()) { |
|
1960 |
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView); |
|
1961 |
||
1962 |
// Get our renderer in the parent view |
|
1963 |
RenderPart* renderer = m_frame->ownerRenderer(); |
|
1964 |
if (!renderer) |
|
1965 |
return localPoint; |
|
1966 |
||
1967 |
IntPoint point(localPoint); |
|
1968 |
||
1969 |
// Add borders and padding |
|
1970 |
point.move(renderer->borderLeft() + renderer->paddingLeft(), |
|
1971 |
renderer->borderTop() + renderer->paddingTop()); |
|
1972 |
return parentView->convertFromRenderer(renderer, point); |
|
1973 |
} |
|
1974 |
||
1975 |
return Widget::convertToContainingView(localPoint); |
|
1976 |
} |
|
1977 |
||
1978 |
return localPoint; |
|
1979 |
} |
|
1980 |
||
1981 |
IntPoint FrameView::convertFromContainingView(const IntPoint& parentPoint) const |
|
1982 |
{ |
|
1983 |
if (const ScrollView* parentScrollView = parent()) { |
|
1984 |
if (parentScrollView->isFrameView()) { |
|
1985 |
const FrameView* parentView = static_cast<const FrameView*>(parentScrollView); |
|
1986 |
||
1987 |
// Get our renderer in the parent view |
|
1988 |
RenderPart* renderer = m_frame->ownerRenderer(); |
|
1989 |
if (!renderer) |
|
1990 |
return parentPoint; |
|
1991 |
||
1992 |
IntPoint point = parentView->convertToRenderer(renderer, parentPoint); |
|
1993 |
// Subtract borders and padding |
|
1994 |
point.move(-renderer->borderLeft() - renderer->paddingLeft(), |
|
1995 |
-renderer->borderTop() - renderer->paddingTop()); |
|
1996 |
return point; |
|
1997 |
} |
|
1998 |
||
1999 |
return Widget::convertFromContainingView(parentPoint); |
|
2000 |
} |
|
2001 |
||
2002 |
return parentPoint; |
|
2003 |
} |
|
2004 |
||
2005 |
} // namespace WebCore |