| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 gtk_window_get_transient_for(GTK_WINDOW(widget)) == GTK_WINDOW( | 494 gtk_window_get_transient_for(GTK_WINDOW(widget)) == GTK_WINDOW( |
| 496 widget_)); | 495 widget_)); |
| 497 } | 496 } |
| 498 if (was_active != IsActive()) { | 497 if (was_active != IsActive()) { |
| 499 IsActiveChanged(); | 498 IsActiveChanged(); |
| 500 GetWidget()->GetRootView()->SchedulePaint(); | 499 GetWidget()->GetRootView()->SchedulePaint(); |
| 501 } | 500 } |
| 502 } | 501 } |
| 503 | 502 |
| 504 //////////////////////////////////////////////////////////////////////////////// | 503 //////////////////////////////////////////////////////////////////////////////// |
| 505 // NativeWidgetGtk, Widget implementation: | 504 // NativeWidgetGtk implementation: |
| 506 | 505 |
| 507 void NativeWidgetGtk::ClearNativeFocus() { | 506 void NativeWidgetGtk::ClearNativeFocus() { |
| 508 DCHECK(!child_); | 507 DCHECK(!child_); |
| 509 if (!GetNativeView()) { | 508 if (!GetNativeView()) { |
| 510 NOTREACHED(); | 509 NOTREACHED(); |
| 511 return; | 510 return; |
| 512 } | 511 } |
| 513 gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); | 512 gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); |
| 514 } | 513 } |
| 515 | 514 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 538 (key.flags() & ~ui::EF_ALT_DOWN) == 0) { | 537 (key.flags() & ~ui::EF_ALT_DOWN) == 0) { |
| 539 // Trigger VKEY_MENU when only this key is pressed and released, and both | 538 // Trigger VKEY_MENU when only this key is pressed and released, and both |
| 540 // press and release events are not handled by others. | 539 // press and release events are not handled by others. |
| 541 Accelerator accelerator(ui::VKEY_MENU, false, false, false); | 540 Accelerator accelerator(ui::VKEY_MENU, false, false, false); |
| 542 handled = GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); | 541 handled = GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); |
| 543 } | 542 } |
| 544 | 543 |
| 545 return handled; | 544 return handled; |
| 546 } | 545 } |
| 547 | 546 |
| 547 bool NativeWidgetGtk::SuppressFreezeUpdates() { |
| 548 if (!painted_) { |
| 549 painted_ = true; |
| 550 return true; |
| 551 } |
| 552 return false; |
| 553 } |
| 554 |
| 548 // static | 555 // static |
| 549 void NativeWidgetGtk::EnableDebugPaint() { | 556 void NativeWidgetGtk::EnableDebugPaint() { |
| 550 debug_paint_enabled_ = true; | 557 gdk_window_set_debug_updates(true); |
| 551 } | 558 } |
| 552 | 559 |
| 553 // static | 560 // static |
| 554 void NativeWidgetGtk::UpdateFreezeUpdatesProperty(GtkWindow* window, | 561 void NativeWidgetGtk::UpdateFreezeUpdatesProperty(GtkWindow* window, |
| 555 bool enable) { | 562 bool enable) { |
| 556 if (!GTK_WIDGET_REALIZED(GTK_WIDGET(window))) | 563 if (!GTK_WIDGET_REALIZED(GTK_WIDGET(window))) |
| 557 gtk_widget_realize(GTK_WIDGET(window)); | 564 gtk_widget_realize(GTK_WIDGET(window)); |
| 558 GdkWindow* gdk_window = GTK_WIDGET(window)->window; | 565 GdkWindow* gdk_window = GTK_WIDGET(window)->window; |
| 559 | 566 |
| 560 static GdkAtom freeze_atom_ = | 567 static GdkAtom freeze_atom_ = |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 // Clear the background before drawing any view and native components. | 1182 // Clear the background before drawing any view and native components. |
| 1176 DrawTransparentBackground(widget, event); | 1183 DrawTransparentBackground(widget, event); |
| 1177 if (!CompositePainter::IsComposited(widget_) && | 1184 if (!CompositePainter::IsComposited(widget_) && |
| 1178 gdk_screen_is_composited(gdk_screen_get_default())) { | 1185 gdk_screen_is_composited(gdk_screen_get_default())) { |
| 1179 // Let the parent draw the content only after something is drawn on | 1186 // Let the parent draw the content only after something is drawn on |
| 1180 // the widget. | 1187 // the widget. |
| 1181 CompositePainter::SetComposited(widget_); | 1188 CompositePainter::SetComposited(widget_); |
| 1182 } | 1189 } |
| 1183 } | 1190 } |
| 1184 | 1191 |
| 1185 if (debug_paint_enabled_) { | |
| 1186 // Using cairo directly because using skia didn't have immediate effect. | |
| 1187 cairo_t* cr = gdk_cairo_create(event->window); | |
| 1188 gdk_cairo_region(cr, event->region); | |
| 1189 cairo_set_source_rgb(cr, 1, 0, 0); // red | |
| 1190 cairo_rectangle(cr, | |
| 1191 event->area.x, event->area.y, | |
| 1192 event->area.width, event->area.height); | |
| 1193 cairo_fill(cr); | |
| 1194 cairo_destroy(cr); | |
| 1195 // Make sure that users see the red flash. | |
| 1196 XSync(ui::GetXDisplay(), false /* don't discard events */); | |
| 1197 } | |
| 1198 | |
| 1199 ui::ScopedRegion region(gdk_region_copy(event->region)); | 1192 ui::ScopedRegion region(gdk_region_copy(event->region)); |
| 1200 if (!gdk_region_empty(region.Get())) { | 1193 if (!gdk_region_empty(region.Get())) { |
| 1201 GdkRectangle clip_bounds; | 1194 GdkRectangle clip_bounds; |
| 1202 gdk_region_get_clipbox(region.Get(), &clip_bounds); | 1195 gdk_region_get_clipbox(region.Get(), &clip_bounds); |
| 1203 if (!delegate_->OnNativeWidgetPaintAccelerated(gfx::Rect(clip_bounds))) { | 1196 if (!delegate_->OnNativeWidgetPaintAccelerated(gfx::Rect(clip_bounds))) { |
| 1204 gfx::CanvasSkiaPaint canvas(event); | 1197 gfx::CanvasSkiaPaint canvas(event); |
| 1205 if (!canvas.is_empty()) { | 1198 if (!canvas.is_empty()) { |
| 1206 canvas.set_composite_alpha(is_transparent()); | 1199 canvas.set_composite_alpha(is_transparent()); |
| 1207 delegate_->OnNativeWidgetPaint(&canvas); | 1200 delegate_->OnNativeWidgetPaint(&canvas); |
| 1208 } | 1201 } |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 | 1924 |
| 1932 // And now, notify them that they have a brand new parent. | 1925 // And now, notify them that they have a brand new parent. |
| 1933 for (NativeWidgets::iterator it = widgets.begin(); | 1926 for (NativeWidgets::iterator it = widgets.begin(); |
| 1934 it != widgets.end(); ++it) { | 1927 it != widgets.end(); ++it) { |
| 1935 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, | 1928 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, |
| 1936 new_parent); | 1929 new_parent); |
| 1937 } | 1930 } |
| 1938 } | 1931 } |
| 1939 | 1932 |
| 1940 } // namespace views | 1933 } // namespace views |
| OLD | NEW |