Changeset 76192 in webkit


Ignore:
Timestamp:
Jan 19, 2011 6:49:54 PM (13 years ago)
Author:
Martin Robinson
Message:

2011-01-13 Martin Robinson <mrobinson@igalia.com>

Reviewed by Daniel Bates.

[GTK] Move progress bar painting out of gtk2drawing.c
https://bugs.webkit.org/show_bug.cgi?id=52385

Move progress bar painting to RenderThemeGtk2 and share some animation
logic between the GTK+ 2.x and GTK+ 3.x port.

No new tests. This should not change functionality.

  • platform/gtk/RenderThemeGtk.cpp: (WebCore::RenderThemeGtk::animationRepeatIntervalForProgressBar): Moved from RenderThemeGtk3. (WebCore::RenderThemeGtk::animationDurationForProgressBar): Ditto. (WebCore::RenderThemeGtk::calculateProgressRect): Calculate the proper rectangle for the progress indicator given the rect for the maximum size of the indicator.
  • platform/gtk/RenderThemeGtk.h: Added calculateProgressRect declaration and a new widget member for GTK+ 2.x
  • platform/gtk/RenderThemeGtk2.cpp: (WebCore::RenderThemeGtk::platformInit): Added initialization for the new widget member. (WebCore::RenderThemeGtk::paintProgressBar): Paint the progress bar manually instead of calling the old Mozilla code. (WebCore::RenderThemeGtk::gtkProgressBar): Added.
  • platform/gtk/RenderThemeGtk3.cpp: (WebCore::RenderThemeGtk::paintProgressBar): Call calculateProgressRect now to get the area of the progress indicator.
  • platform/gtk/gtk2drawing.c: Remove unused code. (moz_gtk_get_widget_border): (moz_gtk_widget_paint):
  • platform/gtk/gtkdrawing.h: Ditto.
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r76189 r76192  
     12011-01-13  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Daniel Bates.
     4
     5        [GTK] Move progress bar painting out of gtk2drawing.c
     6        https://bugs.webkit.org/show_bug.cgi?id=52385
     7
     8        Move progress bar painting to RenderThemeGtk2 and share some animation
     9        logic between the GTK+ 2.x and GTK+ 3.x port.
     10
     11        No new tests. This should not change functionality.
     12
     13        * platform/gtk/RenderThemeGtk.cpp:
     14        (WebCore::RenderThemeGtk::animationRepeatIntervalForProgressBar): Moved from RenderThemeGtk3.
     15        (WebCore::RenderThemeGtk::animationDurationForProgressBar): Ditto.
     16        (WebCore::RenderThemeGtk::calculateProgressRect): Calculate the proper rectangle for the
     17        progress indicator given the rect for the maximum size of the indicator.
     18        * platform/gtk/RenderThemeGtk.h: Added calculateProgressRect declaration and
     19        a new widget member for GTK+ 2.x
     20        * platform/gtk/RenderThemeGtk2.cpp:
     21        (WebCore::RenderThemeGtk::platformInit): Added initialization for the new widget member.
     22        (WebCore::RenderThemeGtk::paintProgressBar): Paint the progress bar manually instead of
     23        calling the old Mozilla code.
     24        (WebCore::RenderThemeGtk::gtkProgressBar): Added.
     25        * platform/gtk/RenderThemeGtk3.cpp:
     26        (WebCore::RenderThemeGtk::paintProgressBar): Call calculateProgressRect now to get
     27        the area of the progress indicator.
     28        * platform/gtk/gtk2drawing.c: Remove unused code.
     29        (moz_gtk_get_widget_border):
     30        (moz_gtk_widget_paint):
     31        * platform/gtk/gtkdrawing.h: Ditto.
     32
    1332011-01-19  Dmitry Titov  <dimich@chromium.org>
    234
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp

    r75837 r76192  
    4242#include <gtk/gtk.h>
    4343
     44#if ENABLE(PROGRESS_TAG)
     45#include "RenderProgress.h"
     46#endif
     47
    4448namespace WebCore {
    4549
     
    544548    style->setBoxShadow(0);
    545549}
     550
     551// These values have been copied from RenderThemeChromiumSkia.cpp
     552static const int progressActivityBlocks = 5;
     553static const int progressAnimationFrames = 10;
     554static const double progressAnimationInterval = 0.125;
     555double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
     556{
     557    return progressAnimationInterval;
     558}
     559
     560double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
     561{
     562    return progressAnimationInterval * progressAnimationFrames * 2; // "2" for back and forth;
     563}
     564
     565IntRect RenderThemeGtk::calculateProgressRect(RenderObject* renderObject, const IntRect& fullBarRect)
     566{
     567    IntRect progressRect(fullBarRect);
     568    RenderProgress* renderProgress = toRenderProgress(renderObject);
     569    if (renderProgress->isDeterminate()) {
     570        int progressWidth = progressRect.width() * renderProgress->position();
     571        if (renderObject->style()->direction() == RTL)
     572            progressRect.setX(progressRect.x() + progressRect.width() - progressWidth);
     573        progressRect.setWidth(progressWidth);
     574        return progressRect;
     575    }
     576
     577    double animationProgress = renderProgress->animationProgress();
     578
     579    // Never let the progress rect shrink smaller than 2 pixels.
     580    int newWidth = max(2, progressRect.width() / progressActivityBlocks);
     581    int movableWidth = progressRect.width() - newWidth;
     582    progressRect.setWidth(newWidth);
     583
     584    // We want the first 0.5 units of the animation progress to represent the
     585    // forward motion and the second 0.5 units to represent the backward motion,
     586    // thus we multiply by two here to get the full sweep of the progress bar with
     587    // each direction.
     588    if (animationProgress < 0.5)
     589        progressRect.setX(progressRect.x() + (animationProgress * 2 * movableWidth));
     590    else
     591        progressRect.setX(progressRect.x() + ((1.0 - animationProgress) * 2 * movableWidth));
     592    return progressRect;
     593}
    546594#endif
    547595
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h

    r76175 r76192  
    172172private:
    173173    void platformInit();
     174    static void setTextInputBorders(RenderStyle*);
     175    GRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize);
     176
    174177#if ENABLE(VIDEO)
    175178    bool paintMediaButton(RenderObject*, GraphicsContext*, const IntRect&, const char* iconName);
    176179#endif
    177     static void setTextInputBorders(RenderStyle*);
    178     GRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize);
     180
     181#if ENABLE(PROGRESS_TAG)
     182    static IntRect calculateProgressRect(RenderObject*, const IntRect&);
     183#endif
    179184
    180185    mutable Color m_panelColor;
     
    198203    GtkWidget* gtkRadioButton() const;
    199204    GtkWidget* gtkCheckButton() const;
     205    GtkWidget* gtkProgressBar() const;
    200206
    201207    mutable GtkWidget* m_gtkWindow;
     
    208214    mutable GtkWidget* m_gtkRadioButton;
    209215    mutable GtkWidget* m_gtkCheckButton;
     216    mutable GtkWidget* m_gtkProgressBar;
    210217
    211218    bool m_themePartsHaveRGBAColormap;
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp

    r76182 r76192  
    4646#include <gtk/gtk.h>
    4747
    48 #if ENABLE(PROGRESS_TAG)
    49 #include "RenderProgress.h"
    50 #endif
    51 
    5248namespace WebCore {
    5349
     
    6864    m_gtkRadioButton = 0;
    6965    m_gtkCheckButton = 0;
     66    m_gtkProgressBar = 0;
    7067
    7168    memset(&m_themeParts, 0, sizeof(GtkThemeParts));
     
    478475
    479476#if ENABLE(PROGRESS_TAG)
    480 double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
    481 {
    482     // FIXME: It doesn't look like there is a good way yet to support animated
    483     // progress bars with the Mozilla theme drawing code.
    484     return 0;
    485 }
    486 
    487 double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
    488 {
    489     // FIXME: It doesn't look like there is a good way yet to support animated
    490     // progress bars with the Mozilla theme drawing code.
    491     return 0;
    492 }
    493 
    494477bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
    495478{
    496     if (!renderObject->isProgress())
    497         return true;
    498 
    499     GtkWidget* progressBarWidget = moz_gtk_get_progress_widget();
    500     if (!progressBarWidget)
    501         return true;
    502 
    503     if (paintRenderObject(MOZ_GTK_PROGRESSBAR, renderObject, paintInfo.context, rect))
    504         return true;
    505 
    506     IntRect chunkRect(rect);
    507     RenderProgress* renderProgress = toRenderProgress(renderObject);
    508 
    509     GtkStyle* style = gtk_widget_get_style(progressBarWidget);
    510     chunkRect.setHeight(chunkRect.height() - (2 * style->ythickness));
    511     chunkRect.setY(chunkRect.y() + style->ythickness);
    512     chunkRect.setWidth((chunkRect.width() - (2 * style->xthickness)) * renderProgress->position());
    513     if (renderObject->style()->direction() == RTL)
    514         chunkRect.setX(rect.x() + rect.width() - chunkRect.width() - style->xthickness);
    515     else
    516         chunkRect.setX(chunkRect.x() + style->xthickness);
    517 
    518     return paintRenderObject(MOZ_GTK_PROGRESS_CHUNK, renderObject, paintInfo.context, chunkRect);
     479    GtkWidget* widget = gtkProgressBar();
     480    gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style()->direction()));
     481
     482    WidgetRenderingContext widgetContext(paintInfo.context, rect);
     483    IntRect fullProgressBarRect(IntPoint(), rect.size());
     484    widgetContext.gtkPaintBox(fullProgressBarRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "trough");
     485
     486    GtkStyle* style = gtk_widget_get_style(widget);
     487    IntRect progressRect(fullProgressBarRect);
     488    progressRect.inflateX(-style->xthickness);
     489    progressRect.inflateY(-style->ythickness);
     490    progressRect = RenderThemeGtk::calculateProgressRect(renderObject, progressRect);
     491
     492    if (!progressRect.isEmpty())
     493        widgetContext.gtkPaintBox(progressRect, widget, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, "bar");
     494
     495    return false;
    519496}
    520497#endif
     
    687664}
    688665
     666GtkWidget* RenderThemeGtk::gtkProgressBar() const
     667{
     668    if (m_gtkProgressBar)
     669        return m_gtkProgressBar;
     670    m_gtkProgressBar = gtk_progress_bar_new();
     671    setupWidgetAndAddToContainer(m_gtkProgressBar, gtkContainer());
     672    return m_gtkProgressBar;
     673}
     674
     675
    689676GtkWidget* RenderThemeGtk::gtkScrollbar()
    690677{
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp

    r75837 r76192  
    4242#include <gtk/gtk.h>
    4343
    44 #if ENABLE(PROGRESS_TAG)
    45 #include "RenderProgress.h"
    46 #endif
    47 
    4844namespace WebCore {
    4945
     
    691687
    692688#if ENABLE(PROGRESS_TAG)
    693 // These values have been copied from RenderThemeChromiumSkia.cpp
    694 static const int progressActivityBlocks = 5;
    695 static const int progressAnimationFrames = 10;
    696 static const double progressAnimationInterval = 0.125;
    697 double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
    698 {
    699     return progressAnimationInterval;
    700 }
    701 
    702 double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
    703 {
    704     return progressAnimationInterval * progressAnimationFrames * 2; // "2" for back and forth;
    705 }
    706 
    707689bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
    708690{
     
    723705    gtk_style_context_add_class(context, GTK_STYLE_CLASS_PROGRESSBAR);
    724706
    725     RenderProgress* renderProgress = toRenderProgress(renderObject);
    726707
    727708    GtkBorder padding;
     
    730711                         rect.width() - (padding.left + padding.right),
    731712                         rect.height() - (padding.top + padding.bottom));
    732 
    733     if (renderProgress->isDeterminate()) {
    734         progressRect.setWidth(progressRect.width() * renderProgress->position());
    735         if (renderObject->style()->direction() == RTL)
    736             progressRect.setX(rect.x() + rect.width() - progressRect.width() - padding.right);
    737     } else {
    738         double animationProgress = renderProgress->animationProgress();
    739 
    740         progressRect.setWidth(max(2, progressRect.width() / progressActivityBlocks));
    741         int movableWidth = rect.width() - progressRect.width();
    742         if (animationProgress < 0.5)
    743             progressRect.setX(progressRect.x() + (animationProgress * 2 * movableWidth));
    744         else
    745             progressRect.setX(progressRect.x() + ((1.0 - animationProgress) * 2 * movableWidth));
    746     }
     713    progressRect = RenderThemeGtk::calculateProgressRect(renderObject, progressRect);
    747714
    748715    if (!progressRect.isEmpty())
     
    750717
    751718    gtk_style_context_restore(context);
    752 
    753719    return false;
    754720}
  • trunk/Source/WebCore/platform/gtk/gtk2drawing.c

    r76182 r76192  
    269269
    270270static gint
    271 ensure_progress_widget()
    272 {
    273     if (!gParts->progresWidget) {
    274         gParts->progresWidget = gtk_progress_bar_new();
    275         setup_widget_prototype(gParts->progresWidget);
    276     }
    277     return MOZ_GTK_SUCCESS;
    278 }
    279 
    280 static gint
    281271ensure_scrolled_window_widget()
    282272{
     
    849839}
    850840
    851 static gint
    852 moz_gtk_progressbar_paint(GdkDrawable* drawable, GdkRectangle* rect,
    853                           GdkRectangle* cliprect, GtkTextDirection direction)
    854 {
    855     GtkStyle* style;
    856 
    857     ensure_progress_widget();
    858     gtk_widget_set_direction(gParts->progresWidget, direction);
    859 
    860     style = gtk_widget_get_style(gParts->progresWidget);
    861 
    862     TSOffsetStyleGCs(style, rect->x, rect->y);
    863     gtk_paint_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN,
    864                   cliprect, gParts->progresWidget, "trough", rect->x, rect->y,
    865                   rect->width, rect->height);
    866 
    867     return MOZ_GTK_SUCCESS;
    868 }
    869 
    870 static gint
    871 moz_gtk_progress_chunk_paint(GdkDrawable* drawable, GdkRectangle* rect,
    872                              GdkRectangle* cliprect, GtkTextDirection direction)
    873 {
    874     GtkStyle* style;
    875 
    876     ensure_progress_widget();
    877     gtk_widget_set_direction(gParts->progresWidget, direction);
    878 
    879     style = gtk_widget_get_style(gParts->progresWidget);
    880 
    881     TSOffsetStyleGCs(style, rect->x, rect->y);
    882     gtk_paint_box(style, drawable, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
    883                   cliprect, gParts->progresWidget, "bar", rect->x, rect->y,
    884                   rect->width, rect->height);
    885 
    886     return MOZ_GTK_SUCCESS;
    887 }
    888 
    889841gint
    890842moz_gtk_get_widget_border(GtkThemeWidgetType widget, gint* left, gint* top,
     
    972924            return MOZ_GTK_SUCCESS;
    973925        }
    974     case MOZ_GTK_PROGRESSBAR:
    975         ensure_progress_widget();
    976         w = gParts->progresWidget;
    977         break;
    978926    /* These widgets have no borders, since they are not containers. */
    979927    case MOZ_GTK_SCROLLBAR_BUTTON:
     
    982930    case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL:
    983931    case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL:
    984     case MOZ_GTK_PROGRESS_CHUNK:
    985932        *left = *top = *right = *bottom = 0;
    986933        return MOZ_GTK_SUCCESS;
     
    10581005                                       (gboolean) flags, direction);
    10591006        break;
    1060     case MOZ_GTK_PROGRESSBAR:
    1061         return moz_gtk_progressbar_paint(drawable, rect, cliprect, direction);
    1062         break;
    1063     case MOZ_GTK_PROGRESS_CHUNK:
    1064         return moz_gtk_progress_chunk_paint(drawable, rect, cliprect,
    1065                                             direction);
    1066         break;
    10671007    default:
    10681008        g_warning("Unknown widget type: %d", widget);
     
    11031043}
    11041044
    1105 GtkWidget* moz_gtk_get_progress_widget()
    1106 {
    1107     if (!is_initialized)
    1108         return NULL;
    1109     ensure_progress_widget();
    1110     return gParts->progresWidget;
    1111 }
    1112 
    11131045#endif // GTK_API_VERSION_2
  • trunk/Source/WebCore/platform/gtk/gtkdrawing.h

    r76182 r76192  
    100100    GtkWidget* comboBoxEntryButtonWidget;
    101101    GtkWidget* comboBoxEntryArrowWidget;
    102     GtkWidget* progresWidget;
    103102    GtkWidget* scrolledWindowWidget;
    104103} GtkThemeParts;
     
    137136  /* Paints a GtkOptionMenu. */
    138137  MOZ_GTK_DROPDOWN,
    139   /* Paints a GtkProgressBar. */
    140   MOZ_GTK_PROGRESSBAR,
    141   /* Paints a progress chunk of a GtkProgressBar. */
    142   MOZ_GTK_PROGRESS_CHUNK
    143138} GtkThemeWidgetType;
    144139
     
    243238GtkWidget* moz_gtk_get_scrollbar_widget(void);
    244239
    245 /**
    246  * Retrieve an actual GTK progress bar widget for style analysis. It will not
    247  * be modified.
    248  */
    249 GtkWidget* moz_gtk_get_progress_widget(void);
    250 
    251240#ifdef __cplusplus
    252241}
Note: See TracChangeset for help on using the changeset viewer.