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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 m_draggingDocument(false), | 58 m_draggingDocument(false), |
59 m_documentDragPos(0), | 59 m_documentDragPos(0), |
60 m_enabled(true), | 60 m_enabled(true), |
61 m_scrollTimer(this, &Scrollbar::autoscrollTimerFired), | 61 m_scrollTimer(this, &Scrollbar::autoscrollTimerFired), |
62 m_overlapsResizer(false), | 62 m_overlapsResizer(false), |
63 m_elasticOverscroll(0), | 63 m_elasticOverscroll(0), |
64 m_trackNeedsRepaint(true), | 64 m_trackNeedsRepaint(true), |
65 m_thumbNeedsRepaint(true) { | 65 m_thumbNeedsRepaint(true) { |
66 m_theme.registerScrollbar(*this); | 66 m_theme.registerScrollbar(*this); |
67 | 67 |
68 // FIXME: This is ugly and would not be necessary if we fix cross-platform cod
e to actually query for | 68 // FIXME: This is ugly and would not be necessary if we fix cross-platform |
69 // scrollbar thickness and use it when sizing scrollbars (rather than leaving
one dimension of the scrollbar | 69 // code to actually query for scrollbar thickness and use it when sizing |
70 // alone when sizing). | 70 // scrollbars (rather than leaving one dimension of the scrollbar alone when |
| 71 // sizing). |
71 int thickness = m_theme.scrollbarThickness(controlSize); | 72 int thickness = m_theme.scrollbarThickness(controlSize); |
72 if (m_hostWindow) | 73 if (m_hostWindow) |
73 thickness = m_hostWindow->windowToViewportScalar(thickness); | 74 thickness = m_hostWindow->windowToViewportScalar(thickness); |
74 Widget::setFrameRect(IntRect(0, 0, thickness, thickness)); | 75 Widget::setFrameRect(IntRect(0, 0, thickness, thickness)); |
75 | 76 |
76 m_currentPos = scrollableAreaCurrentPos(); | 77 m_currentPos = scrollableAreaCurrentPos(); |
77 } | 78 } |
78 | 79 |
79 Scrollbar::~Scrollbar() { | 80 Scrollbar::~Scrollbar() { |
80 m_theme.unregisterScrollbar(*this); | 81 m_theme.unregisterScrollbar(*this); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 UserScroll); | 296 UserScroll); |
296 } | 297 } |
297 } | 298 } |
298 | 299 |
299 void Scrollbar::setHoveredPart(ScrollbarPart part) { | 300 void Scrollbar::setHoveredPart(ScrollbarPart part) { |
300 if (part == m_hoveredPart) | 301 if (part == m_hoveredPart) |
301 return; | 302 return; |
302 | 303 |
303 if (((m_hoveredPart == NoPart || part == NoPart) && | 304 if (((m_hoveredPart == NoPart || part == NoPart) && |
304 theme().invalidateOnMouseEnterExit()) | 305 theme().invalidateOnMouseEnterExit()) |
305 // When there's a pressed part, we don't draw a hovered state, so there's
no reason to invalidate. | 306 // When there's a pressed part, we don't draw a hovered state, so there's |
| 307 // no reason to invalidate. |
306 || m_pressedPart == NoPart) | 308 || m_pressedPart == NoPart) |
307 setNeedsPaintInvalidation(static_cast<ScrollbarPart>(m_hoveredPart | part)); | 309 setNeedsPaintInvalidation(static_cast<ScrollbarPart>(m_hoveredPart | part)); |
308 | 310 |
309 m_hoveredPart = part; | 311 m_hoveredPart = part; |
310 } | 312 } |
311 | 313 |
312 void Scrollbar::setPressedPart(ScrollbarPart part) { | 314 void Scrollbar::setPressedPart(ScrollbarPart part) { |
313 if (m_pressedPart != NoPart | 315 if (m_pressedPart != NoPart |
314 // When we no longer have a pressed part, we can start drawing a hovered s
tate on the hovered part. | 316 // When we no longer have a pressed part, we can start drawing a hovered |
| 317 // state on the hovered part. |
315 || m_hoveredPart != NoPart) | 318 || m_hoveredPart != NoPart) |
316 setNeedsPaintInvalidation( | 319 setNeedsPaintInvalidation( |
317 static_cast<ScrollbarPart>(m_pressedPart | m_hoveredPart | part)); | 320 static_cast<ScrollbarPart>(m_pressedPart | m_hoveredPart | part)); |
318 m_pressedPart = part; | 321 m_pressedPart = part; |
319 } | 322 } |
320 | 323 |
321 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt, | 324 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt, |
322 bool* shouldUpdateCapture) { | 325 bool* shouldUpdateCapture) { |
323 DCHECK(shouldUpdateCapture); | 326 DCHECK(shouldUpdateCapture); |
324 switch (evt.type()) { | 327 switch (evt.type()) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 setHoveredPart(NoPart); | 463 setHoveredPart(NoPart); |
461 } | 464 } |
462 | 465 |
463 void Scrollbar::mouseUp(const PlatformMouseEvent& mouseEvent) { | 466 void Scrollbar::mouseUp(const PlatformMouseEvent& mouseEvent) { |
464 setPressedPart(NoPart); | 467 setPressedPart(NoPart); |
465 m_pressedPos = 0; | 468 m_pressedPos = 0; |
466 m_draggingDocument = false; | 469 m_draggingDocument = false; |
467 stopTimerIfNeeded(); | 470 stopTimerIfNeeded(); |
468 | 471 |
469 if (m_scrollableArea) { | 472 if (m_scrollableArea) { |
470 // m_hoveredPart won't be updated until the next mouseMoved or mouseDown, so
we have to hit test | 473 // m_hoveredPart won't be updated until the next mouseMoved or mouseDown, so |
471 // to really know if the mouse has exited the scrollbar on a mouseUp. | 474 // we have to hit test to really know if the mouse has exited the scrollbar |
| 475 // on a mouseUp. |
472 ScrollbarPart part = theme().hitTest(*this, mouseEvent.position()); | 476 ScrollbarPart part = theme().hitTest(*this, mouseEvent.position()); |
473 if (part == NoPart) | 477 if (part == NoPart) |
474 m_scrollableArea->mouseExitedScrollbar(*this); | 478 m_scrollableArea->mouseExitedScrollbar(*this); |
475 } | 479 } |
476 } | 480 } |
477 | 481 |
478 void Scrollbar::mouseDown(const PlatformMouseEvent& evt) { | 482 void Scrollbar::mouseDown(const PlatformMouseEvent& evt) { |
479 // Early exit for right click | 483 // Early exit for right click |
480 if (evt.pointerProperties().button == WebPointerProperties::Button::Right) | 484 if (evt.pointerProperties().button == WebPointerProperties::Button::Right) |
481 return; | 485 return; |
482 | 486 |
483 setPressedPart(theme().hitTest(*this, evt.position())); | 487 setPressedPart(theme().hitTest(*this, evt.position())); |
484 int pressedPos = orientation() == HorizontalScrollbar | 488 int pressedPos = orientation() == HorizontalScrollbar |
485 ? convertFromRootFrame(evt.position()).x() | 489 ? convertFromRootFrame(evt.position()).x() |
486 : convertFromRootFrame(evt.position()).y(); | 490 : convertFromRootFrame(evt.position()).y(); |
487 | 491 |
488 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && | 492 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && |
489 theme().shouldCenterOnThumb(*this, evt)) { | 493 theme().shouldCenterOnThumb(*this, evt)) { |
490 setHoveredPart(ThumbPart); | 494 setHoveredPart(ThumbPart); |
491 setPressedPart(ThumbPart); | 495 setPressedPart(ThumbPart); |
492 m_dragOrigin = m_currentPos; | 496 m_dragOrigin = m_currentPos; |
493 int thumbLen = theme().thumbLength(*this); | 497 int thumbLen = theme().thumbLength(*this); |
494 int desiredPos = pressedPos; | 498 int desiredPos = pressedPos; |
495 // Set the pressed position to the middle of the thumb so that when we do th
e move, the delta | 499 // Set the pressed position to the middle of the thumb so that when we do |
496 // will be from the current pixel position of the thumb to the new desired p
osition for the thumb. | 500 // the move, the delta will be from the current pixel position of the thumb |
| 501 // to the new desired position for the thumb. |
497 m_pressedPos = theme().trackPosition(*this) + theme().thumbPosition(*this) + | 502 m_pressedPos = theme().trackPosition(*this) + theme().thumbPosition(*this) + |
498 thumbLen / 2; | 503 thumbLen / 2; |
499 moveThumb(desiredPos); | 504 moveThumb(desiredPos); |
500 return; | 505 return; |
501 } | 506 } |
502 if (m_pressedPart == ThumbPart) | 507 if (m_pressedPart == ThumbPart) |
503 m_dragOrigin = m_currentPos; | 508 m_dragOrigin = m_currentPos; |
504 | 509 |
505 m_pressedPos = pressedPos; | 510 m_pressedPos = pressedPos; |
506 | 511 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 invalidParts = AllParts; | 618 invalidParts = AllParts; |
614 if (invalidParts & ~ThumbPart) | 619 if (invalidParts & ~ThumbPart) |
615 m_trackNeedsRepaint = true; | 620 m_trackNeedsRepaint = true; |
616 if (invalidParts & ThumbPart) | 621 if (invalidParts & ThumbPart) |
617 m_thumbNeedsRepaint = true; | 622 m_thumbNeedsRepaint = true; |
618 if (m_scrollableArea) | 623 if (m_scrollableArea) |
619 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); | 624 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); |
620 } | 625 } |
621 | 626 |
622 } // namespace blink | 627 } // namespace blink |
OLD | NEW |