Skip to content

Commit

Permalink
Merge pull request #57581 from groud/remove_get_fowus_owner
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Feb 3, 2022
2 parents e165f18 + 73e784d commit 7f93eb3
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 26 deletions.
6 changes: 0 additions & 6 deletions doc/classes/Control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,6 @@
Returns the focus neighbor for the specified [enum Side]. A getter method for [member focus_neighbor_bottom], [member focus_neighbor_left], [member focus_neighbor_right] and [member focus_neighbor_top].
</description>
</method>
<method name="get_focus_owner" qualifiers="const">
<return type="Control" />
<description>
Returns the control that has the keyboard focus or [code]null[/code] if none.
</description>
</method>
<method name="get_global_rect" qualifiers="const">
<return type="Rect2" />
<description>
Expand Down
2 changes: 1 addition & 1 deletion editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3481,7 +3481,7 @@ void AnimationTrackEditor::_track_remove_request(int p_track) {

void AnimationTrackEditor::_track_grab_focus(int p_track) {
// Don't steal focus if not working with the track editor.
if (Object::cast_to<AnimationTrackEdit>(get_focus_owner())) {
if (Object::cast_to<AnimationTrackEdit>(get_viewport()->gui_get_focus_owner())) {
track_edits[p_track]->grab_focus();
}
}
Expand Down
4 changes: 2 additions & 2 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void FindReplaceBar::unhandled_input(const Ref<InputEvent> &p_event) {
return;
}

Control *focus_owner = get_focus_owner();
Control *focus_owner = get_viewport()->gui_get_focus_owner();
if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_ancestor_of(focus_owner))) {
bool accepted = true;

Expand Down Expand Up @@ -724,7 +724,7 @@ void CodeTextEditor::input(const Ref<InputEvent> &event) {
}

if (!text_editor->has_focus()) {
if ((find_replace_bar != nullptr && find_replace_bar->is_visible()) && (find_replace_bar->has_focus() || find_replace_bar->is_ancestor_of(get_focus_owner()))) {
if ((find_replace_bar != nullptr && find_replace_bar->is_visible()) && (find_replace_bar->has_focus() || find_replace_bar->is_ancestor_of(get_viewport()->gui_get_focus_owner()))) {
if (ED_IS_SHORTCUT("script_text_editor/find_next", key_event)) {
find_replace_bar->search_next();
accept_event();
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ void FindBar::unhandled_input(const Ref<InputEvent> &p_event) {

Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
if (k->is_pressed() && (rich_text_label->has_focus() || is_ancestor_of(get_focus_owner()))) {
if (k->is_pressed() && (rich_text_label->has_focus() || is_ancestor_of(get_viewport()->gui_get_focus_owner()))) {
bool accepted = true;

switch (k->get_keycode()) {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,7 @@ void EditorInspector::update_tree() {
if (property_focusable != -1) {
//check focusable is really focusable
bool restore_focus = false;
Control *focused = get_focus_owner();
Control *focused = get_viewport() ? get_viewport()->gui_get_focus_owner() : nullptr;
if (focused) {
Node *parent = focused->get_parent();
while (parent) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
_update_cursor();

// Grab focus
if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) {
if (!viewport->has_focus() && (!get_viewport()->gui_get_focus_owner() || !get_viewport()->gui_get_focus_owner()->is_text_field())) {
viewport->call_deferred(SNAME("grab_focus"));
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const
}

void Node3DEditorViewport::_surface_mouse_enter() {
if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) {
if (!surface->has_focus() && (!get_viewport()->gui_get_focus_owner() || !get_viewport()->gui_get_focus_owner()->is_text_field())) {
surface->grab_focus();
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/theme_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ void ThemeTypeEditor::_update_type_list() {
}
updating = true;

Control *focused = get_focus_owner();
Control *focused = get_viewport()->gui_get_focus_owner();
if (focused) {
if (focusables.has(focused)) {
// If focus is currently on one of the internal property editors, don't update.
Expand Down
4 changes: 2 additions & 2 deletions editor/rename_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void RenameDialog::_bind_methods() {
}

void RenameDialog::_update_substitute() {
LineEdit *focus_owner_line_edit = Object::cast_to<LineEdit>(scene_tree_editor->get_focus_owner());
LineEdit *focus_owner_line_edit = Object::cast_to<LineEdit>(scene_tree_editor->get_viewport()->gui_get_focus_owner());
bool is_main_field = _is_main_field(focus_owner_line_edit);

but_insert_name->set_disabled(!is_main_field);
Expand Down Expand Up @@ -632,7 +632,7 @@ bool RenameDialog::_is_main_field(LineEdit *line_edit) {
}

void RenameDialog::_insert_text(String text) {
LineEdit *focus_owner = Object::cast_to<LineEdit>(scene_tree_editor->get_focus_owner());
LineEdit *focus_owner = Object::cast_to<LineEdit>(scene_tree_editor->get_viewport()->gui_get_focus_owner());

if (_is_main_field(focus_owner)) {
focus_owner->selection_delete();
Expand Down
2 changes: 1 addition & 1 deletion editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void SceneTreeDock::input(const Ref<InputEvent> &p_event) {
void SceneTreeDock::unhandled_key_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

if (get_focus_owner() && get_focus_owner()->is_text_field()) {
if (get_viewport()->gui_get_focus_owner() && get_viewport()->gui_get_focus_owner()->is_text_field()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/base_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ bool BaseButton::_is_focus_owner_in_shorcut_context() const {
}

Node *ctx_node = get_shortcut_context();
Control *vp_focus = get_focus_owner();
Control *vp_focus = get_viewport() ? get_viewport()->gui_get_focus_owner() : nullptr;

// If the context is valid and the viewport focus is valid, check if the context is the focus or is a parent of it.
return ctx_node && vp_focus && (ctx_node == vp_focus || ctx_node->is_ancestor_of(vp_focus));
Expand Down
6 changes: 0 additions & 6 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2599,11 +2599,6 @@ Control::MouseFilter Control::get_mouse_filter() const {
return data.mouse_filter;
}

Control *Control::get_focus_owner() const {
ERR_FAIL_COND_V(!is_inside_tree(), nullptr);
return get_viewport()->gui_get_focus_owner();
}

void Control::warp_mouse(const Point2 &p_to_pos) {
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->warp_mouse(get_global_transform().xform(p_to_pos));
Expand Down Expand Up @@ -2893,7 +2888,6 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("release_focus"), &Control::release_focus);
ClassDB::bind_method(D_METHOD("find_prev_valid_focus"), &Control::find_prev_valid_focus);
ClassDB::bind_method(D_METHOD("find_next_valid_focus"), &Control::find_next_valid_focus);
ClassDB::bind_method(D_METHOD("get_focus_owner"), &Control::get_focus_owner);

ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags);
ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags);
Expand Down
2 changes: 0 additions & 2 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,6 @@ class Control : public CanvasItem {
void set_focus_previous(const NodePath &p_prev);
NodePath get_focus_previous() const;

Control *get_focus_owner() const;

void set_mouse_filter(MouseFilter p_filter);
MouseFilter get_mouse_filter() const;

Expand Down

0 comments on commit 7f93eb3

Please sign in to comment.