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

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

Issue 641733004: Merge FrameView and ScrollView. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months 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
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "core/rendering/RenderView.h" 68 #include "core/rendering/RenderView.h"
69 #include "core/rendering/RenderWidget.h" 69 #include "core/rendering/RenderWidget.h"
70 #include "core/rendering/TextAutosizer.h" 70 #include "core/rendering/TextAutosizer.h"
71 #include "core/rendering/compositing/CompositedLayerMapping.h" 71 #include "core/rendering/compositing/CompositedLayerMapping.h"
72 #include "core/rendering/compositing/CompositedSelectionBound.h" 72 #include "core/rendering/compositing/CompositedSelectionBound.h"
73 #include "core/rendering/compositing/RenderLayerCompositor.h" 73 #include "core/rendering/compositing/RenderLayerCompositor.h"
74 #include "core/rendering/style/RenderStyle.h" 74 #include "core/rendering/style/RenderStyle.h"
75 #include "core/rendering/svg/RenderSVGRoot.h" 75 #include "core/rendering/svg/RenderSVGRoot.h"
76 #include "core/svg/SVGDocumentExtensions.h" 76 #include "core/svg/SVGDocumentExtensions.h"
77 #include "core/svg/SVGSVGElement.h" 77 #include "core/svg/SVGSVGElement.h"
78 #include "platform/HostWindow.h"
78 #include "platform/RuntimeEnabledFeatures.h" 79 #include "platform/RuntimeEnabledFeatures.h"
79 #include "platform/ScriptForbiddenScope.h" 80 #include "platform/ScriptForbiddenScope.h"
80 #include "platform/TraceEvent.h" 81 #include "platform/TraceEvent.h"
81 #include "platform/fonts/FontCache.h" 82 #include "platform/fonts/FontCache.h"
82 #include "platform/geometry/FloatRect.h" 83 #include "platform/geometry/FloatRect.h"
83 #include "platform/graphics/GraphicsContext.h" 84 #include "platform/graphics/GraphicsContext.h"
85 #include "platform/graphics/GraphicsContextStateSaver.h"
86 #include "platform/graphics/GraphicsLayer.h"
84 #include "platform/graphics/GraphicsLayerDebugInfo.h" 87 #include "platform/graphics/GraphicsLayerDebugInfo.h"
85 #include "platform/scroll/ScrollAnimator.h" 88 #include "platform/scroll/ScrollAnimator.h"
86 #include "platform/scroll/ScrollbarTheme.h" 89 #include "platform/scroll/ScrollbarTheme.h"
87 #include "platform/text/TextStream.h" 90 #include "platform/text/TextStream.h"
88 #include "wtf/CurrentTime.h" 91 #include "wtf/CurrentTime.h"
92 #include "wtf/StdLibExtras.h"
89 #include "wtf/TemporaryChange.h" 93 #include "wtf/TemporaryChange.h"
90 94
91 namespace blink { 95 namespace blink {
92 96
93 using namespace HTMLNames; 97 using namespace HTMLNames;
94 98
95 double FrameView::s_currentFrameTimeStamp = 0.0; 99 double FrameView::s_currentFrameTimeStamp = 0.0;
96 bool FrameView::s_inPaintContents = false; 100 bool FrameView::s_inPaintContents = false;
97 101
98 // The maximum number of updateWidgets iterations that should be done before ret urning. 102 // The maximum number of updateWidgets iterations that should be done before ret urning.
(...skipping 18 matching lines...) Expand all
117 , m_inProgrammaticScroll(false) 121 , m_inProgrammaticScroll(false)
118 , m_safeToPropagateScrollToParent(true) 122 , m_safeToPropagateScrollToParent(true)
119 , m_isTrackingPaintInvalidations(false) 123 , m_isTrackingPaintInvalidations(false)
120 , m_scrollCorner(nullptr) 124 , m_scrollCorner(nullptr)
121 , m_visibleContentScaleFactor(1) 125 , m_visibleContentScaleFactor(1)
122 , m_inputEventsScaleFactorForEmulation(1) 126 , m_inputEventsScaleFactorForEmulation(1)
123 , m_layoutSizeFixedToFrameSize(true) 127 , m_layoutSizeFixedToFrameSize(true)
124 , m_didScrollTimer(this, &FrameView::didScrollTimerFired) 128 , m_didScrollTimer(this, &FrameView::didScrollTimerFired)
125 , m_needsUpdateWidgetPositions(false) 129 , m_needsUpdateWidgetPositions(false)
126 , m_topControlsViewportAdjustment(0) 130 , m_topControlsViewportAdjustment(0)
131 , m_horizontalScrollbarMode(ScrollbarAuto)
132 , m_verticalScrollbarMode(ScrollbarAuto)
133 , m_horizontalScrollbarLock(false)
134 , m_verticalScrollbarLock(false)
135 , m_scrollbarsAvoidingResizer(0)
136 , m_scrollbarsSuppressed(false)
137 , m_inUpdateScrollbars(false)
138 , m_drawPanScrollIcon(false)
139 , m_clipsRepaints(true)
127 { 140 {
128 ASSERT(m_frame); 141 ASSERT(m_frame);
129 init(); 142 init();
130 143
131 if (!m_frame->isMainFrame()) 144 if (!m_frame->isMainFrame())
132 return; 145 return;
133 146
134 ScrollableArea::setVerticalScrollElasticity(ScrollElasticityAllowed); 147 ScrollableArea::setVerticalScrollElasticity(ScrollElasticityAllowed);
135 ScrollableArea::setHorizontalScrollElasticity(ScrollElasticityAllowed); 148 ScrollableArea::setHorizontalScrollElasticity(ScrollElasticityAllowed);
136 } 149 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 { 337 {
325 IntRect oldRect = frameRect(); 338 IntRect oldRect = frameRect();
326 if (newRect == oldRect) 339 if (newRect == oldRect)
327 return; 340 return;
328 341
329 // Autosized font sizes depend on the width of the viewing area. 342 // Autosized font sizes depend on the width of the viewing area.
330 bool autosizerNeedsUpdating = false; 343 bool autosizerNeedsUpdating = false;
331 if (newRect.width() != oldRect.width() && m_frame->isMainFrame() && m_frame- >settings()->textAutosizingEnabled()) 344 if (newRect.width() != oldRect.width() && m_frame->isMainFrame() && m_frame- >settings()->textAutosizingEnabled())
332 autosizerNeedsUpdating = true; 345 autosizerNeedsUpdating = true;
333 346
334 ScrollView::setFrameRect(newRect); 347 setFrameRectInternal(newRect);
335 348
336 updateScrollableAreaSet(); 349 updateScrollableAreaSet();
337 350
338 if (autosizerNeedsUpdating) { 351 if (autosizerNeedsUpdating) {
339 // This needs to be after the call to ScrollView::setFrameRect, because it reads the new width. 352 // This needs to be after the call to ScrollView::setFrameRect, because it reads the new width.
340 if (TextAutosizer* textAutosizer = m_frame->document()->textAutosizer()) 353 if (TextAutosizer* textAutosizer = m_frame->document()->textAutosizer())
341 textAutosizer->updatePageInfoInAllFrames(); 354 textAutosizer->updatePageInfoInAllFrames();
342 } 355 }
343 356
344 if (RenderView* renderView = this->renderView()) { 357 if (RenderView* renderView = this->renderView()) {
(...skipping 15 matching lines...) Expand all
360 } 373 }
361 374
362 RenderView* FrameView::renderView() const 375 RenderView* FrameView::renderView() const
363 { 376 {
364 return frame().contentRenderer(); 377 return frame().contentRenderer();
365 } 378 }
366 379
367 void FrameView::setCanHaveScrollbars(bool canHaveScrollbars) 380 void FrameView::setCanHaveScrollbars(bool canHaveScrollbars)
368 { 381 {
369 m_canHaveScrollbars = canHaveScrollbars; 382 m_canHaveScrollbars = canHaveScrollbars;
370 ScrollView::setCanHaveScrollbars(canHaveScrollbars); 383 setCanHaveScrollbarsInternal(canHaveScrollbars);
371 } 384 }
372 385
373 bool FrameView::shouldUseCustomScrollbars(Element*& customScrollbarElement, Loca lFrame*& customScrollbarFrame) 386 bool FrameView::shouldUseCustomScrollbars(Element*& customScrollbarElement, Loca lFrame*& customScrollbarFrame)
374 { 387 {
375 customScrollbarElement = 0; 388 customScrollbarElement = 0;
376 customScrollbarFrame = 0; 389 customScrollbarFrame = 0;
377 390
378 if (Settings* settings = m_frame->settings()) { 391 if (Settings* settings = m_frame->settings()) {
379 if (!settings->allowCustomScrollbarInMainFrame() && m_frame->isMainFrame ()) 392 if (!settings->allowCustomScrollbarInMainFrame() && m_frame->isMainFrame ())
380 return false; 393 return false;
(...skipping 27 matching lines...) Expand all
408 } 421 }
409 422
410 PassRefPtr<Scrollbar> FrameView::createScrollbar(ScrollbarOrientation orientatio n) 423 PassRefPtr<Scrollbar> FrameView::createScrollbar(ScrollbarOrientation orientatio n)
411 { 424 {
412 Element* customScrollbarElement = 0; 425 Element* customScrollbarElement = 0;
413 LocalFrame* customScrollbarFrame = 0; 426 LocalFrame* customScrollbarFrame = 0;
414 if (shouldUseCustomScrollbars(customScrollbarElement, customScrollbarFrame)) 427 if (shouldUseCustomScrollbars(customScrollbarElement, customScrollbarFrame))
415 return RenderScrollbar::createCustomScrollbar(this, orientation, customS crollbarElement, customScrollbarFrame); 428 return RenderScrollbar::createCustomScrollbar(this, orientation, customS crollbarElement, customScrollbarFrame);
416 429
417 // Nobody set a custom style, so we just use a native scrollbar. 430 // Nobody set a custom style, so we just use a native scrollbar.
418 return ScrollView::createScrollbar(orientation); 431 return createScrollbarInternal(orientation);
419 } 432 }
420 433
421 void FrameView::setContentsSize(const IntSize& size) 434 void FrameView::setContentsSize(const IntSize& size)
422 { 435 {
423 if (size == contentsSize()) 436 if (size == contentsSize())
424 return; 437 return;
425 438
426 ScrollView::setContentsSize(size); 439 setContentsSizeInternal(size);
427 ScrollView::contentsResized(); 440 ScrollableArea::contentsResized();
428 441
429 Page* page = frame().page(); 442 Page* page = frame().page();
430 if (!page) 443 if (!page)
431 return; 444 return;
432 445
433 updateScrollableAreaSet(); 446 updateScrollableAreaSet();
434 447
435 page->chrome().contentsSizeChanged(m_frame.get(), size); 448 page->chrome().contentsSizeChanged(m_frame.get(), size);
436 } 449 }
437 450
(...skipping 14 matching lines...) Expand all
452 void FrameView::adjustViewSize() 465 void FrameView::adjustViewSize()
453 { 466 {
454 RenderView* renderView = this->renderView(); 467 RenderView* renderView = this->renderView();
455 if (!renderView) 468 if (!renderView)
456 return; 469 return;
457 470
458 ASSERT(m_frame->view() == this); 471 ASSERT(m_frame->view() == this);
459 472
460 const IntRect rect = renderView->documentRect(); 473 const IntRect rect = renderView->documentRect();
461 const IntSize& size = rect.size(); 474 const IntSize& size = rect.size();
462 ScrollView::setScrollOrigin(IntPoint(-rect.x(), -rect.y()), !m_frame->docume nt()->printing(), size == contentsSize()); 475 setScrollOrigin(IntPoint(-rect.x(), -rect.y()), !m_frame->document()->printi ng(), size == contentsSize());
463 476
464 setContentsSize(size); 477 setContentsSize(size);
465 } 478 }
466 479
467 void FrameView::applyOverflowToViewportAndSetRenderer(RenderObject* o, Scrollbar Mode& hMode, ScrollbarMode& vMode) 480 void FrameView::applyOverflowToViewportAndSetRenderer(RenderObject* o, Scrollbar Mode& hMode, ScrollbarMode& vMode)
468 { 481 {
469 // Handle the overflow:hidden/scroll case for the body/html elements. WinIE treats 482 // Handle the overflow:hidden/scroll case for the body/html elements. WinIE treats
470 // overflow:hidden and overflow:scroll on <body> as applying to the document 's 483 // overflow:hidden and overflow:scroll on <body> as applying to the document 's
471 // scrollbars. The CSS2.1 draft states that HTML UAs should use the <html> or <body> element and XML/XHTML UAs should 484 // scrollbars. The CSS2.1 draft states that HTML UAs should use the <html> or <body> element and XML/XHTML UAs should
472 // use the root element. 485 // use the root element.
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 if (RenderPart* frameRenderer = m_frame->ownerRenderer()) { 1309 if (RenderPart* frameRenderer = m_frame->ownerRenderer()) {
1297 if (isEnclosedInCompositingLayer()) { 1310 if (isEnclosedInCompositingLayer()) {
1298 LayoutRect rect(frameRenderer->borderLeft() + frameRenderer->padding Left(), 1311 LayoutRect rect(frameRenderer->borderLeft() + frameRenderer->padding Left(),
1299 frameRenderer->borderTop() + frameRenderer->paddingT op(), 1312 frameRenderer->borderTop() + frameRenderer->paddingT op(),
1300 visibleWidth(), visibleHeight()); 1313 visibleWidth(), visibleHeight());
1301 frameRenderer->invalidatePaintRectangle(rect); 1314 frameRenderer->invalidatePaintRectangle(rect);
1302 return; 1315 return;
1303 } 1316 }
1304 } 1317 }
1305 1318
1306 ScrollView::scrollContentsSlowPath(updateRect); 1319 scrollContentsSlowPathInternal(updateRect);
1307 } 1320 }
1308 1321
1309 void FrameView::restoreScrollbar() 1322 void FrameView::restoreScrollbar()
1310 { 1323 {
1311 setScrollbarsSuppressed(false); 1324 setScrollbarsSuppressed(false);
1312 } 1325 }
1313 1326
1314 bool FrameView::scrollToFragment(const KURL& url) 1327 bool FrameView::scrollToFragment(const KURL& url)
1315 { 1328 {
1316 // If our URL has no ref, then we have no place we need to jump to. 1329 // If our URL has no ref, then we have no place we need to jump to.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 if (newScrollPosition == scrollPosition()) 1443 if (newScrollPosition == scrollPosition())
1431 return; 1444 return;
1432 1445
1433 if (scrollBehavior == ScrollBehaviorAuto) { 1446 if (scrollBehavior == ScrollBehaviorAuto) {
1434 RenderObject* renderer = m_frame->document()->documentElement() ? m_fram e->document()->documentElement()->renderer() : 0; 1447 RenderObject* renderer = m_frame->document()->documentElement() ? m_fram e->document()->documentElement()->renderer() : 0;
1435 if (renderer) 1448 if (renderer)
1436 scrollBehavior = renderer->style()->scrollBehavior(); 1449 scrollBehavior = renderer->style()->scrollBehavior();
1437 else 1450 else
1438 scrollBehavior = ScrollBehaviorInstant; 1451 scrollBehavior = ScrollBehaviorInstant;
1439 } 1452 }
1440 ScrollView::setScrollPosition(newScrollPosition, scrollBehavior); 1453 setScrollPositionInternal(newScrollPosition, scrollBehavior);
1441 } 1454 }
1442 1455
1443 void FrameView::setScrollPositionNonProgrammatically(const IntPoint& scrollPoint ) 1456 void FrameView::setScrollPositionNonProgrammatically(const IntPoint& scrollPoint )
1444 { 1457 {
1445 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); 1458 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint);
1446 1459
1447 if (newScrollPosition == scrollPosition()) 1460 if (newScrollPosition == scrollPosition())
1448 return; 1461 return;
1449 1462
1450 TemporaryChange<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, fal se); 1463 TemporaryChange<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, fal se);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 if (m_isTrackingPaintInvalidations) { 1604 if (m_isTrackingPaintInvalidations) {
1592 IntRect paintInvalidationRect = r; 1605 IntRect paintInvalidationRect = r;
1593 paintInvalidationRect.move(-scrollOffset()); 1606 paintInvalidationRect.move(-scrollOffset());
1594 m_trackedPaintInvalidationRects.append(paintInvalidationRect); 1607 m_trackedPaintInvalidationRects.append(paintInvalidationRect);
1595 // FIXME: http://crbug.com/368518. Eventually, invalidateContentRectangl eForPaint 1608 // FIXME: http://crbug.com/368518. Eventually, invalidateContentRectangl eForPaint
1596 // is going away entirely once all layout tests are FCM. In the short 1609 // is going away entirely once all layout tests are FCM. In the short
1597 // term, no code should be tracking non-composited FrameView paint inval idations. 1610 // term, no code should be tracking non-composited FrameView paint inval idations.
1598 RELEASE_ASSERT_NOT_REACHED(); 1611 RELEASE_ASSERT_NOT_REACHED();
1599 } 1612 }
1600 1613
1601 ScrollView::contentRectangleForPaintInvalidation(r); 1614 contentRectangleForPaintInvalidationInternal(r);
1602 } 1615 }
1603 1616
1604 void FrameView::contentsResized() 1617 void FrameView::contentsResized()
1605 { 1618 {
1606 if (m_frame->isMainFrame() && m_frame->document()) { 1619 if (m_frame->isMainFrame() && m_frame->document()) {
1607 if (TextAutosizer* textAutosizer = m_frame->document()->textAutosizer()) 1620 if (TextAutosizer* textAutosizer = m_frame->document()->textAutosizer())
1608 textAutosizer->updatePageInfoInAllFrames(); 1621 textAutosizer->updatePageInfoInAllFrames();
1609 } 1622 }
1610 1623
1611 ScrollView::contentsResized(); 1624 ScrollableArea::contentsResized();
1612 setNeedsLayout(); 1625 setNeedsLayout();
1613 } 1626 }
1614 1627
1615 void FrameView::scrollbarExistenceDidChange() 1628 void FrameView::scrollbarExistenceDidChange()
1616 { 1629 {
1617 // We check to make sure the view is attached to a frame() as this method ca n 1630 // We check to make sure the view is attached to a frame() as this method ca n
1618 // be triggered before the view is attached by LocalFrame::createView(...) s etting 1631 // be triggered before the view is attached by LocalFrame::createView(...) s etting
1619 // various values such as setScrollBarModes(...) for example. An ASSERT is 1632 // various values such as setScrollBarModes(...) for example. An ASSERT is
1620 // triggered when a view is layout before being attached to a frame(). 1633 // triggered when a view is layout before being attached to a frame().
1621 if (!frame().view()) 1634 if (!frame().view())
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 2093
2081 bool FrameView::isActive() const 2094 bool FrameView::isActive() const
2082 { 2095 {
2083 Page* page = frame().page(); 2096 Page* page = frame().page();
2084 return page && page->focusController().isActive(); 2097 return page && page->focusController().isActive();
2085 } 2098 }
2086 2099
2087 void FrameView::scrollTo(const DoublePoint& newPosition) 2100 void FrameView::scrollTo(const DoublePoint& newPosition)
2088 { 2101 {
2089 DoublePoint position = scrollPositionDouble(); 2102 DoublePoint position = scrollPositionDouble();
2090 ScrollView::scrollTo(newPosition); 2103 scrollToInternal(newPosition);
2091 if (position != scrollPositionDouble()) { 2104 if (position != scrollPositionDouble()) {
2092 updateLayersAndCompositingAfterScrollIfNeeded(); 2105 updateLayersAndCompositingAfterScrollIfNeeded();
2093 scrollPositionChanged(); 2106 scrollPositionChanged();
2094 } 2107 }
2095 frame().loader().client()->didChangeScrollOffset(); 2108 frame().loader().client()->didChangeScrollOffset();
2096 } 2109 }
2097 2110
2098 void FrameView::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rec t) 2111 void FrameView::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rec t)
2099 { 2112 {
2100 // Add in our offset within the FrameView. 2113 // Add in our offset within the FrameView.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 bool FrameView::shouldSuspendScrollAnimations() const 2229 bool FrameView::shouldSuspendScrollAnimations() const
2217 { 2230 {
2218 return m_frame->loader().state() != FrameStateComplete; 2231 return m_frame->loader().state() != FrameStateComplete;
2219 } 2232 }
2220 2233
2221 void FrameView::scrollbarStyleChanged() 2234 void FrameView::scrollbarStyleChanged()
2222 { 2235 {
2223 // FIXME: Why does this only apply to the main frame? 2236 // FIXME: Why does this only apply to the main frame?
2224 if (!m_frame->isMainFrame()) 2237 if (!m_frame->isMainFrame())
2225 return; 2238 return;
2226 ScrollView::scrollbarStyleChanged(); 2239 scrollbarStyleChangedInternal();
2227 } 2240 }
2228 2241
2229 void FrameView::notifyPageThatContentAreaWillPaint() const 2242 void FrameView::notifyPageThatContentAreaWillPaint() const
2230 { 2243 {
2231 Page* page = m_frame->page(); 2244 Page* page = m_frame->page();
2232 if (!page) 2245 if (!page)
2233 return; 2246 return;
2234 2247
2235 contentAreaWillPaint(); 2248 contentAreaWillPaint();
2236 2249
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 if (cornerStyle) { 2310 if (cornerStyle) {
2298 if (!m_scrollCorner) 2311 if (!m_scrollCorner)
2299 m_scrollCorner = RenderScrollbarPart::createAnonymous(doc); 2312 m_scrollCorner = RenderScrollbarPart::createAnonymous(doc);
2300 m_scrollCorner->setStyle(cornerStyle.release()); 2313 m_scrollCorner->setStyle(cornerStyle.release());
2301 invalidateScrollCorner(cornerRect); 2314 invalidateScrollCorner(cornerRect);
2302 } else if (m_scrollCorner) { 2315 } else if (m_scrollCorner) {
2303 m_scrollCorner->destroy(); 2316 m_scrollCorner->destroy();
2304 m_scrollCorner = nullptr; 2317 m_scrollCorner = nullptr;
2305 } 2318 }
2306 2319
2307 ScrollView::updateScrollCorner(); 2320 updateScrollCornerInternal();
2308 } 2321 }
2309 2322
2310 void FrameView::paintScrollCorner(GraphicsContext* context, const IntRect& corne rRect) 2323 void FrameView::paintScrollCorner(GraphicsContext* context, const IntRect& corne rRect)
2311 { 2324 {
2312 if (m_scrollCorner) { 2325 if (m_scrollCorner) {
2313 bool needsBackgorund = m_frame->isMainFrame(); 2326 bool needsBackgorund = m_frame->isMainFrame();
2314 if (needsBackgorund) 2327 if (needsBackgorund)
2315 context->fillRect(cornerRect, baseBackgroundColor()); 2328 context->fillRect(cornerRect, baseBackgroundColor());
2316 ScrollbarPainter::paintIntoRect(m_scrollCorner, context, cornerRect.loca tion(), cornerRect); 2329 ScrollbarPainter::paintIntoRect(m_scrollCorner, context, cornerRect.loca tion(), cornerRect);
2317 return; 2330 return;
2318 } 2331 }
2319 2332
2320 ScrollView::paintScrollCorner(context, cornerRect); 2333 paintScrollCornerInternal(context, cornerRect);
2321 } 2334 }
2322 2335
2323 void FrameView::paintScrollbar(GraphicsContext* context, Scrollbar* bar, const I ntRect& rect) 2336 void FrameView::paintScrollbar(GraphicsContext* context, Scrollbar* bar, const I ntRect& rect)
2324 { 2337 {
2325 bool needsBackgorund = bar->isCustomScrollbar() && m_frame->isMainFrame(); 2338 bool needsBackgorund = bar->isCustomScrollbar() && m_frame->isMainFrame();
2326 if (needsBackgorund) { 2339 if (needsBackgorund) {
2327 IntRect toFill = bar->frameRect(); 2340 IntRect toFill = bar->frameRect();
2328 toFill.intersect(rect); 2341 toFill.intersect(rect);
2329 context->fillRect(toFill, baseBackgroundColor()); 2342 context->fillRect(toFill, baseBackgroundColor());
2330 } 2343 }
2331 2344
2332 ScrollView::paintScrollbar(context, bar, rect); 2345 paintScrollbarInternal(context, bar, rect);
2333 } 2346 }
2334 2347
2335 Color FrameView::documentBackgroundColor() const 2348 Color FrameView::documentBackgroundColor() const
2336 { 2349 {
2337 // <https://bugs.webkit.org/show_bug.cgi?id=59540> We blend the background c olor of 2350 // <https://bugs.webkit.org/show_bug.cgi?id=59540> We blend the background c olor of
2338 // the document and the body against the base background color of the frame view. 2351 // the document and the body against the base background color of the frame view.
2339 // Background images are unfortunately impractical to include. 2352 // Background images are unfortunately impractical to include.
2340 2353
2341 Color result = baseBackgroundColor(); 2354 Color result = baseBackgroundColor();
2342 if (!frame().document()) 2355 if (!frame().document())
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 void FrameView::paintOverhangAreas(GraphicsContext* context, const IntRect& hori zontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRec t) 2533 void FrameView::paintOverhangAreas(GraphicsContext* context, const IntRect& hori zontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRec t)
2521 { 2534 {
2522 if (m_frame->document()->printing()) 2535 if (m_frame->document()->printing())
2523 return; 2536 return;
2524 2537
2525 if (m_frame->isMainFrame()) { 2538 if (m_frame->isMainFrame()) {
2526 if (m_frame->page()->chrome().client().paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect)) 2539 if (m_frame->page()->chrome().client().paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect))
2527 return; 2540 return;
2528 } 2541 }
2529 2542
2530 ScrollView::paintOverhangAreas(context, horizontalOverhangArea, verticalOver hangArea, dirtyRect); 2543 paintOverhangAreasInternal(context, horizontalOverhangArea, verticalOverhang Area, dirtyRect);
2531 } 2544 }
2532 2545
2533 void FrameView::updateWidgetPositionsIfNeeded() 2546 void FrameView::updateWidgetPositionsIfNeeded()
2534 { 2547 {
2535 if (!m_needsUpdateWidgetPositions) 2548 if (!m_needsUpdateWidgetPositions)
2536 return; 2549 return;
2537 2550
2538 m_needsUpdateWidgetPositions = false; 2551 m_needsUpdateWidgetPositions = false;
2539 2552
2540 updateWidgetPositions(); 2553 updateWidgetPositions();
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 IntPoint point = viewPoint; 2755 IntPoint point = viewPoint;
2743 2756
2744 // Convert from FrameView coords into page ("absolute") coordinates. 2757 // Convert from FrameView coords into page ("absolute") coordinates.
2745 point += IntSize(scrollX(), scrollY()); 2758 point += IntSize(scrollX(), scrollY());
2746 2759
2747 return roundedIntPoint(renderer.absoluteToLocal(point, UseTransforms)); 2760 return roundedIntPoint(renderer.absoluteToLocal(point, UseTransforms));
2748 } 2761 }
2749 2762
2750 IntRect FrameView::convertToContainingView(const IntRect& localRect) const 2763 IntRect FrameView::convertToContainingView(const IntRect& localRect) const
2751 { 2764 {
2752 if (const ScrollView* parentScrollView = toScrollView(parent())) { 2765 if (const FrameView* parentScrollView = toFrameView(parent())) {
2753 if (parentScrollView->isFrameView()) { 2766 if (parentScrollView->isFrameView()) {
2754 const FrameView* parentView = toFrameView(parentScrollView); 2767 const FrameView* parentView = parentScrollView;
2755 // Get our renderer in the parent view 2768 // Get our renderer in the parent view
2756 RenderPart* renderer = m_frame->ownerRenderer(); 2769 RenderPart* renderer = m_frame->ownerRenderer();
2757 if (!renderer) 2770 if (!renderer)
2758 return localRect; 2771 return localRect;
2759 2772
2760 IntRect rect(localRect); 2773 IntRect rect(localRect);
2761 // Add borders and padding?? 2774 // Add borders and padding??
2762 rect.move(renderer->borderLeft() + renderer->paddingLeft(), 2775 rect.move(renderer->borderLeft() + renderer->paddingLeft(),
2763 renderer->borderTop() + renderer->paddingTop()); 2776 renderer->borderTop() + renderer->paddingTop());
2764 return parentView->convertFromRenderer(*renderer, rect); 2777 return parentView->convertFromRenderer(*renderer, rect);
2765 } 2778 }
2766 2779
2767 return Widget::convertToContainingView(localRect); 2780 return Widget::convertToContainingView(localRect);
2768 } 2781 }
2769 2782
2770 return localRect; 2783 return localRect;
2771 } 2784 }
2772 2785
2773 IntRect FrameView::convertFromContainingView(const IntRect& parentRect) const 2786 IntRect FrameView::convertFromContainingView(const IntRect& parentRect) const
2774 { 2787 {
2775 if (const ScrollView* parentScrollView = toScrollView(parent())) { 2788 if (const FrameView* parentScrollView = toFrameView(parent())) {
2776 if (parentScrollView->isFrameView()) { 2789 if (parentScrollView->isFrameView()) {
2777 const FrameView* parentView = toFrameView(parentScrollView); 2790 const FrameView* parentView = parentScrollView;
2778 2791
2779 // Get our renderer in the parent view 2792 // Get our renderer in the parent view
2780 RenderPart* renderer = m_frame->ownerRenderer(); 2793 RenderPart* renderer = m_frame->ownerRenderer();
2781 if (!renderer) 2794 if (!renderer)
2782 return parentRect; 2795 return parentRect;
2783 2796
2784 IntRect rect = parentView->convertToRenderer(*renderer, parentRect); 2797 IntRect rect = parentView->convertToRenderer(*renderer, parentRect);
2785 // Subtract borders and padding 2798 // Subtract borders and padding
2786 rect.move(-renderer->borderLeft() - renderer->paddingLeft(), 2799 rect.move(-renderer->borderLeft() - renderer->paddingLeft(),
2787 -renderer->borderTop() - renderer->paddingTop()); 2800 -renderer->borderTop() - renderer->paddingTop());
2788 return rect; 2801 return rect;
2789 } 2802 }
2790 2803
2791 return Widget::convertFromContainingView(parentRect); 2804 return Widget::convertFromContainingView(parentRect);
2792 } 2805 }
2793 2806
2794 return parentRect; 2807 return parentRect;
2795 } 2808 }
2796 2809
2797 IntPoint FrameView::convertToContainingView(const IntPoint& localPoint) const 2810 IntPoint FrameView::convertToContainingView(const IntPoint& localPoint) const
2798 { 2811 {
2799 if (const ScrollView* parentScrollView = toScrollView(parent())) { 2812 if (const FrameView* parentScrollView = toFrameView(parent())) {
2800 if (parentScrollView->isFrameView()) { 2813 if (parentScrollView->isFrameView()) {
2801 const FrameView* parentView = toFrameView(parentScrollView); 2814 const FrameView* parentView = parentScrollView;
2802 2815
2803 // Get our renderer in the parent view 2816 // Get our renderer in the parent view
2804 RenderPart* renderer = m_frame->ownerRenderer(); 2817 RenderPart* renderer = m_frame->ownerRenderer();
2805 if (!renderer) 2818 if (!renderer)
2806 return localPoint; 2819 return localPoint;
2807 2820
2808 IntPoint point(localPoint); 2821 IntPoint point(localPoint);
2809 2822
2810 // Add borders and padding 2823 // Add borders and padding
2811 point.move(renderer->borderLeft() + renderer->paddingLeft(), 2824 point.move(renderer->borderLeft() + renderer->paddingLeft(),
2812 renderer->borderTop() + renderer->paddingTop()); 2825 renderer->borderTop() + renderer->paddingTop());
2813 return parentView->convertFromRenderer(*renderer, point); 2826 return parentView->convertFromRenderer(*renderer, point);
2814 } 2827 }
2815 2828
2816 return Widget::convertToContainingView(localPoint); 2829 return Widget::convertToContainingView(localPoint);
2817 } 2830 }
2818 2831
2819 return localPoint; 2832 return localPoint;
2820 } 2833 }
2821 2834
2822 IntPoint FrameView::convertFromContainingView(const IntPoint& parentPoint) const 2835 IntPoint FrameView::convertFromContainingView(const IntPoint& parentPoint) const
2823 { 2836 {
2824 if (const ScrollView* parentScrollView = toScrollView(parent())) { 2837 if (const FrameView* parentScrollView = toFrameView(parent())) {
2825 if (parentScrollView->isFrameView()) { 2838 if (parentScrollView->isFrameView()) {
2826 const FrameView* parentView = toFrameView(parentScrollView); 2839 const FrameView* parentView = parentScrollView;
2827 2840
2828 // Get our renderer in the parent view 2841 // Get our renderer in the parent view
2829 RenderPart* renderer = m_frame->ownerRenderer(); 2842 RenderPart* renderer = m_frame->ownerRenderer();
2830 if (!renderer) 2843 if (!renderer)
2831 return parentPoint; 2844 return parentPoint;
2832 2845
2833 IntPoint point = parentView->convertToRenderer(*renderer, parentPoin t); 2846 IntPoint point = parentView->convertToRenderer(*renderer, parentPoin t);
2834 // Subtract borders and padding 2847 // Subtract borders and padding
2835 point.move(-renderer->borderLeft() - renderer->paddingLeft(), 2848 point.move(-renderer->borderLeft() - renderer->paddingLeft(),
2836 -renderer->borderTop() - renderer->paddingTop()); 2849 -renderer->borderTop() - renderer->paddingTop());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2908 2921
2909 void FrameView::removeScrollableArea(ScrollableArea* scrollableArea) 2922 void FrameView::removeScrollableArea(ScrollableArea* scrollableArea)
2910 { 2923 {
2911 if (!m_scrollableAreas) 2924 if (!m_scrollableAreas)
2912 return; 2925 return;
2913 m_scrollableAreas->remove(scrollableArea); 2926 m_scrollableAreas->remove(scrollableArea);
2914 } 2927 }
2915 2928
2916 void FrameView::setParent(Widget* widget) 2929 void FrameView::setParent(Widget* widget)
2917 { 2930 {
2918 ScrollView::setParent(widget); 2931 setParentInternal(widget);
2919 updateScrollableAreaSet(); 2932 updateScrollableAreaSet();
2920 } 2933 }
2921 2934
2922 void FrameView::removeChild(Widget* widget) 2935 void FrameView::removeChild(Widget* widget)
2923 { 2936 {
2924 if (widget->isFrameView()) 2937 if (widget->isFrameView())
2925 removeScrollableArea(toFrameView(widget)); 2938 removeScrollableArea(toFrameView(widget));
2926 2939
2927 ScrollView::removeChild(widget); 2940 removeChildInternal(widget);
2928 } 2941 }
2929 2942
2930 bool FrameView::wheelEvent(const PlatformWheelEvent& wheelEvent) 2943 bool FrameView::wheelEvent(const PlatformWheelEvent& wheelEvent)
2931 { 2944 {
2932 bool allowScrolling = userInputScrollable(HorizontalScrollbar) || userInputS crollable(VerticalScrollbar); 2945 bool allowScrolling = userInputScrollable(HorizontalScrollbar) || userInputS crollable(VerticalScrollbar);
2933 2946
2934 // Note that to allow for rubber-band over-scroll behavior, even non-scrolla ble views 2947 // Note that to allow for rubber-band over-scroll behavior, even non-scrolla ble views
2935 // should handle wheel events. 2948 // should handle wheel events.
2936 #if !USE(RUBBER_BANDING) 2949 #if !USE(RUBBER_BANDING)
2937 if (!isScrollable()) 2950 if (!isScrollable())
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2988 if (!page || !page->settings().deviceSupportsMouse()) 3001 if (!page || !page->settings().deviceSupportsMouse())
2989 return; 3002 return;
2990 page->chrome().setCursor(cursor); 3003 page->chrome().setCursor(cursor);
2991 } 3004 }
2992 3005
2993 void FrameView::frameRectsChanged() 3006 void FrameView::frameRectsChanged()
2994 { 3007 {
2995 if (layoutSizeFixedToFrameSize()) 3008 if (layoutSizeFixedToFrameSize())
2996 setLayoutSizeInternal(frameRect().size()); 3009 setLayoutSizeInternal(frameRect().size());
2997 3010
2998 ScrollView::frameRectsChanged(); 3011 frameRectsChangedInternal();
2999 } 3012 }
3000 3013
3001 void FrameView::setLayoutSizeInternal(const IntSize& size) 3014 void FrameView::setLayoutSizeInternal(const IntSize& size)
3002 { 3015 {
3003 if (m_layoutSize == size) 3016 if (m_layoutSize == size)
3004 return; 3017 return;
3005 3018
3006 m_layoutSize = size; 3019 m_layoutSize = size;
3007 contentsResized(); 3020 contentsResized();
3008 } 3021 }
(...skipping 26 matching lines...) Expand all
3035 visibleContentSizeF.scale(1 / visibleContentScaleFactor()); 3048 visibleContentSizeF.scale(1 / visibleContentScaleFactor());
3036 IntSize visibleSize = expandedIntSize(visibleContentSizeF); 3049 IntSize visibleSize = expandedIntSize(visibleContentSizeF);
3037 3050
3038 IntPoint maximumOffset( 3051 IntPoint maximumOffset(
3039 contentsWidth() - visibleSize.width() - scrollOrigin().x(), 3052 contentsWidth() - visibleSize.width() - scrollOrigin().x(),
3040 contentsHeight() - visibleSize.height() - scrollOrigin().y()); 3053 contentsHeight() - visibleSize.height() - scrollOrigin().y());
3041 maximumOffset.clampNegativeToZero(); 3054 maximumOffset.clampNegativeToZero();
3042 return maximumOffset; 3055 return maximumOffset;
3043 } 3056 }
3044 3057
3058 // --- ScrollView ---
3059
3060 void FrameView::addChild(PassRefPtr<Widget> prpChild)
3061 {
3062 Widget* child = prpChild.get();
3063 ASSERT(child != this && !child->parent());
3064 child->setParent(this);
3065 m_children.add(prpChild);
3066 }
3067
3068 void FrameView::removeChildInternal(Widget* child)
3069 {
3070 ASSERT(child->parent() == this);
3071 child->setParent(0);
3072 m_children.remove(child);
3073 }
3074
3075 void FrameView::setHasHorizontalScrollbar(bool hasBar)
3076 {
3077 if (hasBar && !m_horizontalScrollbar) {
3078 m_horizontalScrollbar = createScrollbar(HorizontalScrollbar);
3079 addChild(m_horizontalScrollbar.get());
3080 didAddScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar);
3081 m_horizontalScrollbar->styleChanged();
3082 } else if (!hasBar && m_horizontalScrollbar) {
3083 willRemoveScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar);
3084 // If the scrollbar has been marked as overlapping the window resizer,
3085 // then its removal should reduce the count.
3086 if (m_horizontalScrollbar->overlapsResizer())
3087 adjustScrollbarsAvoidingResizerCount(-1);
3088 removeChild(m_horizontalScrollbar.get());
3089 m_horizontalScrollbar = nullptr;
3090 }
3091 }
3092
3093 void FrameView::setHasVerticalScrollbar(bool hasBar)
3094 {
3095 if (hasBar && !m_verticalScrollbar) {
3096 m_verticalScrollbar = createScrollbar(VerticalScrollbar);
3097 addChild(m_verticalScrollbar.get());
3098 didAddScrollbar(m_verticalScrollbar.get(), VerticalScrollbar);
3099 m_verticalScrollbar->styleChanged();
3100 } else if (!hasBar && m_verticalScrollbar) {
3101 willRemoveScrollbar(m_verticalScrollbar.get(), VerticalScrollbar);
3102 // If the scrollbar has been marked as overlapping the window resizer,
3103 // then its removal should reduce the count.
3104 if (m_verticalScrollbar->overlapsResizer())
3105 adjustScrollbarsAvoidingResizerCount(-1);
3106 removeChild(m_verticalScrollbar.get());
3107 m_verticalScrollbar = nullptr;
3108 }
3109 }
3110
3111 PassRefPtr<Scrollbar> FrameView::createScrollbarInternal(ScrollbarOrientation or ientation)
3112 {
3113 return Scrollbar::create(this, orientation, RegularScrollbar);
3114 }
3115
3116 void FrameView::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode ve rticalMode,
3117 bool horizontalLock, bool verticalLock)
3118 {
3119 bool needsUpdate = false;
3120
3121 if (horizontalMode != horizontalScrollbarMode() && !m_horizontalScrollbarLoc k) {
3122 m_horizontalScrollbarMode = horizontalMode;
3123 needsUpdate = true;
3124 }
3125
3126 if (verticalMode != verticalScrollbarMode() && !m_verticalScrollbarLock) {
3127 m_verticalScrollbarMode = verticalMode;
3128 needsUpdate = true;
3129 }
3130
3131 if (horizontalLock)
3132 setHorizontalScrollbarLock();
3133
3134 if (verticalLock)
3135 setVerticalScrollbarLock();
3136
3137 if (!needsUpdate)
3138 return;
3139
3140 updateScrollbars(scrollOffset());
3141
3142 if (!layerForScrolling())
3143 return;
3144 blink::WebLayer* layer = layerForScrolling()->platformLayer();
3145 if (!layer)
3146 return;
3147 layer->setUserScrollable(userInputScrollable(HorizontalScrollbar), userInput Scrollable(VerticalScrollbar));
3148 }
3149
3150 void FrameView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& ver ticalMode) const
3151 {
3152 horizontalMode = m_horizontalScrollbarMode;
3153 verticalMode = m_verticalScrollbarMode;
3154 }
3155
3156 void FrameView::setCanHaveScrollbarsInternal(bool canScroll)
3157 {
3158 ScrollbarMode newHorizontalMode;
3159 ScrollbarMode newVerticalMode;
3160
3161 scrollbarModes(newHorizontalMode, newVerticalMode);
3162
3163 if (canScroll && newVerticalMode == ScrollbarAlwaysOff)
3164 newVerticalMode = ScrollbarAuto;
3165 else if (!canScroll)
3166 newVerticalMode = ScrollbarAlwaysOff;
3167
3168 if (canScroll && newHorizontalMode == ScrollbarAlwaysOff)
3169 newHorizontalMode = ScrollbarAuto;
3170 else if (!canScroll)
3171 newHorizontalMode = ScrollbarAlwaysOff;
3172
3173 setScrollbarModes(newHorizontalMode, newVerticalMode);
3174 }
3175
3176 void FrameView::setClipsRepaints(bool clipsRepaints)
3177 {
3178 m_clipsRepaints = clipsRepaints;
3179 }
3180
3181 IntSize FrameView::unscaledVisibleContentSize(IncludeScrollbarsInRect scrollbarI nclusion) const
3182 {
3183 return scrollbarInclusion == ExcludeScrollbars ? excludeScrollbars(frameRect ().size()) : frameRect().size();
3184 }
3185
3186 IntSize FrameView::excludeScrollbars(const IntSize& size) const
3187 {
3188 int verticalScrollbarWidth = 0;
3189 int horizontalScrollbarHeight = 0;
3190
3191 if (Scrollbar* verticalBar = verticalScrollbar())
3192 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa r->width() : 0;
3193 if (Scrollbar* horizontalBar = horizontalScrollbar())
3194 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz ontalBar->height() : 0;
3195
3196 return IntSize(std::max(0, size.width() - verticalScrollbarWidth),
3197 std::max(0, size.height() - horizontalScrollbarHeight));
3198
3199 }
3200
3201 IntRect FrameView::visibleContentRect(IncludeScrollbarsInRect scollbarInclusion) const
3202 {
3203 FloatSize visibleContentSize = unscaledVisibleContentSize(scollbarInclusion) ;
3204 visibleContentSize.scale(1 / visibleContentScaleFactor());
3205 return IntRect(flooredIntPoint(m_scrollPosition), expandedIntSize(visibleCon tentSize));
3206 }
3207
3208 IntSize FrameView::contentsSize() const
3209 {
3210 return m_contentsSize;
3211 }
3212
3213 void FrameView::setContentsSizeInternal(const IntSize& newSize)
3214 {
3215 if (contentsSize() == newSize)
3216 return;
3217 m_contentsSize = newSize;
3218 updateScrollbars(scrollOffset());
3219 updateOverhangAreas();
3220 }
3221
3222 IntPoint FrameView::minimumScrollPosition() const
3223 {
3224 return IntPoint(-scrollOrigin().x(), -scrollOrigin().y());
3225 }
3226
3227 IntPoint FrameView::adjustScrollPositionWithinRange(const IntPoint& scrollPoint) const
3228 {
3229 if (!constrainsScrollingToContentEdge())
3230 return scrollPoint;
3231
3232 IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition());
3233 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition());
3234 return newScrollPosition;
3235 }
3236
3237 DoublePoint FrameView::adjustScrollPositionWithinRange(const DoublePoint& scroll Point) const
3238 {
3239 if (!constrainsScrollingToContentEdge())
3240 return scrollPoint;
3241 DoublePoint newScrollPosition = scrollPoint.shrunkTo(
3242 maximumScrollPosition().x(), maximumScrollPosition().y());
3243 newScrollPosition = newScrollPosition.expandedTo(
3244 minimumScrollPosition().x(), minimumScrollPosition().y());
3245 return newScrollPosition;
3246 }
3247
3248 void FrameView::adjustScrollbarOpacity()
3249 {
3250 if (m_horizontalScrollbar && layerForHorizontalScrollbar()) {
3251 bool isOpaqueScrollbar = !m_horizontalScrollbar->isOverlayScrollbar();
3252 layerForHorizontalScrollbar()->setContentsOpaque(isOpaqueScrollbar);
3253 }
3254 if (m_verticalScrollbar && layerForVerticalScrollbar()) {
3255 bool isOpaqueScrollbar = !m_verticalScrollbar->isOverlayScrollbar();
3256 layerForVerticalScrollbar()->setContentsOpaque(isOpaqueScrollbar);
3257 }
3258 }
3259
3260 int FrameView::scrollSize(ScrollbarOrientation orientation) const
3261 {
3262 Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalS crollbar : m_verticalScrollbar).get();
3263
3264 // If no scrollbars are present, the content may still be scrollable.
3265 if (!scrollbar) {
3266 IntSize scrollSize = m_contentsSize - visibleContentRect().size();
3267 scrollSize.clampNegativeToZero();
3268 return orientation == HorizontalScrollbar ? scrollSize.width() : scrollS ize.height();
3269 }
3270
3271 return scrollbar->totalSize() - scrollbar->visibleSize();
3272 }
3273
3274 void FrameView::notifyPageThatContentAreaWillPaintInternal() const
3275 {
3276 }
3277
3278 void FrameView::setScrollOffset(const IntPoint& offset)
3279 {
3280 scrollTo(DoublePoint(adjustScrollPositionWithinRange(offset)));
3281 }
3282
3283 void FrameView::setScrollOffset(const DoublePoint& offset)
3284 {
3285 scrollTo(adjustScrollPositionWithinRange(offset));
3286 }
3287
3288 void FrameView::scrollToInternal(const DoublePoint& newPosition)
3289 {
3290 DoubleSize scrollDelta = newPosition - m_scrollPosition;
3291 if (scrollDelta.isZero())
3292 return;
3293 m_scrollPosition = newPosition;
3294
3295 if (scrollbarsSuppressed())
3296 return;
3297
3298 // FIXME: Change scrollContents() to take DoubleSize. crbug.com/414283.
3299 if (isFrameView())
3300 m_pendingScrollDelta += scrollDelta;
3301 else
3302 scrollContents(flooredIntSize(scrollDelta));
3303 }
3304
3305 void FrameView::setScrollPositionInternal(const IntPoint& scrollPoint, ScrollBeh avior scrollBehavior)
3306 {
3307 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint);
3308
3309 if (newScrollPosition == scrollPosition())
3310 return;
3311
3312 if (scrollBehavior == ScrollBehaviorInstant)
3313 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y()));
3314 else
3315 programmaticallyScrollSmoothlyToOffset(newScrollPosition);
3316 }
3317
3318 bool FrameView::scroll(ScrollDirection direction, ScrollGranularity granularity)
3319 {
3320 ScrollDirection physicalDirection =
3321 toPhysicalDirection(direction, isVerticalDocument(), isFlippedDocument() );
3322
3323 return ScrollableArea::scroll(physicalDirection, granularity);
3324 }
3325
3326 IntSize FrameView::overhangAmount() const
3327 {
3328 IntSize stretch;
3329
3330 IntPoint currentScrollPosition = scrollPosition();
3331 IntPoint minScrollPosition = minimumScrollPosition();
3332 IntPoint maxScrollPosition = maximumScrollPosition();
3333
3334 if (currentScrollPosition.x() < minScrollPosition.x())
3335 stretch.setWidth(currentScrollPosition.x() - minScrollPosition.x());
3336 if (currentScrollPosition.x() > maxScrollPosition.x())
3337 stretch.setWidth(currentScrollPosition.x() - maxScrollPosition.x());
3338
3339 if (currentScrollPosition.y() < minScrollPosition.y())
3340 stretch.setHeight(currentScrollPosition.y() - minScrollPosition.y());
3341 if (currentScrollPosition.y() > maxScrollPosition.y())
3342 stretch.setHeight(currentScrollPosition.y() - maxScrollPosition.y());
3343
3344 return stretch;
3345 }
3346
3347 void FrameView::windowResizerRectChanged()
3348 {
3349 updateScrollbars(scrollOffset());
3350 }
3351
3352 static bool useOverlayScrollbars()
3353 {
3354 // FIXME: Need to detect the presence of CSS custom scrollbars, which are no n-overlay regardless the ScrollbarTheme.
3355 return ScrollbarTheme::theme()->usesOverlayScrollbars();
3356 }
3357
3358 void FrameView::computeScrollbarExistence(bool& newHasHorizontalScrollbar, bool& newHasVerticalScrollbar, const IntSize& docSize, ComputeScrollbarExistenceOptio n option) const
3359 {
3360 bool hasHorizontalScrollbar = m_horizontalScrollbar;
3361 bool hasVerticalScrollbar = m_verticalScrollbar;
3362
3363 newHasHorizontalScrollbar = hasHorizontalScrollbar;
3364 newHasVerticalScrollbar = hasVerticalScrollbar;
3365
3366 ScrollbarMode hScroll = m_horizontalScrollbarMode;
3367 ScrollbarMode vScroll = m_verticalScrollbarMode;
3368
3369 if (hScroll != ScrollbarAuto)
3370 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
3371 if (vScroll != ScrollbarAuto)
3372 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
3373
3374 if (m_scrollbarsSuppressed || (hScroll != ScrollbarAuto && vScroll != Scroll barAuto))
3375 return;
3376
3377 if (hScroll == ScrollbarAuto)
3378 newHasHorizontalScrollbar = docSize.width() > visibleWidth();
3379 if (vScroll == ScrollbarAuto)
3380 newHasVerticalScrollbar = docSize.height() > visibleHeight();
3381
3382 if (useOverlayScrollbars())
3383 return;
3384
3385 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size();
3386
3387 bool attemptToRemoveScrollbars = (option == FirstPass
3388 && docSize.width() <= fullVisibleSize.width() && docSize.height() <= ful lVisibleSize.height());
3389 if (attemptToRemoveScrollbars) {
3390 if (hScroll == ScrollbarAuto)
3391 newHasHorizontalScrollbar = false;
3392 if (vScroll == ScrollbarAuto)
3393 newHasVerticalScrollbar = false;
3394 }
3395
3396 // If we ever turn one scrollbar off, always turn the other one off too.
3397 // Never ever try to both gain/lose a scrollbar in the same pass.
3398 if (!newHasHorizontalScrollbar && hasHorizontalScrollbar && vScroll != Scrol lbarAlwaysOn)
3399 newHasVerticalScrollbar = false;
3400 if (!newHasVerticalScrollbar && hasVerticalScrollbar && hScroll != Scrollbar AlwaysOn)
3401 newHasHorizontalScrollbar = false;
3402 }
3403
3404 void FrameView::updateScrollbarGeometry()
3405 {
3406 if (m_horizontalScrollbar) {
3407 int clientWidth = visibleWidth();
3408 IntRect oldRect(m_horizontalScrollbar->frameRect());
3409 IntRect hBarRect((shouldPlaceVerticalScrollbarOnLeft() && m_verticalScro llbar) ? m_verticalScrollbar->width() : 0,
3410 height() - m_horizontalScrollbar->height(),
3411 width() - (m_verticalScrollbar ? m_verticalScrollbar->width() : 0),
3412 m_horizontalScrollbar->height());
3413 m_horizontalScrollbar->setFrameRect(adjustScrollbarRectForResizer(hBarRe ct, m_horizontalScrollbar.get()));
3414 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct())
3415 m_horizontalScrollbar->invalidate();
3416
3417 if (m_scrollbarsSuppressed)
3418 m_horizontalScrollbar->setSuppressInvalidation(true);
3419 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth);
3420 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth());
3421 m_horizontalScrollbar->offsetDidChange();
3422 if (m_scrollbarsSuppressed)
3423 m_horizontalScrollbar->setSuppressInvalidation(false);
3424 }
3425
3426 if (m_verticalScrollbar) {
3427 int clientHeight = visibleHeight();
3428 IntRect oldRect(m_verticalScrollbar->frameRect());
3429 IntRect vBarRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - m _verticalScrollbar->width()),
3430 0,
3431 m_verticalScrollbar->width(),
3432 height() - (m_horizontalScrollbar ? m_horizontalScrollbar->height() : 0));
3433 m_verticalScrollbar->setFrameRect(adjustScrollbarRectForResizer(vBarRect , m_verticalScrollbar.get()));
3434 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ())
3435 m_verticalScrollbar->invalidate();
3436
3437 if (m_scrollbarsSuppressed)
3438 m_verticalScrollbar->setSuppressInvalidation(true);
3439 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight);
3440 m_verticalScrollbar->setProportion(clientHeight, contentsHeight());
3441 m_verticalScrollbar->offsetDidChange();
3442 if (m_scrollbarsSuppressed)
3443 m_verticalScrollbar->setSuppressInvalidation(false);
3444 }
3445 }
3446
3447 IntRect FrameView::adjustScrollbarRectForResizer(const IntRect& rect, Scrollbar* scrollbar)
3448 {
3449 // Get our window resizer rect and see if we overlap. Adjust to avoid the ov erlap
3450 // if necessary.
3451 IntRect adjustedRect(rect);
3452 bool overlapsResizer = false;
3453 if (!rect.isEmpty() && !windowResizerRect().isEmpty()) {
3454 IntRect resizerRect = convertFromContainingWindow(windowResizerRect());
3455 if (rect.intersects(resizerRect)) {
3456 if (scrollbar->orientation() == HorizontalScrollbar) {
3457 int overlap = rect.maxX() - resizerRect.x();
3458 if (overlap > 0 && resizerRect.maxX() >= rect.maxX()) {
3459 adjustedRect.setWidth(rect.width() - overlap);
3460 overlapsResizer = true;
3461 }
3462 } else {
3463 int overlap = rect.maxY() - resizerRect.y();
3464 if (overlap > 0 && resizerRect.maxY() >= rect.maxY()) {
3465 adjustedRect.setHeight(rect.height() - overlap);
3466 overlapsResizer = true;
3467 }
3468 }
3469 }
3470 }
3471 if (overlapsResizer != scrollbar->overlapsResizer()) {
3472 scrollbar->setOverlapsResizer(overlapsResizer);
3473 adjustScrollbarsAvoidingResizerCount(overlapsResizer ? 1 : -1);
3474 }
3475 return adjustedRect;
3476 }
3477
3478 bool FrameView::adjustScrollbarExistence(ComputeScrollbarExistenceOption option)
3479 {
3480 ASSERT(m_inUpdateScrollbars);
3481
3482 // If we came in here with the view already needing a layout, then go ahead and do that
3483 // first. (This will be the common case, e.g., when the page changes due to window resizing for example).
3484 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total.
3485 if (!m_scrollbarsSuppressed)
3486 scrollbarExistenceDidChange();
3487
3488 bool hasHorizontalScrollbar = m_horizontalScrollbar;
3489 bool hasVerticalScrollbar = m_verticalScrollbar;
3490
3491 bool newHasHorizontalScrollbar = false;
3492 bool newHasVerticalScrollbar = false;
3493 computeScrollbarExistence(newHasHorizontalScrollbar, newHasVerticalScrollbar , contentsSize(), option);
3494
3495 bool scrollbarExistenceChanged = hasHorizontalScrollbar != newHasHorizontalS crollbar || hasVerticalScrollbar != newHasVerticalScrollbar;
3496 if (!scrollbarExistenceChanged)
3497 return false;
3498
3499 setHasHorizontalScrollbar(newHasHorizontalScrollbar);
3500 setHasVerticalScrollbar(newHasVerticalScrollbar);
3501
3502 if (m_scrollbarsSuppressed)
3503 return true;
3504
3505 if (!useOverlayScrollbars())
3506 contentsResized();
3507 scrollbarExistenceDidChange();
3508 return true;
3509 }
3510
3511 void FrameView::updateScrollbars(const IntSize& desiredOffset)
3512 {
3513 if (scrollbarsDisabled()) {
3514 setScrollOffsetFromUpdateScrollbars(desiredOffset);
3515 return;
3516 }
3517
3518 if (m_inUpdateScrollbars)
3519 return;
3520 InUpdateScrollbarsScope inUpdateScrollbarsScope(this);
3521
3522 IntSize oldVisibleSize = visibleSize();
3523
3524 bool scrollbarExistenceChanged = false;
3525 int maxUpdateScrollbarsPass = useOverlayScrollbars() || m_scrollbarsSuppress ed ? 1 : 3;
3526 for (int updateScrollbarsPass = 0; updateScrollbarsPass < maxUpdateScrollbar sPass; updateScrollbarsPass++) {
3527 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental : First Pass))
3528 break;
3529 scrollbarExistenceChanged = true;
3530 }
3531
3532 updateScrollbarGeometry();
3533
3534 if (scrollbarExistenceChanged) {
3535 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec ts changed?
3536 frameRectsChanged();
3537 positionScrollbarLayers();
3538 updateScrollCorner();
3539 }
3540
3541 // FIXME: We don't need to do this if we are composited.
3542 IntSize newVisibleSize = visibleSize();
3543 if (newVisibleSize.width() > oldVisibleSize.width()) {
3544 if (shouldPlaceVerticalScrollbarOnLeft())
3545 invalidateRect(IntRect(0, 0, newVisibleSize.width() - oldVisibleSize .width(), newVisibleSize.height()));
3546 else
3547 invalidateRect(IntRect(oldVisibleSize.width(), 0, newVisibleSize.wid th() - oldVisibleSize.width(), newVisibleSize.height()));
3548 }
3549 if (newVisibleSize.height() > oldVisibleSize.height())
3550 invalidateRect(IntRect(0, oldVisibleSize.height(), newVisibleSize.width( ), newVisibleSize.height() - oldVisibleSize.height()));
3551
3552 setScrollOffsetFromUpdateScrollbars(desiredOffset);
3553 }
3554
3555 void FrameView::setScrollOffsetFromUpdateScrollbars(const IntSize& offset)
3556 {
3557 IntPoint adjustedScrollPosition = IntPoint(offset);
3558
3559 if (!isRubberBandInProgress())
3560 adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollP osition);
3561
3562 if (adjustedScrollPosition != scrollPosition() || scrollOriginChanged()) {
3563 ScrollableArea::scrollToOffsetWithoutAnimation(adjustedScrollPosition);
3564 resetScrollOriginChanged();
3565 }
3566 }
3567
3568 const int panIconSizeLength = 16;
3569
3570 IntRect FrameView::rectToCopyOnScroll() const
3571 {
3572 IntRect scrollViewRect = convertToContainingWindow(IntRect((shouldPlaceVerti calScrollbarOnLeft() && verticalScrollbar()) ? verticalScrollbar()->width() : 0, 0, visibleWidth(), visibleHeight()));
3573 if (hasOverlayScrollbars()) {
3574 int verticalScrollbarWidth = (verticalScrollbar() && !hasLayerForVertica lScrollbar()) ? verticalScrollbar()->width() : 0;
3575 int horizontalScrollbarHeight = (horizontalScrollbar() && !hasLayerForHo rizontalScrollbar()) ? horizontalScrollbar()->height() : 0;
3576
3577 scrollViewRect.setWidth(scrollViewRect.width() - verticalScrollbarWidth) ;
3578 scrollViewRect.setHeight(scrollViewRect.height() - horizontalScrollbarHe ight);
3579 }
3580 return scrollViewRect;
3581 }
3582
3583 void FrameView::scrollContentsIfNeeded()
3584 {
3585 if (m_pendingScrollDelta.isZero())
3586 return;
3587 DoubleSize scrollDelta = m_pendingScrollDelta;
3588 m_pendingScrollDelta = DoubleSize();
3589 // FIXME: Change scrollContents() to take DoubleSize. crbug.com/414283.
3590 scrollContents(flooredIntSize(scrollDelta));
3591 }
3592
3593 void FrameView::scrollContents(const IntSize& scrollDelta)
3594 {
3595 HostWindow* window = hostWindow();
3596 if (!window)
3597 return;
3598
3599 IntRect clipRect = windowClipRect();
3600 IntRect updateRect = clipRect;
3601 updateRect.intersect(rectToCopyOnScroll());
3602
3603 if (m_drawPanScrollIcon) {
3604 // FIXME: the pan icon is broken when accelerated compositing is on, sin ce it will draw under the compositing layers.
3605 // https://bugs.webkit.org/show_bug.cgi?id=47837
3606 int panIconDirtySquareSizeLength = 2 * (panIconSizeLength + std::max(abs (scrollDelta.width()), abs(scrollDelta.height()))); // We only want to repaint w hat's necessary
3607 IntPoint panIconDirtySquareLocation = IntPoint(m_panScrollIconPoint.x() - (panIconDirtySquareSizeLength / 2), m_panScrollIconPoint.y() - (panIconDirtySq uareSizeLength / 2));
3608 IntRect panScrollIconDirtyRect = IntRect(panIconDirtySquareLocation, Int Size(panIconDirtySquareSizeLength, panIconDirtySquareSizeLength));
3609 panScrollIconDirtyRect.intersect(clipRect);
3610 window->invalidateContentsAndRootView(panScrollIconDirtyRect);
3611 }
3612
3613 if (!scrollContentsFastPath(-scrollDelta))
3614 scrollContentsSlowPath(updateRect);
3615
3616 // Invalidate the overhang areas if they are visible.
3617 updateOverhangAreas();
3618
3619 // This call will move children with native widgets (plugins) and invalidate them as well.
3620 frameRectsChanged();
3621 }
3622
3623 void FrameView::scrollContentsSlowPathInternal(const IntRect& updateRect)
3624 {
3625 hostWindow()->invalidateContentsForSlowScroll(updateRect);
3626 }
3627
3628 IntPoint FrameView::rootViewToContents(const IntPoint& rootViewPoint) const
3629 {
3630 IntPoint viewPoint = convertFromContainingWindow(rootViewPoint);
3631 return viewPoint + scrollOffset();
3632 }
3633
3634 IntPoint FrameView::contentsToRootView(const IntPoint& contentsPoint) const
3635 {
3636 IntPoint viewPoint = contentsPoint - scrollOffset();
3637 return convertToContainingWindow(viewPoint);
3638 }
3639
3640 IntRect FrameView::rootViewToContents(const IntRect& rootViewRect) const
3641 {
3642 IntRect viewRect = convertFromContainingWindow(rootViewRect);
3643 viewRect.move(scrollOffset());
3644 return viewRect;
3645 }
3646
3647 IntRect FrameView::contentsToRootView(const IntRect& contentsRect) const
3648 {
3649 IntRect viewRect = contentsRect;
3650 viewRect.move(-scrollOffset());
3651 return convertToContainingWindow(viewRect);
3652 }
3653
3654 IntPoint FrameView::windowToContents(const IntPoint& windowPoint) const
3655 {
3656 IntPoint viewPoint = convertFromContainingWindow(windowPoint);
3657 return viewPoint + scrollOffset();
3658 }
3659
3660 FloatPoint FrameView::windowToContents(const FloatPoint& windowPoint) const
3661 {
3662 FloatPoint viewPoint = convertFromContainingWindow(windowPoint);
3663 return viewPoint + scrollOffset();
3664 }
3665
3666 IntPoint FrameView::contentsToWindow(const IntPoint& contentsPoint) const
3667 {
3668 IntPoint viewPoint = contentsPoint - scrollOffset();
3669 return convertToContainingWindow(viewPoint);
3670 }
3671
3672 IntRect FrameView::windowToContents(const IntRect& windowRect) const
3673 {
3674 IntRect viewRect = convertFromContainingWindow(windowRect);
3675 viewRect.move(scrollOffset());
3676 return viewRect;
3677 }
3678
3679 IntRect FrameView::contentsToWindow(const IntRect& contentsRect) const
3680 {
3681 IntRect viewRect = contentsRect;
3682 viewRect.move(-scrollOffset());
3683 return convertToContainingWindow(viewRect);
3684 }
3685
3686 IntRect FrameView::contentsToScreen(const IntRect& rect) const
3687 {
3688 HostWindow* window = hostWindow();
3689 if (!window)
3690 return IntRect();
3691 return window->rootViewToScreen(contentsToRootView(rect));
3692 }
3693
3694 bool FrameView::containsScrollbarsAvoidingResizer() const
3695 {
3696 return !m_scrollbarsAvoidingResizer;
3697 }
3698
3699 void FrameView::adjustScrollbarsAvoidingResizerCount(int overlapDelta)
3700 {
3701 int oldCount = m_scrollbarsAvoidingResizer;
3702 m_scrollbarsAvoidingResizer += overlapDelta;
3703 if (parent()) {
3704 toFrameView(parent())->adjustScrollbarsAvoidingResizerCount(overlapDelta );
3705 } else if (!scrollbarsSuppressed()) {
3706 // If we went from n to 0 or from 0 to n and we're the outermost view,
3707 // we need to invalidate the windowResizerRect(), since it will now need to paint
3708 // differently.
3709 if ((oldCount > 0 && m_scrollbarsAvoidingResizer == 0)
3710 || (oldCount == 0 && m_scrollbarsAvoidingResizer > 0))
3711 invalidateRect(windowResizerRect());
3712 }
3713 }
3714
3715 void FrameView::setParentInternal(Widget* parentView)
3716 {
3717 if (parentView == parent())
3718 return;
3719
3720 if (m_scrollbarsAvoidingResizer && parent())
3721 toFrameView(parent())->adjustScrollbarsAvoidingResizerCount(-m_scrollbar sAvoidingResizer);
3722
3723 Widget::setParent(parentView);
3724
3725 if (m_scrollbarsAvoidingResizer && parent())
3726 toFrameView(parent())->adjustScrollbarsAvoidingResizerCount(m_scrollbars AvoidingResizer);
3727 }
3728
3729 void FrameView::setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppres s)
3730 {
3731 if (suppressed == m_scrollbarsSuppressed)
3732 return;
3733
3734 m_scrollbarsSuppressed = suppressed;
3735
3736 if (repaintOnUnsuppress && !suppressed) {
3737 if (m_horizontalScrollbar)
3738 m_horizontalScrollbar->invalidate();
3739 if (m_verticalScrollbar)
3740 m_verticalScrollbar->invalidate();
3741
3742 // Invalidate the scroll corner too on unsuppress.
3743 invalidateRect(scrollCornerRect());
3744 }
3745 }
3746
3747 Scrollbar* FrameView::scrollbarAtWindowPoint(const IntPoint& windowPoint)
3748 {
3749 IntPoint viewPoint = convertFromContainingWindow(windowPoint);
3750 return scrollbarAtViewPoint(viewPoint);
3751 }
3752
3753 Scrollbar* FrameView::scrollbarAtViewPoint(const IntPoint& viewPoint)
3754 {
3755 if (m_horizontalScrollbar && m_horizontalScrollbar->shouldParticipateInHitTe sting() && m_horizontalScrollbar->frameRect().contains(viewPoint))
3756 return m_horizontalScrollbar.get();
3757 if (m_verticalScrollbar && m_verticalScrollbar->shouldParticipateInHitTestin g() && m_verticalScrollbar->frameRect().contains(viewPoint))
3758 return m_verticalScrollbar.get();
3759 return 0;
3760 }
3761
3762 void FrameView::setFrameRectInternal(const IntRect& newRect)
3763 {
3764 IntRect oldRect = frameRect();
3765
3766 if (newRect == oldRect)
3767 return;
3768
3769 Widget::setFrameRect(newRect);
3770
3771 updateScrollbars(scrollOffset());
3772
3773 frameRectsChanged();
3774 }
3775
3776 void FrameView::frameRectsChangedInternal()
3777 {
3778 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end();
3779 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current)
3780 (*current)->frameRectsChanged();
3781 }
3782
3783 static void positionScrollbarLayer(GraphicsLayer* graphicsLayer, Scrollbar* scro llbar)
3784 {
3785 if (!graphicsLayer || !scrollbar)
3786 return;
3787
3788 IntRect scrollbarRect = scrollbar->frameRect();
3789 graphicsLayer->setPosition(scrollbarRect.location());
3790
3791 if (scrollbarRect.size() == graphicsLayer->size())
3792 return;
3793
3794 graphicsLayer->setSize(scrollbarRect.size());
3795
3796 if (graphicsLayer->hasContentsLayer()) {
3797 graphicsLayer->setContentsRect(IntRect(0, 0, scrollbarRect.width(), scro llbarRect.height()));
3798 return;
3799 }
3800
3801 graphicsLayer->setDrawsContent(true);
3802 graphicsLayer->setNeedsDisplay();
3803 }
3804
3805 static void positionScrollCornerLayer(GraphicsLayer* graphicsLayer, const IntRec t& cornerRect)
3806 {
3807 if (!graphicsLayer)
3808 return;
3809 graphicsLayer->setDrawsContent(!cornerRect.isEmpty());
3810 graphicsLayer->setPosition(cornerRect.location());
3811 if (cornerRect.size() != graphicsLayer->size())
3812 graphicsLayer->setNeedsDisplay();
3813 graphicsLayer->setSize(cornerRect.size());
3814 }
3815
3816 void FrameView::positionScrollbarLayers()
3817 {
3818 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar()) ;
3819 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar());
3820 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect());
3821 }
3822
3823 bool FrameView::userInputScrollable(ScrollbarOrientation orientation) const
3824 {
3825 ScrollbarMode mode = (orientation == HorizontalScrollbar) ?
3826 m_horizontalScrollbarMode : m_verticalScrollbarMode;
3827
3828 return mode == ScrollbarAuto || mode == ScrollbarAlwaysOn;
3829 }
3830
3831 bool FrameView::shouldPlaceVerticalScrollbarOnLeft() const
3832 {
3833 return false;
3834 }
3835
3836 void FrameView::contentRectangleForPaintInvalidationInternal(const IntRect& rect )
3837 {
3838 IntRect paintRect = rect;
3839 if (clipsPaintInvalidations())
3840 paintRect.intersect(visibleContentRect());
3841 if (paintRect.isEmpty())
3842 return;
3843
3844 if (HostWindow* window = hostWindow())
3845 window->invalidateContentsAndRootView(contentsToWindow(paintRect));
3846 }
3847
3848 IntRect FrameView::scrollCornerRect() const
3849 {
3850 IntRect cornerRect;
3851
3852 if (hasOverlayScrollbars())
3853 return cornerRect;
3854
3855 if (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) {
3856 cornerRect.unite(IntRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : m_ho rizontalScrollbar->width(),
3857 height() - m_horizontalScrollbar->height(),
3858 width() - m_horizontalScrollbar->width(),
3859 m_horizontalScrollbar->height()));
3860 }
3861
3862 if (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0) {
3863 cornerRect.unite(IntRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (wid th() - m_verticalScrollbar->width()),
3864 m_verticalScrollbar->height(),
3865 m_verticalScrollbar->width(),
3866 height() - m_verticalScrollbar->height()));
3867 }
3868
3869 return cornerRect;
3870 }
3871
3872 bool FrameView::isScrollCornerVisible() const
3873 {
3874 return !scrollCornerRect().isEmpty();
3875 }
3876
3877 void FrameView::scrollbarStyleChangedInternal()
3878 {
3879 adjustScrollbarOpacity();
3880 contentsResized();
3881 updateScrollbars(scrollOffset());
3882 positionScrollbarLayers();
3883 }
3884
3885 void FrameView::updateScrollCornerInternal()
3886 {
3887 }
3888
3889 void FrameView::paintScrollCornerInternal(GraphicsContext* context, const IntRec t& cornerRect)
3890 {
3891 ScrollbarTheme::theme()->paintScrollCorner(context, cornerRect);
3892 }
3893
3894 void FrameView::paintScrollbarInternal(GraphicsContext* context, Scrollbar* bar, const IntRect& rect)
3895 {
3896 bar->paint(context, rect);
3897 }
3898
3899 void FrameView::invalidateScrollCornerRect(const IntRect& rect)
3900 {
3901 invalidateRect(rect);
3902 }
3903
3904 void FrameView::paintScrollbars(GraphicsContext* context, const IntRect& rect)
3905 {
3906 if (m_horizontalScrollbar && !layerForHorizontalScrollbar())
3907 paintScrollbar(context, m_horizontalScrollbar.get(), rect);
3908 if (m_verticalScrollbar && !layerForVerticalScrollbar())
3909 paintScrollbar(context, m_verticalScrollbar.get(), rect);
3910
3911 if (layerForScrollCorner())
3912 return;
3913 paintScrollCorner(context, scrollCornerRect());
3914 }
3915
3916 void FrameView::paintPanScrollIcon(GraphicsContext* context)
3917 {
3918 DEFINE_STATIC_REF(Image, panScrollIcon, (Image::loadPlatformResource("panIco n")));
3919 IntPoint iconGCPoint = m_panScrollIconPoint;
3920 if (parent())
3921 iconGCPoint = toFrameView(parent())->windowToContents(iconGCPoint);
3922 context->drawImage(panScrollIcon, iconGCPoint);
3923 }
3924
3925 void FrameView::paint(GraphicsContext* context, const IntRect& rect)
3926 {
3927 notifyPageThatContentAreaWillPaint();
3928
3929 IntRect documentDirtyRect = rect;
3930 IntRect visibleAreaWithoutScrollbars(location(), visibleContentRect().size() );
3931 documentDirtyRect.intersect(visibleAreaWithoutScrollbars);
3932
3933 if (!documentDirtyRect.isEmpty()) {
3934 GraphicsContextStateSaver stateSaver(*context);
3935
3936 context->translate(x() - scrollX(), y() - scrollY());
3937 context->clip(visibleContentRect());
3938
3939 documentDirtyRect.moveBy(-location() + scrollPosition());
3940 paintContents(context, documentDirtyRect);
3941 }
3942
3943 calculateAndPaintOverhangAreas(context, rect);
3944
3945 // Now paint the scrollbars.
3946 if (!m_scrollbarsSuppressed && (m_horizontalScrollbar || m_verticalScrollbar )) {
3947 GraphicsContextStateSaver stateSaver(*context);
3948 IntRect scrollViewDirtyRect = rect;
3949 IntRect visibleAreaWithScrollbars(location(), visibleContentRect(Include Scrollbars).size());
3950 scrollViewDirtyRect.intersect(visibleAreaWithScrollbars);
3951 context->translate(x(), y());
3952 scrollViewDirtyRect.moveBy(-location());
3953 context->clip(IntRect(IntPoint(), visibleAreaWithScrollbars.size()));
3954
3955 paintScrollbars(context, scrollViewDirtyRect);
3956 }
3957
3958 // Paint the panScroll Icon
3959 if (m_drawPanScrollIcon)
3960 paintPanScrollIcon(context);
3961 }
3962
3963 void FrameView::calculateOverhangAreasForPainting(IntRect& horizontalOverhangRec t, IntRect& verticalOverhangRect)
3964 {
3965 int verticalScrollbarWidth = (verticalScrollbar() && !verticalScrollbar()->i sOverlayScrollbar())
3966 ? verticalScrollbar()->width() : 0;
3967 int horizontalScrollbarHeight = (horizontalScrollbar() && !horizontalScrollb ar()->isOverlayScrollbar())
3968 ? horizontalScrollbar()->height() : 0;
3969
3970 int physicalScrollY = scrollPosition().y() + scrollOrigin().y();
3971 if (physicalScrollY < 0) {
3972 horizontalOverhangRect = frameRect();
3973 horizontalOverhangRect.setHeight(-physicalScrollY);
3974 horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - vertica lScrollbarWidth);
3975 } else if (contentsHeight() && physicalScrollY > contentsHeight() - visibleH eight()) {
3976 int height = physicalScrollY - (contentsHeight() - visibleHeight());
3977 horizontalOverhangRect = frameRect();
3978 horizontalOverhangRect.setY(frameRect().maxY() - height - horizontalScro llbarHeight);
3979 horizontalOverhangRect.setHeight(height);
3980 horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - vertica lScrollbarWidth);
3981 }
3982
3983 int physicalScrollX = scrollPosition().x() + scrollOrigin().x();
3984 if (physicalScrollX < 0) {
3985 verticalOverhangRect.setWidth(-physicalScrollX);
3986 verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhang Rect.height() - horizontalScrollbarHeight);
3987 verticalOverhangRect.setX(frameRect().x());
3988 if (horizontalOverhangRect.y() == frameRect().y())
3989 verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.h eight());
3990 else
3991 verticalOverhangRect.setY(frameRect().y());
3992 } else if (contentsWidth() && physicalScrollX > contentsWidth() - visibleWid th()) {
3993 int width = physicalScrollX - (contentsWidth() - visibleWidth());
3994 verticalOverhangRect.setWidth(width);
3995 verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhang Rect.height() - horizontalScrollbarHeight);
3996 verticalOverhangRect.setX(frameRect().maxX() - width - verticalScrollbar Width);
3997 if (horizontalOverhangRect.y() == frameRect().y())
3998 verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.h eight());
3999 else
4000 verticalOverhangRect.setY(frameRect().y());
4001 }
4002 }
4003
4004 void FrameView::updateOverhangAreas()
4005 {
4006 HostWindow* window = hostWindow();
4007 if (!window)
4008 return;
4009
4010 IntRect horizontalOverhangRect;
4011 IntRect verticalOverhangRect;
4012 calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRe ct);
4013 if (!horizontalOverhangRect.isEmpty())
4014 window->invalidateContentsAndRootView(horizontalOverhangRect);
4015 if (!verticalOverhangRect.isEmpty())
4016 window->invalidateContentsAndRootView(verticalOverhangRect);
4017 }
4018
4019 void FrameView::paintOverhangAreasInternal(GraphicsContext* context, const IntRe ct& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect)
4020 {
4021 ScrollbarTheme::theme()->paintOverhangBackground(context, horizontalOverhang Rect, verticalOverhangRect, dirtyRect);
4022 ScrollbarTheme::theme()->paintOverhangShadows(context, scrollOffset(), horiz ontalOverhangRect, verticalOverhangRect, dirtyRect);
4023 }
4024
4025 void FrameView::calculateAndPaintOverhangAreas(GraphicsContext* context, const I ntRect& dirtyRect)
4026 {
4027 IntRect horizontalOverhangRect;
4028 IntRect verticalOverhangRect;
4029 calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRe ct);
4030
4031 if (dirtyRect.intersects(horizontalOverhangRect) || dirtyRect.intersects(ver ticalOverhangRect))
4032 paintOverhangAreas(context, horizontalOverhangRect, verticalOverhangRect , dirtyRect);
4033 }
4034
4035 void FrameView::calculateAndPaintOverhangBackground(GraphicsContext* context, co nst IntRect& dirtyRect)
4036 {
4037 IntRect horizontalOverhangRect;
4038 IntRect verticalOverhangRect;
4039 calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRe ct);
4040
4041 if (dirtyRect.intersects(horizontalOverhangRect) || dirtyRect.intersects(ver ticalOverhangRect))
4042 ScrollbarTheme::theme()->paintOverhangBackground(context, horizontalOver hangRect, verticalOverhangRect, dirtyRect);
4043 }
4044
4045 bool FrameView::isPointInScrollbarCorner(const IntPoint& windowPoint)
4046 {
4047 if (!scrollbarCornerPresent())
4048 return false;
4049
4050 IntPoint viewPoint = convertFromContainingWindow(windowPoint);
4051
4052 if (m_horizontalScrollbar) {
4053 int horizontalScrollbarYMin = m_horizontalScrollbar->frameRect().y();
4054 int horizontalScrollbarYMax = m_horizontalScrollbar->frameRect().y() + m _horizontalScrollbar->frameRect().height();
4055 int horizontalScrollbarXMin = m_horizontalScrollbar->frameRect().x() + m _horizontalScrollbar->frameRect().width();
4056
4057 return viewPoint.y() > horizontalScrollbarYMin && viewPoint.y() < horizo ntalScrollbarYMax && viewPoint.x() > horizontalScrollbarXMin;
4058 }
4059
4060 int verticalScrollbarXMin = m_verticalScrollbar->frameRect().x();
4061 int verticalScrollbarXMax = m_verticalScrollbar->frameRect().x() + m_vertica lScrollbar->frameRect().width();
4062 int verticalScrollbarYMin = m_verticalScrollbar->frameRect().y() + m_vertica lScrollbar->frameRect().height();
4063
4064 return viewPoint.x() > verticalScrollbarXMin && viewPoint.x() < verticalScro llbarXMax && viewPoint.y() > verticalScrollbarYMin;
4065 }
4066
4067 bool FrameView::scrollbarCornerPresent() const
4068 {
4069 return (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0)
4070 || (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0) ;
4071 }
4072
4073 IntRect FrameView::convertFromScrollbarToContainingView(const Scrollbar* scrollb ar, const IntRect& localRect) const
4074 {
4075 // Scrollbars won't be transformed within us
4076 IntRect newRect = localRect;
4077 newRect.moveBy(scrollbar->location());
4078 return newRect;
4079 }
4080
4081 IntRect FrameView::convertFromContainingViewToScrollbar(const Scrollbar* scrollb ar, const IntRect& parentRect) const
4082 {
4083 IntRect newRect = parentRect;
4084 // Scrollbars won't be transformed within us
4085 newRect.moveBy(-scrollbar->location());
4086 return newRect;
4087 }
4088
4089 // FIXME: test these on windows
4090 IntPoint FrameView::convertFromScrollbarToContainingView(const Scrollbar* scroll bar, const IntPoint& localPoint) const
4091 {
4092 // Scrollbars won't be transformed within us
4093 IntPoint newPoint = localPoint;
4094 newPoint.moveBy(scrollbar->location());
4095 return newPoint;
4096 }
4097
4098 IntPoint FrameView::convertFromContainingViewToScrollbar(const Scrollbar* scroll bar, const IntPoint& parentPoint) const
4099 {
4100 IntPoint newPoint = parentPoint;
4101 // Scrollbars won't be transformed within us
4102 newPoint.moveBy(-scrollbar->location());
4103 return newPoint;
4104 }
4105
4106 void FrameView::setParentVisible(bool visible)
4107 {
4108 if (isParentVisible() == visible)
4109 return;
4110
4111 Widget::setParentVisible(visible);
4112
4113 if (!isSelfVisible())
4114 return;
4115
4116 HashSet<RefPtr<Widget> >::iterator end = m_children.end();
4117 for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it != end; ++it)
4118 (*it)->setParentVisible(visible);
4119 }
4120
4121 void FrameView::show()
4122 {
4123 if (!isSelfVisible()) {
4124 setSelfVisible(true);
4125 if (isParentVisible()) {
4126 HashSet<RefPtr<Widget> >::iterator end = m_children.end();
4127 for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it != end; ++it)
4128 (*it)->setParentVisible(true);
4129 }
4130 }
4131
4132 Widget::show();
4133 }
4134
4135 void FrameView::hide()
4136 {
4137 if (isSelfVisible()) {
4138 if (isParentVisible()) {
4139 HashSet<RefPtr<Widget> >::iterator end = m_children.end();
4140 for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it != end; ++it)
4141 (*it)->setParentVisible(false);
4142 }
4143 setSelfVisible(false);
4144 }
4145
4146 Widget::hide();
4147 }
4148
4149 void FrameView::addPanScrollIcon(const IntPoint& iconPosition)
4150 {
4151 HostWindow* window = hostWindow();
4152 if (!window)
4153 return;
4154 m_drawPanScrollIcon = true;
4155 m_panScrollIconPoint = IntPoint(iconPosition.x() - panIconSizeLength / 2 , i conPosition.y() - panIconSizeLength / 2);
4156 window->invalidateContentsAndRootView(IntRect(m_panScrollIconPoint, IntSize( panIconSizeLength, panIconSizeLength)));
4157 }
4158
4159 void FrameView::removePanScrollIcon()
4160 {
4161 HostWindow* window = hostWindow();
4162 if (!window)
4163 return;
4164 m_drawPanScrollIcon = false;
4165 window->invalidateContentsAndRootView(IntRect(m_panScrollIconPoint, IntSize( panIconSizeLength, panIconSizeLength)));
4166 }
4167
4168 void FrameView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAll , bool updatePositionSynchronously)
4169 {
4170 if (scrollOrigin() == origin)
4171 return;
4172
4173 ScrollableArea::setScrollOrigin(origin);
4174
4175 // Update if the scroll origin changes, since our position will be different if the content size did not change.
4176 if (updatePositionAtAll && updatePositionSynchronously)
4177 updateScrollbars(scrollOffset());
4178 }
4179
3045 } // namespace blink 4180 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698