| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2011 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 namespace blink { | 50 namespace blink { |
| 51 | 51 |
| 52 bool ScrollbarTheme::gMockScrollbarsEnabled = false; | 52 bool ScrollbarTheme::gMockScrollbarsEnabled = false; |
| 53 | 53 |
| 54 static inline bool shouldPaintScrollbarPart(const IntRect& partRect, const CullR
ect& cullRect) | 54 static inline bool shouldPaintScrollbarPart(const IntRect& partRect, const CullR
ect& cullRect) |
| 55 { | 55 { |
| 56 return (!partRect.isEmpty()) || cullRect.intersectsCullRect(partRect); | 56 return (!partRect.isEmpty()) || cullRect.intersectsCullRect(partRect); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool ScrollbarTheme::paint(const ScrollbarThemeClient* scrollbar, GraphicsContex
t* graphicsContext, const CullRect& cullRect) | 59 bool ScrollbarTheme::paint(const ScrollbarThemeClient& scrollbar, GraphicsContex
t& graphicsContext, const CullRect& cullRect) |
| 60 { | 60 { |
| 61 // Create the ScrollbarControlPartMask based on the cullRect | 61 // Create the ScrollbarControlPartMask based on the cullRect |
| 62 ScrollbarControlPartMask scrollMask = NoPart; | 62 ScrollbarControlPartMask scrollMask = NoPart; |
| 63 | 63 |
| 64 IntRect backButtonStartPaintRect; | 64 IntRect backButtonStartPaintRect; |
| 65 IntRect backButtonEndPaintRect; | 65 IntRect backButtonEndPaintRect; |
| 66 IntRect forwardButtonStartPaintRect; | 66 IntRect forwardButtonStartPaintRect; |
| 67 IntRect forwardButtonEndPaintRect; | 67 IntRect forwardButtonEndPaintRect; |
| 68 if (hasButtons(scrollbar)) { | 68 if (hasButtons(scrollbar)) { |
| 69 backButtonStartPaintRect = backButtonRect(scrollbar, BackButtonStartPart
, true); | 69 backButtonStartPaintRect = backButtonRect(scrollbar, BackButtonStartPart
, true); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 paintTickmarks(graphicsContext, scrollbar, trackPaintRect); | 123 paintTickmarks(graphicsContext, scrollbar, trackPaintRect); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Paint the thumb. | 126 // Paint the thumb. |
| 127 if (scrollMask & ThumbPart) | 127 if (scrollMask & ThumbPart) |
| 128 paintThumb(graphicsContext, scrollbar, thumbRect); | 128 paintThumb(graphicsContext, scrollbar, thumbRect); |
| 129 | 129 |
| 130 return true; | 130 return true; |
| 131 } | 131 } |
| 132 | 132 |
| 133 ScrollbarPart ScrollbarTheme::hitTest(const ScrollbarThemeClient* scrollbar, con
st IntPoint& positionInRootFrame) | 133 ScrollbarPart ScrollbarTheme::hitTest(const ScrollbarThemeClient& scrollbar, con
st IntPoint& positionInRootFrame) |
| 134 { | 134 { |
| 135 ScrollbarPart result = NoPart; | 135 ScrollbarPart result = NoPart; |
| 136 if (!scrollbar->enabled()) | 136 if (!scrollbar.enabled()) |
| 137 return result; | 137 return result; |
| 138 | 138 |
| 139 IntPoint testPosition = scrollbar->convertFromRootFrame(positionInRootFrame)
; | 139 IntPoint testPosition = scrollbar.convertFromRootFrame(positionInRootFrame); |
| 140 testPosition.move(scrollbar->x(), scrollbar->y()); | 140 testPosition.move(scrollbar.x(), scrollbar.y()); |
| 141 | 141 |
| 142 if (!scrollbar->frameRect().contains(testPosition)) | 142 if (!scrollbar.frameRect().contains(testPosition)) |
| 143 return NoPart; | 143 return NoPart; |
| 144 | 144 |
| 145 result = ScrollbarBGPart; | 145 result = ScrollbarBGPart; |
| 146 | 146 |
| 147 IntRect track = trackRect(scrollbar); | 147 IntRect track = trackRect(scrollbar); |
| 148 if (track.contains(testPosition)) { | 148 if (track.contains(testPosition)) { |
| 149 IntRect beforeThumbRect; | 149 IntRect beforeThumbRect; |
| 150 IntRect thumbRect; | 150 IntRect thumbRect; |
| 151 IntRect afterThumbRect; | 151 IntRect afterThumbRect; |
| 152 splitTrack(scrollbar, track, beforeThumbRect, thumbRect, afterThumbRect)
; | 152 splitTrack(scrollbar, track, beforeThumbRect, thumbRect, afterThumbRect)
; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 163 } else if (backButtonRect(scrollbar, BackButtonEndPart).contains(testPositio
n)) { | 163 } else if (backButtonRect(scrollbar, BackButtonEndPart).contains(testPositio
n)) { |
| 164 result = BackButtonEndPart; | 164 result = BackButtonEndPart; |
| 165 } else if (forwardButtonRect(scrollbar, ForwardButtonStartPart).contains(tes
tPosition)) { | 165 } else if (forwardButtonRect(scrollbar, ForwardButtonStartPart).contains(tes
tPosition)) { |
| 166 result = ForwardButtonStartPart; | 166 result = ForwardButtonStartPart; |
| 167 } else if (forwardButtonRect(scrollbar, ForwardButtonEndPart).contains(testP
osition)) { | 167 } else if (forwardButtonRect(scrollbar, ForwardButtonEndPart).contains(testP
osition)) { |
| 168 result = ForwardButtonEndPart; | 168 result = ForwardButtonEndPart; |
| 169 } | 169 } |
| 170 return result; | 170 return result; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void ScrollbarTheme::paintScrollCorner(GraphicsContext* context, const DisplayIt
emClient& displayItemClient, const IntRect& cornerRect) | 173 void ScrollbarTheme::paintScrollCorner(GraphicsContext& context, const DisplayIt
emClient& displayItemClient, const IntRect& cornerRect) |
| 174 { | 174 { |
| 175 if (cornerRect.isEmpty()) | 175 if (cornerRect.isEmpty()) |
| 176 return; | 176 return; |
| 177 | 177 |
| 178 if (DrawingRecorder::useCachedDrawingIfPossible(*context, displayItemClient,
DisplayItem::ScrollbarCorner)) | 178 if (DrawingRecorder::useCachedDrawingIfPossible(context, displayItemClient,
DisplayItem::ScrollbarCorner)) |
| 179 return; | 179 return; |
| 180 | 180 |
| 181 DrawingRecorder recorder(*context, displayItemClient, DisplayItem::Scrollbar
Corner, cornerRect); | 181 DrawingRecorder recorder(context, displayItemClient, DisplayItem::ScrollbarC
orner, cornerRect); |
| 182 #if OS(MACOSX) | 182 #if OS(MACOSX) |
| 183 context->fillRect(cornerRect, Color::white); | 183 context.fillRect(cornerRect, Color::white); |
| 184 #else | 184 #else |
| 185 Platform::current()->themeEngine()->paint(context->canvas(), WebThemeEngine:
:PartScrollbarCorner, WebThemeEngine::StateNormal, WebRect(cornerRect), 0); | 185 Platform::current()->themeEngine()->paint(context.canvas(), WebThemeEngine::
PartScrollbarCorner, WebThemeEngine::StateNormal, WebRect(cornerRect), 0); |
| 186 #endif | 186 #endif |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool ScrollbarTheme::shouldCenterOnThumb(const ScrollbarThemeClient* scrollbar,
const PlatformMouseEvent& evt) | 189 bool ScrollbarTheme::shouldCenterOnThumb(const ScrollbarThemeClient& scrollbar,
const PlatformMouseEvent& evt) |
| 190 { | 190 { |
| 191 return Platform::current()->scrollbarBehavior()->shouldCenterOnThumb(static_
cast<WebScrollbarBehavior::Button>(evt.button()), evt.shiftKey(), evt.altKey()); | 191 return Platform::current()->scrollbarBehavior()->shouldCenterOnThumb(static_
cast<WebScrollbarBehavior::Button>(evt.button()), evt.shiftKey(), evt.altKey()); |
| 192 } | 192 } |
| 193 | 193 |
| 194 bool ScrollbarTheme::shouldSnapBackToDragOrigin(const ScrollbarThemeClient* scro
llbar, const PlatformMouseEvent& evt) | 194 bool ScrollbarTheme::shouldSnapBackToDragOrigin(const ScrollbarThemeClient& scro
llbar, const PlatformMouseEvent& evt) |
| 195 { | 195 { |
| 196 IntPoint mousePosition = scrollbar->convertFromRootFrame(evt.position()); | 196 IntPoint mousePosition = scrollbar.convertFromRootFrame(evt.position()); |
| 197 mousePosition.move(scrollbar->x(), scrollbar->y()); | 197 mousePosition.move(scrollbar.x(), scrollbar.y()); |
| 198 return Platform::current()->scrollbarBehavior()->shouldSnapBackToDragOrigin(
mousePosition, trackRect(scrollbar), scrollbar->orientation() == HorizontalScrol
lbar); | 198 return Platform::current()->scrollbarBehavior()->shouldSnapBackToDragOrigin(
mousePosition, trackRect(scrollbar), scrollbar.orientation() == HorizontalScroll
bar); |
| 199 } | 199 } |
| 200 | 200 |
| 201 int ScrollbarTheme::thumbPosition(const ScrollbarThemeClient* scrollbar) | 201 int ScrollbarTheme::thumbPosition(const ScrollbarThemeClient& scrollbar) |
| 202 { | 202 { |
| 203 if (scrollbar->enabled()) { | 203 if (scrollbar.enabled()) { |
| 204 float size = scrollbar->totalSize() - scrollbar->visibleSize(); | 204 float size = scrollbar.totalSize() - scrollbar.visibleSize(); |
| 205 // Avoid doing a floating point divide by zero and return 1 when usedTot
alSize == visibleSize. | 205 // Avoid doing a floating point divide by zero and return 1 when usedTot
alSize == visibleSize. |
| 206 if (!size) | 206 if (!size) |
| 207 return 0; | 207 return 0; |
| 208 float pos = std::max(0.0f, scrollbar->currentPos()) * (trackLength(scrol
lbar) - thumbLength(scrollbar)) / size; | 208 float pos = std::max(0.0f, scrollbar.currentPos()) * (trackLength(scroll
bar) - thumbLength(scrollbar)) / size; |
| 209 return (pos < 1 && pos > 0) ? 1 : pos; | 209 return (pos < 1 && pos > 0) ? 1 : pos; |
| 210 } | 210 } |
| 211 return 0; | 211 return 0; |
| 212 } | 212 } |
| 213 | 213 |
| 214 int ScrollbarTheme::thumbLength(const ScrollbarThemeClient* scrollbar) | 214 int ScrollbarTheme::thumbLength(const ScrollbarThemeClient& scrollbar) |
| 215 { | 215 { |
| 216 if (!scrollbar->enabled()) | 216 if (!scrollbar.enabled()) |
| 217 return 0; | 217 return 0; |
| 218 | 218 |
| 219 float overhang = fabsf(scrollbar->elasticOverscroll()); | 219 float overhang = fabsf(scrollbar.elasticOverscroll()); |
| 220 float proportion = 0.0f; | 220 float proportion = 0.0f; |
| 221 float totalSize = scrollbar->totalSize(); | 221 float totalSize = scrollbar.totalSize(); |
| 222 if (totalSize > 0.0f) { | 222 if (totalSize > 0.0f) { |
| 223 proportion = (scrollbar->visibleSize() - overhang) / totalSize; | 223 proportion = (scrollbar.visibleSize() - overhang) / totalSize; |
| 224 } | 224 } |
| 225 int trackLen = trackLength(scrollbar); | 225 int trackLen = trackLength(scrollbar); |
| 226 int length = round(proportion * trackLen); | 226 int length = round(proportion * trackLen); |
| 227 length = std::max(length, minimumThumbLength(scrollbar)); | 227 length = std::max(length, minimumThumbLength(scrollbar)); |
| 228 if (length > trackLen) | 228 if (length > trackLen) |
| 229 length = 0; // Once the thumb is below the track length, it just goes aw
ay (to make more room for the track). | 229 length = 0; // Once the thumb is below the track length, it just goes aw
ay (to make more room for the track). |
| 230 return length; | 230 return length; |
| 231 } | 231 } |
| 232 | 232 |
| 233 int ScrollbarTheme::trackPosition(const ScrollbarThemeClient* scrollbar) | 233 int ScrollbarTheme::trackPosition(const ScrollbarThemeClient& scrollbar) |
| 234 { | 234 { |
| 235 IntRect constrainedTrackRect = constrainTrackRectToTrackPieces(scrollbar, tr
ackRect(scrollbar)); | 235 IntRect constrainedTrackRect = constrainTrackRectToTrackPieces(scrollbar, tr
ackRect(scrollbar)); |
| 236 return (scrollbar->orientation() == HorizontalScrollbar) ? constrainedTrackR
ect.x() - scrollbar->x() : constrainedTrackRect.y() - scrollbar->y(); | 236 return (scrollbar.orientation() == HorizontalScrollbar) ? constrainedTrackRe
ct.x() - scrollbar.x() : constrainedTrackRect.y() - scrollbar.y(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 int ScrollbarTheme::trackLength(const ScrollbarThemeClient* scrollbar) | 239 int ScrollbarTheme::trackLength(const ScrollbarThemeClient& scrollbar) |
| 240 { | 240 { |
| 241 IntRect constrainedTrackRect = constrainTrackRectToTrackPieces(scrollbar, tr
ackRect(scrollbar)); | 241 IntRect constrainedTrackRect = constrainTrackRectToTrackPieces(scrollbar, tr
ackRect(scrollbar)); |
| 242 return (scrollbar->orientation() == HorizontalScrollbar) ? constrainedTrackR
ect.width() : constrainedTrackRect.height(); | 242 return (scrollbar.orientation() == HorizontalScrollbar) ? constrainedTrackRe
ct.width() : constrainedTrackRect.height(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 IntRect ScrollbarTheme::thumbRect(const ScrollbarThemeClient* scrollbar) | 245 IntRect ScrollbarTheme::thumbRect(const ScrollbarThemeClient& scrollbar) |
| 246 { | 246 { |
| 247 if (!hasThumb(scrollbar)) | 247 if (!hasThumb(scrollbar)) |
| 248 return IntRect(); | 248 return IntRect(); |
| 249 | 249 |
| 250 IntRect track = trackRect(scrollbar); | 250 IntRect track = trackRect(scrollbar); |
| 251 IntRect startTrackRect; | 251 IntRect startTrackRect; |
| 252 IntRect thumbRect; | 252 IntRect thumbRect; |
| 253 IntRect endTrackRect; | 253 IntRect endTrackRect; |
| 254 splitTrack(scrollbar, track, startTrackRect, thumbRect, endTrackRect); | 254 splitTrack(scrollbar, track, startTrackRect, thumbRect, endTrackRect); |
| 255 | 255 |
| 256 return thumbRect; | 256 return thumbRect; |
| 257 } | 257 } |
| 258 | 258 |
| 259 int ScrollbarTheme::thumbThickness(const ScrollbarThemeClient* scrollbar) | 259 int ScrollbarTheme::thumbThickness(const ScrollbarThemeClient& scrollbar) |
| 260 { | 260 { |
| 261 IntRect track = trackRect(scrollbar); | 261 IntRect track = trackRect(scrollbar); |
| 262 return scrollbar->orientation() == HorizontalScrollbar ? track.height() : tr
ack.width(); | 262 return scrollbar.orientation() == HorizontalScrollbar ? track.height() : tra
ck.width(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 int ScrollbarTheme::minimumThumbLength(const ScrollbarThemeClient* scrollbar) | 265 int ScrollbarTheme::minimumThumbLength(const ScrollbarThemeClient& scrollbar) |
| 266 { | 266 { |
| 267 return scrollbarThickness(scrollbar->controlSize()); | 267 return scrollbarThickness(scrollbar.controlSize()); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void ScrollbarTheme::splitTrack(const ScrollbarThemeClient* scrollbar, const Int
Rect& unconstrainedTrackRect, IntRect& beforeThumbRect, IntRect& thumbRect, IntR
ect& afterThumbRect) | 270 void ScrollbarTheme::splitTrack(const ScrollbarThemeClient& scrollbar, const Int
Rect& unconstrainedTrackRect, IntRect& beforeThumbRect, IntRect& thumbRect, IntR
ect& afterThumbRect) |
| 271 { | 271 { |
| 272 // This function won't even get called unless we're big enough to have some
combination of these three rects where at least | 272 // This function won't even get called unless we're big enough to have some
combination of these three rects where at least |
| 273 // one of them is non-empty. | 273 // one of them is non-empty. |
| 274 IntRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrained
TrackRect); | 274 IntRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrained
TrackRect); |
| 275 int thumbPos = thumbPosition(scrollbar); | 275 int thumbPos = thumbPosition(scrollbar); |
| 276 if (scrollbar->orientation() == HorizontalScrollbar) { | 276 if (scrollbar.orientation() == HorizontalScrollbar) { |
| 277 thumbRect = IntRect(trackRect.x() + thumbPos, trackRect.y(), thumbLength
(scrollbar), scrollbar->height()); | 277 thumbRect = IntRect(trackRect.x() + thumbPos, trackRect.y(), thumbLength
(scrollbar), scrollbar.height()); |
| 278 beforeThumbRect = IntRect(trackRect.x(), trackRect.y(), thumbPos + thumb
Rect.width() / 2, trackRect.height()); | 278 beforeThumbRect = IntRect(trackRect.x(), trackRect.y(), thumbPos + thumb
Rect.width() / 2, trackRect.height()); |
| 279 afterThumbRect = IntRect(trackRect.x() + beforeThumbRect.width(), trackR
ect.y(), trackRect.maxX() - beforeThumbRect.maxX(), trackRect.height()); | 279 afterThumbRect = IntRect(trackRect.x() + beforeThumbRect.width(), trackR
ect.y(), trackRect.maxX() - beforeThumbRect.maxX(), trackRect.height()); |
| 280 } else { | 280 } else { |
| 281 thumbRect = IntRect(trackRect.x(), trackRect.y() + thumbPos, scrollbar->
width(), thumbLength(scrollbar)); | 281 thumbRect = IntRect(trackRect.x(), trackRect.y() + thumbPos, scrollbar.w
idth(), thumbLength(scrollbar)); |
| 282 beforeThumbRect = IntRect(trackRect.x(), trackRect.y(), trackRect.width(
), thumbPos + thumbRect.height() / 2); | 282 beforeThumbRect = IntRect(trackRect.x(), trackRect.y(), trackRect.width(
), thumbPos + thumbRect.height() / 2); |
| 283 afterThumbRect = IntRect(trackRect.x(), trackRect.y() + beforeThumbRect.
height(), trackRect.width(), trackRect.maxY() - beforeThumbRect.maxY()); | 283 afterThumbRect = IntRect(trackRect.x(), trackRect.y() + beforeThumbRect.
height(), trackRect.width(), trackRect.maxY() - beforeThumbRect.maxY()); |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 ScrollbarTheme* ScrollbarTheme::theme() | 287 ScrollbarTheme& ScrollbarTheme::theme() |
| 288 { | 288 { |
| 289 if (ScrollbarTheme::mockScrollbarsEnabled()) { | 289 if (ScrollbarTheme::mockScrollbarsEnabled()) { |
| 290 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { | 290 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { |
| 291 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlayMock, overlayMockTheme, ())
; | 291 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlayMock, overlayMockTheme, ())
; |
| 292 return &overlayMockTheme; | 292 return overlayMockTheme; |
| 293 } | 293 } |
| 294 | 294 |
| 295 DEFINE_STATIC_LOCAL(ScrollbarThemeMock, mockTheme, ()); | 295 DEFINE_STATIC_LOCAL(ScrollbarThemeMock, mockTheme, ()); |
| 296 return &mockTheme; | 296 return mockTheme; |
| 297 } | 297 } |
| 298 return nativeTheme(); | 298 return nativeTheme(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void ScrollbarTheme::setMockScrollbarsEnabled(bool flag) | 301 void ScrollbarTheme::setMockScrollbarsEnabled(bool flag) |
| 302 { | 302 { |
| 303 gMockScrollbarsEnabled = flag; | 303 gMockScrollbarsEnabled = flag; |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool ScrollbarTheme::mockScrollbarsEnabled() | 306 bool ScrollbarTheme::mockScrollbarsEnabled() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 332 return DisplayItem::ScrollbarBackTrack; | 332 return DisplayItem::ScrollbarBackTrack; |
| 333 case ForwardTrackPart: | 333 case ForwardTrackPart: |
| 334 return DisplayItem::ScrollbarForwardTrack; | 334 return DisplayItem::ScrollbarForwardTrack; |
| 335 default: | 335 default: |
| 336 ASSERT_NOT_REACHED(); | 336 ASSERT_NOT_REACHED(); |
| 337 return DisplayItem::ScrollbarBackTrack; | 337 return DisplayItem::ScrollbarBackTrack; |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace blink | 341 } // namespace blink |
| OLD | NEW |