| 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_aura.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "third_party/WebKit/public/platform/WebPoint.h" | 8 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 9 #include "third_party/WebKit/public/platform/WebRect.h" | 9 #include "third_party/WebKit/public/platform/WebRect.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 bool WebScrollbarBehaviorImpl::shouldCenterOnThumb( | 13 bool WebScrollbarBehaviorImpl::shouldCenterOnThumb( |
| 14 blink::WebPointerProperties::Button mouseButton, | 14 blink::WebPointerProperties::Button mouseButton, |
| 15 bool shiftKeyPressed, | 15 bool shiftKeyPressed, |
| 16 bool altKeyPressed) { | 16 bool altKeyPressed) { |
| 17 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 17 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 18 if (mouseButton == blink::WebPointerProperties::Button::Middle) | 18 if (mouseButton == blink::WebPointerProperties::Button::Middle) |
| 19 return true; | 19 return true; |
| 20 #endif | 20 #endif |
| 21 return (mouseButton == blink::WebPointerProperties::Button::Left) && | 21 return (mouseButton == blink::WebPointerProperties::Button::Left) && |
| 22 shiftKeyPressed; | 22 shiftKeyPressed; |
| 23 } | 23 } |
| 24 | 24 |
| 25 bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin( | 25 bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin( |
| 26 const blink::WebPoint& eventPoint, | 26 const blink::WebPoint& eventPoint, |
| 27 const blink::WebRect& scrollbarRect, | 27 const blink::WebRect& scrollbarRect, |
| 28 bool isHorizontal) { | 28 bool isHorizontal) { |
| 29 // Disable snapback on desktop Linux to better integrate with the desktop |
| 30 // behavior. Typically, Linux apps do not implement scrollbar snapback (this is |
| 31 // true for at least GTK and QT apps). |
| 32 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 33 return false; |
| 34 #endif |
| 35 |
| 29 // Constants used to figure the drag rect outside which we should snap the | 36 // Constants used to figure the drag rect outside which we should snap the |
| 30 // scrollbar thumb back to its origin. These calculations are based on | 37 // scrollbar thumb back to its origin. These calculations are based on |
| 31 // observing the behavior of the MSVC8 main window scrollbar + some | 38 // observing the behavior of the MSVC8 main window scrollbar + some |
| 32 // guessing/extrapolation. | 39 // guessing/extrapolation. |
| 33 static const int kOffEndMultiplier = 3; | 40 static const int kOffEndMultiplier = 3; |
| 34 static const int kOffSideMultiplier = 8; | 41 static const int kOffSideMultiplier = 8; |
| 35 static const int kDefaultWinScrollbarThickness = 17; | 42 static const int kDefaultWinScrollbarThickness = 17; |
| 36 | 43 |
| 37 // Find the rect within which we shouldn't snap, by expanding the track rect | 44 // Find the rect within which we shouldn't snap, by expanding the track rect |
| 38 // in both dimensions. | 45 // in both dimensions. |
| 39 gfx::Rect noSnapRect(scrollbarRect); | 46 gfx::Rect noSnapRect(scrollbarRect); |
| 40 int thickness = isHorizontal ? noSnapRect.height() : noSnapRect.width(); | 47 int thickness = isHorizontal ? noSnapRect.height() : noSnapRect.width(); |
| 41 // Even if the platform's scrollbar is narrower than the default Windows one, | 48 // Even if the platform's scrollbar is narrower than the default Windows one, |
| 42 // we still want to provide at least as much slop area, since a slightly | 49 // we still want to provide at least as much slop area, since a slightly |
| 43 // narrower scrollbar doesn't necessarily imply that users will drag | 50 // narrower scrollbar doesn't necessarily imply that users will drag |
| 44 // straighter. | 51 // straighter. |
| 45 thickness = std::max(thickness, kDefaultWinScrollbarThickness); | 52 thickness = std::max(thickness, kDefaultWinScrollbarThickness); |
| 46 noSnapRect.Inset( | 53 noSnapRect.Inset( |
| 47 (isHorizontal ? kOffEndMultiplier : kOffSideMultiplier) * -thickness, | 54 (isHorizontal ? kOffEndMultiplier : kOffSideMultiplier) * -thickness, |
| 48 (isHorizontal ? kOffSideMultiplier : kOffEndMultiplier) * -thickness); | 55 (isHorizontal ? kOffSideMultiplier : kOffEndMultiplier) * -thickness); |
| 49 | 56 |
| 50 // On most platforms, we should snap iff the event is outside our calculated | |
| 51 // rect. On Linux, however, we should not snap for events off the ends, but | |
| 52 // not the sides, of the rect. | |
| 53 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | |
| 54 return isHorizontal ? | |
| 55 (eventPoint.y < noSnapRect.y() || eventPoint.y >= noSnapRect.bottom()) : | |
| 56 (eventPoint.x < noSnapRect.x() || eventPoint.x >= noSnapRect.right()); | |
| 57 #else | |
| 58 return !noSnapRect.Contains(eventPoint); | 57 return !noSnapRect.Contains(eventPoint); |
| 59 #endif | |
| 60 } | 58 } |
| 61 | 59 |
| 62 } // namespace content | 60 } // namespace content |
| OLD | NEW |