Changeset 203294 in webkit


Ignore:
Timestamp:
Jul 15, 2016 1:19:29 PM (8 years ago)
Author:
tonikitoo@webkit.org
Message:

ScrollView::setHasHorizontalScrollbar / setHasVerticalScrollbar duplicate their logic
https://bugs.webkit.org/show_bug.cgi?id=159825

Patch introduces a (private) method to ScrollView
to share the code/logic of setHas{Horizontal,Vertical}Scrollbar.

Patch by Antonio Gomes <tonikitoo@igalia.com> on 2016-07-15
Reviewed by Simon Fraser.

No new tests needed.

  • platform/ScrollView.cpp:

(WebCore::ScrollView::setHasScrollbarInternal):
(WebCore::ScrollView::setHasHorizontalScrollbar):
(WebCore::ScrollView::setHasVerticalScrollbar):

  • platform/ScrollView.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r203289 r203294  
     12016-07-15  Antonio Gomes  <tonikitoo@igalia.com>
     2
     3        ScrollView::setHasHorizontalScrollbar / setHasVerticalScrollbar duplicate their logic
     4        https://bugs.webkit.org/show_bug.cgi?id=159825
     5
     6        Patch introduces a (private) method to ScrollView
     7        to share the code/logic of setHas{Horizontal,Vertical}Scrollbar.
     8
     9        Reviewed by Simon Fraser.
     10
     11        No new tests needed.
     12
     13        * platform/ScrollView.cpp:
     14        (WebCore::ScrollView::setHasScrollbarInternal):
     15        (WebCore::ScrollView::setHasHorizontalScrollbar):
     16        (WebCore::ScrollView::setHasVerticalScrollbar):
     17        * platform/ScrollView.h:
     18
    1192016-07-15  Frederic Wang  <fwang@igalia.com>
    220
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r200963 r203294  
    8484bool ScrollView::setHasHorizontalScrollbar(bool hasBar, bool* contentSizeAffected)
    8585{
     86    return setHasScrollbarInternal(m_horizontalScrollbar, HorizontalScrollbar, hasBar, contentSizeAffected);
     87}
     88
     89bool ScrollView::setHasVerticalScrollbar(bool hasBar, bool* contentSizeAffected)
     90{
     91    return setHasScrollbarInternal(m_verticalScrollbar, VerticalScrollbar, hasBar, contentSizeAffected);
     92}
     93
     94bool ScrollView::setHasScrollbarInternal(RefPtr<Scrollbar>& scrollbar, ScrollbarOrientation orientation, bool hasBar, bool* contentSizeAffected)
     95{
    8696    ASSERT(!hasBar || !avoidScrollbarCreation());
    87     if (hasBar && !m_horizontalScrollbar) {
    88         m_horizontalScrollbar = createScrollbar(HorizontalScrollbar);
    89         addChild(m_horizontalScrollbar.get());
    90         didAddScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar);
    91         m_horizontalScrollbar->styleChanged();
     97
     98    if (hasBar && !scrollbar) {
     99        scrollbar = createScrollbar(orientation);
     100        addChild(scrollbar.get());
     101        didAddScrollbar(scrollbar.get(), orientation);
     102        scrollbar->styleChanged();
    92103        if (contentSizeAffected)
    93             *contentSizeAffected = !m_horizontalScrollbar->isOverlayScrollbar();
     104            *contentSizeAffected = !scrollbar->isOverlayScrollbar();
    94105        return true;
    95106    }
    96107   
    97     if (!hasBar && m_horizontalScrollbar) {
    98         bool wasOverlayScrollbar = m_horizontalScrollbar->isOverlayScrollbar();
    99         willRemoveScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar);
    100         removeChild(*m_horizontalScrollbar);
    101         m_horizontalScrollbar = nullptr;
    102         if (contentSizeAffected)
    103             *contentSizeAffected = !wasOverlayScrollbar;
    104         return true;
    105     }
    106 
    107     return false;
    108 }
    109 
    110 bool ScrollView::setHasVerticalScrollbar(bool hasBar, bool* contentSizeAffected)
    111 {
    112     ASSERT(!hasBar || !avoidScrollbarCreation());
    113     if (hasBar && !m_verticalScrollbar) {
    114         m_verticalScrollbar = createScrollbar(VerticalScrollbar);
    115         addChild(m_verticalScrollbar.get());
    116         didAddScrollbar(m_verticalScrollbar.get(), VerticalScrollbar);
    117         m_verticalScrollbar->styleChanged();
    118         if (contentSizeAffected)
    119             *contentSizeAffected = !m_verticalScrollbar->isOverlayScrollbar();
    120         return true;
    121     }
    122    
    123     if (!hasBar && m_verticalScrollbar) {
    124         bool wasOverlayScrollbar = m_verticalScrollbar->isOverlayScrollbar();
    125         willRemoveScrollbar(m_verticalScrollbar.get(), VerticalScrollbar);
    126         removeChild(*m_verticalScrollbar);
    127         m_verticalScrollbar = nullptr;
     108    if (!hasBar && scrollbar) {
     109        bool wasOverlayScrollbar = scrollbar->isOverlayScrollbar();
     110        willRemoveScrollbar(scrollbar.get(), orientation);
     111        removeChild(*scrollbar);
     112        scrollbar = nullptr;
    128113        if (contentSizeAffected)
    129114            *contentSizeAffected = !wasOverlayScrollbar;
  • trunk/Source/WebCore/platform/ScrollView.h

    r200963 r203294  
    432432    void completeUpdatesAfterScrollTo(const IntSize& scrollDelta);
    433433
     434    bool setHasScrollbarInternal(RefPtr<Scrollbar>&, ScrollbarOrientation, bool hasBar, bool* contentSizeAffected);
     435
    434436    RefPtr<Scrollbar> m_horizontalScrollbar;
    435437    RefPtr<Scrollbar> m_verticalScrollbar;
Note: See TracChangeset for help on using the changeset viewer.