diff options
author | robert.bradford@intel.com <robert.bradford@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 19:54:58 +0000 |
---|---|---|
committer | robert.bradford@intel.com <robert.bradford@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 19:54:58 +0000 |
commit | 27197de0f56a27e665116caa4a18b45578fffe07 (patch) | |
tree | 5c986d864f666c2bfe93eb1ac584e71da8f25045 | |
parent | c338a18f062731442b0bd1c7d4266a9169de04e2 (diff) | |
download | chromium_src-27197de0f56a27e665116caa4a18b45578fffe07.zip chromium_src-27197de0f56a27e665116caa4a18b45578fffe07.tar.gz chromium_src-27197de0f56a27e665116caa4a18b45578fffe07.tar.bz2 |
GTK: Port RenderWidgetHostViewGtk to latest GTK
New API used:
gtk_widget_get_window - replaces direct access
gtk_widget_get_allocation - added in 2.18 - replaces direct access
gdk_window_get_width / gdk_window_get_height added in 2.24 - replaces
deprecated gdk_window_get_size so is added to ui/base/gtk/gtk_compat.h
With these changes the file can be compiled with sealed structures and
deprecated API disabled with the exception of the deprecated function
gdk_bitmap_create_from_data used in the cursor creation. That will come in a
separate change.
BUG=79722
TEST=Compiles and chrome runs
Review URL: http://codereview.chromium.org/8635018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112498 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_gtk.cc | 43 | ||||
-rw-r--r-- | ui/base/gtk/gtk_compat.h | 18 |
2 files changed, 41 insertions, 20 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.cc b/content/browser/renderer_host/render_widget_host_view_gtk.cc index b014f6a..fedcbd2 100644 --- a/content/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/content/browser/renderer_host/render_widget_host_view_gtk.cc @@ -37,6 +37,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFactory.h" #include "third_party/WebKit/Source/WebKit/chromium/public/x11/WebScreenInfoFactory.h" +#include "ui/base/gtk/gtk_compat.h" #include "ui/base/text/text_elider.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/gtk_native_view_id_manager.h" @@ -240,7 +241,7 @@ class RenderWidgetHostViewGtkWidget { RenderWidgetHostViewGtk* host_view) { // Whenever we lose focus, set the cursor back to that of our parent window, // which should be the default arrow. - gdk_window_set_cursor(widget->window, NULL); + gdk_window_set_cursor(gtk_widget_get_window(widget), NULL); // If we are showing a context menu, maintain the illusion that webkit has // focus. if (!host_view->is_showing_context_menu_) { @@ -270,7 +271,7 @@ class RenderWidgetHostViewGtkWidget { host_view->was_imcontext_focused_before_grab_ = host_view->im_context_->is_focused(); if (host_view->was_imcontext_focused_before_grab_) { - gdk_window_set_cursor(widget->window, NULL); + gdk_window_set_cursor(gtk_widget_get_window(widget), NULL); host_view->im_context_->OnFocusOut(); } } @@ -340,8 +341,10 @@ class RenderWidgetHostViewGtkWidget { // If the mouse event happens outside our popup, force the popup to // close. We do this so a hung renderer doesn't prevent us from // releasing the x pointer grab. - bool click_in_popup = x >= 0 && y >= 0 && x < widget->allocation.width && - y < widget->allocation.height; + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); + bool click_in_popup = x >= 0 && y >= 0 && x < allocation.width && + y < allocation.height; // Only Shutdown on mouse downs. Mouse ups can occur outside the render // view if the user drags for DnD or while using the scrollbar on a select // dropdown. Don't shutdown if we are not a popup. @@ -622,7 +625,7 @@ void RenderWidgetHostViewGtk::InitAsPopup( // Now grab all of X's input. if (do_x_grab_) { gdk_pointer_grab( - parent_->window, + gtk_widget_get_window(parent_), TRUE, // Only events outside of the window are reported with respect // to |parent_->window|. static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK | @@ -631,7 +634,7 @@ void RenderWidgetHostViewGtk::InitAsPopup( NULL, GDK_CURRENT_TIME); // We grab keyboard events too so things like alt+tab are eaten. - gdk_keyboard_grab(parent_->window, TRUE, GDK_CURRENT_TIME); + gdk_keyboard_grab(gtk_widget_get_window(parent_), TRUE, GDK_CURRENT_TIME); } } } @@ -765,7 +768,7 @@ bool RenderWidgetHostViewGtk::IsShowing() { } gfx::Rect RenderWidgetHostViewGtk::GetViewBounds() const { - GdkWindow* gdk_window = view_.get()->window; + GdkWindow* gdk_window = gtk_widget_get_window(view_.get()); if (!gdk_window) return gfx::Rect(requested_size_); GdkRectangle window_rect; @@ -1000,9 +1003,10 @@ void RenderWidgetHostViewGtk::DoPopupOrFullscreenInit(GtkWindow* window, BackingStore* RenderWidgetHostViewGtk::AllocBackingStore( const gfx::Size& size) { + gint depth = gdk_visual_get_depth(gtk_widget_get_visual(view_.get())); return new BackingStoreGtk(host_, size, ui::GetVisualFromGtkWidget(view_.get()), - gtk_widget_get_visual(view_.get())->depth); + depth); } void RenderWidgetHostViewGtk::AcceleratedSurfaceBuffersSwapped( @@ -1046,18 +1050,19 @@ void RenderWidgetHostViewGtk::ModifyEventForEdgeDragging( gdk_screen_get_monitor_geometry(screen, monitor, &geometry); drag_monitor_size.SetSize(geometry.width, geometry.height); } - + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); // Check X and Y independently, as the user could be dragging into a corner. if (event->x == 0 && event->x_root == 0) { new_dragged_at_horizontal_edge = dragged_at_horizontal_edge_ - 1; - } else if (widget->allocation.width - 1 == static_cast<gint>(event->x) && + } else if (allocation.width - 1 == static_cast<gint>(event->x) && drag_monitor_size.width() - 1 == static_cast<gint>(event->x_root)) { new_dragged_at_horizontal_edge = dragged_at_horizontal_edge_ + 1; } if (event->y == 0 && event->y_root == 0) { new_dragged_at_vertical_edge = dragged_at_vertical_edge_ - 1; - } else if (widget->allocation.height - 1 == static_cast<gint>(event->y) && + } else if (allocation.height - 1 == static_cast<gint>(event->y) && drag_monitor_size.height() - 1 == static_cast<gint>(event->y_root)) { new_dragged_at_vertical_edge = dragged_at_vertical_edge_ + 1; } @@ -1083,7 +1088,7 @@ void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) { return; } - GdkWindow* window = view_.get()->window; + GdkWindow* window = gtk_widget_get_window(view_.get()); DCHECK(!about_to_validate_and_paint_); invalid_rect_ = damage_rect; @@ -1174,7 +1179,7 @@ void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) { void RenderWidgetHostViewGtk::ShowCurrentCursor() { // The widget may not have a window. If that's the case, abort mission. This // is the same issue as that explained above in Paint(). - if (!view_.get()->window) + if (!gtk_widget_get_window(view_.get())) return; // TODO(port): WebKit bug https://bugs.webkit.org/show_bug.cgi?id=16388 is @@ -1188,7 +1193,7 @@ void RenderWidgetHostViewGtk::ShowCurrentCursor() { } else { gdk_cursor = current_cursor_.GetNativeCursor(); } - gdk_window_set_cursor(view_.get()->window, gdk_cursor); + gdk_window_set_cursor(gtk_widget_get_window(view_.get()), gdk_cursor); } void RenderWidgetHostViewGtk::CreatePluginContainer( @@ -1240,7 +1245,7 @@ void RenderWidgetHostViewGtk::OnAcceleratedCompositingStateChange() { } void RenderWidgetHostViewGtk::GetScreenInfo(WebKit::WebScreenInfo* results) { - GdkWindow* gdk_window = view_.get()->window; + GdkWindow* gdk_window = gtk_widget_get_window(view_.get()); if (!gdk_window) { GdkDisplay* display = gdk_display_get_default(); gdk_window = gdk_display_get_default_group(display); @@ -1256,7 +1261,7 @@ gfx::Rect RenderWidgetHostViewGtk::GetRootWindowBounds() { return gfx::Rect(); GdkRectangle frame_extents; - GdkWindow* gdk_window = toplevel->window; + GdkWindow* gdk_window = gtk_widget_get_window(toplevel); if (!gdk_window) return gfx::Rect(); @@ -1393,10 +1398,8 @@ gfx::Point RenderWidgetHostViewGtk::GetWidgetCenter() { gint window_x = 0; gint window_y = 0; gdk_window_get_origin(window, &window_x, &window_y); - gint window_w = 0; - gint window_h = 0; - gdk_window_get_size(window, &window_w, &window_h); - + gint window_w = gdk_window_get_width(window); + gint window_h = gdk_window_get_height(window); widget_center_.SetPoint(window_x + window_w / 2, window_y + window_h / 2); widget_center_valid_ = true; diff --git a/ui/base/gtk/gtk_compat.h b/ui/base/gtk/gtk_compat.h index e6c119a..b9f7fd2 100644 --- a/ui/base/gtk/gtk_compat.h +++ b/ui/base/gtk/gtk_compat.h @@ -26,14 +26,32 @@ inline gboolean gtk_widget_is_toplevel(GtkWidget* widget) { } #endif +#if !GTK_CHECK_VERSION(2, 22, 0) +inline gint gdk_visual_get_depth(GdkVisual* visual) { + return visual->depth; +} +#endif + #if !GTK_CHECK_VERSION(2, 24, 0) inline void gdk_pixmap_get_size(GdkPixmap* pixmap, gint* width, gint* height) { gdk_drawable_get_size(GDK_DRAWABLE(pixmap), width, height); } +inline int gdk_window_get_height(GdkWindow* window) { + int height; + gdk_drawable_get_size(GDK_DRAWABLE(window), NULL, &height); + return height; +} + inline GdkScreen* gdk_window_get_screen(GdkWindow* window) { return gdk_drawable_get_screen(GDK_DRAWABLE(window)); } + +inline int gdk_window_get_width(GdkWindow* window) { + int width; + gdk_drawable_get_size(GDK_DRAWABLE(window), &width, NULL); + return width; +} #endif #endif // UI_BASE_GTK_GTK_COMPAT_H_ |