| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 #include "platform/graphics/GraphicsContext.h" | 29 #include "platform/graphics/GraphicsContext.h" |
| 30 #include "platform/PlatformGestureEvent.h" | 30 #include "platform/PlatformGestureEvent.h" |
| 31 #include "platform/PlatformMouseEvent.h" | 31 #include "platform/PlatformMouseEvent.h" |
| 32 #include "platform/scroll/ScrollableArea.h" | 32 #include "platform/scroll/ScrollableArea.h" |
| 33 #include "platform/scroll/ScrollAnimator.h" | 33 #include "platform/scroll/ScrollAnimator.h" |
| 34 #include "platform/scroll/Scrollbar.h" | 34 #include "platform/scroll/Scrollbar.h" |
| 35 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 36 #include "public/platform/WebPoint.h" | 36 #include "public/platform/WebPoint.h" |
| 37 #include "public/platform/WebRect.h" | 37 #include "public/platform/WebRect.h" |
| 38 #include "public/platform/WebScrollbarBehavior.h" | |
| 39 #include "public/platform/WebThemeEngine.h" | 38 #include "public/platform/WebThemeEngine.h" |
| 40 | 39 |
| 41 // The position of the scrollbar thumb affects the appearance of the steppers, s
o | 40 // The position of the scrollbar thumb affects the appearance of the steppers, s
o |
| 42 // when the thumb moves, we have to invalidate them for painting. | 41 // when the thumb moves, we have to invalidate them for painting. |
| 43 #define THUMB_POSITION_AFFECTS_BUTTONS | 42 #define THUMB_POSITION_AFFECTS_BUTTONS |
| 44 | 43 |
| 45 namespace blink { | 44 namespace blink { |
| 46 | 45 |
| 47 static const int kThumbThickness = 3; | 46 static const int kThumbThickness = 3; |
| 48 static const int kScrollbarMargin = 3; | 47 static const int kScrollbarMargin = 3; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 315 } |
| 317 default: | 316 default: |
| 318 // By default, we assume that gestures don't deselect the scrollbar. | 317 // By default, we assume that gestures don't deselect the scrollbar. |
| 319 return true; | 318 return true; |
| 320 } | 319 } |
| 321 } | 320 } |
| 322 | 321 |
| 323 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) | 322 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) |
| 324 { | 323 { |
| 325 if (m_pressedPart == ThumbPart) { | 324 if (m_pressedPart == ThumbPart) { |
| 326 if (shouldSnapBackToDragOrigin(evt)) { | 325 moveThumb(m_orientation == HorizontalScrollbar ? |
| 327 if (m_scrollableArea) | 326 convertFromContainingView(evt.position()).x() : |
| 328 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation,
m_dragOrigin + m_scrollableArea->minimumScrollPosition(m_orientation)); | 327 convertFromContainingView(evt.position()).y()); |
| 329 } else { | |
| 330 moveThumb(m_orientation == HorizontalScrollbar ? | |
| 331 convertFromContainingView(evt.position()).x() : | |
| 332 convertFromContainingView(evt.position()).y()); | |
| 333 } | |
| 334 return; | 328 return; |
| 335 } | 329 } |
| 336 | 330 |
| 337 if (m_pressedPart != NoPart) | 331 if (m_pressedPart != NoPart) |
| 338 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain
ingView(evt.position()).x() : convertFromContainingView(evt.position()).y(); | 332 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain
ingView(evt.position()).x() : convertFromContainingView(evt.position()).y(); |
| 339 | 333 |
| 340 // FIXME(sky): Cleanup this code now that part is always NoPart. | 334 // FIXME(sky): Cleanup this code now that part is always NoPart. |
| 341 ScrollbarPart part = NoPart; | 335 ScrollbarPart part = NoPart; |
| 342 if (part != m_hoveredPart) { | 336 if (part != m_hoveredPart) { |
| 343 if (m_pressedPart != NoPart) { | 337 if (m_pressedPart != NoPart) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 void Scrollbar::mouseDown(const PlatformMouseEvent& evt) | 383 void Scrollbar::mouseDown(const PlatformMouseEvent& evt) |
| 390 { | 384 { |
| 391 // Early exit for right click | 385 // Early exit for right click |
| 392 if (evt.button() == RightButton) | 386 if (evt.button() == RightButton) |
| 393 return; | 387 return; |
| 394 | 388 |
| 395 // FIXME(sky): Do we still need setPressedPart now that we only set it to No
Part? | 389 // FIXME(sky): Do we still need setPressedPart now that we only set it to No
Part? |
| 396 setPressedPart(NoPart); | 390 setPressedPart(NoPart); |
| 397 int pressedPos = orientation() == HorizontalScrollbar ? convertFromContainin
gView(evt.position()).x() : convertFromContainingView(evt.position()).y(); | 391 int pressedPos = orientation() == HorizontalScrollbar ? convertFromContainin
gView(evt.position()).x() : convertFromContainingView(evt.position()).y(); |
| 398 | 392 |
| 399 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) &&
shouldCenterOnThumb(evt)) { | 393 if (m_pressedPart == ThumbPart) |
| 400 setHoveredPart(ThumbPart); | |
| 401 setPressedPart(ThumbPart); | |
| 402 m_dragOrigin = m_currentPos; | |
| 403 int thumbLen = thumbLength(); | |
| 404 int desiredPos = pressedPos; | |
| 405 // Set the pressed position to the middle of the thumb so that when we d
o the move, the delta | |
| 406 // will be from the current pixel position of the thumb to the new desir
ed position for the thumb. | |
| 407 m_pressedPos = trackPosition() + thumbPosition() + thumbLen / 2; | |
| 408 moveThumb(desiredPos); | |
| 409 return; | |
| 410 } else if (m_pressedPart == ThumbPart) | |
| 411 m_dragOrigin = m_currentPos; | 394 m_dragOrigin = m_currentPos; |
| 412 | 395 |
| 413 m_pressedPos = pressedPos; | 396 m_pressedPos = pressedPos; |
| 414 | 397 |
| 415 autoscrollPressedPart(initialAutoscrollTimerDelay()); | 398 autoscrollPressedPart(initialAutoscrollTimerDelay()); |
| 416 } | 399 } |
| 417 | 400 |
| 418 void Scrollbar::setEnabled(bool e) | 401 void Scrollbar::setEnabled(bool e) |
| 419 { | 402 { |
| 420 if (m_enabled == e) | 403 if (m_enabled == e) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 result = beforeThumbRect; | 487 result = beforeThumbRect; |
| 505 else if (part == ForwardTrackPart) | 488 else if (part == ForwardTrackPart) |
| 506 result = afterThumbRect; | 489 result = afterThumbRect; |
| 507 else | 490 else |
| 508 result = thumbRect; | 491 result = thumbRect; |
| 509 | 492 |
| 510 result.moveBy(-location()); | 493 result.moveBy(-location()); |
| 511 invalidateRect(result); | 494 invalidateRect(result); |
| 512 } | 495 } |
| 513 | 496 |
| 514 bool Scrollbar::shouldCenterOnThumb(const PlatformMouseEvent& evt) | |
| 515 { | |
| 516 return blink::Platform::current()->scrollbarBehavior()->shouldCenterOnThumb(
static_cast<blink::WebScrollbarBehavior::Button>(evt.button()), evt.shiftKey(),
evt.altKey()); | |
| 517 } | |
| 518 | |
| 519 bool Scrollbar::shouldSnapBackToDragOrigin(const PlatformMouseEvent& evt) | |
| 520 { | |
| 521 IntPoint mousePosition = convertFromContainingView(evt.position()); | |
| 522 mousePosition.move(x(), y()); | |
| 523 return blink::Platform::current()->scrollbarBehavior()->shouldSnapBackToDrag
Origin(mousePosition, trackRect(), orientation() == HorizontalScrollbar); | |
| 524 } | |
| 525 | |
| 526 int Scrollbar::thumbPosition() | 497 int Scrollbar::thumbPosition() |
| 527 { | 498 { |
| 528 if (!totalSize()) | 499 if (!totalSize()) |
| 529 return 0; | 500 return 0; |
| 530 | 501 |
| 531 int trackLen = trackLength(); | 502 int trackLen = trackLength(); |
| 532 float proportion = static_cast<float>(currentPos()) / totalSize(); | 503 float proportion = static_cast<float>(currentPos()) / totalSize(); |
| 533 return round(proportion * trackLen); | 504 return round(proportion * trackLen); |
| 534 } | 505 } |
| 535 | 506 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 thumbRect.setWidth(thumbRect.width() - kScrollbarMargin); | 586 thumbRect.setWidth(thumbRect.width() - kScrollbarMargin); |
| 616 if (isLeftSideVerticalScrollbar()) | 587 if (isLeftSideVerticalScrollbar()) |
| 617 thumbRect.setX(thumbRect.x() + kScrollbarMargin); | 588 thumbRect.setX(thumbRect.x() + kScrollbarMargin); |
| 618 } | 589 } |
| 619 | 590 |
| 620 DEFINE_STATIC_LOCAL(Color, color, (128, 128, 128, 128)); | 591 DEFINE_STATIC_LOCAL(Color, color, (128, 128, 128, 128)); |
| 621 context->fillRect(thumbRect, color); | 592 context->fillRect(thumbRect, color); |
| 622 } | 593 } |
| 623 | 594 |
| 624 } // namespace blink | 595 } // namespace blink |
| OLD | NEW |