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

Side by Side Diff: chrome/browser/ui/gtk/constrained_window_gtk.cc

Issue 12851002: Remove ConstrainedWindowGtkDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/gtk/gtk_util.h" 12 #include "chrome/browser/ui/gtk/gtk_util.h"
13 #include "chrome/browser/ui/gtk/tab_contents/chrome_web_contents_view_delegate_g tk.h" 13 #include "chrome/browser/ui/gtk/tab_contents/chrome_web_contents_view_delegate_g tk.h"
14 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" 14 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
15 #include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h" 15 #include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "ui/base/gtk/focus_store_gtk.h" 18 #include "ui/base/gtk/focus_store_gtk.h"
19 #include "ui/base/gtk/gtk_compat.h" 19 #include "ui/base/gtk/gtk_compat.h"
20 #include "ui/base/gtk/gtk_hig_constants.h" 20 #include "ui/base/gtk/gtk_hig_constants.h"
21 21
22 using content::BrowserThread; 22 using content::BrowserThread;
23 23
24 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() {
25 }
26
27 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) {
28 return false;
29 }
30
31 ConstrainedWindowGtk::ConstrainedWindowGtk( 24 ConstrainedWindowGtk::ConstrainedWindowGtk(
32 content::WebContents* web_contents, 25 content::WebContents* web_contents,
33 ConstrainedWindowGtkDelegate* delegate) 26 GtkWidget* contents,
27 GtkWidget* focus_widget)
34 : web_contents_(web_contents), 28 : web_contents_(web_contents),
35 delegate_(delegate), 29 focus_widget_(focus_widget),
36 visible_(false) { 30 visible_(false) {
37 DCHECK(web_contents); 31 DCHECK(web_contents);
38 DCHECK(delegate);
39 GtkWidget* dialog = delegate->GetWidgetRoot();
40 32
41 // Unlike other users of CreateBorderBin, we need a dedicated frame around 33 // Unlike other users of CreateBorderBin, we need a dedicated frame around
42 // our "window". 34 // our "window".
43 border_ = gtk_event_box_new(); 35 border_ = gtk_event_box_new();
44 g_object_ref_sink(border_); 36 g_object_ref_sink(border_);
45 GtkWidget* frame = gtk_frame_new(NULL); 37 GtkWidget* frame = gtk_frame_new(NULL);
46 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); 38 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
47 39
48 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 40 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
49 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 41 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
50 ui::kContentAreaBorder, ui::kContentAreaBorder, 42 ui::kContentAreaBorder, ui::kContentAreaBorder,
51 ui::kContentAreaBorder, ui::kContentAreaBorder); 43 ui::kContentAreaBorder, ui::kContentAreaBorder);
52 44
53 if (gtk_widget_get_parent(dialog)) 45 if (gtk_widget_get_parent(contents))
54 gtk_widget_reparent(dialog, alignment); 46 gtk_widget_reparent(contents, alignment);
55 else 47 else
56 gtk_container_add(GTK_CONTAINER(alignment), dialog); 48 gtk_container_add(GTK_CONTAINER(alignment), contents);
57 49
58 gtk_container_add(GTK_CONTAINER(frame), alignment); 50 gtk_container_add(GTK_CONTAINER(frame), alignment);
59 gtk_container_add(GTK_CONTAINER(border_), frame); 51 gtk_container_add(GTK_CONTAINER(border_), frame);
60 52
61 GdkColor background; 53 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK);
62 if (delegate_->GetBackgroundColor(&background)) { 54 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk),
63 gtk_widget_modify_base(border_, GTK_STATE_NORMAL, &background);
64 gtk_widget_modify_fg(border_, GTK_STATE_NORMAL, &background);
65 gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &background);
66 }
67
68 gtk_widget_add_events(border_, GDK_KEY_PRESS_MASK);
69 g_signal_connect(border_, "key-press-event", G_CALLBACK(OnKeyPressThunk),
70 this); 55 this);
71 g_signal_connect(border_, "hierarchy-changed", 56 g_signal_connect(border_, "hierarchy-changed",
72 G_CALLBACK(OnHierarchyChangedThunk), this); 57 G_CALLBACK(OnHierarchyChangedThunk), this);
73 g_signal_connect(border_, "destroy", G_CALLBACK(OnDestroyThunk), 58 g_signal_connect(border_, "destroy", G_CALLBACK(OnDestroyThunk),
74 this); 59 this);
75 60
76 // TODO(wittman): Getting/setting data on the widget is a hack to facilitate 61 // TODO(wittman): Getting/setting data on the widget is a hack to facilitate
77 // looking up the ConstrainedWindowGtk from the GtkWindow during refactoring. 62 // looking up the ConstrainedWindowGtk from the GtkWindow during refactoring.
78 // Remove once ConstrainedWindowGtk is gone. 63 // Remove once ConstrainedWindowGtk is gone.
79 g_object_set_data(G_OBJECT(border_), "ConstrainedWindowGtk", this); 64 g_object_set_data(G_OBJECT(border_), "ConstrainedWindowGtk", this);
80 } 65 }
81 66
82 ConstrainedWindowGtk::~ConstrainedWindowGtk() { 67 ConstrainedWindowGtk::~ConstrainedWindowGtk() {
83 } 68 }
84 69
85 void ConstrainedWindowGtk::ShowWebContentsModalDialog() { 70 void ConstrainedWindowGtk::ShowWebContentsModalDialog() {
86 gtk_widget_show_all(border_); 71 gtk_widget_show_all(border_);
87 72
88 // We collaborate with WebContentsView and stick ourselves in the 73 // We collaborate with WebContentsView and stick ourselves in the
89 // WebContentsView's floating container. 74 // WebContentsView's floating container.
90 ContainingView()->AttachWebContentsModalDialog(border_); 75 ContainingView()->AttachWebContentsModalDialog(border_);
91 76
92 visible_ = true; 77 visible_ = true;
93 } 78 }
94 79
95 void ConstrainedWindowGtk::FocusWebContentsModalDialog() { 80 void ConstrainedWindowGtk::FocusWebContentsModalDialog() {
96 GtkWidget* focus_widget = delegate_->GetFocusWidget(); 81 if (!focus_widget_)
97 if (!focus_widget)
98 return; 82 return;
99 83
100 // The user may have focused another tab. In this case do not grab focus 84 // The user may have focused another tab. In this case do not grab focus
101 // until this tab is refocused. 85 // until this tab is refocused.
102 if (gtk_util::IsWidgetAncestryVisible(focus_widget)) 86 if (gtk_util::IsWidgetAncestryVisible(focus_widget_))
103 gtk_widget_grab_focus(focus_widget); 87 gtk_widget_grab_focus(focus_widget_);
104 else 88 else
105 ContainingView()->focus_store()->SetWidget(focus_widget); 89 ContainingView()->focus_store()->SetWidget(focus_widget_);
106 } 90 }
107 91
108 void ConstrainedWindowGtk::PulseWebContentsModalDialog() { 92 void ConstrainedWindowGtk::PulseWebContentsModalDialog() {
109 } 93 }
110 94
111 NativeWebContentsModalDialog ConstrainedWindowGtk::GetNativeDialog() { 95 NativeWebContentsModalDialog ConstrainedWindowGtk::GetNativeDialog() {
112 return widget(); 96 return widget();
113 } 97 }
114 98
115 ConstrainedWindowGtk::TabContentsViewType* 99 ConstrainedWindowGtk::TabContentsViewType*
(...skipping 17 matching lines...) Expand all
133 117
134 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(border_))) 118 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(border_)))
135 return; 119 return;
136 120
137 FocusWebContentsModalDialog(); 121 FocusWebContentsModalDialog();
138 } 122 }
139 123
140 void ConstrainedWindowGtk::OnDestroy(GtkWidget* sender) { 124 void ConstrainedWindowGtk::OnDestroy(GtkWidget* sender) {
141 if (visible_) 125 if (visible_)
142 ContainingView()->RemoveWebContentsModalDialog(border_); 126 ContainingView()->RemoveWebContentsModalDialog(border_);
143 delegate_->DeleteDelegate();
144 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 127 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
145 WebContentsModalDialogManager::FromWebContents(web_contents_); 128 WebContentsModalDialogManager::FromWebContents(web_contents_);
146 web_contents_modal_dialog_manager->WillClose(border_); 129 web_contents_modal_dialog_manager->WillClose(border_);
147 130
148 g_object_unref(border_); 131 g_object_unref(border_);
149 border_ = NULL; 132 border_ = NULL;
150 133
151 delete this; 134 delete this;
152 } 135 }
153 136
154 GtkWidget* CreateWebContentsModalDialogGtk( 137 GtkWidget* CreateWebContentsModalDialogGtk(
155 content::WebContents* web_contents, 138 content::WebContents* web_contents,
156 ConstrainedWindowGtkDelegate* delegate) { 139 GtkWidget* contents,
140 GtkWidget* focus_widget) {
157 ConstrainedWindowGtk* window = 141 ConstrainedWindowGtk* window =
158 new ConstrainedWindowGtk(web_contents, delegate); 142 new ConstrainedWindowGtk(web_contents, contents, focus_widget);
159 return window->widget(); 143 return window->widget();
160 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698