Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: views/widget/native_widget_gtk.cc

Issue 7054052: Move more from Window onto Widget. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/widget/native_widget_gtk.h ('k') | views/widget/native_widget_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 439
440 drag_data_ = NULL; 440 drag_data_ = NULL;
441 441
442 if (drag_icon_widget) { 442 if (drag_icon_widget) {
443 gtk_widget_destroy(drag_icon_widget); 443 gtk_widget_destroy(drag_icon_widget);
444 g_object_unref(provider.drag_image()); 444 g_object_unref(provider.drag_image());
445 } 445 }
446 } 446 }
447 447
448 void NativeWidgetGtk::IsActiveChanged() { 448 void NativeWidgetGtk::IsActiveChanged() {
449 GetWidget()->widget_delegate()->OnWidgetActivated(IsActive()); 449 delegate_->OnNativeWidgetActivationChanged(IsActive());
450 } 450 }
451 451
452 void NativeWidgetGtk::SetInitialFocus() { 452 void NativeWidgetGtk::SetInitialFocus() {
453 if (!focus_on_creation_) 453 if (!focus_on_creation_)
454 return; 454 return;
455 455
456 View* v = GetWidget()->widget_delegate()->GetInitiallyFocusedView(); 456 View* v = GetWidget()->widget_delegate()->GetInitiallyFocusedView();
457 if (v) 457 if (v)
458 v->RequestFocus(); 458 v->RequestFocus();
459 } 459 }
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 // enough for our uses. 913 // enough for our uses.
914 gtk_window_get_size(GTK_WINDOW(widget_), &w, &h); 914 gtk_window_get_size(GTK_WINDOW(widget_), &w, &h);
915 } else { 915 } else {
916 GetWidgetPositionOnScreen(widget_, &x, &y); 916 GetWidgetPositionOnScreen(widget_, &x, &y);
917 w = widget_->allocation.width; 917 w = widget_->allocation.width;
918 h = widget_->allocation.height; 918 h = widget_->allocation.height;
919 } 919 }
920 return gfx::Rect(x, y, w, h); 920 return gfx::Rect(x, y, w, h);
921 } 921 }
922 922
923 gfx::Rect NativeWidgetGtk::GetRestoredBounds() const {
924 // We currently don't support tiling, so this doesn't matter.
925 return GetWindowScreenBounds();
926 }
927
923 void NativeWidgetGtk::SetBounds(const gfx::Rect& bounds) { 928 void NativeWidgetGtk::SetBounds(const gfx::Rect& bounds) {
924 if (child_) { 929 if (child_) {
925 GtkWidget* parent = gtk_widget_get_parent(widget_); 930 GtkWidget* parent = gtk_widget_get_parent(widget_);
926 if (GTK_IS_VIEWS_FIXED(parent)) { 931 if (GTK_IS_VIEWS_FIXED(parent)) {
927 NativeWidgetGtk* parent_widget = static_cast<NativeWidgetGtk*>( 932 NativeWidgetGtk* parent_widget = static_cast<NativeWidgetGtk*>(
928 NativeWidget::GetNativeWidgetForNativeView(parent)); 933 NativeWidget::GetNativeWidgetForNativeView(parent));
929 parent_widget->PositionChild(widget_, bounds.x(), bounds.y(), 934 parent_widget->PositionChild(widget_, bounds.x(), bounds.y(),
930 bounds.width(), bounds.height()); 935 bounds.width(), bounds.height());
931 } else { 936 } else {
932 DCHECK(GTK_IS_FIXED(parent)) 937 DCHECK(GTK_IS_FIXED(parent))
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 } 1011 }
1007 } 1012 }
1008 1013
1009 void NativeWidgetGtk::CloseNow() { 1014 void NativeWidgetGtk::CloseNow() {
1010 if (widget_) { 1015 if (widget_) {
1011 input_method_.reset(); 1016 input_method_.reset();
1012 gtk_widget_destroy(widget_); // Triggers OnDestroy(). 1017 gtk_widget_destroy(widget_); // Triggers OnDestroy().
1013 } 1018 }
1014 } 1019 }
1015 1020
1021 void NativeWidgetGtk::EnableClose(bool enable) {
1022 gtk_window_set_deletable(GetNativeWindow(), enable);
1023 }
1024
1016 void NativeWidgetGtk::Show() { 1025 void NativeWidgetGtk::Show() {
1017 if (widget_) { 1026 if (widget_) {
1018 gtk_widget_show(widget_); 1027 gtk_widget_show(widget_);
1019 if (widget_->window) 1028 if (widget_->window)
1020 gdk_window_raise(widget_->window); 1029 gdk_window_raise(widget_->window);
1021 } 1030 }
1022 } 1031 }
1023 1032
1024 void NativeWidgetGtk::Hide() { 1033 void NativeWidgetGtk::Hide() {
1025 if (widget_) { 1034 if (widget_) {
1026 gtk_widget_hide(widget_); 1035 gtk_widget_hide(widget_);
1027 if (widget_->window) 1036 if (widget_->window)
1028 gdk_window_lower(widget_->window); 1037 gdk_window_lower(widget_->window);
1029 } 1038 }
1030 } 1039 }
1031 1040
1041 void NativeWidgetGtk::ShowNativeWidget(ShowState state) {
1042 // No concept of maximization (yet) on ChromeOS.
1043 if (state == NativeWidget::SHOW_INACTIVE)
1044 gtk_window_set_focus_on_map(GetNativeWindow(), false);
1045 gtk_widget_show(GetNativeView());
1046 }
1047
1032 bool NativeWidgetGtk::IsVisible() const { 1048 bool NativeWidgetGtk::IsVisible() const {
1033 return GTK_WIDGET_VISIBLE(GetNativeView()); 1049 return GTK_WIDGET_VISIBLE(GetNativeView());
1034 } 1050 }
1035 1051
1036 void NativeWidgetGtk::Activate() { 1052 void NativeWidgetGtk::Activate() {
1037 gtk_window_present(GetNativeWindow()); 1053 gtk_window_present(GetNativeWindow());
1038 } 1054 }
1039 1055
1040 void NativeWidgetGtk::Deactivate() { 1056 void NativeWidgetGtk::Deactivate() {
1041 gdk_window_lower(GTK_WIDGET(GetNativeView())->window); 1057 gdk_window_lower(GTK_WIDGET(GetNativeView())->window);
(...skipping 21 matching lines...) Expand all
1063 1079
1064 bool NativeWidgetGtk::IsMaximized() const { 1080 bool NativeWidgetGtk::IsMaximized() const {
1065 return window_state_ & GDK_WINDOW_STATE_MAXIMIZED; 1081 return window_state_ & GDK_WINDOW_STATE_MAXIMIZED;
1066 } 1082 }
1067 1083
1068 bool NativeWidgetGtk::IsMinimized() const { 1084 bool NativeWidgetGtk::IsMinimized() const {
1069 return window_state_ & GDK_WINDOW_STATE_ICONIFIED; 1085 return window_state_ & GDK_WINDOW_STATE_ICONIFIED;
1070 } 1086 }
1071 1087
1072 void NativeWidgetGtk::Restore() { 1088 void NativeWidgetGtk::Restore() {
1073 if (IsMaximized()) 1089 if (IsFullscreen()) {
1074 gtk_window_unmaximize(GetNativeWindow()); 1090 SetFullscreen(false);
1075 else if (IsMinimized()) 1091 } else {
1076 gtk_window_deiconify(GetNativeWindow()); 1092 if (IsMaximized())
1093 gtk_window_unmaximize(GetNativeWindow());
1094 else if (IsMinimized())
1095 gtk_window_deiconify(GetNativeWindow());
1096 }
1077 } 1097 }
1078 1098
1079 void NativeWidgetGtk::SetFullscreen(bool fullscreen) { 1099 void NativeWidgetGtk::SetFullscreen(bool fullscreen) {
1080 if (fullscreen) 1100 if (fullscreen)
1081 gtk_window_fullscreen(GetNativeWindow()); 1101 gtk_window_fullscreen(GetNativeWindow());
1082 else 1102 else
1083 gtk_window_unfullscreen(GetNativeWindow()); 1103 gtk_window_unfullscreen(GetNativeWindow());
1084 } 1104 }
1085 1105
1086 bool NativeWidgetGtk::IsFullscreen() const { 1106 bool NativeWidgetGtk::IsFullscreen() const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 void NativeWidgetGtk::OnSizeAllocate(GtkWidget* widget, 1180 void NativeWidgetGtk::OnSizeAllocate(GtkWidget* widget,
1161 GtkAllocation* allocation) { 1181 GtkAllocation* allocation) {
1162 // See comment next to size_ as to why we do this. Also note, it's tempting 1182 // See comment next to size_ as to why we do this. Also note, it's tempting
1163 // to put this in the static method so subclasses don't need to worry about 1183 // to put this in the static method so subclasses don't need to worry about
1164 // it, but if a subclasses needs to set a shape then they need to always 1184 // it, but if a subclasses needs to set a shape then they need to always
1165 // reset the shape in this method regardless of whether the size changed. 1185 // reset the shape in this method regardless of whether the size changed.
1166 gfx::Size new_size(allocation->width, allocation->height); 1186 gfx::Size new_size(allocation->width, allocation->height);
1167 if (new_size == size_) 1187 if (new_size == size_)
1168 return; 1188 return;
1169 size_ = new_size; 1189 size_ = new_size;
1170 delegate_->OnSizeChanged(size_); 1190 delegate_->OnNativeWidgetSizeChanged(size_);
1171 } 1191 }
1172 1192
1173 gboolean NativeWidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { 1193 gboolean NativeWidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) {
1174 if (transparent_ && child_) { 1194 if (transparent_ && child_) {
1175 // Clear the background before drawing any view and native components. 1195 // Clear the background before drawing any view and native components.
1176 DrawTransparentBackground(widget, event); 1196 DrawTransparentBackground(widget, event);
1177 if (!CompositePainter::IsComposited(widget_) && 1197 if (!CompositePainter::IsComposited(widget_) &&
1178 gdk_screen_is_composited(gdk_screen_get_default())) { 1198 gdk_screen_is_composited(gdk_screen_get_default())) {
1179 // Let the parent draw the content only after something is drawn on 1199 // Let the parent draw the content only after something is drawn on
1180 // the widget. 1200 // the widget.
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 } 1460 }
1441 1461
1442 void NativeWidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { 1462 void NativeWidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) {
1443 if (!window_contents_) 1463 if (!window_contents_)
1444 return; // Grab broke after window destroyed, don't try processing it. 1464 return; // Grab broke after window destroyed, don't try processing it.
1445 gtk_grab_remove(window_contents_); 1465 gtk_grab_remove(window_contents_);
1446 HandleGtkGrabBroke(); 1466 HandleGtkGrabBroke();
1447 } 1467 }
1448 1468
1449 void NativeWidgetGtk::OnDestroy(GtkWidget* object) { 1469 void NativeWidgetGtk::OnDestroy(GtkWidget* object) {
1470 delegate_->OnNativeWidgetDestroying();
1450 if (!child_) 1471 if (!child_)
1451 ActiveWindowWatcherX::RemoveObserver(this); 1472 ActiveWindowWatcherX::RemoveObserver(this);
1452 // Note that this handler is hooked to GtkObject::destroy. 1473 // Note that this handler is hooked to GtkObject::destroy.
1453 // NULL out pointers here since we might still be in an observer list 1474 // NULL out pointers here since we might still be in an observer list
1454 // until deletion happens. 1475 // until deletion happens.
1455 widget_ = window_contents_ = NULL; 1476 widget_ = window_contents_ = NULL;
1456 } 1477 }
1457 1478
1458 void NativeWidgetGtk::OnDestroyed(GObject *where_the_object_was) { 1479 void NativeWidgetGtk::OnDestroyed(GObject *where_the_object_was) {
1459 delegate_->OnNativeWidgetDestroyed(); 1480 delegate_->OnNativeWidgetDestroyed();
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 1952
1932 // And now, notify them that they have a brand new parent. 1953 // And now, notify them that they have a brand new parent.
1933 for (NativeWidgets::iterator it = widgets.begin(); 1954 for (NativeWidgets::iterator it = widgets.begin();
1934 it != widgets.end(); ++it) { 1955 it != widgets.end(); ++it) {
1935 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, 1956 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true,
1936 new_parent); 1957 new_parent);
1937 } 1958 }
1938 } 1959 }
1939 1960
1940 } // namespace views 1961 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/native_widget_gtk.h ('k') | views/widget/native_widget_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698