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

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

Issue 459633002: Autosizing storage doesnot belong on FrameView (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Aligned with review comments Created 6 years, 4 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
« no previous file with comments | « Source/core/frame/FrameView.h ('k') | Source/core/frame/FrameViewAutoSizeInfo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 , m_isTransparent(false) 106 , m_isTransparent(false)
107 , m_baseBackgroundColor(Color::white) 107 , m_baseBackgroundColor(Color::white)
108 , m_mediaType("screen") 108 , m_mediaType("screen")
109 , m_overflowStatusDirty(true) 109 , m_overflowStatusDirty(true)
110 , m_viewportRenderer(0) 110 , m_viewportRenderer(0)
111 , m_wasScrolledByUser(false) 111 , m_wasScrolledByUser(false)
112 , m_inProgrammaticScroll(false) 112 , m_inProgrammaticScroll(false)
113 , m_safeToPropagateScrollToParent(true) 113 , m_safeToPropagateScrollToParent(true)
114 , m_isTrackingPaintInvalidations(false) 114 , m_isTrackingPaintInvalidations(false)
115 , m_scrollCorner(nullptr) 115 , m_scrollCorner(nullptr)
116 , m_shouldAutoSize(false)
117 , m_inAutoSize(false)
118 , m_didRunAutosize(false)
119 , m_hasSoftwareFilters(false) 116 , m_hasSoftwareFilters(false)
120 , m_visibleContentScaleFactor(1) 117 , m_visibleContentScaleFactor(1)
121 , m_inputEventsScaleFactorForEmulation(1) 118 , m_inputEventsScaleFactorForEmulation(1)
122 , m_layoutSizeFixedToFrameSize(true) 119 , m_layoutSizeFixedToFrameSize(true)
123 , m_didScrollTimer(this, &FrameView::didScrollTimerFired) 120 , m_didScrollTimer(this, &FrameView::didScrollTimerFired)
124 { 121 {
125 ASSERT(m_frame); 122 ASSERT(m_frame);
126 init(); 123 init();
127 124
128 if (!m_frame->isMainFrame()) 125 if (!m_frame->isMainFrame())
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 if (body && body->renderer()) { 848 if (body && body->renderer()) {
852 if (isHTMLFrameSetElement(*body)) { 849 if (isHTMLFrameSetElement(*body)) {
853 body->renderer()->setChildNeedsLayout(); 850 body->renderer()->setChildNeedsLayout();
854 } else if (isHTMLBodyElement(*body)) { 851 } else if (isHTMLBodyElement(*body)) {
855 if (!m_firstLayout && m_size.height() != layoutSize().height () && body->renderer()->enclosingBox()->stretchesToViewport()) 852 if (!m_firstLayout && m_size.height() != layoutSize().height () && body->renderer()->enclosingBox()->stretchesToViewport())
856 body->renderer()->setChildNeedsLayout(); 853 body->renderer()->setChildNeedsLayout();
857 } 854 }
858 } 855 }
859 } 856 }
860 updateCounters(); 857 updateCounters();
861 autoSizeIfEnabled(); 858 if (m_autoSizeInfo)
859 m_autoSizeInfo->autoSizeIfNeeded();
862 860
863 ScrollbarMode hMode; 861 ScrollbarMode hMode;
864 ScrollbarMode vMode; 862 ScrollbarMode vMode;
865 calculateScrollbarModesForLayoutAndSetViewportRenderer(hMode, vMode); 863 calculateScrollbarModesForLayoutAndSetViewportRenderer(hMode, vMode);
866 864
867 if (!inSubtreeLayout) { 865 if (!inSubtreeLayout) {
868 // Now set our scrollbar state for the layout. 866 // Now set our scrollbar state for the layout.
869 ScrollbarMode currentHMode = horizontalScrollbarMode(); 867 ScrollbarMode currentHMode = horizontalScrollbarMode();
870 ScrollbarMode currentVMode = verticalScrollbarMode(); 868 ScrollbarMode currentVMode = verticalScrollbarMode();
871 869
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 1662
1665 if (!useOverlayScrollbars) 1663 if (!useOverlayScrollbars)
1666 renderView()->compositor()->frameViewDidChangeSize(); 1664 renderView()->compositor()->frameViewDidChangeSize();
1667 } 1665 }
1668 } 1666 }
1669 1667
1670 void FrameView::handleLoadCompleted() 1668 void FrameView::handleLoadCompleted()
1671 { 1669 {
1672 // Once loading has completed, allow autoSize one last opportunity to 1670 // Once loading has completed, allow autoSize one last opportunity to
1673 // reduce the size of the frame. 1671 // reduce the size of the frame.
1674 autoSizeIfEnabled(); 1672 if (m_autoSizeInfo)
1673 m_autoSizeInfo->autoSizeIfNeeded();
1675 } 1674 }
1676 1675
1677 void FrameView::scheduleRelayout() 1676 void FrameView::scheduleRelayout()
1678 { 1677 {
1679 ASSERT(m_frame->view() == this); 1678 ASSERT(m_frame->view() == this);
1680 1679
1681 if (isSubtreeLayout()) { 1680 if (isSubtreeLayout()) {
1682 m_layoutSubtreeRoot->markContainingBlocksForLayout(false); 1681 m_layoutSubtreeRoot->markContainingBlocksForLayout(false);
1683 m_layoutSubtreeRoot = 0; 1682 m_layoutSubtreeRoot = 0;
1684 } 1683 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 return; 2020 return;
2022 2021
2023 for (RenderObject* renderer = view; renderer; renderer = renderer->nextInPre Order()) { 2022 for (RenderObject* renderer = view; renderer; renderer = renderer->nextInPre Order()) {
2024 if (!renderer->isCounter()) 2023 if (!renderer->isCounter())
2025 continue; 2024 continue;
2026 2025
2027 toRenderCounter(renderer)->updateCounter(); 2026 toRenderCounter(renderer)->updateCounter();
2028 } 2027 }
2029 } 2028 }
2030 2029
2031 void FrameView::autoSizeIfEnabled()
2032 {
2033 if (!m_shouldAutoSize)
2034 return;
2035
2036 if (m_inAutoSize)
2037 return;
2038
2039 TemporaryChange<bool> changeInAutoSize(m_inAutoSize, true);
2040
2041 Document* document = frame().document();
2042 if (!document || !document->isActive())
2043 return;
2044
2045 Element* documentElement = document->documentElement();
2046 if (!documentElement)
2047 return;
2048
2049 // If this is the first time we run autosize, start from small height and
2050 // allow it to grow.
2051 if (!m_didRunAutosize)
2052 resize(frameRect().width(), m_minAutoSize.height());
2053
2054 IntSize size = frameRect().size();
2055
2056 // Do the resizing twice. The first time is basically a rough calculation us ing the preferred width
2057 // which may result in a height change during the second iteration.
2058 for (int i = 0; i < 2; i++) {
2059 // Update various sizes including contentsSize, scrollHeight, etc.
2060 document->updateLayoutIgnorePendingStylesheets();
2061
2062 RenderView* renderView = document->renderView();
2063 if (!renderView)
2064 return;
2065
2066 int width = renderView->minPreferredLogicalWidth();
2067
2068 RenderBox* documentRenderBox = documentElement->renderBox();
2069 if (!documentRenderBox)
2070 return;
2071
2072 int height = documentRenderBox->scrollHeight();
2073 IntSize newSize(width, height);
2074
2075 // Check to see if a scrollbar is needed for a given dimension and
2076 // if so, increase the other dimension to account for the scrollbar.
2077 // Since the dimensions are only for the view rectangle, once a
2078 // dimension exceeds the maximum, there is no need to increase it furthe r.
2079 if (newSize.width() > m_maxAutoSize.width()) {
2080 RefPtr<Scrollbar> localHorizontalScrollbar = horizontalScrollbar();
2081 if (!localHorizontalScrollbar)
2082 localHorizontalScrollbar = createScrollbar(HorizontalScrollbar);
2083 if (!localHorizontalScrollbar->isOverlayScrollbar())
2084 newSize.setHeight(newSize.height() + localHorizontalScrollbar->h eight());
2085
2086 // Don't bother checking for a vertical scrollbar because the width is at
2087 // already greater the maximum.
2088 } else if (newSize.height() > m_maxAutoSize.height()) {
2089 RefPtr<Scrollbar> localVerticalScrollbar = verticalScrollbar();
2090 if (!localVerticalScrollbar)
2091 localVerticalScrollbar = createScrollbar(VerticalScrollbar);
2092 if (!localVerticalScrollbar->isOverlayScrollbar())
2093 newSize.setWidth(newSize.width() + localVerticalScrollbar->width ());
2094
2095 // Don't bother checking for a horizontal scrollbar because the heig ht is
2096 // already greater the maximum.
2097 }
2098
2099 // Ensure the size is at least the min bounds.
2100 newSize = newSize.expandedTo(m_minAutoSize);
2101
2102 // Bound the dimensions by the max bounds and determine what scrollbars to show.
2103 ScrollbarMode horizonalScrollbarMode = ScrollbarAlwaysOff;
2104 if (newSize.width() > m_maxAutoSize.width()) {
2105 newSize.setWidth(m_maxAutoSize.width());
2106 horizonalScrollbarMode = ScrollbarAlwaysOn;
2107 }
2108 ScrollbarMode verticalScrollbarMode = ScrollbarAlwaysOff;
2109 if (newSize.height() > m_maxAutoSize.height()) {
2110 newSize.setHeight(m_maxAutoSize.height());
2111 verticalScrollbarMode = ScrollbarAlwaysOn;
2112 }
2113
2114 if (newSize == size)
2115 continue;
2116
2117 // While loading only allow the size to increase (to avoid twitching dur ing intermediate smaller states)
2118 // unless autoresize has just been turned on or the maximum size is smal ler than the current size.
2119 if (m_didRunAutosize && size.height() <= m_maxAutoSize.height() && size. width() <= m_maxAutoSize.width()
2120 && !m_frame->document()->loadEventFinished() && (newSize.height() < size.height() || newSize.width() < size.width()))
2121 break;
2122
2123 resize(newSize.width(), newSize.height());
2124 // Force the scrollbar state to avoid the scrollbar code adding them and causing them to be needed. For example,
2125 // a vertical scrollbar may cause text to wrap and thus increase the hei ght (which is the only reason the scollbar is needed).
2126 setVerticalScrollbarLock(false);
2127 setHorizontalScrollbarLock(false);
2128 setScrollbarModes(horizonalScrollbarMode, verticalScrollbarMode, true, t rue);
2129 }
2130 m_didRunAutosize = true;
2131 }
2132
2133 void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverf low) 2030 void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverf low)
2134 { 2031 {
2135 if (!m_viewportRenderer) 2032 if (!m_viewportRenderer)
2136 return; 2033 return;
2137 2034
2138 if (m_overflowStatusDirty) { 2035 if (m_overflowStatusDirty) {
2139 m_horizontalOverflow = horizontalOverflow; 2036 m_horizontalOverflow = horizontalOverflow;
2140 m_verticalOverflow = verticalOverflow; 2037 m_verticalOverflow = verticalOverflow;
2141 m_overflowStatusDirty = false; 2038 m_overflowStatusDirty = false;
2142 return; 2039 return;
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 lifecycle().advanceTo(DocumentLifecycle::PaintInvalidationClean); 2631 lifecycle().advanceTo(DocumentLifecycle::PaintInvalidationClean);
2735 2632
2736 for (Frame* child = m_frame->tree().firstChild(); child; child = child->tree ().nextSibling()) { 2633 for (Frame* child = m_frame->tree().firstChild(); child; child = child->tree ().nextSibling()) {
2737 if (!child->isLocalFrame()) 2634 if (!child->isLocalFrame())
2738 continue; 2635 continue;
2739 2636
2740 toLocalFrame(child)->view()->invalidateTreeIfNeededRecursive(); 2637 toLocalFrame(child)->view()->invalidateTreeIfNeededRecursive();
2741 } 2638 }
2742 } 2639 }
2743 2640
2744 void FrameView::enableAutoSizeMode(bool enable, const IntSize& minSize, const In tSize& maxSize) 2641 void FrameView::enableAutoSizeMode(const IntSize& minSize, const IntSize& maxSiz e)
2745 { 2642 {
2746 ASSERT(!enable || !minSize.isEmpty()); 2643 if (!m_autoSizeInfo)
2747 ASSERT(minSize.width() <= maxSize.width()); 2644 m_autoSizeInfo = adoptPtr(new FrameViewAutoSizeInfo(this));
2748 ASSERT(minSize.height() <= maxSize.height());
2749 2645
2750 if (m_shouldAutoSize == enable && m_minAutoSize == minSize && m_maxAutoSize == maxSize) 2646 m_autoSizeInfo->configureAutoSizeMode(minSize, maxSize);
2751 return;
2752
2753
2754 m_shouldAutoSize = enable;
2755 m_minAutoSize = minSize;
2756 m_maxAutoSize = maxSize;
2757 m_didRunAutosize = false;
2758
2759 setLayoutSizeFixedToFrameSize(enable);
2760 setNeedsLayout();
2761 scheduleRelayout();
2762 if (m_shouldAutoSize)
2763 return;
2764
2765 // Since autosize mode forces the scrollbar mode, change them to being auto.
2766 setVerticalScrollbarLock(false);
2767 setHorizontalScrollbarLock(false);
2768 setScrollbarModes(ScrollbarAuto, ScrollbarAuto);
2769 } 2647 }
2770 2648
2771 void FrameView::forceLayout(bool allowSubtree) 2649 void FrameView::forceLayout(bool allowSubtree)
2772 { 2650 {
2773 layout(allowSubtree); 2651 layout(allowSubtree);
2774 } 2652 }
2775 2653
2776 void FrameView::forceLayoutForPagination(const FloatSize& pageSize, const FloatS ize& originalPageSize, float maximumShrinkFactor) 2654 void FrameView::forceLayoutForPagination(const FloatSize& pageSize, const FloatS ize& originalPageSize, float maximumShrinkFactor)
2777 { 2655 {
2778 // Dumping externalRepresentation(m_frame->renderer()).ascii() is a good tri ck to see 2656 // Dumping externalRepresentation(m_frame->renderer()).ascii() is a good tri ck to see
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
3131 void FrameView::willRemoveScrollbar(Scrollbar* scrollbar, ScrollbarOrientation o rientation) 3009 void FrameView::willRemoveScrollbar(Scrollbar* scrollbar, ScrollbarOrientation o rientation)
3132 { 3010 {
3133 ScrollableArea::willRemoveScrollbar(scrollbar, orientation); 3011 ScrollableArea::willRemoveScrollbar(scrollbar, orientation);
3134 if (AXObjectCache* cache = axObjectCache()) { 3012 if (AXObjectCache* cache = axObjectCache()) {
3135 cache->remove(scrollbar); 3013 cache->remove(scrollbar);
3136 cache->handleScrollbarUpdate(this); 3014 cache->handleScrollbarUpdate(this);
3137 } 3015 }
3138 } 3016 }
3139 3017
3140 } // namespace blink 3018 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/FrameView.h ('k') | Source/core/frame/FrameViewAutoSizeInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698