| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 // static | 278 // static |
| 279 GtkWidget* NativeWidgetGtk::null_parent_ = NULL; | 279 GtkWidget* NativeWidgetGtk::null_parent_ = NULL; |
| 280 bool NativeWidgetGtk::debug_paint_enabled_ = false; | 280 bool NativeWidgetGtk::debug_paint_enabled_ = false; |
| 281 | 281 |
| 282 //////////////////////////////////////////////////////////////////////////////// | 282 //////////////////////////////////////////////////////////////////////////////// |
| 283 // NativeWidgetGtk, public: | 283 // NativeWidgetGtk, public: |
| 284 | 284 |
| 285 NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate) | 285 NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate) |
| 286 : is_window_(false), | 286 : is_window_(false), |
| 287 window_state_(GDK_WINDOW_STATE_WITHDRAWN), |
| 287 delegate_(delegate), | 288 delegate_(delegate), |
| 288 widget_(NULL), | 289 widget_(NULL), |
| 289 window_contents_(NULL), | 290 window_contents_(NULL), |
| 290 child_(false), | 291 child_(false), |
| 291 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 292 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
| 292 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 293 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 293 transparent_(false), | 294 transparent_(false), |
| 294 ignore_events_(false), | 295 ignore_events_(false), |
| 295 ignore_drag_leave_(false), | 296 ignore_drag_leave_(false), |
| 296 opacity_(255), | 297 opacity_(255), |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 g_signal_connect(window_contents_, "drag_drop", | 710 g_signal_connect(window_contents_, "drag_drop", |
| 710 G_CALLBACK(&OnDragDropThunk), this); | 711 G_CALLBACK(&OnDragDropThunk), this); |
| 711 g_signal_connect(window_contents_, "drag_leave", | 712 g_signal_connect(window_contents_, "drag_leave", |
| 712 G_CALLBACK(&OnDragLeaveThunk), this); | 713 G_CALLBACK(&OnDragLeaveThunk), this); |
| 713 g_signal_connect(window_contents_, "drag_data_get", | 714 g_signal_connect(window_contents_, "drag_data_get", |
| 714 G_CALLBACK(&OnDragDataGetThunk), this); | 715 G_CALLBACK(&OnDragDataGetThunk), this); |
| 715 g_signal_connect(window_contents_, "drag_end", | 716 g_signal_connect(window_contents_, "drag_end", |
| 716 G_CALLBACK(&OnDragEndThunk), this); | 717 G_CALLBACK(&OnDragEndThunk), this); |
| 717 g_signal_connect(window_contents_, "drag_failed", | 718 g_signal_connect(window_contents_, "drag_failed", |
| 718 G_CALLBACK(&OnDragFailedThunk), this); | 719 G_CALLBACK(&OnDragFailedThunk), this); |
| 720 g_signal_connect(G_OBJECT(widget_), "window-state-event", |
| 721 G_CALLBACK(&OnWindowStateEventThunk), this); |
| 719 | 722 |
| 720 tooltip_manager_.reset(new TooltipManagerGtk(this)); | 723 tooltip_manager_.reset(new TooltipManagerGtk(this)); |
| 721 | 724 |
| 722 // Register for tooltips. | 725 // Register for tooltips. |
| 723 g_object_set(G_OBJECT(window_contents_), "has-tooltip", TRUE, NULL); | 726 g_object_set(G_OBJECT(window_contents_), "has-tooltip", TRUE, NULL); |
| 724 g_signal_connect(window_contents_, "query_tooltip", | 727 g_signal_connect(window_contents_, "query_tooltip", |
| 725 G_CALLBACK(&OnQueryTooltipThunk), this); | 728 G_CALLBACK(&OnQueryTooltipThunk), this); |
| 726 | 729 |
| 727 if (child_) { | 730 if (child_) { |
| 728 if (parent) | 731 if (parent) |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 } | 953 } |
| 951 | 954 |
| 952 void NativeWidgetGtk::Hide() { | 955 void NativeWidgetGtk::Hide() { |
| 953 if (widget_) { | 956 if (widget_) { |
| 954 gtk_widget_hide(widget_); | 957 gtk_widget_hide(widget_); |
| 955 if (widget_->window) | 958 if (widget_->window) |
| 956 gdk_window_lower(widget_->window); | 959 gdk_window_lower(widget_->window); |
| 957 } | 960 } |
| 958 } | 961 } |
| 959 | 962 |
| 960 void NativeWidgetGtk::SetOpacity(unsigned char opacity) { | 963 bool NativeWidgetGtk::IsVisible() const { |
| 961 opacity_ = opacity; | 964 return GTK_WIDGET_VISIBLE(GetNativeView()); |
| 962 if (widget_) { | 965 } |
| 963 // We can only set the opacity when the widget has been realized. | 966 |
| 964 gdk_window_set_opacity(widget_->window, static_cast<gdouble>(opacity) / | 967 void NativeWidgetGtk::Activate() { |
| 965 static_cast<gdouble>(255)); | 968 gtk_window_present(GetNativeWindow()); |
| 966 } | 969 } |
| 970 |
| 971 void NativeWidgetGtk::Deactivate() { |
| 972 gdk_window_lower(GTK_WIDGET(GetNativeView())->window); |
| 973 } |
| 974 |
| 975 bool NativeWidgetGtk::IsActive() const { |
| 976 DCHECK(!child_); |
| 977 return is_active_; |
| 967 } | 978 } |
| 968 | 979 |
| 969 void NativeWidgetGtk::SetAlwaysOnTop(bool on_top) { | 980 void NativeWidgetGtk::SetAlwaysOnTop(bool on_top) { |
| 970 DCHECK(!child_); | 981 DCHECK(!child_); |
| 971 always_on_top_ = on_top; | 982 always_on_top_ = on_top; |
| 972 if (widget_) | 983 if (widget_) |
| 973 gtk_window_set_keep_above(GTK_WINDOW(widget_), on_top); | 984 gtk_window_set_keep_above(GTK_WINDOW(widget_), on_top); |
| 974 } | 985 } |
| 975 | 986 |
| 976 bool NativeWidgetGtk::IsVisible() const { | 987 void NativeWidgetGtk::Maximize() { |
| 977 return GTK_WIDGET_VISIBLE(widget_); | 988 gtk_window_maximize(GetNativeWindow()); |
| 978 } | 989 } |
| 979 | 990 |
| 980 bool NativeWidgetGtk::IsActive() const { | 991 void NativeWidgetGtk::Minimize() { |
| 981 DCHECK(!child_); | 992 gtk_window_iconify(GetNativeWindow()); |
| 982 return is_active_; | 993 } |
| 994 |
| 995 bool NativeWidgetGtk::IsMaximized() const { |
| 996 return window_state_ & GDK_WINDOW_STATE_MAXIMIZED; |
| 997 } |
| 998 |
| 999 bool NativeWidgetGtk::IsMinimized() const { |
| 1000 return window_state_ & GDK_WINDOW_STATE_ICONIFIED; |
| 1001 } |
| 1002 |
| 1003 void NativeWidgetGtk::Restore() { |
| 1004 if (IsMaximized()) |
| 1005 gtk_window_unmaximize(GetNativeWindow()); |
| 1006 else if (IsMinimized()) |
| 1007 gtk_window_deiconify(GetNativeWindow()); |
| 1008 } |
| 1009 |
| 1010 void NativeWidgetGtk::SetOpacity(unsigned char opacity) { |
| 1011 opacity_ = opacity; |
| 1012 if (widget_) { |
| 1013 // We can only set the opacity when the widget has been realized. |
| 1014 gdk_window_set_opacity(widget_->window, static_cast<gdouble>(opacity) / |
| 1015 static_cast<gdouble>(255)); |
| 1016 } |
| 983 } | 1017 } |
| 984 | 1018 |
| 985 bool NativeWidgetGtk::IsAccessibleWidget() const { | 1019 bool NativeWidgetGtk::IsAccessibleWidget() const { |
| 986 return false; | 1020 return false; |
| 987 } | 1021 } |
| 988 | 1022 |
| 989 bool NativeWidgetGtk::ContainsNativeView(gfx::NativeView native_view) const { | 1023 bool NativeWidgetGtk::ContainsNativeView(gfx::NativeView native_view) const { |
| 990 // TODO(port) See implementation in NativeWidgetWin::ContainsNativeView. | 1024 // TODO(port) See implementation in NativeWidgetWin::ContainsNativeView. |
| 991 NOTREACHED() << "NativeWidgetGtk::ContainsNativeView is not implemented."; | 1025 NOTREACHED() << "NativeWidgetGtk::ContainsNativeView is not implemented."; |
| 992 return false; | 1026 return false; |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 // a bug in message_pump_glib_x.cc as we do get X Expose event but | 1388 // a bug in message_pump_glib_x.cc as we do get X Expose event but |
| 1355 // it doesn't trigger gtk's expose signal. We're not going to fix this | 1389 // it doesn't trigger gtk's expose signal. We're not going to fix this |
| 1356 // as we're removing gtk and migrating to new compositor. | 1390 // as we're removing gtk and migrating to new compositor. |
| 1357 gdk_window_process_all_updates(); | 1391 gdk_window_process_all_updates(); |
| 1358 #endif | 1392 #endif |
| 1359 } | 1393 } |
| 1360 | 1394 |
| 1361 void NativeWidgetGtk::OnHide(GtkWidget* widget) { | 1395 void NativeWidgetGtk::OnHide(GtkWidget* widget) { |
| 1362 } | 1396 } |
| 1363 | 1397 |
| 1398 gboolean NativeWidgetGtk::OnWindowStateEvent(GtkWidget* widget, |
| 1399 GdkEventWindowState* event) { |
| 1400 window_state_ = event->new_window_state; |
| 1401 return FALSE; |
| 1402 } |
| 1403 |
| 1364 void NativeWidgetGtk::HandleXGrabBroke() { | 1404 void NativeWidgetGtk::HandleXGrabBroke() { |
| 1365 } | 1405 } |
| 1366 | 1406 |
| 1367 void NativeWidgetGtk::HandleGtkGrabBroke() { | 1407 void NativeWidgetGtk::HandleGtkGrabBroke() { |
| 1368 delegate_->OnMouseCaptureLost(); | 1408 delegate_->OnMouseCaptureLost(); |
| 1369 } | 1409 } |
| 1370 | 1410 |
| 1371 //////////////////////////////////////////////////////////////////////////////// | 1411 //////////////////////////////////////////////////////////////////////////////// |
| 1372 // NativeWidgetGtk, private: | 1412 // NativeWidgetGtk, private: |
| 1373 | 1413 |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 | 1846 |
| 1807 // And now, notify them that they have a brand new parent. | 1847 // And now, notify them that they have a brand new parent. |
| 1808 for (NativeWidgets::iterator it = widgets.begin(); | 1848 for (NativeWidgets::iterator it = widgets.begin(); |
| 1809 it != widgets.end(); ++it) { | 1849 it != widgets.end(); ++it) { |
| 1810 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, | 1850 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, |
| 1811 new_parent); | 1851 new_parent); |
| 1812 } | 1852 } |
| 1813 } | 1853 } |
| 1814 | 1854 |
| 1815 } // namespace views | 1855 } // namespace views |
| OLD | NEW |