| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h" | |
| 6 | |
| 7 #include "build/build_config.h" | |
| 8 #include "third_party/WebKit/public/platform/WebPoint.h" | |
| 9 #include "third_party/WebKit/public/platform/WebRect.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 bool WebScrollbarBehaviorImpl::shouldCenterOnThumb( | |
| 14 blink::WebPointerProperties::Button mouseButton, | |
| 15 bool shiftKeyPressed, | |
| 16 bool altKeyPressed) { | |
| 17 #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | |
| 18 if (mouseButton == blink::WebPointerProperties::Button::Middle) | |
| 19 return true; | |
| 20 #endif | |
| 21 return (mouseButton == blink::WebPointerProperties::Button::Left) && | |
| 22 shiftKeyPressed; | |
| 23 } | |
| 24 | |
| 25 bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin( | |
| 26 const blink::WebPoint& eventPoint, | |
| 27 const blink::WebRect& scrollbarRect, | |
| 28 bool isHorizontal) { | |
| 29 // 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 | |
| 31 // observing the behavior of the MSVC8 main window scrollbar + some | |
| 32 // guessing/extrapolation. | |
| 33 static const int kOffEndMultiplier = 3; | |
| 34 static const int kOffSideMultiplier = 8; | |
| 35 static const int kDefaultWinScrollbarThickness = 17; | |
| 36 | |
| 37 // Find the rect within which we shouldn't snap, by expanding the track rect | |
| 38 // in both dimensions. | |
| 39 gfx::Rect noSnapRect(scrollbarRect); | |
| 40 int thickness = isHorizontal ? noSnapRect.height() : noSnapRect.width(); | |
| 41 // 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 | |
| 43 // narrower scrollbar doesn't necessarily imply that users will drag | |
| 44 // straighter. | |
| 45 thickness = std::max(thickness, kDefaultWinScrollbarThickness); | |
| 46 noSnapRect.Inset( | |
| 47 (isHorizontal ? kOffEndMultiplier : kOffSideMultiplier) * -thickness, | |
| 48 (isHorizontal ? kOffSideMultiplier : kOffEndMultiplier) * -thickness); | |
| 49 | |
| 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); | |
| 59 #endif | |
| 60 } | |
| 61 | |
| 62 } // namespace content | |
| OLD | NEW |