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

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: Rebased 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
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 autoSizeInfo().autoSizeIfEnabled();
eseidel 2014/08/19 16:31:18 This caused us to allocate the AutosizeInfo. I wo
Shanmuga Pandi 2014/08/20 14:54:12 Done.
862 859
863 ScrollbarMode hMode; 860 ScrollbarMode hMode;
864 ScrollbarMode vMode; 861 ScrollbarMode vMode;
865 calculateScrollbarModesForLayoutAndSetViewportRenderer(hMode, vMode); 862 calculateScrollbarModesForLayoutAndSetViewportRenderer(hMode, vMode);
866 863
867 if (!inSubtreeLayout) { 864 if (!inSubtreeLayout) {
868 // Now set our scrollbar state for the layout. 865 // Now set our scrollbar state for the layout.
869 ScrollbarMode currentHMode = horizontalScrollbarMode(); 866 ScrollbarMode currentHMode = horizontalScrollbarMode();
870 ScrollbarMode currentVMode = verticalScrollbarMode(); 867 ScrollbarMode currentVMode = verticalScrollbarMode();
871 868
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 1662
1666 if (!useOverlayScrollbars) 1663 if (!useOverlayScrollbars)
1667 renderView()->compositor()->frameViewDidChangeSize(); 1664 renderView()->compositor()->frameViewDidChangeSize();
1668 } 1665 }
1669 } 1666 }
1670 1667
1671 void FrameView::handleLoadCompleted() 1668 void FrameView::handleLoadCompleted()
1672 { 1669 {
1673 // Once loading has completed, allow autoSize one last opportunity to 1670 // Once loading has completed, allow autoSize one last opportunity to
1674 // reduce the size of the frame. 1671 // reduce the size of the frame.
1675 autoSizeIfEnabled(); 1672 autoSizeInfo().autoSizeIfEnabled();
1676 } 1673 }
1677 1674
1678 void FrameView::scheduleRelayout() 1675 void FrameView::scheduleRelayout()
1679 { 1676 {
1680 ASSERT(m_frame->view() == this); 1677 ASSERT(m_frame->view() == this);
1681 1678
1682 if (isSubtreeLayout()) { 1679 if (isSubtreeLayout()) {
1683 m_layoutSubtreeRoot->markContainingBlocksForLayout(false); 1680 m_layoutSubtreeRoot->markContainingBlocksForLayout(false);
1684 m_layoutSubtreeRoot = 0; 1681 m_layoutSubtreeRoot = 0;
1685 } 1682 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 return; 2019 return;
2023 2020
2024 for (RenderObject* renderer = view; renderer; renderer = renderer->nextInPre Order()) { 2021 for (RenderObject* renderer = view; renderer; renderer = renderer->nextInPre Order()) {
2025 if (!renderer->isCounter()) 2022 if (!renderer->isCounter())
2026 continue; 2023 continue;
2027 2024
2028 toRenderCounter(renderer)->updateCounter(); 2025 toRenderCounter(renderer)->updateCounter();
2029 } 2026 }
2030 } 2027 }
2031 2028
2032 void FrameView::autoSizeIfEnabled()
2033 {
2034 if (!m_shouldAutoSize)
2035 return;
2036
2037 if (m_inAutoSize)
2038 return;
2039
2040 TemporaryChange<bool> changeInAutoSize(m_inAutoSize, true);
2041
2042 Document* document = frame().document();
2043 if (!document || !document->isActive())
2044 return;
2045
2046 Element* documentElement = document->documentElement();
2047 if (!documentElement)
2048 return;
2049
2050 // If this is the first time we run autosize, start from small height and
2051 // allow it to grow.
2052 if (!m_didRunAutosize)
2053 resize(frameRect().width(), m_minAutoSize.height());
2054
2055 IntSize size = frameRect().size();
2056
2057 // Do the resizing twice. The first time is basically a rough calculation us ing the preferred width
2058 // which may result in a height change during the second iteration.
2059 for (int i = 0; i < 2; i++) {
2060 // Update various sizes including contentsSize, scrollHeight, etc.
2061 document->updateLayoutIgnorePendingStylesheets();
2062
2063 RenderView* renderView = document->renderView();
2064 if (!renderView)
2065 return;
2066
2067 int width = renderView->minPreferredLogicalWidth();
2068
2069 RenderBox* documentRenderBox = documentElement->renderBox();
2070 if (!documentRenderBox)
2071 return;
2072
2073 int height = documentRenderBox->scrollHeight();
2074 IntSize newSize(width, height);
2075
2076 // Check to see if a scrollbar is needed for a given dimension and
2077 // if so, increase the other dimension to account for the scrollbar.
2078 // Since the dimensions are only for the view rectangle, once a
2079 // dimension exceeds the maximum, there is no need to increase it furthe r.
2080 if (newSize.width() > m_maxAutoSize.width()) {
2081 RefPtr<Scrollbar> localHorizontalScrollbar = horizontalScrollbar();
2082 if (!localHorizontalScrollbar)
2083 localHorizontalScrollbar = createScrollbar(HorizontalScrollbar);
2084 if (!localHorizontalScrollbar->isOverlayScrollbar())
2085 newSize.setHeight(newSize.height() + localHorizontalScrollbar->h eight());
2086
2087 // Don't bother checking for a vertical scrollbar because the width is at
2088 // already greater the maximum.
2089 } else if (newSize.height() > m_maxAutoSize.height()) {
2090 RefPtr<Scrollbar> localVerticalScrollbar = verticalScrollbar();
2091 if (!localVerticalScrollbar)
2092 localVerticalScrollbar = createScrollbar(VerticalScrollbar);
2093 if (!localVerticalScrollbar->isOverlayScrollbar())
2094 newSize.setWidth(newSize.width() + localVerticalScrollbar->width ());
2095
2096 // Don't bother checking for a horizontal scrollbar because the heig ht is
2097 // already greater the maximum.
2098 }
2099
2100 // Ensure the size is at least the min bounds.
2101 newSize = newSize.expandedTo(m_minAutoSize);
2102
2103 // Bound the dimensions by the max bounds and determine what scrollbars to show.
2104 ScrollbarMode horizonalScrollbarMode = ScrollbarAlwaysOff;
2105 if (newSize.width() > m_maxAutoSize.width()) {
2106 newSize.setWidth(m_maxAutoSize.width());
2107 horizonalScrollbarMode = ScrollbarAlwaysOn;
2108 }
2109 ScrollbarMode verticalScrollbarMode = ScrollbarAlwaysOff;
2110 if (newSize.height() > m_maxAutoSize.height()) {
2111 newSize.setHeight(m_maxAutoSize.height());
2112 verticalScrollbarMode = ScrollbarAlwaysOn;
2113 }
2114
2115 if (newSize == size)
2116 continue;
2117
2118 // While loading only allow the size to increase (to avoid twitching dur ing intermediate smaller states)
2119 // unless autoresize has just been turned on or the maximum size is smal ler than the current size.
2120 if (m_didRunAutosize && size.height() <= m_maxAutoSize.height() && size. width() <= m_maxAutoSize.width()
2121 && !m_frame->document()->loadEventFinished() && (newSize.height() < size.height() || newSize.width() < size.width()))
2122 break;
2123
2124 resize(newSize.width(), newSize.height());
2125 // Force the scrollbar state to avoid the scrollbar code adding them and causing them to be needed. For example,
2126 // a vertical scrollbar may cause text to wrap and thus increase the hei ght (which is the only reason the scollbar is needed).
2127 setVerticalScrollbarLock(false);
2128 setHorizontalScrollbarLock(false);
2129 setScrollbarModes(horizonalScrollbarMode, verticalScrollbarMode, true, t rue);
2130 }
2131 m_didRunAutosize = true;
2132 }
2133
2134 void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverf low) 2029 void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverf low)
2135 { 2030 {
2136 if (!m_viewportRenderer) 2031 if (!m_viewportRenderer)
2137 return; 2032 return;
2138 2033
2139 if (m_overflowStatusDirty) { 2034 if (m_overflowStatusDirty) {
2140 m_horizontalOverflow = horizontalOverflow; 2035 m_horizontalOverflow = horizontalOverflow;
2141 m_verticalOverflow = verticalOverflow; 2036 m_verticalOverflow = verticalOverflow;
2142 m_overflowStatusDirty = false; 2037 m_overflowStatusDirty = false;
2143 return; 2038 return;
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
2736 lifecycle().advanceTo(DocumentLifecycle::PaintInvalidationClean); 2631 lifecycle().advanceTo(DocumentLifecycle::PaintInvalidationClean);
2737 2632
2738 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()) {
2739 if (!child->isLocalFrame()) 2634 if (!child->isLocalFrame())
2740 continue; 2635 continue;
2741 2636
2742 toLocalFrame(child)->view()->invalidateTreeIfNeededRecursive(); 2637 toLocalFrame(child)->view()->invalidateTreeIfNeededRecursive();
2743 } 2638 }
2744 } 2639 }
2745 2640
2746 void FrameView::enableAutoSizeMode(bool enable, const IntSize& minSize, const In tSize& maxSize) 2641 void FrameView::enableAutoSizeMode(bool enable, const IntSize& minSize, const In tSize& maxSize)
eseidel 2014/08/19 16:35:00 I suspect we want to split enableAutoSizeMode out
Shanmuga Pandi 2014/08/20 14:54:12 Done.
2747 { 2642 {
2748 ASSERT(!enable || !minSize.isEmpty()); 2643 autoSizeInfo().enableAutoSizeMode(enable, minSize, maxSize);
2749 ASSERT(minSize.width() <= maxSize.width());
2750 ASSERT(minSize.height() <= maxSize.height());
2751
2752 if (m_shouldAutoSize == enable && m_minAutoSize == minSize && m_maxAutoSize == maxSize)
2753 return;
2754
2755
2756 m_shouldAutoSize = enable;
2757 m_minAutoSize = minSize;
2758 m_maxAutoSize = maxSize;
2759 m_didRunAutosize = false;
2760
2761 setLayoutSizeFixedToFrameSize(enable);
2762 setNeedsLayout();
2763 scheduleRelayout();
2764 if (m_shouldAutoSize)
2765 return;
2766
2767 // Since autosize mode forces the scrollbar mode, change them to being auto.
2768 setVerticalScrollbarLock(false);
2769 setHorizontalScrollbarLock(false);
2770 setScrollbarModes(ScrollbarAuto, ScrollbarAuto);
2771 } 2644 }
2772 2645
2773 void FrameView::forceLayout(bool allowSubtree) 2646 void FrameView::forceLayout(bool allowSubtree)
2774 { 2647 {
2775 layout(allowSubtree); 2648 layout(allowSubtree);
2776 } 2649 }
2777 2650
2778 void FrameView::forceLayoutForPagination(const FloatSize& pageSize, const FloatS ize& originalPageSize, float maximumShrinkFactor) 2651 void FrameView::forceLayoutForPagination(const FloatSize& pageSize, const FloatS ize& originalPageSize, float maximumShrinkFactor)
2779 { 2652 {
2780 // Dumping externalRepresentation(m_frame->renderer()).ascii() is a good tri ck to see 2653 // 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
3133 void FrameView::willRemoveScrollbar(Scrollbar* scrollbar, ScrollbarOrientation o rientation) 3006 void FrameView::willRemoveScrollbar(Scrollbar* scrollbar, ScrollbarOrientation o rientation)
3134 { 3007 {
3135 ScrollableArea::willRemoveScrollbar(scrollbar, orientation); 3008 ScrollableArea::willRemoveScrollbar(scrollbar, orientation);
3136 if (AXObjectCache* cache = axObjectCache()) { 3009 if (AXObjectCache* cache = axObjectCache()) {
3137 cache->remove(scrollbar); 3010 cache->remove(scrollbar);
3138 cache->handleScrollbarUpdate(this); 3011 cache->handleScrollbarUpdate(this);
3139 } 3012 }
3140 } 3013 }
3141 3014
3142 } // namespace blink 3015 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698