summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-14 20:20:35 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-14 20:20:35 +0000
commit2be2c01334383d74703dc88ecb67fae96a9124f9 (patch)
tree33b49e76db9830e974d235047ee940c0eecacdd4 /views
parent9c1a794e4b6c9d3ffca49889958ff381ecb82e32 (diff)
downloadchromium_src-2be2c01334383d74703dc88ecb67fae96a9124f9.zip
chromium_src-2be2c01334383d74703dc88ecb67fae96a9124f9.tar.gz
chromium_src-2be2c01334383d74703dc88ecb67fae96a9124f9.tar.bz2
This CL makes the focus remembered across tab switches for Chrome Linux with toolkit views.
It also contains clean-ups and implementation of different minor focus related things. BUG=None TEST=Open several tabs. Focus the location bar for some tabs, the page for others. Make sure that when switching between tabs the focus is restored to the last focused place (location bar or page) for each tab. Also test that deactivating/reactivating the browser window still restores focus properly. Review URL: http://codereview.chromium.org/194041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/native/native_view_host.cc4
-rw-r--r--views/controls/native/native_view_host.h2
-rw-r--r--views/controls/native/native_view_host_gtk.cc32
-rw-r--r--views/controls/native/native_view_host_gtk.h8
4 files changed, 41 insertions, 5 deletions
diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc
index e6637a9..9cbeaf7 100644
--- a/views/controls/native/native_view_host.cc
+++ b/views/controls/native/native_view_host.cc
@@ -33,6 +33,10 @@ 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;
native_wrapper_->NativeViewAttached();
}
diff --git a/views/controls/native/native_view_host.h b/views/controls/native/native_view_host.h
index d34ccf9..679e176 100644
--- a/views/controls/native/native_view_host.h
+++ b/views/controls/native/native_view_host.h
@@ -71,12 +71,12 @@ class NativeViewHost : public View {
virtual void Layout();
virtual void Paint(gfx::Canvas* canvas);
virtual void VisibilityChanged(View* starting_from, bool is_visible);
+ virtual void Focus();
protected:
virtual void VisibleBoundsInRootChanged();
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
virtual std::string GetClassName() const;
- virtual void Focus();
private:
// The attached native view.
diff --git a/views/controls/native/native_view_host_gtk.cc b/views/controls/native/native_view_host_gtk.cc
index 5e91d18..306aa94 100644
--- a/views/controls/native/native_view_host_gtk.cc
+++ b/views/controls/native/native_view_host_gtk.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "views/controls/native/native_view_host.h"
+#include "views/focus/focus_manager.h"
#include "views/widget/widget_gtk.h"
namespace views {
@@ -19,6 +20,7 @@ NativeViewHostGtk::NativeViewHostGtk(NativeViewHost* host)
: host_(host),
installed_clip_(false),
destroy_signal_id_(0),
+ focus_signal_id_(0),
fixed_(NULL) {
CreateFixed(false);
}
@@ -44,6 +46,12 @@ void NativeViewHostGtk::NativeViewAttached() {
this);
}
+ if (!focus_signal_id_) {
+ focus_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()),
+ "focus-in-event",
+ G_CALLBACK(CallFocusIn), this);
+ }
+
// Always layout though.
host_->Layout();
@@ -61,8 +69,10 @@ void NativeViewHostGtk::NativeViewDetaching() {
destroy_signal_id_);
destroy_signal_id_ = 0;
- // TODO(port): focus.
- // FocusManager::UninstallFocusSubclass(native_view());
+ g_signal_handler_disconnect(G_OBJECT(host_->native_view()),
+ focus_signal_id_);
+ focus_signal_id_ = 0;
+
installed_clip_ = false;
// Release ownership back to the caller.
@@ -154,7 +164,8 @@ void NativeViewHostGtk::HideWidget() {
}
void NativeViewHostGtk::SetFocus() {
- NOTIMPLEMENTED();
+ DCHECK(host_->native_view());
+ gtk_widget_grab_focus(host_->native_view());
}
////////////////////////////////////////////////////////////////////////////////
@@ -199,7 +210,20 @@ WidgetGtk* NativeViewHostGtk::GetHostWidget() const {
// static
void NativeViewHostGtk::CallDestroy(GtkObject* object,
NativeViewHostGtk* host) {
- return host->host_->NativeViewDestroyed();
+ host->host_->NativeViewDestroyed();
+}
+
+// static
+void NativeViewHostGtk::CallFocusIn(GtkWidget* widget,
+ GdkEventFocus* event,
+ NativeViewHostGtk* host) {
+ FocusManager* focus_manager =
+ FocusManager::GetFocusManagerForNativeView(widget);
+ if (!focus_manager) {
+ NOTREACHED();
+ return;
+ }
+ focus_manager->SetFocusedView(host->host_->focus_view());
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/views/controls/native/native_view_host_gtk.h b/views/controls/native/native_view_host_gtk.h
index 70cf438..81a2a7a1 100644
--- a/views/controls/native/native_view_host_gtk.h
+++ b/views/controls/native/native_view_host_gtk.h
@@ -54,6 +54,11 @@ class NativeViewHostGtk : public NativeViewHostWrapper {
// Invoked from the 'destroy' signal.
static void CallDestroy(GtkObject* object, NativeViewHostGtk* host);
+ // Invoked from the 'focus-in-event' signal.
+ static void CallFocusIn(GtkWidget* widget,
+ GdkEventFocus* event,
+ NativeViewHostGtk* button);
+
// Our associated NativeViewHost.
NativeViewHost* host_;
@@ -68,6 +73,9 @@ class NativeViewHostGtk : public NativeViewHostWrapper {
// Signal handle id for 'destroy' signal.
gulong destroy_signal_id_;
+ // Signal handle id for 'focus-in-event' signal.
+ gulong focus_signal_id_;
+
// The GtkFixed that contains the attached gfx::NativeView (used for
// clipping).
GtkWidget* fixed_;