| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "ScrollbarThemeChromium.h" | 27 #include "ScrollbarThemeChromium.h" |
| 28 | 28 |
| 29 #include <windows.h> | 29 #include <windows.h> |
| 30 #include <vsstyle.h> | 30 #include <vsstyle.h> |
| 31 | 31 |
| 32 #include "ChromiumBridge.h" | 32 #include "ChromiumBridge.h" |
| 33 #include "GraphicsContext.h" | |
| 34 #include "PlatformContextSkia.h" | |
| 35 #include "PlatformMouseEvent.h" | 33 #include "PlatformMouseEvent.h" |
| 36 #include "Scrollbar.h" | 34 #include "Scrollbar.h" |
| 37 | 35 |
| 38 #include "base/gfx/native_theme.h" | |
| 39 #include "base/win_util.h" | |
| 40 | |
| 41 namespace WebCore { | 36 namespace WebCore { |
| 42 | 37 |
| 43 // The scrollbar size in DumpRenderTree on the Mac - so we can match their | 38 // The scrollbar size in DumpRenderTree on the Mac - so we can match their |
| 44 // layout results. Entries are for regular, small, and mini scrollbars. | 39 // layout results. Entries are for regular, small, and mini scrollbars. |
| 45 // Metrics obtained using [NSScroller scrollerWidthForControlSize:] | 40 // Metrics obtained using [NSScroller scrollerWidthForControlSize:] |
| 46 static const int kMacScrollbarSize[3] = { 15, 11, 15 }; | 41 static const int kMacScrollbarSize[3] = { 15, 11, 15 }; |
| 47 | 42 |
| 48 static bool runningVista() | |
| 49 { | |
| 50 return win_util::GetWinVersion() >= win_util::WINVERSION_VISTA; | |
| 51 } | |
| 52 | |
| 53 static RECT toRECT(const IntRect& input) | 43 static RECT toRECT(const IntRect& input) |
| 54 { | 44 { |
| 55 RECT output; | 45 RECT output; |
| 56 output.left = input.x(); | 46 output.left = input.x(); |
| 57 output.right = input.right(); | 47 output.right = input.right(); |
| 58 output.top = input.y(); | 48 output.top = input.y(); |
| 59 output.bottom = input.bottom(); | 49 output.bottom = input.bottom(); |
| 60 return output; | 50 return output; |
| 61 } | 51 } |
| 62 | 52 |
| 63 int ScrollbarThemeChromium::scrollbarThickness(ScrollbarControlSize controlSize) | 53 int ScrollbarThemeChromium::scrollbarThickness(ScrollbarControlSize controlSize) |
| 64 { | 54 { |
| 65 static int thickness; | 55 static int thickness; |
| 66 if (!thickness) { | 56 if (!thickness) { |
| 67 if (ChromiumBridge::layoutTestMode()) | 57 if (ChromiumBridge::layoutTestMode()) |
| 68 return kMacScrollbarSize[controlSize]; | 58 return kMacScrollbarSize[controlSize]; |
| 69 thickness = GetSystemMetrics(SM_CXVSCROLL); | 59 thickness = GetSystemMetrics(SM_CXVSCROLL); |
| 70 } | 60 } |
| 71 return thickness; | 61 return thickness; |
| 72 } | 62 } |
| 73 | 63 |
| 74 bool ScrollbarThemeChromium::invalidateOnMouseEnterExit() | 64 bool ScrollbarThemeChromium::invalidateOnMouseEnterExit() |
| 75 { | 65 { |
| 76 return runningVista(); | 66 return ChromiumBridge::runningVista(); |
| 77 } | 67 } |
| 78 | 68 |
| 79 void ScrollbarThemeChromium::paintTrackPiece(GraphicsContext* gc, Scrollbar* scr
ollbar, const IntRect& rect, ScrollbarPart partType) | 69 void ScrollbarThemeChromium::paintTrackPiece(GraphicsContext* gc, Scrollbar* scr
ollbar, const IntRect& rect, ScrollbarPart partType) |
| 80 { | 70 { |
| 81 bool horz = scrollbar->orientation() == HorizontalScrollbar; | 71 bool horz = scrollbar->orientation() == HorizontalScrollbar; |
| 82 | 72 |
| 83 gfx::PlatformCanvasWin* canvas = gc->platformContext()->canvas(); | 73 HDC hdc = ChromiumBridge::beginPlatformCanvasPaint(gc); |
| 84 HDC hdc = canvas->beginPlatformPaint(); | |
| 85 | 74 |
| 86 RECT paintRect = toRECT(rect); | 75 RECT paintRect = toRECT(rect); |
| 87 | 76 |
| 88 int partId; | 77 int partId; |
| 89 if (partType == BackTrackPart) { | 78 if (partType == BackTrackPart) { |
| 90 partId = horz ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT; | 79 partId = horz ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT; |
| 91 } else { | 80 } else { |
| 92 partId = horz ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT; | 81 partId = horz ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT; |
| 93 } | 82 } |
| 94 | 83 |
| 95 RECT alignRect = toRECT(trackRect(scrollbar, false)); | 84 RECT alignRect = toRECT(trackRect(scrollbar, false)); |
| 96 | 85 |
| 97 // Draw the track area before/after the thumb on the scroll bar. | 86 // Draw the track area before/after the thumb on the scroll bar. |
| 98 gfx::NativeTheme::instance()->PaintScrollbarTrack( | 87 ChromiumBridge::paintScrollbarTrack( |
| 99 hdc, | 88 hdc, |
| 100 partId, | 89 partId, |
| 101 getThemeState(scrollbar, partType), | 90 getThemeState(scrollbar, partType), |
| 102 getClassicThemeState(scrollbar, partType), | 91 getClassicThemeState(scrollbar, partType), |
| 103 &paintRect, | 92 &paintRect, |
| 104 &alignRect, | 93 &alignRect, |
| 105 gc->platformContext()->canvas()); | 94 gc); |
| 106 | 95 |
| 107 canvas->endPlatformPaint(); | 96 ChromiumBridge::endPlatformCanvasPaint(gc); |
| 108 } | 97 } |
| 109 | 98 |
| 110 void ScrollbarThemeChromium::paintButton(GraphicsContext* gc, Scrollbar* scrollb
ar, const IntRect& rect, ScrollbarPart part) | 99 void ScrollbarThemeChromium::paintButton(GraphicsContext* gc, Scrollbar* scrollb
ar, const IntRect& rect, ScrollbarPart part) |
| 111 { | 100 { |
| 112 bool horz = scrollbar->orientation() == HorizontalScrollbar; | 101 bool horz = scrollbar->orientation() == HorizontalScrollbar; |
| 113 | 102 |
| 114 gfx::PlatformCanvasWin* canvas = gc->platformContext()->canvas(); | 103 HDC hdc = ChromiumBridge::beginPlatformCanvasPaint(gc); |
| 115 HDC hdc = canvas->beginPlatformPaint(); | |
| 116 | 104 |
| 117 RECT paintRect = toRECT(rect); | 105 RECT paintRect = toRECT(rect); |
| 118 | 106 |
| 119 int partId; | 107 int partId; |
| 120 if (part == BackButtonStartPart || part == ForwardButtonStartPart) { | 108 if (part == BackButtonStartPart || part == ForwardButtonStartPart) { |
| 121 partId = horz ? DFCS_SCROLLLEFT : DFCS_SCROLLUP; | 109 partId = horz ? DFCS_SCROLLLEFT : DFCS_SCROLLUP; |
| 122 } else { | 110 } else { |
| 123 partId = horz ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN; | 111 partId = horz ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN; |
| 124 } | 112 } |
| 125 | 113 |
| 126 // Draw the thumb (the box you drag in the scroll bar to scroll). | 114 // Draw the thumb (the box you drag in the scroll bar to scroll). |
| 127 gfx::NativeTheme::instance()->PaintScrollbarArrow( | 115 ChromiumBridge::paintScrollbarArrow( |
| 128 hdc, | 116 hdc, |
| 129 getThemeArrowState(scrollbar, part), | 117 getThemeArrowState(scrollbar, part), |
| 130 partId | getClassicThemeState(scrollbar, part), | 118 partId | getClassicThemeState(scrollbar, part), |
| 131 &paintRect); | 119 &paintRect); |
| 132 | 120 |
| 133 canvas->endPlatformPaint(); | 121 ChromiumBridge::endPlatformCanvasPaint(gc); |
| 134 } | 122 } |
| 135 | 123 |
| 136 void ScrollbarThemeChromium::paintThumb(GraphicsContext* gc, Scrollbar* scrollba
r, const IntRect& rect) | 124 void ScrollbarThemeChromium::paintThumb(GraphicsContext* gc, Scrollbar* scrollba
r, const IntRect& rect) |
| 137 { | 125 { |
| 138 bool horz = scrollbar->orientation() == HorizontalScrollbar; | 126 bool horz = scrollbar->orientation() == HorizontalScrollbar; |
| 139 | 127 |
| 140 gfx::PlatformCanvasWin* canvas = gc->platformContext()->canvas(); | 128 HDC hdc = ChromiumBridge::beginPlatformCanvasPaint(gc); |
| 141 HDC hdc = canvas->beginPlatformPaint(); | |
| 142 | 129 |
| 143 RECT paintRect = toRECT(rect); | 130 RECT paintRect = toRECT(rect); |
| 144 | 131 |
| 145 // Draw the thumb (the box you drag in the scroll bar to scroll). | 132 // Draw the thumb (the box you drag in the scroll bar to scroll). |
| 146 gfx::NativeTheme::instance()->PaintScrollbarThumb( | 133 ChromiumBridge::paintScrollbarThumb( |
| 147 hdc, | 134 hdc, |
| 148 horz ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT, | 135 horz ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT, |
| 149 getThemeState(scrollbar, ThumbPart), | 136 getThemeState(scrollbar, ThumbPart), |
| 150 getClassicThemeState(scrollbar, ThumbPart), | 137 getClassicThemeState(scrollbar, ThumbPart), |
| 151 &paintRect); | 138 &paintRect); |
| 152 | 139 |
| 153 // Draw the gripper (the three little lines on the thumb). | 140 // Draw the gripper (the three little lines on the thumb). |
| 154 gfx::NativeTheme::instance()->PaintScrollbarThumb( | 141 ChromiumBridge::paintScrollbarThumb( |
| 155 hdc, | 142 hdc, |
| 156 horz ? SBP_GRIPPERHORZ : SBP_GRIPPERVERT, | 143 horz ? SBP_GRIPPERHORZ : SBP_GRIPPERVERT, |
| 157 getThemeState(scrollbar, ThumbPart), | 144 getThemeState(scrollbar, ThumbPart), |
| 158 getClassicThemeState(scrollbar, ThumbPart), | 145 getClassicThemeState(scrollbar, ThumbPart), |
| 159 &paintRect); | 146 &paintRect); |
| 160 | 147 |
| 161 canvas->endPlatformPaint(); | 148 ChromiumBridge::endPlatformCanvasPaint(gc); |
| 162 } | 149 } |
| 163 | 150 |
| 164 int ScrollbarThemeChromium::getThemeState(Scrollbar* scrollbar, ScrollbarPart pa
rt) const | 151 int ScrollbarThemeChromium::getThemeState(Scrollbar* scrollbar, ScrollbarPart pa
rt) const |
| 165 { | 152 { |
| 166 // When dragging the thumb, draw thumb pressed and other segments normal | 153 // When dragging the thumb, draw thumb pressed and other segments normal |
| 167 // regardless of where the cursor actually is. See also four places in | 154 // regardless of where the cursor actually is. See also four places in |
| 168 // getThemeArrowState(). | 155 // getThemeArrowState(). |
| 169 if (scrollbar->pressedPart() == ThumbPart) { | 156 if (scrollbar->pressedPart() == ThumbPart) { |
| 170 if (part == ThumbPart) | 157 if (part == ThumbPart) |
| 171 return SCRBS_PRESSED; | 158 return SCRBS_PRESSED; |
| 172 return runningVista() ? SCRBS_HOVER : SCRBS_NORMAL; | 159 return ChromiumBridge::runningVista() ? SCRBS_HOVER : SCRBS_NORMAL; |
| 173 } | 160 } |
| 174 if (!scrollbar->enabled()) | 161 if (!scrollbar->enabled()) |
| 175 return SCRBS_DISABLED; | 162 return SCRBS_DISABLED; |
| 176 if (scrollbar->hoveredPart() != part || part == BackTrackPart || part == For
wardTrackPart) | 163 if (scrollbar->hoveredPart() != part || part == BackTrackPart || part == For
wardTrackPart) |
| 177 return (scrollbar->hoveredPart() == NoPart || !runningVista()) ? SCRBS_N
ORMAL : SCRBS_HOVER; | 164 return (scrollbar->hoveredPart() == NoPart || !ChromiumBridge::runningVi
sta()) ? SCRBS_NORMAL : SCRBS_HOVER; |
| 178 if (scrollbar->pressedPart() == NoPart) | 165 if (scrollbar->pressedPart() == NoPart) |
| 179 return SCRBS_HOT; | 166 return SCRBS_HOT; |
| 180 return (scrollbar->pressedPart() == part) ? SCRBS_PRESSED : SCRBS_NORMAL; | 167 return (scrollbar->pressedPart() == part) ? SCRBS_PRESSED : SCRBS_NORMAL; |
| 181 } | 168 } |
| 182 | 169 |
| 183 int ScrollbarThemeChromium::getThemeArrowState(Scrollbar* scrollbar, ScrollbarPa
rt part) const | 170 int ScrollbarThemeChromium::getThemeArrowState(Scrollbar* scrollbar, ScrollbarPa
rt part) const |
| 184 { | 171 { |
| 185 // We could take advantage of knowing the values in the state enum to write | 172 // We could take advantage of knowing the values in the state enum to write |
| 186 // some simpler code, but treating the state enum as a black box seems | 173 // some simpler code, but treating the state enum as a black box seems |
| 187 // clearer and more future-proof. | 174 // clearer and more future-proof. |
| 188 if (part == BackButtonStartPart || part == ForwardButtonStartPart) { | 175 if (part == BackButtonStartPart || part == ForwardButtonStartPart) { |
| 189 if (scrollbar->orientation() == HorizontalScrollbar) { | 176 if (scrollbar->orientation() == HorizontalScrollbar) { |
| 190 if (scrollbar->pressedPart() == ThumbPart) | 177 if (scrollbar->pressedPart() == ThumbPart) |
| 191 return !runningVista() ? ABS_LEFTNORMAL : ABS_LEFTHOVER; | 178 return !ChromiumBridge::runningVista() ? ABS_LEFTNORMAL : ABS_LE
FTHOVER; |
| 192 if (!scrollbar->enabled()) | 179 if (!scrollbar->enabled()) |
| 193 return ABS_LEFTDISABLED; | 180 return ABS_LEFTDISABLED; |
| 194 if (scrollbar->hoveredPart() != part) | 181 if (scrollbar->hoveredPart() != part) |
| 195 return ((scrollbar->hoveredPart() == NoPart) || !runningVista())
? ABS_LEFTNORMAL : ABS_LEFTHOVER; | 182 return ((scrollbar->hoveredPart() == NoPart) || !ChromiumBridge:
:runningVista()) ? ABS_LEFTNORMAL : ABS_LEFTHOVER; |
| 196 if (scrollbar->pressedPart() == NoPart) | 183 if (scrollbar->pressedPart() == NoPart) |
| 197 return ABS_LEFTHOT; | 184 return ABS_LEFTHOT; |
| 198 return (scrollbar->pressedPart() == part) ? | 185 return (scrollbar->pressedPart() == part) ? |
| 199 ABS_LEFTPRESSED : ABS_LEFTNORMAL; | 186 ABS_LEFTPRESSED : ABS_LEFTNORMAL; |
| 200 } | 187 } |
| 201 if (scrollbar->pressedPart() == ThumbPart) | 188 if (scrollbar->pressedPart() == ThumbPart) |
| 202 return !runningVista() ? ABS_UPNORMAL : ABS_UPHOVER; | 189 return !ChromiumBridge::runningVista() ? ABS_UPNORMAL : ABS_UPHOVER; |
| 203 if (!scrollbar->enabled()) | 190 if (!scrollbar->enabled()) |
| 204 return ABS_UPDISABLED; | 191 return ABS_UPDISABLED; |
| 205 if (scrollbar->hoveredPart() != part) | 192 if (scrollbar->hoveredPart() != part) |
| 206 return ((scrollbar->hoveredPart() == NoPart) || !runningVista()) ? A
BS_UPNORMAL : ABS_UPHOVER; | 193 return ((scrollbar->hoveredPart() == NoPart) || !ChromiumBridge::run
ningVista()) ? ABS_UPNORMAL : ABS_UPHOVER; |
| 207 if (scrollbar->pressedPart() == NoPart) | 194 if (scrollbar->pressedPart() == NoPart) |
| 208 return ABS_UPHOT; | 195 return ABS_UPHOT; |
| 209 return (scrollbar->pressedPart() == part) ? ABS_UPPRESSED : ABS_UPNORMAL
; | 196 return (scrollbar->pressedPart() == part) ? ABS_UPPRESSED : ABS_UPNORMAL
; |
| 210 } | 197 } |
| 211 if (scrollbar->orientation() == HorizontalScrollbar) { | 198 if (scrollbar->orientation() == HorizontalScrollbar) { |
| 212 if (scrollbar->pressedPart() == ThumbPart) | 199 if (scrollbar->pressedPart() == ThumbPart) |
| 213 return !runningVista() ? ABS_RIGHTNORMAL : ABS_RIGHTHOVER; | 200 return !ChromiumBridge::runningVista() ? ABS_RIGHTNORMAL : ABS_RIGHT
HOVER; |
| 214 if (!scrollbar->enabled()) | 201 if (!scrollbar->enabled()) |
| 215 return ABS_RIGHTDISABLED; | 202 return ABS_RIGHTDISABLED; |
| 216 if (scrollbar->hoveredPart() != part) | 203 if (scrollbar->hoveredPart() != part) |
| 217 return ((scrollbar->hoveredPart() == NoPart) || !runningVista()) ? A
BS_RIGHTNORMAL : ABS_RIGHTHOVER; | 204 return ((scrollbar->hoveredPart() == NoPart) || !ChromiumBridge::run
ningVista()) ? ABS_RIGHTNORMAL : ABS_RIGHTHOVER; |
| 218 if (scrollbar->pressedPart() == NoPart) | 205 if (scrollbar->pressedPart() == NoPart) |
| 219 return ABS_RIGHTHOT; | 206 return ABS_RIGHTHOT; |
| 220 return (scrollbar->pressedPart() == part) ? ABS_RIGHTPRESSED : ABS_RIGHT
NORMAL; | 207 return (scrollbar->pressedPart() == part) ? ABS_RIGHTPRESSED : ABS_RIGHT
NORMAL; |
| 221 } | 208 } |
| 222 if (scrollbar->pressedPart() == ThumbPart) | 209 if (scrollbar->pressedPart() == ThumbPart) |
| 223 return !runningVista() ? ABS_DOWNNORMAL : ABS_DOWNHOVER; | 210 return !ChromiumBridge::runningVista() ? ABS_DOWNNORMAL : ABS_DOWNHOVER; |
| 224 if (!scrollbar->enabled()) | 211 if (!scrollbar->enabled()) |
| 225 return ABS_DOWNDISABLED; | 212 return ABS_DOWNDISABLED; |
| 226 if (scrollbar->hoveredPart() != part) | 213 if (scrollbar->hoveredPart() != part) |
| 227 return ((scrollbar->hoveredPart() == NoPart) || !runningVista()) ? ABS_D
OWNNORMAL : ABS_DOWNHOVER; | 214 return ((scrollbar->hoveredPart() == NoPart) || !ChromiumBridge::running
Vista()) ? ABS_DOWNNORMAL : ABS_DOWNHOVER; |
| 228 if (scrollbar->pressedPart() == NoPart) | 215 if (scrollbar->pressedPart() == NoPart) |
| 229 return ABS_DOWNHOT; | 216 return ABS_DOWNHOT; |
| 230 return (scrollbar->pressedPart() == part) ? ABS_DOWNPRESSED : ABS_DOWNNORMAL
; | 217 return (scrollbar->pressedPart() == part) ? ABS_DOWNPRESSED : ABS_DOWNNORMAL
; |
| 231 } | 218 } |
| 232 | 219 |
| 233 int ScrollbarThemeChromium::getClassicThemeState(Scrollbar* scrollbar, Scrollbar
Part part) const | 220 int ScrollbarThemeChromium::getClassicThemeState(Scrollbar* scrollbar, Scrollbar
Part part) const |
| 234 { | 221 { |
| 235 // When dragging the thumb, draw the buttons normal even when hovered. | 222 // When dragging the thumb, draw the buttons normal even when hovered. |
| 236 if (scrollbar->pressedPart() == ThumbPart) | 223 if (scrollbar->pressedPart() == ThumbPart) |
| 237 return 0; | 224 return 0; |
| 238 if (!scrollbar->enabled()) | 225 if (!scrollbar->enabled()) |
| 239 return DFCS_INACTIVE; | 226 return DFCS_INACTIVE; |
| 240 if (scrollbar->hoveredPart() != part || part == BackTrackPart || part == For
wardTrackPart) | 227 if (scrollbar->hoveredPart() != part || part == BackTrackPart || part == For
wardTrackPart) |
| 241 return 0; | 228 return 0; |
| 242 if (scrollbar->pressedPart() == NoPart) | 229 if (scrollbar->pressedPart() == NoPart) |
| 243 return DFCS_HOT; | 230 return DFCS_HOT; |
| 244 return (scrollbar->pressedPart() == part) ? (DFCS_PUSHED | DFCS_FLAT) : 0; | 231 return (scrollbar->pressedPart() == part) ? (DFCS_PUSHED | DFCS_FLAT) : 0; |
| 245 } | 232 } |
| 246 | 233 |
| 247 } | 234 } |
| OLD | NEW |