Changeset 51827 in webkit
- Timestamp:
- Dec 7, 2009 6:54:52 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r51825 r51827 1 2009-12-07 Evan Martin <evan@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Chromium: theme scrollbars to match GTK theme. 6 Add functions to RenderThemeChromiumLinux to change the scrollbar 7 color. 8 9 Since the change is to the Chromium WebKit API layer, testing will 10 be in Chromium's test shell. 11 http://bugs.webkit.org/show_bug.cgi?id=32048 12 13 Patch from Markus Gutschke <markus@chromium.org>. 14 15 * platform/chromium/ScrollbarThemeChromiumLinux.cpp: 16 (WebCore::saturateAndBrighten): 17 (WebCore::outlineColor): 18 (WebCore::ScrollbarThemeChromiumLinux::paintTrackPiece): 19 (WebCore::ScrollbarThemeChromiumLinux::paintThumb): 20 * rendering/RenderThemeChromiumLinux.cpp: 21 (WebCore::RenderThemeChromiumLinux::setScrollbarColors): 22 * rendering/RenderThemeChromiumLinux.h: 23 (WebCore::RenderThemeChromiumLinux::thumbInactiveColor): 24 (WebCore::RenderThemeChromiumLinux::thumbActiveColor): 25 (WebCore::RenderThemeChromiumLinux::trackColor): 26 1 27 2009-12-08 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk> 2 28 -
trunk/WebCore/platform/chromium/ScrollbarThemeChromiumLinux.cpp
r49553 r51827 34 34 #include "PlatformContextSkia.h" 35 35 #include "PlatformMouseEvent.h" 36 #include "RenderTheme.h" 37 #include "RenderThemeChromiumLinux.h" 36 38 #include "Scrollbar.h" 37 39 #include "TransformationMatrix.h" … … 74 76 } 75 77 78 static SkScalar clamp(SkScalar value, SkScalar min, SkScalar max) 79 { 80 return std::min(std::max(value, min), max); 81 } 82 83 static SkColor saturateAndBrighten(SkScalar* hsv, 84 SkScalar saturateAmount, 85 SkScalar brightenAmount) 86 { 87 SkScalar color[3]; 88 color[0] = hsv[0]; 89 color[1] = clamp(hsv[1] + saturateAmount, 0.0, 1.0); 90 color[2] = clamp(hsv[2] + brightenAmount, 0.0, 1.0); 91 return SkHSVToColor(color); 92 } 93 94 static SkColor outlineColor(SkScalar* hsv1, SkScalar* hsv2) 95 { 96 // GTK Theme engines have way too much control over the layout of 97 // the scrollbar. We might be able to more closely approximate its 98 // look-and-feel, if we sent whole images instead of just colors 99 // from the browser to the renderer. But even then, some themes 100 // would just break. 101 // 102 // So, instead, we don't even try to 100% replicate the look of 103 // the native scrollbar. We render our own version, but we make 104 // sure to pick colors that blend in nicely with the system GTK 105 // theme. In most cases, we can just sample a couple of pixels 106 // from the system scrollbar and use those colors to draw our 107 // scrollbar. 108 // 109 // This works fine for the track color and the overall thumb 110 // color. But it fails spectacularly for the outline color used 111 // around the thumb piece. Not all themes have a clearly defined 112 // outline. For some of them it is partially transparent, and for 113 // others the thickness is very unpredictable. 114 // 115 // So, instead of trying to approximate the system theme, we 116 // instead try to compute a reasonable looking choice based on the 117 // known color of the track and the thumb piece. This is difficult 118 // when trying to deal both with high- and low-contrast themes, 119 // and both with positive and inverted themes. 120 // 121 // The following code has been tested to look OK with all of the 122 // default GTK themes. 123 SkScalar minDiff = clamp((hsv1[1] + hsv2[1]) * 1.2, 0.2, 0.5); 124 SkScalar diff = clamp(fabs(hsv1[2] - hsv2[2]) / 2, minDiff, 0.5); 125 126 if (hsv1[2] + hsv2[2] > 1.0) 127 diff = -diff; 128 129 return saturateAndBrighten(hsv2, -0.2, diff); 130 } 131 76 132 IntRect ScrollbarThemeChromium::trackRect(Scrollbar* scrollbar, bool) 77 133 { … … 90 146 91 147 skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); 92 paint.setARGB(0xff, 0xe3, 0xdd, 0xd8); 93 canvas->drawIRect(skrect, paint); 94 95 paint.setARGB(0xff, 0xc5, 0xba, 0xb0); 148 SkScalar track_hsv[3]; 149 SkColorToHSV(RenderThemeChromiumLinux::trackColor(), track_hsv); 150 paint.setColor(saturateAndBrighten(track_hsv, 0, 0)); 151 canvas->drawIRect(skrect, paint); 152 153 SkScalar thumb_hsv[3]; 154 SkColorToHSV(RenderThemeChromiumLinux::thumbInactiveColor(), 155 thumb_hsv); 156 157 paint.setColor(outlineColor(track_hsv, thumb_hsv)); 96 158 drawBox(canvas, rect, paint); 97 159 } … … 110 172 SkCanvas* const canvas = gc->platformContext()->canvas(); 111 173 174 SkScalar thumb[3]; 175 SkColorToHSV(hovered 176 ? RenderThemeChromiumLinux::thumbActiveColor() 177 : RenderThemeChromiumLinux::thumbInactiveColor(), 178 thumb); 179 112 180 SkPaint paint; 113 if (hovered) 114 paint.setARGB(0xff, 0xff, 0xff, 0xff); 115 else 116 paint.setARGB(0xff, 0xf4, 0xf2, 0xef); 181 paint.setColor(saturateAndBrighten(thumb, 0, 0.02)); 117 182 118 183 SkIRect skrect; … … 124 189 canvas->drawIRect(skrect, paint); 125 190 126 if (hovered) 127 paint.setARGB(0xff, 0xf4, 0xf2, 0xef); 128 else 129 paint.setARGB(0xff, 0xea, 0xe5, 0xe0); 191 paint.setColor(saturateAndBrighten(thumb, 0, -0.02)); 130 192 131 193 if (vertical) … … 136 198 canvas->drawIRect(skrect, paint); 137 199 138 paint.setARGB(0xff, 0x9d, 0x96, 0x8e); 200 SkScalar track[3]; 201 SkColorToHSV(RenderThemeChromiumLinux::trackColor(), track); 202 paint.setColor(outlineColor(track, thumb)); 139 203 drawBox(canvas, rect, paint); 140 204 141 205 if (rect.height() > 10 && rect.width() > 10) { 142 paint.setARGB(0xff, 0x9d, 0x96, 0x8e);143 206 const int grippyHalfWidth = 2; 144 207 const int interGrippyOffset = 3; -
trunk/WebCore/rendering/RenderThemeChromiumLinux.cpp
r48317 r51827 32 32 33 33 namespace WebCore { 34 35 unsigned RenderThemeChromiumLinux::m_thumbInactiveColor = 0; 36 unsigned RenderThemeChromiumLinux::m_thumbActiveColor = 0; 37 unsigned RenderThemeChromiumLinux::m_trackColor = 0; 34 38 35 39 PassRefPtr<RenderTheme> RenderThemeChromiumLinux::create() … … 123 127 } 124 128 129 void RenderThemeChromiumLinux::setScrollbarColors( 130 SkColor inactiveColor, SkColor activeColor, SkColor trackColor) 131 { 132 m_thumbInactiveColor = inactiveColor; 133 m_thumbActiveColor = activeColor; 134 m_trackColor = trackColor; 135 } 136 125 137 } // namespace WebCore -
trunk/WebCore/rendering/RenderThemeChromiumLinux.h
r48317 r51827 55 55 virtual double caretBlinkIntervalInternal() const; 56 56 57 static void setScrollbarColors(unsigned inactive_color, 58 unsigned active_color, 59 unsigned track_color); 60 static unsigned thumbInactiveColor() { return m_thumbInactiveColor; } 61 static unsigned thumbActiveColor() { return m_thumbActiveColor; } 62 static unsigned trackColor() { return m_trackColor; } 63 57 64 private: 58 65 RenderThemeChromiumLinux(); … … 63 70 64 71 double m_caretBlinkInterval; 72 73 static unsigned m_thumbInactiveColor; 74 static unsigned m_thumbActiveColor; 75 static unsigned m_trackColor; 65 76 }; 66 77 -
trunk/WebKit/chromium/ChangeLog
r51818 r51827 1 2009-12-07 Evan Martin <evan@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Chromium: theme scrollbars to match GTK theme. 6 Add API to set the colors. 7 8 Since the change is to the Chromium WebKit API layer, testing will 9 be in Chromium's test shell. 10 http://bugs.webkit.org/show_bug.cgi?id=32048 11 12 Patch from Markus Gutschke <markus@chromium.org>. 13 14 * public/WebView.h: 15 * src/WebViewImpl.cpp: 16 (WebKit::WebViewImpl::setScrollbarColors): 17 * src/WebViewImpl.h: 18 1 19 2009-12-07 Finnur Thorarinsson <finnur.webkit@gmail.com> 2 20 -
trunk/WebKit/chromium/public/WebView.h
r51719 r51827 246 246 WEBKIT_API static void resetVisitedLinkState(); 247 247 248 // Scrollbar colors ---------------------------------------------------- 249 virtual void setScrollbarColors(unsigned inactiveColor, 250 unsigned activeColor, 251 unsigned trackColor) = 0; 248 252 249 253 protected: -
trunk/WebKit/chromium/src/WebViewImpl.cpp
r51818 r51827 98 98 #include "RenderThemeChromiumWin.h" 99 99 #else 100 #if PLATFORM(LINUX) 101 #include "RenderThemeChromiumLinux.h" 102 #endif 100 103 #include "KeyboardCodesPosix.h" 101 104 #include "RenderTheme.h" … … 1622 1625 } 1623 1626 1627 void WebViewImpl::setScrollbarColors(unsigned inactiveColor, 1628 unsigned activeColor, 1629 unsigned trackColor) { 1630 #if PLATFORM(LINUX) 1631 RenderThemeChromiumLinux::setScrollbarColors(inactiveColor, 1632 activeColor, 1633 trackColor); 1634 #endif 1635 } 1636 1624 1637 void WebViewImpl::didCommitLoad(bool* isNewNavigation) 1625 1638 { -
trunk/WebKit/chromium/src/WebViewImpl.h
r51719 r51827 155 155 int defaultSuggestionIndex); 156 156 virtual void hideAutofillPopup(); 157 virtual void setScrollbarColors(unsigned inactiveColor, 158 unsigned activeColor, 159 unsigned trackColor); 157 160 158 161 // WebViewImpl
Note: See TracChangeset
for help on using the changeset viewer.