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

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

Issue 621653002: Don't call into ScrollView from Scrollbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@resizer
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
« no previous file with comments | « Source/platform/scroll/ScrollView.h ('k') | Source/platform/scroll/ScrollableArea.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) 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 void ScrollView::setHasHorizontalScrollbar(bool hasBar) 69 void ScrollView::setHasHorizontalScrollbar(bool hasBar)
70 { 70 {
71 if (hasBar && !m_horizontalScrollbar) { 71 if (hasBar && !m_horizontalScrollbar) {
72 m_horizontalScrollbar = createScrollbar(HorizontalScrollbar); 72 m_horizontalScrollbar = createScrollbar(HorizontalScrollbar);
73 addChild(m_horizontalScrollbar.get()); 73 addChild(m_horizontalScrollbar.get());
74 didAddScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); 74 didAddScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar);
75 m_horizontalScrollbar->styleChanged(); 75 m_horizontalScrollbar->styleChanged();
76 } else if (!hasBar && m_horizontalScrollbar) { 76 } else if (!hasBar && m_horizontalScrollbar) {
77 willRemoveScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); 77 willRemoveScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar);
78 // If the scrollbar has been marked as overlapping the window resizer,
79 // then its removal should reduce the count.
80 if (m_horizontalScrollbar->overlapsResizer())
81 adjustScrollbarsAvoidingResizerCount(-1);
78 removeChild(m_horizontalScrollbar.get()); 82 removeChild(m_horizontalScrollbar.get());
79 m_horizontalScrollbar = nullptr; 83 m_horizontalScrollbar = nullptr;
80 } 84 }
81 } 85 }
82 86
83 void ScrollView::setHasVerticalScrollbar(bool hasBar) 87 void ScrollView::setHasVerticalScrollbar(bool hasBar)
84 { 88 {
85 if (hasBar && !m_verticalScrollbar) { 89 if (hasBar && !m_verticalScrollbar) {
86 m_verticalScrollbar = createScrollbar(VerticalScrollbar); 90 m_verticalScrollbar = createScrollbar(VerticalScrollbar);
87 addChild(m_verticalScrollbar.get()); 91 addChild(m_verticalScrollbar.get());
88 didAddScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); 92 didAddScrollbar(m_verticalScrollbar.get(), VerticalScrollbar);
89 m_verticalScrollbar->styleChanged(); 93 m_verticalScrollbar->styleChanged();
90 } else if (!hasBar && m_verticalScrollbar) { 94 } else if (!hasBar && m_verticalScrollbar) {
91 willRemoveScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); 95 willRemoveScrollbar(m_verticalScrollbar.get(), VerticalScrollbar);
96 // If the scrollbar has been marked as overlapping the window resizer,
97 // then its removal should reduce the count.
98 if (m_verticalScrollbar->overlapsResizer())
99 adjustScrollbarsAvoidingResizerCount(-1);
92 removeChild(m_verticalScrollbar.get()); 100 removeChild(m_verticalScrollbar.get());
93 m_verticalScrollbar = nullptr; 101 m_verticalScrollbar = nullptr;
94 } 102 }
95 } 103 }
96 104
97 PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientati on) 105 PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientati on)
98 { 106 {
99 return Scrollbar::create(this, orientation, RegularScrollbar); 107 return Scrollbar::create(this, orientation, RegularScrollbar);
100 } 108 }
101 109
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 404
397 void ScrollView::updateScrollbarGeometry() 405 void ScrollView::updateScrollbarGeometry()
398 { 406 {
399 if (m_horizontalScrollbar) { 407 if (m_horizontalScrollbar) {
400 int clientWidth = visibleWidth(); 408 int clientWidth = visibleWidth();
401 IntRect oldRect(m_horizontalScrollbar->frameRect()); 409 IntRect oldRect(m_horizontalScrollbar->frameRect());
402 IntRect hBarRect((shouldPlaceVerticalScrollbarOnLeft() && m_verticalScro llbar) ? m_verticalScrollbar->width() : 0, 410 IntRect hBarRect((shouldPlaceVerticalScrollbarOnLeft() && m_verticalScro llbar) ? m_verticalScrollbar->width() : 0,
403 height() - m_horizontalScrollbar->height(), 411 height() - m_horizontalScrollbar->height(),
404 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0), 412 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0),
405 m_horizontalScrollbar->height()); 413 m_horizontalScrollbar->height());
406 m_horizontalScrollbar->setFrameRect(hBarRect); 414 m_horizontalScrollbar->setFrameRect(adjustScrollbarRectForResizer(hBarRe ct, m_horizontalScrollbar.get()));
407 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct()) 415 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct())
408 m_horizontalScrollbar->invalidate(); 416 m_horizontalScrollbar->invalidate();
409 417
410 if (m_scrollbarsSuppressed) 418 if (m_scrollbarsSuppressed)
411 m_horizontalScrollbar->setSuppressInvalidation(true); 419 m_horizontalScrollbar->setSuppressInvalidation(true);
412 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); 420 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth);
413 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); 421 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth());
414 m_horizontalScrollbar->offsetDidChange(); 422 m_horizontalScrollbar->offsetDidChange();
415 if (m_scrollbarsSuppressed) 423 if (m_scrollbarsSuppressed)
416 m_horizontalScrollbar->setSuppressInvalidation(false); 424 m_horizontalScrollbar->setSuppressInvalidation(false);
417 } 425 }
418 426
419 if (m_verticalScrollbar) { 427 if (m_verticalScrollbar) {
420 int clientHeight = visibleHeight(); 428 int clientHeight = visibleHeight();
421 IntRect oldRect(m_verticalScrollbar->frameRect()); 429 IntRect oldRect(m_verticalScrollbar->frameRect());
422 IntRect vBarRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - m _verticalScrollbar->width()), 430 IntRect vBarRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - m _verticalScrollbar->width()),
423 0, 431 0,
424 m_verticalScrollbar->width(), 432 m_verticalScrollbar->width(),
425 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0)); 433 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0));
426 m_verticalScrollbar->setFrameRect(vBarRect); 434 m_verticalScrollbar->setFrameRect(adjustScrollbarRectForResizer(vBarRect , m_verticalScrollbar.get()));
427 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ()) 435 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ())
428 m_verticalScrollbar->invalidate(); 436 m_verticalScrollbar->invalidate();
429 437
430 if (m_scrollbarsSuppressed) 438 if (m_scrollbarsSuppressed)
431 m_verticalScrollbar->setSuppressInvalidation(true); 439 m_verticalScrollbar->setSuppressInvalidation(true);
432 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); 440 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight);
433 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); 441 m_verticalScrollbar->setProportion(clientHeight, contentsHeight());
434 m_verticalScrollbar->offsetDidChange(); 442 m_verticalScrollbar->offsetDidChange();
435 if (m_scrollbarsSuppressed) 443 if (m_scrollbarsSuppressed)
436 m_verticalScrollbar->setSuppressInvalidation(false); 444 m_verticalScrollbar->setSuppressInvalidation(false);
437 } 445 }
438 } 446 }
439 447
448 IntRect ScrollView::adjustScrollbarRectForResizer(const IntRect& rect, Scrollbar * scrollbar)
449 {
450 // Get our window resizer rect and see if we overlap. Adjust to avoid the ov erlap
451 // if necessary.
452 IntRect adjustedRect(rect);
453 bool overlapsResizer = false;
454 if (!rect.isEmpty() && !windowResizerRect().isEmpty()) {
455 IntRect resizerRect = convertFromContainingWindow(windowResizerRect());
456 if (rect.intersects(resizerRect)) {
457 if (scrollbar->orientation() == HorizontalScrollbar) {
458 int overlap = rect.maxX() - resizerRect.x();
459 if (overlap > 0 && resizerRect.maxX() >= rect.maxX()) {
460 adjustedRect.setWidth(rect.width() - overlap);
461 overlapsResizer = true;
462 }
463 } else {
464 int overlap = rect.maxY() - resizerRect.y();
465 if (overlap > 0 && resizerRect.maxY() >= rect.maxY()) {
466 adjustedRect.setHeight(rect.height() - overlap);
467 overlapsResizer = true;
468 }
469 }
470 }
471 }
472 if (overlapsResizer != scrollbar->overlapsResizer()) {
473 scrollbar->setOverlapsResizer(overlapsResizer);
474 adjustScrollbarsAvoidingResizerCount(overlapsResizer ? 1 : -1);
475 }
476 return adjustedRect;
477 }
478
440 bool ScrollView::adjustScrollbarExistence(ComputeScrollbarExistenceOption option ) 479 bool ScrollView::adjustScrollbarExistence(ComputeScrollbarExistenceOption option )
441 { 480 {
442 ASSERT(m_inUpdateScrollbars); 481 ASSERT(m_inUpdateScrollbars);
443 482
444 // If we came in here with the view already needing a layout, then go ahead and do that 483 // If we came in here with the view already needing a layout, then go ahead and do that
445 // first. (This will be the common case, e.g., when the page changes due to window resizing for example). 484 // first. (This will be the common case, e.g., when the page changes due to window resizing for example).
446 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total. 485 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total.
447 if (!m_scrollbarsSuppressed) 486 if (!m_scrollbarsSuppressed)
448 scrollbarExistenceDidChange(); 487 scrollbarExistenceDidChange();
449 488
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 return; 1172 return;
1134 1173
1135 ScrollableArea::setScrollOrigin(origin); 1174 ScrollableArea::setScrollOrigin(origin);
1136 1175
1137 // Update if the scroll origin changes, since our position will be different if the content size did not change. 1176 // Update if the scroll origin changes, since our position will be different if the content size did not change.
1138 if (updatePositionAtAll && updatePositionSynchronously) 1177 if (updatePositionAtAll && updatePositionSynchronously)
1139 updateScrollbars(scrollOffset()); 1178 updateScrollbars(scrollOffset());
1140 } 1179 }
1141 1180
1142 } // namespace blink 1181 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollView.h ('k') | Source/platform/scroll/ScrollableArea.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698