| 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 <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { | 469 void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { |
| 470 // This is used for positioning the download shelf arrow animation, | 470 // This is used for positioning the download shelf arrow animation, |
| 471 // as well as sizing some other widgets in Windows. In GTK the size is | 471 // as well as sizing some other widgets in Windows. In GTK the size is |
| 472 // managed for us, so it appears to be only used for the download shelf | 472 // managed for us, so it appears to be only used for the download shelf |
| 473 // animation. | 473 // animation. |
| 474 int x = 0; | 474 int x = 0; |
| 475 int y = 0; | 475 int y = 0; |
| 476 if (fixed_->window) | 476 if (fixed_->window) |
| 477 gdk_window_get_origin(fixed_->window, &x, &y); | 477 gdk_window_get_origin(fixed_->window, &x, &y); |
| 478 out->SetRect(x + fixed_->allocation.x, y + fixed_->allocation.y, | 478 out->SetRect(x + fixed_->allocation.x, y + fixed_->allocation.y, |
| 479 fixed_->allocation.width, fixed_->allocation.height); | 479 requested_size_.width(), requested_size_.height()); |
| 480 } | 480 } |
| 481 | 481 |
| 482 void TabContentsViewGtk::OnContentsDestroy() { | 482 void TabContentsViewGtk::OnContentsDestroy() { |
| 483 // We don't want to try to handle drag events from this point on. | 483 // We don't want to try to handle drag events from this point on. |
| 484 drag_source_.reset(); | 484 drag_source_.reset(); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void TabContentsViewGtk::SetPageTitle(const std::wstring& title) { | 487 void TabContentsViewGtk::SetPageTitle(const std::wstring& title) { |
| 488 // Set the window name to include the page title so it's easier to spot | 488 // Set the window name to include the page title so it's easier to spot |
| 489 // when debugging (e.g. via xwininfo -tree). | 489 // when debugging (e.g. via xwininfo -tree). |
| 490 gfx::NativeView content_view = GetContentNativeView(); | 490 gfx::NativeView content_view = GetContentNativeView(); |
| 491 if (content_view && content_view->window) | 491 if (content_view && content_view->window) |
| 492 gdk_window_set_title(content_view->window, WideToUTF8(title).c_str()); | 492 gdk_window_set_title(content_view->window, WideToUTF8(title).c_str()); |
| 493 } | 493 } |
| 494 | 494 |
| 495 void TabContentsViewGtk::OnTabCrashed() { | 495 void TabContentsViewGtk::OnTabCrashed() { |
| 496 if (!sad_tab_.get()) { | 496 if (!sad_tab_.get()) { |
| 497 sad_tab_.reset(new SadTabGtk); | 497 sad_tab_.reset(new SadTabGtk); |
| 498 InsertIntoContentArea(sad_tab_->widget()); | 498 InsertIntoContentArea(sad_tab_->widget()); |
| 499 gtk_widget_show(sad_tab_->widget()); | 499 gtk_widget_show(sad_tab_->widget()); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 | 502 |
| 503 void TabContentsViewGtk::SizeContents(const gfx::Size& size) { | 503 void TabContentsViewGtk::SizeContents(const gfx::Size& size) { |
| 504 // We don't normally need to manually set the size of of widgets in GTK+, | 504 // We don't need to manually set the size of of widgets in GTK+, but we do |
| 505 // but this is used when creating background tabs. When a tab is created in | 505 // need to pass the sizing information on to the RWHV which will pass the |
| 506 // the background, we need to set the size so WebKit can properly compute | 506 // sizing information on to the renderer. |
| 507 // the scrolling offset if a #ref is provided. | 507 requested_size_ = size; |
| 508 if (tab_contents()->render_widget_host_view()) { | 508 if (tab_contents()->render_widget_host_view()) |
| 509 GtkWidget* widget = | 509 tab_contents()->render_widget_host_view()->SetSize(size); |
| 510 tab_contents()->render_widget_host_view()->GetNativeView(); | |
| 511 // During unit tests, |widget| can be NULL. | |
| 512 if (widget) { | |
| 513 widget->allocation.width = size.width(); | |
| 514 widget->allocation.height = size.height(); | |
| 515 } | |
| 516 } | |
| 517 } | 510 } |
| 518 | 511 |
| 519 void TabContentsViewGtk::Focus() { | 512 void TabContentsViewGtk::Focus() { |
| 520 if (tab_contents()->showing_interstitial_page()) { | 513 if (tab_contents()->showing_interstitial_page()) { |
| 521 tab_contents()->interstitial_page()->Focus(); | 514 tab_contents()->interstitial_page()->Focus(); |
| 522 } else { | 515 } else { |
| 523 GtkWidget* widget = GetContentNativeView(); | 516 GtkWidget* widget = GetContentNativeView(); |
| 524 if (widget) | 517 if (widget) |
| 525 gtk_widget_grab_focus(widget); | 518 gtk_widget_grab_focus(widget); |
| 526 } | 519 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 GdkEventButton* event, TabContentsViewGtk* view) { | 621 GdkEventButton* event, TabContentsViewGtk* view) { |
| 629 view->last_mouse_down_ = *event; | 622 view->last_mouse_down_ = *event; |
| 630 return FALSE; | 623 return FALSE; |
| 631 } | 624 } |
| 632 | 625 |
| 633 gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, | 626 gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, |
| 634 GtkAllocation* allocation, | 627 GtkAllocation* allocation, |
| 635 TabContentsViewGtk* view) { | 628 TabContentsViewGtk* view) { |
| 636 int width = allocation->width; | 629 int width = allocation->width; |
| 637 int height = allocation->height; | 630 int height = allocation->height; |
| 631 view->requested_size_.set_width(width); |
| 632 view->requested_size_.set_height(height); |
| 638 // |delegate()| can be NULL here during browser teardown. | 633 // |delegate()| can be NULL here during browser teardown. |
| 639 if (view->tab_contents()->delegate()) | 634 if (view->tab_contents()->delegate()) |
| 640 height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); | 635 height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); |
| 641 gfx::Size size(width, height); | 636 gfx::Size size(width, height); |
| 642 gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size); | 637 gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size); |
| 643 | 638 |
| 644 return FALSE; | 639 return FALSE; |
| 645 } | 640 } |
| 646 | 641 |
| 647 // static | 642 // static |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 691 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 697 widget, "x", &value); | 692 widget, "x", &value); |
| 698 | 693 |
| 699 int child_y = std::max(half_view_height - (requisition.height / 2), 0); | 694 int child_y = std::max(half_view_height - (requisition.height / 2), 0); |
| 700 g_value_set_int(&value, child_y); | 695 g_value_set_int(&value, child_y); |
| 701 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 696 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 702 widget, "y", &value); | 697 widget, "y", &value); |
| 703 g_value_unset(&value); | 698 g_value_unset(&value); |
| 704 } | 699 } |
| 705 } | 700 } |
| OLD | NEW |