Changeset 76192 in webkit
- Timestamp:
- Jan 19, 2011 6:49:54 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r76189 r76192 1 2011-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 1 33 2011-01-19 Dmitry Titov <dimich@chromium.org> 2 34 -
trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp
r75837 r76192 42 42 #include <gtk/gtk.h> 43 43 44 #if ENABLE(PROGRESS_TAG) 45 #include "RenderProgress.h" 46 #endif 47 44 48 namespace WebCore { 45 49 … … 544 548 style->setBoxShadow(0); 545 549 } 550 551 // These values have been copied from RenderThemeChromiumSkia.cpp 552 static const int progressActivityBlocks = 5; 553 static const int progressAnimationFrames = 10; 554 static const double progressAnimationInterval = 0.125; 555 double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const 556 { 557 return progressAnimationInterval; 558 } 559 560 double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const 561 { 562 return progressAnimationInterval * progressAnimationFrames * 2; // "2" for back and forth; 563 } 564 565 IntRect 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 } 546 594 #endif 547 595 -
trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h
r76175 r76192 172 172 private: 173 173 void platformInit(); 174 static void setTextInputBorders(RenderStyle*); 175 GRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize); 176 174 177 #if ENABLE(VIDEO) 175 178 bool paintMediaButton(RenderObject*, GraphicsContext*, const IntRect&, const char* iconName); 176 179 #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 179 184 180 185 mutable Color m_panelColor; … … 198 203 GtkWidget* gtkRadioButton() const; 199 204 GtkWidget* gtkCheckButton() const; 205 GtkWidget* gtkProgressBar() const; 200 206 201 207 mutable GtkWidget* m_gtkWindow; … … 208 214 mutable GtkWidget* m_gtkRadioButton; 209 215 mutable GtkWidget* m_gtkCheckButton; 216 mutable GtkWidget* m_gtkProgressBar; 210 217 211 218 bool m_themePartsHaveRGBAColormap; -
trunk/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp
r76182 r76192 46 46 #include <gtk/gtk.h> 47 47 48 #if ENABLE(PROGRESS_TAG)49 #include "RenderProgress.h"50 #endif51 52 48 namespace WebCore { 53 49 … … 68 64 m_gtkRadioButton = 0; 69 65 m_gtkCheckButton = 0; 66 m_gtkProgressBar = 0; 70 67 71 68 memset(&m_themeParts, 0, sizeof(GtkThemeParts)); … … 478 475 479 476 #if ENABLE(PROGRESS_TAG) 480 double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const481 {482 // FIXME: It doesn't look like there is a good way yet to support animated483 // progress bars with the Mozilla theme drawing code.484 return 0;485 }486 487 double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const488 {489 // FIXME: It doesn't look like there is a good way yet to support animated490 // progress bars with the Mozilla theme drawing code.491 return 0;492 }493 494 477 bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 495 478 { 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; 519 496 } 520 497 #endif … … 687 664 } 688 665 666 GtkWidget* 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 689 676 GtkWidget* RenderThemeGtk::gtkScrollbar() 690 677 { -
trunk/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
r75837 r76192 42 42 #include <gtk/gtk.h> 43 43 44 #if ENABLE(PROGRESS_TAG)45 #include "RenderProgress.h"46 #endif47 48 44 namespace WebCore { 49 45 … … 691 687 692 688 #if ENABLE(PROGRESS_TAG) 693 // These values have been copied from RenderThemeChromiumSkia.cpp694 static const int progressActivityBlocks = 5;695 static const int progressAnimationFrames = 10;696 static const double progressAnimationInterval = 0.125;697 double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const698 {699 return progressAnimationInterval;700 }701 702 double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const703 {704 return progressAnimationInterval * progressAnimationFrames * 2; // "2" for back and forth;705 }706 707 689 bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 708 690 { … … 723 705 gtk_style_context_add_class(context, GTK_STYLE_CLASS_PROGRESSBAR); 724 706 725 RenderProgress* renderProgress = toRenderProgress(renderObject);726 707 727 708 GtkBorder padding; … … 730 711 rect.width() - (padding.left + padding.right), 731 712 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); 747 714 748 715 if (!progressRect.isEmpty()) … … 750 717 751 718 gtk_style_context_restore(context); 752 753 719 return false; 754 720 } -
trunk/Source/WebCore/platform/gtk/gtk2drawing.c
r76182 r76192 269 269 270 270 static 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 gint281 271 ensure_scrolled_window_widget() 282 272 { … … 849 839 } 850 840 851 static gint852 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 gint871 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 889 841 gint 890 842 moz_gtk_get_widget_border(GtkThemeWidgetType widget, gint* left, gint* top, … … 972 924 return MOZ_GTK_SUCCESS; 973 925 } 974 case MOZ_GTK_PROGRESSBAR:975 ensure_progress_widget();976 w = gParts->progresWidget;977 break;978 926 /* These widgets have no borders, since they are not containers. */ 979 927 case MOZ_GTK_SCROLLBAR_BUTTON: … … 982 930 case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL: 983 931 case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL: 984 case MOZ_GTK_PROGRESS_CHUNK:985 932 *left = *top = *right = *bottom = 0; 986 933 return MOZ_GTK_SUCCESS; … … 1058 1005 (gboolean) flags, direction); 1059 1006 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;1067 1007 default: 1068 1008 g_warning("Unknown widget type: %d", widget); … … 1103 1043 } 1104 1044 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 1113 1045 #endif // GTK_API_VERSION_2 -
trunk/Source/WebCore/platform/gtk/gtkdrawing.h
r76182 r76192 100 100 GtkWidget* comboBoxEntryButtonWidget; 101 101 GtkWidget* comboBoxEntryArrowWidget; 102 GtkWidget* progresWidget;103 102 GtkWidget* scrolledWindowWidget; 104 103 } GtkThemeParts; … … 137 136 /* Paints a GtkOptionMenu. */ 138 137 MOZ_GTK_DROPDOWN, 139 /* Paints a GtkProgressBar. */140 MOZ_GTK_PROGRESSBAR,141 /* Paints a progress chunk of a GtkProgressBar. */142 MOZ_GTK_PROGRESS_CHUNK143 138 } GtkThemeWidgetType; 144 139 … … 243 238 GtkWidget* moz_gtk_get_scrollbar_widget(void); 244 239 245 /**246 * Retrieve an actual GTK progress bar widget for style analysis. It will not247 * be modified.248 */249 GtkWidget* moz_gtk_get_progress_widget(void);250 251 240 #ifdef __cplusplus 252 241 }
Note: See TracChangeset
for help on using the changeset viewer.