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