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

Side by Side Diff: views/focus/focus_manager_gtk.cc

Issue 200020: Improving GetFocusManager on Gtk (Closed)
Patch Set: Added FocusNativeView 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 unified diff | Download patch
« no previous file with comments | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gtk/gtk.h> 5 #include <gtk/gtk.h>
6 6
7 #include "views/focus/focus_manager.h" 7 #include "views/focus/focus_manager.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "views/widget/widget_gtk.h" 10 #include "views/widget/widget_gtk.h"
11 11
12 namespace views { 12 namespace views {
13 13
14 void FocusManager::ClearNativeFocus() { 14 void FocusManager::ClearNativeFocus() {
15 gtk_widget_grab_focus(widget_->GetNativeView()); 15 gtk_widget_grab_focus(widget_->GetNativeView());
16 } 16 }
17 17
18 void FocusManager::FocusNativeView(gfx::NativeView native_view) { 18 void FocusManager::FocusNativeView(gfx::NativeView native_view) {
19 NOTIMPLEMENTED(); 19 if (native_view && !gtk_widget_is_focus(native_view))
20 gtk_widget_grab_focus(native_view);
20 } 21 }
21 22
22 // static 23 // static
23 FocusManager* FocusManager::GetFocusManagerForNativeView( 24 FocusManager* FocusManager::GetFocusManagerForNativeView(
24 gfx::NativeView native_view) { 25 gfx::NativeView native_view) {
25 GtkWidget* parent; 26 GtkWidget* root = gtk_widget_get_toplevel(native_view);
26 while ((parent = gtk_widget_get_parent(native_view)) != NULL) { 27 if (!root || !GTK_WIDGET_TOPLEVEL(root))
27 native_view = parent; 28 return NULL;
28 } 29
29 WidgetGtk* widget = WidgetGtk::GetViewForNative(native_view); 30 WidgetGtk* widget = WidgetGtk::GetViewForNative(root);
30 if (!widget) { 31 if (!widget) {
31 NOTREACHED(); 32 NOTREACHED();
32 return NULL; 33 return NULL;
33 } 34 }
34 FocusManager* focus_manager = widget->GetFocusManager(); 35 FocusManager* focus_manager = widget->GetFocusManager();
35 DCHECK(focus_manager) << "no FocusManager for top level Widget"; 36 DCHECK(focus_manager) << "no FocusManager for top level Widget";
36 return focus_manager; 37 return focus_manager;
37 } 38 }
38 39
39 } // namespace views 40 } // namespace views
OLDNEW
« no previous file with comments | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698