| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 "sky/engine/config.h" | 26 #include "sky/engine/config.h" |
| 27 #include "sky/engine/platform/scroll/Scrollbar.h" | 27 #include "sky/engine/platform/scroll/Scrollbar.h" |
| 28 | 28 |
| 29 #include "sky/engine/platform/PlatformGestureEvent.h" | 29 #include "sky/engine/platform/PlatformGestureEvent.h" |
| 30 #include "sky/engine/platform/PlatformMouseEvent.h" | |
| 31 #include "sky/engine/platform/graphics/GraphicsContext.h" | 30 #include "sky/engine/platform/graphics/GraphicsContext.h" |
| 32 #include "sky/engine/platform/scroll/ScrollAnimator.h" | 31 #include "sky/engine/platform/scroll/ScrollAnimator.h" |
| 33 #include "sky/engine/platform/scroll/ScrollableArea.h" | 32 #include "sky/engine/platform/scroll/ScrollableArea.h" |
| 34 #include "sky/engine/platform/scroll/Scrollbar.h" | 33 #include "sky/engine/platform/scroll/Scrollbar.h" |
| 35 #include "sky/engine/public/platform/Platform.h" | 34 #include "sky/engine/public/platform/Platform.h" |
| 36 #include "sky/engine/public/platform/WebPoint.h" | 35 #include "sky/engine/public/platform/WebPoint.h" |
| 37 #include "sky/engine/public/platform/WebRect.h" | 36 #include "sky/engine/public/platform/WebRect.h" |
| 38 | 37 |
| 39 // The position of the scrollbar thumb affects the appearance of the steppers, s
o | 38 // The position of the scrollbar thumb affects the appearance of the steppers, s
o |
| 40 // when the thumb moves, we have to invalidate them for painting. | 39 // when the thumb moves, we have to invalidate them for painting. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 m_pressedPos = 0; | 279 m_pressedPos = 0; |
| 281 setPressedPart(NoPart); | 280 setPressedPart(NoPart); |
| 282 return false; | 281 return false; |
| 283 } | 282 } |
| 284 default: | 283 default: |
| 285 // By default, we assume that gestures don't deselect the scrollbar. | 284 // By default, we assume that gestures don't deselect the scrollbar. |
| 286 return true; | 285 return true; |
| 287 } | 286 } |
| 288 } | 287 } |
| 289 | 288 |
| 290 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) | |
| 291 { | |
| 292 if (m_pressedPart == ThumbPart) { | |
| 293 moveThumb(m_orientation == HorizontalScrollbar ? | |
| 294 convertFromContainingView(evt.position()).x() : | |
| 295 convertFromContainingView(evt.position()).y()); | |
| 296 return; | |
| 297 } | |
| 298 | |
| 299 if (m_pressedPart != NoPart) | |
| 300 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain
ingView(evt.position()).x() : convertFromContainingView(evt.position()).y(); | |
| 301 | |
| 302 // FIXME(sky): Cleanup this code now that part is always NoPart. | |
| 303 ScrollbarPart part = NoPart; | |
| 304 if (part != m_hoveredPart) { | |
| 305 if (m_pressedPart != NoPart) { | |
| 306 if (part == m_pressedPart) { | |
| 307 // The mouse is moving back over the pressed part. We | |
| 308 // need to start up the timer action again. | |
| 309 startTimerIfNeeded(autoscrollTimerDelay()); | |
| 310 } else if (m_hoveredPart == m_pressedPart) { | |
| 311 // The mouse is leaving the pressed part. Kill our timer | |
| 312 // if needed. | |
| 313 stopTimerIfNeeded(); | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 setHoveredPart(part); | |
| 318 } | |
| 319 | |
| 320 return; | |
| 321 } | |
| 322 | |
| 323 void Scrollbar::mouseEntered() | 289 void Scrollbar::mouseEntered() |
| 324 { | 290 { |
| 325 if (m_scrollableArea) | 291 if (m_scrollableArea) |
| 326 m_scrollableArea->mouseEnteredScrollbar(this); | 292 m_scrollableArea->mouseEnteredScrollbar(this); |
| 327 } | 293 } |
| 328 | 294 |
| 329 void Scrollbar::mouseExited() | 295 void Scrollbar::mouseExited() |
| 330 { | 296 { |
| 331 if (m_scrollableArea) | 297 if (m_scrollableArea) |
| 332 m_scrollableArea->mouseExitedScrollbar(this); | 298 m_scrollableArea->mouseExitedScrollbar(this); |
| 333 setHoveredPart(NoPart); | 299 setHoveredPart(NoPart); |
| 334 } | 300 } |
| 335 | 301 |
| 336 void Scrollbar::mouseUp(const PlatformMouseEvent& mouseEvent) | |
| 337 { | |
| 338 setPressedPart(NoPart); | |
| 339 m_pressedPos = 0; | |
| 340 stopTimerIfNeeded(); | |
| 341 | |
| 342 if (m_scrollableArea) { | |
| 343 // m_hoveredPart won't be updated until the next mouseMoved or mouseDown
, so we have to hit test | |
| 344 // to really know if the mouse has exited the scrollbar on a mouseUp. | |
| 345 m_scrollableArea->mouseExitedScrollbar(this); | |
| 346 } | |
| 347 } | |
| 348 | |
| 349 void Scrollbar::mouseDown(const PlatformMouseEvent& evt) | |
| 350 { | |
| 351 // Early exit for right click | |
| 352 if (evt.button() == RightButton) | |
| 353 return; | |
| 354 | |
| 355 // FIXME(sky): Do we still need setPressedPart now that we only set it to No
Part? | |
| 356 setPressedPart(NoPart); | |
| 357 int pressedPos = orientation() == HorizontalScrollbar ? convertFromContainin
gView(evt.position()).x() : convertFromContainingView(evt.position()).y(); | |
| 358 | |
| 359 if (m_pressedPart == ThumbPart) | |
| 360 m_dragOrigin = m_currentPos; | |
| 361 | |
| 362 m_pressedPos = pressedPos; | |
| 363 | |
| 364 autoscrollPressedPart(initialAutoscrollTimerDelay()); | |
| 365 } | |
| 366 | |
| 367 bool Scrollbar::isOverlayScrollbar() const | 302 bool Scrollbar::isOverlayScrollbar() const |
| 368 { | 303 { |
| 369 // FIXME(sky): Remove | 304 // FIXME(sky): Remove |
| 370 return true; | 305 return true; |
| 371 } | 306 } |
| 372 | 307 |
| 373 bool Scrollbar::shouldParticipateInHitTesting() | 308 bool Scrollbar::shouldParticipateInHitTesting() |
| 374 { | 309 { |
| 375 // Non-overlay scrollbars should always participate in hit testing. | 310 // Non-overlay scrollbars should always participate in hit testing. |
| 376 if (!isOverlayScrollbar()) | 311 if (!isOverlayScrollbar()) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 thumbRect.setWidth(thumbRect.width() - kScrollbarMargin); | 453 thumbRect.setWidth(thumbRect.width() - kScrollbarMargin); |
| 519 if (isLeftSideVerticalScrollbar()) | 454 if (isLeftSideVerticalScrollbar()) |
| 520 thumbRect.setX(thumbRect.x() + kScrollbarMargin); | 455 thumbRect.setX(thumbRect.x() + kScrollbarMargin); |
| 521 } | 456 } |
| 522 | 457 |
| 523 DEFINE_STATIC_LOCAL(Color, color, (128, 128, 128, 128)); | 458 DEFINE_STATIC_LOCAL(Color, color, (128, 128, 128, 128)); |
| 524 context->fillRect(thumbRect, color); | 459 context->fillRect(thumbRect, color); |
| 525 } | 460 } |
| 526 | 461 |
| 527 } // namespace blink | 462 } // namespace blink |
| OLD | NEW |