diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 03:56:51 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 03:56:51 +0000 |
commit | 507b33eab2acbb4e360b5b6eb9f2e666079d0e3b (patch) | |
tree | 6fd3dd864e9da3e68efc7ded0dbaf96b597fcd3c /webkit | |
parent | 529338471fec2ab9b07bac9b07e3477b20e0ae28 (diff) | |
download | chromium_src-507b33eab2acbb4e360b5b6eb9f2e666079d0e3b.zip chromium_src-507b33eab2acbb4e360b5b6eb9f2e666079d0e3b.tar.gz chromium_src-507b33eab2acbb4e360b5b6eb9f2e666079d0e3b.tar.bz2 |
Fix cmd-up/cmd-down.
The approach is to special-case moveToBeginningOfDocument and moveToEndOfDocument in WebFrameImpl::executeCommand(). With this (and the cocoa keyboard bindings patch being landed), the special-case code in WebViewImpl::ScrollViewWithKeyboard() can be removed.
Also add a test for cmd-up/down.
Change chrome.gyp so that it supports osx-only unit tests (_unittest_mac.mm).
Move OnPrintPageAsBitmap to the other printing tests.
BUG=22585
TEST=Go to a page with both text box and scrollbar (e.g. http://en.wikipedia.org ). Pressing cmd-down should scroll to end of page, cmd-up back to start. Clicking the text box and trying some emacs shortcuts should work (ctrl-a jumps to start of line, cmd-h acts as backspace, etc).
Review URL: http://codereview.chromium.org/254002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webframe_impl.cc | 19 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 33 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 5 |
3 files changed, 33 insertions, 24 deletions
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 68c6882..e49fed8 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -121,6 +121,7 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "ScriptSourceCode.h" #include "ScriptValue.h" #include "ScrollbarTheme.h" +#include "ScrollTypes.h" #include "SelectionController.h" #include "Settings.h" #include "SkiaUtils.h" @@ -1011,8 +1012,22 @@ bool WebFrameImpl::executeCommand(const WebString& name) { bool WebFrameImpl::executeCommand(const WebString& name, const WebString& value) { ASSERT(frame()); - return frame()->editor()->command(webkit_glue::WebStringToString(name)). - execute(webkit_glue::WebStringToString(value)); + WebCore::String web_name = webkit_glue::WebStringToString(name); + + // moveToBeginningOfDocument and moveToEndfDocument are only handled by WebKit + // for editable nodes. + if (!frame()->editor()->canEdit() && + web_name == "moveToBeginningOfDocument") { + return GetWebViewImpl()->PropagateScroll(WebCore::ScrollUp, + WebCore::ScrollByDocument); + } else if (!frame()->editor()->canEdit() && + web_name == "moveToEndOfDocument") { + return GetWebViewImpl()->PropagateScroll(WebCore::ScrollDown, + WebCore::ScrollByDocument); + } else { + return frame()->editor()->command(web_name). + execute(webkit_glue::WebStringToString(value)); + } } bool WebFrameImpl::isCommandEnabled(const WebString& name) const { diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index 6900853..74a4c3f 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -862,10 +862,6 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { } bool WebViewImpl::ScrollViewWithKeyboard(int key_code, int modifiers) { - Frame* frame = GetFocusedWebCoreFrame(); - if (!frame) - return false; - ScrollDirection scroll_direction; ScrollGranularity scroll_granularity; @@ -880,29 +876,11 @@ bool WebViewImpl::ScrollViewWithKeyboard(int key_code, int modifiers) { break; case VKEY_UP: scroll_direction = ScrollUp; -#if defined(OS_MACOSX) - // Many Mac applications (such as TextEdit, Safari, Firefox, etc.) scroll - // to the beginning of a page when typing command+up keys. It is better - // for Mac Chrome to emulate this behavior to improve compatibility with - // these applications. - scroll_granularity = (modifiers == WebInputEvent::MetaKey) ? - ScrollByDocument : ScrollByLine; -#else scroll_granularity = ScrollByLine; -#endif break; case VKEY_DOWN: scroll_direction = ScrollDown; -#if defined(OS_MACOSX) - // Many Mac applications (such as TextEdit, Safari, Firefox, etc.) scroll - // to the end of a page when typing command+down keys. It is better - // for Mac Chrome to emulate this behavior to improve compatibility with - // these applications. - scroll_granularity = (modifiers == WebInputEvent::MetaKey) ? - ScrollByDocument : ScrollByLine; -#else scroll_granularity = ScrollByLine; -#endif break; case VKEY_HOME: scroll_direction = ScrollUp; @@ -924,6 +902,17 @@ bool WebViewImpl::ScrollViewWithKeyboard(int key_code, int modifiers) { return false; } + return PropagateScroll(scroll_direction, scroll_granularity); +} + +bool WebViewImpl::PropagateScroll( + WebCore::ScrollDirection scroll_direction, + WebCore::ScrollGranularity scroll_granularity) { + + Frame* frame = GetFocusedWebCoreFrame(); + if (!frame) + return false; + bool scroll_handled = frame->eventHandler()->scrollOverflow(scroll_direction, scroll_granularity); diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 5ecb4cc..bb9f077 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -256,6 +256,11 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { WebKit::NotificationPresenterImpl* GetNotificationPresenter(); #endif + // Tries to scroll a frame or any parent of a frame. Returns true if the view + // was scrolled. + bool PropagateScroll(WebCore::ScrollDirection scroll_direction, + WebCore::ScrollGranularity scroll_granularity); + protected: friend class WebView; // So WebView::Create can call our constructor friend class base::RefCounted<WebViewImpl>; |