| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 PassRefPtrWillBeRawPtr<Scrollbar> Scrollbar::create(ScrollableArea* scrollableAr
ea, ScrollbarOrientation orientation, ScrollbarControlSize size) | 44 PassRefPtrWillBeRawPtr<Scrollbar> Scrollbar::create(ScrollableArea* scrollableAr
ea, ScrollbarOrientation orientation, ScrollbarControlSize size) |
| 45 { | 45 { |
| 46 return adoptRefWillBeNoop(new Scrollbar(scrollableArea, orientation, size)); | 46 return adoptRefWillBeNoop(new Scrollbar(scrollableArea, orientation, size)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orient
ation, ScrollbarControlSize controlSize, ScrollbarTheme* theme) | 49 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orient
ation, ScrollbarControlSize controlSize, ScrollbarTheme* theme) |
| 50 : m_scrollableArea(scrollableArea) | 50 : m_scrollableArea(scrollableArea) |
| 51 , m_orientation(orientation) | 51 , m_orientation(orientation) |
| 52 , m_controlSize(controlSize) | 52 , m_controlSize(controlSize) |
| 53 , m_theme(theme) | 53 , m_theme(theme ? *theme : ScrollbarTheme::theme()) |
| 54 , m_visibleSize(0) | 54 , m_visibleSize(0) |
| 55 , m_totalSize(0) | 55 , m_totalSize(0) |
| 56 , m_currentPos(0) | 56 , m_currentPos(0) |
| 57 , m_dragOrigin(0) | 57 , m_dragOrigin(0) |
| 58 , m_hoveredPart(NoPart) | 58 , m_hoveredPart(NoPart) |
| 59 , m_pressedPart(NoPart) | 59 , m_pressedPart(NoPart) |
| 60 , m_pressedPos(0) | 60 , m_pressedPos(0) |
| 61 , m_scrollPos(0) | 61 , m_scrollPos(0) |
| 62 , m_draggingDocument(false) | 62 , m_draggingDocument(false) |
| 63 , m_documentDragPos(0) | 63 , m_documentDragPos(0) |
| 64 , m_enabled(true) | 64 , m_enabled(true) |
| 65 , m_scrollTimer(this, &Scrollbar::autoscrollTimerFired) | 65 , m_scrollTimer(this, &Scrollbar::autoscrollTimerFired) |
| 66 , m_overlapsResizer(false) | 66 , m_overlapsResizer(false) |
| 67 , m_isAlphaLocked(false) | 67 , m_isAlphaLocked(false) |
| 68 , m_elasticOverscroll(0) | 68 , m_elasticOverscroll(0) |
| 69 , m_trackNeedsRepaint(true) | 69 , m_trackNeedsRepaint(true) |
| 70 , m_thumbNeedsRepaint(true) | 70 , m_thumbNeedsRepaint(true) |
| 71 { | 71 { |
| 72 if (!m_theme) | 72 m_theme.registerScrollbar(*this); |
| 73 m_theme = ScrollbarTheme::theme(); | |
| 74 | |
| 75 m_theme->registerScrollbar(this); | |
| 76 | 73 |
| 77 // FIXME: This is ugly and would not be necessary if we fix cross-platform c
ode to actually query for | 74 // FIXME: This is ugly and would not be necessary if we fix cross-platform c
ode to actually query for |
| 78 // scrollbar thickness and use it when sizing scrollbars (rather than leavin
g one dimension of the scrollbar | 75 // scrollbar thickness and use it when sizing scrollbars (rather than leavin
g one dimension of the scrollbar |
| 79 // alone when sizing). | 76 // alone when sizing). |
| 80 int thickness = m_theme->scrollbarThickness(controlSize); | 77 int thickness = m_theme.scrollbarThickness(controlSize); |
| 81 Widget::setFrameRect(IntRect(0, 0, thickness, thickness)); | 78 Widget::setFrameRect(IntRect(0, 0, thickness, thickness)); |
| 82 | 79 |
| 83 m_currentPos = scrollableAreaCurrentPos(); | 80 m_currentPos = scrollableAreaCurrentPos(); |
| 84 } | 81 } |
| 85 | 82 |
| 86 Scrollbar::~Scrollbar() | 83 Scrollbar::~Scrollbar() |
| 87 { | 84 { |
| 88 m_theme->unregisterScrollbar(this); | 85 m_theme.unregisterScrollbar(*this); |
| 89 } | 86 } |
| 90 | 87 |
| 91 DEFINE_TRACE(Scrollbar) | 88 DEFINE_TRACE(Scrollbar) |
| 92 { | 89 { |
| 93 visitor->trace(m_scrollableArea); | 90 visitor->trace(m_scrollableArea); |
| 94 Widget::trace(visitor); | 91 Widget::trace(visitor); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void Scrollbar::setFrameRect(const IntRect& frameRect) | 94 void Scrollbar::setFrameRect(const IntRect& frameRect) |
| 98 { | 95 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 127 } | 124 } |
| 128 | 125 |
| 129 void Scrollbar::offsetDidChange() | 126 void Scrollbar::offsetDidChange() |
| 130 { | 127 { |
| 131 ASSERT(m_scrollableArea); | 128 ASSERT(m_scrollableArea); |
| 132 | 129 |
| 133 float position = scrollableAreaCurrentPos(); | 130 float position = scrollableAreaCurrentPos(); |
| 134 if (position == m_currentPos) | 131 if (position == m_currentPos) |
| 135 return; | 132 return; |
| 136 | 133 |
| 137 int oldThumbPosition = theme()->thumbPosition(this); | 134 int oldThumbPosition = theme().thumbPosition(*this); |
| 138 m_currentPos = position; | 135 m_currentPos = position; |
| 139 updateThumbPosition(); | 136 updateThumbPosition(); |
| 140 if (m_pressedPart == ThumbPart) | 137 if (m_pressedPart == ThumbPart) |
| 141 setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPosi
tion); | 138 setPressedPos(m_pressedPos + theme().thumbPosition(*this) - oldThumbPosi
tion); |
| 142 } | 139 } |
| 143 | 140 |
| 144 void Scrollbar::disconnectFromScrollableArea() | 141 void Scrollbar::disconnectFromScrollableArea() |
| 145 { | 142 { |
| 146 m_scrollableArea = nullptr; | 143 m_scrollableArea = nullptr; |
| 147 } | 144 } |
| 148 | 145 |
| 149 void Scrollbar::setProportion(int visibleSize, int totalSize) | 146 void Scrollbar::setProportion(int visibleSize, int totalSize) |
| 150 { | 147 { |
| 151 if (visibleSize == m_visibleSize && totalSize == m_totalSize) | 148 if (visibleSize == m_visibleSize && totalSize == m_totalSize) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 165 void Scrollbar::updateThumbPosition() | 162 void Scrollbar::updateThumbPosition() |
| 166 { | 163 { |
| 167 updateThumb(); | 164 updateThumb(); |
| 168 } | 165 } |
| 169 | 166 |
| 170 void Scrollbar::updateThumbProportion() | 167 void Scrollbar::updateThumbProportion() |
| 171 { | 168 { |
| 172 updateThumb(); | 169 updateThumb(); |
| 173 } | 170 } |
| 174 | 171 |
| 175 void Scrollbar::paint(GraphicsContext* context, const CullRect& cullRect) const | 172 void Scrollbar::paint(GraphicsContext& context, const CullRect& cullRect) const |
| 176 { | 173 { |
| 177 if (!cullRect.intersectsCullRect(frameRect())) | 174 if (!cullRect.intersectsCullRect(frameRect())) |
| 178 return; | 175 return; |
| 179 | 176 |
| 180 if (!theme()->paint(this, context, cullRect)) | 177 if (!theme().paint(*this, context, cullRect)) |
| 181 Widget::paint(context, cullRect); | 178 Widget::paint(context, cullRect); |
| 182 } | 179 } |
| 183 | 180 |
| 184 void Scrollbar::autoscrollTimerFired(Timer<Scrollbar>*) | 181 void Scrollbar::autoscrollTimerFired(Timer<Scrollbar>*) |
| 185 { | 182 { |
| 186 autoscrollPressedPart(theme()->autoscrollTimerDelay()); | 183 autoscrollPressedPart(theme().autoscrollTimerDelay()); |
| 187 } | 184 } |
| 188 | 185 |
| 189 static bool thumbUnderMouse(Scrollbar* scrollbar) | 186 static bool thumbUnderMouse(Scrollbar& scrollbar) |
| 190 { | 187 { |
| 191 int thumbPos = scrollbar->theme()->trackPosition(scrollbar) + scrollbar->the
me()->thumbPosition(scrollbar); | 188 int thumbPos = scrollbar.theme().trackPosition(scrollbar) + scrollbar.theme(
).thumbPosition(scrollbar); |
| 192 int thumbLength = scrollbar->theme()->thumbLength(scrollbar); | 189 int thumbLength = scrollbar.theme().thumbLength(scrollbar); |
| 193 return scrollbar->pressedPos() >= thumbPos && scrollbar->pressedPos() < thum
bPos + thumbLength; | 190 return scrollbar.pressedPos() >= thumbPos && scrollbar.pressedPos() < thumbP
os + thumbLength; |
| 194 } | 191 } |
| 195 | 192 |
| 196 void Scrollbar::autoscrollPressedPart(double delay) | 193 void Scrollbar::autoscrollPressedPart(double delay) |
| 197 { | 194 { |
| 198 // Don't do anything for the thumb or if nothing was pressed. | 195 // Don't do anything for the thumb or if nothing was pressed. |
| 199 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart) | 196 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart) |
| 200 return; | 197 return; |
| 201 | 198 |
| 202 // Handle the track. | 199 // Handle the track. |
| 203 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) &&
thumbUnderMouse(this)) { | 200 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) &&
thumbUnderMouse(*this)) { |
| 204 setNeedsPaintInvalidation(); | 201 setNeedsPaintInvalidation(); |
| 205 setHoveredPart(ThumbPart); | 202 setHoveredPart(ThumbPart); |
| 206 return; | 203 return; |
| 207 } | 204 } |
| 208 | 205 |
| 209 // Handle the arrows and track. | 206 // Handle the arrows and track. |
| 210 if (m_scrollableArea && m_scrollableArea->userScroll(pressedPartScrollDirect
ionPhysical(), pressedPartScrollGranularity()).didScroll) | 207 if (m_scrollableArea && m_scrollableArea->userScroll(pressedPartScrollDirect
ionPhysical(), pressedPartScrollGranularity()).didScroll) |
| 211 startTimerIfNeeded(delay); | 208 startTimerIfNeeded(delay); |
| 212 } | 209 } |
| 213 | 210 |
| 214 void Scrollbar::startTimerIfNeeded(double delay) | 211 void Scrollbar::startTimerIfNeeded(double delay) |
| 215 { | 212 { |
| 216 // Don't do anything for the thumb. | 213 // Don't do anything for the thumb. |
| 217 if (m_pressedPart == ThumbPart) | 214 if (m_pressedPart == ThumbPart) |
| 218 return; | 215 return; |
| 219 | 216 |
| 220 // Handle the track. We halt track scrolling once the thumb is level | 217 // Handle the track. We halt track scrolling once the thumb is level |
| 221 // with us. | 218 // with us. |
| 222 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) &&
thumbUnderMouse(this)) { | 219 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) &&
thumbUnderMouse(*this)) { |
| 223 setNeedsPaintInvalidation(); | 220 setNeedsPaintInvalidation(); |
| 224 setHoveredPart(ThumbPart); | 221 setHoveredPart(ThumbPart); |
| 225 return; | 222 return; |
| 226 } | 223 } |
| 227 | 224 |
| 228 // We can't scroll if we've hit the beginning or end. | 225 // We can't scroll if we've hit the beginning or end. |
| 229 ScrollDirectionPhysical dir = pressedPartScrollDirectionPhysical(); | 226 ScrollDirectionPhysical dir = pressedPartScrollDirectionPhysical(); |
| 230 if (dir == ScrollUp || dir == ScrollLeft) { | 227 if (dir == ScrollUp || dir == ScrollLeft) { |
| 231 if (m_currentPos == 0) | 228 if (m_currentPos == 0) |
| 232 return; | 229 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 { | 265 { |
| 269 if (!m_scrollableArea) | 266 if (!m_scrollableArea) |
| 270 return; | 267 return; |
| 271 | 268 |
| 272 int delta = pos - m_pressedPos; | 269 int delta = pos - m_pressedPos; |
| 273 | 270 |
| 274 if (draggingDocument) { | 271 if (draggingDocument) { |
| 275 if (m_draggingDocument) | 272 if (m_draggingDocument) |
| 276 delta = pos - m_documentDragPos; | 273 delta = pos - m_documentDragPos; |
| 277 m_draggingDocument = true; | 274 m_draggingDocument = true; |
| 278 FloatPoint currentPosition = m_scrollableArea->scrollAnimator()->current
Position(); | 275 FloatPoint currentPosition = m_scrollableArea->scrollAnimator().currentP
osition(); |
| 279 float destinationPosition = (m_orientation == HorizontalScrollbar ? curr
entPosition.x() : currentPosition.y()) + delta; | 276 float destinationPosition = (m_orientation == HorizontalScrollbar ? curr
entPosition.x() : currentPosition.y()) + delta; |
| 280 destinationPosition = m_scrollableArea->clampScrollPosition(m_orientatio
n, destinationPosition); | 277 destinationPosition = m_scrollableArea->clampScrollPosition(m_orientatio
n, destinationPosition); |
| 281 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, destination
Position, UserScroll); | 278 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, destination
Position, UserScroll); |
| 282 m_documentDragPos = pos; | 279 m_documentDragPos = pos; |
| 283 return; | 280 return; |
| 284 } | 281 } |
| 285 | 282 |
| 286 if (m_draggingDocument) { | 283 if (m_draggingDocument) { |
| 287 delta += m_pressedPos - m_documentDragPos; | 284 delta += m_pressedPos - m_documentDragPos; |
| 288 m_draggingDocument = false; | 285 m_draggingDocument = false; |
| 289 } | 286 } |
| 290 | 287 |
| 291 // Drag the thumb. | 288 // Drag the thumb. |
| 292 int thumbPos = theme()->thumbPosition(this); | 289 int thumbPos = theme().thumbPosition(*this); |
| 293 int thumbLen = theme()->thumbLength(this); | 290 int thumbLen = theme().thumbLength(*this); |
| 294 int trackLen = theme()->trackLength(this); | 291 int trackLen = theme().trackLength(*this); |
| 295 ASSERT(thumbLen <= trackLen); | 292 ASSERT(thumbLen <= trackLen); |
| 296 if (thumbLen == trackLen) | 293 if (thumbLen == trackLen) |
| 297 return; | 294 return; |
| 298 | 295 |
| 299 if (delta > 0) | 296 if (delta > 0) |
| 300 delta = std::min(trackLen - thumbLen - thumbPos, delta); | 297 delta = std::min(trackLen - thumbLen - thumbPos, delta); |
| 301 else if (delta < 0) | 298 else if (delta < 0) |
| 302 delta = std::max(-thumbPos, delta); | 299 delta = std::max(-thumbPos, delta); |
| 303 | 300 |
| 304 float minPos = m_scrollableArea->minimumScrollPosition(m_orientation); | 301 float minPos = m_scrollableArea->minimumScrollPosition(m_orientation); |
| 305 float maxPos = m_scrollableArea->maximumScrollPosition(m_orientation); | 302 float maxPos = m_scrollableArea->maximumScrollPosition(m_orientation); |
| 306 if (delta) { | 303 if (delta) { |
| 307 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min
Pos) / (trackLen - thumbLen) + minPos; | 304 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min
Pos) / (trackLen - thumbLen) + minPos; |
| 308 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, newPosition
, UserScroll); | 305 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, newPosition
, UserScroll); |
| 309 } | 306 } |
| 310 } | 307 } |
| 311 | 308 |
| 312 void Scrollbar::setHoveredPart(ScrollbarPart part) | 309 void Scrollbar::setHoveredPart(ScrollbarPart part) |
| 313 { | 310 { |
| 314 if (part == m_hoveredPart) | 311 if (part == m_hoveredPart) |
| 315 return; | 312 return; |
| 316 | 313 |
| 317 if (((m_hoveredPart == NoPart || part == NoPart) && theme()->invalidateOnMou
seEnterExit()) | 314 if (((m_hoveredPart == NoPart || part == NoPart) && theme().invalidateOnMous
eEnterExit()) |
| 318 // When there's a pressed part, we don't draw a hovered state, so there'
s no reason to invalidate. | 315 // When there's a pressed part, we don't draw a hovered state, so there'
s no reason to invalidate. |
| 319 || m_pressedPart == NoPart) | 316 || m_pressedPart == NoPart) |
| 320 setNeedsPaintInvalidation(); | 317 setNeedsPaintInvalidation(); |
| 321 | 318 |
| 322 m_hoveredPart = part; | 319 m_hoveredPart = part; |
| 323 } | 320 } |
| 324 | 321 |
| 325 void Scrollbar::setPressedPart(ScrollbarPart part) | 322 void Scrollbar::setPressedPart(ScrollbarPart part) |
| 326 { | 323 { |
| 327 if (m_pressedPart != NoPart | 324 if (m_pressedPart != NoPart |
| 328 // When we no longer have a pressed part, we can start drawing a hovered
state on the hovered part. | 325 // When we no longer have a pressed part, we can start drawing a hovered
state on the hovered part. |
| 329 || m_hoveredPart != NoPart) | 326 || m_hoveredPart != NoPart) |
| 330 setNeedsPaintInvalidation(); | 327 setNeedsPaintInvalidation(); |
| 331 m_pressedPart = part; | 328 m_pressedPart = part; |
| 332 } | 329 } |
| 333 | 330 |
| 334 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt) | 331 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt) |
| 335 { | 332 { |
| 336 switch (evt.type()) { | 333 switch (evt.type()) { |
| 337 case PlatformEvent::GestureTapDown: | 334 case PlatformEvent::GestureTapDown: |
| 338 setPressedPart(theme()->hitTest(this, evt.position())); | 335 setPressedPart(theme().hitTest(*this, evt.position())); |
| 339 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFra
me(evt.position()).x() : convertFromRootFrame(evt.position()).y(); | 336 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFra
me(evt.position()).x() : convertFromRootFrame(evt.position()).y(); |
| 340 return true; | 337 return true; |
| 341 case PlatformEvent::GestureTapDownCancel: | 338 case PlatformEvent::GestureTapDownCancel: |
| 342 case PlatformEvent::GestureScrollBegin: | 339 case PlatformEvent::GestureScrollBegin: |
| 343 if (m_pressedPart != ThumbPart) | 340 if (m_pressedPart != ThumbPart) |
| 344 return false; | 341 return false; |
| 345 m_scrollPos = m_pressedPos; | 342 m_scrollPos = m_pressedPos; |
| 346 return true; | 343 return true; |
| 347 case PlatformEvent::GestureScrollUpdate: | 344 case PlatformEvent::GestureScrollUpdate: |
| 348 if (m_pressedPart != ThumbPart) | 345 if (m_pressedPart != ThumbPart) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 369 } | 366 } |
| 370 default: | 367 default: |
| 371 // By default, we assume that gestures don't deselect the scrollbar. | 368 // By default, we assume that gestures don't deselect the scrollbar. |
| 372 return true; | 369 return true; |
| 373 } | 370 } |
| 374 } | 371 } |
| 375 | 372 |
| 376 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) | 373 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) |
| 377 { | 374 { |
| 378 if (m_pressedPart == ThumbPart) { | 375 if (m_pressedPart == ThumbPart) { |
| 379 if (theme()->shouldSnapBackToDragOrigin(this, evt)) { | 376 if (theme().shouldSnapBackToDragOrigin(*this, evt)) { |
| 380 if (m_scrollableArea) { | 377 if (m_scrollableArea) { |
| 381 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, m_d
ragOrigin + m_scrollableArea->minimumScrollPosition(m_orientation), UserScroll); | 378 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, m_d
ragOrigin + m_scrollableArea->minimumScrollPosition(m_orientation), UserScroll); |
| 382 } | 379 } |
| 383 } else { | 380 } else { |
| 384 moveThumb(m_orientation == HorizontalScrollbar | 381 moveThumb(m_orientation == HorizontalScrollbar |
| 385 ? convertFromRootFrame(evt.position()).x() | 382 ? convertFromRootFrame(evt.position()).x() |
| 386 : convertFromRootFrame(evt.position()).y(), theme()->shouldDragD
ocumentInsteadOfThumb(this, evt)); | 383 : convertFromRootFrame(evt.position()).y(), theme().shouldDragDo
cumentInsteadOfThumb(*this, evt)); |
| 387 } | 384 } |
| 388 return; | 385 return; |
| 389 } | 386 } |
| 390 | 387 |
| 391 if (m_pressedPart != NoPart) | 388 if (m_pressedPart != NoPart) |
| 392 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFra
me(evt.position()).x() : convertFromRootFrame(evt.position()).y(); | 389 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFra
me(evt.position()).x() : convertFromRootFrame(evt.position()).y(); |
| 393 | 390 |
| 394 ScrollbarPart part = theme()->hitTest(this, evt.position()); | 391 ScrollbarPart part = theme().hitTest(*this, evt.position()); |
| 395 if (part != m_hoveredPart) { | 392 if (part != m_hoveredPart) { |
| 396 if (m_pressedPart != NoPart) { | 393 if (m_pressedPart != NoPart) { |
| 397 if (part == m_pressedPart) { | 394 if (part == m_pressedPart) { |
| 398 // The mouse is moving back over the pressed part. We | 395 // The mouse is moving back over the pressed part. We |
| 399 // need to start up the timer action again. | 396 // need to start up the timer action again. |
| 400 startTimerIfNeeded(theme()->autoscrollTimerDelay()); | 397 startTimerIfNeeded(theme().autoscrollTimerDelay()); |
| 401 setNeedsPaintInvalidation(); | 398 setNeedsPaintInvalidation(); |
| 402 } else if (m_hoveredPart == m_pressedPart) { | 399 } else if (m_hoveredPart == m_pressedPart) { |
| 403 // The mouse is leaving the pressed part. Kill our timer | 400 // The mouse is leaving the pressed part. Kill our timer |
| 404 // if needed. | 401 // if needed. |
| 405 stopTimerIfNeeded(); | 402 stopTimerIfNeeded(); |
| 406 setNeedsPaintInvalidation(); | 403 setNeedsPaintInvalidation(); |
| 407 } | 404 } |
| 408 } | 405 } |
| 409 | 406 |
| 410 setHoveredPart(part); | 407 setHoveredPart(part); |
| 411 } | 408 } |
| 412 | 409 |
| 413 return; | 410 return; |
| 414 } | 411 } |
| 415 | 412 |
| 416 void Scrollbar::mouseEntered() | 413 void Scrollbar::mouseEntered() |
| 417 { | 414 { |
| 418 if (m_scrollableArea) | 415 if (m_scrollableArea) |
| 419 m_scrollableArea->mouseEnteredScrollbar(this); | 416 m_scrollableArea->mouseEnteredScrollbar(*this); |
| 420 } | 417 } |
| 421 | 418 |
| 422 void Scrollbar::mouseExited() | 419 void Scrollbar::mouseExited() |
| 423 { | 420 { |
| 424 if (m_scrollableArea) | 421 if (m_scrollableArea) |
| 425 m_scrollableArea->mouseExitedScrollbar(this); | 422 m_scrollableArea->mouseExitedScrollbar(*this); |
| 426 setHoveredPart(NoPart); | 423 setHoveredPart(NoPart); |
| 427 } | 424 } |
| 428 | 425 |
| 429 void Scrollbar::mouseUp(const PlatformMouseEvent& mouseEvent) | 426 void Scrollbar::mouseUp(const PlatformMouseEvent& mouseEvent) |
| 430 { | 427 { |
| 431 setPressedPart(NoPart); | 428 setPressedPart(NoPart); |
| 432 m_pressedPos = 0; | 429 m_pressedPos = 0; |
| 433 m_draggingDocument = false; | 430 m_draggingDocument = false; |
| 434 stopTimerIfNeeded(); | 431 stopTimerIfNeeded(); |
| 435 | 432 |
| 436 if (m_scrollableArea) { | 433 if (m_scrollableArea) { |
| 437 // m_hoveredPart won't be updated until the next mouseMoved or mouseDown
, so we have to hit test | 434 // m_hoveredPart won't be updated until the next mouseMoved or mouseDown
, so we have to hit test |
| 438 // to really know if the mouse has exited the scrollbar on a mouseUp. | 435 // to really know if the mouse has exited the scrollbar on a mouseUp. |
| 439 ScrollbarPart part = theme()->hitTest(this, mouseEvent.position()); | 436 ScrollbarPart part = theme().hitTest(*this, mouseEvent.position()); |
| 440 if (part == NoPart) | 437 if (part == NoPart) |
| 441 m_scrollableArea->mouseExitedScrollbar(this); | 438 m_scrollableArea->mouseExitedScrollbar(*this); |
| 442 } | 439 } |
| 443 } | 440 } |
| 444 | 441 |
| 445 void Scrollbar::mouseDown(const PlatformMouseEvent& evt) | 442 void Scrollbar::mouseDown(const PlatformMouseEvent& evt) |
| 446 { | 443 { |
| 447 // Early exit for right click | 444 // Early exit for right click |
| 448 if (evt.button() == RightButton) | 445 if (evt.button() == RightButton) |
| 449 return; | 446 return; |
| 450 | 447 |
| 451 setPressedPart(theme()->hitTest(this, evt.position())); | 448 setPressedPart(theme().hitTest(*this, evt.position())); |
| 452 int pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFrame
(evt.position()).x() : convertFromRootFrame(evt.position()).y(); | 449 int pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFrame
(evt.position()).x() : convertFromRootFrame(evt.position()).y(); |
| 453 | 450 |
| 454 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) &&
theme()->shouldCenterOnThumb(this, evt)) { | 451 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) &&
theme().shouldCenterOnThumb(*this, evt)) { |
| 455 setHoveredPart(ThumbPart); | 452 setHoveredPart(ThumbPart); |
| 456 setPressedPart(ThumbPart); | 453 setPressedPart(ThumbPart); |
| 457 m_dragOrigin = m_currentPos; | 454 m_dragOrigin = m_currentPos; |
| 458 int thumbLen = theme()->thumbLength(this); | 455 int thumbLen = theme().thumbLength(*this); |
| 459 int desiredPos = pressedPos; | 456 int desiredPos = pressedPos; |
| 460 // Set the pressed position to the middle of the thumb so that when we d
o the move, the delta | 457 // Set the pressed position to the middle of the thumb so that when we d
o the move, the delta |
| 461 // will be from the current pixel position of the thumb to the new desir
ed position for the thumb. | 458 // will be from the current pixel position of the thumb to the new desir
ed position for the thumb. |
| 462 m_pressedPos = theme()->trackPosition(this) + theme()->thumbPosition(thi
s) + thumbLen / 2; | 459 m_pressedPos = theme().trackPosition(*this) + theme().thumbPosition(*thi
s) + thumbLen / 2; |
| 463 moveThumb(desiredPos); | 460 moveThumb(desiredPos); |
| 464 return; | 461 return; |
| 465 } else if (m_pressedPart == ThumbPart) | 462 } |
| 463 if (m_pressedPart == ThumbPart) |
| 466 m_dragOrigin = m_currentPos; | 464 m_dragOrigin = m_currentPos; |
| 467 | 465 |
| 468 m_pressedPos = pressedPos; | 466 m_pressedPos = pressedPos; |
| 469 | 467 |
| 470 autoscrollPressedPart(theme()->initialAutoscrollTimerDelay()); | 468 autoscrollPressedPart(theme().initialAutoscrollTimerDelay()); |
| 471 } | 469 } |
| 472 | 470 |
| 473 void Scrollbar::visibilityChanged() | 471 void Scrollbar::visibilityChanged() |
| 474 { | 472 { |
| 475 if (m_scrollableArea) | 473 if (m_scrollableArea) |
| 476 m_scrollableArea->scrollbarVisibilityChanged(); | 474 m_scrollableArea->scrollbarVisibilityChanged(); |
| 477 } | 475 } |
| 478 | 476 |
| 479 void Scrollbar::setEnabled(bool e) | 477 void Scrollbar::setEnabled(bool e) |
| 480 { | 478 { |
| 481 if (m_enabled == e) | 479 if (m_enabled == e) |
| 482 return; | 480 return; |
| 483 m_enabled = e; | 481 m_enabled = e; |
| 484 theme()->updateEnabledState(this); | 482 theme().updateEnabledState(*this); |
| 485 setNeedsPaintInvalidation(); | 483 setNeedsPaintInvalidation(); |
| 486 } | 484 } |
| 487 | 485 |
| 488 bool Scrollbar::isOverlayScrollbar() const | 486 bool Scrollbar::isOverlayScrollbar() const |
| 489 { | 487 { |
| 490 return m_theme->usesOverlayScrollbars(); | 488 return m_theme.usesOverlayScrollbars(); |
| 491 } | 489 } |
| 492 | 490 |
| 493 bool Scrollbar::shouldParticipateInHitTesting() | 491 bool Scrollbar::shouldParticipateInHitTesting() |
| 494 { | 492 { |
| 495 // Non-overlay scrollbars should always participate in hit testing. | 493 // Non-overlay scrollbars should always participate in hit testing. |
| 496 if (!isOverlayScrollbar()) | 494 if (!isOverlayScrollbar()) |
| 497 return true; | 495 return true; |
| 498 return m_scrollableArea->scrollAnimator()->shouldScrollbarParticipateInHitTe
sting(this); | 496 return m_scrollableArea->scrollAnimator().shouldScrollbarParticipateInHitTes
ting(*this); |
| 499 } | 497 } |
| 500 | 498 |
| 501 // Don't use this method. It will be removed later. | 499 // Don't use this method. It will be removed later. |
| 502 // TODO(ellyjones): remove this method after Snow Leopard support drops. | 500 // TODO(ellyjones): remove this method after Snow Leopard support drops. |
| 503 void Scrollbar::windowActiveChangedForSnowLeopardOnly() | 501 void Scrollbar::windowActiveChangedForSnowLeopardOnly() |
| 504 { | 502 { |
| 505 #if OS(MACOSX) | 503 #if OS(MACOSX) |
| 506 // On Snow Leopard, scrollbars need to be invalidated when the window | 504 // On Snow Leopard, scrollbars need to be invalidated when the window |
| 507 // activity changes so that they take on the "inactive" scrollbar | 505 // activity changes so that they take on the "inactive" scrollbar |
| 508 // appearance. Later OS X releases do not have such an appearance. | 506 // appearance. Later OS X releases do not have such an appearance. |
| 509 if (m_theme && m_theme->invalidateOnWindowActiveChange()) { | 507 if (m_theme.invalidateOnWindowActiveChange()) { |
| 510 ASSERT(IsOSSnowLeopard()); | 508 ASSERT(IsOSSnowLeopard()); |
| 511 invalidate(); | 509 invalidate(); |
| 512 } | 510 } |
| 513 #endif | 511 #endif |
| 514 } | 512 } |
| 515 | 513 |
| 516 bool Scrollbar::isWindowActive() const | 514 bool Scrollbar::isWindowActive() const |
| 517 { | 515 { |
| 518 return m_scrollableArea && m_scrollableArea->isActive(); | 516 return m_scrollableArea && m_scrollableArea->isActive(); |
| 519 } | 517 } |
| 520 | 518 |
| 521 IntRect Scrollbar::convertToContainingWidget(const IntRect& localRect) const | 519 IntRect Scrollbar::convertToContainingWidget(const IntRect& localRect) const |
| 522 { | 520 { |
| 523 if (m_scrollableArea) | 521 if (m_scrollableArea) |
| 524 return m_scrollableArea->convertFromScrollbarToContainingWidget(this, lo
calRect); | 522 return m_scrollableArea->convertFromScrollbarToContainingWidget(*this, l
ocalRect); |
| 525 | 523 |
| 526 return Widget::convertToContainingWidget(localRect); | 524 return Widget::convertToContainingWidget(localRect); |
| 527 } | 525 } |
| 528 | 526 |
| 529 IntRect Scrollbar::convertFromContainingWidget(const IntRect& parentRect) const | 527 IntRect Scrollbar::convertFromContainingWidget(const IntRect& parentRect) const |
| 530 { | 528 { |
| 531 if (m_scrollableArea) | 529 if (m_scrollableArea) |
| 532 return m_scrollableArea->convertFromContainingWidgetToScrollbar(this, pa
rentRect); | 530 return m_scrollableArea->convertFromContainingWidgetToScrollbar(*this, p
arentRect); |
| 533 | 531 |
| 534 return Widget::convertFromContainingWidget(parentRect); | 532 return Widget::convertFromContainingWidget(parentRect); |
| 535 } | 533 } |
| 536 | 534 |
| 537 IntPoint Scrollbar::convertToContainingWidget(const IntPoint& localPoint) const | 535 IntPoint Scrollbar::convertToContainingWidget(const IntPoint& localPoint) const |
| 538 { | 536 { |
| 539 if (m_scrollableArea) | 537 if (m_scrollableArea) |
| 540 return m_scrollableArea->convertFromScrollbarToContainingWidget(this, lo
calPoint); | 538 return m_scrollableArea->convertFromScrollbarToContainingWidget(*this, l
ocalPoint); |
| 541 | 539 |
| 542 return Widget::convertToContainingWidget(localPoint); | 540 return Widget::convertToContainingWidget(localPoint); |
| 543 } | 541 } |
| 544 | 542 |
| 545 IntPoint Scrollbar::convertFromContainingWidget(const IntPoint& parentPoint) con
st | 543 IntPoint Scrollbar::convertFromContainingWidget(const IntPoint& parentPoint) con
st |
| 546 { | 544 { |
| 547 if (m_scrollableArea) | 545 if (m_scrollableArea) |
| 548 return m_scrollableArea->convertFromContainingWidgetToScrollbar(this, pa
rentPoint); | 546 return m_scrollableArea->convertFromContainingWidgetToScrollbar(*this, p
arentPoint); |
| 549 | 547 |
| 550 return Widget::convertFromContainingWidget(parentPoint); | 548 return Widget::convertFromContainingWidget(parentPoint); |
| 551 } | 549 } |
| 552 | 550 |
| 553 float Scrollbar::scrollableAreaCurrentPos() const | 551 float Scrollbar::scrollableAreaCurrentPos() const |
| 554 { | 552 { |
| 555 if (!m_scrollableArea) | 553 if (!m_scrollableArea) |
| 556 return 0; | 554 return 0; |
| 557 | 555 |
| 558 if (m_orientation == HorizontalScrollbar) | 556 if (m_orientation == HorizontalScrollbar) |
| 559 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu
mScrollPosition().x(); | 557 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu
mScrollPosition().x(); |
| 560 | 558 |
| 561 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr
ollPosition().y(); | 559 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr
ollPosition().y(); |
| 562 } | 560 } |
| 563 | 561 |
| 564 void Scrollbar::setNeedsPaintInvalidation() | 562 void Scrollbar::setNeedsPaintInvalidation() |
| 565 { | 563 { |
| 566 if (m_theme->shouldRepaintAllPartsOnInvalidation()) { | 564 if (m_theme.shouldRepaintAllPartsOnInvalidation()) { |
| 567 m_trackNeedsRepaint = true; | 565 m_trackNeedsRepaint = true; |
| 568 m_thumbNeedsRepaint = true; | 566 m_thumbNeedsRepaint = true; |
| 569 } | 567 } |
| 570 if (m_scrollableArea) | 568 if (m_scrollableArea) |
| 571 m_scrollableArea->setScrollbarNeedsPaintInvalidation(this); | 569 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); |
| 572 } | 570 } |
| 573 | 571 |
| 574 } // namespace blink | 572 } // namespace blink |
| OLD | NEW |