| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/FrameViewAutoSizeInfo.h" | 6 #include "core/frame/FrameViewAutoSizeInfo.h" |
| 7 | 7 |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/rendering/RenderBox.h" | 10 #include "core/rendering/RenderBox.h" |
| 11 #include "core/rendering/RenderView.h" | 11 #include "core/rendering/RenderView.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 FrameViewAutoSizeInfo::FrameViewAutoSizeInfo(FrameView* view) | 15 FrameViewAutoSizeInfo::FrameViewAutoSizeInfo(FrameView* view) |
| 16 : m_frameView(view) | 16 : m_frameView(view) |
| 17 , m_inAutoSize(false) | 17 , m_inAutoSize(false) |
| 18 , m_didRunAutosize(false) | 18 , m_didRunAutosize(false) |
| 19 { | 19 { |
| 20 ASSERT(m_frameView); | 20 ASSERT(m_frameView); |
| 21 } | 21 } |
| 22 | 22 |
| 23 FrameViewAutoSizeInfo::~FrameViewAutoSizeInfo() | 23 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(FrameViewAutoSizeInfo); |
| 24 |
| 25 void FrameViewAutoSizeInfo::trace(Visitor* visitor) |
| 24 { | 26 { |
| 25 removeAutoSizeMode(); | 27 visitor->trace(m_frameView); |
| 26 } | 28 } |
| 27 | 29 |
| 28 void FrameViewAutoSizeInfo::configureAutoSizeMode(const IntSize& minSize, const
IntSize& maxSize) | 30 void FrameViewAutoSizeInfo::configureAutoSizeMode(const IntSize& minSize, const
IntSize& maxSize) |
| 29 { | 31 { |
| 30 ASSERT(!minSize.isEmpty()); | 32 ASSERT(!minSize.isEmpty()); |
| 31 ASSERT(minSize.width() <= maxSize.width()); | 33 ASSERT(minSize.width() <= maxSize.width()); |
| 32 ASSERT(minSize.height() <= maxSize.height()); | 34 ASSERT(minSize.height() <= maxSize.height()); |
| 33 | 35 |
| 34 if (m_minAutoSize == minSize && m_maxAutoSize == maxSize) | 36 if (m_minAutoSize == minSize && m_maxAutoSize == maxSize) |
| 35 return; | 37 return; |
| 36 | 38 |
| 37 m_minAutoSize = minSize; | 39 m_minAutoSize = minSize; |
| 38 m_maxAutoSize = maxSize; | 40 m_maxAutoSize = maxSize; |
| 39 m_didRunAutosize = false; | 41 m_didRunAutosize = false; |
| 40 | 42 |
| 41 m_frameView->setLayoutSizeFixedToFrameSize(true); | 43 m_frameView->setLayoutSizeFixedToFrameSize(true); |
| 42 m_frameView->setNeedsLayout(); | 44 m_frameView->setNeedsLayout(); |
| 43 m_frameView->scheduleRelayout(); | 45 m_frameView->scheduleRelayout(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void FrameViewAutoSizeInfo::removeAutoSizeMode() | |
| 47 { | |
| 48 m_frameView->setLayoutSizeFixedToFrameSize(false); | |
| 49 m_frameView->setNeedsLayout(); | |
| 50 m_frameView->scheduleRelayout(); | |
| 51 | |
| 52 // Since autosize mode forces the scrollbar mode, change them to being auto. | |
| 53 m_frameView->setVerticalScrollbarLock(false); | |
| 54 m_frameView->setHorizontalScrollbarLock(false); | |
| 55 m_frameView->setScrollbarModes(ScrollbarAuto, ScrollbarAuto); | |
| 56 } | |
| 57 | |
| 58 void FrameViewAutoSizeInfo::autoSizeIfNeeded() | 48 void FrameViewAutoSizeInfo::autoSizeIfNeeded() |
| 59 { | 49 { |
| 60 if (m_inAutoSize) | 50 if (m_inAutoSize) |
| 61 return; | 51 return; |
| 62 | 52 |
| 63 TemporaryChange<bool> changeInAutoSize(m_inAutoSize, true); | 53 TemporaryChange<bool> changeInAutoSize(m_inAutoSize, true); |
| 64 | 54 |
| 65 Document* document = m_frameView->frame().document(); | 55 Document* document = m_frameView->frame().document(); |
| 66 if (!document || !document->isActive()) | 56 if (!document || !document->isActive()) |
| 67 return; | 57 return; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 94 return; | 84 return; |
| 95 | 85 |
| 96 int height = documentRenderBox->scrollHeight(); | 86 int height = documentRenderBox->scrollHeight(); |
| 97 IntSize newSize(width, height); | 87 IntSize newSize(width, height); |
| 98 | 88 |
| 99 // Check to see if a scrollbar is needed for a given dimension and | 89 // Check to see if a scrollbar is needed for a given dimension and |
| 100 // if so, increase the other dimension to account for the scrollbar. | 90 // if so, increase the other dimension to account for the scrollbar. |
| 101 // Since the dimensions are only for the view rectangle, once a | 91 // Since the dimensions are only for the view rectangle, once a |
| 102 // dimension exceeds the maximum, there is no need to increase it furthe
r. | 92 // dimension exceeds the maximum, there is no need to increase it furthe
r. |
| 103 if (newSize.width() > m_maxAutoSize.width()) { | 93 if (newSize.width() > m_maxAutoSize.width()) { |
| 104 RefPtr<Scrollbar> localHorizontalScrollbar = m_frameView->horizontal
Scrollbar(); | 94 RefPtrWillBeRawPtr<Scrollbar> localHorizontalScrollbar = m_frameView
->horizontalScrollbar(); |
| 105 if (!localHorizontalScrollbar) | 95 if (!localHorizontalScrollbar) |
| 106 localHorizontalScrollbar = m_frameView->createScrollbar(Horizont
alScrollbar); | 96 localHorizontalScrollbar = m_frameView->createScrollbar(Horizont
alScrollbar); |
| 107 if (!localHorizontalScrollbar->isOverlayScrollbar()) | 97 if (!localHorizontalScrollbar->isOverlayScrollbar()) |
| 108 newSize.setHeight(newSize.height() + localHorizontalScrollbar->h
eight()); | 98 newSize.setHeight(newSize.height() + localHorizontalScrollbar->h
eight()); |
| 109 | 99 |
| 110 // Don't bother checking for a vertical scrollbar because the width
is at | 100 // Don't bother checking for a vertical scrollbar because the width
is at |
| 111 // already greater the maximum. | 101 // already greater the maximum. |
| 112 } else if (newSize.height() > m_maxAutoSize.height()) { | 102 } else if (newSize.height() > m_maxAutoSize.height()) { |
| 113 RefPtr<Scrollbar> localVerticalScrollbar = m_frameView->verticalScro
llbar(); | 103 RefPtrWillBeRawPtr<Scrollbar> localVerticalScrollbar = m_frameView->
verticalScrollbar(); |
| 114 if (!localVerticalScrollbar) | 104 if (!localVerticalScrollbar) |
| 115 localVerticalScrollbar = m_frameView->createScrollbar(VerticalSc
rollbar); | 105 localVerticalScrollbar = m_frameView->createScrollbar(VerticalSc
rollbar); |
| 116 if (!localVerticalScrollbar->isOverlayScrollbar()) | 106 if (!localVerticalScrollbar->isOverlayScrollbar()) |
| 117 newSize.setWidth(newSize.width() + localVerticalScrollbar->width
()); | 107 newSize.setWidth(newSize.width() + localVerticalScrollbar->width
()); |
| 118 | 108 |
| 119 // Don't bother checking for a horizontal scrollbar because the heig
ht is | 109 // Don't bother checking for a horizontal scrollbar because the heig
ht is |
| 120 // already greater the maximum. | 110 // already greater the maximum. |
| 121 } | 111 } |
| 122 | 112 |
| 123 // Ensure the size is at least the min bounds. | 113 // Ensure the size is at least the min bounds. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 148 // Force the scrollbar state to avoid the scrollbar code adding them and
causing them to be needed. For example, | 138 // Force the scrollbar state to avoid the scrollbar code adding them and
causing them to be needed. For example, |
| 149 // a vertical scrollbar may cause text to wrap and thus increase the hei
ght (which is the only reason the scollbar is needed). | 139 // a vertical scrollbar may cause text to wrap and thus increase the hei
ght (which is the only reason the scollbar is needed). |
| 150 m_frameView->setVerticalScrollbarLock(false); | 140 m_frameView->setVerticalScrollbarLock(false); |
| 151 m_frameView->setHorizontalScrollbarLock(false); | 141 m_frameView->setHorizontalScrollbarLock(false); |
| 152 m_frameView->setScrollbarModes(horizonalScrollbarMode, verticalScrollbar
Mode, true, true); | 142 m_frameView->setScrollbarModes(horizonalScrollbarMode, verticalScrollbar
Mode, true, true); |
| 153 } | 143 } |
| 154 m_didRunAutosize = true; | 144 m_didRunAutosize = true; |
| 155 } | 145 } |
| 156 | 146 |
| 157 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |