summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authorericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 21:32:47 +0000
committerericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 21:32:47 +0000
commit0d2772ecb10500d6bf4be0c3033ab4021dfbf4a3 (patch)
treecc47266ff06c35dbab8dc413772889fae9b16be8 /webkit/glue
parentfdbdc954056fd81d6291ccaffae45e849596dd18 (diff)
downloadchromium_src-0d2772ecb10500d6bf4be0c3033ab4021dfbf4a3.zip
chromium_src-0d2772ecb10500d6bf4be0c3033ab4021dfbf4a3.tar.gz
chromium_src-0d2772ecb10500d6bf4be0c3033ab4021dfbf4a3.tar.bz2
yMake ctrl-clicks in GMail open in background tabs rather than foreground tabs.
This piggybacks on eseidel's fix last July that made middle-clicks work. BUG=2566 TEST=Manual testing on Vista with GMail and non-GMail links, with ctrl+click, middle-click, click, and ctrl+shift+click. Review URL: http://codereview.chromium.org/246040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27770 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/chrome_client_impl.cc30
-rw-r--r--webkit/glue/webframeloaderclient_impl.cc28
-rw-r--r--webkit/glue/webview_impl.cc31
-rw-r--r--webkit/glue/webview_impl.h10
4 files changed, 72 insertions, 27 deletions
diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc
index d635fb4..f96889c 100644
--- a/webkit/glue/chrome_client_impl.cc
+++ b/webkit/glue/chrome_client_impl.cc
@@ -236,7 +236,32 @@ static inline bool CurrentEventShouldCauseBackgroundTab(
const WebMouseEvent* mouse_event =
static_cast<const WebMouseEvent*>(input_event);
- return (mouse_event->button == WebMouseEvent::ButtonMiddle);
+
+ WebNavigationPolicy policy;
+ unsigned short button_number;
+ switch (mouse_event->button) {
+ case WebMouseEvent::ButtonLeft:
+ button_number = 0;
+ break;
+ case WebMouseEvent::ButtonMiddle:
+ button_number = 1;
+ break;
+ case WebMouseEvent::ButtonRight:
+ button_number = 2;
+ break;
+ default:
+ return false;
+ }
+ bool ctrl = mouse_event->modifiers & WebMouseEvent::ControlKey;
+ bool shift = mouse_event->modifiers & WebMouseEvent::ShiftKey;
+ bool alt = mouse_event->modifiers & WebMouseEvent::AltKey;
+ bool meta = mouse_event->modifiers & WebMouseEvent::MetaKey;
+
+ if (!WebViewImpl::NavigationPolicyFromMouseEvent(button_number, ctrl,
+ shift, alt, meta, &policy))
+ return false;
+
+ return policy == WebKit::WebNavigationPolicyNewBackgroundTab;
}
void ChromeClientImpl::show() {
@@ -257,7 +282,8 @@ void ChromeClientImpl::show() {
WebNavigationPolicy policy = WebKit::WebNavigationPolicyNewForegroundTab;
if (as_popup)
policy = WebKit::WebNavigationPolicyNewPopup;
- if (CurrentEventShouldCauseBackgroundTab(WebViewImpl::current_input_event()))
+ if (CurrentEventShouldCauseBackgroundTab(
+ WebViewImpl::current_input_event()))
policy = WebKit::WebNavigationPolicyNewBackgroundTab;
delegate->show(policy);
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc
index b2c91b8..9ceda5b 100644
--- a/webkit/glue/webframeloaderclient_impl.cc
+++ b/webkit/glue/webframeloaderclient_impl.cc
@@ -1298,31 +1298,9 @@ bool WebFrameLoaderClient::ActionSpecifiesNavigationPolicy(
return false;
const MouseEvent* event = static_cast<const MouseEvent*>(action.event());
-#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD)
- const bool new_tab_modifier = (event->button() == 1) || event->ctrlKey();
-#elif defined(OS_MACOSX)
- const bool new_tab_modifier = (event->button() == 1) || event->metaKey();
-#endif
- const bool shift = event->shiftKey();
- const bool alt = event->altKey();
- if (!new_tab_modifier && !shift && !alt)
- return false;
-
- DCHECK(policy);
- if (new_tab_modifier) {
- if (shift) {
- *policy = WebKit::WebNavigationPolicyNewForegroundTab;
- } else {
- *policy = WebKit::WebNavigationPolicyNewBackgroundTab;
- }
- } else {
- if (shift) {
- *policy = WebKit::WebNavigationPolicyNewWindow;
- } else {
- *policy = WebKit::WebNavigationPolicyDownload;
- }
- }
- return true;
+ return WebViewImpl::NavigationPolicyFromMouseEvent(event->button(),
+ event->ctrlKey(), event->shiftKey(), event->altKey(), event->metaKey(),
+ policy);
}
void WebFrameLoaderClient::HandleBackForwardNavigation(const GURL& url) {
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc
index 86cca15..3572d57 100644
--- a/webkit/glue/webview_impl.cc
+++ b/webkit/glue/webview_impl.cc
@@ -105,6 +105,7 @@ using WebKit::WebInputEvent;
using WebKit::WebKeyboardEvent;
using WebKit::WebMouseEvent;
using WebKit::WebMouseWheelEvent;
+using WebKit::WebNavigationPolicy;
using WebKit::WebPoint;
using WebKit::WebRect;
using WebKit::WebSettings;
@@ -1791,6 +1792,36 @@ void WebViewImpl::DidCommitLoad(bool* is_new_navigation) {
observed_new_navigation_ = false;
}
+// static
+bool WebViewImpl::NavigationPolicyFromMouseEvent(unsigned short button,
+ bool ctrl, bool shift,
+ bool alt, bool meta,
+ WebNavigationPolicy* policy) {
+#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD)
+ const bool new_tab_modifier = (button == 1) || ctrl;
+#elif defined(OS_MACOSX)
+ const bool new_tab_modifier = (button == 1) || meta;
+#endif
+ if (!new_tab_modifier && !shift && !alt)
+ return false;
+
+ DCHECK(policy);
+ if (new_tab_modifier) {
+ if (shift) {
+ *policy = WebKit::WebNavigationPolicyNewForegroundTab;
+ } else {
+ *policy = WebKit::WebNavigationPolicyNewBackgroundTab;
+ }
+ } else {
+ if (shift) {
+ *policy = WebKit::WebNavigationPolicyNewWindow;
+ } else {
+ *policy = WebKit::WebNavigationPolicyDownload;
+ }
+ }
+ return true;
+}
+
void WebViewImpl::StartDragging(const WebPoint& event_pos,
const WebDragData& drag_data,
WebDragOperationsMask mask) {
diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h
index 0e999ec..bad4764 100644
--- a/webkit/glue/webview_impl.h
+++ b/webkit/glue/webview_impl.h
@@ -233,6 +233,16 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
return initial_navigation_policy_;
}
+ // Determines whether a page should e.g. be opened in a background tab.
+ // Returns false if it has no opinion, in which case it doesn't set *policy.
+ static bool NavigationPolicyFromMouseEvent(
+ unsigned short button,
+ bool ctrl,
+ bool shift,
+ bool alt,
+ bool meta,
+ WebKit::WebNavigationPolicy* policy);
+
// Start a system drag and drop operation.
void StartDragging(
const WebKit::WebPoint& event_pos,