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"
12 bool WebScrollbarBehaviorImpl::shouldCenterOnThumb(
13 blink::WebScrollbarBehavior::Button mouseButton
,
16 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS))
17 if (mouseButton
== blink::WebScrollbarBehavior::ButtonMiddle
)
20 return (mouseButton
== blink::WebScrollbarBehavior::ButtonLeft
) &&
24 bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin(
25 const blink::WebPoint
& eventPoint
,
26 const blink::WebRect
& scrollbarRect
,
28 // Constants used to figure the drag rect outside which we should snap the
29 // scrollbar thumb back to its origin. These calculations are based on
30 // observing the behavior of the MSVC8 main window scrollbar + some
31 // guessing/extrapolation.
32 static const int kOffEndMultiplier
= 3;
33 static const int kOffSideMultiplier
= 8;
35 // Find the rect within which we shouldn't snap, by expanding the track rect
36 // in both dimensions.
37 gfx::Rect
noSnapRect(scrollbarRect
);
38 const int thickness
= isHorizontal
? noSnapRect
.height() : noSnapRect
.width();
40 (isHorizontal
? kOffEndMultiplier
: kOffSideMultiplier
) * -thickness
,
41 (isHorizontal
? kOffSideMultiplier
: kOffEndMultiplier
) * -thickness
);
43 // We should snap iff the event is outside our calculated rect.
44 return !noSnapRect
.Contains(eventPoint
);
47 } // namespace content