IntRect ScrollbarThemeAura::trackRect(const ScrollbarThemeClient& scrollbar, bool) { // The track occupies all space between the two buttons. IntSize bs = buttonSize(scrollbar); if (scrollbar.orientation() == HorizontalScrollbar) { if (scrollbar.width() <= 2 * bs.width()) return IntRect(); return IntRect(scrollbar.x() + bs.width(), scrollbar.y(), scrollbar.width() - 2 * bs.width(), scrollbar.height()); } if (scrollbar.height() <= 2 * bs.height()) return IntRect(); return IntRect(scrollbar.x(), scrollbar.y() + bs.height(), scrollbar.width(), scrollbar.height() - 2 * bs.height()); }
int ScrollbarTheme::trackPosition(const ScrollbarThemeClient& scrollbar) { IntRect constrainedTrackRect = constrainTrackRectToTrackPieces(scrollbar, trackRect(scrollbar)); return (scrollbar.orientation() == HorizontalScrollbar) ? constrainedTrackRect.x() - scrollbar.x() : constrainedTrackRect.y() - scrollbar.y(); }
bool ScrollbarTheme::shouldSnapBackToDragOrigin( const ScrollbarThemeClient& scrollbar, const PlatformMouseEvent& evt) { IntPoint mousePosition = scrollbar.convertFromRootFrame(evt.position()); mousePosition.move(scrollbar.x(), scrollbar.y()); return Platform::current()->scrollbarBehavior()->shouldSnapBackToDragOrigin( mousePosition, trackRect(scrollbar), scrollbar.orientation() == HorizontalScrollbar); }
IntRect ScrollbarThemeAura::forwardButtonRect( const ScrollbarThemeClient& scrollbar, ScrollbarPart part, bool) { // Windows and Linux just have single arrows. if (part == ForwardButtonStartPart) return IntRect(); IntSize size = buttonSize(scrollbar); int x, y; if (scrollbar.orientation() == HorizontalScrollbar) { x = scrollbar.x() + scrollbar.width() - size.width(); y = scrollbar.y(); } else { x = scrollbar.x(); y = scrollbar.y() + scrollbar.height() - size.height(); } return IntRect(x, y, size.width(), size.height()); }
IntRect ScrollbarThemeAura::backButtonRect( const ScrollbarThemeClient& scrollbar, ScrollbarPart part, bool) { // Windows and Linux just have single arrows. if (part == BackButtonEndPart) return IntRect(); IntSize size = buttonSize(scrollbar); return IntRect(scrollbar.x(), scrollbar.y(), size.width(), size.height()); }
ScrollbarPart ScrollbarTheme::hitTest(const ScrollbarThemeClient& scrollbar, const IntPoint& positionInRootFrame) { ScrollbarPart result = NoPart; if (!scrollbar.enabled()) return result; IntPoint testPosition = scrollbar.convertFromRootFrame(positionInRootFrame); testPosition.move(scrollbar.x(), scrollbar.y()); if (!scrollbar.frameRect().contains(testPosition)) return NoPart; result = ScrollbarBGPart; IntRect track = trackRect(scrollbar); if (track.contains(testPosition)) { IntRect beforeThumbRect; IntRect thumbRect; IntRect afterThumbRect; splitTrack(scrollbar, track, beforeThumbRect, thumbRect, afterThumbRect); if (thumbRect.contains(testPosition)) result = ThumbPart; else if (beforeThumbRect.contains(testPosition)) result = BackTrackPart; else if (afterThumbRect.contains(testPosition)) result = ForwardTrackPart; else result = TrackBGPart; } else if (backButtonRect(scrollbar, BackButtonStartPart) .contains(testPosition)) { result = BackButtonStartPart; } else if (backButtonRect(scrollbar, BackButtonEndPart) .contains(testPosition)) { result = BackButtonEndPart; } else if (forwardButtonRect(scrollbar, ForwardButtonStartPart) .contains(testPosition)) { result = ForwardButtonStartPart; } else if (forwardButtonRect(scrollbar, ForwardButtonEndPart) .contains(testPosition)) { result = ForwardButtonEndPart; } return result; }