summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authoryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-01 01:38:12 +0000
committeryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-01 01:38:12 +0000
commit5d5f7af66e100999851a743a1e15cd1641df72c6 (patch)
treeec926577892e9fc373881abc2fa89eb4af8fc22a /content
parent7075f0b9eb6fd3dd20f8900c4f05ae69f152a089 (diff)
downloadchromium_src-5d5f7af66e100999851a743a1e15cd1641df72c6.zip
chromium_src-5d5f7af66e100999851a743a1e15cd1641df72c6.tar.gz
chromium_src-5d5f7af66e100999851a743a1e15cd1641df72c6.tar.bz2
Only allow to lock the mouse when the tab is in fullscreen mode.
BUG=41781 TEST=Manual test in ppapi/examples/mouse_lock. Review URL: http://codereview.chromium.org/8072011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/render_view_host.cc7
-rw-r--r--content/browser/renderer_host/render_view_host.h35
-rw-r--r--content/browser/renderer_host/render_view_host_delegate.cc4
-rw-r--r--content/browser/renderer_host/render_view_host_delegate.h1
-rw-r--r--content/browser/renderer_host/render_widget_host.cc22
-rw-r--r--content/browser/renderer_host/render_widget_host.h6
-rw-r--r--content/browser/tab_contents/tab_contents.cc4
-rw-r--r--content/browser/tab_contents/tab_contents.h1
-rw-r--r--content/browser/tab_contents/tab_contents_delegate.cc4
-rw-r--r--content/browser/tab_contents/tab_contents_delegate.h1
10 files changed, 61 insertions, 24 deletions
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index e051c0f..431d87b 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -1131,6 +1131,11 @@ void RenderViewHost::NotifyRendererResponsive() {
delegate_->RendererResponsive(this);
}
+bool RenderViewHost::CanLockMouse() const {
+ // Only allow to lock the mouse when the current tab is in fullscreen mode.
+ return delegate_->IsFullscreenForCurrentTab();
+}
+
void RenderViewHost::OnMsgFocus() {
delegate_->Activate();
}
@@ -1223,6 +1228,8 @@ void RenderViewHost::SetAltErrorPageURL(const GURL& url) {
}
void RenderViewHost::ExitFullscreen() {
+ UnlockMouseIfNecessary();
+
Send(new ViewMsg_ExitFullscreen(routing_id()));
}
diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h
index 180f3ce..ef541c8 100644
--- a/content/browser/renderer_host/render_view_host.h
+++ b/content/browser/renderer_host/render_view_host.h
@@ -9,6 +9,7 @@
#include <string>
#include <vector>
+#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
@@ -325,14 +326,16 @@ class CONTENT_EXPORT RenderViewHost : public RenderWidgetHost {
}
// RenderWidgetHost public overrides.
- virtual void Shutdown();
- virtual bool IsRenderView() const;
- virtual bool OnMessageReceived(const IPC::Message& msg);
- virtual void GotFocus();
- virtual void LostCapture();
- virtual void ForwardMouseEvent(const WebKit::WebMouseEvent& mouse_event);
- virtual void OnMouseActivate();
- virtual void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event);
+ virtual void Shutdown() OVERRIDE;
+ virtual bool IsRenderView() const OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
+ virtual void GotFocus() OVERRIDE;
+ virtual void LostCapture() OVERRIDE;
+ virtual void ForwardMouseEvent(
+ const WebKit::WebMouseEvent& mouse_event) OVERRIDE;
+ virtual void OnMouseActivate() OVERRIDE;
+ virtual void ForwardKeyboardEvent(
+ const NativeWebKeyboardEvent& key_event) OVERRIDE;
// Creates a new RenderView with the given route id.
void CreateNewWindow(int route_id,
@@ -450,13 +453,15 @@ class CONTENT_EXPORT RenderViewHost : public RenderWidgetHost {
// RenderWidgetHost protected overrides.
virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
- bool* is_keyboard_shortcut);
- virtual void UnhandledKeyboardEvent(const NativeWebKeyboardEvent& event);
- virtual void OnUserGesture();
- virtual void NotifyRendererUnresponsive();
- virtual void NotifyRendererResponsive();
- virtual void OnMsgFocus();
- virtual void OnMsgBlur();
+ bool* is_keyboard_shortcut) OVERRIDE;
+ virtual void UnhandledKeyboardEvent(
+ const NativeWebKeyboardEvent& event) OVERRIDE;
+ virtual void OnUserGesture() OVERRIDE;
+ virtual void NotifyRendererUnresponsive() OVERRIDE;
+ virtual void NotifyRendererResponsive() OVERRIDE;
+ virtual bool CanLockMouse() const OVERRIDE;
+ virtual void OnMsgFocus() OVERRIDE;
+ virtual void OnMsgBlur() OVERRIDE;
// IPC message handlers.
void OnMsgShowView(int route_id,
diff --git a/content/browser/renderer_host/render_view_host_delegate.cc b/content/browser/renderer_host/render_view_host_delegate.cc
index be281c5..6cd4a0b 100644
--- a/content/browser/renderer_host/render_view_host_delegate.cc
+++ b/content/browser/renderer_host/render_view_host_delegate.cc
@@ -43,3 +43,7 @@ bool RenderViewHostDelegate::PreHandleKeyboardEvent(
const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
return false;
}
+
+bool RenderViewHostDelegate::IsFullscreenForCurrentTab() const {
+ return false;
+}
diff --git a/content/browser/renderer_host/render_view_host_delegate.h b/content/browser/renderer_host/render_view_host_delegate.h
index d807111..2fa528a 100644
--- a/content/browser/renderer_host/render_view_host_delegate.h
+++ b/content/browser/renderer_host/render_view_host_delegate.h
@@ -373,6 +373,7 @@ class CONTENT_EXPORT RenderViewHostDelegate : public IPC::Channel::Listener {
// Notification that the page wants to go into or out of fullscreen mode.
virtual void ToggleFullscreenMode(bool enter_fullscreen) {}
+ virtual bool IsFullscreenForCurrentTab() const;
// The contents' preferred size changed.
virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
diff --git a/content/browser/renderer_host/render_widget_host.cc b/content/browser/renderer_host/render_widget_host.cc
index b40f69c..37b72d8 100644
--- a/content/browser/renderer_host/render_widget_host.cc
+++ b/content/browser/renderer_host/render_widget_host.cc
@@ -378,8 +378,7 @@ void RenderWidgetHost::Focus() {
}
void RenderWidgetHost::Blur() {
- if (IsMouseLocked())
- view_->UnlockMouse();
+ UnlockMouseIfNecessary();
Send(new ViewMsg_SetFocus(routing_id_, false));
}
@@ -393,8 +392,7 @@ void RenderWidgetHost::LostMouseLock() {
}
void RenderWidgetHost::ViewDestroyed() {
- if (IsMouseLocked())
- view_->UnlockMouse();
+ UnlockMouseIfNecessary();
// TODO(evanm): tracking this may no longer be necessary;
// eliminate this function if so.
@@ -796,6 +794,15 @@ void RenderWidgetHost::ImeCancelComposition() {
std::vector<WebKit::WebCompositionUnderline>(), 0, 0));
}
+bool RenderWidgetHost::CanLockMouse() const {
+ return false;
+}
+
+void RenderWidgetHost::UnlockMouseIfNecessary() {
+ if (IsMouseLocked())
+ view_->UnlockMouse();
+}
+
bool RenderWidgetHost::IsMouseLocked() const {
return view_ ? view_->mouse_locked() : false;
}
@@ -1146,9 +1153,7 @@ void RenderWidgetHost::OnMsgDidActivateAcceleratedCompositing(bool activated) {
}
void RenderWidgetHost::OnMsgLockMouse() {
- // TODO(yzshen): Only allow to lock the mouse when in fullscreen mode, and
- // make sure that the mouse is unlocked when leaving fullscreen mode.
- if (!view_ || !view_->HasFocus() || !view_->LockMouse()) {
+ if (!CanLockMouse() || !view_ || !view_->HasFocus()|| !view_->LockMouse()) {
Send(new ViewMsg_LockMouse_ACK(routing_id_, false));
} else {
Send(new ViewMsg_LockMouse_ACK(routing_id_, true));
@@ -1156,8 +1161,7 @@ void RenderWidgetHost::OnMsgLockMouse() {
}
void RenderWidgetHost::OnMsgUnlockMouse() {
- if (IsMouseLocked())
- view_->UnlockMouse();
+ UnlockMouseIfNecessary();
}
#if defined(OS_POSIX)
diff --git a/content/browser/renderer_host/render_widget_host.h b/content/browser/renderer_host/render_widget_host.h
index 9b6a14c..894e551 100644
--- a/content/browser/renderer_host/render_widget_host.h
+++ b/content/browser/renderer_host/render_widget_host.h
@@ -468,6 +468,12 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener,
virtual void NotifyRendererUnresponsive() {}
virtual void NotifyRendererResponsive() {}
+ // RenderViewHost overrides this method to impose further restrictions on when
+ // to allow mouse lock. For now, it only allows to lock the mouse when the
+ // current tab is in fullscreen mode.
+ virtual bool CanLockMouse() const;
+
+ void UnlockMouseIfNecessary();
bool IsMouseLocked() const;
protected:
diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc
index 74bc332..548f6df 100644
--- a/content/browser/tab_contents/tab_contents.cc
+++ b/content/browser/tab_contents/tab_contents.cc
@@ -512,6 +512,10 @@ void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
}
+bool TabContents::IsFullscreenForCurrentTab() const {
+ return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
+}
+
void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
if (delegate_)
delegate_->UpdatePreferredSize(this, pref_size);
diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h
index 635f7e0..7ecd21cf 100644
--- a/content/browser/tab_contents/tab_contents.h
+++ b/content/browser/tab_contents/tab_contents.h
@@ -698,6 +698,7 @@ class CONTENT_EXPORT TabContents : public PageNavigator,
virtual void RunFileChooser(RenderViewHost* render_view_host,
const ViewHostMsg_RunFileChooser_Params& params);
virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
+ virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
// RenderViewHostManager::Delegate -------------------------------------------
diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc
index 07a5fc5..dec1c13 100644
--- a/content/browser/tab_contents/tab_contents_delegate.cc
+++ b/content/browser/tab_contents/tab_contents_delegate.cc
@@ -283,6 +283,10 @@ void TabContentsDelegate::ToggleFullscreenModeForTab(TabContents* tab,
bool enter_fullscreen) {
}
+bool TabContentsDelegate::IsFullscreenForTab(const TabContents* tab) const {
+ return false;
+}
+
void TabContentsDelegate::JSOutOfMemory(TabContents* tab) {
}
diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h
index 3a0cdad..d1bb423 100644
--- a/content/browser/tab_contents/tab_contents_delegate.h
+++ b/content/browser/tab_contents/tab_contents_delegate.h
@@ -307,6 +307,7 @@ class CONTENT_EXPORT TabContentsDelegate {
// Called when the renderer puts a tab into or out of fullscreen mode.
virtual void ToggleFullscreenModeForTab(TabContents* tab,
bool enter_fullscreen);
+ virtual bool IsFullscreenForTab(const TabContents* tab) const;
// Called when a Javascript out of memory notification is received.
virtual void JSOutOfMemory(TabContents* tab);