blob: a52a6d90a5bc9b134db4691e89ff25243a410aa1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <gtk/gtk.h>
#include "views/focus/focus_manager.h"
#include "base/logging.h"
#include "views/widget/widget_gtk.h"
#include "views/window/window_gtk.h"
namespace views {
void FocusManager::ClearNativeFocus() {
GtkWidget* gtk_widget = widget_->GetNativeView();
if (!gtk_widget) {
NOTREACHED();
return;
}
// Since only top-level WidgetGtk have a focus manager, the native view is
// expected to be a GtkWindow.
gtk_window_set_focus(GTK_WINDOW(gtk_widget), NULL);
}
void FocusManager::FocusNativeView(gfx::NativeView native_view) {
if (native_view && !gtk_widget_is_focus(native_view))
gtk_widget_grab_focus(native_view);
}
// static
FocusManager* FocusManager::GetFocusManagerForNativeView(
gfx::NativeView native_view) {
GtkWidget* root = gtk_widget_get_toplevel(native_view);
if (!root || !GTK_WIDGET_TOPLEVEL(root))
return NULL;
WidgetGtk* widget = WidgetGtk::GetViewForNative(root);
if (!widget) {
// TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the
// options page is only based on views.
// NOTREACHED();
NOTIMPLEMENTED();
return NULL;
}
FocusManager* focus_manager = widget->GetFocusManager();
DCHECK(focus_manager) << "no FocusManager for top level Widget";
return focus_manager;
}
// static
FocusManager* FocusManager::GetFocusManagerForNativeWindow(
gfx::NativeWindow native_window) {
return GetFocusManagerForNativeView(GTK_WIDGET(native_window));
}
} // namespace views
|