diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-05 22:14:37 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-05 22:14:37 +0000 |
commit | 1fc72ac73e0915008a7484b304d12a1145bbd15f (patch) | |
tree | f7a88f4ab88bb84ad3a3b8b4dc85eef72cb5d3eb | |
parent | 7acf245ce362ae251975696611ac80e686dc36a2 (diff) | |
download | chromium_src-1fc72ac73e0915008a7484b304d12a1145bbd15f.zip chromium_src-1fc72ac73e0915008a7484b304d12a1145bbd15f.tar.gz chromium_src-1fc72ac73e0915008a7484b304d12a1145bbd15f.tar.bz2 |
Merge 254305 "After Aura copied the original Linux scrollbar beh..."
> After Aura copied the original Linux scrollbar behvaior, it never got updated
> with Windows-specific native behaviors from ScrollbarThemeWin.cpp:
>
> * Snap the scrollbar back to its drag origin when dragged too far off the track.
> This code matches the old code we had for years and also matches my Win 7
> native scrollbars pixel-for-pixel.
>
> * Don't jump the scroll thumb to the mouse cursor on a middle-click, only on a
> shift-click. Middle-click must be a GTK-ism.
>
> This is the Chrome side of the changes to re-add this behavior.
>
> BUG=337919
> TEST=Drag a scroll thumb to somewhere in the track, then without releasing, move the mouse far away from the track. The scroll thumb should snap back to the scroll origin.
> R=avi@chromium.org
>
> Review URL: https://codereview.chromium.org/175903002
TBR=pkasting@chromium.org
Review URL: https://codereview.chromium.org/188083003
git-svn-id: svn://svn.chromium.org/chrome/branches/1847/src@255163 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/content_renderer.gypi | 11 | ||||
-rw-r--r-- | content/renderer/render_thread_impl.cc | 28 | ||||
-rw-r--r-- | content/renderer/renderer_webkitplatformsupport_impl.cc | 33 | ||||
-rw-r--r-- | content/renderer/renderer_webkitplatformsupport_impl.h | 3 | ||||
-rw-r--r-- | content/renderer/webscrollbarbehavior_impl_gtkoraura.cc | 51 | ||||
-rw-r--r-- | content/renderer/webscrollbarbehavior_impl_gtkoraura.h | 25 | ||||
-rw-r--r-- | content/renderer/webscrollbarbehavior_impl_mac.h | 32 | ||||
-rw-r--r-- | content/renderer/webscrollbarbehavior_impl_mac.mm | 21 |
8 files changed, 184 insertions, 20 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 30c102a..ee69c72 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -523,6 +523,10 @@ 'renderer/webgraphicscontext3d_provider_impl.h', 'renderer/webpublicsuffixlist_impl.cc', 'renderer/webpublicsuffixlist_impl.h', + 'renderer/webscrollbarbehavior_impl_gtkoraura.cc', + 'renderer/webscrollbarbehavior_impl_gtkoraura.h', + 'renderer/webscrollbarbehavior_impl_mac.mm', + 'renderer/webscrollbarbehavior_impl_mac.h', 'renderer/websharedworker_proxy.cc', 'renderer/websharedworker_proxy.h', ], @@ -547,6 +551,13 @@ ['OS=="mac"', { 'sources!': [ 'common/process_watcher_posix.cc', + 'renderer/webscrollbarbehavior_impl_gtkoraura.cc', + 'renderer/webscrollbarbehavior_impl_gtkoraura.h', + ], + }, { + 'sources!': [ + 'renderer/webscrollbarbehavior_impl_mac.mm', + 'renderer/webscrollbarbehavior_impl_mac.h', ], }], ['OS=="win" and win_use_allocator_shim==1', { diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index e27d04f..96f4904 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -115,6 +115,20 @@ #include "webkit/child/worker_task_runner.h" #include "webkit/renderer/compositor_bindings/web_external_bitmap_impl.h" +#if defined(OS_ANDROID) +#include <cpu-features.h> +#include "content/renderer/android/synchronous_compositor_factory.h" +#include "content/renderer/media/android/renderer_demuxer_android.h" +#endif + +#if defined(OS_MACOSX) +#include "content/renderer/webscrollbarbehavior_impl_mac.h" +#endif + +#if defined(OS_POSIX) +#include "ipc/ipc_channel_posix.h" +#endif + #if defined(OS_WIN) #include <windows.h> #include <objbase.h> @@ -124,16 +138,6 @@ #include "content/child/npapi/np_channel_base.h" #endif -#if defined(OS_POSIX) -#include "ipc/ipc_channel_posix.h" -#endif - -#if defined(OS_ANDROID) -#include <cpu-features.h> -#include "content/renderer/android/synchronous_compositor_factory.h" -#include "content/renderer/media/android/renderer_demuxer_android.h" -#endif - #if defined(ENABLE_PLUGINS) #include "content/renderer/npapi/plugin_channel_host.h" #endif @@ -1321,9 +1325,11 @@ void RenderThreadImpl::OnUpdateScrollbarTheme( bool jump_on_track_click, blink::ScrollerStyle preferred_scroller_style, bool redraw) { + static_cast<WebScrollbarBehaviorImpl*>( + webkit_platform_support_->scrollbarBehavior())->set_jump_on_track_click( + jump_on_track_click); blink::WebScrollbarTheme::updateScrollbars(initial_button_delay, autoscroll_button_delay, - jump_on_track_click, preferred_scroller_style, redraw); } diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc index a92c3ae..3d6f55e 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.cc +++ b/content/renderer/renderer_webkitplatformsupport_impl.cc @@ -75,18 +75,20 @@ #include "webkit/common/gpu/context_provider_web_context.h" #include "webkit/common/quota/quota_types.h" -#if defined(OS_WIN) -#include "content/common/child_process_messages.h" -#include "third_party/WebKit/public/platform/win/WebSandboxSupport.h" +#if defined(OS_ANDROID) +#include "content/renderer/media/android/audio_decoder_android.h" #endif #if defined(OS_MACOSX) #include "content/common/mac/font_descriptor.h" #include "content/common/mac/font_loader.h" +#include "content/renderer/webscrollbarbehavior_impl_mac.h" #include "third_party/WebKit/public/platform/mac/WebSandboxSupport.h" #endif -#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) +#if defined(OS_POSIX) +#include "base/file_descriptor_posix.h" +#if !defined(OS_MACOSX) && !defined(OS_ANDROID) #include <map> #include <string> @@ -96,13 +98,18 @@ #include "third_party/WebKit/public/platform/linux/WebSandboxSupport.h" #include "third_party/icu/source/common/unicode/utf16.h" #endif +#endif -#if defined(OS_POSIX) -#include "base/file_descriptor_posix.h" +#if defined(OS_WIN) +#include "content/common/child_process_messages.h" +#include "third_party/WebKit/public/platform/win/WebSandboxSupport.h" #endif -#if defined(OS_ANDROID) -#include "content/renderer/media/android/audio_decoder_android.h" +#if defined(TOOLKIT_GTK) || defined(USE_AURA) +#include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h" +#elif !defined(OS_MACOSX) +#include "third_party/WebKit/public/platform/WebScrollbarBehavior.h" +#define WebScrollbarBehaviorImpl blink::WebScrollbarBehavior #endif using blink::Platform; @@ -206,7 +213,8 @@ RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), sudden_termination_disables_(0), plugin_refresh_allowed_(true), - child_thread_loop_(base::MessageLoopProxy::current()) { + child_thread_loop_(base::MessageLoopProxy::current()), + web_scrollbar_behavior_(new WebScrollbarBehaviorImpl) { if (g_sandbox_enabled && sandboxEnabled()) { sandbox_support_.reset( new RendererWebKitPlatformSupportImpl::SandboxSupport); @@ -843,6 +851,13 @@ void RendererWebKitPlatformSupportImpl::screenColorProfile( //------------------------------------------------------------------------------ +blink::WebScrollbarBehavior* + RendererWebKitPlatformSupportImpl::scrollbarBehavior() { + return web_scrollbar_behavior_.get(); +} + +//------------------------------------------------------------------------------ + WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { // blob_registry_ can be NULL when running some tests. return blob_registry_.get(); diff --git a/content/renderer/renderer_webkitplatformsupport_impl.h b/content/renderer/renderer_webkitplatformsupport_impl.h index 45f2924..f9ab0b3 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.h +++ b/content/renderer/renderer_webkitplatformsupport_impl.h @@ -91,6 +91,7 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl blink::WebPluginListBuilder* builder); virtual blink::WebPublicSuffixList* publicSuffixList(); virtual void screenColorProfile(blink::WebVector<char>* to_profile); + virtual blink::WebScrollbarBehavior* scrollbarBehavior(); virtual blink::WebIDBFactory* idbFactory(); virtual blink::WebFileSystem* fileSystem(); virtual bool canAccelerate2dCanvas(); @@ -218,6 +219,8 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl scoped_ptr<WebCryptoImpl> web_crypto_; + scoped_ptr<blink::WebScrollbarBehavior> web_scrollbar_behavior_; + DISALLOW_COPY_AND_ASSIGN(RendererWebKitPlatformSupportImpl); }; diff --git a/content/renderer/webscrollbarbehavior_impl_gtkoraura.cc b/content/renderer/webscrollbarbehavior_impl_gtkoraura.cc new file mode 100644 index 0000000..8398858 --- /dev/null +++ b/content/renderer/webscrollbarbehavior_impl_gtkoraura.cc @@ -0,0 +1,51 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/renderer/webscrollbarbehavior_impl_gtkoraura.h" + +#include "third_party/WebKit/public/platform/WebPoint.h" +#include "third_party/WebKit/public/platform/WebRect.h" + +namespace content { + +bool WebScrollbarBehaviorImpl::shouldCenterOnThumb( + blink::WebScrollbarBehavior::Button mouseButton, + bool shiftKeyPressed, + bool altKeyPressed) { +#if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) + if (mouseButton == blink::WebScrollbarBehavior::ButtonMiddle) + return true; +#endif + return (mouseButton == blink::WebScrollbarBehavior::ButtonLeft) && + shiftKeyPressed; +} + +bool WebScrollbarBehaviorImpl::shouldSnapBackToDragOrigin( + const blink::WebPoint& eventPoint, + const blink::WebRect& scrollbarRect, + bool isHorizontal) { +#if defined(TOOLKIT_GTK) + return false; +#endif + + // Constants used to figure the drag rect outside which we should snap the + // scrollbar thumb back to its origin. These calculations are based on + // observing the behavior of the MSVC8 main window scrollbar + some + // guessing/extrapolation. + static const int kOffEndMultiplier = 3; + static const int kOffSideMultiplier = 8; + + // Find the rect within which we shouldn't snap, by expanding the track rect + // in both dimensions. + gfx::Rect noSnapRect(scrollbarRect); + const int thickness = isHorizontal ? noSnapRect.height() : noSnapRect.width(); + noSnapRect.Inset( + (isHorizontal ? kOffEndMultiplier : kOffSideMultiplier) * -thickness, + (isHorizontal ? kOffSideMultiplier : kOffEndMultiplier) * -thickness); + + // We should snap iff the event is outside our calculated rect. + return !noSnapRect.Contains(eventPoint); +} + +} // namespace content
\ No newline at end of file diff --git a/content/renderer/webscrollbarbehavior_impl_gtkoraura.h b/content/renderer/webscrollbarbehavior_impl_gtkoraura.h new file mode 100644 index 0000000..7d681d3 --- /dev/null +++ b/content/renderer/webscrollbarbehavior_impl_gtkoraura.h @@ -0,0 +1,25 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_CHILD_WEBSCROLLBARBEHAVIOR_IMPL_GTKORAURA_H_ +#define CONTENT_CHILD_WEBSCROLLBARBEHAVIOR_IMPL_GTKORAURA_H_ + +#include "third_party/WebKit/public/platform/WebScrollbarBehavior.h" + +namespace content { + +class WebScrollbarBehaviorImpl : public blink::WebScrollbarBehavior { + public: + virtual bool shouldCenterOnThumb( + blink::WebScrollbarBehavior::Button mouseButton, + bool shiftKeyPressed, + bool altKeyPressed); + virtual bool shouldSnapBackToDragOrigin(const blink::WebPoint& eventPoint, + const blink::WebRect& scrollbarRect, + bool isHorizontal); +}; + +} // namespace content + +#endif // CONTENT_CHILD_WEBSCROLLBARBEHAVIOR_IMPL_GTKORAURA_H_ diff --git a/content/renderer/webscrollbarbehavior_impl_mac.h b/content/renderer/webscrollbarbehavior_impl_mac.h new file mode 100644 index 0000000..5632299 --- /dev/null +++ b/content/renderer/webscrollbarbehavior_impl_mac.h @@ -0,0 +1,32 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_CHILD_WEBSCROLLBARBEHAVIOR_IMPL_MAC_H_ +#define CONTENT_CHILD_WEBSCROLLBARBEHAVIOR_IMPL_MAC_H_ + +#include "third_party/WebKit/public/platform/WebScrollbarBehavior.h" + +namespace content { + +class WebScrollbarBehaviorImpl : public blink::WebScrollbarBehavior { + public: + WebScrollbarBehaviorImpl(); + + virtual bool shouldCenterOnThumb( + blink::WebScrollbarBehavior::Button mouseButton, + bool shiftKeyPressed, + bool altKeyPressed); + + void set_jump_on_track_click(bool jump_on_track_click) { + jump_on_track_click_ = jump_on_track_click; + } + + private: + // The current value of AppleScrollerPagingBehavior from NSUserDefaults. + bool jump_on_track_click_; +}; + +} // namespace content + +#endif // CONTENT_CHILD_WEBSCROLLBARBEHAVIOR_IMPL_MAC_H_ diff --git a/content/renderer/webscrollbarbehavior_impl_mac.mm b/content/renderer/webscrollbarbehavior_impl_mac.mm new file mode 100644 index 0000000..9f83f8a --- /dev/null +++ b/content/renderer/webscrollbarbehavior_impl_mac.mm @@ -0,0 +1,21 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/renderer/webscrollbarbehavior_impl_mac.h" + +namespace content { + +WebScrollbarBehaviorImpl::WebScrollbarBehaviorImpl() + : jump_on_track_click_(false) { +} + +bool WebScrollbarBehaviorImpl::shouldCenterOnThumb( + blink::WebScrollbarBehavior::Button mouseButton, + bool shiftKeyPressed, + bool altKeyPressed) { + return (mouseButton == blink::WebScrollbarBehavior::ButtonLeft) && + (jump_on_track_click_ != altKeyPressed); +} + +} // namespace content |