| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/renderer_host/render_widget_host_view_gtk.h" | 5 #include "chrome/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 URLRequestStatus::Status. | 9 // badly with URLRequestStatus::Status. |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "gfx/gtk_preserve_window.h" | 39 #include "gfx/gtk_preserve_window.h" |
| 40 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" | 40 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" |
| 41 #include "webkit/glue/plugins/webplugin.h" | 41 #include "webkit/glue/plugins/webplugin.h" |
| 42 #include "webkit/glue/webaccessibility.h" | 42 #include "webkit/glue/webaccessibility.h" |
| 43 #include "webkit/glue/webcursor_gtk_data.h" | 43 #include "webkit/glue/webcursor_gtk_data.h" |
| 44 | 44 |
| 45 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
| 46 #include "views/widget/tooltip_window_gtk.h" | 46 #include "views/widget/tooltip_window_gtk.h" |
| 47 #endif // defined(OS_CHROMEOS) | 47 #endif // defined(OS_CHROMEOS) |
| 48 | 48 |
| 49 static const int kMaxWindowWidth = 4000; | 49 namespace { |
| 50 static const int kMaxWindowHeight = 4000; | 50 |
| 51 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 51 const int kMaxWindowWidth = 4000; |
| 52 const int kMaxWindowHeight = 4000; |
| 53 const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
| 54 |
| 55 // The duration of the fade-out animation. See |overlay_animation_|. |
| 56 const int kFadeEffectDuration = 300; |
| 52 | 57 |
| 53 #if defined(OS_CHROMEOS) | 58 #if defined(OS_CHROMEOS) |
| 54 // TODO(davemoore) Under Chromeos we are increasing the rate that the trackpad | 59 // TODO(davemoore) Under Chromeos we are increasing the rate that the trackpad |
| 55 // generates events to get better precisions. Eventually we will coordinate the | 60 // generates events to get better precisions. Eventually we will coordinate the |
| 56 // driver and this setting to ensure they match. | 61 // driver and this setting to ensure they match. |
| 57 static const float kDefaultScrollPixelsPerTick = 20; | 62 const float kDefaultScrollPixelsPerTick = 20; |
| 58 #else | 63 #else |
| 59 // See WebInputEventFactor.cpp for a reason for this being the default | 64 // See WebInputEventFactor.cpp for a reason for this being the default |
| 60 // scroll size for linux. | 65 // scroll size for linux. |
| 61 static const float kDefaultScrollPixelsPerTick = 160.0f / 3.0f; | 66 const float kDefaultScrollPixelsPerTick = 160.0f / 3.0f; |
| 62 #endif | 67 #endif |
| 63 | 68 |
| 69 } // namespace |
| 70 |
| 64 using WebKit::WebInputEventFactory; | 71 using WebKit::WebInputEventFactory; |
| 65 using WebKit::WebMouseWheelEvent; | 72 using WebKit::WebMouseWheelEvent; |
| 66 | 73 |
| 67 // This class is a simple convenience wrapper for Gtk functions. It has only | 74 // This class is a simple convenience wrapper for Gtk functions. It has only |
| 68 // static methods. | 75 // static methods. |
| 69 class RenderWidgetHostViewGtkWidget { | 76 class RenderWidgetHostViewGtkWidget { |
| 70 public: | 77 public: |
| 71 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { | 78 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { |
| 72 GtkWidget* widget = gtk_preserve_window_new(); | 79 GtkWidget* widget = gtk_preserve_window_new(); |
| 73 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); | 80 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 RenderWidgetHost* widget) { | 480 RenderWidgetHost* widget) { |
| 474 return new RenderWidgetHostViewGtk(widget); | 481 return new RenderWidgetHostViewGtk(widget); |
| 475 } | 482 } |
| 476 | 483 |
| 477 RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host) | 484 RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host) |
| 478 : host_(widget_host), | 485 : host_(widget_host), |
| 479 about_to_validate_and_paint_(false), | 486 about_to_validate_and_paint_(false), |
| 480 is_hidden_(false), | 487 is_hidden_(false), |
| 481 is_loading_(false), | 488 is_loading_(false), |
| 482 is_showing_context_menu_(false), | 489 is_showing_context_menu_(false), |
| 483 visually_deemphasized_(false), | 490 overlay_color_(0), |
| 491 overlay_animation_(this), |
| 484 parent_host_view_(NULL), | 492 parent_host_view_(NULL), |
| 485 parent_(NULL), | 493 parent_(NULL), |
| 486 is_popup_first_mouse_release_(true), | 494 is_popup_first_mouse_release_(true), |
| 487 was_focused_before_grab_(false), | 495 was_focused_before_grab_(false), |
| 488 do_x_grab_(false), | 496 do_x_grab_(false), |
| 489 dragged_at_horizontal_edge_(0), | 497 dragged_at_horizontal_edge_(0), |
| 490 dragged_at_vertical_edge_(0) { | 498 dragged_at_vertical_edge_(0) { |
| 491 host_->set_view(this); | 499 host_->set_view(this); |
| 492 } | 500 } |
| 493 | 501 |
| 494 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { | 502 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { |
| 495 view_.Destroy(); | 503 view_.Destroy(); |
| 496 } | 504 } |
| 497 | 505 |
| 498 void RenderWidgetHostViewGtk::InitAsChild() { | 506 void RenderWidgetHostViewGtk::InitAsChild() { |
| 499 view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); | 507 view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); |
| 500 // |im_context_| must be created after creating |view_| widget. | 508 // |im_context_| must be created after creating |view_| widget. |
| 501 im_context_.reset(new GtkIMContextWrapper(this)); | 509 im_context_.reset(new GtkIMContextWrapper(this)); |
| 502 // |key_bindings_handler_| must be created after creating |view_| widget. | 510 // |key_bindings_handler_| must be created after creating |view_| widget. |
| 503 key_bindings_handler_.reset(new GtkKeyBindingsHandler(view_.get())); | 511 key_bindings_handler_.reset(new GtkKeyBindingsHandler(view_.get())); |
| 504 plugin_container_manager_.set_host_widget(view_.get()); | 512 plugin_container_manager_.set_host_widget(view_.get()); |
| 505 | 513 |
| 506 #if defined(OS_CHROMEOS) | 514 #if defined(OS_CHROMEOS) |
| 507 tooltip_window_.reset(new views::TooltipWindowGtk(view_.get())); | 515 tooltip_window_.reset(new views::TooltipWindowGtk(view_.get())); |
| 508 #endif // defined(OS_CHROMEOS) | 516 #endif // defined(OS_CHROMEOS) |
| 509 | 517 |
| 518 overlay_animation_.SetDuration(kFadeEffectDuration); |
| 519 overlay_animation_.SetSlideDuration(kFadeEffectDuration); |
| 520 |
| 510 gtk_widget_show(view_.get()); | 521 gtk_widget_show(view_.get()); |
| 511 } | 522 } |
| 512 | 523 |
| 513 void RenderWidgetHostViewGtk::InitAsPopup( | 524 void RenderWidgetHostViewGtk::InitAsPopup( |
| 514 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { | 525 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { |
| 515 DoInitAsPopup(parent_host_view, GTK_WINDOW_POPUP, pos, false); | 526 DoInitAsPopup(parent_host_view, GTK_WINDOW_POPUP, pos, false); |
| 516 } | 527 } |
| 517 | 528 |
| 518 void RenderWidgetHostViewGtk::InitAsFullscreen( | 529 void RenderWidgetHostViewGtk::InitAsFullscreen( |
| 519 RenderWidgetHostView* parent_host_view) { | 530 RenderWidgetHostView* parent_host_view) { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 about_to_validate_and_paint_ = false; | 841 about_to_validate_and_paint_ = false; |
| 831 | 842 |
| 832 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); | 843 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); |
| 833 paint_rect = paint_rect.Intersect(invalid_rect_); | 844 paint_rect = paint_rect.Intersect(invalid_rect_); |
| 834 | 845 |
| 835 if (backing_store) { | 846 if (backing_store) { |
| 836 // Only render the widget if it is attached to a window; there's a short | 847 // Only render the widget if it is attached to a window; there's a short |
| 837 // period where this object isn't attached to a window but hasn't been | 848 // period where this object isn't attached to a window but hasn't been |
| 838 // Destroy()ed yet and it receives paint messages... | 849 // Destroy()ed yet and it receives paint messages... |
| 839 if (window) { | 850 if (window) { |
| 840 if (!visually_deemphasized_) { | 851 if (SkColorGetA(overlay_color_) == 0) { |
| 841 // In the common case, use XCopyArea. We don't draw more than once, so | 852 // In the common case, use XCopyArea. We don't draw more than once, so |
| 842 // we don't need to double buffer. | 853 // we don't need to double buffer. |
| 843 backing_store->XShowRect(gfx::Point(0, 0), | 854 backing_store->XShowRect(gfx::Point(0, 0), |
| 844 paint_rect, x11_util::GetX11WindowFromGtkWidget(view_.get())); | 855 paint_rect, x11_util::GetX11WindowFromGtkWidget(view_.get())); |
| 845 } else { | 856 } else { |
| 846 // If the grey blend is showing, we make two drawing calls. Use double | 857 // If the grey blend is showing, we make two drawing calls. Use double |
| 847 // buffering to prevent flicker. Use CairoShowRect because XShowRect | 858 // buffering to prevent flicker. Use CairoShowRect because XShowRect |
| 848 // shortcuts GDK's double buffering. We won't be able to draw outside | 859 // shortcuts GDK's double buffering. We won't be able to draw outside |
| 849 // of |damage_rect|, so invalidate the difference between |paint_rect| | 860 // of |damage_rect|, so invalidate the difference between |paint_rect| |
| 850 // and |damage_rect|. | 861 // and |damage_rect|. |
| 851 if (paint_rect != damage_rect) { | 862 if (paint_rect != damage_rect) { |
| 852 GdkRectangle extra_gdk_rect = | 863 GdkRectangle extra_gdk_rect = |
| 853 paint_rect.Subtract(damage_rect).ToGdkRectangle(); | 864 paint_rect.Subtract(damage_rect).ToGdkRectangle(); |
| 854 gdk_window_invalidate_rect(window, &extra_gdk_rect, false); | 865 gdk_window_invalidate_rect(window, &extra_gdk_rect, false); |
| 855 } | 866 } |
| 856 | 867 |
| 857 GdkRectangle rect = { damage_rect.x(), damage_rect.y(), | 868 GdkRectangle rect = { damage_rect.x(), damage_rect.y(), |
| 858 damage_rect.width(), damage_rect.height() }; | 869 damage_rect.width(), damage_rect.height() }; |
| 859 gdk_window_begin_paint_rect(window, &rect); | 870 gdk_window_begin_paint_rect(window, &rect); |
| 860 | 871 |
| 861 backing_store->CairoShowRect(damage_rect, GDK_DRAWABLE(window)); | 872 backing_store->CairoShowRect(damage_rect, GDK_DRAWABLE(window)); |
| 862 | 873 |
| 863 cairo_t* cr = gdk_cairo_create(window); | 874 cairo_t* cr = gdk_cairo_create(window); |
| 864 gdk_cairo_rectangle(cr, &rect); | 875 gdk_cairo_rectangle(cr, &rect); |
| 865 cairo_set_source_rgba(cr, 0, 0, 0, 0.7); | 876 SkColor overlay = SkColorSetA( |
| 877 overlay_color_, |
| 878 SkColorGetA(overlay_color_) * |
| 879 overlay_animation_.GetCurrentValue()); |
| 880 float r = SkColorGetR(overlay) / 255.; |
| 881 float g = SkColorGetG(overlay) / 255.; |
| 882 float b = SkColorGetB(overlay) / 255.; |
| 883 float a = SkColorGetA(overlay) / 255.; |
| 884 cairo_set_source_rgba(cr, r, g, b, a); |
| 866 cairo_fill(cr); | 885 cairo_fill(cr); |
| 867 cairo_destroy(cr); | 886 cairo_destroy(cr); |
| 868 | 887 |
| 869 gdk_window_end_paint(window); | 888 gdk_window_end_paint(window); |
| 870 } | 889 } |
| 871 } | 890 } |
| 872 if (!whiteout_start_time_.is_null()) { | 891 if (!whiteout_start_time_.is_null()) { |
| 873 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - | 892 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - |
| 874 whiteout_start_time_; | 893 whiteout_start_time_; |
| 875 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); | 894 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 void RenderWidgetHostViewGtk::CreatePluginContainer( | 1042 void RenderWidgetHostViewGtk::CreatePluginContainer( |
| 1024 gfx::PluginWindowHandle id) { | 1043 gfx::PluginWindowHandle id) { |
| 1025 plugin_container_manager_.CreatePluginContainer(id); | 1044 plugin_container_manager_.CreatePluginContainer(id); |
| 1026 } | 1045 } |
| 1027 | 1046 |
| 1028 void RenderWidgetHostViewGtk::DestroyPluginContainer( | 1047 void RenderWidgetHostViewGtk::DestroyPluginContainer( |
| 1029 gfx::PluginWindowHandle id) { | 1048 gfx::PluginWindowHandle id) { |
| 1030 plugin_container_manager_.DestroyPluginContainer(id); | 1049 plugin_container_manager_.DestroyPluginContainer(id); |
| 1031 } | 1050 } |
| 1032 | 1051 |
| 1033 void RenderWidgetHostViewGtk::SetVisuallyDeemphasized(bool deemphasized) { | 1052 void RenderWidgetHostViewGtk::SetVisuallyDeemphasized( |
| 1034 if (deemphasized == visually_deemphasized_) | 1053 const SkColor* color, bool animate) { |
| 1054 // Do nothing unless |color| has changed, meaning |animate| is only |
| 1055 // respected for the first call. |
| 1056 if (color && (*color == overlay_color_)) |
| 1035 return; | 1057 return; |
| 1036 | 1058 |
| 1037 visually_deemphasized_ = deemphasized; | 1059 overlay_color_ = color ? *color : 0; |
| 1038 gtk_widget_queue_draw(view_.get()); | 1060 |
| 1061 if (animate) { |
| 1062 overlay_animation_.Reset(); |
| 1063 overlay_animation_.Show(); |
| 1064 } else { |
| 1065 overlay_animation_.Reset(1.0); |
| 1066 gtk_widget_queue_draw(view_.get()); |
| 1067 } |
| 1039 } | 1068 } |
| 1040 | 1069 |
| 1041 bool RenderWidgetHostViewGtk::ContainsNativeView( | 1070 bool RenderWidgetHostViewGtk::ContainsNativeView( |
| 1042 gfx::NativeView native_view) const { | 1071 gfx::NativeView native_view) const { |
| 1043 // TODO(port) | 1072 // TODO(port) |
| 1044 NOTREACHED() << | 1073 NOTREACHED() << |
| 1045 "RenderWidgetHostViewGtk::ContainsNativeView not implemented."; | 1074 "RenderWidgetHostViewGtk::ContainsNativeView not implemented."; |
| 1046 return false; | 1075 return false; |
| 1047 } | 1076 } |
| 1048 | 1077 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1059 return; | 1088 return; |
| 1060 | 1089 |
| 1061 EditCommands edit_commands; | 1090 EditCommands edit_commands; |
| 1062 if (!event.skip_in_browser && | 1091 if (!event.skip_in_browser && |
| 1063 key_bindings_handler_->Match(event, &edit_commands)) { | 1092 key_bindings_handler_->Match(event, &edit_commands)) { |
| 1064 host_->ForwardEditCommandsForNextKeyEvent(edit_commands); | 1093 host_->ForwardEditCommandsForNextKeyEvent(edit_commands); |
| 1065 } | 1094 } |
| 1066 host_->ForwardKeyboardEvent(event); | 1095 host_->ForwardKeyboardEvent(event); |
| 1067 } | 1096 } |
| 1068 | 1097 |
| 1098 void RenderWidgetHostViewGtk::AnimationEnded(const Animation* animation) { |
| 1099 gtk_widget_queue_draw(view_.get()); |
| 1100 } |
| 1101 |
| 1102 void RenderWidgetHostViewGtk::AnimationProgressed(const Animation* animation) { |
| 1103 gtk_widget_queue_draw(view_.get()); |
| 1104 } |
| 1105 |
| 1106 void RenderWidgetHostViewGtk::AnimationCanceled(const Animation* animation) { |
| 1107 gtk_widget_queue_draw(view_.get()); |
| 1108 } |
| 1109 |
| 1069 // static | 1110 // static |
| 1070 RenderWidgetHostView* | 1111 RenderWidgetHostView* |
| 1071 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1112 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 1072 gfx::NativeView widget) { | 1113 gfx::NativeView widget) { |
| 1073 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 1114 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
| 1074 kRenderWidgetHostViewKey); | 1115 kRenderWidgetHostViewKey); |
| 1075 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 1116 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
| 1076 } | 1117 } |
| OLD | NEW |