Changeset 69586 in webkit
- Timestamp:
- Oct 12, 2010 10:10:33 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r69579 r69586 1 2010-10-12 Dave Moore <davemoore@chromium.org> 2 3 Reviewed by Tony Chang. 4 5 Use new WebThemeEngine api on chromium / linux to draw scrollbars. 6 https://bugs.webkit.org/show_bug.cgi?id=47473 7 8 * platform/chromium/ChromiumBridge.h: 9 * platform/chromium/ScrollbarThemeChromiumLinux.cpp: 10 1 11 2010-10-12 Andreas Kling <kling@webkit.org> 2 12 -
trunk/WebCore/platform/chromium/ChromiumBridge.h
r68112 r69586 255 255 static void paintProgressBar( 256 256 GraphicsContext*, const IntRect& barRect, const IntRect& valueRect, bool determinate, double animatedSeconds); 257 #elif OS(LINUX) 258 // The UI part which is being accessed. 259 enum ThemePart { 260 PartScrollbarDownArrow, 261 PartScrollbarLeftArrow, 262 PartScrollbarRightArrow, 263 PartScrollbarUpArrow, 264 PartScrollbarHorizontalThumb, 265 PartScrollbarVerticalThumb, 266 PartScrollbarHoriztonalTrack, 267 PartScrollbarVerticalTrack, 268 }; 269 270 // The current state of the associated Part. 271 enum ThemePaintState { 272 StateDisabled, 273 StateHover, 274 StateNormal, 275 StatePressed, 276 }; 277 278 struct ScrollbarTrackExtraParams { 279 // The bounds of the entire track, as opposed to the part being painted. 280 int trackX; 281 int trackY; 282 int trackWidth; 283 int trackHeight; 284 }; 285 286 union ThemePaintExtraParams { 287 ScrollbarTrackExtraParams scrollbarTrack; 288 }; 289 290 // Gets the size of the given theme part. For variable sized items 291 // like vertical scrollbar thumbs, the width will be the required width of 292 // the track while the height will be the minimum height. 293 static IntSize getThemePartSize(ThemePart); 294 // Paint the given the given theme part. 295 static void paintThemePart(GraphicsContext*, ThemePart, ThemePaintState, const IntRect&, const ThemePaintExtraParams*); 257 296 #endif 258 297 -
trunk/WebCore/platform/chromium/ScrollbarThemeChromiumLinux.cpp
r69126 r69586 32 32 #include "ScrollbarThemeChromiumLinux.h" 33 33 34 #include " PlatformContextSkia.h"34 #include "ChromiumBridge.h" 35 35 #include "PlatformMouseEvent.h" 36 #include "PlatformThemeChromiumGtk.h"37 36 #include "Scrollbar.h" 38 #include "TransformationMatrix.h"39 37 40 38 namespace WebCore { 41 42 static const int scrollbarThicknessValue = 15;43 static const int buttonLength = 14;44 39 45 40 ScrollbarTheme* ScrollbarTheme::nativeTheme() … … 51 46 int ScrollbarThemeChromiumLinux::scrollbarThickness(ScrollbarControlSize controlSize) 52 47 { 53 return scrollbarThicknessValue; 54 } 55 56 static void drawVertLine(SkCanvas* canvas, int x, int y1, int y2, const SkPaint& paint) 57 { 58 SkIRect skrect; 59 skrect.set(x, y1, x + 1, y2 + 1); 60 canvas->drawIRect(skrect, paint); 61 } 62 63 static void drawHorizLine(SkCanvas* canvas, int x1, int x2, int y, const SkPaint& paint) 64 { 65 SkIRect skrect; 66 skrect.set(x1, y, x2 + 1, y + 1); 67 canvas->drawIRect(skrect, paint); 68 } 69 70 static void drawBox(SkCanvas* canvas, const IntRect& rect, const SkPaint& paint) 71 { 72 const int right = rect.x() + rect.width() - 1; 73 const int bottom = rect.y() + rect.height() - 1; 74 drawHorizLine(canvas, rect.x(), right, rect.y(), paint); 75 drawVertLine(canvas, right, rect.y(), bottom, paint); 76 drawHorizLine(canvas, rect.x(), right, bottom, paint); 77 drawVertLine(canvas, rect.x(), rect.y(), bottom, paint); 48 // Horiz and Vert scrollbars are the same thickness. 49 IntSize scrollbarSize = ChromiumBridge::getThemePartSize(ChromiumBridge::PartScrollbarVerticalTrack); 50 return scrollbarSize.width(); 78 51 } 79 52 80 53 void ScrollbarThemeChromiumLinux::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType) 81 54 { 82 SkCanvas* const canvas = gc->platformContext()->canvas(); 83 SkPaint paint; 84 SkIRect skrect; 85 86 skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); 87 SkScalar trackHSV[3]; 88 SkColorToHSV(PlatformThemeChromiumGtk::trackColor(), trackHSV); 89 paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(trackHSV, 0, 0)); 90 canvas->drawIRect(skrect, paint); 91 92 SkScalar thumbHSV[3]; 93 SkColorToHSV(PlatformThemeChromiumGtk::thumbInactiveColor(), 94 thumbHSV); 95 96 paint.setColor(PlatformThemeChromiumGtk::outlineColor(trackHSV, thumbHSV)); 97 drawBox(canvas, rect, paint); 55 ChromiumBridge::ThemePaintState state = scrollbar->hoveredPart() == partType ? ChromiumBridge::StateHover : ChromiumBridge::StateNormal; 56 IntRect alignRect = trackRect(scrollbar, false); 57 ChromiumBridge::ThemePaintExtraParams extraParams; 58 extraParams.scrollbarTrack.trackX = alignRect.x(); 59 extraParams.scrollbarTrack.trackY = alignRect.y(); 60 extraParams.scrollbarTrack.trackWidth = alignRect.width(); 61 extraParams.scrollbarTrack.trackHeight = alignRect.height(); 62 ChromiumBridge::paintThemePart( 63 gc, 64 scrollbar->orientation() == HorizontalScrollbar ? ChromiumBridge::PartScrollbarHoriztonalTrack : ChromiumBridge::PartScrollbarVerticalTrack, 65 state, 66 rect, 67 &extraParams); 98 68 } 99 69 100 70 void ScrollbarThemeChromiumLinux::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part) 101 71 { 102 PlatformThemeChromiumGtk::ArrowDirection direction; 72 ChromiumBridge::ThemePart paintPart; 73 ChromiumBridge::ThemePaintState state = ChromiumBridge::StateNormal; 74 bool checkMin = false; 75 bool checkMax = false; 103 76 if (scrollbar->orientation() == HorizontalScrollbar) { 104 if (part == BackButtonStartPart) 105 direction = PlatformThemeChromiumGtk::West; 106 else 107 direction = PlatformThemeChromiumGtk::East; 77 if (part == BackButtonStartPart) { 78 paintPart = ChromiumBridge::PartScrollbarLeftArrow; 79 checkMin = true; 80 } else { 81 paintPart = ChromiumBridge::PartScrollbarRightArrow; 82 checkMax = true; 83 } 108 84 } else { 109 if (part == BackButtonStartPart) 110 direction = PlatformThemeChromiumGtk::North; 111 else 112 direction = PlatformThemeChromiumGtk::South; 85 if (part == BackButtonStartPart) { 86 paintPart = ChromiumBridge::PartScrollbarUpArrow; 87 checkMin = true; 88 } else { 89 paintPart = ChromiumBridge::PartScrollbarDownArrow; 90 checkMax = true; 91 } 113 92 } 114 115 ControlStates states = 0; 116 // Determine if the button can be pressed. 117 if (((direction == PlatformThemeChromiumGtk::West || direction == PlatformThemeChromiumGtk::North) && scrollbar->currentPos()) 118 || ((direction == PlatformThemeChromiumGtk::East || direction == PlatformThemeChromiumGtk::South) && scrollbar->currentPos() != scrollbar->maximum())) 119 states |= EnabledState; 120 121 if (states & EnabledState) { 93 if ((checkMin && (scrollbar->currentPos() <= 0)) 94 || (checkMax && scrollbar->currentPos() == scrollbar->maximum())) { 95 state = ChromiumBridge::StateDisabled; 96 } else { 122 97 if (part == scrollbar->pressedPart()) 123 state s |= PressedState;98 state = ChromiumBridge::StatePressed; 124 99 else if (part == scrollbar->hoveredPart()) 125 state s |= HoverState;100 state = ChromiumBridge::StateHover; 126 101 } 127 128 PlatformThemeChromiumGtk::paintArrowButton(gc, rect, direction, states); 102 ChromiumBridge::paintThemePart(gc, paintPart, state, rect, 0); 129 103 } 130 104 131 105 void ScrollbarThemeChromiumLinux::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect) 132 106 { 133 const bool hovered = scrollbar->hoveredPart() == ThumbPart; 134 const int midx = rect.x() + rect.width() / 2; 135 const int midy = rect.y() + rect.height() / 2; 136 const bool vertical = scrollbar->orientation() == VerticalScrollbar; 137 SkCanvas* const canvas = gc->platformContext()->canvas(); 107 ChromiumBridge::ThemePaintState state; 138 108 139 SkScalar thumb[3]; 140 SkColorToHSV(hovered 141 ? PlatformThemeChromiumGtk::thumbActiveColor() 142 : PlatformThemeChromiumGtk::thumbInactiveColor(), 143 thumb); 144 145 SkPaint paint; 146 paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(thumb, 0, 0.02)); 147 148 SkIRect skrect; 149 if (vertical) 150 skrect.set(rect.x(), rect.y(), midx + 1, rect.y() + rect.height()); 109 if (scrollbar->pressedPart() == ThumbPart) 110 state = ChromiumBridge::StatePressed; 111 else if (scrollbar->hoveredPart() == ThumbPart) 112 state = ChromiumBridge::StateHover; 151 113 else 152 skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), midy + 1); 153 154 canvas->drawIRect(skrect, paint); 155 156 paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(thumb, 0, -0.02)); 157 158 if (vertical) 159 skrect.set(midx + 1, rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); 160 else 161 skrect.set(rect.x(), midy + 1, rect.x() + rect.width(), rect.y() + rect.height()); 162 163 canvas->drawIRect(skrect, paint); 164 165 SkScalar track[3]; 166 SkColorToHSV(PlatformThemeChromiumGtk::trackColor(), track); 167 paint.setColor(PlatformThemeChromiumGtk::outlineColor(track, thumb)); 168 drawBox(canvas, rect, paint); 169 170 if (rect.height() > 10 && rect.width() > 10) { 171 const int grippyHalfWidth = 2; 172 const int interGrippyOffset = 3; 173 if (vertical) { 174 drawHorizLine(canvas, midx - grippyHalfWidth, midx + grippyHalfWidth, midy - interGrippyOffset, paint); 175 drawHorizLine(canvas, midx - grippyHalfWidth, midx + grippyHalfWidth, midy, paint); 176 drawHorizLine(canvas, midx - grippyHalfWidth, midx + grippyHalfWidth, midy + interGrippyOffset, paint); 177 } else { 178 drawVertLine(canvas, midx - interGrippyOffset, midy - grippyHalfWidth, midy + grippyHalfWidth, paint); 179 drawVertLine(canvas, midx, midy - grippyHalfWidth, midy + grippyHalfWidth, paint); 180 drawVertLine(canvas, midx + interGrippyOffset, midy - grippyHalfWidth, midy + grippyHalfWidth, paint); 181 } 182 } 114 state = ChromiumBridge::StateNormal; 115 ChromiumBridge::paintThemePart( 116 gc, 117 scrollbar->orientation() == HorizontalScrollbar ? ChromiumBridge::PartScrollbarHorizontalThumb : ChromiumBridge::PartScrollbarVerticalThumb, 118 state, 119 rect, 120 0); 183 121 } 184 122 … … 190 128 IntSize ScrollbarThemeChromiumLinux::buttonSize(Scrollbar* scrollbar) 191 129 { 192 if (scrollbar->orientation() == VerticalScrollbar) 193 return IntSize(scrollbarThicknessValue, scrollbar->height() < 2 * buttonLength ? scrollbar->height() / 2 : buttonLength); 130 if (scrollbar->orientation() == VerticalScrollbar) { 131 IntSize size = ChromiumBridge::getThemePartSize(ChromiumBridge::PartScrollbarUpArrow); 132 return IntSize(size.width(), scrollbar->height() < 2 * size.height() ? scrollbar->height() / 2 : size.height()); 133 } 194 134 195 135 // HorizontalScrollbar 196 return IntSize(scrollbar->width() < 2 * buttonLength ? scrollbar->width() / 2 : buttonLength, scrollbarThicknessValue); 136 IntSize size = ChromiumBridge::getThemePartSize(ChromiumBridge::PartScrollbarLeftArrow); 137 return IntSize(scrollbar->width() < 2 * size.width() ? scrollbar->width() / 2 : size.width(), size.height()); 197 138 } 198 139 199 140 int ScrollbarThemeChromiumLinux::minimumThumbLength(Scrollbar* scrollbar) 200 141 { 201 // This matches Firefox on Linux. 202 return 2 * scrollbarThickness(scrollbar->controlSize()); 142 if (scrollbar->orientation() == VerticalScrollbar) { 143 IntSize size = ChromiumBridge::getThemePartSize(ChromiumBridge::PartScrollbarVerticalThumb); 144 return size.height(); 145 } 146 147 IntSize size = ChromiumBridge::getThemePartSize(ChromiumBridge::PartScrollbarHorizontalThumb); 148 return size.width(); 203 149 } 204 150 -
trunk/WebKit/chromium/ChangeLog
r69551 r69586 1 2010-10-12 Dave Moore <davemoore@chromium.org> 2 3 Reviewed by Tony Chang. 4 5 Use new WebThemeEngine api on chromium / linux to draw scrollbars. 6 https://bugs.webkit.org/show_bug.cgi?id=47473 7 8 * public/WebThemeEngine.h: Removed. 9 * chromium/src/ChromiumBridge.cpp: 10 1 11 2010-10-11 Daniel Cheng <dcheng@chromium.org> 2 12 -
trunk/WebKit/chromium/src/ChromiumBridge.cpp
r69311 r69586 68 68 69 69 #if OS(LINUX) || OS(FREEBSD) 70 #include "linux/WebThemeEngine.h" 70 71 #include "WebFontInfo.h" 71 72 #include "WebFontRenderStyle.h" … … 738 739 webKitClient()->themeEngine()->paintProgressBar( 739 740 gc->platformContext()->canvas(), barRect, valueRect, determinate, animatedSeconds); 741 } 742 743 #elif OS(LINUX) 744 745 static WebThemeEngine::Part WebThemePart(ChromiumBridge::ThemePart part) 746 { 747 switch (part) { 748 case ChromiumBridge::PartScrollbarDownArrow: return WebThemeEngine::PartScrollbarDownArrow; 749 case ChromiumBridge::PartScrollbarLeftArrow: return WebThemeEngine::PartScrollbarLeftArrow; 750 case ChromiumBridge::PartScrollbarRightArrow: return WebThemeEngine::PartScrollbarRightArrow; 751 case ChromiumBridge::PartScrollbarUpArrow: return WebThemeEngine::PartScrollbarUpArrow; 752 case ChromiumBridge::PartScrollbarHorizontalThumb: return WebThemeEngine::PartScrollbarHorizontalThumb; 753 case ChromiumBridge::PartScrollbarVerticalThumb: return WebThemeEngine::PartScrollbarVerticalThumb; 754 case ChromiumBridge::PartScrollbarHoriztonalTrack: return WebThemeEngine::PartScrollbarHoriztonalTrack; 755 case ChromiumBridge::PartScrollbarVerticalTrack: return WebThemeEngine::PartScrollbarVerticalTrack; 756 } 757 ASSERT_NOT_REACHED(); 758 return WebThemeEngine::PartScrollbarDownArrow; 759 } 760 761 static WebThemeEngine::State WebThemeState(ChromiumBridge::ThemePaintState state) 762 { 763 switch (state) { 764 case ChromiumBridge::StateDisabled: return WebThemeEngine::StateDisabled; 765 case ChromiumBridge::StateHover: return WebThemeEngine::StateHover; 766 case ChromiumBridge::StateNormal: return WebThemeEngine::StateNormal; 767 case ChromiumBridge::StatePressed: return WebThemeEngine::StatePressed; 768 } 769 ASSERT_NOT_REACHED(); 770 return WebThemeEngine::StateDisabled; 771 } 772 773 static void GetWebThemeExtraParams(ChromiumBridge::ThemePart part, ChromiumBridge::ThemePaintState state, const ChromiumBridge::ThemePaintExtraParams* extraParams, WebThemeEngine::ExtraParams* webThemeExtraParams) 774 { 775 if (part == ChromiumBridge::PartScrollbarHoriztonalTrack || part == ChromiumBridge::PartScrollbarVerticalTrack) { 776 webThemeExtraParams->scrollbarTrack.trackX = extraParams->scrollbarTrack.trackX; 777 webThemeExtraParams->scrollbarTrack.trackY = extraParams->scrollbarTrack.trackY; 778 webThemeExtraParams->scrollbarTrack.trackWidth = extraParams->scrollbarTrack.trackWidth; 779 webThemeExtraParams->scrollbarTrack.trackHeight = extraParams->scrollbarTrack.trackHeight; 780 } 781 } 782 783 IntSize ChromiumBridge::getThemePartSize(ThemePart part) 784 { 785 return webKitClient()->themeEngine()->getSize(WebThemePart(part)); 786 } 787 788 void ChromiumBridge::paintThemePart( 789 GraphicsContext* gc, ThemePart part, ThemePaintState state, const IntRect& rect, const ThemePaintExtraParams* extraParams) 790 { 791 WebThemeEngine::ExtraParams webThemeExtraParams; 792 GetWebThemeExtraParams(part, state, extraParams, &webThemeExtraParams); 793 webKitClient()->themeEngine()->paint( 794 gc->platformContext()->canvas(), WebThemePart(part), WebThemeState(state), rect, &webThemeExtraParams); 740 795 } 741 796
Note: See TracChangeset
for help on using the changeset viewer.