summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/plugin_process_host.cc2
-rw-r--r--chrome/browser/plugin_process_host.h1
-rw-r--r--chrome/browser/plugin_process_host_mac.cc13
-rw-r--r--chrome/common/plugin_messages_internal.h19
-rw-r--r--chrome/plugin/plugin_thread.cc19
-rw-r--r--chrome/plugin/webplugin_delegate_stub.cc26
-rw-r--r--chrome/plugin/webplugin_delegate_stub.h3
-rw-r--r--chrome/renderer/render_view.cc10
-rw-r--r--chrome/renderer/webplugin_delegate_pepper.cc5
-rw-r--r--chrome/renderer/webplugin_delegate_pepper.h2
-rw-r--r--chrome/renderer/webplugin_delegate_proxy.cc15
-rw-r--r--chrome/renderer/webplugin_delegate_proxy.h10
-rw-r--r--webkit/glue/plugins/webplugin_delegate.h4
-rw-r--r--webkit/glue/plugins/webplugin_delegate_impl.h29
-rw-r--r--webkit/glue/plugins/webplugin_delegate_impl_gtk.cc4
-rw-r--r--webkit/glue/plugins/webplugin_delegate_impl_mac.mm118
-rw-r--r--webkit/glue/plugins/webplugin_delegate_impl_win.cc4
-rw-r--r--webkit/glue/plugins/webplugin_impl.cc4
18 files changed, 115 insertions, 173 deletions
diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc
index a7aadaa..f64ca33 100644
--- a/chrome/browser/plugin_process_host.cc
+++ b/chrome/browser/plugin_process_host.cc
@@ -498,8 +498,6 @@ void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) {
OnPluginShowWindow)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginHideWindow,
OnPluginHideWindow)
- IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginReceivedFocus,
- OnPluginReceivedFocus)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSetCursorVisibility,
OnPluginSetCursorVisibility)
#endif
diff --git a/chrome/browser/plugin_process_host.h b/chrome/browser/plugin_process_host.h
index e05ea2a..3f7e661 100644
--- a/chrome/browser/plugin_process_host.h
+++ b/chrome/browser/plugin_process_host.h
@@ -131,7 +131,6 @@ class PluginProcessHost : public ChildProcessHost,
void OnPluginShowWindow(uint32 window_id, gfx::Rect window_rect,
bool modal);
void OnPluginHideWindow(uint32 window_id, gfx::Rect window_rect);
- void OnPluginReceivedFocus(int process_id, int instance_id);
void OnPluginSetCursorVisibility(bool visible);
#endif
diff --git a/chrome/browser/plugin_process_host_mac.cc b/chrome/browser/plugin_process_host_mac.cc
index 86bfe9f..716ab81 100644
--- a/chrome/browser/plugin_process_host_mac.cc
+++ b/chrome/browser/plugin_process_host_mac.cc
@@ -100,19 +100,6 @@ void PluginProcessHost::OnAppActivation() {
}
}
-void PluginProcessHost::OnPluginReceivedFocus(int process_id, int instance_id) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- // A plugin has received keyboard focus, so tell all other plugin processes
- // that they no longer have it (simulating the OS-level focus notifications
- // that Gtk and Windows provide).
- for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
- !iter.Done(); ++iter) {
- PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
- int instance = (plugin->handle() == process_id) ? instance_id : 0;
- plugin->Send(new PluginProcessMsg_PluginFocusNotify(instance));
- }
-}
-
void PluginProcessHost::OnPluginSetCursorVisibility(bool visible) {
if (plugin_cursor_visible_ != visible) {
plugin_cursor_visible_ = visible;
diff --git a/chrome/common/plugin_messages_internal.h b/chrome/common/plugin_messages_internal.h
index 87a7e48..29388a4 100644
--- a/chrome/common/plugin_messages_internal.h
+++ b/chrome/common/plugin_messages_internal.h
@@ -51,14 +51,6 @@ IPC_BEGIN_MESSAGES(PluginProcess)
bool /* on or off */)
#endif
-#if defined(OS_MACOSX)
- // Notifies a plugin process that keyboard focus has changed. If another
- // plugin instance has received focus, the instance IDs is passed as a
- // parameter; if focus has been taken away from a plugin, 0 is passed.
- IPC_MESSAGE_CONTROL1(PluginProcessMsg_PluginFocusNotify,
- uint32 /* instance ID */)
-#endif
-
IPC_END_MESSAGES(PluginProcess)
@@ -159,11 +151,6 @@ IPC_BEGIN_MESSAGES(PluginProcessHost)
uint32 /* window ID */,
gfx::Rect /* window rect */)
- // Notifies the browser that a plugin instance has received keyboard focus.
- IPC_MESSAGE_CONTROL2(PluginProcessHostMsg_PluginReceivedFocus,
- uint32 /* process ID */,
- uint32 /* instance ID */)
-
// Notifies the browser that a plugin instance has requested a cursor
// visibility change.
IPC_MESSAGE_CONTROL1(PluginProcessHostMsg_PluginSetCursorVisibility,
@@ -226,7 +213,8 @@ IPC_BEGIN_MESSAGES(Plugin)
IPC_SYNC_MESSAGE_ROUTED1_0(PluginMsg_UpdateGeometrySync,
PluginMsg_UpdateGeometry_Param)
- IPC_SYNC_MESSAGE_ROUTED0_0(PluginMsg_SetFocus)
+ IPC_SYNC_MESSAGE_ROUTED1_0(PluginMsg_SetFocus,
+ bool /* focused */)
IPC_SYNC_MESSAGE_ROUTED1_2(PluginMsg_HandleInputEvent,
IPC::WebInputEventPointer /* event */,
@@ -237,6 +225,9 @@ IPC_BEGIN_MESSAGES(Plugin)
IPC_MESSAGE_ROUTED1(PluginMsg_SetWindowFocus,
bool /* has_focus */)
+ IPC_MESSAGE_ROUTED1(PluginMsg_SetContentAreaFocus,
+ bool /* has_focus */)
+
IPC_MESSAGE_ROUTED0(PluginMsg_ContainerHidden)
IPC_MESSAGE_ROUTED3(PluginMsg_ContainerShown,
diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc
index fb24e3f..e74e95e 100644
--- a/chrome/plugin/plugin_thread.cc
+++ b/chrome/plugin/plugin_thread.cc
@@ -135,10 +135,6 @@ void PluginThread::OnControlMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage)
IPC_MESSAGE_HANDLER(PluginProcessMsg_NotifyRenderersOfPendingShutdown,
OnNotifyRenderersOfPendingShutdown)
-#if defined(OS_MACOSX)
- IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginFocusNotify,
- OnPluginFocusNotify)
-#endif
IPC_END_MESSAGE_MAP()
}
@@ -177,21 +173,6 @@ void PluginThread::OnNotifyRenderersOfPendingShutdown() {
PluginChannel::NotifyRenderersOfPendingShutdown();
}
-#if defined(OS_MACOSX)
-void PluginThread::OnPluginFocusNotify(uint32 instance_id) {
- WebPluginDelegateImpl* focused_instance =
- reinterpret_cast<WebPluginDelegateImpl*>(instance_id);
- std::set<WebPluginDelegateImpl*> active_delegates =
- WebPluginDelegateImpl::GetActiveDelegates();
- for (std::set<WebPluginDelegateImpl*>::iterator iter =
- active_delegates.begin();
- iter != active_delegates.end(); iter++) {
- WebPluginDelegateImpl* instance = *iter;
- instance->FocusChanged(instance == focused_instance);
- }
-}
-#endif
-
namespace webkit_glue {
#if defined(OS_WIN)
diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc
index 104c8b9..c0de5d2 100644
--- a/chrome/plugin/webplugin_delegate_stub.cc
+++ b/chrome/plugin/webplugin_delegate_stub.cc
@@ -46,22 +46,6 @@ class FinishDestructionTask : public Task {
WebPlugin* webplugin_;
};
-#if defined(OS_MACOSX)
-namespace {
-
-void FocusNotifier(WebPluginDelegateImpl *instance) {
- uint32 process_id = getpid();
- uint32 instance_id = reinterpret_cast<uint32>(instance);
- PluginThread* plugin_thread = PluginThread::current();
- if (plugin_thread) {
- plugin_thread->Send(
- new PluginProcessHostMsg_PluginReceivedFocus(process_id, instance_id));
- }
-}
-
-}
-#endif
-
WebPluginDelegateStub::WebPluginDelegateStub(
const std::string& mime_type, int instance_id, PluginChannel* channel) :
mime_type_(mime_type),
@@ -123,6 +107,7 @@ void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) {
OnSendJavaScriptStream)
#if defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(PluginMsg_SetWindowFocus, OnSetWindowFocus)
+ IPC_MESSAGE_HANDLER(PluginMsg_SetContentAreaFocus, OnSetContentAreaFocus)
IPC_MESSAGE_HANDLER(PluginMsg_ContainerHidden, OnContainerHidden)
IPC_MESSAGE_HANDLER(PluginMsg_ContainerShown, OnContainerShown)
IPC_MESSAGE_HANDLER(PluginMsg_WindowFrameChanged, OnWindowFrameChanged)
@@ -197,7 +182,6 @@ void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params,
webplugin_,
params.load_manually);
#if defined(OS_MACOSX)
- delegate_->SetFocusNotifier(FocusNotifier);
delegate_->WindowFrameChanged(params.containing_window_frame,
params.containing_content_frame);
delegate_->SetWindowHasFocus(params.containing_window_has_focus);
@@ -258,8 +242,8 @@ void WebPluginDelegateStub::OnDidFinishLoadWithReason(
delegate_->DidFinishLoadWithReason(url, reason, notify_id);
}
-void WebPluginDelegateStub::OnSetFocus() {
- delegate_->SetFocus();
+void WebPluginDelegateStub::OnSetFocus(bool focused) {
+ delegate_->SetFocus(focused);
}
void WebPluginDelegateStub::OnHandleInputEvent(
@@ -352,6 +336,10 @@ void WebPluginDelegateStub::OnSetWindowFocus(bool has_focus) {
delegate_->SetWindowHasFocus(has_focus);
}
+void WebPluginDelegateStub::OnSetContentAreaFocus(bool has_focus) {
+ delegate_->SetContentAreaHasFocus(has_focus);
+}
+
void WebPluginDelegateStub::OnContainerHidden() {
delegate_->SetContainerVisibility(false);
}
diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h
index 5a7be5d..9c9d0b4 100644
--- a/chrome/plugin/webplugin_delegate_stub.h
+++ b/chrome/plugin/webplugin_delegate_stub.h
@@ -65,7 +65,7 @@ class WebPluginDelegateStub : public IPC::Channel::Listener,
void OnDidFinishLoading(int id);
void OnDidFail(int id);
void OnDidFinishLoadWithReason(const GURL& url, int reason, int notify_id);
- void OnSetFocus();
+ void OnSetFocus(bool focused);
void OnHandleInputEvent(const WebKit::WebInputEvent* event,
bool* handled, WebCursor* cursor);
void OnPaint(const gfx::Rect& damaged_rect);
@@ -80,6 +80,7 @@ class WebPluginDelegateStub : public IPC::Channel::Listener,
#if defined(OS_MACOSX)
void OnSetWindowFocus(bool has_focus);
+ void OnSetContentAreaFocus(bool has_focus);
void OnContainerHidden();
void OnContainerShown(gfx::Rect window_frame, gfx::Rect view_frame,
bool has_focus);
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index da1bea90..d3c1744 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -4801,13 +4801,15 @@ void RenderView::OnWasRestored(bool needs_repainting) {
void RenderView::OnSetFocus(bool enable) {
RenderWidget::OnSetFocus(enable);
- // RenderWidget's call to setFocus can cause the underlying webview's
- // activation state to change just like a call to setIsActive.
- if (enable && webview() && webview()->isActive()) {
+ if (webview() && webview()->isActive()) {
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
- (*plugin_it)->SetWindowFocus(true);
+ // RenderWidget's call to setFocus can cause the underlying webview's
+ // activation state to change just like a call to setIsActive.
+ if (enable)
+ (*plugin_it)->SetWindowFocus(true);
+ (*plugin_it)->SetContentAreaFocus(enable);
}
}
}
diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc
index 753844d..44b76fe 100644
--- a/chrome/renderer/webplugin_delegate_pepper.cc
+++ b/chrome/renderer/webplugin_delegate_pepper.cc
@@ -1375,7 +1375,10 @@ void WebPluginDelegatePepper::InstallMissingPlugin() {
NOTIMPLEMENTED();
}
-void WebPluginDelegatePepper::SetFocus() {
+void WebPluginDelegatePepper::SetFocus(bool focused) {
+ if (!focused)
+ return;
+
NPPepperEvent npevent;
npevent.type = NPEventType_Focus;
diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h
index 70a113a..9ca3858 100644
--- a/chrome/renderer/webplugin_delegate_pepper.h
+++ b/chrome/renderer/webplugin_delegate_pepper.h
@@ -56,7 +56,7 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate,
const gfx::Rect& clip_rect);
virtual void Paint(WebKit::WebCanvas* canvas, const gfx::Rect& rect);
virtual void Print(gfx::NativeDrawingContext context);
- virtual void SetFocus();
+ virtual void SetFocus(bool focused);
virtual bool HandleInputEvent(const WebKit::WebInputEvent& event,
WebKit::WebCursorInfo* cursor);
virtual NPObject* GetPluginScriptableObject();
diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc
index 5ff3e68..2a54c6d 100644
--- a/chrome/renderer/webplugin_delegate_proxy.cc
+++ b/chrome/renderer/webplugin_delegate_proxy.cc
@@ -939,8 +939,8 @@ void WebPluginDelegateProxy::DidFinishLoadWithReason(
instance_id_, url, reason, notify_id));
}
-void WebPluginDelegateProxy::SetFocus() {
- Send(new PluginMsg_SetFocus(instance_id_));
+void WebPluginDelegateProxy::SetFocus(bool focused) {
+ Send(new PluginMsg_SetFocus(instance_id_, focused));
}
bool WebPluginDelegateProxy::HandleInputEvent(
@@ -968,7 +968,16 @@ int WebPluginDelegateProxy::GetProcessId() {
void WebPluginDelegateProxy::SetWindowFocus(bool window_has_focus) {
IPC::Message* msg = new PluginMsg_SetWindowFocus(instance_id_,
window_has_focus);
- // Make sure visibility events are delivered in the right order relative to
+ // Make sure focus events are delivered in the right order relative to
+ // sync messages they might interact with (Paint, HandleEvent, etc.).
+ msg->set_unblock(true);
+ Send(msg);
+}
+
+void WebPluginDelegateProxy::SetContentAreaFocus(bool has_focus) {
+ IPC::Message* msg = new PluginMsg_SetContentAreaFocus(instance_id_,
+ has_focus);
+ // Make sure focus events are delivered in the right order relative to
// sync messages they might interact with (Paint, HandleEvent, etc.).
msg->set_unblock(true);
Send(msg);
diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h
index 6d7b731..b12183b 100644
--- a/chrome/renderer/webplugin_delegate_proxy.h
+++ b/chrome/renderer/webplugin_delegate_proxy.h
@@ -66,16 +66,20 @@ class WebPluginDelegateProxy
virtual NPObject* GetPluginScriptableObject();
virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason,
int notify_id);
- virtual void SetFocus();
+ virtual void SetFocus(bool focused);
virtual bool HandleInputEvent(const WebKit::WebInputEvent& event,
WebKit::WebCursorInfo* cursor);
virtual int GetProcessId();
#if defined(OS_MACOSX)
+ // Informs the plugin that its enclosing window has gained or lost focus.
virtual void SetWindowFocus(bool window_has_focus);
- // Inform the plugin that its container (window/tab) has changed visibility.
+ // Informs the plugin that its containing content view has gained or lost
+ // first responder status.
+ virtual void SetContentAreaFocus(bool has_focus);
+ // Informs the plugin that its container (window/tab) has changed visibility.
virtual void SetContainerVisibility(bool is_visible);
- // Inform the plugin that its enclosing window's frame has changed.
+ // Informs the plugin that its enclosing window's frame has changed.
virtual void WindowFrameChanged(gfx::Rect window_frame, gfx::Rect view_frame);
#endif
diff --git a/webkit/glue/plugins/webplugin_delegate.h b/webkit/glue/plugins/webplugin_delegate.h
index 0b08c9e..6b15839 100644
--- a/webkit/glue/plugins/webplugin_delegate.h
+++ b/webkit/glue/plugins/webplugin_delegate.h
@@ -83,9 +83,9 @@ class WebPluginDelegate : public WebPlugin2DDeviceDelegate,
// Tells the plugin to print itself.
virtual void Print(gfx::NativeDrawingContext hdc) = 0;
- // Informs the plugin that it now has focus. This is only called in
+ // Informs the plugin that it has gained or lost focus. This is only called in
// windowless mode.
- virtual void SetFocus() = 0;
+ virtual void SetFocus(bool focused) = 0;
// For windowless plugins, gives them a user event like mouse/keyboard.
// Returns whether the event was handled. This is only called in windowsless
diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h
index 2fef88b..0d113ca 100644
--- a/webkit/glue/plugins/webplugin_delegate_impl.h
+++ b/webkit/glue/plugins/webplugin_delegate_impl.h
@@ -97,7 +97,7 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate {
const gfx::Rect& clip_rect);
virtual void Paint(WebKit::WebCanvas* canvas, const gfx::Rect& rect);
virtual void Print(gfx::NativeDrawingContext context);
- virtual void SetFocus();
+ virtual void SetFocus(bool focused);
virtual bool HandleInputEvent(const WebKit::WebInputEvent& event,
WebKit::WebCursorInfo* cursor_info);
virtual NPObject* GetPluginScriptableObject();
@@ -141,19 +141,11 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate {
gfx::NativeDrawingContext context);
// Returns the delegate currently processing events.
static WebPluginDelegateImpl* GetActiveDelegate();
- // Returns a vector of currently active delegates in this process.
- static std::set<WebPluginDelegateImpl*> GetActiveDelegates();
- // Informs the delegate that it has gained or lost focus.
- void FocusChanged(bool has_focus);
- // Set a notifier function that gets called when the delegate is accepting
- // the focus. If no notifier function has been set, the delegate will just
- // call FocusChanged(true). This is used in a multiprocess environment to
- // propagate focus notifications to all running plugin processes.
- void SetFocusNotifier(void (*notifier)(WebPluginDelegateImpl*)) {
- focus_notifier_ = notifier;
- }
// Informs the plugin that the window it is in has gained or lost focus.
void SetWindowHasFocus(bool has_focus);
+ // Informs the plugin that the view it is in has gained or lost first
+ // responder status.
+ void SetContentAreaHasFocus(bool has_focus);
// Returns whether or not the window the plugin is in has focus.
bool GetWindowHasFocus() const { return containing_window_has_focus_; }
// Informs the plugin that its tab or window has been hidden or shown.
@@ -369,6 +361,10 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate {
// Updates everything that depends on the plugin's absolute screen location.
void PluginScreenLocationChanged();
+ // Informs the plugin that it has gained or lost keyboard focus (i.e., window
+ // first responder status).
+ void SetPluginHasFocus(bool has_focus);
+
// Returns the apparent zoom ratio for the given event, as inferred from our
// current knowledge about about where on screen the plugin is.
// This is a temporary workaround for <http://crbug.com/9996>; once that is
@@ -424,9 +420,12 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate {
gfx::Point content_area_origin_;
// True if the plugin thinks it has keyboard focus
- bool have_focus_;
- // A function to call when we want to accept keyboard focus
- void (*focus_notifier_)(WebPluginDelegateImpl* notifier);
+ bool plugin_has_focus_;
+ // True if the plugin element has focus within the page, regardless of whether
+ // its containing view is currently the first responder for the window.
+ bool has_webkit_focus_;
+ // True if the containing view is the window's first responder.
+ bool containing_view_has_focus_;
bool containing_window_has_focus_;
bool initial_window_focus_;
diff --git a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc
index bf8b141..e9830b4 100644
--- a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc
+++ b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc
@@ -480,8 +480,10 @@ void WebPluginDelegateImpl::WindowlessSetWindow() {
}
}
-void WebPluginDelegateImpl::SetFocus() {
+void WebPluginDelegateImpl::SetFocus(bool focused) {
DCHECK(instance()->windowless());
+ if (!focused)
+ return;
NPEvent np_event = {0};
XFocusChangeEvent &event = np_event.xfocus;
diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm
index 3d5f71a..ee40ceb 100644
--- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm
+++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm
@@ -53,9 +53,6 @@ const int kCoreAnimationRedrawPeriodMs = 20; // 50fps
namespace {
-base::LazyInstance<std::set<WebPluginDelegateImpl*> > g_active_delegates(
- base::LINKER_INITIALIZED);
-
WebPluginDelegateImpl* g_active_delegate;
// Helper to simplify correct usage of g_active_delegate. Instantiating will
@@ -262,8 +259,9 @@ WebPluginDelegateImpl::WebPluginDelegateImpl(
layer_(nil),
surface_(NULL),
renderer_(nil),
- have_focus_(false),
- focus_notifier_(NULL),
+ plugin_has_focus_(false),
+ has_webkit_focus_(false),
+ containing_view_has_focus_(false),
containing_window_has_focus_(false),
initial_window_focus_(false),
container_is_visible_(false),
@@ -278,15 +276,9 @@ WebPluginDelegateImpl::WebPluginDelegateImpl(
memset(&qd_port_, 0, sizeof(qd_port_));
#endif
instance->set_windowless(true);
-
- std::set<WebPluginDelegateImpl*>* delegates = g_active_delegates.Pointer();
- delegates->insert(this);
}
WebPluginDelegateImpl::~WebPluginDelegateImpl() {
- std::set<WebPluginDelegateImpl*>* delegates = g_active_delegates.Pointer();
- delegates->erase(this);
-
DestroyInstance();
#ifndef NP_NO_CARBON
@@ -476,11 +468,13 @@ void WebPluginDelegateImpl::Print(CGContextRef context) {
NOTIMPLEMENTED();
}
-void WebPluginDelegateImpl::SetFocus() {
- if (focus_notifier_)
- focus_notifier_(this);
- else
- FocusChanged(true);
+void WebPluginDelegateImpl::SetFocus(bool focused) {
+ // This is called when internal WebKit focus (the focused element on the page)
+ // changes, but plugins need to know about actual first responder status, so
+ // we have an extra layer of focus tracking.
+ has_webkit_focus_ = focused;
+ if (containing_view_has_focus_)
+ SetPluginHasFocus(focused);
}
bool WebPluginDelegateImpl::PlatformHandleInputEvent(
@@ -559,17 +553,6 @@ bool WebPluginDelegateImpl::PlatformHandleInputEvent(
}
#endif
- // if we do not currently have focus and this is a mouseDown, trigger a
- // notification that we are taking the keyboard focus. We can't just key
- // off of incoming calls to SetFocus, since WebKit may already think we
- // have it if we were the most recently focused element on our parent tab.
- if (event.type == WebInputEvent::MouseDown && !have_focus_) {
- SetFocus();
- // Make sure that the plugin is still there after handling the focus event.
- if (!instance())
- return false;
- }
-
ScopedActiveDelegate active_delegate(this);
// Create the plugin event structure.
@@ -812,29 +795,34 @@ WebPluginDelegateImpl* WebPluginDelegateImpl::GetActiveDelegate() {
return g_active_delegate;
}
-std::set<WebPluginDelegateImpl*> WebPluginDelegateImpl::GetActiveDelegates() {
- std::set<WebPluginDelegateImpl*>* delegates = g_active_delegates.Pointer();
- return *delegates;
-}
-
-void WebPluginDelegateImpl::FocusChanged(bool has_focus) {
- if (!have_called_set_window_)
+void WebPluginDelegateImpl::SetWindowHasFocus(bool has_focus) {
+ // If we get a window focus event before calling SetWindow, just remember the
+ // states (WindowlessSetWindow will then send it on the first call).
+ if (!have_called_set_window_) {
+ initial_window_focus_ = has_focus;
return;
+ }
- if (has_focus == have_focus_)
+ if (has_focus == containing_window_has_focus_)
return;
- have_focus_ = has_focus;
+ containing_window_has_focus_ = has_focus;
- ScopedActiveDelegate active_delegate(this);
+#ifndef NP_NO_QUICKDRAW
+ // Make sure controls repaint with the correct look.
+ if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH)
+ SetQuickDrawFastPathEnabled(false);
+#endif
+ ScopedActiveDelegate active_delegate(this);
switch (instance()->event_model()) {
#ifndef NP_NO_CARBON
case NPEventModelCarbon: {
NPEvent focus_event = { 0 };
- if (have_focus_)
- focus_event.what = NPEventType_GetFocusEvent;
- else
- focus_event.what = NPEventType_LoseFocusEvent;
+ focus_event.what = activateEvt;
+ if (has_focus)
+ focus_event.modifiers |= activeFlag;
+ focus_event.message =
+ reinterpret_cast<unsigned long>(np_cg_context_.window);
focus_event.when = TickCount();
instance()->NPP_HandleEvent(&focus_event);
break;
@@ -843,42 +831,32 @@ void WebPluginDelegateImpl::FocusChanged(bool has_focus) {
case NPEventModelCocoa: {
NPCocoaEvent focus_event;
memset(&focus_event, 0, sizeof(focus_event));
- focus_event.type = NPCocoaEventFocusChanged;
- focus_event.data.focus.hasFocus = have_focus_;
+ focus_event.type = NPCocoaEventWindowFocusChanged;
+ focus_event.data.focus.hasFocus = has_focus;
instance()->NPP_HandleEvent(&focus_event);
break;
}
}
}
-void WebPluginDelegateImpl::SetWindowHasFocus(bool has_focus) {
- // If we get a window focus event before calling SetWindow, just remember the
- // states (WindowlessSetWindow will then send it on the first call).
- if (!have_called_set_window_) {
- initial_window_focus_ = has_focus;
+void WebPluginDelegateImpl::SetPluginHasFocus(bool has_focus) {
+ if (!have_called_set_window_)
return;
- }
- if (has_focus == containing_window_has_focus_)
+ if (has_focus == plugin_has_focus_)
return;
- containing_window_has_focus_ = has_focus;
-
-#ifndef NP_NO_QUICKDRAW
- // Make sure controls repaint with the correct look.
- if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH)
- SetQuickDrawFastPathEnabled(false);
-#endif
+ plugin_has_focus_ = has_focus;
ScopedActiveDelegate active_delegate(this);
+
switch (instance()->event_model()) {
#ifndef NP_NO_CARBON
case NPEventModelCarbon: {
NPEvent focus_event = { 0 };
- focus_event.what = activateEvt;
- if (has_focus)
- focus_event.modifiers |= activeFlag;
- focus_event.message =
- reinterpret_cast<unsigned long>(np_cg_context_.window);
+ if (plugin_has_focus_)
+ focus_event.what = NPEventType_GetFocusEvent;
+ else
+ focus_event.what = NPEventType_LoseFocusEvent;
focus_event.when = TickCount();
instance()->NPP_HandleEvent(&focus_event);
break;
@@ -887,14 +865,19 @@ void WebPluginDelegateImpl::SetWindowHasFocus(bool has_focus) {
case NPEventModelCocoa: {
NPCocoaEvent focus_event;
memset(&focus_event, 0, sizeof(focus_event));
- focus_event.type = NPCocoaEventWindowFocusChanged;
- focus_event.data.focus.hasFocus = has_focus;
+ focus_event.type = NPCocoaEventFocusChanged;
+ focus_event.data.focus.hasFocus = plugin_has_focus_;
instance()->NPP_HandleEvent(&focus_event);
break;
}
}
}
+void WebPluginDelegateImpl::SetContentAreaHasFocus(bool has_focus) {
+ containing_view_has_focus_ = has_focus;
+ SetPluginHasFocus(containing_view_has_focus_ && has_webkit_focus_);
+}
+
void WebPluginDelegateImpl::SetContainerVisibility(bool is_visible) {
if (is_visible == container_is_visible_)
return;
@@ -910,13 +893,6 @@ void WebPluginDelegateImpl::SetContainerVisibility(bool is_visible) {
clip_rect_.set_height(0);
}
- // TODO(stuartmorgan): We may need to remember whether we had focus, and
- // restore it ourselves when we become visible again. Revisit once SetFocus
- // is actually being called in all the cases it should be, at which point
- // we'll know whether or not that's handled for us by WebKit.
- if (!is_visible)
- FocusChanged(false);
-
// If the plugin is changing visibility, let the plugin know. If it's scrolled
// off screen (i.e., cached_clip_rect_ is empty), then container visibility
// doesn't change anything.
diff --git a/webkit/glue/plugins/webplugin_delegate_impl_win.cc b/webkit/glue/plugins/webplugin_delegate_impl_win.cc
index ed8203a..b8af405 100644
--- a/webkit/glue/plugins/webplugin_delegate_impl_win.cc
+++ b/webkit/glue/plugins/webplugin_delegate_impl_win.cc
@@ -1031,8 +1031,10 @@ void WebPluginDelegateImpl::WindowlessSetWindow() {
DCHECK(err == NPERR_NO_ERROR);
}
-void WebPluginDelegateImpl::SetFocus() {
+void WebPluginDelegateImpl::SetFocus(bool focused) {
DCHECK(instance()->windowless());
+ if (!focused)
+ return;
NPEvent focus_event;
focus_event.event = WM_SETFOCUS;
diff --git a/webkit/glue/plugins/webplugin_impl.cc b/webkit/glue/plugins/webplugin_impl.cc
index 30c2fa3..9ee98ed 100644
--- a/webkit/glue/plugins/webplugin_impl.cc
+++ b/webkit/glue/plugins/webplugin_impl.cc
@@ -298,8 +298,8 @@ void WebPluginImpl::updateGeometry(
}
void WebPluginImpl::updateFocus(bool focused) {
- if (focused && accepts_input_events_)
- delegate_->SetFocus();
+ if (accepts_input_events_)
+ delegate_->SetFocus(focused);
}
void WebPluginImpl::updateVisibility(bool visible) {