OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h" | 5 #include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h" |
6 | 6 |
7 #include "third_party/WebKit/public/platform/WebPoint.h" | 7 #include "third_party/WebKit/public/platform/WebPoint.h" |
8 #include "third_party/WebKit/public/platform/WebRect.h" | 8 #include "third_party/WebKit/public/platform/WebRect.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
(...skipping 13 matching lines...) Expand all Loading... |
24 bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin( | 24 bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin( |
25 const blink::WebPoint& eventPoint, | 25 const blink::WebPoint& eventPoint, |
26 const blink::WebRect& scrollbarRect, | 26 const blink::WebRect& scrollbarRect, |
27 bool isHorizontal) { | 27 bool isHorizontal) { |
28 // Constants used to figure the drag rect outside which we should snap the | 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 | 29 // scrollbar thumb back to its origin. These calculations are based on |
30 // observing the behavior of the MSVC8 main window scrollbar + some | 30 // observing the behavior of the MSVC8 main window scrollbar + some |
31 // guessing/extrapolation. | 31 // guessing/extrapolation. |
32 static const int kOffEndMultiplier = 3; | 32 static const int kOffEndMultiplier = 3; |
33 static const int kOffSideMultiplier = 8; | 33 static const int kOffSideMultiplier = 8; |
| 34 static const int kDefaultWinScrollbarThickness = 17; |
34 | 35 |
35 // Find the rect within which we shouldn't snap, by expanding the track rect | 36 // Find the rect within which we shouldn't snap, by expanding the track rect |
36 // in both dimensions. | 37 // in both dimensions. |
37 gfx::Rect noSnapRect(scrollbarRect); | 38 gfx::Rect noSnapRect(scrollbarRect); |
38 const int thickness = isHorizontal ? noSnapRect.height() : noSnapRect.width(); | 39 int thickness = isHorizontal ? noSnapRect.height() : noSnapRect.width(); |
| 40 // Even if the platform's scrollbar is narrower than the default Windows one, |
| 41 // we still want to provide at least as much slop area, since a slightly |
| 42 // narrower scrollbar doesn't necessarily imply that users will drag |
| 43 // straighter. |
| 44 thickness = std::max(thickness, kDefaultWinScrollbarThickness); |
39 noSnapRect.Inset( | 45 noSnapRect.Inset( |
40 (isHorizontal ? kOffEndMultiplier : kOffSideMultiplier) * -thickness, | 46 (isHorizontal ? kOffEndMultiplier : kOffSideMultiplier) * -thickness, |
41 (isHorizontal ? kOffSideMultiplier : kOffEndMultiplier) * -thickness); | 47 (isHorizontal ? kOffSideMultiplier : kOffEndMultiplier) * -thickness); |
42 | 48 |
43 // On most platforms, we should snap iff the event is outside our calculated | 49 // On most platforms, we should snap iff the event is outside our calculated |
44 // rect. On Linux, however, we should not snap for events off the ends, but | 50 // rect. On Linux, however, we should not snap for events off the ends, but |
45 // not the sides, of the rect. | 51 // not the sides, of the rect. |
46 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 52 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
47 return isHorizontal ? | 53 return isHorizontal ? |
48 (eventPoint.y < noSnapRect.y() || eventPoint.y >= noSnapRect.bottom()) : | 54 (eventPoint.y < noSnapRect.y() || eventPoint.y >= noSnapRect.bottom()) : |
49 (eventPoint.x < noSnapRect.x() || eventPoint.x >= noSnapRect.right()); | 55 (eventPoint.x < noSnapRect.x() || eventPoint.x >= noSnapRect.right()); |
50 #else | 56 #else |
51 return !noSnapRect.Contains(eventPoint); | 57 return !noSnapRect.Contains(eventPoint); |
52 #endif | 58 #endif |
53 } | 59 } |
54 | 60 |
55 } // namespace content | 61 } // namespace content |
OLD | NEW |