OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/widget/widget_gtk.h" | 5 #include "views/widget/widget_gtk.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
9 #include <X11/extensions/shape.h> | 9 #include <X11/extensions/shape.h> |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 CompositePainter* painter = static_cast<CompositePainter*>( | 55 CompositePainter* painter = static_cast<CompositePainter*>( |
56 g_object_get_data(G_OBJECT(widget), kCompositePainterKey)); | 56 g_object_get_data(G_OBJECT(widget), kCompositePainterKey)); |
57 if (!painter) { | 57 if (!painter) { |
58 g_object_set_data(G_OBJECT(widget), kCompositePainterKey, | 58 g_object_set_data(G_OBJECT(widget), kCompositePainterKey, |
59 new CompositePainter(widget)); | 59 new CompositePainter(widget)); |
60 g_signal_connect(widget, "destroy", | 60 g_signal_connect(widget, "destroy", |
61 G_CALLBACK(&DestroyPainter), NULL); | 61 G_CALLBACK(&DestroyPainter), NULL); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 // Enable the composition. | 65 // Set the composition flag. |
66 static void SetComposited(GtkWidget* widget) { | 66 static void SetComposited(GtkWidget* widget) { |
67 DCHECK(GTK_WIDGET_REALIZED(widget)); | |
68 gdk_window_set_composited(widget->window, true); | |
69 g_object_set_data(G_OBJECT(widget), kCompositeEnabledKey, | 67 g_object_set_data(G_OBJECT(widget), kCompositeEnabledKey, |
70 const_cast<char*>("")); | 68 const_cast<char*>("")); |
71 } | 69 } |
72 | 70 |
73 // Returns true if the |widget| is composited. | 71 // Returns true if the |widget| is composited and ready to be drawn. |
74 static bool IsComposited(GtkWidget* widget) { | 72 static bool IsComposited(GtkWidget* widget) { |
75 return g_object_get_data(G_OBJECT(widget), kCompositeEnabledKey) != NULL; | 73 return g_object_get_data(G_OBJECT(widget), kCompositeEnabledKey) != NULL; |
76 } | 74 } |
77 | 75 |
78 private: | 76 private: |
79 virtual ~CompositePainter() {} | 77 virtual ~CompositePainter() {} |
80 | 78 |
81 // Composes a image from one child. | 79 // Composes a image from one child. |
82 static void CompositeChildWidget(GtkWidget* child, gpointer data) { | 80 static void CompositeChildWidget(GtkWidget* child, gpointer data) { |
83 GdkEventExpose* event = static_cast<GdkEventExpose*>(data); | 81 GdkEventExpose* event = static_cast<GdkEventExpose*>(data); |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 return; | 892 return; |
895 size_ = new_size; | 893 size_ = new_size; |
896 root_view_->SetBounds(0, 0, allocation->width, allocation->height); | 894 root_view_->SetBounds(0, 0, allocation->width, allocation->height); |
897 root_view_->SchedulePaint(); | 895 root_view_->SchedulePaint(); |
898 } | 896 } |
899 | 897 |
900 gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { | 898 gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { |
901 if (transparent_) { | 899 if (transparent_) { |
902 // Clear the background before drawing any view and native components. | 900 // Clear the background before drawing any view and native components. |
903 DrawTransparentBackground(widget, event); | 901 DrawTransparentBackground(widget, event); |
| 902 if (type_ == TYPE_CHILD && !CompositePainter::IsComposited(widget_)) { |
| 903 // Let the parent draw the content only after something is drawn on |
| 904 // the widget. |
| 905 CompositePainter::SetComposited(widget_); |
| 906 } |
904 } | 907 } |
905 root_view_->OnPaint(event); | 908 root_view_->OnPaint(event); |
906 return false; // False indicates other widgets should get the event as well. | 909 return false; // False indicates other widgets should get the event as well. |
907 } | 910 } |
908 | 911 |
909 void WidgetGtk::OnDragDataGet(GtkWidget* widget, | 912 void WidgetGtk::OnDragDataGet(GtkWidget* widget, |
910 GdkDragContext* context, | 913 GdkDragContext* context, |
911 GtkSelectionData* data, | 914 GtkSelectionData* data, |
912 guint info, | 915 guint info, |
913 guint time) { | 916 guint time) { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 // transparency has to be configured before widget is realized. | 1304 // transparency has to be configured before widget is realized. |
1302 DCHECK(parent) << "Transparent widget must have parent when initialized"; | 1305 DCHECK(parent) << "Transparent widget must have parent when initialized"; |
1303 ConfigureWidgetForTransparentBackground(parent); | 1306 ConfigureWidgetForTransparentBackground(parent); |
1304 } | 1307 } |
1305 gtk_container_add(GTK_CONTAINER(parent ? parent : null_parent_), widget_); | 1308 gtk_container_add(GTK_CONTAINER(parent ? parent : null_parent_), widget_); |
1306 gtk_widget_realize(widget_); | 1309 gtk_widget_realize(widget_); |
1307 if (transparent_) { | 1310 if (transparent_) { |
1308 // The widget has to be realized to set composited flag. | 1311 // The widget has to be realized to set composited flag. |
1309 // I tried "realize" signal to set this flag, but it did not work | 1312 // I tried "realize" signal to set this flag, but it did not work |
1310 // when the top level is popup. | 1313 // when the top level is popup. |
1311 CompositePainter::SetComposited(widget_); | 1314 DCHECK(GTK_WIDGET_REALIZED(widget_)); |
| 1315 gdk_window_set_composited(widget_->window, true); |
1312 } | 1316 } |
1313 } else { | 1317 } else { |
1314 widget_ = gtk_window_new( | 1318 widget_ = gtk_window_new( |
1315 (type_ == TYPE_WINDOW || type_ == TYPE_DECORATED_WINDOW) ? | 1319 (type_ == TYPE_WINDOW || type_ == TYPE_DECORATED_WINDOW) ? |
1316 GTK_WINDOW_TOPLEVEL : GTK_WINDOW_POPUP); | 1320 GTK_WINDOW_TOPLEVEL : GTK_WINDOW_POPUP); |
1317 gtk_widget_set_name(widget_, "views-gtkwidget-window"); | 1321 gtk_widget_set_name(widget_, "views-gtkwidget-window"); |
1318 if (transient_to_parent_) | 1322 if (transient_to_parent_) |
1319 gtk_window_set_transient_for(GTK_WINDOW(widget_), GTK_WINDOW(parent)); | 1323 gtk_window_set_transient_for(GTK_WINDOW(widget_), GTK_WINDOW(parent)); |
1320 GTK_WIDGET_UNSET_FLAGS(widget_, GTK_DOUBLE_BUFFERED); | 1324 GTK_WIDGET_UNSET_FLAGS(widget_, GTK_DOUBLE_BUFFERED); |
1321 | 1325 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 GtkWindow* window = GTK_WINDOW(element->data); | 1524 GtkWindow* window = GTK_WINDOW(element->data); |
1521 DCHECK(window); | 1525 DCHECK(window); |
1522 RootView *root_view = FindRootView(window); | 1526 RootView *root_view = FindRootView(window); |
1523 if (root_view) | 1527 if (root_view) |
1524 root_view->NotifyLocaleChanged(); | 1528 root_view->NotifyLocaleChanged(); |
1525 } | 1529 } |
1526 g_list_free(window_list); | 1530 g_list_free(window_list); |
1527 } | 1531 } |
1528 | 1532 |
1529 } // namespace views | 1533 } // namespace views |
OLD | NEW |