OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/gtk/constrained_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 BackgroundColorChanged(); | 68 BackgroundColorChanged(); |
69 | 69 |
70 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK); | 70 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK); |
71 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk), | 71 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk), |
72 this); | 72 this); |
73 g_signal_connect(widget(), "hierarchy-changed", | 73 g_signal_connect(widget(), "hierarchy-changed", |
74 G_CALLBACK(OnHierarchyChangedThunk), this); | 74 G_CALLBACK(OnHierarchyChangedThunk), this); |
75 | 75 |
76 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 76 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
77 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 77 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
78 constrained_window_tab_helper->AddConstrainedDialog(this); | 78 constrained_window_tab_helper->AddDialog(this); |
79 } | 79 } |
80 | 80 |
81 ConstrainedWindowGtk::~ConstrainedWindowGtk() { | 81 ConstrainedWindowGtk::~ConstrainedWindowGtk() { |
82 border_.Destroy(); | 82 border_.Destroy(); |
83 } | 83 } |
84 | 84 |
85 void ConstrainedWindowGtk::ShowConstrainedWindow() { | 85 void ConstrainedWindowGtk::ShowWebContentsModalDialog() { |
86 gtk_widget_show_all(border_.get()); | 86 gtk_widget_show_all(border_.get()); |
87 | 87 |
88 // We collaborate with WebContentsView and stick ourselves in the | 88 // We collaborate with WebContentsView and stick ourselves in the |
89 // WebContentsView's floating container. | 89 // WebContentsView's floating container. |
90 ContainingView()->AttachConstrainedWindow(this); | 90 ContainingView()->AttachConstrainedWindow(this); |
91 | 91 |
92 visible_ = true; | 92 visible_ = true; |
93 } | 93 } |
94 | 94 |
95 void ConstrainedWindowGtk::CloseConstrainedWindow() { | 95 void ConstrainedWindowGtk::CloseWebContentsModalDialog() { |
96 if (visible_) | 96 if (visible_) |
97 ContainingView()->RemoveConstrainedWindow(this); | 97 ContainingView()->RemoveConstrainedWindow(this); |
98 delegate_->DeleteDelegate(); | 98 delegate_->DeleteDelegate(); |
99 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 99 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
100 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 100 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
101 constrained_window_tab_helper->WillClose(this); | 101 constrained_window_tab_helper->WillClose(this); |
102 | 102 |
103 delete this; | 103 delete this; |
104 } | 104 } |
105 | 105 |
106 void ConstrainedWindowGtk::FocusConstrainedWindow() { | 106 void ConstrainedWindowGtk::FocusWebContentsModalDialog() { |
107 GtkWidget* focus_widget = delegate_->GetFocusWidget(); | 107 GtkWidget* focus_widget = delegate_->GetFocusWidget(); |
108 if (!focus_widget) | 108 if (!focus_widget) |
109 return; | 109 return; |
110 | 110 |
111 // The user may have focused another tab. In this case do not grab focus | 111 // The user may have focused another tab. In this case do not grab focus |
112 // until this tab is refocused. | 112 // until this tab is refocused. |
113 ConstrainedWindowTabHelper* helper = | 113 ConstrainedWindowTabHelper* helper = |
114 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 114 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
115 if ((!helper->delegate() || | 115 if ((!helper->delegate() || |
116 helper->delegate()->ShouldFocusConstrainedWindow()) && | 116 helper->delegate()->ShouldFocusConstrainedWindow()) && |
(...skipping 18 matching lines...) Expand all Loading... |
135 return ChromeWebContentsViewDelegateGtk::GetFor(web_contents_); | 135 return ChromeWebContentsViewDelegateGtk::GetFor(web_contents_); |
136 } | 136 } |
137 | 137 |
138 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender, | 138 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender, |
139 GdkEventKey* key) { | 139 GdkEventKey* key) { |
140 if (key->keyval == GDK_Escape) { | 140 if (key->keyval == GDK_Escape) { |
141 // Let the stack unwind so the event handler can release its ref | 141 // Let the stack unwind so the event handler can release its ref |
142 // on widget(). | 142 // on widget(). |
143 MessageLoop::current()->PostTask( | 143 MessageLoop::current()->PostTask( |
144 FROM_HERE, | 144 FROM_HERE, |
145 base::Bind(&ConstrainedWindowGtk::CloseConstrainedWindow, | 145 base::Bind(&ConstrainedWindowGtk::CloseWebContentsModalDialog, |
146 weak_factory_.GetWeakPtr())); | 146 weak_factory_.GetWeakPtr())); |
147 return TRUE; | 147 return TRUE; |
148 } | 148 } |
149 | 149 |
150 return FALSE; | 150 return FALSE; |
151 } | 151 } |
152 | 152 |
153 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender, | 153 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender, |
154 GtkWidget* previous_toplevel) { | 154 GtkWidget* previous_toplevel) { |
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
156 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(widget()))) | 156 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(widget()))) |
157 return; | 157 return; |
158 | 158 |
159 FocusConstrainedWindow(); | 159 FocusWebContentsModalDialog(); |
160 } | 160 } |
OLD | NEW |