| 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 "chrome/browser/tab_contents/tab_contents_view_gtk.h" | 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 // static | 94 // static |
| 95 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 95 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
| 96 return new TabContentsViewGtk(tab_contents); | 96 return new TabContentsViewGtk(tab_contents); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) | 99 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) |
| 100 : TabContentsView(tab_contents), | 100 : TabContentsView(tab_contents), |
| 101 vbox_(gtk_vbox_new(FALSE, 0)) { | 101 fixed_(gtk_fixed_new()) { |
| 102 fixed_ = gtk_fixed_new(); | 102 g_signal_connect(fixed_.get(), "size-allocate", |
| 103 gtk_box_pack_start(GTK_BOX(vbox_.get()), fixed_, TRUE, TRUE, 0); | |
| 104 g_signal_connect(fixed_, "size-allocate", | |
| 105 G_CALLBACK(OnSizeAllocate), this); | 103 G_CALLBACK(OnSizeAllocate), this); |
| 106 gtk_widget_show(fixed_); | 104 gtk_widget_show(fixed_.get()); |
| 107 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, | 105 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, |
| 108 Source<TabContents>(tab_contents)); | 106 Source<TabContents>(tab_contents)); |
| 109 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, | 107 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, |
| 110 Source<TabContents>(tab_contents)); | 108 Source<TabContents>(tab_contents)); |
| 111 } | 109 } |
| 112 | 110 |
| 113 TabContentsViewGtk::~TabContentsViewGtk() { | 111 TabContentsViewGtk::~TabContentsViewGtk() { |
| 114 vbox_.Destroy(); | 112 fixed_.Destroy(); |
| 115 } | 113 } |
| 116 | 114 |
| 117 void TabContentsViewGtk::CreateView() { | 115 void TabContentsViewGtk::CreateView() { |
| 118 // Windows uses this to do initialization, but we do all our initialization | 116 // Windows uses this to do initialization, but we do all our initialization |
| 119 // in the constructor. | 117 // in the constructor. |
| 120 } | 118 } |
| 121 | 119 |
| 122 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( | 120 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( |
| 123 RenderWidgetHost* render_widget_host) { | 121 RenderWidgetHost* render_widget_host) { |
| 124 if (render_widget_host->view()) { | 122 if (render_widget_host->view()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 146 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | | 144 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | |
| 147 GDK_POINTER_MOTION_MASK); | 145 GDK_POINTER_MOTION_MASK); |
| 148 g_signal_connect(content_view, "button-press-event", | 146 g_signal_connect(content_view, "button-press-event", |
| 149 G_CALLBACK(OnMouseDown), this); | 147 G_CALLBACK(OnMouseDown), this); |
| 150 | 148 |
| 151 InsertIntoContentArea(content_view); | 149 InsertIntoContentArea(content_view); |
| 152 return view; | 150 return view; |
| 153 } | 151 } |
| 154 | 152 |
| 155 gfx::NativeView TabContentsViewGtk::GetNativeView() const { | 153 gfx::NativeView TabContentsViewGtk::GetNativeView() const { |
| 156 return vbox_.get(); | 154 return fixed_.get(); |
| 157 } | 155 } |
| 158 | 156 |
| 159 gfx::NativeView TabContentsViewGtk::GetContentNativeView() const { | 157 gfx::NativeView TabContentsViewGtk::GetContentNativeView() const { |
| 160 if (!tab_contents()->render_widget_host_view()) | 158 if (!tab_contents()->render_widget_host_view()) |
| 161 return NULL; | 159 return NULL; |
| 162 return tab_contents()->render_widget_host_view()->GetPluginNativeView(); | 160 return tab_contents()->render_widget_host_view()->GetPluginNativeView(); |
| 163 } | 161 } |
| 164 | 162 |
| 165 | 163 |
| 166 gfx::NativeWindow TabContentsViewGtk::GetTopLevelNativeWindow() const { | 164 gfx::NativeWindow TabContentsViewGtk::GetTopLevelNativeWindow() const { |
| 167 GtkWidget* window = gtk_widget_get_ancestor(GetNativeView(), GTK_TYPE_WINDOW); | 165 GtkWidget* window = gtk_widget_get_ancestor(GetNativeView(), GTK_TYPE_WINDOW); |
| 168 return window ? GTK_WINDOW(window) : NULL; | 166 return window ? GTK_WINDOW(window) : NULL; |
| 169 } | 167 } |
| 170 | 168 |
| 171 void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { | 169 void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { |
| 172 // This is used for positioning the download shelf arrow animation, | 170 // This is used for positioning the download shelf arrow animation, |
| 173 // as well as sizing some other widgets in Windows. In GTK the size is | 171 // as well as sizing some other widgets in Windows. In GTK the size is |
| 174 // managed for us, so it appears to be only used for the download shelf | 172 // managed for us, so it appears to be only used for the download shelf |
| 175 // animation. | 173 // animation. |
| 176 int x = 0; | 174 int x = 0; |
| 177 int y = 0; | 175 int y = 0; |
| 178 if (vbox_.get()->window) | 176 if (fixed_.get()->window) |
| 179 gdk_window_get_origin(vbox_.get()->window, &x, &y); | 177 gdk_window_get_origin(fixed_.get()->window, &x, &y); |
| 180 out->SetRect(x + vbox_.get()->allocation.x, y + vbox_.get()->allocation.y, | 178 out->SetRect(x + fixed_.get()->allocation.x, y + fixed_.get()->allocation.y, |
| 181 vbox_.get()->allocation.width, vbox_.get()->allocation.height); | 179 fixed_.get()->allocation.width, fixed_.get()->allocation.height); |
| 182 } | 180 } |
| 183 | 181 |
| 184 void TabContentsViewGtk::OnContentsDestroy() { | 182 void TabContentsViewGtk::OnContentsDestroy() { |
| 185 // TODO(estade): Windows uses this function cancel pending drag-n-drop drags. | 183 // TODO(estade): Windows uses this function cancel pending drag-n-drop drags. |
| 186 // We don't have drags yet, so do nothing for now. | 184 // We don't have drags yet, so do nothing for now. |
| 187 } | 185 } |
| 188 | 186 |
| 189 void TabContentsViewGtk::SetPageTitle(const std::wstring& title) { | 187 void TabContentsViewGtk::SetPageTitle(const std::wstring& title) { |
| 190 // Set the window name to include the page title so it's easier to spot | 188 // Set the window name to include the page title so it's easier to spot |
| 191 // when debugging (e.g. via xwininfo -tree). | 189 // when debugging (e.g. via xwininfo -tree). |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 295 |
| 298 // Until we have d'n'd implemented, just immediately pretend we're | 296 // Until we have d'n'd implemented, just immediately pretend we're |
| 299 // already done with the drag and drop so we don't get stuck | 297 // already done with the drag and drop so we don't get stuck |
| 300 // thinking we're in mid-drag. | 298 // thinking we're in mid-drag. |
| 301 // TODO(port): remove me when the above NOTIMPLEMENTED is fixed. | 299 // TODO(port): remove me when the above NOTIMPLEMENTED is fixed. |
| 302 if (tab_contents()->render_view_host()) | 300 if (tab_contents()->render_view_host()) |
| 303 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 301 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); |
| 304 } | 302 } |
| 305 | 303 |
| 306 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { | 304 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { |
| 307 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); | 305 gtk_fixed_put(GTK_FIXED(fixed_.get()), widget, 0, 0); |
| 308 } | 306 } |
| 309 | 307 |
| 310 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, | 308 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, |
| 311 GdkEventButton* event, TabContentsViewGtk* view) { | 309 GdkEventButton* event, TabContentsViewGtk* view) { |
| 312 view->last_mouse_down_time_ = event->time; | 310 view->last_mouse_down_time_ = event->time; |
| 313 return FALSE; | 311 return FALSE; |
| 314 } | 312 } |
| 315 | 313 |
| 316 gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, | 314 gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, |
| 317 GtkAllocation* allocation, | 315 GtkAllocation* allocation, |
| 318 TabContentsViewGtk* view) { | 316 TabContentsViewGtk* view) { |
| 319 int width = allocation->width; | 317 int width = allocation->width; |
| 320 DownloadShelf* shelf = view->tab_contents()->GetDownloadShelf(false); | 318 int height = allocation->height; |
| 321 int height = shelf && shelf->IsClosing() ? | |
| 322 widget->parent->allocation.height : allocation->height; | |
| 323 height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); | 319 height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); |
| 324 gfx::Size size(width, height); | 320 gfx::Size size(width, height); |
| 325 gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size); | 321 gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size); |
| 326 | 322 |
| 327 return FALSE; | 323 return FALSE; |
| 328 } | 324 } |
| OLD | NEW |