Changeset 205853 in webkit


Ignore:
Timestamp:
Sep 12, 2016 11:15:09 PM (8 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Scrollbar too large
https://bugs.webkit.org/show_bug.cgi?id=161735

Reviewed by Michael Catanzaro.

We were not calculating the total scrollbar size correctly when the theme defines a minimum width/height. In
that case we need to take the extra size into account (border, margin, padding), but not adding the minimum
size. We were also adjusting the thumb position when rendering in indicator mode, but we really need to adjust
the whole rectangle. This worked in Adwaita because it uses a transparent track when in indicator mode. We are
also now taking into account the text direction when doing this adjustment for the indicator mode.

  • platform/gtk/ScrollbarThemeGtk.cpp:

(WebCore::ScrollbarThemeGtk::paint):
(WebCore::ScrollbarThemeGtk::scrollbarThickness):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r205852 r205853  
     12016-09-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Scrollbar  too large
     4        https://bugs.webkit.org/show_bug.cgi?id=161735
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        We were not calculating the total scrollbar size correctly when the theme defines a minimum width/height. In
     9        that case we need to take the extra size into account (border, margin, padding), but not adding the minimum
     10        size. We were also adjusting the thumb position when rendering in indicator mode, but we really need to adjust
     11        the whole rectangle. This worked in Adwaita because it uses a transparent track when in indicator mode. We are
     12        also now taking into account the text direction when doing this adjustment for the indicator mode.
     13
     14        * platform/gtk/ScrollbarThemeGtk.cpp:
     15        (WebCore::ScrollbarThemeGtk::paint):
     16        (WebCore::ScrollbarThemeGtk::scrollbarThickness):
     17
    1182016-09-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    219
  • trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp

    r204466 r205853  
    477477        return true;
    478478
     479    bool scrollbarOnLeft = scrollbar.scrollableArea().shouldPlaceBlockDirectionScrollbarOnLeft();
     480
    479481    RenderThemeGadget::Info info = { RenderThemeGadget::Type::Scrollbar, "scrollbar", scrollbarPartStateFlags(scrollbar, AllParts, true), { } };
    480482    if (scrollbar.orientation() == VerticalScrollbar) {
    481483        info.classList.append("vertical");
    482         info.classList.append("right");
     484        info.classList.append(scrollbarOnLeft ? "left" : "right");
    483485    } else {
    484486        info.classList.append("horizontal");
     
    526528    RenderThemeGadget* troughGadget = contentsGadget->child(troughPosition);
    527529
     530    IntSize preferredSize = contentsGadget->preferredSize();
     531    std::unique_ptr<RenderThemeGadget> sliderGadget;
     532    int thumbSize = thumbLength(scrollbar);
     533    if (thumbSize) {
     534        info.name = "slider";
     535        info.state = scrollbarPartStateFlags(scrollbar, ThumbPart);
     536        sliderGadget = RenderThemeGadget::create(info, troughGadget);
     537        preferredSize = preferredSize.expandedTo(sliderGadget->preferredSize());
     538    }
     539    preferredSize += scrollbarGadget->preferredSize() - scrollbarGadget->minimumSize();
     540
     541    FloatRect contentsRect(rect);
     542    // When using overlay scrollbars we always claim the size of the scrollbar when hovered, so when
     543    // drawing the indicator we need to adjust the rectangle to its actual size in indicator mode.
     544    if (scrollbar.orientation() == VerticalScrollbar) {
     545        if (rect.width() != preferredSize.width()) {
     546            if (!scrollbarOnLeft)
     547                contentsRect.move(std::abs(rect.width() - preferredSize.width()), 0);
     548            contentsRect.setWidth(preferredSize.width());
     549        }
     550    } else {
     551        if (rect.height() != preferredSize.height()) {
     552            contentsRect.move(0, std::abs(rect.height() - preferredSize.height()));
     553            contentsRect.setHeight(preferredSize.height());
     554        }
     555    }
     556
    528557    if (opacity != 1) {
    529558        graphicsContext.save();
     
    532561    }
    533562
    534     FloatRect contentsRect;
    535     scrollbarGadget->render(graphicsContext.platformContext()->cr(), rect, &contentsRect);
     563    scrollbarGadget->render(graphicsContext.platformContext()->cr(), contentsRect, &contentsRect);
    536564    contentsGadget->render(graphicsContext.platformContext()->cr(), contentsRect, &contentsRect);
    537565
     
    607635
    608636    troughGadget->render(graphicsContext.platformContext()->cr(), contentsRect, &contentsRect);
    609 
    610     if (int thumbSize = thumbLength(scrollbar)) {
    611         info.name = "slider";
    612         info.state = scrollbarPartStateFlags(scrollbar, ThumbPart);
    613         auto sliderGadget = RenderThemeGadget::create(info, troughGadget);
    614 
    615         // When using overlay scrollbars we always claim the size of the scrollbar when hovered, so when
    616         // drawing the indicator we need to adjust the rectangle to its actual size in indicator mode.
    617         bool isIndicator = m_usesOverlayScrollbars && scrollbar.hoveredPart() == NoPart;
     637    if (sliderGadget) {
    618638        if (scrollbar.orientation() == VerticalScrollbar) {
    619             int sliderWidth = sliderGadget->preferredSize().width();
    620             contentsRect.move(isIndicator ? contentsRect.width() - sliderWidth : 0, thumbPosition(scrollbar));
    621             contentsRect.setWidth(sliderWidth);
     639            contentsRect.move(0, thumbPosition(scrollbar));
     640            contentsRect.setWidth(sliderGadget->preferredSize().width());
    622641            contentsRect.setHeight(thumbSize);
    623642        } else {
    624             int sliderHeight = sliderGadget->preferredSize().height();
    625             contentsRect.move(thumbPosition(scrollbar), isIndicator ? contentsRect.height() - sliderHeight : 0);
     643            contentsRect.move(thumbPosition(scrollbar), 0);
    626644            contentsRect.setWidth(thumbSize);
    627             contentsRect.setHeight(sliderHeight);
     645            contentsRect.setHeight(sliderGadget->preferredSize().height());
    628646        }
    629647        if (contentsRect.intersects(damageRect))
     
    851869    info.name = "slider";
    852870    auto sliderGadget = RenderThemeGadget::create(info, contentsGadget->child(troughPositon));
    853     IntSize preferredSize = scrollbarGadget->preferredSize();
    854871    IntSize contentsPreferredSize = contentsGadget->preferredSize();
    855872    contentsPreferredSize = contentsPreferredSize.expandedTo(sliderGadget->preferredSize());
    856     preferredSize += contentsPreferredSize;
     873    IntSize preferredSize = contentsPreferredSize + scrollbarGadget->preferredSize() - scrollbarGadget->minimumSize();
    857874
    858875    return preferredSize.width();
Note: See TracChangeset for help on using the changeset viewer.