Changeset 73561 in webkit
- Timestamp:
- Dec 8, 2010 3:50:25 PM (13 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r73559 r73561 1 2010-12-08 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Use gtk_icon_set_render_icon() to render icons in RenderThemeGtk 6 https://bugs.webkit.org/show_bug.cgi?id=50623 7 8 We don't need to cache the icons since the will be cached by GTK+, 9 and they will be rendered using the state and text direction. 10 11 * platform/gtk/RenderThemeGtk.cpp: 12 (WebCore::paintStockIcon): 13 (WebCore::getMediaButtonIconSize): 14 (WebCore::RenderThemeGtk::initMediaColors): 15 (WebCore::RenderThemeGtk::initMediaButtons): 16 (WebCore::RenderThemeGtk::RenderThemeGtk): 17 (WebCore::RenderThemeGtk::~RenderThemeGtk): 18 (WebCore::RenderThemeGtk::gtkIconState): 19 (WebCore::RenderThemeGtk::adjustSearchFieldResultsDecorationStyle): 20 (WebCore::centerRectVerticallyInParentInputElement): 21 (WebCore::RenderThemeGtk::paintSearchFieldResultsDecoration): 22 (WebCore::RenderThemeGtk::adjustSearchFieldCancelButtonStyle): 23 (WebCore::RenderThemeGtk::paintSearchFieldCancelButton): 24 (WebCore::RenderThemeGtk::platformColorsDidChange): 25 (WebCore::RenderThemeGtk::paintMediaButton): 26 (WebCore::RenderThemeGtk::paintMediaFullscreenButton): 27 (WebCore::RenderThemeGtk::paintMediaMuteButton): 28 (WebCore::RenderThemeGtk::paintMediaPlayButton): 29 (WebCore::RenderThemeGtk::paintMediaSeekBackButton): 30 (WebCore::RenderThemeGtk::paintMediaSeekForwardButton): 31 * platform/gtk/RenderThemeGtk.h: 32 1 33 2010-12-08 Abhishek Arya <inferno@chromium.org> 2 34 -
trunk/WebCore/platform/gtk/RenderThemeGtk.cpp
r73454 r73561 67 67 } 68 68 69 static gchar* getIconNameForTextDirection(const char* baseName) 70 { 71 GString* nameWithDirection = g_string_new(baseName); 72 GtkTextDirection textDirection = gtk_widget_get_default_direction(); 73 74 if (textDirection == GTK_TEXT_DIR_RTL) 75 g_string_append(nameWithDirection, "-rtl"); 76 else if (textDirection == GTK_TEXT_DIR_LTR) 77 g_string_append(nameWithDirection, "-ltr"); 78 79 return g_string_free(nameWithDirection, FALSE); 80 } 81 82 void RenderThemeGtk::initMediaStyling(GtkStyle* style, bool force) 83 { 84 static bool stylingInitialized = false; 85 86 if (!stylingInitialized || force) { 87 m_panelColor = style->bg[GTK_STATE_NORMAL]; 88 m_sliderColor = style->bg[GTK_STATE_ACTIVE]; 89 m_sliderThumbColor = style->bg[GTK_STATE_SELECTED]; 90 91 // Names of these icons can vary because of text direction. 92 gchar* playButtonIconName = getIconNameForTextDirection("gtk-media-play"); 93 gchar* seekBackButtonIconName = getIconNameForTextDirection("gtk-media-rewind"); 94 gchar* seekForwardButtonIconName = getIconNameForTextDirection("gtk-media-forward"); 95 96 m_fullscreenButton.clear(); 97 m_muteButton.clear(); 98 m_unmuteButton.clear(); 99 m_playButton.clear(); 100 m_pauseButton.clear(); 101 m_seekBackButton.clear(); 102 m_seekForwardButton.clear(); 103 104 m_fullscreenButton = Image::loadPlatformThemeIcon("gtk-fullscreen", m_mediaIconSize); 105 // Note that the muteButton and unmuteButton take icons reflecting 106 // the *current* state. Hence, the unmuteButton represents the *muted* 107 // status, the muteButton represents the then current *unmuted* status. 108 m_muteButton = Image::loadPlatformThemeIcon("audio-volume-high", m_mediaIconSize); 109 m_unmuteButton = Image::loadPlatformThemeIcon("audio-volume-muted", m_mediaIconSize); 110 m_playButton = Image::loadPlatformThemeIcon(reinterpret_cast<const char*>(playButtonIconName), m_mediaIconSize); 111 m_pauseButton = Image::loadPlatformThemeIcon("gtk-media-pause", m_mediaIconSize); 112 m_seekBackButton = Image::loadPlatformThemeIcon(reinterpret_cast<const char*>(seekBackButtonIconName), m_mediaIconSize); 113 m_seekForwardButton = Image::loadPlatformThemeIcon(reinterpret_cast<const char*>(seekForwardButtonIconName), m_mediaIconSize); 114 115 g_free(playButtonIconName); 116 g_free(seekBackButtonIconName); 117 g_free(seekForwardButtonIconName); 118 stylingInitialized = true; 69 static void paintStockIcon(GraphicsContext* context, const IntPoint& iconPoint, GtkStyle* style, const char* iconName, 70 GtkTextDirection direction, GtkStateType state, GtkIconSize iconSize) 71 { 72 GtkIconSet* iconSet = gtk_style_lookup_icon_set(style, iconName); 73 PlatformRefPtr<GdkPixbuf> icon = adoptPlatformRef(gtk_icon_set_render_icon(iconSet, style, direction, state, iconSize, 0, 0)); 74 75 cairo_t* cr = context->platformContext(); 76 cairo_save(cr); 77 gdk_cairo_set_source_pixbuf(cr, icon.get(), iconPoint.x(), iconPoint.y()); 78 cairo_paint(cr); 79 cairo_restore(cr); 80 } 81 82 static GtkIconSize getMediaButtonIconSize(int mediaIconSize) 83 { 84 GtkIconSize iconSize = gtk_icon_size_from_name("webkit-media-button-size"); 85 if (!iconSize) 86 iconSize = gtk_icon_size_register("webkit-media-button-size", mediaIconSize, mediaIconSize); 87 return iconSize; 88 } 89 90 void RenderThemeGtk::initMediaColors() 91 { 92 GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkContainer())); 93 m_panelColor = style->bg[GTK_STATE_NORMAL]; 94 m_sliderColor = style->bg[GTK_STATE_ACTIVE]; 95 m_sliderThumbColor = style->bg[GTK_STATE_SELECTED]; 96 } 97 98 void RenderThemeGtk::initMediaButtons() 99 { 100 static bool iconsInitialized = false; 101 102 if (iconsInitialized) 103 return; 104 105 PlatformRefPtr<GtkIconFactory> iconFactory = adoptPlatformRef(gtk_icon_factory_new()); 106 GtkIconSource* iconSource = gtk_icon_source_new(); 107 const char* icons[] = { "audio-volume-high", "audio-volume-muted" }; 108 109 gtk_icon_factory_add_default(iconFactory.get()); 110 111 for (size_t i = 0; i < G_N_ELEMENTS(icons); ++i) { 112 gtk_icon_source_set_icon_name(iconSource, icons[i]); 113 GtkIconSet* iconSet = gtk_icon_set_new(); 114 gtk_icon_set_add_source(iconSet, iconSource); 115 gtk_icon_factory_add(iconFactory.get(), icons[i], iconSet); 116 gtk_icon_set_unref(iconSet); 119 117 } 118 119 gtk_icon_source_free(iconSource); 120 121 iconsInitialized = true; 120 122 } 121 123 #endif … … 147 149 , m_mediaSliderThumbWidth(12) 148 150 , m_mediaSliderThumbHeight(12) 149 , m_fullscreenButton(0)150 , m_muteButton(0)151 , m_unmuteButton(0)152 , m_playButton(0)153 , m_pauseButton(0)154 , m_seekBackButton(0)155 , m_seekForwardButton(0)156 151 #ifdef GTK_API_VERSION_2 157 152 , m_themePartsHaveRGBAColormap(true) … … 177 172 178 173 #if ENABLE(VIDEO) 179 initMediaStyling(gtk_rc_get_style(GTK_WIDGET(gtkContainer())), false); 174 initMediaColors(); 175 initMediaButtons(); 180 176 #endif 181 177 } … … 187 183 if (!mozGtkRefCount) 188 184 moz_gtk_shutdown(); 189 190 m_fullscreenButton.clear();191 m_muteButton.clear();192 m_unmuteButton.clear();193 m_playButton.clear();194 m_pauseButton.clear();195 m_seekBackButton.clear();196 m_seekForwardButton.clear();197 185 198 186 gtk_widget_destroy(m_gtkWindow); … … 267 255 } 268 256 257 GtkStateType RenderThemeGtk::gtkIconState(RenderObject* renderObject) 258 { 259 if (!isEnabled(renderObject)) 260 return GTK_STATE_INSENSITIVE; 261 if (isPressed(renderObject)) 262 return GTK_STATE_ACTIVE; 263 if (isHovered(renderObject)) 264 return GTK_STATE_PRELIGHT; 265 266 return GTK_STATE_NORMAL; 267 } 268 269 269 bool RenderThemeGtk::paintRenderObject(GtkThemeWidgetType type, RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, int flags) 270 270 { … … 468 468 style->resetPadding(); 469 469 470 // FIXME: This should not be hard-coded. 471 IntSize size = IntSize(14, 14); 472 style->setWidth(Length(size.width(), Fixed)); 473 style->setHeight(Length(size.height(), Fixed)); 474 } 475 476 static IntRect centerRectVerticallyInParentInputElement(RenderObject* object, const IntRect& rect) 477 { 478 IntRect centeredRect(rect); 470 gint width = 0, height = 0; 471 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); 472 style->setWidth(Length(width, Fixed)); 473 style->setHeight(Length(height, Fixed)); 474 } 475 476 static IntPoint centerRectVerticallyInParentInputElement(RenderObject* object, const IntRect& rect) 477 { 479 478 Node* input = object->node()->shadowAncestorNode(); // Get the renderer of <input> element. 480 if (!input->renderer()->isBox()) 481 return centeredRect;479 if (!input->renderer()->isBox()) 480 return rect.topLeft(); 482 481 483 482 // If possible center the y-coordinate of the rect vertically in the parent input element. … … 485 484 // that are even, which looks in relation to the box text. 486 485 IntRect inputContentBox = toRenderBox(input->renderer())->absoluteContentBox(); 487 centeredRect.setY(inputContentBox.y() + (inputContentBox.height() - centeredRect.height() + 1) / 2); 488 return centeredRect; 489 } 490 491 bool RenderThemeGtk::paintSearchFieldResultsDecoration(RenderObject* object, const PaintInfo& i, const IntRect& rect) 492 { 493 static Image* searchImage = Image::loadPlatformThemeIcon(GTK_STOCK_FIND, rect.width()).releaseRef(); 494 IntRect centeredRect(centerRectVerticallyInParentInputElement(object, rect)); 495 i.context->drawImage(searchImage, ColorSpaceDeviceRGB, centeredRect); 486 487 return IntPoint(rect.x(), inputContentBox.y() + (inputContentBox.height() - rect.height() + 1) / 2); 488 } 489 490 bool RenderThemeGtk::paintSearchFieldResultsDecoration(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 491 { 492 GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkEntry())); 493 IntPoint iconPoint(centerRectVerticallyInParentInputElement(renderObject, rect)); 494 paintStockIcon(paintInfo.context, iconPoint, style, GTK_STOCK_FIND, 495 gtkTextDirection(renderObject->style()->direction()), 496 gtkIconState(renderObject), GTK_ICON_SIZE_MENU); 496 497 return false; 497 498 } … … 502 503 style->resetPadding(); 503 504 504 // FIXME: This should not be hard-coded. 505 IntSize size = IntSize(14, 14); 506 style->setWidth(Length(size.width(), Fixed)); 507 style->setHeight(Length(size.height(), Fixed)); 508 } 509 510 bool RenderThemeGtk::paintSearchFieldCancelButton(RenderObject* object, const PaintInfo& i, const IntRect& rect) 511 { 512 // TODO: Brightening up the image on hover is desirable here, I believe. 513 static Image* cancelImage = Image::loadPlatformThemeIcon(GTK_STOCK_CLEAR, rect.width()).releaseRef(); 514 IntRect centeredRect(centerRectVerticallyInParentInputElement(object, rect)); 515 i.context->drawImage(cancelImage, ColorSpaceDeviceRGB, centeredRect); 505 gint width = 0, height = 0; 506 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); 507 style->setWidth(Length(width, Fixed)); 508 style->setHeight(Length(height, Fixed)); 509 } 510 511 bool RenderThemeGtk::paintSearchFieldCancelButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 512 { 513 GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkEntry())); 514 IntPoint iconPoint(centerRectVerticallyInParentInputElement(renderObject, rect)); 515 paintStockIcon(paintInfo.context, iconPoint, style, GTK_STOCK_CLEAR, 516 gtkTextDirection(renderObject->style()->direction()), 517 gtkIconState(renderObject), GTK_ICON_SIZE_MENU); 516 518 return false; 517 519 } … … 763 765 { 764 766 #if ENABLE(VIDEO) 765 initMedia Styling(gtk_rc_get_style(GTK_WIDGET(gtkContainer())), true);767 initMediaColors(); 766 768 #endif 767 769 RenderTheme::platformColorsDidChange(); … … 774 776 } 775 777 776 static inline bool paintMediaButton(GraphicsContext* context, const IntRect& r, Image* image, Color panelColor, int mediaIconSize) 777 { 778 context->fillRect(FloatRect(r), panelColor, ColorSpaceDeviceRGB); 779 context->drawImage(image, ColorSpaceDeviceRGB, 780 IntRect(r.x() + (r.width() - mediaIconSize) / 2, 781 r.y() + (r.height() - mediaIconSize) / 2, 782 mediaIconSize, mediaIconSize)); 778 bool RenderThemeGtk::paintMediaButton(RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, const char* iconName) 779 { 780 GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkContainer())); 781 IntPoint iconPoint(rect.x() + (rect.width() - m_mediaIconSize) / 2, 782 rect.y() + (rect.height() - m_mediaIconSize) / 2); 783 context->fillRect(FloatRect(rect), m_panelColor, ColorSpaceDeviceRGB); 784 paintStockIcon(context, iconPoint, style, iconName, gtkTextDirection(renderObject->style()->direction()), 785 gtkIconState(renderObject), getMediaButtonIconSize(m_mediaIconSize)); 783 786 784 787 return false; 785 788 } 786 789 787 bool RenderThemeGtk::paintMediaFullscreenButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)788 { 789 return paintMediaButton( paintInfo.context, r, m_fullscreenButton.get(), m_panelColor, m_mediaIconSize);790 } 791 792 bool RenderThemeGtk::paintMediaMuteButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)793 { 794 HTMLMediaElement* mediaElement = getMediaElementFromRenderObject( o);790 bool RenderThemeGtk::paintMediaFullscreenButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 791 { 792 return paintMediaButton(renderObject, paintInfo.context, rect, GTK_STOCK_FULLSCREEN); 793 } 794 795 bool RenderThemeGtk::paintMediaMuteButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 796 { 797 HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(renderObject); 795 798 if (!mediaElement) 796 799 return false; 797 800 798 return paintMediaButton( paintInfo.context, r, mediaElement->muted() ? m_unmuteButton.get() : m_muteButton.get(), m_panelColor, m_mediaIconSize);799 } 800 801 bool RenderThemeGtk::paintMediaPlayButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)802 { 803 Node* node = o->node();801 return paintMediaButton(renderObject, paintInfo.context, rect, mediaElement->muted() ? "audio-volume-muted" : "audio-volume-high"); 802 } 803 804 bool RenderThemeGtk::paintMediaPlayButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 805 { 806 Node* node = renderObject->node(); 804 807 if (!node) 805 808 return false; 806 809 807 810 MediaControlPlayButtonElement* button = static_cast<MediaControlPlayButtonElement*>(node); 808 return paintMediaButton( paintInfo.context, r, button->displayType() == MediaPlayButton ? m_playButton.get() : m_pauseButton.get(), m_panelColor, m_mediaIconSize);809 } 810 811 bool RenderThemeGtk::paintMediaSeekBackButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)812 { 813 return paintMediaButton( paintInfo.context, r, m_seekBackButton.get(), m_panelColor, m_mediaIconSize);814 } 815 816 bool RenderThemeGtk::paintMediaSeekForwardButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)817 { 818 return paintMediaButton( paintInfo.context, r, m_seekForwardButton.get(), m_panelColor, m_mediaIconSize);811 return paintMediaButton(renderObject, paintInfo.context, rect, button->displayType() == MediaPlayButton ? GTK_STOCK_MEDIA_PLAY : GTK_STOCK_MEDIA_PAUSE); 812 } 813 814 bool RenderThemeGtk::paintMediaSeekBackButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 815 { 816 return paintMediaButton(renderObject, paintInfo.context, rect, GTK_STOCK_MEDIA_REWIND); 817 } 818 819 bool RenderThemeGtk::paintMediaSeekForwardButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 820 { 821 return paintMediaButton(renderObject, paintInfo.context, rect, GTK_STOCK_MEDIA_FORWARD); 819 822 } 820 823 -
trunk/WebCore/platform/gtk/RenderThemeGtk.h
r73128 r73561 139 139 140 140 #if ENABLE(VIDEO) 141 virtual void initMediaStyling(GtkStyle* style, bool force); 141 void initMediaColors(); 142 void initMediaButtons(); 142 143 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&); 143 144 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&); … … 171 172 172 173 bool paintRenderObject(GtkThemeWidgetType, RenderObject*, GraphicsContext*, const IntRect& rect, int flags = 0); 174 #if ENABLE(VIDEO) 175 bool paintMediaButton(RenderObject*, GraphicsContext*, const IntRect&, const char* iconName); 176 #endif 177 GtkStateType gtkIconState(RenderObject*); 173 178 174 179 mutable GtkWidget* m_gtkWindow; … … 187 192 const int m_mediaSliderThumbHeight; 188 193 189 RefPtr<Image> m_fullscreenButton;190 RefPtr<Image> m_muteButton;191 RefPtr<Image> m_unmuteButton;192 RefPtr<Image> m_playButton;193 RefPtr<Image> m_pauseButton;194 RefPtr<Image> m_seekBackButton;195 RefPtr<Image> m_seekForwardButton;196 194 GtkThemeParts m_themeParts; 197 195 #ifdef GTK_API_VERSION_2
Note: See TracChangeset
for help on using the changeset viewer.