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

Side by Side Diff: Source/core/platform/ScrollView.cpp

Issue 23819019: Refactor fixed layout mode (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: git rebase Created 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 : m_horizontalScrollbarMode(ScrollbarAuto) 42 : m_horizontalScrollbarMode(ScrollbarAuto)
43 , m_verticalScrollbarMode(ScrollbarAuto) 43 , m_verticalScrollbarMode(ScrollbarAuto)
44 , m_horizontalScrollbarLock(false) 44 , m_horizontalScrollbarLock(false)
45 , m_verticalScrollbarLock(false) 45 , m_verticalScrollbarLock(false)
46 , m_canBlitOnScroll(true) 46 , m_canBlitOnScroll(true)
47 , m_scrollbarsAvoidingResizer(0) 47 , m_scrollbarsAvoidingResizer(0)
48 , m_scrollbarsSuppressed(false) 48 , m_scrollbarsSuppressed(false)
49 , m_inUpdateScrollbars(false) 49 , m_inUpdateScrollbars(false)
50 , m_updateScrollbarsPass(0) 50 , m_updateScrollbarsPass(0)
51 , m_drawPanScrollIcon(false) 51 , m_drawPanScrollIcon(false)
52 , m_useFixedLayout(false)
53 , m_paintsEntireContents(false) 52 , m_paintsEntireContents(false)
54 , m_clipsRepaints(true) 53 , m_clipsRepaints(true)
55 { 54 {
56 } 55 }
57 56
58 ScrollView::~ScrollView() 57 ScrollView::~ScrollView()
59 { 58 {
60 } 59 }
61 60
62 void ScrollView::addChild(PassRefPtr<Widget> prpChild) 61 void ScrollView::addChild(PassRefPtr<Widget> prpChild)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 void ScrollView::setPaintsEntireContents(bool paintsEntireContents) 178 void ScrollView::setPaintsEntireContents(bool paintsEntireContents)
180 { 179 {
181 m_paintsEntireContents = paintsEntireContents; 180 m_paintsEntireContents = paintsEntireContents;
182 } 181 }
183 182
184 void ScrollView::setClipsRepaints(bool clipsRepaints) 183 void ScrollView::setClipsRepaints(bool clipsRepaints)
185 { 184 {
186 m_clipsRepaints = clipsRepaints; 185 m_clipsRepaints = clipsRepaints;
187 } 186 }
188 187
189 IntSize ScrollView::unscaledVisibleContentSize(VisibleContentRectIncludesScrollb ars scrollbarInclusion) const 188 IntSize ScrollView::unscaledVisibleContentSize(IncludeScrollbarsInRect scrollbar Inclusion) const
189 {
190 return scrollbarInclusion == ExcludeScrollbars ? excludeScrollbars(frameRect ().size()) : frameRect().size();
191 }
192
193 IntSize ScrollView::excludeScrollbars(const IntSize& size) const
190 { 194 {
191 int verticalScrollbarWidth = 0; 195 int verticalScrollbarWidth = 0;
192 int horizontalScrollbarHeight = 0; 196 int horizontalScrollbarHeight = 0;
193 197
194 if (scrollbarInclusion == ExcludeScrollbars) { 198 if (Scrollbar* verticalBar = verticalScrollbar())
195 if (Scrollbar* verticalBar = verticalScrollbar()) 199 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa r->width() : 0;
196 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic alBar->width() : 0; 200 if (Scrollbar* horizontalBar = horizontalScrollbar())
197 if (Scrollbar* horizontalBar = horizontalScrollbar()) 201 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz ontalBar->height() : 0;
198 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? h orizontalBar->height() : 0;
199 }
200 202
201 return IntSize(max(0, width() - verticalScrollbarWidth), 203 return IntSize(max(0, size.width() - verticalScrollbarWidth),
202 max(0, height() - horizontalScrollbarHeight)); 204 max(0, size.height() - horizontalScrollbarHeight));
205
203 } 206 }
204 207
205 IntRect ScrollView::visibleContentRect(VisibleContentRectIncludesScrollbars scol lbarInclusion) const 208 IntRect ScrollView::visibleContentRect(IncludeScrollbarsInRect scollbarInclusion ) const
206 { 209 {
207 FloatSize visibleContentSize = unscaledVisibleContentSize(scollbarInclusion) ; 210 FloatSize visibleContentSize = unscaledVisibleContentSize(scollbarInclusion) ;
208 visibleContentSize.scale(1 / visibleContentScaleFactor()); 211 visibleContentSize.scale(1 / visibleContentScaleFactor());
209 return IntRect(IntPoint(m_scrollOffset), expandedIntSize(visibleContentSize) ); 212 return IntRect(IntPoint(m_scrollOffset), expandedIntSize(visibleContentSize) );
210 } 213 }
211 214
212 IntSize ScrollView::layoutSize(VisibleContentRectIncludesScrollbars scrollbarInc lusion) const
213 {
214 return m_fixedLayoutSize.isZero() || !m_useFixedLayout ? unscaledVisibleCont entSize(scrollbarInclusion) : m_fixedLayoutSize;
215 }
216
217 IntSize ScrollView::fixedLayoutSize() const
218 {
219 return m_fixedLayoutSize;
220 }
221
222 void ScrollView::setFixedLayoutSize(const IntSize& newSize)
223 {
224 if (fixedLayoutSize() == newSize)
225 return;
226 m_fixedLayoutSize = newSize;
227 updateScrollbars(scrollOffset());
228 if (m_useFixedLayout)
229 contentsResized();
230 }
231
232 bool ScrollView::useFixedLayout() const
233 {
234 return m_useFixedLayout;
235 }
236
237 void ScrollView::setUseFixedLayout(bool enable)
238 {
239 if (useFixedLayout() == enable)
240 return;
241 m_useFixedLayout = enable;
242 updateScrollbars(scrollOffset());
243 contentsResized();
244 }
245
246 IntSize ScrollView::contentsSize() const 215 IntSize ScrollView::contentsSize() const
247 { 216 {
248 return m_contentsSize; 217 return m_contentsSize;
249 } 218 }
250 219
251 void ScrollView::setContentsSize(const IntSize& newSize) 220 void ScrollView::setContentsSize(const IntSize& newSize)
252 { 221 {
253 if (contentsSize() == newSize) 222 if (contentsSize() == newSize)
254 return; 223 return;
255 m_contentsSize = newSize; 224 m_contentsSize = newSize;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 void ScrollView::updateScrollbars(const IntSize& desiredOffset) 330 void ScrollView::updateScrollbars(const IntSize& desiredOffset)
362 { 331 {
363 if (m_inUpdateScrollbars) 332 if (m_inUpdateScrollbars)
364 return; 333 return;
365 334
366 // If we came in here with the view already needing a layout, then go ahead and do that 335 // If we came in here with the view already needing a layout, then go ahead and do that
367 // first. (This will be the common case, e.g., when the page changes due to window resizing for example). 336 // first. (This will be the common case, e.g., when the page changes due to window resizing for example).
368 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total. 337 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total.
369 if (!m_scrollbarsSuppressed) { 338 if (!m_scrollbarsSuppressed) {
370 m_inUpdateScrollbars = true; 339 m_inUpdateScrollbars = true;
371 visibleContentsResized(); 340 scrollbarExistenceDidChange();
372 m_inUpdateScrollbars = false; 341 m_inUpdateScrollbars = false;
373 } 342 }
374 343
375 IntRect oldScrollCornerRect = scrollCornerRect(); 344 IntRect oldScrollCornerRect = scrollCornerRect();
376 345
377 bool hasHorizontalScrollbar = m_horizontalScrollbar; 346 bool hasHorizontalScrollbar = m_horizontalScrollbar;
378 bool hasVerticalScrollbar = m_verticalScrollbar; 347 bool hasVerticalScrollbar = m_verticalScrollbar;
379 348
380 bool newHasHorizontalScrollbar = hasHorizontalScrollbar; 349 bool newHasHorizontalScrollbar = hasHorizontalScrollbar;
381 bool newHasVerticalScrollbar = hasVerticalScrollbar; 350 bool newHasVerticalScrollbar = hasVerticalScrollbar;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 ScrollableArea::setScrollOrigin(IntPoint(scrollOrigin().x() - m_ verticalScrollbar->width(), scrollOrigin().y())); 405 ScrollableArea::setScrollOrigin(IntPoint(scrollOrigin().x() - m_ verticalScrollbar->width(), scrollOrigin().y()));
437 if (hasVerticalScrollbar) 406 if (hasVerticalScrollbar)
438 m_verticalScrollbar->invalidate(); 407 m_verticalScrollbar->invalidate();
439 setHasVerticalScrollbar(newHasVerticalScrollbar); 408 setHasVerticalScrollbar(newHasVerticalScrollbar);
440 } 409 }
441 410
442 if (scrollbarExistenceChanged) { 411 if (scrollbarExistenceChanged) {
443 if (scrollbarsAreOverlay) { 412 if (scrollbarsAreOverlay) {
444 // Synchronize status of scrollbar layers if necessary. 413 // Synchronize status of scrollbar layers if necessary.
445 m_inUpdateScrollbars = true; 414 m_inUpdateScrollbars = true;
446 visibleContentsResized(); 415 scrollbarExistenceDidChange();
447 m_inUpdateScrollbars = false; 416 m_inUpdateScrollbars = false;
448 } else if (m_updateScrollbarsPass < cMaxUpdateScrollbarsPass) { 417 } else if (m_updateScrollbarsPass < cMaxUpdateScrollbarsPass) {
449 m_updateScrollbarsPass++; 418 m_updateScrollbarsPass++;
450 contentsResized(); 419 contentsResized();
451 visibleContentsResized(); 420 scrollbarExistenceDidChange();
452 IntSize newDocSize = contentsSize(); 421 IntSize newDocSize = contentsSize();
453 if (newDocSize == docSize) { 422 if (newDocSize == docSize) {
454 // The layout with the new scroll state had no impact on 423 // The layout with the new scroll state had no impact on
455 // the document's overall size, so updateScrollbars didn't g et called. 424 // the document's overall size, so updateScrollbars didn't g et called.
456 // Recur manually. 425 // Recur manually.
457 updateScrollbars(desiredOffset); 426 updateScrollbars(desiredOffset);
458 } 427 }
459 m_updateScrollbarsPass--; 428 m_updateScrollbarsPass--;
460 } 429 }
461 } 430 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 701
733 void ScrollView::setFrameRect(const IntRect& newRect) 702 void ScrollView::setFrameRect(const IntRect& newRect)
734 { 703 {
735 IntRect oldRect = frameRect(); 704 IntRect oldRect = frameRect();
736 705
737 if (newRect == oldRect) 706 if (newRect == oldRect)
738 return; 707 return;
739 708
740 Widget::setFrameRect(newRect); 709 Widget::setFrameRect(newRect);
741 710
742 frameRectsChanged();
743
744 updateScrollbars(scrollOffset()); 711 updateScrollbars(scrollOffset());
745 712
746 if (!m_useFixedLayout && oldRect.size() != newRect.size()) 713 frameRectsChanged();
747 contentsResized();
748 } 714 }
749 715
750 void ScrollView::frameRectsChanged() 716 void ScrollView::frameRectsChanged()
751 { 717 {
752 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end(); 718 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end();
753 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current) 719 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current)
754 (*current)->frameRectsChanged(); 720 (*current)->frameRectsChanged();
755 } 721 }
756 722
757 void ScrollView::clipRectChanged() 723 void ScrollView::clipRectChanged()
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 int ScrollView::pageStep(ScrollbarOrientation orientation) const 1158 int ScrollView::pageStep(ScrollbarOrientation orientation) const
1193 { 1159 {
1194 int length = (orientation == HorizontalScrollbar) ? visibleWidth() : visible Height(); 1160 int length = (orientation == HorizontalScrollbar) ? visibleWidth() : visible Height();
1195 int minPageStep = static_cast<float>(length) * minFractionToStepWhenPaging() ; 1161 int minPageStep = static_cast<float>(length) * minFractionToStepWhenPaging() ;
1196 int pageStep = std::max(minPageStep, length - maxOverlapBetweenPages()); 1162 int pageStep = std::max(minPageStep, length - maxOverlapBetweenPages());
1197 1163
1198 return std::max(pageStep, 1); 1164 return std::max(pageStep, 1);
1199 } 1165 }
1200 1166
1201 } // namespace WebCore 1167 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698