| 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 "views/widget/native_widget_gtk.h" | 5 #include "views/widget/native_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 #include <X11/Xatom.h> | 10 #include <X11/Xatom.h> |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 gdk_pixbuf_get_width(drag_image), | 272 gdk_pixbuf_get_width(drag_image), |
| 273 gdk_pixbuf_get_height(drag_image)); | 273 gdk_pixbuf_get_height(drag_image)); |
| 274 | 274 |
| 275 g_signal_connect(G_OBJECT(drag_widget), "expose-event", | 275 g_signal_connect(G_OBJECT(drag_widget), "expose-event", |
| 276 G_CALLBACK(&DragIconWidgetPaint), drag_image); | 276 G_CALLBACK(&DragIconWidgetPaint), drag_image); |
| 277 return drag_widget; | 277 return drag_widget; |
| 278 } | 278 } |
| 279 | 279 |
| 280 // static | 280 // static |
| 281 GtkWidget* NativeWidgetGtk::null_parent_ = NULL; | 281 GtkWidget* NativeWidgetGtk::null_parent_ = NULL; |
| 282 bool NativeWidgetGtk::debug_paint_enabled_ = false; | |
| 283 | 282 |
| 284 //////////////////////////////////////////////////////////////////////////////// | 283 //////////////////////////////////////////////////////////////////////////////// |
| 285 // NativeWidgetGtk, public: | 284 // NativeWidgetGtk, public: |
| 286 | 285 |
| 287 NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate) | 286 NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate) |
| 288 : is_window_(false), | 287 : is_window_(false), |
| 289 window_state_(GDK_WINDOW_STATE_WITHDRAWN), | 288 window_state_(GDK_WINDOW_STATE_WITHDRAWN), |
| 290 delegate_(delegate), | 289 delegate_(delegate), |
| 291 widget_(NULL), | 290 widget_(NULL), |
| 292 window_contents_(NULL), | 291 window_contents_(NULL), |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 gtk_window_get_transient_for(GTK_WINDOW(widget)) == GTK_WINDOW( | 499 gtk_window_get_transient_for(GTK_WINDOW(widget)) == GTK_WINDOW( |
| 501 widget_)); | 500 widget_)); |
| 502 } | 501 } |
| 503 if (was_active != IsActive()) { | 502 if (was_active != IsActive()) { |
| 504 IsActiveChanged(); | 503 IsActiveChanged(); |
| 505 GetWidget()->GetRootView()->SchedulePaint(); | 504 GetWidget()->GetRootView()->SchedulePaint(); |
| 506 } | 505 } |
| 507 } | 506 } |
| 508 | 507 |
| 509 //////////////////////////////////////////////////////////////////////////////// | 508 //////////////////////////////////////////////////////////////////////////////// |
| 510 // NativeWidgetGtk, Widget implementation: | 509 // NativeWidgetGtk implementation: |
| 511 | 510 |
| 512 void NativeWidgetGtk::ClearNativeFocus() { | 511 void NativeWidgetGtk::ClearNativeFocus() { |
| 513 DCHECK(!child_); | 512 DCHECK(!child_); |
| 514 if (!GetNativeView()) { | 513 if (!GetNativeView()) { |
| 515 NOTREACHED(); | 514 NOTREACHED(); |
| 516 return; | 515 return; |
| 517 } | 516 } |
| 518 gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); | 517 gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); |
| 519 } | 518 } |
| 520 | 519 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 543 (key.flags() & ~ui::EF_ALT_DOWN) == 0) { | 542 (key.flags() & ~ui::EF_ALT_DOWN) == 0) { |
| 544 // Trigger VKEY_MENU when only this key is pressed and released, and both | 543 // Trigger VKEY_MENU when only this key is pressed and released, and both |
| 545 // press and release events are not handled by others. | 544 // press and release events are not handled by others. |
| 546 Accelerator accelerator(ui::VKEY_MENU, false, false, false); | 545 Accelerator accelerator(ui::VKEY_MENU, false, false, false); |
| 547 handled = GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); | 546 handled = GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); |
| 548 } | 547 } |
| 549 | 548 |
| 550 return handled; | 549 return handled; |
| 551 } | 550 } |
| 552 | 551 |
| 552 bool NativeWidgetGtk::SuppressFreezeUpdates() { |
| 553 if (!painted_) { |
| 554 painted_ = true; |
| 555 return true; |
| 556 } |
| 557 return false; |
| 558 } |
| 559 |
| 553 // static | 560 // static |
| 554 void NativeWidgetGtk::EnableDebugPaint() { | 561 void NativeWidgetGtk::EnableDebugPaint() { |
| 555 debug_paint_enabled_ = true; | 562 gdk_window_set_debug_updates(true); |
| 556 } | 563 } |
| 557 | 564 |
| 558 // static | 565 // static |
| 559 void NativeWidgetGtk::UpdateFreezeUpdatesProperty(GtkWindow* window, | 566 void NativeWidgetGtk::UpdateFreezeUpdatesProperty(GtkWindow* window, |
| 560 bool enable) { | 567 bool enable) { |
| 561 if (!GTK_WIDGET_REALIZED(GTK_WIDGET(window))) | 568 if (!GTK_WIDGET_REALIZED(GTK_WIDGET(window))) |
| 562 gtk_widget_realize(GTK_WIDGET(window)); | 569 gtk_widget_realize(GTK_WIDGET(window)); |
| 563 GdkWindow* gdk_window = GTK_WIDGET(window)->window; | 570 GdkWindow* gdk_window = GTK_WIDGET(window)->window; |
| 564 | 571 |
| 565 static GdkAtom freeze_atom_ = | 572 static GdkAtom freeze_atom_ = |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 // Clear the background before drawing any view and native components. | 1166 // Clear the background before drawing any view and native components. |
| 1160 DrawTransparentBackground(widget, event); | 1167 DrawTransparentBackground(widget, event); |
| 1161 if (!CompositePainter::IsComposited(widget_) && | 1168 if (!CompositePainter::IsComposited(widget_) && |
| 1162 gdk_screen_is_composited(gdk_screen_get_default())) { | 1169 gdk_screen_is_composited(gdk_screen_get_default())) { |
| 1163 // Let the parent draw the content only after something is drawn on | 1170 // Let the parent draw the content only after something is drawn on |
| 1164 // the widget. | 1171 // the widget. |
| 1165 CompositePainter::SetComposited(widget_); | 1172 CompositePainter::SetComposited(widget_); |
| 1166 } | 1173 } |
| 1167 } | 1174 } |
| 1168 | 1175 |
| 1169 if (debug_paint_enabled_) { | |
| 1170 // Using cairo directly because using skia didn't have immediate effect. | |
| 1171 cairo_t* cr = gdk_cairo_create(event->window); | |
| 1172 gdk_cairo_region(cr, event->region); | |
| 1173 cairo_set_source_rgb(cr, 1, 0, 0); // red | |
| 1174 cairo_rectangle(cr, | |
| 1175 event->area.x, event->area.y, | |
| 1176 event->area.width, event->area.height); | |
| 1177 cairo_fill(cr); | |
| 1178 cairo_destroy(cr); | |
| 1179 // Make sure that users see the red flash. | |
| 1180 XSync(ui::GetXDisplay(), false /* don't discard events */); | |
| 1181 } | |
| 1182 | |
| 1183 ui::ScopedRegion region(gdk_region_copy(event->region)); | 1176 ui::ScopedRegion region(gdk_region_copy(event->region)); |
| 1184 if (!gdk_region_empty(region.Get())) { | 1177 if (!gdk_region_empty(region.Get())) { |
| 1185 GdkRectangle clip_bounds; | 1178 GdkRectangle clip_bounds; |
| 1186 gdk_region_get_clipbox(region.Get(), &clip_bounds); | 1179 gdk_region_get_clipbox(region.Get(), &clip_bounds); |
| 1187 if (!delegate_->OnNativeWidgetPaintAccelerated(gfx::Rect(clip_bounds))) { | 1180 if (!delegate_->OnNativeWidgetPaintAccelerated(gfx::Rect(clip_bounds))) { |
| 1188 gfx::CanvasSkiaPaint canvas(event); | 1181 gfx::CanvasSkiaPaint canvas(event); |
| 1189 if (!canvas.is_empty()) { | 1182 if (!canvas.is_empty()) { |
| 1190 canvas.set_composite_alpha(is_transparent()); | 1183 canvas.set_composite_alpha(is_transparent()); |
| 1191 delegate_->OnNativeWidgetPaint(&canvas); | 1184 delegate_->OnNativeWidgetPaint(&canvas); |
| 1192 } | 1185 } |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1914 | 1907 |
| 1915 // And now, notify them that they have a brand new parent. | 1908 // And now, notify them that they have a brand new parent. |
| 1916 for (NativeWidgets::iterator it = widgets.begin(); | 1909 for (NativeWidgets::iterator it = widgets.begin(); |
| 1917 it != widgets.end(); ++it) { | 1910 it != widgets.end(); ++it) { |
| 1918 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, | 1911 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, |
| 1919 new_parent); | 1912 new_parent); |
| 1920 } | 1913 } |
| 1921 } | 1914 } |
| 1922 | 1915 |
| 1923 } // namespace views | 1916 } // namespace views |
| OLD | NEW |