summaryrefslogtreecommitdiffstats
path: root/views/controls/native/native_view_host.cc
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 23:15:10 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 23:15:10 +0000
commit0aaec000440c2453f20265a7b580efc4ad10b282 (patch)
treec1739e498cf814750a0c63495a3ebca358117261 /views/controls/native/native_view_host.cc
parentf5c8a1596de89f2f3010186b03cc2378d23254ae (diff)
downloadchromium_src-0aaec000440c2453f20265a7b580efc4ad10b282.zip
chromium_src-0aaec000440c2453f20265a7b580efc4ad10b282.tar.gz
chromium_src-0aaec000440c2453f20265a7b580efc4ad10b282.tar.bz2
Relanding the NativeViewHost refactoring (it was breaking the ChromeOS build).
Refactoring some of the NativeViewHost and NativeControl focus management so their consumers don't have to explicitly set the focused view. See original review: http://codereview.chromium.org/235011/show BUG=None TEST=Run all tests. Make sure focus is stored/restored properly in Chrome. TBR=ben Review URL: http://codereview.chromium.org/246032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27563 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/native/native_view_host.cc')
-rw-r--r--views/controls/native/native_view_host.cc40
1 files changed, 34 insertions, 6 deletions
diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc
index 9cbeaf7..b5eb509 100644
--- a/views/controls/native/native_view_host.cc
+++ b/views/controls/native/native_view_host.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "app/gfx/canvas.h"
#include "views/controls/native/native_view_host_wrapper.h"
+#include "views/focus/focus_manager.h"
#include "views/widget/widget.h"
namespace views {
@@ -20,7 +21,10 @@ const char NativeViewHost::kViewClassName[] = "views/NativeViewHost";
NativeViewHost::NativeViewHost()
: native_view_(NULL),
fast_resize_(false),
- focus_view_(NULL) {
+ focus_native_view_(NULL) {
+ // By default we make this view the one that should be set as the focused view
+ // when the native view gets the focus.
+ focus_view_ = this;
// The native widget is placed relative to the root. As such, we need to
// know when the position of any ancestor changes, or our visibility relative
// to other views changed as it'll effect our position relative to the root.
@@ -33,10 +37,12 @@ NativeViewHost::~NativeViewHost() {
void NativeViewHost::Attach(gfx::NativeView native_view) {
DCHECK(!native_view_);
native_view_ = native_view;
- // If set_focus_view() has not been invoked, this view is the one that should
- // be seen as focused when the native view receives focus.
- if (!focus_view_)
- focus_view_ = this;
+ // If this NativeViewHost is the focus view, than it should obviously be
+ // focusable. If it is not, then it acts as a container and we don't want it
+ // to get focus through tab-traversal, so we make it not focusable.
+ SetFocusable(focus_view_ == this);
+ if (!focus_native_view_)
+ focus_native_view_ = native_view;
native_wrapper_->NativeViewAttached();
}
@@ -44,6 +50,7 @@ void NativeViewHost::Detach() {
DCHECK(native_view_);
native_wrapper_->NativeViewDetaching();
native_view_ = NULL;
+ focus_native_view_ = NULL;
}
void NativeViewHost::SetPreferredSize(const gfx::Size& size) {
@@ -57,6 +64,22 @@ void NativeViewHost::NativeViewDestroyed() {
native_view_ = NULL;
}
+void NativeViewHost::GotNativeFocus() {
+ // Some NativeViewHost may not have an associated focus view. This is the
+ // case for containers for example. They might still get the native focus,
+ // if one non native view they contain gets focused. In that case, we should
+ // not change the focused view.
+ if (!focus_view_ || !focus_view_->IsFocusable())
+ return;
+
+ FocusManager* focus_manager = GetFocusManager();
+ if (!focus_manager) {
+ NOTREACHED();
+ return;
+ }
+ focus_manager->SetFocusedView(focus_view_);
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeViewHost, View overrides:
@@ -134,7 +157,12 @@ std::string NativeViewHost::GetClassName() const {
}
void NativeViewHost::Focus() {
- native_wrapper_->SetFocus();
+ FocusManager* focus_manager = GetFocusManager();
+ if (!focus_manager) {
+ NOTREACHED();
+ return;
+ }
+ focus_manager->FocusNativeView(focus_native_view_);
}
} // namespace views