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

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

Issue 7850026: Aura under Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: First version that links (and crashes) Created 9 years, 3 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) 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 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 #else 183 #else
184 184
185 TabContents* GetBrowserWindowSelectedTabContents(BrowserWindow* window) { 185 TabContents* GetBrowserWindowSelectedTabContents(BrowserWindow* window) {
186 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( 186 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>(
187 window); 187 window);
188 return browser_window->browser()->GetSelectedTabContents(); 188 return browser_window->browser()->GetSelectedTabContents();
189 } 189 }
190 190
191 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) { 191 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) {
192 #if defined(USE_AURA)
193 // TODO(saintlou): This entire module should be removed from Aura soon
Ben Goodger (Google) 2011/09/16 01:11:18 Why do you need to build this file?
Emmanuel Saint-loubert-Bié 2011/09/16 02:34:54 There are a few methods that we need, but will be
194 return NULL;
195 #else
192 return gtk_window_get_focus(window->GetNativeHandle()); 196 return gtk_window_get_focus(window->GetNativeHandle());
197 #endif
193 } 198 }
194 199
195 #endif 200 #endif
196 201
197 } // namespace 202 } // namespace
198 203
199 namespace event_utils { 204 namespace event_utils {
200 205
201 // TODO(shinyak) This function will be removed after refactoring. 206 // TODO(shinyak) This function will be removed after refactoring.
202 WindowOpenDisposition DispositionFromGdkState(guint state) { 207 WindowOpenDisposition DispositionFromGdkState(guint state) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 389
385 // Move to user expected desktop if window is already visible. 390 // Move to user expected desktop if window is already visible.
386 if (GTK_WIDGET(window)->window) { 391 if (GTK_WIDGET(window)->window) {
387 ui::ChangeWindowDesktop( 392 ui::ChangeWindowDesktop(
388 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window)), 393 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window)),
389 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(parent))); 394 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(parent)));
390 } 395 }
391 } 396 }
392 397
393 void MakeAppModalWindowGroup() { 398 void MakeAppModalWindowGroup() {
399 #if defined(USE_AURA)
400 // TODO(saintlou): This entire module should be removed from Aura soon
401 return;
402 #else
394 // Older versions of GTK+ don't give us gtk_window_group_list() which is what 403 // Older versions of GTK+ don't give us gtk_window_group_list() which is what
395 // we need to add current non-browser modal dialogs to the list. If 404 // we need to add current non-browser modal dialogs to the list. If
396 // we have 2.14+ we can do things the correct way. 405 // we have 2.14+ we can do things the correct way.
397 GtkWindowGroup* window_group = gtk_window_group_new(); 406 GtkWindowGroup* window_group = gtk_window_group_new();
398 for (BrowserList::const_iterator it = BrowserList::begin(); 407 for (BrowserList::const_iterator it = BrowserList::begin();
399 it != BrowserList::end(); ++it) { 408 it != BrowserList::end(); ++it) {
400 // List all windows in this current group 409 // List all windows in this current group
401 GtkWindowGroup* old_group = 410 GtkWindowGroup* old_group =
402 gtk_window_get_group((*it)->window()->GetNativeHandle()); 411 gtk_window_get_group((*it)->window()->GetNativeHandle());
403 412
404 GList* all_windows = gtk_window_group_list_windows(old_group); 413 GList* all_windows = gtk_window_group_list_windows(old_group);
405 for (GList* window = all_windows; window; window = window->next) { 414 for (GList* window = all_windows; window; window = window->next) {
406 gtk_window_group_add_window(window_group, GTK_WINDOW(window->data)); 415 gtk_window_group_add_window(window_group, GTK_WINDOW(window->data));
407 } 416 }
408 g_list_free(all_windows); 417 g_list_free(all_windows);
409 } 418 }
410 g_object_unref(window_group); 419 g_object_unref(window_group);
420 #endif
411 } 421 }
412 422
413 void AppModalDismissedUngroupWindows() { 423 void AppModalDismissedUngroupWindows() {
424 #if defined(USE_AURA)
425 // TODO(saintlou): This entire module should be removed from Aura soon
426 return;
427 #else
414 if (BrowserList::begin() != BrowserList::end()) { 428 if (BrowserList::begin() != BrowserList::end()) {
415 std::vector<GtkWindow*> transient_windows; 429 std::vector<GtkWindow*> transient_windows;
416 430
417 // All windows should be part of one big modal group right now. 431 // All windows should be part of one big modal group right now.
418 GtkWindowGroup* window_group = gtk_window_get_group( 432 GtkWindowGroup* window_group = gtk_window_get_group(
419 (*BrowserList::begin())->window()->GetNativeHandle()); 433 (*BrowserList::begin())->window()->GetNativeHandle());
420 GList* windows = gtk_window_group_list_windows(window_group); 434 GList* windows = gtk_window_group_list_windows(window_group);
421 435
422 for (GList* item = windows; item; item = item->next) { 436 for (GList* item = windows; item; item = item->next) {
423 GtkWindow* window = GTK_WINDOW(item->data); 437 GtkWindow* window = GTK_WINDOW(item->data);
424 GtkWindow* transient_for = gtk_window_get_transient_for(window); 438 GtkWindow* transient_for = gtk_window_get_transient_for(window);
425 if (transient_for) { 439 if (transient_for) {
426 transient_windows.push_back(window); 440 transient_windows.push_back(window);
427 } else { 441 } else {
428 GtkWindowGroup* window_group = gtk_window_group_new(); 442 GtkWindowGroup* window_group = gtk_window_group_new();
429 gtk_window_group_add_window(window_group, window); 443 gtk_window_group_add_window(window_group, window);
430 g_object_unref(window_group); 444 g_object_unref(window_group);
431 } 445 }
432 } 446 }
433 447
434 // Put each transient window in the same group as its transient parent. 448 // Put each transient window in the same group as its transient parent.
435 for (std::vector<GtkWindow*>::iterator it = transient_windows.begin(); 449 for (std::vector<GtkWindow*>::iterator it = transient_windows.begin();
436 it != transient_windows.end(); ++it) { 450 it != transient_windows.end(); ++it) {
437 GtkWindow* transient_parent = gtk_window_get_transient_for(*it); 451 GtkWindow* transient_parent = gtk_window_get_transient_for(*it);
438 GtkWindowGroup* group = gtk_window_get_group(transient_parent); 452 GtkWindowGroup* group = gtk_window_get_group(transient_parent);
439 gtk_window_group_add_window(group, *it); 453 gtk_window_group_add_window(group, *it);
440 } 454 }
441 } 455 }
456 #endif
442 } 457 }
443 458
444 void RemoveAllChildren(GtkWidget* container) { 459 void RemoveAllChildren(GtkWidget* container) {
445 gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container); 460 gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container);
446 } 461 }
447 462
448 void ForceFontSizePixels(GtkWidget* widget, double size_pixels) { 463 void ForceFontSizePixels(GtkWidget* widget, double size_pixels) {
449 PangoFontDescription* font_desc = pango_font_description_new(); 464 PangoFontDescription* font_desc = pango_font_description_new();
450 // pango_font_description_set_absolute_size sets the font size in device 465 // pango_font_description_set_absolute_size sets the font size in device
451 // units, which for us is pixels. 466 // units, which for us is pixels.
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 810
796 gtk_style_detach(our_style); 811 gtk_style_detach(our_style);
797 g_object_unref(our_style); 812 g_object_unref(our_style);
798 } 813 }
799 814
800 void DrawThemedToolbarBackground(GtkWidget* widget, 815 void DrawThemedToolbarBackground(GtkWidget* widget,
801 cairo_t* cr, 816 cairo_t* cr,
802 GdkEventExpose* event, 817 GdkEventExpose* event,
803 const gfx::Point& tabstrip_origin, 818 const gfx::Point& tabstrip_origin,
804 GtkThemeService* theme_service) { 819 GtkThemeService* theme_service) {
820 #if !defined(USE_AURA)
805 // Fill the entire region with the toolbar color. 821 // Fill the entire region with the toolbar color.
806 GdkColor color = theme_service->GetGdkColor( 822 GdkColor color = theme_service->GetGdkColor(
807 ThemeService::COLOR_TOOLBAR); 823 ThemeService::COLOR_TOOLBAR);
808 gdk_cairo_set_source_color(cr, &color); 824 gdk_cairo_set_source_color(cr, &color);
809 cairo_fill(cr); 825 cairo_fill(cr);
810 826
811 // The toolbar is supposed to blend in with the active tab, so we have to pass 827 // The toolbar is supposed to blend in with the active tab, so we have to pass
812 // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the 828 // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the
813 // tab strip. 829 // tab strip.
814 CairoCachedSurface* background = theme_service->GetSurfaceNamed( 830 CairoCachedSurface* background = theme_service->GetSurfaceNamed(
815 IDR_THEME_TOOLBAR, widget); 831 IDR_THEME_TOOLBAR, widget);
816 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y()); 832 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y());
817 // We tile the toolbar background in both directions. 833 // We tile the toolbar background in both directions.
818 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 834 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
819 cairo_rectangle(cr, 835 cairo_rectangle(cr,
820 tabstrip_origin.x(), 836 tabstrip_origin.x(),
821 tabstrip_origin.y(), 837 tabstrip_origin.y(),
822 event->area.x + event->area.width - tabstrip_origin.x(), 838 event->area.x + event->area.width - tabstrip_origin.x(),
823 event->area.y + event->area.height - tabstrip_origin.y()); 839 event->area.y + event->area.height - tabstrip_origin.y());
824 cairo_fill(cr); 840 cairo_fill(cr);
841 #endif
825 } 842 }
826 843
827 GdkColor AverageColors(GdkColor color_one, GdkColor color_two) { 844 GdkColor AverageColors(GdkColor color_one, GdkColor color_two) {
828 GdkColor average_color; 845 GdkColor average_color;
829 average_color.pixel = 0; 846 average_color.pixel = 0;
830 average_color.red = (color_one.red + color_two.red) / 2; 847 average_color.red = (color_one.red + color_two.red) / 2;
831 average_color.green = (color_one.green + color_two.green) / 2; 848 average_color.green = (color_one.green + color_two.green) / 2;
832 average_color.blue = (color_one.blue + color_two.blue) / 2; 849 average_color.blue = (color_one.blue + color_two.blue) / 2;
833 return average_color; 850 return average_color;
834 } 851 }
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 } 1227 }
1211 1228
1212 // Performs Cut/Copy/Paste operation on the |window|. 1229 // Performs Cut/Copy/Paste operation on the |window|.
1213 // If the current render view is focused, then just call the specified |method| 1230 // If the current render view is focused, then just call the specified |method|
1214 // against the current render view host, otherwise emit the specified |signal| 1231 // against the current render view host, otherwise emit the specified |signal|
1215 // against the focused widget. 1232 // against the focused widget.
1216 // TODO(suzhe): This approach does not work for plugins. 1233 // TODO(suzhe): This approach does not work for plugins.
1217 void DoCutCopyPaste(BrowserWindow* window, 1234 void DoCutCopyPaste(BrowserWindow* window,
1218 void (RenderViewHost::*method)(), 1235 void (RenderViewHost::*method)(),
1219 const char* signal) { 1236 const char* signal) {
1237 #if defined(USE_AURA)
1238 // TODO(saintlou): This entire module should be removed from Aura soon
1239 return;
1240 #else
1220 GtkWidget* widget = GetBrowserWindowFocusedWidget(window); 1241 GtkWidget* widget = GetBrowserWindowFocusedWidget(window);
1221 if (widget == NULL) 1242 if (widget == NULL)
1222 return; // Do nothing if no focused widget. 1243 return; // Do nothing if no focused widget.
1223 1244
1224 TabContents* current_tab = GetBrowserWindowSelectedTabContents(window); 1245 TabContents* current_tab = GetBrowserWindowSelectedTabContents(window);
1225 if (current_tab && widget == current_tab->GetContentNativeView()) { 1246 if (current_tab && widget == current_tab->GetContentNativeView()) {
1226 (current_tab->render_view_host()->*method)(); 1247 (current_tab->render_view_host()->*method)();
1227 } else { 1248 } else {
1228 guint id; 1249 guint id;
1229 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0) 1250 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0)
1230 g_signal_emit(widget, id, 0); 1251 g_signal_emit(widget, id, 0);
1231 } 1252 }
1253 #endif
1232 } 1254 }
1233 1255
1234 void DoCut(BrowserWindow* window) { 1256 void DoCut(BrowserWindow* window) {
1235 DoCutCopyPaste(window, &RenderViewHost::Cut, "cut-clipboard"); 1257 DoCutCopyPaste(window, &RenderViewHost::Cut, "cut-clipboard");
1236 } 1258 }
1237 1259
1238 void DoCopy(BrowserWindow* window) { 1260 void DoCopy(BrowserWindow* window) {
1239 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); 1261 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard");
1240 } 1262 }
1241 1263
1242 void DoPaste(BrowserWindow* window) { 1264 void DoPaste(BrowserWindow* window) {
1243 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); 1265 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard");
1244 } 1266 }
1245 1267
1246 } // namespace gtk_util 1268 } // namespace gtk_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698