OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_gtk.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" |
6 | 6 |
7 // If this gets included after the gtk headers, then a bunch of compiler | 7 // If this gets included after the gtk headers, then a bunch of compiler |
8 // errors happen because of a "#define Status int" in Xlib.h, which interacts | 8 // errors happen because of a "#define Status int" in Xlib.h, which interacts |
9 // badly with net::URLRequestStatus::Status. | 9 // badly with net::URLRequestStatus::Status. |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 #include "content/browser/renderer_host/render_view_host_impl.h" | 36 #include "content/browser/renderer_host/render_view_host_impl.h" |
37 #include "content/common/gpu/gpu_messages.h" | 37 #include "content/common/gpu/gpu_messages.h" |
38 #include "content/public/browser/native_web_keyboard_event.h" | 38 #include "content/public/browser/native_web_keyboard_event.h" |
39 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
42 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact ory.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact ory.h" |
43 #include "third_party/WebKit/Source/WebKit/chromium/public/x11/WebScreenInfoFact ory.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/x11/WebScreenInfoFact ory.h" |
44 #include "ui/base/gtk/gtk_compat.h" | 44 #include "ui/base/gtk/gtk_compat.h" |
45 #include "ui/base/text/text_elider.h" | 45 #include "ui/base/text/text_elider.h" |
46 #include "ui/base/x/active_window_watcher_x.h" | |
46 #include "ui/base/x/x11_util.h" | 47 #include "ui/base/x/x11_util.h" |
47 #include "ui/gfx/gtk_native_view_id_manager.h" | 48 #include "ui/gfx/gtk_native_view_id_manager.h" |
48 #include "ui/gfx/gtk_preserve_window.h" | 49 #include "ui/gfx/gtk_preserve_window.h" |
49 #include "webkit/glue/webcursor_gtk_data.h" | 50 #include "webkit/glue/webcursor_gtk_data.h" |
50 #include "webkit/plugins/npapi/webplugin.h" | 51 #include "webkit/plugins/npapi/webplugin.h" |
51 | 52 |
52 namespace { | 53 namespace { |
53 | 54 |
54 // Paint rects on Linux are bounded by the maximum size of a shared memory | 55 // Paint rects on Linux are bounded by the maximum size of a shared memory |
55 // region. By default that's 32MB, but many distros increase it significantly | 56 // region. By default that's 32MB, but many distros increase it significantly |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 content::RenderWidgetHost* widget_host) | 568 content::RenderWidgetHost* widget_host) |
568 : host_(RenderWidgetHostImpl::From(widget_host)), | 569 : host_(RenderWidgetHostImpl::From(widget_host)), |
569 about_to_validate_and_paint_(false), | 570 about_to_validate_and_paint_(false), |
570 is_hidden_(false), | 571 is_hidden_(false), |
571 is_loading_(false), | 572 is_loading_(false), |
572 parent_(NULL), | 573 parent_(NULL), |
573 is_popup_first_mouse_release_(true), | 574 is_popup_first_mouse_release_(true), |
574 was_imcontext_focused_before_grab_(false), | 575 was_imcontext_focused_before_grab_(false), |
575 do_x_grab_(false), | 576 do_x_grab_(false), |
576 is_fullscreen_(false), | 577 is_fullscreen_(false), |
578 made_active_(false), | |
Daniel Erat
2012/06/13 19:18:43
actually, having this variable contain false infor
| |
577 destroy_handler_id_(0), | 579 destroy_handler_id_(0), |
578 dragged_at_horizontal_edge_(0), | 580 dragged_at_horizontal_edge_(0), |
579 dragged_at_vertical_edge_(0), | 581 dragged_at_vertical_edge_(0), |
580 compositing_surface_(gfx::kNullPluginWindow), | 582 compositing_surface_(gfx::kNullPluginWindow), |
581 last_mouse_down_(NULL) { | 583 last_mouse_down_(NULL) { |
582 host_->SetView(this); | 584 host_->SetView(this); |
583 } | 585 } |
584 | 586 |
585 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { | 587 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { |
586 UnlockMouse(); | 588 UnlockMouse(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 } | 654 } |
653 | 655 |
654 void RenderWidgetHostViewGtk::InitAsFullscreen( | 656 void RenderWidgetHostViewGtk::InitAsFullscreen( |
655 RenderWidgetHostView* /*reference_host_view*/) { | 657 RenderWidgetHostView* /*reference_host_view*/) { |
656 DoSharedInit(); | 658 DoSharedInit(); |
657 | 659 |
658 is_fullscreen_ = true; | 660 is_fullscreen_ = true; |
659 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 661 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
660 gtk_window_set_decorated(window, FALSE); | 662 gtk_window_set_decorated(window, FALSE); |
661 gtk_window_fullscreen(window); | 663 gtk_window_fullscreen(window); |
662 g_signal_connect(GTK_WIDGET(window), | |
663 "window-state-event", | |
664 G_CALLBACK(&OnWindowStateEventThunk), | |
665 this); | |
666 destroy_handler_id_ = g_signal_connect(GTK_WIDGET(window), | 664 destroy_handler_id_ = g_signal_connect(GTK_WIDGET(window), |
667 "destroy", | 665 "destroy", |
668 G_CALLBACK(OnDestroyThunk), | 666 G_CALLBACK(OnDestroyThunk), |
669 this); | 667 this); |
670 gtk_container_add(GTK_CONTAINER(window), view_.get()); | 668 gtk_container_add(GTK_CONTAINER(window), view_.get()); |
671 | 669 |
670 ui::ActiveWindowWatcherX::AddObserver(this); | |
671 | |
672 // Try to move and resize the window to cover the screen in case the window | 672 // Try to move and resize the window to cover the screen in case the window |
673 // manager doesn't support _NET_WM_STATE_FULLSCREEN. | 673 // manager doesn't support _NET_WM_STATE_FULLSCREEN. |
674 GdkScreen* screen = gtk_window_get_screen(window); | 674 GdkScreen* screen = gtk_window_get_screen(window); |
675 gfx::Rect bounds( | 675 gfx::Rect bounds( |
676 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen)); | 676 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen)); |
677 DoPopupOrFullscreenInit(window, bounds); | 677 DoPopupOrFullscreenInit(window, bounds); |
678 } | 678 } |
679 | 679 |
680 content::RenderWidgetHost* | 680 content::RenderWidgetHost* |
681 RenderWidgetHostViewGtk::GetRenderWidgetHost() const { | 681 RenderWidgetHostViewGtk::GetRenderWidgetHost() const { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 void RenderWidgetHostViewGtk::Blur() { | 759 void RenderWidgetHostViewGtk::Blur() { |
760 // TODO(estade): We should be clearing native focus as well, but I know of no | 760 // TODO(estade): We should be clearing native focus as well, but I know of no |
761 // way to do that without focusing another widget. | 761 // way to do that without focusing another widget. |
762 host_->Blur(); | 762 host_->Blur(); |
763 } | 763 } |
764 | 764 |
765 bool RenderWidgetHostViewGtk::HasFocus() const { | 765 bool RenderWidgetHostViewGtk::HasFocus() const { |
766 return gtk_widget_is_focus(view_.get()); | 766 return gtk_widget_is_focus(view_.get()); |
767 } | 767 } |
768 | 768 |
769 void RenderWidgetHostViewGtk::ActiveWindowChanged(GdkWindow *window) { | |
770 DCHECK(is_fullscreen_); | |
771 GdkWindow* our_window = gtk_widget_get_parent_window(view_.get()); | |
772 // If the window was previously active, but isn't active anymore, shut it | |
773 // down. | |
774 if (our_window == window) | |
775 made_active_ = true; | |
776 else if (made_active_) | |
777 host_->Shutdown(); | |
778 } | |
779 | |
769 bool RenderWidgetHostViewGtk::IsSurfaceAvailableForCopy() const { | 780 bool RenderWidgetHostViewGtk::IsSurfaceAvailableForCopy() const { |
770 return !!host_->GetBackingStore(false); | 781 return !!host_->GetBackingStore(false); |
771 } | 782 } |
772 | 783 |
773 void RenderWidgetHostViewGtk::Show() { | 784 void RenderWidgetHostViewGtk::Show() { |
774 gtk_widget_show(view_.get()); | 785 gtk_widget_show(view_.get()); |
775 } | 786 } |
776 | 787 |
777 void RenderWidgetHostViewGtk::Hide() { | 788 void RenderWidgetHostViewGtk::Hide() { |
778 gtk_widget_hide(view_.get()); | 789 gtk_widget_hide(view_.get()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 gdk_display_pointer_ungrab(display, GDK_CURRENT_TIME); | 881 gdk_display_pointer_ungrab(display, GDK_CURRENT_TIME); |
871 gdk_display_keyboard_ungrab(display, GDK_CURRENT_TIME); | 882 gdk_display_keyboard_ungrab(display, GDK_CURRENT_TIME); |
872 } | 883 } |
873 | 884 |
874 // If this is a popup or fullscreen widget, then we need to destroy the window | 885 // If this is a popup or fullscreen widget, then we need to destroy the window |
875 // that we created to hold it. | 886 // that we created to hold it. |
876 if (IsPopup() || is_fullscreen_) { | 887 if (IsPopup() || is_fullscreen_) { |
877 GtkWidget* window = gtk_widget_get_parent(view_.get()); | 888 GtkWidget* window = gtk_widget_get_parent(view_.get()); |
878 | 889 |
879 // Disconnect the destroy handler so that we don't try to shutdown twice. | 890 // Disconnect the destroy handler so that we don't try to shutdown twice. |
880 if (is_fullscreen_) | 891 if (is_fullscreen_) { |
881 g_signal_handler_disconnect(window, destroy_handler_id_); | 892 g_signal_handler_disconnect(window, destroy_handler_id_); |
893 ui::ActiveWindowWatcherX::RemoveObserver(this); | |
894 } | |
882 | 895 |
883 gtk_widget_destroy(window); | 896 gtk_widget_destroy(window); |
884 } | 897 } |
885 | 898 |
886 // Remove |view_| from all containers now, so nothing else can hold a | 899 // Remove |view_| from all containers now, so nothing else can hold a |
887 // reference to |view_|'s widget except possibly a gtk signal handler if | 900 // reference to |view_|'s widget except possibly a gtk signal handler if |
888 // this code is currently executing within the context of a gtk signal | 901 // this code is currently executing within the context of a gtk signal |
889 // handler. Note that |view_| is still alive after this call. It will be | 902 // handler. Note that |view_| is still alive after this call. It will be |
890 // deallocated in the destructor. | 903 // deallocated in the destructor. |
891 // See http://www.crbug.com/11847 for details. | 904 // See http://www.crbug.com/11847 for details. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 } | 957 } |
945 | 958 |
946 GdkEventButton* RenderWidgetHostViewGtk::GetLastMouseDown() { | 959 GdkEventButton* RenderWidgetHostViewGtk::GetLastMouseDown() { |
947 return last_mouse_down_; | 960 return last_mouse_down_; |
948 } | 961 } |
949 | 962 |
950 gfx::NativeView RenderWidgetHostViewGtk::BuildInputMethodsGtkMenu() { | 963 gfx::NativeView RenderWidgetHostViewGtk::BuildInputMethodsGtkMenu() { |
951 return im_context_->BuildInputMethodsGtkMenu(); | 964 return im_context_->BuildInputMethodsGtkMenu(); |
952 } | 965 } |
953 | 966 |
954 gboolean RenderWidgetHostViewGtk::OnWindowStateEvent( | |
955 GtkWidget* widget, | |
956 GdkEventWindowState* event) { | |
957 if (is_fullscreen_) { | |
958 // If a fullscreen widget got unfullscreened (e.g. by the window manager), | |
959 // close it. | |
960 bool unfullscreened = | |
961 (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) && | |
962 !(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN); | |
963 if (unfullscreened) { | |
964 host_->Shutdown(); | |
965 return TRUE; | |
966 } | |
967 } | |
968 | |
969 return FALSE; | |
970 } | |
971 | |
972 void RenderWidgetHostViewGtk::OnDestroy(GtkWidget* widget) { | 967 void RenderWidgetHostViewGtk::OnDestroy(GtkWidget* widget) { |
973 DCHECK(is_fullscreen_); | 968 DCHECK(is_fullscreen_); |
974 host_->Shutdown(); | 969 host_->Shutdown(); |
975 } | 970 } |
976 | 971 |
977 bool RenderWidgetHostViewGtk::NeedsInputGrab() { | 972 bool RenderWidgetHostViewGtk::NeedsInputGrab() { |
978 return popup_type_ == WebKit::WebPopupTypeSelect; | 973 return popup_type_ == WebKit::WebPopupTypeSelect; |
979 } | 974 } |
980 | 975 |
981 bool RenderWidgetHostViewGtk::IsPopup() const { | 976 bool RenderWidgetHostViewGtk::IsPopup() const { |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1510 parent, | 1505 parent, |
1511 static_cast<content::AccessibilityNodeData::State>(0), | 1506 static_cast<content::AccessibilityNodeData::State>(0), |
1512 this)); | 1507 this)); |
1513 } | 1508 } |
1514 BrowserAccessibilityGtk* root = | 1509 BrowserAccessibilityGtk* root = |
1515 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); | 1510 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); |
1516 | 1511 |
1517 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); | 1512 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); |
1518 return root->GetAtkObject(); | 1513 return root->GetAtkObject(); |
1519 } | 1514 } |
OLD | NEW |