Changeset 75364 in webkit


Ignore:
Timestamp:
Jan 10, 2011 1:09:42 AM (13 years ago)
Author:
Carlos Garcia Campos
Message:

2011-01-10 Carlos Garcia Campos <cgarcia@igalia.com>

Reviewed by Martin Robinson.

[GTK] Port progressbar painting to GtkStyleContext
https://bugs.webkit.org/show_bug.cgi?id=52054

Use GtkStyleContext API to paint progressbars when building with
GTK+ 3.x. Also add support for indeterminate progressbars.

No new tests. This should not change functionality.

  • platform/gtk/RenderThemeGtk.cpp:
  • platform/gtk/RenderThemeGtk2.cpp: (WebCore::RenderThemeGtk::animationRepeatIntervalForProgressBar): (WebCore::RenderThemeGtk::animationDurationForProgressBar):
  • platform/gtk/RenderThemeGtk3.cpp: (WebCore::RenderThemeGtk::animationRepeatIntervalForProgressBar): (WebCore::RenderThemeGtk::animationDurationForProgressBar): (WebCore::RenderThemeGtk::paintProgressBar):
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r75363 r75364  
     12011-01-10  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Port progressbar painting to GtkStyleContext
     6        https://bugs.webkit.org/show_bug.cgi?id=52054
     7
     8        Use GtkStyleContext API to paint progressbars when building with
     9        GTK+ 3.x. Also add support for indeterminate progressbars.
     10
     11        No new tests. This should not change functionality.
     12
     13        * platform/gtk/RenderThemeGtk.cpp:
     14        * platform/gtk/RenderThemeGtk2.cpp:
     15        (WebCore::RenderThemeGtk::animationRepeatIntervalForProgressBar):
     16        (WebCore::RenderThemeGtk::animationDurationForProgressBar):
     17        * platform/gtk/RenderThemeGtk3.cpp:
     18        (WebCore::RenderThemeGtk::animationRepeatIntervalForProgressBar):
     19        (WebCore::RenderThemeGtk::animationDurationForProgressBar):
     20        (WebCore::RenderThemeGtk::paintProgressBar):
     21
    1222011-01-10  Andreas Kling  <kling@webkit.org>
    223
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp

    r75241 r75364  
    576576
    577577#if ENABLE(PROGRESS_TAG)
    578 double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
    579 {
    580     // FIXME: It doesn't look like there is a good way yet to support animated
    581     // progress bars with the Mozilla theme drawing code.
    582     return 0;
    583 }
    584 
    585 double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
    586 {
    587     // FIXME: It doesn't look like there is a good way yet to support animated
    588     // progress bars with the Mozilla theme drawing code.
    589     return 0;
    590 }
    591 
    592578void RenderThemeGtk::adjustProgressBarStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
    593579{
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp

    r75241 r75364  
    331331
    332332#if ENABLE(PROGRESS_TAG)
     333double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
     334{
     335    // FIXME: It doesn't look like there is a good way yet to support animated
     336    // progress bars with the Mozilla theme drawing code.
     337    return 0;
     338}
     339
     340double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
     341{
     342    // FIXME: It doesn't look like there is a good way yet to support animated
     343    // progress bars with the Mozilla theme drawing code.
     344    return 0;
     345}
     346
    333347bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
    334348{
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp

    r75259 r75364  
    437437
    438438#if ENABLE(PROGRESS_TAG)
     439// These values have been copied from RenderThemeChromiumSkia.cpp
     440static const int progressActivityBlocks = 5;
     441static const int progressAnimationFrames = 10;
     442static const double progressAnimationInterval = 0.125;
     443double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
     444{
     445    return progressAnimationInterval;
     446}
     447
     448double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
     449{
     450    return progressAnimationInterval * progressAnimationFrames * 2; // "2" for back and forth;
     451}
     452
    439453bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
    440454{
     
    442456        return true;
    443457
    444     GtkWidget* progressBarWidget = moz_gtk_get_progress_widget();
    445     if (!progressBarWidget)
    446         return true;
    447 
    448     if (paintRenderObject(MOZ_GTK_PROGRESSBAR, renderObject, paintInfo.context, rect))
    449         return true;
    450 
    451     IntRect chunkRect(rect);
     458    GtkStyleContext* context = getStyleContext(GTK_TYPE_PROGRESS_BAR);
     459    gtk_style_context_save(context);
     460
     461    gtk_style_context_add_class(context, GTK_STYLE_CLASS_TROUGH);
     462
     463    gtk_render_background(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
     464    gtk_render_frame(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
     465
     466    gtk_style_context_restore(context);
     467
     468    gtk_style_context_save(context);
     469    gtk_style_context_add_class(context, GTK_STYLE_CLASS_PROGRESSBAR);
     470
    452471    RenderProgress* renderProgress = toRenderProgress(renderObject);
    453472
    454     GtkStyle* style = gtk_widget_get_style(progressBarWidget);
    455     chunkRect.setHeight(chunkRect.height() - (2 * style->ythickness));
    456     chunkRect.setY(chunkRect.y() + style->ythickness);
    457     chunkRect.setWidth((chunkRect.width() - (2 * style->xthickness)) * renderProgress->position());
    458     if (renderObject->style()->direction() == RTL)
    459         chunkRect.setX(rect.x() + rect.width() - chunkRect.width() - style->xthickness);
    460     else
    461         chunkRect.setX(chunkRect.x() + style->xthickness);
    462 
    463     return paintRenderObject(MOZ_GTK_PROGRESS_CHUNK, renderObject, paintInfo.context, chunkRect);
     473    GtkBorder padding;
     474    gtk_style_context_get_padding(context, static_cast<GtkStateFlags>(0), &padding);
     475    IntRect progressRect(rect.x() + padding.left, rect.y() + padding.top,
     476                         rect.width() - (padding.left + padding.right),
     477                         rect.height() - (padding.top + padding.bottom));
     478
     479    if (renderProgress->isDeterminate()) {
     480        progressRect.setWidth(progressRect.width() * renderProgress->position());
     481        if (renderObject->style()->direction() == RTL)
     482            progressRect.setX(rect.x() + rect.width() - progressRect.width() - padding.right);
     483    } else {
     484        double animationProgress = renderProgress->animationProgress();
     485
     486        progressRect.setWidth(max(2, progressRect.width() / progressActivityBlocks));
     487        int movableWidth = rect.width() - progressRect.width();
     488        if (animationProgress < 0.5)
     489            progressRect.setX(progressRect.x() + (animationProgress * 2 * movableWidth));
     490        else
     491            progressRect.setX(progressRect.x() + ((1.0 - animationProgress) * 2 * movableWidth));
     492    }
     493
     494    if (!progressRect.isEmpty())
     495        gtk_render_activity(context, paintInfo.context->platformContext(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
     496
     497    gtk_style_context_restore(context);
     498
     499    return false;
    464500}
    465501#endif
Note: See TracChangeset for help on using the changeset viewer.