| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_gtk.h" | 5 #include "content/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 net::URLRequestStatus::Status. | 9 // badly with net::URLRequestStatus::Status. |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "third_party/WebKit/Source/WebKit/chromium/public/x11/WebScreenInfoFact
ory.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/x11/WebScreenInfoFact
ory.h" |
| 46 #include "ui/base/gtk/gtk_compat.h" | 46 #include "ui/base/gtk/gtk_compat.h" |
| 47 #include "ui/base/text/text_elider.h" | 47 #include "ui/base/text/text_elider.h" |
| 48 #include "ui/base/x/active_window_watcher_x.h" | 48 #include "ui/base/x/active_window_watcher_x.h" |
| 49 #include "ui/base/x/x11_util.h" | 49 #include "ui/base/x/x11_util.h" |
| 50 #include "ui/gfx/gtk_native_view_id_manager.h" | 50 #include "ui/gfx/gtk_native_view_id_manager.h" |
| 51 #include "ui/gfx/gtk_preserve_window.h" | 51 #include "ui/gfx/gtk_preserve_window.h" |
| 52 #include "webkit/glue/webcursor_gtk_data.h" | 52 #include "webkit/glue/webcursor_gtk_data.h" |
| 53 #include "webkit/plugins/npapi/webplugin.h" | 53 #include "webkit/plugins/npapi/webplugin.h" |
| 54 | 54 |
| 55 using WebKit::WebInputEventFactory; |
| 56 using WebKit::WebMouseWheelEvent; |
| 57 using WebKit::WebScreenInfo; |
| 58 |
| 59 namespace content { |
| 55 namespace { | 60 namespace { |
| 56 | 61 |
| 57 // Paint rects on Linux are bounded by the maximum size of a shared memory | 62 // Paint rects on Linux are bounded by the maximum size of a shared memory |
| 58 // region. By default that's 32MB, but many distros increase it significantly | 63 // region. By default that's 32MB, but many distros increase it significantly |
| 59 // (i.e. to 256MB). | 64 // (i.e. to 256MB). |
| 60 // | 65 // |
| 61 // We fetch the maximum value from /proc/sys/kernel/shmmax at runtime and, if | 66 // We fetch the maximum value from /proc/sys/kernel/shmmax at runtime and, if |
| 62 // we exceed that, then we limit the height of the paint rect in the renderer. | 67 // we exceed that, then we limit the height of the paint rect in the renderer. |
| 63 // | 68 // |
| 64 // These constants are here to ensure that, in the event that we exceed it, we | 69 // These constants are here to ensure that, in the event that we exceed it, we |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 102 } |
| 98 | 103 |
| 99 bool MovedToCenter(const WebKit::WebMouseEvent& mouse_event, | 104 bool MovedToCenter(const WebKit::WebMouseEvent& mouse_event, |
| 100 const gfx::Point& center) { | 105 const gfx::Point& center) { |
| 101 return mouse_event.globalX == center.x() && | 106 return mouse_event.globalX == center.x() && |
| 102 mouse_event.globalY == center.y(); | 107 mouse_event.globalY == center.y(); |
| 103 } | 108 } |
| 104 | 109 |
| 105 } // namespace | 110 } // namespace |
| 106 | 111 |
| 107 using content::NativeWebKeyboardEvent; | |
| 108 using content::RenderWidgetHostImpl; | |
| 109 using content::RenderWidgetHostView; | |
| 110 using content::RenderWidgetHostViewPort; | |
| 111 using WebKit::WebInputEventFactory; | |
| 112 using WebKit::WebMouseWheelEvent; | |
| 113 | |
| 114 // This class is a simple convenience wrapper for Gtk functions. It has only | 112 // This class is a simple convenience wrapper for Gtk functions. It has only |
| 115 // static methods. | 113 // static methods. |
| 116 class RenderWidgetHostViewGtkWidget { | 114 class RenderWidgetHostViewGtkWidget { |
| 117 public: | 115 public: |
| 118 static AtkObject* GetAccessible(void* userdata) { | 116 static AtkObject* GetAccessible(void* userdata) { |
| 119 return (static_cast<RenderWidgetHostViewGtk*>(userdata))-> | 117 return (static_cast<RenderWidgetHostViewGtk*>(userdata))-> |
| 120 GetAccessible(); | 118 GetAccessible(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { | 121 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 web_event.deltaX += GetPendingScrollDelta(false, event->state); | 558 web_event.deltaX += GetPendingScrollDelta(false, event->state); |
| 561 } | 559 } |
| 562 RenderWidgetHostImpl::From( | 560 RenderWidgetHostImpl::From( |
| 563 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event); | 561 host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event); |
| 564 return FALSE; | 562 return FALSE; |
| 565 } | 563 } |
| 566 | 564 |
| 567 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); | 565 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); |
| 568 }; | 566 }; |
| 569 | 567 |
| 570 RenderWidgetHostViewGtk::RenderWidgetHostViewGtk( | 568 RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host) |
| 571 content::RenderWidgetHost* widget_host) | |
| 572 : host_(RenderWidgetHostImpl::From(widget_host)), | 569 : host_(RenderWidgetHostImpl::From(widget_host)), |
| 573 about_to_validate_and_paint_(false), | 570 about_to_validate_and_paint_(false), |
| 574 is_hidden_(false), | 571 is_hidden_(false), |
| 575 is_loading_(false), | 572 is_loading_(false), |
| 576 parent_(NULL), | 573 parent_(NULL), |
| 577 is_popup_first_mouse_release_(true), | 574 is_popup_first_mouse_release_(true), |
| 578 was_imcontext_focused_before_grab_(false), | 575 was_imcontext_focused_before_grab_(false), |
| 579 do_x_grab_(false), | 576 do_x_grab_(false), |
| 580 is_fullscreen_(false), | 577 is_fullscreen_(false), |
| 581 made_active_(false), | 578 made_active_(false), |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 } else { | 683 } else { |
| 687 bounds = gfx::Rect( | 684 bounds = gfx::Rect( |
| 688 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen)); | 685 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen)); |
| 689 } | 686 } |
| 690 gtk_window_move(window, bounds.x(), bounds.y()); | 687 gtk_window_move(window, bounds.x(), bounds.y()); |
| 691 gtk_window_resize(window, bounds.width(), bounds.height()); | 688 gtk_window_resize(window, bounds.width(), bounds.height()); |
| 692 gtk_window_fullscreen(window); | 689 gtk_window_fullscreen(window); |
| 693 DoPopupOrFullscreenInit(window, bounds); | 690 DoPopupOrFullscreenInit(window, bounds); |
| 694 } | 691 } |
| 695 | 692 |
| 696 content::RenderWidgetHost* | 693 RenderWidgetHost* RenderWidgetHostViewGtk::GetRenderWidgetHost() const { |
| 697 RenderWidgetHostViewGtk::GetRenderWidgetHost() const { | |
| 698 return host_; | 694 return host_; |
| 699 } | 695 } |
| 700 | 696 |
| 701 void RenderWidgetHostViewGtk::WasRestored() { | 697 void RenderWidgetHostViewGtk::WasRestored() { |
| 702 if (!is_hidden_) | 698 if (!is_hidden_) |
| 703 return; | 699 return; |
| 704 | 700 |
| 705 if (web_contents_switch_paint_time_.is_null()) | 701 if (web_contents_switch_paint_time_.is_null()) |
| 706 web_contents_switch_paint_time_ = base::TimeTicks::Now(); | 702 web_contents_switch_paint_time_ = base::TimeTicks::Now(); |
| 707 is_hidden_ = false; | 703 is_hidden_ = false; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 gtk_widget_set_has_tooltip(view_.get(), FALSE); | 937 gtk_widget_set_has_tooltip(view_.get(), FALSE); |
| 942 } else { | 938 } else { |
| 943 gtk_widget_set_tooltip_text(view_.get(), | 939 gtk_widget_set_tooltip_text(view_.get(), |
| 944 UTF16ToUTF8(clamped_tooltip).c_str()); | 940 UTF16ToUTF8(clamped_tooltip).c_str()); |
| 945 } | 941 } |
| 946 } | 942 } |
| 947 | 943 |
| 948 void RenderWidgetHostViewGtk::SelectionChanged(const string16& text, | 944 void RenderWidgetHostViewGtk::SelectionChanged(const string16& text, |
| 949 size_t offset, | 945 size_t offset, |
| 950 const ui::Range& range) { | 946 const ui::Range& range) { |
| 951 content::RenderWidgetHostViewBase::SelectionChanged(text, offset, range); | 947 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); |
| 952 | 948 |
| 953 if (text.empty() || range.is_empty()) | 949 if (text.empty() || range.is_empty()) |
| 954 return; | 950 return; |
| 955 size_t pos = range.GetMin() - offset; | 951 size_t pos = range.GetMin() - offset; |
| 956 size_t n = range.length(); | 952 size_t n = range.length(); |
| 957 | 953 |
| 958 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; | 954 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; |
| 959 if (pos >= text.length()) { | 955 if (pos >= text.length()) { |
| 960 NOTREACHED() << "The text can not cover range."; | 956 NOTREACHED() << "The text can not cover range."; |
| 961 return; | 957 return; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 | 1082 |
| 1087 bool RenderWidgetHostViewGtk::HasAcceleratedSurface( | 1083 bool RenderWidgetHostViewGtk::HasAcceleratedSurface( |
| 1088 const gfx::Size& desired_size) { | 1084 const gfx::Size& desired_size) { |
| 1089 // TODO(jbates) Implement this so this view can use GetBackingStore for both | 1085 // TODO(jbates) Implement this so this view can use GetBackingStore for both |
| 1090 // software and GPU frames. Defaulting to false just makes GetBackingStore | 1086 // software and GPU frames. Defaulting to false just makes GetBackingStore |
| 1091 // only useable for software frames. | 1087 // only useable for software frames. |
| 1092 return false; | 1088 return false; |
| 1093 } | 1089 } |
| 1094 | 1090 |
| 1095 void RenderWidgetHostViewGtk::SetBackground(const SkBitmap& background) { | 1091 void RenderWidgetHostViewGtk::SetBackground(const SkBitmap& background) { |
| 1096 content::RenderWidgetHostViewBase::SetBackground(background); | 1092 RenderWidgetHostViewBase::SetBackground(background); |
| 1097 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 1093 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
| 1098 } | 1094 } |
| 1099 | 1095 |
| 1100 void RenderWidgetHostViewGtk::ModifyEventForEdgeDragging( | 1096 void RenderWidgetHostViewGtk::ModifyEventForEdgeDragging( |
| 1101 GtkWidget* widget, GdkEventMotion* event) { | 1097 GtkWidget* widget, GdkEventMotion* event) { |
| 1102 // If the widget is aligned with an edge of the monitor its on and the user | 1098 // If the widget is aligned with an edge of the monitor its on and the user |
| 1103 // attempts to drag past that edge we track the number of times it has | 1099 // attempts to drag past that edge we track the number of times it has |
| 1104 // occurred, so that we can force the widget to scroll when it otherwise | 1100 // occurred, so that we can force the widget to scroll when it otherwise |
| 1105 // would be unable to, by modifying the (x,y) position in the drag | 1101 // would be unable to, by modifying the (x,y) position in the drag |
| 1106 // event that we forward on to webkit. If we get a move that's no longer a | 1102 // event that we forward on to webkit. If we get a move that's no longer a |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 } | 1252 } |
| 1257 | 1253 |
| 1258 | 1254 |
| 1259 void RenderWidgetHostViewGtk::OnAcceleratedCompositingStateChange() { | 1255 void RenderWidgetHostViewGtk::OnAcceleratedCompositingStateChange() { |
| 1260 bool activated = host_->is_accelerated_compositing_active(); | 1256 bool activated = host_->is_accelerated_compositing_active(); |
| 1261 GtkPreserveWindow* widget = reinterpret_cast<GtkPreserveWindow*>(view_.get()); | 1257 GtkPreserveWindow* widget = reinterpret_cast<GtkPreserveWindow*>(view_.get()); |
| 1262 | 1258 |
| 1263 gtk_preserve_window_delegate_resize(widget, activated); | 1259 gtk_preserve_window_delegate_resize(widget, activated); |
| 1264 } | 1260 } |
| 1265 | 1261 |
| 1266 void RenderWidgetHostViewGtk::GetScreenInfo(WebKit::WebScreenInfo* results) { | 1262 void RenderWidgetHostViewGtk::GetScreenInfo(WebScreenInfo* results) { |
| 1267 GdkWindow* gdk_window = gtk_widget_get_window(view_.get()); | 1263 GdkWindow* gdk_window = gtk_widget_get_window(view_.get()); |
| 1268 if (!gdk_window) { | 1264 if (!gdk_window) { |
| 1269 GdkDisplay* display = gdk_display_get_default(); | 1265 GdkDisplay* display = gdk_display_get_default(); |
| 1270 gdk_window = gdk_display_get_default_group(display); | 1266 gdk_window = gdk_display_get_default_group(display); |
| 1271 } | 1267 } |
| 1272 if (!gdk_window) | 1268 if (!gdk_window) |
| 1273 return; | 1269 return; |
| 1274 content::GetScreenInfoFromNativeWindow(gdk_window, results); | 1270 GetScreenInfoFromNativeWindow(gdk_window, results); |
| 1275 } | 1271 } |
| 1276 | 1272 |
| 1277 gfx::Rect RenderWidgetHostViewGtk::GetRootWindowBounds() { | 1273 gfx::Rect RenderWidgetHostViewGtk::GetRootWindowBounds() { |
| 1278 GtkWidget* toplevel = gtk_widget_get_toplevel(view_.get()); | 1274 GtkWidget* toplevel = gtk_widget_get_toplevel(view_.get()); |
| 1279 if (!toplevel) | 1275 if (!toplevel) |
| 1280 return gfx::Rect(); | 1276 return gfx::Rect(); |
| 1281 | 1277 |
| 1282 GdkRectangle frame_extents; | 1278 GdkRectangle frame_extents; |
| 1283 GdkWindow* gdk_window = gtk_widget_get_window(toplevel); | 1279 GdkWindow* gdk_window = gtk_widget_get_window(toplevel); |
| 1284 if (!gdk_window) | 1280 if (!gdk_window) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 unlocked_mouse_position_.SetPoint(event->windowX, event->windowY); | 1465 unlocked_mouse_position_.SetPoint(event->windowX, event->windowY); |
| 1470 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY); | 1466 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY); |
| 1471 } | 1467 } |
| 1472 } | 1468 } |
| 1473 | 1469 |
| 1474 //////////////////////////////////////////////////////////////////////////////// | 1470 //////////////////////////////////////////////////////////////////////////////// |
| 1475 // RenderWidgetHostView, public: | 1471 // RenderWidgetHostView, public: |
| 1476 | 1472 |
| 1477 // static | 1473 // static |
| 1478 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 1474 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
| 1479 content::RenderWidgetHost* widget) { | 1475 RenderWidgetHost* widget) { |
| 1480 return new RenderWidgetHostViewGtk(widget); | 1476 return new RenderWidgetHostViewGtk(widget); |
| 1481 } | 1477 } |
| 1482 | 1478 |
| 1483 // static | 1479 // static |
| 1484 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1480 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 1485 WebKit::WebScreenInfo* results) { | |
| 1486 GdkWindow* gdk_window = | 1481 GdkWindow* gdk_window = |
| 1487 gdk_display_get_default_group(gdk_display_get_default()); | 1482 gdk_display_get_default_group(gdk_display_get_default()); |
| 1488 content::GetScreenInfoFromNativeWindow(gdk_window, results); | 1483 GetScreenInfoFromNativeWindow(gdk_window, results); |
| 1489 } | 1484 } |
| 1490 | 1485 |
| 1491 void RenderWidgetHostViewGtk::SetAccessibilityFocus(int acc_obj_id) { | 1486 void RenderWidgetHostViewGtk::SetAccessibilityFocus(int acc_obj_id) { |
| 1492 if (!host_) | 1487 if (!host_) |
| 1493 return; | 1488 return; |
| 1494 | 1489 |
| 1495 host_->AccessibilitySetFocus(acc_obj_id); | 1490 host_->AccessibilitySetFocus(acc_obj_id); |
| 1496 } | 1491 } |
| 1497 | 1492 |
| 1498 void RenderWidgetHostViewGtk::AccessibilityDoDefaultAction(int acc_obj_id) { | 1493 void RenderWidgetHostViewGtk::AccessibilityDoDefaultAction(int acc_obj_id) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1526 host_->AccessibilitySetTextSelection(acc_obj_id, start_offset, end_offset); | 1521 host_->AccessibilitySetTextSelection(acc_obj_id, start_offset, end_offset); |
| 1527 } | 1522 } |
| 1528 | 1523 |
| 1529 void RenderWidgetHostViewGtk::OnAccessibilityNotifications( | 1524 void RenderWidgetHostViewGtk::OnAccessibilityNotifications( |
| 1530 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | 1525 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { |
| 1531 if (!browser_accessibility_manager_.get()) { | 1526 if (!browser_accessibility_manager_.get()) { |
| 1532 GtkWidget* parent = gtk_widget_get_parent(view_.get()); | 1527 GtkWidget* parent = gtk_widget_get_parent(view_.get()); |
| 1533 browser_accessibility_manager_.reset( | 1528 browser_accessibility_manager_.reset( |
| 1534 BrowserAccessibilityManager::CreateEmptyDocument( | 1529 BrowserAccessibilityManager::CreateEmptyDocument( |
| 1535 parent, | 1530 parent, |
| 1536 static_cast<content::AccessibilityNodeData::State>(0), | 1531 static_cast<AccessibilityNodeData::State>(0), |
| 1537 this)); | 1532 this)); |
| 1538 } | 1533 } |
| 1539 browser_accessibility_manager_->OnAccessibilityNotifications(params); | 1534 browser_accessibility_manager_->OnAccessibilityNotifications(params); |
| 1540 } | 1535 } |
| 1541 | 1536 |
| 1542 AtkObject* RenderWidgetHostViewGtk::GetAccessible() { | 1537 AtkObject* RenderWidgetHostViewGtk::GetAccessible() { |
| 1543 if (!browser_accessibility_manager_.get()) { | 1538 if (!browser_accessibility_manager_.get()) { |
| 1544 GtkWidget* parent = gtk_widget_get_parent(view_.get()); | 1539 GtkWidget* parent = gtk_widget_get_parent(view_.get()); |
| 1545 browser_accessibility_manager_.reset( | 1540 browser_accessibility_manager_.reset( |
| 1546 BrowserAccessibilityManager::CreateEmptyDocument( | 1541 BrowserAccessibilityManager::CreateEmptyDocument( |
| 1547 parent, | 1542 parent, |
| 1548 static_cast<content::AccessibilityNodeData::State>(0), | 1543 static_cast<AccessibilityNodeData::State>(0), |
| 1549 this)); | 1544 this)); |
| 1550 } | 1545 } |
| 1551 BrowserAccessibilityGtk* root = | 1546 BrowserAccessibilityGtk* root = |
| 1552 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); | 1547 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); |
| 1553 | 1548 |
| 1554 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); | 1549 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); |
| 1555 return root->GetAtkObject(); | 1550 return root->GetAtkObject(); |
| 1556 } | 1551 } |
| 1552 |
| 1553 } // namespace content |
| OLD | NEW |