After Aura copied the original Linux scrollbar behvaior, it never got updated
[chromium-blink-merge.git] / content / renderer / webscrollbarbehavior_impl_gtkoraura.cc
blob8398858b5b2e95efe1a5d243c6a426cc1e51f10c
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h"
7 #include "third_party/WebKit/public/platform/WebPoint.h"
8 #include "third_party/WebKit/public/platform/WebRect.h"
10 namespace content {
12 bool WebScrollbarBehaviorImpl::shouldCenterOnThumb(
13 blink::WebScrollbarBehavior::Button mouseButton,
14 bool shiftKeyPressed,
15 bool altKeyPressed) {
16 #if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
17 if (mouseButton == blink::WebScrollbarBehavior::ButtonMiddle)
18 return true;
19 #endif
20 return (mouseButton == blink::WebScrollbarBehavior::ButtonLeft) &&
21 shiftKeyPressed;
24 bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin(
25 const blink::WebPoint& eventPoint,
26 const blink::WebRect& scrollbarRect,
27 bool isHorizontal) {
28 #if defined(TOOLKIT_GTK)
29 return false;
30 #endif
32 // Constants used to figure the drag rect outside which we should snap the
33 // scrollbar thumb back to its origin. These calculations are based on
34 // observing the behavior of the MSVC8 main window scrollbar + some
35 // guessing/extrapolation.
36 static const int kOffEndMultiplier = 3;
37 static const int kOffSideMultiplier = 8;
39 // Find the rect within which we shouldn't snap, by expanding the track rect
40 // in both dimensions.
41 gfx::Rect noSnapRect(scrollbarRect);
42 const int thickness = isHorizontal ? noSnapRect.height() : noSnapRect.width();
43 noSnapRect.Inset(
44 (isHorizontal ? kOffEndMultiplier : kOffSideMultiplier) * -thickness,
45 (isHorizontal ? kOffSideMultiplier : kOffEndMultiplier) * -thickness);
47 // We should snap iff the event is outside our calculated rect.
48 return !noSnapRect.Contains(eventPoint);
51 } // namespace content