| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gtk_util.h" | 5 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 | 8 |
| 9 #include <cstdarg> | 9 #include <cstdarg> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "chrome/browser/chromeos/frame/browser_view.h" | 49 #include "chrome/browser/chromeos/frame/browser_view.h" |
| 50 #include "chrome/browser/chromeos/native_dialog_window.h" | 50 #include "chrome/browser/chromeos/native_dialog_window.h" |
| 51 #else | 51 #else |
| 52 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 52 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 // These conflict with base/tracked_objects.h, so need to come last. | 55 // These conflict with base/tracked_objects.h, so need to come last. |
| 56 #include <gdk/gdkx.h> | 56 #include <gdk/gdkx.h> |
| 57 #include <gtk/gtk.h> | 57 #include <gtk/gtk.h> |
| 58 | 58 |
| 59 using content::WebContents; |
| 60 |
| 59 namespace { | 61 namespace { |
| 60 | 62 |
| 61 #if defined(GOOGLE_CHROME_BUILD) | 63 #if defined(GOOGLE_CHROME_BUILD) |
| 62 static const char* kIconName = "google-chrome"; | 64 static const char* kIconName = "google-chrome"; |
| 63 #else | 65 #else |
| 64 static const char* kIconName = "chromium-browser"; | 66 static const char* kIconName = "chromium-browser"; |
| 65 #endif | 67 #endif |
| 66 | 68 |
| 67 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; | 69 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; |
| 68 | 70 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 GTK_WIDGET(item->data), | 154 GTK_WIDGET(item->data), |
| 153 event); | 155 event); |
| 154 } | 156 } |
| 155 g_list_free(children); | 157 g_list_free(children); |
| 156 | 158 |
| 157 return TRUE; | 159 return TRUE; |
| 158 } | 160 } |
| 159 | 161 |
| 160 #if defined(OS_CHROMEOS) | 162 #if defined(OS_CHROMEOS) |
| 161 | 163 |
| 162 TabContents* GetBrowserWindowSelectedTabContents(BrowserWindow* window) { | 164 WebContents* GetBrowserWindowSelectedWebContents(BrowserWindow* window) { |
| 163 chromeos::BrowserView* browser_view = static_cast<chromeos::BrowserView*>( | 165 chromeos::BrowserView* browser_view = static_cast<chromeos::BrowserView*>( |
| 164 window); | 166 window); |
| 165 return browser_view->GetSelectedTabContents(); | 167 return browser_view->GetSelectedWebContents(); |
| 166 } | 168 } |
| 167 | 169 |
| 168 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { | 170 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { |
| 169 gfx::NativeView widget = gtk_window_get_focus(window->GetNativeHandle()); | 171 gfx::NativeView widget = gtk_window_get_focus(window->GetNativeHandle()); |
| 170 | 172 |
| 171 if (widget == NULL) { | 173 if (widget == NULL) { |
| 172 chromeos::BrowserView* browser_view = static_cast<chromeos::BrowserView*>( | 174 chromeos::BrowserView* browser_view = static_cast<chromeos::BrowserView*>( |
| 173 window); | 175 window); |
| 174 widget = browser_view->saved_focused_widget(); | 176 widget = browser_view->saved_focused_widget(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 return widget; | 179 return widget; |
| 178 } | 180 } |
| 179 | 181 |
| 180 #else | 182 #else |
| 181 | 183 |
| 182 TabContents* GetBrowserWindowSelectedTabContents(BrowserWindow* window) { | 184 WebContents* GetBrowserWindowSelectedWebContents(BrowserWindow* window) { |
| 183 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( | 185 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( |
| 184 window); | 186 window); |
| 185 return browser_window->browser()->GetSelectedTabContents(); | 187 return browser_window->browser()->GetSelectedWebContents(); |
| 186 } | 188 } |
| 187 | 189 |
| 188 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { | 190 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { |
| 189 return gtk_window_get_focus(window->GetNativeHandle()); | 191 return gtk_window_get_focus(window->GetNativeHandle()); |
| 190 } | 192 } |
| 191 | 193 |
| 192 #endif | 194 #endif |
| 193 | 195 |
| 194 } // namespace | 196 } // namespace |
| 195 | 197 |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 // against the current render view host, otherwise emit the specified |signal| | 1167 // against the current render view host, otherwise emit the specified |signal| |
| 1166 // against the focused widget. | 1168 // against the focused widget. |
| 1167 // TODO(suzhe): This approach does not work for plugins. | 1169 // TODO(suzhe): This approach does not work for plugins. |
| 1168 void DoCutCopyPaste(BrowserWindow* window, | 1170 void DoCutCopyPaste(BrowserWindow* window, |
| 1169 void (RenderViewHost::*method)(), | 1171 void (RenderViewHost::*method)(), |
| 1170 const char* signal) { | 1172 const char* signal) { |
| 1171 GtkWidget* widget = GetBrowserWindowFocusedWidget(window); | 1173 GtkWidget* widget = GetBrowserWindowFocusedWidget(window); |
| 1172 if (widget == NULL) | 1174 if (widget == NULL) |
| 1173 return; // Do nothing if no focused widget. | 1175 return; // Do nothing if no focused widget. |
| 1174 | 1176 |
| 1175 TabContents* current_tab = GetBrowserWindowSelectedTabContents(window); | 1177 WebContents* current_tab = GetBrowserWindowSelectedWebContents(window); |
| 1176 if (current_tab && widget == current_tab->GetContentNativeView()) { | 1178 if (current_tab && widget == current_tab->GetContentNativeView()) { |
| 1177 (current_tab->GetRenderViewHost()->*method)(); | 1179 (current_tab->GetRenderViewHost()->*method)(); |
| 1178 } else { | 1180 } else { |
| 1179 guint id; | 1181 guint id; |
| 1180 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0) | 1182 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0) |
| 1181 g_signal_emit(widget, id, 0); | 1183 g_signal_emit(widget, id, 0); |
| 1182 } | 1184 } |
| 1183 } | 1185 } |
| 1184 | 1186 |
| 1185 void DoCut(BrowserWindow* window) { | 1187 void DoCut(BrowserWindow* window) { |
| 1186 DoCutCopyPaste(window, &RenderViewHost::Cut, "cut-clipboard"); | 1188 DoCutCopyPaste(window, &RenderViewHost::Cut, "cut-clipboard"); |
| 1187 } | 1189 } |
| 1188 | 1190 |
| 1189 void DoCopy(BrowserWindow* window) { | 1191 void DoCopy(BrowserWindow* window) { |
| 1190 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); | 1192 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); |
| 1191 } | 1193 } |
| 1192 | 1194 |
| 1193 void DoPaste(BrowserWindow* window) { | 1195 void DoPaste(BrowserWindow* window) { |
| 1194 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); | 1196 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); |
| 1195 } | 1197 } |
| 1196 | 1198 |
| 1197 } // namespace gtk_util | 1199 } // namespace gtk_util |
| OLD | NEW |