Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Unified Diff: views/controls/native/native_view_host_win.cc

Issue 214029: Adding focus to NaviteViewHost. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/controls/native/native_view_host_win.h ('k') | views/controls/native/native_view_host_wrapper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/native/native_view_host_win.cc
===================================================================
--- views/controls/native/native_view_host_win.cc (revision 27081)
+++ views/controls/native/native_view_host_win.cc (working copy)
@@ -6,10 +6,13 @@
#include "app/gfx/canvas.h"
#include "base/logging.h"
+#include "base/win_util.h"
#include "views/controls/native/native_view_host.h"
#include "views/focus/focus_manager.h"
#include "views/widget/widget.h"
+const wchar_t* kNativeViewHostWinKey = L"__NATIVE_VIEW_HOST_WIN__";
+
namespace views {
////////////////////////////////////////////////////////////////////////////////
@@ -17,7 +20,8 @@
NativeViewHostWin::NativeViewHostWin(NativeViewHost* host)
: host_(host),
- installed_clip_(false) {
+ installed_clip_(false),
+ original_wndproc_(NULL) {
}
NativeViewHostWin::~NativeViewHostWin() {
@@ -37,10 +41,32 @@
// Need to set the HWND's parent before changing its size to avoid flashing.
SetParent(host_->native_view(), host_->GetWidget()->GetNativeView());
host_->Layout();
+
+ // Subclass the appropriate HWND to get focus notifications.
+ HWND focus_hwnd = host_->focus_native_view();
+ DCHECK(focus_hwnd == host_->native_view() ||
+ ::IsChild(host_->native_view(), focus_hwnd));
+ original_wndproc_ =
+ win_util::SetWindowProc(focus_hwnd,
+ &NativeViewHostWin::NativeViewHostWndProc);
+
+ // We use a property to retrieve the NativeViewHostWin from the window
+ // procedure.
+ ::SetProp(focus_hwnd, kNativeViewHostWinKey, this);
}
void NativeViewHostWin::NativeViewDetaching() {
installed_clip_ = false;
+
+ // Restore the original Windows procedure.
+ DCHECK(original_wndproc_);
+ WNDPROC wndproc = win_util::SetWindowProc(host_->focus_native_view(),
+ original_wndproc_);
+ DCHECK(wndproc == &NativeViewHostWin::NativeViewHostWndProc);
+
+ // Also remove the property, it's not needed anymore.
+ HANDLE h = ::RemoveProp(host_->focus_native_view(), kNativeViewHostWinKey);
+ DCHECK(h == this);
}
void NativeViewHostWin::AddedToWidget() {
@@ -116,8 +142,22 @@
SWP_NOREDRAW | SWP_NOOWNERZORDER);
}
-void NativeViewHostWin::SetFocus() {
- ::SetFocus(host_->native_view());
+// static
+LRESULT CALLBACK NativeViewHostWin::NativeViewHostWndProc(HWND window,
+ UINT message,
+ WPARAM w_param,
+ LPARAM l_param) {
+ NativeViewHostWin* native_view_host =
+ static_cast<NativeViewHostWin*>(::GetProp(window, kNativeViewHostWinKey));
+ DCHECK(native_view_host);
+
+ if (message == WM_SETFOCUS)
+ native_view_host->host_->GotNativeFocus();
+ if (message == WM_DESTROY)
+ native_view_host->host_->Detach();
+
+ return CallWindowProc(native_view_host->original_wndproc_,
+ window, message, w_param, l_param);
}
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « views/controls/native/native_view_host_win.h ('k') | views/controls/native/native_view_host_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698