| OLD | NEW |
| 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 "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 <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" | 16 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents_view_wrapper_gtk.h" |
| 17 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h" | 18 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h" |
| 18 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" | 19 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" |
| 19 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 20 #include "content/browser/renderer_host/render_view_host_factory.h" | 21 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 21 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" | 22 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" |
| 22 #include "content/browser/tab_contents/interstitial_page.h" | 23 #include "content/browser/tab_contents/interstitial_page.h" |
| 23 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
| 24 #include "content/browser/tab_contents/tab_contents_delegate.h" | 25 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 25 #include "content/browser/tab_contents/web_drag_dest_gtk.h" | 26 #include "content/browser/tab_contents/web_drag_dest_gtk.h" |
| 26 #include "content/browser/tab_contents/web_drag_source_gtk.h" | 27 #include "content/browser/tab_contents/web_drag_source_gtk.h" |
| 27 #include "ui/base/gtk/gtk_expanded_container.h" | 28 #include "ui/base/gtk/gtk_expanded_container.h" |
| 28 #include "ui/base/gtk/gtk_floating_container.h" | |
| 29 #include "ui/gfx/point.h" | 29 #include "ui/gfx/point.h" |
| 30 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
| 31 #include "ui/gfx/size.h" | 31 #include "ui/gfx/size.h" |
| 32 #include "webkit/glue/webdropdata.h" | 32 #include "webkit/glue/webdropdata.h" |
| 33 | 33 |
| 34 using WebKit::WebDragOperation; | 34 using WebKit::WebDragOperation; |
| 35 using WebKit::WebDragOperationsMask; | 35 using WebKit::WebDragOperationsMask; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 66 tab_contents->delegate()->ContentsZoomChange(true); | 66 tab_contents->delegate()->ContentsZoomChange(true); |
| 67 return TRUE; | 67 return TRUE; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 return FALSE; | 71 return FALSE; |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) | 76 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents, |
| 77 TabContentsViewWrapperGtk* view_wrapper) |
| 77 : tab_contents_(tab_contents), | 78 : tab_contents_(tab_contents), |
| 78 floating_(gtk_floating_container_new()), | |
| 79 expanded_(gtk_expanded_container_new()), | 79 expanded_(gtk_expanded_container_new()), |
| 80 constrained_window_(NULL), | 80 view_wrapper_(view_wrapper), |
| 81 overlaid_view_(NULL) { | 81 overlaid_view_(NULL) { |
| 82 gtk_widget_set_name(expanded_, "chrome-tab-contents-view"); | 82 gtk_widget_set_name(expanded_.get(), "chrome-tab-contents-view"); |
| 83 g_signal_connect(expanded_, "size-allocate", | 83 g_signal_connect(expanded_.get(), "size-allocate", |
| 84 G_CALLBACK(OnSizeAllocateThunk), this); | 84 G_CALLBACK(OnSizeAllocateThunk), this); |
| 85 g_signal_connect(expanded_, "child-size-request", | 85 g_signal_connect(expanded_.get(), "child-size-request", |
| 86 G_CALLBACK(OnChildSizeRequestThunk), this); | 86 G_CALLBACK(OnChildSizeRequestThunk), this); |
| 87 g_signal_connect(floating_.get(), "set-floating-position", | |
| 88 G_CALLBACK(OnSetFloatingPositionThunk), this); | |
| 89 | 87 |
| 90 gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_); | 88 gtk_widget_show(expanded_.get()); |
| 91 gtk_widget_show(expanded_); | |
| 92 gtk_widget_show(floating_.get()); | |
| 93 drag_source_.reset(new content::WebDragSourceGtk(tab_contents)); | 89 drag_source_.reset(new content::WebDragSourceGtk(tab_contents)); |
| 90 |
| 91 if (view_wrapper_.get()) |
| 92 view_wrapper_->WrapView(this); |
| 94 } | 93 } |
| 95 | 94 |
| 96 TabContentsViewGtk::~TabContentsViewGtk() { | 95 TabContentsViewGtk::~TabContentsViewGtk() { |
| 97 floating_.Destroy(); | 96 expanded_.Destroy(); |
| 98 } | |
| 99 | |
| 100 void TabContentsViewGtk::AttachConstrainedWindow( | |
| 101 ConstrainedWindowGtk* constrained_window) { | |
| 102 DCHECK(constrained_window_ == NULL); | |
| 103 | |
| 104 constrained_window_ = constrained_window; | |
| 105 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()), | |
| 106 constrained_window->widget()); | |
| 107 } | |
| 108 | |
| 109 void TabContentsViewGtk::RemoveConstrainedWindow( | |
| 110 ConstrainedWindowGtk* constrained_window) { | |
| 111 DCHECK(constrained_window == constrained_window_); | |
| 112 | |
| 113 constrained_window_ = NULL; | |
| 114 gtk_container_remove(GTK_CONTAINER(floating_.get()), | |
| 115 constrained_window->widget()); | |
| 116 } | 97 } |
| 117 | 98 |
| 118 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { | 99 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { |
| 119 requested_size_ = initial_size; | 100 requested_size_ = initial_size; |
| 120 } | 101 } |
| 121 | 102 |
| 122 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( | 103 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( |
| 123 RenderWidgetHost* render_widget_host) { | 104 RenderWidgetHost* render_widget_host) { |
| 124 if (render_widget_host->view()) { | 105 if (render_widget_host->view()) { |
| 125 // During testing, the view will already be set up in most cases to the | 106 // During testing, the view will already be set up in most cases to the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 141 g_signal_connect(content_view, "motion-notify-event", | 122 g_signal_connect(content_view, "motion-notify-event", |
| 142 G_CALLBACK(OnMouseMove), tab_contents_); | 123 G_CALLBACK(OnMouseMove), tab_contents_); |
| 143 g_signal_connect(content_view, "scroll-event", | 124 g_signal_connect(content_view, "scroll-event", |
| 144 G_CALLBACK(OnMouseScroll), tab_contents_); | 125 G_CALLBACK(OnMouseScroll), tab_contents_); |
| 145 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | | 126 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | |
| 146 GDK_POINTER_MOTION_MASK); | 127 GDK_POINTER_MOTION_MASK); |
| 147 InsertIntoContentArea(content_view); | 128 InsertIntoContentArea(content_view); |
| 148 | 129 |
| 149 // Renderer target DnD. | 130 // Renderer target DnD. |
| 150 drag_dest_.reset(new content::WebDragDestGtk(tab_contents_, content_view)); | 131 drag_dest_.reset(new content::WebDragDestGtk(tab_contents_, content_view)); |
| 151 bookmark_handler_gtk_.reset(new WebDragBookmarkHandlerGtk); | 132 |
| 152 drag_dest_->set_delegate(bookmark_handler_gtk_.get()); | 133 if (view_wrapper_.get()) |
| 134 view_wrapper_->OnCreateViewForWidget(); |
| 153 | 135 |
| 154 return view; | 136 return view; |
| 155 } | 137 } |
| 156 | 138 |
| 157 gfx::NativeView TabContentsViewGtk::GetNativeView() const { | 139 gfx::NativeView TabContentsViewGtk::GetNativeView() const { |
| 158 return floating_.get(); | 140 if (view_wrapper_.get()) |
| 141 return view_wrapper_->GetNativeView(); |
| 142 |
| 143 return expanded_.get(); |
| 159 } | 144 } |
| 160 | 145 |
| 161 gfx::NativeView TabContentsViewGtk::GetContentNativeView() const { | 146 gfx::NativeView TabContentsViewGtk::GetContentNativeView() const { |
| 162 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); | 147 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); |
| 163 if (!rwhv) | 148 if (!rwhv) |
| 164 return NULL; | 149 return NULL; |
| 165 return rwhv->GetNativeView(); | 150 return rwhv->GetNativeView(); |
| 166 } | 151 } |
| 167 | 152 |
| 168 gfx::NativeWindow TabContentsViewGtk::GetTopLevelNativeWindow() const { | 153 gfx::NativeWindow TabContentsViewGtk::GetTopLevelNativeWindow() const { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (rwhv) | 189 if (rwhv) |
| 205 rwhv->SetSize(size); | 190 rwhv->SetSize(size); |
| 206 } | 191 } |
| 207 | 192 |
| 208 void TabContentsViewGtk::RenderViewCreated(RenderViewHost* host) { | 193 void TabContentsViewGtk::RenderViewCreated(RenderViewHost* host) { |
| 209 } | 194 } |
| 210 | 195 |
| 211 void TabContentsViewGtk::Focus() { | 196 void TabContentsViewGtk::Focus() { |
| 212 if (tab_contents_->showing_interstitial_page()) { | 197 if (tab_contents_->showing_interstitial_page()) { |
| 213 tab_contents_->interstitial_page()->Focus(); | 198 tab_contents_->interstitial_page()->Focus(); |
| 214 } else if (!constrained_window_) { | 199 } else if (wrapper()) { |
| 215 GtkWidget* widget = GetContentNativeView(); | 200 wrapper()->Focus(); |
| 216 if (widget) | |
| 217 gtk_widget_grab_focus(widget); | |
| 218 } | 201 } |
| 219 } | 202 } |
| 220 | 203 |
| 221 void TabContentsViewGtk::SetInitialFocus() { | 204 void TabContentsViewGtk::SetInitialFocus() { |
| 222 if (tab_contents_->FocusLocationBarByDefault()) | 205 if (tab_contents_->FocusLocationBarByDefault()) |
| 223 tab_contents_->SetFocusToLocationBar(false); | 206 tab_contents_->SetFocusToLocationBar(false); |
| 224 else | 207 else |
| 225 Focus(); | 208 Focus(); |
| 226 } | 209 } |
| 227 | 210 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 244 } | 227 } |
| 245 | 228 |
| 246 bool TabContentsViewGtk::IsEventTracking() const { | 229 bool TabContentsViewGtk::IsEventTracking() const { |
| 247 return false; | 230 return false; |
| 248 } | 231 } |
| 249 | 232 |
| 250 void TabContentsViewGtk::CloseTabAfterEventTracking() { | 233 void TabContentsViewGtk::CloseTabAfterEventTracking() { |
| 251 } | 234 } |
| 252 | 235 |
| 253 void TabContentsViewGtk::GetViewBounds(gfx::Rect* out) const { | 236 void TabContentsViewGtk::GetViewBounds(gfx::Rect* out) const { |
| 254 if (!floating_->window) { | 237 if (!GetNativeView()->window) { |
| 255 out->SetRect(0, 0, requested_size_.width(), requested_size_.height()); | 238 out->SetRect(0, 0, requested_size_.width(), requested_size_.height()); |
| 256 return; | 239 return; |
| 257 } | 240 } |
| 258 int x = 0, y = 0, w, h; | 241 int x = 0, y = 0, w, h; |
| 259 gdk_window_get_geometry(floating_->window, &x, &y, &w, &h, NULL); | 242 gdk_window_get_geometry(GetNativeView()->window, &x, &y, &w, &h, NULL); |
| 260 out->SetRect(x, y, w, h); | 243 out->SetRect(x, y, w, h); |
| 261 } | 244 } |
| 262 | 245 |
| 263 void TabContentsViewGtk::InstallOverlayView(gfx::NativeView view) { | 246 void TabContentsViewGtk::InstallOverlayView(gfx::NativeView view) { |
| 264 DCHECK(!overlaid_view_); | 247 DCHECK(!overlaid_view_); |
| 265 overlaid_view_ = view; | 248 overlaid_view_ = view; |
| 266 InsertIntoContentArea(view); | 249 InsertIntoContentArea(view); |
| 267 gtk_widget_show(view); | 250 gtk_widget_show(view); |
| 268 } | 251 } |
| 269 | 252 |
| 270 void TabContentsViewGtk::RemoveOverlayView() { | 253 void TabContentsViewGtk::RemoveOverlayView() { |
| 271 DCHECK(overlaid_view_); | 254 DCHECK(overlaid_view_); |
| 272 gtk_container_remove(GTK_CONTAINER(expanded_), overlaid_view_); | 255 gtk_container_remove(GTK_CONTAINER(expanded_.get()), overlaid_view_); |
| 273 overlaid_view_ = NULL; | 256 overlaid_view_ = NULL; |
| 274 } | 257 } |
| 275 | 258 |
| 276 void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) { | 259 void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) { |
| 277 focus_store_.SetWidget(widget); | 260 focus_store_.SetWidget(widget); |
| 278 } | 261 } |
| 279 | 262 |
| 280 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { | 263 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { |
| 281 drag_dest_->UpdateDragStatus(operation); | 264 drag_dest_->UpdateDragStatus(operation); |
| 282 } | 265 } |
| 283 | 266 |
| 284 void TabContentsViewGtk::GotFocus() { | 267 void TabContentsViewGtk::GotFocus() { |
| 285 // This is only used in the views FocusManager stuff but it bleeds through | 268 // This is only used in the views FocusManager stuff but it bleeds through |
| 286 // all subclasses. http://crbug.com/21875 | 269 // all subclasses. http://crbug.com/21875 |
| 287 } | 270 } |
| 288 | 271 |
| 289 // This is called when we the renderer asks us to take focus back (i.e., it has | 272 // This is called when we the renderer asks us to take focus back (i.e., it has |
| 290 // iterated past the last focusable element on the page). | 273 // iterated past the last focusable element on the page). |
| 291 void TabContentsViewGtk::TakeFocus(bool reverse) { | 274 void TabContentsViewGtk::TakeFocus(bool reverse) { |
| 292 if (!tab_contents_->delegate()->TakeFocus(reverse)) { | 275 if (!tab_contents_->delegate()->TakeFocus(reverse)) { |
| 293 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), | 276 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), |
| 294 reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD); | 277 reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD); |
| 295 } | 278 } |
| 296 } | 279 } |
| 297 | 280 |
| 281 void TabContentsViewGtk::SetDragDestDelegate( |
| 282 content::WebDragDestDelegate* delegate) { |
| 283 drag_dest_->set_delegate(delegate); |
| 284 } |
| 285 |
| 286 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { |
| 287 gtk_container_add(GTK_CONTAINER(expanded_.get()), widget); |
| 288 } |
| 289 |
| 290 // Called when the content view gtk widget is tabbed to, or after the call to |
| 291 // gtk_widget_child_focus() in TakeFocus(). We return true |
| 292 // and grab focus if we don't have it. The call to |
| 293 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to |
| 294 // webkit. |
| 295 gboolean TabContentsViewGtk::OnFocus(GtkWidget* widget, |
| 296 GtkDirectionType focus) { |
| 297 // Give our view wrapper first chance at this event. |
| 298 if (view_wrapper_.get()) { |
| 299 gboolean return_value = FALSE; |
| 300 if (view_wrapper_->OnNativeViewFocusEvent(widget, focus, &return_value)) |
| 301 return return_value; |
| 302 } |
| 303 |
| 304 // If we already have focus, let the next widget have a shot at it. We will |
| 305 // reach this situation after the call to gtk_widget_child_focus() in |
| 306 // TakeFocus(). |
| 307 if (gtk_widget_is_focus(widget)) |
| 308 return FALSE; |
| 309 |
| 310 gtk_widget_grab_focus(widget); |
| 311 bool reverse = focus == GTK_DIR_TAB_BACKWARD; |
| 312 tab_contents_->FocusThroughTabTraversal(reverse); |
| 313 return TRUE; |
| 314 } |
| 315 |
| 298 void TabContentsViewGtk::CreateNewWindow( | 316 void TabContentsViewGtk::CreateNewWindow( |
| 299 int route_id, | 317 int route_id, |
| 300 const ViewHostMsg_CreateWindow_Params& params) { | 318 const ViewHostMsg_CreateWindow_Params& params) { |
| 301 delegate_view_helper_.CreateNewWindowFromTabContents( | 319 delegate_view_helper_.CreateNewWindowFromTabContents( |
| 302 tab_contents_, route_id, params); | 320 tab_contents_, route_id, params); |
| 303 } | 321 } |
| 304 | 322 |
| 305 void TabContentsViewGtk::CreateNewWidget( | 323 void TabContentsViewGtk::CreateNewWidget( |
| 306 int route_id, WebKit::WebPopupType popup_type) { | 324 int route_id, WebKit::WebPopupType popup_type) { |
| 307 delegate_view_helper_.CreateNewWidget(route_id, popup_type, | 325 delegate_view_helper_.CreateNewWidget(route_id, popup_type, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 325 int route_id, const gfx::Rect& initial_pos) { | 343 int route_id, const gfx::Rect& initial_pos) { |
| 326 delegate_view_helper_.ShowCreatedWidget( | 344 delegate_view_helper_.ShowCreatedWidget( |
| 327 tab_contents_, route_id, initial_pos); | 345 tab_contents_, route_id, initial_pos); |
| 328 } | 346 } |
| 329 | 347 |
| 330 void TabContentsViewGtk::ShowCreatedFullscreenWidget(int route_id) { | 348 void TabContentsViewGtk::ShowCreatedFullscreenWidget(int route_id) { |
| 331 delegate_view_helper_.ShowCreatedFullscreenWidget(tab_contents_, route_id); | 349 delegate_view_helper_.ShowCreatedFullscreenWidget(tab_contents_, route_id); |
| 332 } | 350 } |
| 333 | 351 |
| 334 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { | 352 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { |
| 335 // Find out the RenderWidgetHostView that corresponds to the render widget on | 353 if (wrapper()) |
| 336 // which this context menu is showed, so that we can retrieve the last mouse | 354 wrapper()->ShowContextMenu(params); |
| 337 // down event on the render widget and use it as the timestamp of the | 355 else |
| 338 // activation event to show the context menu. | 356 DLOG(ERROR) << "Implement context menus without chrome/ code"; |
| 339 RenderWidgetHostView* view = NULL; | |
| 340 if (params.custom_context.render_widget_id != | |
| 341 webkit_glue::CustomContextMenuContext::kCurrentRenderWidget) { | |
| 342 IPC::Channel::Listener* listener = | |
| 343 tab_contents_->render_view_host()->process()->GetListenerByID( | |
| 344 params.custom_context.render_widget_id); | |
| 345 if (!listener) { | |
| 346 NOTREACHED(); | |
| 347 return; | |
| 348 } | |
| 349 view = static_cast<RenderWidgetHost*>(listener)->view(); | |
| 350 } else { | |
| 351 view = tab_contents_->GetRenderWidgetHostView(); | |
| 352 } | |
| 353 RenderWidgetHostViewGtk* view_gtk = | |
| 354 static_cast<RenderWidgetHostViewGtk*>(view); | |
| 355 if (!view_gtk) | |
| 356 return; | |
| 357 | |
| 358 context_menu_.reset(new RenderViewContextMenuGtk( | |
| 359 tab_contents_, params, GDK_CURRENT_TIME)); | |
| 360 context_menu_->Init(); | |
| 361 | |
| 362 gfx::Rect bounds; | |
| 363 GetContainerBounds(&bounds); | |
| 364 gfx::Point point = bounds.origin(); | |
| 365 point.Offset(params.x, params.y); | |
| 366 context_menu_->Popup(point); | |
| 367 } | 357 } |
| 368 | 358 |
| 369 void TabContentsViewGtk::ShowPopupMenu(const gfx::Rect& bounds, | 359 void TabContentsViewGtk::ShowPopupMenu(const gfx::Rect& bounds, |
| 370 int item_height, | 360 int item_height, |
| 371 double item_font_size, | 361 double item_font_size, |
| 372 int selected_item, | 362 int selected_item, |
| 373 const std::vector<WebMenuItem>& items, | 363 const std::vector<WebMenuItem>& items, |
| 374 bool right_aligned) { | 364 bool right_aligned) { |
| 375 // We are not using external popup menus on Linux, they are rendered by | 365 // We are not using external popup menus on Linux, they are rendered by |
| 376 // WebKit. | 366 // WebKit. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 389 tab_contents_->GetRenderWidgetHostView()); | 379 tab_contents_->GetRenderWidgetHostView()); |
| 390 if (!view_gtk || !view_gtk->last_mouse_down()) | 380 if (!view_gtk || !view_gtk->last_mouse_down()) |
| 391 return; | 381 return; |
| 392 | 382 |
| 393 drag_source_->StartDragging(drop_data, ops, view_gtk->last_mouse_down(), | 383 drag_source_->StartDragging(drop_data, ops, view_gtk->last_mouse_down(), |
| 394 image, image_offset); | 384 image, image_offset); |
| 395 } | 385 } |
| 396 | 386 |
| 397 // ----------------------------------------------------------------------------- | 387 // ----------------------------------------------------------------------------- |
| 398 | 388 |
| 399 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { | |
| 400 gtk_container_add(GTK_CONTAINER(expanded_), widget); | |
| 401 } | |
| 402 | |
| 403 // Called when the content view gtk widget is tabbed to, or after the call to | |
| 404 // gtk_widget_child_focus() in TakeFocus(). We return true | |
| 405 // and grab focus if we don't have it. The call to | |
| 406 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to | |
| 407 // webkit. | |
| 408 gboolean TabContentsViewGtk::OnFocus(GtkWidget* widget, | |
| 409 GtkDirectionType focus) { | |
| 410 // If we are showing a constrained window, don't allow the native view to take | |
| 411 // focus. | |
| 412 if (constrained_window_) { | |
| 413 // If we return false, it will revert to the default handler, which will | |
| 414 // take focus. We don't want that. But if we return true, the event will | |
| 415 // stop being propagated, leaving focus wherever it is currently. That is | |
| 416 // also bad. So we return false to let the default handler run, but take | |
| 417 // focus first so as to trick it into thinking the view was already focused | |
| 418 // and allowing the event to propagate. | |
| 419 gtk_widget_grab_focus(widget); | |
| 420 return FALSE; | |
| 421 } | |
| 422 | |
| 423 // If we already have focus, let the next widget have a shot at it. We will | |
| 424 // reach this situation after the call to gtk_widget_child_focus() in | |
| 425 // TakeFocus(). | |
| 426 if (gtk_widget_is_focus(widget)) | |
| 427 return FALSE; | |
| 428 | |
| 429 gtk_widget_grab_focus(widget); | |
| 430 bool reverse = focus == GTK_DIR_TAB_BACKWARD; | |
| 431 tab_contents_->FocusThroughTabTraversal(reverse); | |
| 432 return TRUE; | |
| 433 } | |
| 434 | |
| 435 void TabContentsViewGtk::OnChildSizeRequest(GtkWidget* widget, | 389 void TabContentsViewGtk::OnChildSizeRequest(GtkWidget* widget, |
| 436 GtkWidget* child, | 390 GtkWidget* child, |
| 437 GtkRequisition* requisition) { | 391 GtkRequisition* requisition) { |
| 438 if (tab_contents_->delegate()) { | 392 if (tab_contents_->delegate()) { |
| 439 requisition->height += | 393 requisition->height += |
| 440 tab_contents_->delegate()->GetExtraRenderViewHeight(); | 394 tab_contents_->delegate()->GetExtraRenderViewHeight(); |
| 441 } | 395 } |
| 442 } | 396 } |
| 443 | 397 |
| 444 void TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, | 398 void TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, |
| 445 GtkAllocation* allocation) { | 399 GtkAllocation* allocation) { |
| 446 int width = allocation->width; | 400 int width = allocation->width; |
| 447 int height = allocation->height; | 401 int height = allocation->height; |
| 448 // |delegate()| can be NULL here during browser teardown. | 402 // |delegate()| can be NULL here during browser teardown. |
| 449 if (tab_contents_->delegate()) | 403 if (tab_contents_->delegate()) |
| 450 height += tab_contents_->delegate()->GetExtraRenderViewHeight(); | 404 height += tab_contents_->delegate()->GetExtraRenderViewHeight(); |
| 451 gfx::Size size(width, height); | 405 gfx::Size size(width, height); |
| 452 requested_size_ = size; | 406 requested_size_ = size; |
| 453 | 407 |
| 454 // We manually tell our RWHV to resize the renderer content. This avoids | 408 // We manually tell our RWHV to resize the renderer content. This avoids |
| 455 // spurious resizes from GTK+. | 409 // spurious resizes from GTK+. |
| 456 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); | 410 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); |
| 457 if (rwhv) | 411 if (rwhv) |
| 458 rwhv->SetSize(size); | 412 rwhv->SetSize(size); |
| 459 if (tab_contents_->interstitial_page()) | 413 if (tab_contents_->interstitial_page()) |
| 460 tab_contents_->interstitial_page()->SetSize(size); | 414 tab_contents_->interstitial_page()->SetSize(size); |
| 461 } | 415 } |
| 462 | |
| 463 void TabContentsViewGtk::OnSetFloatingPosition( | |
| 464 GtkWidget* floating_container, GtkAllocation* allocation) { | |
| 465 if (!constrained_window_) | |
| 466 return; | |
| 467 | |
| 468 // Place each ConstrainedWindow in the center of the view. | |
| 469 GtkWidget* widget = constrained_window_->widget(); | |
| 470 DCHECK(widget->parent == floating_.get()); | |
| 471 | |
| 472 GtkRequisition requisition; | |
| 473 gtk_widget_size_request(widget, &requisition); | |
| 474 | |
| 475 GValue value = { 0, }; | |
| 476 g_value_init(&value, G_TYPE_INT); | |
| 477 | |
| 478 int child_x = std::max((allocation->width - requisition.width) / 2, 0); | |
| 479 g_value_set_int(&value, child_x); | |
| 480 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | |
| 481 widget, "x", &value); | |
| 482 | |
| 483 int child_y = std::max((allocation->height - requisition.height) / 2, 0); | |
| 484 g_value_set_int(&value, child_y); | |
| 485 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | |
| 486 widget, "y", &value); | |
| 487 g_value_unset(&value); | |
| 488 } | |
| OLD | NEW |