| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/widget_gtk.h" | 5 #include "views/widget/widget_gtk.h" |
| 6 | 6 |
| 7 #include "app/gfx/path.h" | 7 #include "app/gfx/path.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "views/fill_layout.h" | 9 #include "views/fill_layout.h" |
| 10 #include "views/widget/default_theme_provider.h" | 10 #include "views/widget/default_theme_provider.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 const gfx::Rect& bounds, | 80 const gfx::Rect& bounds, |
| 81 bool has_own_focus_manager) { | 81 bool has_own_focus_manager) { |
| 82 // Force creation of the RootView if it hasn't been created yet. | 82 // Force creation of the RootView if it hasn't been created yet. |
| 83 GetRootView(); | 83 GetRootView(); |
| 84 | 84 |
| 85 #if !defined(LINUX2) | 85 #if !defined(LINUX2) |
| 86 default_theme_provider_.reset(new DefaultThemeProvider()); | 86 default_theme_provider_.reset(new DefaultThemeProvider()); |
| 87 #endif | 87 #endif |
| 88 | 88 |
| 89 // Make container here. | 89 // Make container here. |
| 90 CreateGtkWidget(parent); | 90 CreateGtkWidget(parent, bounds); |
| 91 | 91 |
| 92 // Make sure we receive our motion events. | 92 // Make sure we receive our motion events. |
| 93 | 93 |
| 94 // In general we register most events on the parent of all widgets. At a | 94 // In general we register most events on the parent of all widgets. At a |
| 95 // minimum we need painting to happen on the parent (otherwise painting | 95 // minimum we need painting to happen on the parent (otherwise painting |
| 96 // doesn't work at all), and similarly we need mouse release events on the | 96 // doesn't work at all), and similarly we need mouse release events on the |
| 97 // parent as windows don't get mouse releases. | 97 // parent as windows don't get mouse releases. |
| 98 gtk_widget_add_events(window_contents_, | 98 gtk_widget_add_events(window_contents_, |
| 99 GDK_ENTER_NOTIFY_MASK | | 99 GDK_ENTER_NOTIFY_MASK | |
| 100 GDK_LEAVE_NOTIFY_MASK | | 100 GDK_LEAVE_NOTIFY_MASK | |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // WidgetGtk, MessageLoopForUI::Observer implementation: | 396 // WidgetGtk, MessageLoopForUI::Observer implementation: |
| 397 | 397 |
| 398 void WidgetGtk::DidProcessEvent(GdkEvent* event) { | 398 void WidgetGtk::DidProcessEvent(GdkEvent* event) { |
| 399 if (root_view_->NeedsPainting(true)) | 399 if (root_view_->NeedsPainting(true)) |
| 400 PaintNow(root_view_->GetScheduledPaintRect()); | 400 PaintNow(root_view_->GetScheduledPaintRect()); |
| 401 } | 401 } |
| 402 | 402 |
| 403 //////////////////////////////////////////////////////////////////////////////// | 403 //////////////////////////////////////////////////////////////////////////////// |
| 404 // TODO(beng): organize into sections: | 404 // TODO(beng): organize into sections: |
| 405 | 405 |
| 406 void WidgetGtk::CreateGtkWidget(GtkWidget* parent) { | 406 void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { |
| 407 if (type_ == TYPE_CHILD) { | 407 if (type_ == TYPE_CHILD) { |
| 408 window_contents_ = widget_ = gtk_fixed_new(); | 408 window_contents_ = widget_ = gtk_fixed_new(); |
| 409 gtk_fixed_set_has_window(GTK_FIXED(widget_), true); | 409 gtk_fixed_set_has_window(GTK_FIXED(widget_), true); |
| 410 if (!parent && !null_parent_) { | 410 if (!parent && !null_parent_) { |
| 411 GtkWidget* popup = gtk_window_new(GTK_WINDOW_POPUP); | 411 GtkWidget* popup = gtk_window_new(GTK_WINDOW_POPUP); |
| 412 null_parent_ = gtk_fixed_new(); | 412 null_parent_ = gtk_fixed_new(); |
| 413 gtk_container_add(GTK_CONTAINER(popup), null_parent_); | 413 gtk_container_add(GTK_CONTAINER(popup), null_parent_); |
| 414 gtk_widget_realize(null_parent_); | 414 gtk_widget_realize(null_parent_); |
| 415 } | 415 } |
| 416 gtk_container_add(GTK_CONTAINER(parent ? parent : null_parent_), widget_); | 416 gtk_container_add(GTK_CONTAINER(parent ? parent : null_parent_), widget_); |
| 417 SetViewForNative(widget_, this); | 417 SetViewForNative(widget_, this); |
| 418 } else { | 418 } else { |
| 419 widget_ = gtk_window_new( | 419 widget_ = gtk_window_new( |
| 420 type_ == TYPE_WINDOW ? GTK_WINDOW_TOPLEVEL : GTK_WINDOW_POPUP); | 420 type_ == TYPE_WINDOW ? GTK_WINDOW_TOPLEVEL : GTK_WINDOW_POPUP); |
| 421 |
| 422 if (!bounds.size().IsEmpty()) { |
| 423 // When we realize the window, the window manager is given a size. If we |
| 424 // don't specify a size before then GTK defaults to 200x200. Specify |
| 425 // a size now so that the window manager sees the requested size. |
| 426 GtkAllocation alloc = { 0, 0, bounds.width(), bounds.height() }; |
| 427 gtk_widget_size_allocate(widget_, &alloc); |
| 428 } |
| 421 gtk_window_set_decorated(GTK_WINDOW(widget_), false); | 429 gtk_window_set_decorated(GTK_WINDOW(widget_), false); |
| 422 // We'll take care of positioning our window. | 430 // We'll take care of positioning our window. |
| 423 gtk_window_set_position(GTK_WINDOW(widget_), GTK_WIN_POS_NONE); | 431 gtk_window_set_position(GTK_WINDOW(widget_), GTK_WIN_POS_NONE); |
| 424 SetWindowForNative(widget_, static_cast<WindowGtk*>(this)); | 432 SetWindowForNative(widget_, static_cast<WindowGtk*>(this)); |
| 425 SetViewForNative(widget_, this); | 433 SetViewForNative(widget_, this); |
| 426 | 434 |
| 427 window_contents_ = gtk_fixed_new(); | 435 window_contents_ = gtk_fixed_new(); |
| 428 gtk_fixed_set_has_window(GTK_FIXED(window_contents_), true); | 436 gtk_fixed_set_has_window(GTK_FIXED(window_contents_), true); |
| 429 gtk_container_add(GTK_CONTAINER(widget_), window_contents_); | 437 gtk_container_add(GTK_CONTAINER(widget_), window_contents_); |
| 430 gtk_widget_show(window_contents_); | 438 gtk_widget_show(window_contents_); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 void WidgetGtk::HandleGrabBroke() { | 822 void WidgetGtk::HandleGrabBroke() { |
| 815 if (has_capture_) { | 823 if (has_capture_) { |
| 816 if (is_mouse_down_) | 824 if (is_mouse_down_) |
| 817 root_view_->ProcessMouseDragCanceled(); | 825 root_view_->ProcessMouseDragCanceled(); |
| 818 is_mouse_down_ = false; | 826 is_mouse_down_ = false; |
| 819 has_capture_ = false; | 827 has_capture_ = false; |
| 820 } | 828 } |
| 821 } | 829 } |
| 822 | 830 |
| 823 } // namespace views | 831 } // namespace views |
| OLD | NEW |