diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-10 22:20:52 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-10 22:20:52 +0000 |
commit | dcc2977772bdd296d8bfbcaedafd4441def78e3d (patch) | |
tree | cb0bdc148cff3f5a221b89ad2c055212d58bb976 /content | |
parent | 404d9a54ceae52b741b3e173af12fb7fd21c8548 (diff) | |
download | chromium_src-dcc2977772bdd296d8bfbcaedafd4441def78e3d.zip chromium_src-dcc2977772bdd296d8bfbcaedafd4441def78e3d.tar.gz chromium_src-dcc2977772bdd296d8bfbcaedafd4441def78e3d.tar.bz2 |
Delete the GTK+ port of Chrome.
BUG=297026
R=ben@chromium.org
Review URL: https://codereview.chromium.org/231733005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263101 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
72 files changed, 12 insertions, 10671 deletions
diff --git a/content/browser/accessibility/accessibility_tree_formatter_gtk.cc b/content/browser/accessibility/accessibility_tree_formatter_gtk.cc deleted file mode 100644 index d244667..0000000 --- a/content/browser/accessibility/accessibility_tree_formatter_gtk.cc +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/accessibility/accessibility_tree_formatter.h" - -#include <atk/atk.h> - -#include "base/logging.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "content/browser/accessibility/browser_accessibility_gtk.h" - -namespace content { - -void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, - base::DictionaryValue* dict) { - BrowserAccessibilityGtk* node_gtk = - const_cast<BrowserAccessibility*>(&node)->ToBrowserAccessibilityGtk(); - AtkObject* atk_object = node_gtk->GetAtkObject(); - AtkRole role = atk_object_get_role(atk_object); - if (role != ATK_ROLE_UNKNOWN) - dict->SetString("role", atk_role_get_name(role)); - dict->SetString("name", atk_object_get_name(atk_object)); - dict->SetString("description", atk_object_get_description(atk_object)); - AtkStateSet* state_set = - atk_object_ref_state_set(atk_object); - base::ListValue* states = new base::ListValue; - for (int i = ATK_STATE_INVALID; i < ATK_STATE_LAST_DEFINED; i++) { - AtkStateType state_type = static_cast<AtkStateType>(i); - if (atk_state_set_contains_state(state_set, state_type)) - states->AppendString(atk_state_type_get_name(state_type)); - } - dict->Set("states", states); - dict->SetInteger("id", node.GetId()); -} - -base::string16 AccessibilityTreeFormatter::ToString( - const base::DictionaryValue& node, - const base::string16& indent) { - base::string16 line; - std::string role_value; - node.GetString("role", &role_value); - if (!role_value.empty()) { - WriteAttribute(true, - base::StringPrintf("[%s]", role_value.c_str()), &line); - } - - std::string name_value; - node.GetString("name", &name_value); - WriteAttribute(true, base::StringPrintf("name='%s'", name_value.c_str()), - &line); - - std::string description_value; - node.GetString("description", &description_value); - WriteAttribute(false, - base::StringPrintf("description='%s'", - description_value.c_str()), - &line); - - const base::ListValue* states_value; - node.GetList("states", &states_value); - for (base::ListValue::const_iterator it = states_value->begin(); - it != states_value->end(); - ++it) { - std::string state_value; - if ((*it)->GetAsString(&state_value)) - WriteAttribute(true, state_value, &line); - } - - int id_value; - node.GetInteger("id", &id_value); - WriteAttribute(false, - base::StringPrintf("id=%d", id_value), - &line); - - return indent + line + base::ASCIIToUTF16("\n"); -} - -void AccessibilityTreeFormatter::Initialize() {} - -// static -const base::FilePath::StringType -AccessibilityTreeFormatter::GetActualFileSuffix() { - return FILE_PATH_LITERAL("-actual-gtk.txt"); -} - -// static -const base::FilePath::StringType -AccessibilityTreeFormatter::GetExpectedFileSuffix() { - return FILE_PATH_LITERAL("-expected-gtk.txt"); -} - -// static -const std::string AccessibilityTreeFormatter::GetAllowEmptyString() { - return "@GTK-ALLOW-EMPTY:"; -} - -// static -const std::string AccessibilityTreeFormatter::GetAllowString() { - return "@GTK-ALLOW:"; -} - -// static -const std::string AccessibilityTreeFormatter::GetDenyString() { - return "@GTK-DENY:"; -} - -} diff --git a/content/browser/accessibility/browser_accessibility_gtk.cc b/content/browser/accessibility/browser_accessibility_gtk.cc deleted file mode 100644 index 4ec1b89..0000000 --- a/content/browser/accessibility/browser_accessibility_gtk.cc +++ /dev/null @@ -1,518 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/accessibility/browser_accessibility_gtk.h" - -#include <gtk/gtk.h> - -#include "base/strings/utf_string_conversions.h" -#include "content/browser/accessibility/browser_accessibility_manager_gtk.h" -#include "content/common/accessibility_messages.h" - -namespace content { - -static gpointer browser_accessibility_parent_class = NULL; - -static BrowserAccessibilityGtk* ToBrowserAccessibilityGtk( - BrowserAccessibilityAtk* atk_object) { - if (!atk_object) - return NULL; - - return atk_object->m_object; -} - -// -// AtkComponent interface. -// - -static BrowserAccessibilityGtk* ToBrowserAccessibilityGtk( - AtkComponent* atk_object) { - if (!IS_BROWSER_ACCESSIBILITY(atk_object)) - return NULL; - - return ToBrowserAccessibilityGtk(BROWSER_ACCESSIBILITY(atk_object)); -} - -static AtkObject* browser_accessibility_accessible_at_point( - AtkComponent* component, gint x, gint y, AtkCoordType coord_type) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(component); - if (!obj) - return NULL; - - gfx::Point point(x, y); - if (!obj->GetGlobalBoundsRect().Contains(point)) - return NULL; - - BrowserAccessibility* result = obj->BrowserAccessibilityForPoint(point); - if (!result) - return NULL; - - AtkObject* atk_result = result->ToBrowserAccessibilityGtk()->GetAtkObject(); - g_object_ref(atk_result); - return atk_result; -} - -static void browser_accessibility_get_extents( - AtkComponent* component, gint* x, gint* y, gint* width, gint* height, - AtkCoordType coord_type) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(component); - if (!obj) - return; - - gfx::Rect bounds = obj->GetGlobalBoundsRect(); - *x = bounds.x(); - *y = bounds.y(); - *width = bounds.width(); - *height = bounds.height(); -} - -static gboolean browser_accessibility_grab_focus(AtkComponent* component) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(component); - if (!obj) - return false; - - obj->manager()->SetFocus(obj, true); - return true; -} - -static void ComponentInterfaceInit(AtkComponentIface* iface) { - iface->ref_accessible_at_point = browser_accessibility_accessible_at_point; - iface->get_extents = browser_accessibility_get_extents; - iface->grab_focus = browser_accessibility_grab_focus; -} - -static const GInterfaceInfo ComponentInfo = { - reinterpret_cast<GInterfaceInitFunc>(ComponentInterfaceInit), 0, 0 -}; - -// -// AtkValue interface. -// - -static BrowserAccessibilityGtk* ToBrowserAccessibilityGtk( - AtkValue* atk_object) { - if (!IS_BROWSER_ACCESSIBILITY(atk_object)) - return NULL; - - return ToBrowserAccessibilityGtk(BROWSER_ACCESSIBILITY(atk_object)); -} - -static void browser_accessibility_get_current_value( - AtkValue* atk_object, GValue* value) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return; - - float float_val; - if (obj->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, - &float_val)) { - memset(value, 0, sizeof(*value)); - g_value_init(value, G_TYPE_FLOAT); - g_value_set_float(value, float_val); - } -} - -static void browser_accessibility_get_minimum_value( - AtkValue* atk_object, GValue* value) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return; - - float float_val; - if (obj->GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE, - &float_val)) { - memset(value, 0, sizeof(*value)); - g_value_init(value, G_TYPE_FLOAT); - g_value_set_float(value, float_val); - } -} - -static void browser_accessibility_get_maximum_value( - AtkValue* atk_object, GValue* value) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return; - - float float_val; - if (obj->GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE, - &float_val)) { - memset(value, 0, sizeof(*value)); - g_value_init(value, G_TYPE_FLOAT); - g_value_set_float(value, float_val); - } -} - -static void browser_accessibility_get_minimum_increment( - AtkValue* atk_object, GValue* value) { - // TODO(dmazzoni): get the correct value from an <input type=range>. - memset(value, 0, sizeof(*value)); - g_value_init(value, G_TYPE_FLOAT); - g_value_set_float(value, 1.0); -} - -static void ValueInterfaceInit(AtkValueIface* iface) { - iface->get_current_value = browser_accessibility_get_current_value; - iface->get_minimum_value = browser_accessibility_get_minimum_value; - iface->get_maximum_value = browser_accessibility_get_maximum_value; - iface->get_minimum_increment = browser_accessibility_get_minimum_increment; -} - -static const GInterfaceInfo ValueInfo = { - reinterpret_cast<GInterfaceInitFunc>(ValueInterfaceInit), 0, 0 -}; - -// -// AtkObject interface -// - -static BrowserAccessibilityGtk* ToBrowserAccessibilityGtk( - AtkObject* atk_object) { - if (!IS_BROWSER_ACCESSIBILITY(atk_object)) - return NULL; - - return ToBrowserAccessibilityGtk(BROWSER_ACCESSIBILITY(atk_object)); -} - -static const gchar* browser_accessibility_get_name(AtkObject* atk_object) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return NULL; - - return obj->GetStringAttribute(ui::AX_ATTR_NAME).c_str(); -} - -static const gchar* browser_accessibility_get_description( - AtkObject* atk_object) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return NULL; - - return obj->GetStringAttribute( - ui::AX_ATTR_DESCRIPTION).c_str(); -} - -static AtkObject* browser_accessibility_get_parent(AtkObject* atk_object) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return NULL; - if (obj->GetParent()) - return obj->GetParent()->ToBrowserAccessibilityGtk()->GetAtkObject(); - - BrowserAccessibilityManagerGtk* manager = - static_cast<BrowserAccessibilityManagerGtk*>(obj->manager()); - return gtk_widget_get_accessible(manager->parent_widget()); -} - -static gint browser_accessibility_get_n_children(AtkObject* atk_object) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return 0; - - return obj->PlatformChildCount(); -} - -static AtkObject* browser_accessibility_ref_child( - AtkObject* atk_object, gint index) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return NULL; - - if (index < 0 || index >= static_cast<gint>(obj->PlatformChildCount())) - return NULL; - - AtkObject* result = - obj->InternalGetChild(index)->ToBrowserAccessibilityGtk()->GetAtkObject(); - g_object_ref(result); - return result; -} - -static gint browser_accessibility_get_index_in_parent(AtkObject* atk_object) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return 0; - return obj->GetIndexInParent(); -} - -static AtkAttributeSet* browser_accessibility_get_attributes( - AtkObject* atk_object) { - return NULL; -} - -static AtkRole browser_accessibility_get_role(AtkObject* atk_object) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return ATK_ROLE_INVALID; - return obj->atk_role(); -} - -static AtkStateSet* browser_accessibility_ref_state_set(AtkObject* atk_object) { - BrowserAccessibilityGtk* obj = ToBrowserAccessibilityGtk(atk_object); - if (!obj) - return NULL; - AtkStateSet* state_set = - ATK_OBJECT_CLASS(browser_accessibility_parent_class)-> - ref_state_set(atk_object); - int32 state = obj->GetState(); - - if (state & (1 << ui::AX_STATE_FOCUSABLE)) - atk_state_set_add_state(state_set, ATK_STATE_FOCUSABLE); - if (obj->manager()->GetFocus(NULL) == obj) - atk_state_set_add_state(state_set, ATK_STATE_FOCUSED); - if (state & (1 << ui::AX_STATE_ENABLED)) - atk_state_set_add_state(state_set, ATK_STATE_ENABLED); - - return state_set; -} - -static AtkRelationSet* browser_accessibility_ref_relation_set( - AtkObject* atk_object) { - AtkRelationSet* relation_set = - ATK_OBJECT_CLASS(browser_accessibility_parent_class) - ->ref_relation_set(atk_object); - return relation_set; -} - -// -// The rest of the BrowserAccessibilityGtk code, not specific to one -// of the Atk* interfaces. -// - -static void browser_accessibility_init(AtkObject* atk_object, gpointer data) { - if (ATK_OBJECT_CLASS(browser_accessibility_parent_class)->initialize) { - ATK_OBJECT_CLASS(browser_accessibility_parent_class)->initialize( - atk_object, data); - } - - BROWSER_ACCESSIBILITY(atk_object)->m_object = - reinterpret_cast<BrowserAccessibilityGtk*>(data); -} - -static void browser_accessibility_finalize(GObject* atk_object) { - G_OBJECT_CLASS(browser_accessibility_parent_class)->finalize(atk_object); -} - -static void browser_accessibility_class_init(AtkObjectClass* klass) { - GObjectClass* gobject_class = G_OBJECT_CLASS(klass); - browser_accessibility_parent_class = g_type_class_peek_parent(klass); - - gobject_class->finalize = browser_accessibility_finalize; - klass->initialize = browser_accessibility_init; - klass->get_name = browser_accessibility_get_name; - klass->get_description = browser_accessibility_get_description; - klass->get_parent = browser_accessibility_get_parent; - klass->get_n_children = browser_accessibility_get_n_children; - klass->ref_child = browser_accessibility_ref_child; - klass->get_role = browser_accessibility_get_role; - klass->ref_state_set = browser_accessibility_ref_state_set; - klass->get_index_in_parent = browser_accessibility_get_index_in_parent; - klass->get_attributes = browser_accessibility_get_attributes; - klass->ref_relation_set = browser_accessibility_ref_relation_set; -} - -GType browser_accessibility_get_type() { - static volatile gsize type_volatile = 0; - - if (g_once_init_enter(&type_volatile)) { - static const GTypeInfo tinfo = { - sizeof(BrowserAccessibilityAtkClass), - (GBaseInitFunc) 0, - (GBaseFinalizeFunc) 0, - (GClassInitFunc) browser_accessibility_class_init, - (GClassFinalizeFunc) 0, - 0, /* class data */ - sizeof(BrowserAccessibilityAtk), /* instance size */ - 0, /* nb preallocs */ - (GInstanceInitFunc) 0, - 0 /* value table */ - }; - - GType type = g_type_register_static( - ATK_TYPE_OBJECT, "BrowserAccessibility", &tinfo, GTypeFlags(0)); - g_once_init_leave(&type_volatile, type); - } - - return type_volatile; -} - -static const char* GetUniqueAccessibilityTypeName(int interface_mask) -{ - // 20 characters is enough for "Chrome%x" with any integer value. - static char name[20]; - snprintf(name, sizeof(name), "Chrome%x", interface_mask); - return name; -} - -enum AtkInterfaces { - ATK_ACTION_INTERFACE, - ATK_COMPONENT_INTERFACE, - ATK_DOCUMENT_INTERFACE, - ATK_EDITABLE_TEXT_INTERFACE, - ATK_HYPERLINK_INTERFACE, - ATK_HYPERTEXT_INTERFACE, - ATK_IMAGE_INTERFACE, - ATK_SELECTION_INTERFACE, - ATK_TABLE_INTERFACE, - ATK_TEXT_INTERFACE, - ATK_VALUE_INTERFACE, -}; - -static int GetInterfaceMaskFromObject(BrowserAccessibilityGtk* obj) { - int interface_mask = 0; - - // Component interface is always supported. - interface_mask |= 1 << ATK_COMPONENT_INTERFACE; - - int role = obj->GetRole(); - if (role == ui::AX_ROLE_PROGRESS_INDICATOR || - role == ui::AX_ROLE_SCROLL_BAR || - role == ui::AX_ROLE_SLIDER) { - interface_mask |= 1 << ATK_VALUE_INTERFACE; - } - - return interface_mask; -} - -static GType GetAccessibilityTypeFromObject(BrowserAccessibilityGtk* obj) { - static const GTypeInfo type_info = { - sizeof(BrowserAccessibilityAtkClass), - (GBaseInitFunc) 0, - (GBaseFinalizeFunc) 0, - (GClassInitFunc) 0, - (GClassFinalizeFunc) 0, - 0, /* class data */ - sizeof(BrowserAccessibilityAtk), /* instance size */ - 0, /* nb preallocs */ - (GInstanceInitFunc) 0, - 0 /* value table */ - }; - - int interface_mask = GetInterfaceMaskFromObject(obj); - const char* atk_type_name = GetUniqueAccessibilityTypeName(interface_mask); - GType type = g_type_from_name(atk_type_name); - if (type) - return type; - - type = g_type_register_static(BROWSER_ACCESSIBILITY_TYPE, - atk_type_name, - &type_info, - GTypeFlags(0)); - if (interface_mask & (1 << ATK_COMPONENT_INTERFACE)) - g_type_add_interface_static(type, ATK_TYPE_COMPONENT, &ComponentInfo); - if (interface_mask & (1 << ATK_VALUE_INTERFACE)) - g_type_add_interface_static(type, ATK_TYPE_VALUE, &ValueInfo); - - return type; -} - -BrowserAccessibilityAtk* browser_accessibility_new( - BrowserAccessibilityGtk* obj) { - GType type = GetAccessibilityTypeFromObject(obj); - AtkObject* atk_object = static_cast<AtkObject*>(g_object_new(type, 0)); - - atk_object_initialize(atk_object, obj); - - return BROWSER_ACCESSIBILITY(atk_object); -} - -void browser_accessibility_detach(BrowserAccessibilityAtk* atk_object) { - atk_object->m_object = NULL; -} - -// static -BrowserAccessibility* BrowserAccessibility::Create() { - return new BrowserAccessibilityGtk(); -} - -BrowserAccessibilityGtk* BrowserAccessibility::ToBrowserAccessibilityGtk() { - return static_cast<BrowserAccessibilityGtk*>(this); -} - -BrowserAccessibilityGtk::BrowserAccessibilityGtk() - : atk_object_(NULL) { -} - -BrowserAccessibilityGtk::~BrowserAccessibilityGtk() { - browser_accessibility_detach(BROWSER_ACCESSIBILITY(atk_object_)); - if (atk_object_) - g_object_unref(atk_object_); -} - -AtkObject* BrowserAccessibilityGtk::GetAtkObject() const { - if (!G_IS_OBJECT(atk_object_)) - return NULL; - return atk_object_; -} - -void BrowserAccessibilityGtk::PreInitialize() { - BrowserAccessibility::PreInitialize(); - InitRoleAndState(); - - if (atk_object_) { - // If the object's role changes and that causes its - // interface mask to change, we need to create a new - // AtkObject for it. - int interface_mask = GetInterfaceMaskFromObject(this); - if (interface_mask != interface_mask_) { - g_object_unref(atk_object_); - atk_object_ = NULL; - } - } - - if (!atk_object_) { - interface_mask_ = GetInterfaceMaskFromObject(this); - atk_object_ = ATK_OBJECT(browser_accessibility_new(this)); - if (this->GetParent()) { - atk_object_set_parent( - atk_object_, - this->GetParent()->ToBrowserAccessibilityGtk()->GetAtkObject()); - } - } -} - -bool BrowserAccessibilityGtk::IsNative() const { - return true; -} - -void BrowserAccessibilityGtk::InitRoleAndState() { - switch(GetRole()) { - case ui::AX_ROLE_DOCUMENT: - case ui::AX_ROLE_ROOT_WEB_AREA: - case ui::AX_ROLE_WEB_AREA: - atk_role_ = ATK_ROLE_DOCUMENT_WEB; - break; - case ui::AX_ROLE_GROUP: - case ui::AX_ROLE_DIV: - atk_role_ = ATK_ROLE_SECTION; - break; - case ui::AX_ROLE_BUTTON: - atk_role_ = ATK_ROLE_PUSH_BUTTON; - break; - case ui::AX_ROLE_CHECK_BOX: - atk_role_ = ATK_ROLE_CHECK_BOX; - break; - case ui::AX_ROLE_COMBO_BOX: - atk_role_ = ATK_ROLE_COMBO_BOX; - break; - case ui::AX_ROLE_LINK: - atk_role_ = ATK_ROLE_LINK; - break; - case ui::AX_ROLE_RADIO_BUTTON: - atk_role_ = ATK_ROLE_RADIO_BUTTON; - break; - case ui::AX_ROLE_STATIC_TEXT: - atk_role_ = ATK_ROLE_TEXT; - break; - case ui::AX_ROLE_TEXT_AREA: - atk_role_ = ATK_ROLE_ENTRY; - break; - case ui::AX_ROLE_TEXT_FIELD: - atk_role_ = ATK_ROLE_ENTRY; - break; - default: - atk_role_ = ATK_ROLE_UNKNOWN; - break; - } -} - -} // namespace content diff --git a/content/browser/accessibility/browser_accessibility_gtk.h b/content/browser/accessibility/browser_accessibility_gtk.h deleted file mode 100644 index c8895e3..0000000 --- a/content/browser/accessibility/browser_accessibility_gtk.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_GTK_H_ -#define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_GTK_H_ - -#include <atk/atk.h> - -#include "base/compiler_specific.h" -#include "content/browser/accessibility/browser_accessibility.h" - -namespace content { - -class BrowserAccessibilityGtk; -class BrowserAccessibilityManagerGtk; - -G_BEGIN_DECLS - -#define BROWSER_ACCESSIBILITY_TYPE (browser_accessibility_get_type()) -#define BROWSER_ACCESSIBILITY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST( \ - (obj), BROWSER_ACCESSIBILITY_TYPE, BrowserAccessibilityAtk)) -#define BROWSER_ACCESSIBILITY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST( \ - (klass), BROWSER_ACCESSIBILITY_TYPE, BrowserAccessibilityAtkClass)) -#define IS_BROWSER_ACCESSIBILITY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), BROWSER_ACCESSIBILITY_TYPE)) -#define IS_BROWSER_ACCESSIBILITY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), BROWSER_ACCESSIBILITY_TYPE)) -#define BROWSER_ACCESSIBILITY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS( \ - (obj), BROWSER_ACCESSIBILITY_TYPE, BrowserAccessibilityAtkClass)) - -typedef struct _BrowserAccessibilityAtk BrowserAccessibilityAtk; -typedef struct _BrowserAccessibilityAtkClass BrowserAccessibilityAtkClass; - -struct _BrowserAccessibilityAtk { - AtkObject parent; - BrowserAccessibilityGtk* m_object; -}; - -struct _BrowserAccessibilityAtkClass { - AtkObjectClass parent_class; -}; - -GType browser_accessibility_get_type (void) G_GNUC_CONST; - -BrowserAccessibilityAtk* browser_accessibility_new( - BrowserAccessibilityGtk* object); - -BrowserAccessibilityGtk* browser_accessibility_get_object( - BrowserAccessibilityAtk* atk_object); - -void browser_accessibility_detach (BrowserAccessibilityAtk* atk_object); - -AtkObject* browser_accessibility_get_focused_element( - BrowserAccessibilityAtk* atk_object); - -G_END_DECLS - -class BrowserAccessibilityGtk : public BrowserAccessibility { - public: - BrowserAccessibilityGtk(); - - virtual ~BrowserAccessibilityGtk(); - - AtkObject* GetAtkObject() const; - - AtkRole atk_role() { return atk_role_; } - - // BrowserAccessibility methods. - virtual void PreInitialize() OVERRIDE; - virtual bool IsNative() const OVERRIDE; - - private: - virtual void InitRoleAndState(); - - // Give BrowserAccessibility::Create access to our constructor. - friend class BrowserAccessibility; - - AtkObject* atk_object_; - AtkRole atk_role_; - int interface_mask_; - - private: - DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityGtk); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_GTK_H_ diff --git a/content/browser/accessibility/browser_accessibility_manager_gtk.cc b/content/browser/accessibility/browser_accessibility_manager_gtk.cc deleted file mode 100644 index 8748de5..0000000 --- a/content/browser/accessibility/browser_accessibility_manager_gtk.cc +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/accessibility/browser_accessibility_manager_gtk.h" - -#include "content/browser/accessibility/browser_accessibility_gtk.h" -#include "content/common/accessibility_messages.h" - -namespace content { - -// static -BrowserAccessibilityManager* BrowserAccessibilityManager::Create( - const ui::AXNodeData& src, - BrowserAccessibilityDelegate* delegate, - BrowserAccessibilityFactory* factory) { - return new BrowserAccessibilityManagerGtk( - NULL, - src, - delegate, - factory); -} - -BrowserAccessibilityManagerGtk::BrowserAccessibilityManagerGtk( - GtkWidget* parent_widget, - const ui::AXNodeData& src, - BrowserAccessibilityDelegate* delegate, - BrowserAccessibilityFactory* factory) - : BrowserAccessibilityManager(delegate, factory), - parent_widget_(parent_widget) { - Initialize(src); -} - -BrowserAccessibilityManagerGtk::~BrowserAccessibilityManagerGtk() { -} - -// static -ui::AXNodeData BrowserAccessibilityManagerGtk::GetEmptyDocument() { - ui::AXNodeData empty_document; - empty_document.id = 0; - empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; - empty_document.state = - 1 << ui::AX_STATE_READ_ONLY; - return empty_document; -} - -void BrowserAccessibilityManagerGtk::NotifyAccessibilityEvent( - ui::AXEvent event_type, - BrowserAccessibility* node) { - if (!node->IsNative()) - return; - AtkObject* atk_object = node->ToBrowserAccessibilityGtk()->GetAtkObject(); - - switch (event_type) { - case ui::AX_EVENT_CHILDREN_CHANGED: - RecursivelySendChildrenChanged(GetRoot()->ToBrowserAccessibilityGtk()); - break; - case ui::AX_EVENT_FOCUS: - // Note: the focus-event was deprecated in ATK 2.9.4 - // See https://bugzilla.gnome.org/show_bug.cgi?id=649575#c8 - g_signal_emit_by_name(atk_object, "focus-event", true); - break; - default: - break; - } -} - -void BrowserAccessibilityManagerGtk::RecursivelySendChildrenChanged( - BrowserAccessibilityGtk* node) { - AtkObject* atkObject = node->ToBrowserAccessibilityGtk()->GetAtkObject(); - for (unsigned int i = 0; i < node->InternalChildCount(); ++i) { - BrowserAccessibilityGtk* child = - node->InternalGetChild(i)->ToBrowserAccessibilityGtk(); - g_signal_emit_by_name(atkObject, - "children-changed::add", - i, - child->GetAtkObject()); - RecursivelySendChildrenChanged(child); - } -} - -} // namespace content diff --git a/content/browser/accessibility/browser_accessibility_manager_gtk.h b/content/browser/accessibility/browser_accessibility_manager_gtk.h deleted file mode 100644 index 6349a81..0000000 --- a/content/browser/accessibility/browser_accessibility_manager_gtk.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_GTK_H_ -#define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_GTK_H_ - -#include "content/browser/accessibility/browser_accessibility_manager.h" - -struct ViewHostMsg_AccessibilityNotification_Params; - -namespace content { -class BrowserAccessibilityGtk; - -// Manages a tree of BrowserAccessibilityGtk objects. -class CONTENT_EXPORT BrowserAccessibilityManagerGtk - : public BrowserAccessibilityManager { - public: - BrowserAccessibilityManagerGtk( - GtkWidget* parent_widget, - const ui::AXNodeData& src, - BrowserAccessibilityDelegate* delegate, - BrowserAccessibilityFactory* factory = new BrowserAccessibilityFactory()); - - virtual ~BrowserAccessibilityManagerGtk(); - - static ui::AXNodeData GetEmptyDocument(); - - // BrowserAccessibilityManager methods - virtual void NotifyAccessibilityEvent( - ui::AXEvent event_type, BrowserAccessibility* node) OVERRIDE; - - GtkWidget* parent_widget() { return parent_widget_; } - - private: - void RecursivelySendChildrenChanged(BrowserAccessibilityGtk* node); - - GtkWidget* parent_widget_; - - // Give BrowserAccessibilityManager::Create access to our constructor. - friend class BrowserAccessibilityManager; - - DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManagerGtk); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_GTK_H_ diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc index cb250c1..2a6b823 100644 --- a/content/browser/browser_main_loop.cc +++ b/content/browser/browser_main_loop.cc @@ -98,10 +98,6 @@ #include "content/browser/device_monitor_mac.h" #endif -#if defined(TOOLKIT_GTK) -#include "ui/gfx/gtk_util.h" -#endif - #if defined(OS_POSIX) && !defined(OS_MACOSX) #include <sys/stat.h> @@ -384,10 +380,6 @@ void BrowserMainLoop::EarlyInitialization() { g_type_init(); #endif -#if !defined(USE_AURA) - gfx::GtkInitFromCommandLine(parsed_command_line_); -#endif - SetUpGLibLogHandler(); #endif diff --git a/content/browser/frame_host/render_widget_host_view_guest.cc b/content/browser/frame_host/render_widget_host_view_guest.cc index be692c8..00dcd41 100644 --- a/content/browser/frame_host/render_widget_host_view_guest.cc +++ b/content/browser/frame_host/render_widget_host_view_guest.cc @@ -497,16 +497,6 @@ void RenderWidgetHostViewGuest::ShowDisambiguationPopup( } #endif // defined(OS_ANDROID) -#if defined(TOOLKIT_GTK) -GdkEventButton* RenderWidgetHostViewGuest::GetLastMouseDown() { - return NULL; -} - -gfx::NativeView RenderWidgetHostViewGuest::BuildInputMethodsGtkMenu() { - return platform_view_->BuildInputMethodsGtkMenu(); -} -#endif // defined(TOOLKIT_GTK) - #if defined(OS_WIN) void RenderWidgetHostViewGuest::SetParentNativeViewAccessible( gfx::NativeViewAccessible accessible_parent) { diff --git a/content/browser/frame_host/render_widget_host_view_guest.h b/content/browser/frame_host/render_widget_host_view_guest.h index 8413e30..930650d 100644 --- a/content/browser/frame_host/render_widget_host_view_guest.h +++ b/content/browser/frame_host/render_widget_host_view_guest.h @@ -18,10 +18,6 @@ #include "ui/gfx/rect.h" #include "ui/gfx/vector2d_f.h" -#if defined(TOOLKIT_GTK) -#include "content/browser/renderer_host/gtk_plugin_container_manager.h" -#endif // defined(TOOLKIT_GTK) - namespace content { class RenderWidgetHost; class RenderWidgetHostImpl; @@ -149,11 +145,6 @@ class CONTENT_EXPORT RenderWidgetHostViewGuest const SkBitmap& zoomed_bitmap) OVERRIDE; #endif // defined(OS_ANDROID) -#if defined(TOOLKIT_GTK) - virtual GdkEventButton* GetLastMouseDown() OVERRIDE; - virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE; -#endif // defined(TOOLKIT_GTK) - #if defined(OS_WIN) virtual void SetParentNativeViewAccessible( gfx::NativeViewAccessible accessible_parent) OVERRIDE; diff --git a/content/browser/gpu/gpu_surface_tracker.cc b/content/browser/gpu/gpu_surface_tracker.cc index 350e6f3..42ce146 100644 --- a/content/browser/gpu/gpu_surface_tracker.cc +++ b/content/browser/gpu/gpu_surface_tracker.cc @@ -10,57 +10,8 @@ #include "base/logging.h" -#if defined(TOOLKIT_GTK) -#include "base/bind.h" -#include "content/public/browser/browser_thread.h" -#include "ui/gfx/gtk_native_view_id_manager.h" -#endif // defined(TOOLKIT_GTK) - namespace content { -namespace { -#if defined(TOOLKIT_GTK) - -void ReleasePermanentXIDDispatcher( - const gfx::PluginWindowHandle& surface) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); - manager->ReleasePermanentXID(surface); -} - -// Implementation of SurfaceRef that allows GTK to ref and unref the -// surface with the GtkNativeViewManager. -class SurfaceRefPluginWindow : public GpuSurfaceTracker::SurfaceRef { - public: - SurfaceRefPluginWindow(const gfx::PluginWindowHandle& surface_ref); - private: - virtual ~SurfaceRefPluginWindow(); - gfx::PluginWindowHandle surface_; -}; - -SurfaceRefPluginWindow::SurfaceRefPluginWindow( - const gfx::PluginWindowHandle& surface) - : surface_(surface) { - if (surface_ != gfx::kNullPluginWindow) { - GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); - if (!manager->AddRefPermanentXID(surface_)) { - LOG(ERROR) << "Surface " << surface << " cannot be referenced."; - } - } -} - -SurfaceRefPluginWindow::~SurfaceRefPluginWindow() { - if (surface_ != gfx::kNullPluginWindow) { - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::Bind(&ReleasePermanentXIDDispatcher, - surface_)); - } -} -#endif // defined(TOOLKIT_GTK) -} // anonymous - GpuSurfaceTracker::GpuSurfaceTracker() : next_surface_id_(1) { GpuSurfaceLookup::InitInstance(this); @@ -134,9 +85,6 @@ void GpuSurfaceTracker::SetSurfaceHandle(int surface_id, DCHECK(surface_map_.find(surface_id) != surface_map_.end()); SurfaceInfo& info = surface_map_[surface_id]; info.handle = handle; -#if defined(TOOLKIT_GTK) - info.surface_ref = new SurfaceRefPluginWindow(handle.handle); -#endif // defined(TOOLKIT_GTK) } gfx::GLSurfaceHandle GpuSurfaceTracker::GetSurfaceHandle(int surface_id) { diff --git a/content/browser/gpu/test_support_gpu.gypi b/content/browser/gpu/test_support_gpu.gypi index 4892e9a..742d53f 100644 --- a/content/browser/gpu/test_support_gpu.gypi +++ b/content/browser/gpu/test_support_gpu.gypi @@ -51,11 +51,6 @@ # See comments about "xcode_settings" elsewhere in this file. 'xcode_settings': {'OTHER_LDFLAGS': ['-Wl,-ObjC']}, }], - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - '<(src_dir)/build/linux/system.gyp:gtk', - ], - }], ['toolkit_uses_gtk == 1 or chromeos==1 or (OS=="linux" and use_aura==1)', { 'dependencies': [ '<(src_dir)/build/linux/system.gyp:ssl', diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc index b6d54b9..077f512 100644 --- a/content/browser/plugin_process_host.cc +++ b/content/browser/plugin_process_host.cc @@ -43,10 +43,6 @@ #include "ui/gfx/native_widget_types.h" #include "ui/gl/gl_switches.h" -#if defined(USE_X11) -#include "ui/gfx/gtk_native_view_id_manager.h" -#endif - #if defined(OS_MACOSX) #include "base/mac/mac_util.h" #include "content/common/plugin_carbon_interpose_constants_mac.h" @@ -110,16 +106,6 @@ class PluginSandboxedProcessLauncherDelegate DISALLOW_COPY_AND_ASSIGN(PluginSandboxedProcessLauncherDelegate); }; -#if defined(TOOLKIT_GTK) -void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id, - gfx::PluginWindowHandle* output) { - *output = 0; -#if !defined(USE_AURA) - GtkNativeViewManager::GetInstance()->GetXIDForId(output, id); -#endif -} -#endif // defined(TOOLKIT_GTK) - PluginProcessHost::PluginProcessHost() #if defined(OS_MACOSX) : plugin_cursor_visible_(true) @@ -300,10 +286,6 @@ bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, OnPluginWindowDestroyed) #endif -#if defined(TOOLKIT_GTK) - IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, - OnMapNativeViewId) -#endif #if defined(OS_MACOSX) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow, OnPluginSelectWindow) diff --git a/content/browser/plugin_process_host.h b/content/browser/plugin_process_host.h index aaaf6dd..71c7580 100644 --- a/content/browser/plugin_process_host.h +++ b/content/browser/plugin_process_host.h @@ -133,10 +133,6 @@ class CONTENT_EXPORT PluginProcessHost : public BrowserChildProcessHostDelegate, void OnPluginWindowDestroyed(HWND window, HWND parent); #endif -#if defined(USE_X11) - void OnMapNativeViewId(gfx::NativeViewId id, gfx::PluginWindowHandle* output); -#endif - #if defined(OS_MACOSX) void OnPluginSelectWindow(uint32 window_id, gfx::Rect window_rect, bool modal); diff --git a/content/browser/power_save_blocker_x11.cc b/content/browser/power_save_blocker_x11.cc index f55fac9..cecb232 100644 --- a/content/browser/power_save_blocker_x11.cc +++ b/content/browser/power_save_blocker_x11.cc @@ -22,6 +22,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/message_loop/message_loop_proxy.h" +#include "base/message_loop/message_pump_x11.h" #include "base/nix/xdg_util.h" #include "base/synchronization/lock.h" #include "content/public/browser/browser_thread.h" @@ -31,12 +32,6 @@ #include "dbus/object_proxy.h" #include "ui/gfx/x/x11_types.h" -#if defined(TOOLKIT_GTK) -#include "base/message_loop/message_pump_gtk.h" -#else -#include "base/message_loop/message_pump_x11.h" -#endif - namespace { enum DBusAPI { diff --git a/content/browser/renderer_host/backing_store_gtk.cc b/content/browser/renderer_host/backing_store_gtk.cc deleted file mode 100644 index 147ee4d..0000000 --- a/content/browser/renderer_host/backing_store_gtk.cc +++ /dev/null @@ -1,692 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/backing_store_gtk.h" - -#include <cairo-xlib.h> -#include <gtk/gtk.h> -#include <stdlib.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <X11/extensions/sync.h> - -#if defined(OS_OPENBSD) || defined(OS_FREEBSD) -#include <sys/endian.h> -#endif - -#include <algorithm> -#include <limits> -#include <queue> -#include <utility> - -#include "base/compiler_specific.h" -#include "base/logging.h" -#include "base/memory/singleton.h" -#include "base/metrics/histogram.h" -#include "base/time/time.h" -#include "content/browser/renderer_host/render_process_host_impl.h" -#include "skia/ext/platform_canvas.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/gtk/gtk_signal.h" -#include "ui/base/x/x11_util_internal.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/rect_conversions.h" -#include "ui/gfx/x/x11_types.h" -#include "ui/surface/transport_dib.h" - -namespace content { -namespace { - -// Assume that somewhere along the line, someone will do width * height * 4 -// with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = -// 2**29 and floor(sqrt(2**29)) = 23170. - -// Max height and width for layers -static const int kMaxVideoLayerSize = 23170; - - -// X Backing Stores: -// -// Unlike Windows, where the backing store is kept in heap memory, we keep our -// backing store in the X server, as a pixmap. Thus expose events just require -// instructing the X server to copy from the backing store to the window. -// -// The backing store is in the same format as the visual which our main window -// is using. Bitmaps from the renderer are uploaded to the X server, either via -// shared memory or over the wire, and XRENDER is used to convert them to the -// correct format for the backing store. - -// Destroys the image and the associated shared memory structures. This is a -// helper function for code using shared memory. -void DestroySharedImage(XDisplay* display, - XImage* image, - XShmSegmentInfo* shminfo) { - XShmDetach(display, shminfo); - XDestroyImage(image); - shmdt(shminfo->shmaddr); -} - -// So we don't don't want to call XSync(), which can block the UI loop for -// ~100ms on first paint and is generally slow. We optionally use the -// XSyncExtension to push a callback into the X11 event queue and get a -// callback instead of blocking until the event queue is cleared. -// -// TODO(erg): If gfx::GetXDisplay() ever gets fixed to handle multiple Displays, -// this must be modified to be per Display instead of a Singleton. -class XSyncHandler { - public: - static XSyncHandler* GetInstance() { - return Singleton<XSyncHandler>::get(); - } - - bool Enabled() { - return loaded_extension_; - } - - void PushPaintCounter(TransportDIB* dib, - XDisplay* display, - Picture picture, - Pixmap pixmap, - const base::Closure& completion_callback); - - private: - friend struct DefaultSingletonTraits<XSyncHandler>; - - // A struct that has cleanup and callback tasks that were queued into the - // future and are run on |g_backing_store_sync_alarm| firing. - struct BackingStoreEvents { - BackingStoreEvents(TransportDIB* dib, XDisplay* d, Picture pic, Pixmap pix, - const base::Closure& c) - : dib(dib), - display(d), - picture(pic), - pixmap(pix), - closure(c) { - dib->IncreaseInFlightCounter(); - } - - TransportDIB* dib; - - // The display we're running on. - XDisplay* display; - - // Data to delete. - Picture picture; - Pixmap pixmap; - - // Callback once everything else is done. - base::Closure closure; - }; - - XSyncHandler(); - ~XSyncHandler(); - - // An event filter notified about all XEvents. We then filter out XSync - // events that are on counters that we made. - CHROMEG_CALLBACK_1(XSyncHandler, GdkFilterReturn, OnEvent, GdkXEvent*, - GdkEvent*); - - // Whether we successfully loaded XSyncExtension. - bool loaded_extension_; - - // The event ids returned to us by XSyncQueryExtension(). - int xsync_event_base_; - int xsync_error_base_; - - XSyncCounter backing_store_sync_counter_; - XSyncAlarm backing_store_sync_alarm_; - - // A queue of pending paints that we clean up after as alarms fire. - std::queue<BackingStoreEvents*> backing_store_events_; -}; - -void XSyncHandler::PushPaintCounter(TransportDIB* dib, - XDisplay* display, - Picture picture, - Pixmap pixmap, - const base::Closure& completion_callback) { - backing_store_events_.push(new BackingStoreEvents( - dib, display, picture, pixmap, completion_callback)); - - // Push a change counter event into the X11 event queue that will trigger our - // alarm when it is processed. - XSyncValue value; - XSyncIntToValue(&value, 1); - XSyncChangeCounter(gfx::GetXDisplay(), - backing_store_sync_counter_, - value); -} - -XSyncHandler::XSyncHandler() - : loaded_extension_(false), - xsync_event_base_(0), - xsync_error_base_(0), - backing_store_sync_counter_(0), - backing_store_sync_alarm_(0) { - XDisplay* display = gfx::GetXDisplay(); - if (XSyncQueryExtension(display, - &xsync_event_base_, - &xsync_error_base_)) { - // Create our monotonically increasing counter. - XSyncValue value; - XSyncIntToValue(&value, 0); - backing_store_sync_counter_ = XSyncCreateCounter(display, value); - - // Cerate our alarm that watches for changes to our counter. - XSyncAlarmAttributes attributes; - attributes.trigger.counter = backing_store_sync_counter_; - backing_store_sync_alarm_ = XSyncCreateAlarm(display, - XSyncCACounter, - &attributes); - - // Add our filter to the message loop to handle alarm triggers. - gdk_window_add_filter(NULL, &OnEventThunk, this); - - loaded_extension_ = true; - } -} - -XSyncHandler::~XSyncHandler() { - if (loaded_extension_) - gdk_window_remove_filter(NULL, &OnEventThunk, this); - - XSync(gfx::GetXDisplay(), False); - while (!backing_store_events_.empty()) { - // We delete the X11 resources we're holding onto. We don't run the - // callbacks because we are shutting down. - BackingStoreEvents* data = backing_store_events_.front(); - backing_store_events_.pop(); - XRenderFreePicture(data->display, data->picture); - XFreePixmap(data->display, data->pixmap); - data->dib->DecreaseInFlightCounter(); - delete data; - } -} - -GdkFilterReturn XSyncHandler::OnEvent(GdkXEvent* gdkxevent, - GdkEvent* event) { - XEvent* xevent = reinterpret_cast<XEvent*>(gdkxevent); - if (xevent->type == xsync_event_base_ + XSyncAlarmNotify) { - XSyncAlarmNotifyEvent* alarm_event = - reinterpret_cast<XSyncAlarmNotifyEvent*>(xevent); - if (alarm_event->alarm == backing_store_sync_alarm_) { - if (alarm_event->counter_value.hi == 0 && - alarm_event->counter_value.lo == 0) { - // We receive an event about the initial state of the counter during - // alarm creation. We must ignore this event instead of responding to - // it. - return GDK_FILTER_REMOVE; - } - - DCHECK(!backing_store_events_.empty()); - BackingStoreEvents* data = backing_store_events_.front(); - backing_store_events_.pop(); - - // We are responsible for deleting all the data in the struct now that - // we are finished with it. - XRenderFreePicture(data->display, data->picture); - XFreePixmap(data->display, data->pixmap); - - // Dispatch the closure we were given. - data->closure.Run(); - - data->dib->DecreaseInFlightCounter(); - delete data; - - return GDK_FILTER_REMOVE; - } - } - - return GDK_FILTER_CONTINUE; -} - -} // namespace - -BackingStoreGtk::BackingStoreGtk(RenderWidgetHost* widget, - const gfx::Size& size, - void* visual, - int depth) - : BackingStore(widget, size), - display_(gfx::GetXDisplay()), - shared_memory_support_(ui::QuerySharedMemorySupport(display_)), - use_render_(ui::QueryRenderSupport(display_)), - visual_(visual), - visual_depth_(depth), - root_window_(ui::GetX11RootWindow()) { -#if defined(OS_OPENBSD) || defined(OS_FREEBSD) - COMPILE_ASSERT(_BYTE_ORDER == _LITTLE_ENDIAN, assumes_little_endian); -#else - COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, assumes_little_endian); -#endif - - pixmap_ = XCreatePixmap(display_, root_window_, - size.width(), size.height(), depth); - - if (use_render_) { - picture_ = XRenderCreatePicture( - display_, pixmap_, - ui::GetRenderVisualFormat(display_, - static_cast<Visual*>(visual)), - 0, NULL); - pixmap_bpp_ = 0; - } else { - picture_ = 0; - pixmap_bpp_ = gfx::BitsPerPixelForPixmapDepth(display_, depth); - } - - pixmap_gc_ = XCreateGC(display_, pixmap_, 0, NULL); -} - -BackingStoreGtk::BackingStoreGtk(RenderWidgetHost* widget, - const gfx::Size& size) - : BackingStore(widget, size), - display_(NULL), - shared_memory_support_(ui::SHARED_MEMORY_NONE), - use_render_(false), - pixmap_bpp_(0), - visual_(NULL), - visual_depth_(-1), - root_window_(0), - pixmap_(0), - picture_(0), - pixmap_gc_(NULL) { -} - -BackingStoreGtk::~BackingStoreGtk() { - // In unit tests, display_ may be NULL. - if (!display_) - return; - - XRenderFreePicture(display_, picture_); - XFreePixmap(display_, pixmap_); - XFreeGC(display_, static_cast<GC>(pixmap_gc_)); -} - -size_t BackingStoreGtk::MemorySize() { - if (!use_render_) - return size().GetArea() * (pixmap_bpp_ / 8); - else - return size().GetArea() * 4; -} - -void BackingStoreGtk::PaintRectWithoutXrender( - TransportDIB* bitmap, - const gfx::Rect& bitmap_rect, - const std::vector<gfx::Rect>& copy_rects) { - const int width = bitmap_rect.width(); - const int height = bitmap_rect.height(); - Pixmap pixmap = XCreatePixmap(display_, root_window_, width, height, - visual_depth_); - - // Draw ARGB transport DIB onto our pixmap. - gfx::PutARGBImage(display_, visual_, visual_depth_, pixmap, - pixmap_gc_, static_cast<uint8*>(bitmap->memory()), - width, height); - - for (size_t i = 0; i < copy_rects.size(); i++) { - const gfx::Rect& copy_rect = copy_rects[i]; - XCopyArea(display_, - pixmap, // src - pixmap_, // dest - static_cast<GC>(pixmap_gc_), // gc - copy_rect.x() - bitmap_rect.x(), // src_x - copy_rect.y() - bitmap_rect.y(), // src_y - copy_rect.width(), // width - copy_rect.height(), // height - copy_rect.x(), // dest_x - copy_rect.y()); // dest_y - } - - XFreePixmap(display_, pixmap); -} - -void BackingStoreGtk::PaintToBackingStore( - RenderProcessHost* process, - TransportDIB::Id bitmap, - const gfx::Rect& bitmap_rect, - const std::vector<gfx::Rect>& copy_rects, - float scale_factor, - const base::Closure& completion_callback, - bool* scheduled_completion_callback) { - *scheduled_completion_callback = false; - - if (!display_) - return; - - if (bitmap_rect.IsEmpty()) - return; - - gfx::Rect pixel_bitmap_rect = gfx::ToEnclosedRect( - gfx::ScaleRect(bitmap_rect, scale_factor)); - const int width = pixel_bitmap_rect.width(); - const int height = pixel_bitmap_rect.height(); - - if (width <= 0 || width > kMaxVideoLayerSize || - height <= 0 || height > kMaxVideoLayerSize) - return; - - TransportDIB* dib = process->GetTransportDIB(bitmap); - if (!dib) - return; - - if (!use_render_) - return PaintRectWithoutXrender(dib, bitmap_rect, copy_rects); - - Picture picture; - Pixmap pixmap; - - if (shared_memory_support_ == ui::SHARED_MEMORY_PIXMAP) { - XShmSegmentInfo shminfo = {0}; - shminfo.shmseg = dib->MapToX(display_); - - // The NULL in the following is the |data| pointer: this is an artifact of - // Xlib trying to be helpful, rather than just exposing the X protocol. It - // assumes that we have the shared memory segment mapped into our memory, - // which we don't, and it's trying to calculate an offset by taking the - // difference between the |data| pointer and the address of the mapping in - // |shminfo|. Since both are NULL, the offset will be calculated to be 0, - // which is correct for us. - pixmap = XShmCreatePixmap(display_, root_window_, NULL, &shminfo, - width, height, 32); - } else { - // We don't have shared memory pixmaps. Fall back to creating a pixmap - // ourselves and putting an image on it. - pixmap = XCreatePixmap(display_, root_window_, width, height, 32); - GC gc = XCreateGC(display_, pixmap, 0, NULL); - - if (shared_memory_support_ == ui::SHARED_MEMORY_PUTIMAGE) { - const XID shmseg = dib->MapToX(display_); - - XShmSegmentInfo shminfo; - memset(&shminfo, 0, sizeof(shminfo)); - shminfo.shmseg = shmseg; - shminfo.shmaddr = static_cast<char*>(dib->memory()); - - XImage* image = XShmCreateImage(display_, static_cast<Visual*>(visual_), - 32, ZPixmap, - shminfo.shmaddr, &shminfo, - width, height); - - // This code path is important for performance and we have found that - // different techniques work better on different platforms. See - // http://code.google.com/p/chromium/issues/detail?id=44124. - // - // Checking for ARM is an approximation, but it seems to be a good one so - // far. -#if defined(ARCH_CPU_ARM_FAMILY) - for (size_t i = 0; i < copy_rects.size(); i++) { - const gfx::Rect& copy_rect = copy_rects[i]; - gfx::Rect pixel_copy_rect = gfx::ToEnclosedRect( - gfx::ScaleRect(copy_rect, scale_factor)); - XShmPutImage(display_, pixmap, gc, image, - pixel_copy_rect.x() - pixel_bitmap_rect.x(), /* source x */ - pixel_copy_rect.y() - pixel_bitmap_rect.y(), /* source y */ - pixel_copy_rect.x() - pixel_bitmap_rect.x(), /* dest x */ - pixel_copy_rect.y() - pixel_bitmap_rect.y(), /* dest y */ - pixel_copy_rect.width(), pixel_copy_rect.height(), - False /* send_event */); - } -#else - XShmPutImage(display_, pixmap, gc, image, - 0, 0 /* source x, y */, 0, 0 /* dest x, y */, - width, height, False /* send_event */); -#endif - XDestroyImage(image); - } else { // case SHARED_MEMORY_NONE - // No shared memory support, we have to copy the bitmap contents - // to the X server. Xlib wraps the underlying PutImage call - // behind several layers of functions which try to convert the - // image into the format which the X server expects. The - // following values hopefully disable all conversions. - XImage image; - memset(&image, 0, sizeof(image)); - - image.width = width; - image.height = height; - image.depth = 32; - image.bits_per_pixel = 32; - image.format = ZPixmap; - image.byte_order = LSBFirst; - image.bitmap_unit = 8; - image.bitmap_bit_order = LSBFirst; - image.bytes_per_line = width * 4; - image.red_mask = 0xff; - image.green_mask = 0xff00; - image.blue_mask = 0xff0000; - image.data = static_cast<char*>(dib->memory()); - - XPutImage(display_, pixmap, gc, &image, - 0, 0 /* source x, y */, 0, 0 /* dest x, y */, - width, height); - } - XFreeGC(display_, gc); - } - - picture = ui::CreatePictureFromSkiaPixmap(display_, pixmap); - - if (scale_factor != 1.0) { - float up_scale = 1.0 / scale_factor; - XTransform scaling = { { - { XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0) }, - { XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0) }, - { XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(up_scale) } - } }; - XRenderSetPictureTransform(display_, picture, &scaling); - XRenderSetPictureFilter(display_, picture, FilterGood, NULL, 0); - } - for (size_t i = 0; i < copy_rects.size(); i++) { - const gfx::Rect& copy_rect = copy_rects[i]; - XRenderComposite(display_, - PictOpSrc, // op - picture, // src - 0, // mask - picture_, // dest - copy_rect.x() - bitmap_rect.x(), // src_x - copy_rect.y() - bitmap_rect.y(), // src_y - 0, // mask_x - 0, // mask_y - copy_rect.x(), // dest_x - copy_rect.y(), // dest_y - copy_rect.width(), // width - copy_rect.height()); // height - } - - // In the case of shared memory, we wait for the composite to complete so that - // we are sure that the X server has finished reading from the shared memory - // segment. - if (shared_memory_support_ != ui::SHARED_MEMORY_NONE) { - XSyncHandler* handler = XSyncHandler::GetInstance(); - if (handler->Enabled()) { - *scheduled_completion_callback = true; - handler->PushPaintCounter( - dib, display_, picture, pixmap, completion_callback); - } else { - XSync(display_, False); - } - } - - if (*scheduled_completion_callback == false) { - // If we didn't schedule a callback, we need to delete our resources now. - XRenderFreePicture(display_, picture); - XFreePixmap(display_, pixmap); - } -} - -bool BackingStoreGtk::CopyFromBackingStore(const gfx::Rect& rect, - skia::PlatformBitmap* output) { - base::TimeTicks begin_time = base::TimeTicks::Now(); - - if (visual_depth_ < 24) { - // CopyFromBackingStore() copies pixels out of the XImage - // in a way that assumes that each component (red, green, - // blue) is a byte. This doesn't work on visuals which - // encode a pixel color with less than a byte per color. - return false; - } - - const int width = std::min(size().width(), rect.width()); - const int height = std::min(size().height(), rect.height()); - - XImage* image; - XShmSegmentInfo shminfo; // Used only when shared memory is enabled. - if (shared_memory_support_ != ui::SHARED_MEMORY_NONE) { - // Use shared memory for faster copies when it's available. - Visual* visual = static_cast<Visual*>(visual_); - memset(&shminfo, 0, sizeof(shminfo)); - image = XShmCreateImage(display_, visual, 32, - ZPixmap, NULL, &shminfo, width, height); - if (!image) { - return false; - } - // Create the shared memory segment for the image and map it. - if (image->bytes_per_line == 0 || image->height == 0 || - static_cast<size_t>(image->height) > - (std::numeric_limits<size_t>::max() / image->bytes_per_line)) { - XDestroyImage(image); - return false; - } - shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, - IPC_CREAT|0600); - if (shminfo.shmid == -1) { - XDestroyImage(image); - LOG(WARNING) << "Failed to get shared memory segment. " - "Performance may be degraded."; - return false; - } else { - VLOG(1) << "Got shared memory segment " << shminfo.shmid; - } - - void* mapped_memory = shmat(shminfo.shmid, NULL, SHM_RDONLY); - shmctl(shminfo.shmid, IPC_RMID, 0); - if (mapped_memory == (void*)-1) { - XDestroyImage(image); - return false; - } - shminfo.shmaddr = image->data = static_cast<char*>(mapped_memory); - - if (!XShmAttach(display_, &shminfo) || - !XShmGetImage(display_, pixmap_, image, rect.x(), rect.y(), - AllPlanes)) { - DestroySharedImage(display_, image, &shminfo); - LOG(WARNING) << "X failed to get shared memory segment. " - "Performance may be degraded."; - return false; - } - - VLOG(1) << "Using X shared memory segment " << shminfo.shmid; - } else { - LOG(WARNING) << "Not using X shared memory."; - // Non-shared memory case just copy the image from the server. - image = XGetImage(display_, pixmap_, - rect.x(), rect.y(), width, height, - AllPlanes, ZPixmap); - } - - // TODO(jhawkins): Need to convert the image data if the image bits per pixel - // is not 32. - // Note that this also initializes the output bitmap as opaque. - if (!output->Allocate(width, height, true) || - image->bits_per_pixel != 32) { - if (shared_memory_support_ != ui::SHARED_MEMORY_NONE) - DestroySharedImage(display_, image, &shminfo); - else - XDestroyImage(image); - return false; - } - - // The X image might have a different row stride, so iterate through - // it and copy each row out, only up to the pixels we're actually - // using. This code assumes a visual mode where a pixel is - // represented using a 32-bit unsigned int, with a byte per component. - const SkBitmap& bitmap = output->GetBitmap(); - SkAutoLockPixels alp(bitmap); - - for (int y = 0; y < height; y++) { - const uint32* src_row = reinterpret_cast<uint32*>( - &image->data[image->bytes_per_line * y]); - uint32* dest_row = bitmap.getAddr32(0, y); - for (int x = 0; x < width; ++x, ++dest_row) { - // Force alpha to be 0xff, because otherwise it causes rendering problems. - *dest_row = src_row[x] | 0xff000000; - } - } - - if (shared_memory_support_ != ui::SHARED_MEMORY_NONE) - DestroySharedImage(display_, image, &shminfo); - else - XDestroyImage(image); - - HISTOGRAM_TIMES("BackingStore.RetrievalFromX", - base::TimeTicks::Now() - begin_time); - return true; -} - -void BackingStoreGtk::ScrollBackingStore(const gfx::Vector2d& delta, - const gfx::Rect& clip_rect, - const gfx::Size& view_size) { - if (!display_) - return; - - // We only support scrolling in one direction at a time. - DCHECK(delta.x() == 0 || delta.y() == 0); - - if (delta.y()) { - // Positive values of |delta|.y() scroll up - if (abs(delta.y()) < clip_rect.height()) { - XCopyArea(display_, pixmap_, pixmap_, static_cast<GC>(pixmap_gc_), - clip_rect.x() /* source x */, - std::max(clip_rect.y(), clip_rect.y() - delta.y()), - clip_rect.width(), - clip_rect.height() - abs(delta.y()), - clip_rect.x() /* dest x */, - std::max(clip_rect.y(), clip_rect.y() + delta.y()) /* dest y */ - ); - } - } else if (delta.x()) { - // Positive values of |delta|.x() scroll right - if (abs(delta.x()) < clip_rect.width()) { - XCopyArea(display_, pixmap_, pixmap_, static_cast<GC>(pixmap_gc_), - std::max(clip_rect.x(), clip_rect.x() - delta.x()), - clip_rect.y() /* source y */, - clip_rect.width() - abs(delta.x()), - clip_rect.height(), - std::max(clip_rect.x(), clip_rect.x() + delta.x()) /* dest x */, - clip_rect.y() /* dest x */); - } - } -} - -void BackingStoreGtk::XShowRect(const gfx::Point &origin, - const gfx::Rect& rect, XID target) { - XCopyArea(display_, pixmap_, target, static_cast<GC>(pixmap_gc_), - rect.x(), rect.y(), rect.width(), rect.height(), - rect.x() + origin.x(), rect.y() + origin.y()); -} - -#if defined(TOOLKIT_GTK) -void BackingStoreGtk::PaintToRect(const gfx::Rect& rect, GdkDrawable* target) { - cairo_surface_t* surface = cairo_xlib_surface_create( - display_, pixmap_, static_cast<Visual*>(visual_), - size().width(), size().height()); - cairo_t* cr = gdk_cairo_create(target); - - cairo_translate(cr, rect.x(), rect.y()); - double x_scale = static_cast<double>(rect.width()) / size().width(); - double y_scale = static_cast<double>(rect.height()) / size().height(); - cairo_scale(cr, x_scale, y_scale); - - cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface); - cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST); - cairo_set_source(cr, pattern); - cairo_pattern_destroy(pattern); - - cairo_identity_matrix(cr); - - cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); - cairo_fill(cr); - cairo_destroy(cr); -} -#endif - -} // namespace content diff --git a/content/browser/renderer_host/backing_store_gtk.h b/content/browser/renderer_host/backing_store_gtk.h deleted file mode 100644 index 29776fc..0000000 --- a/content/browser/renderer_host/backing_store_gtk.h +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_ -#define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "build/build_config.h" -#include "content/browser/renderer_host/backing_store.h" -#include "content/common/content_export.h" -#include "ui/gfx/x/x11_types.h" - -namespace gfx { -class Point; -class Rect; -} - -typedef struct _GdkDrawable GdkDrawable; - -namespace content { - -class CONTENT_EXPORT BackingStoreGtk : public BackingStore { - public: - // Create a backing store on the X server. The visual is an Xlib Visual - // describing the format of the target window and the depth is the color - // depth of the X window which will be drawn into. - BackingStoreGtk(RenderWidgetHost* widget, - const gfx::Size& size, - void* visual, - int depth); - - // This is for unittesting only. An object constructed using this constructor - // will silently ignore all paints - BackingStoreGtk(RenderWidgetHost* widget, const gfx::Size& size); - - virtual ~BackingStoreGtk(); - - XDisplay* display() const { return display_; } - XID root_window() const { return root_window_; } - - // Copy from the server-side backing store to the target window - // origin: the destination rectangle origin - // damage: the area to copy - // target: the X id of the target window - void XShowRect(const gfx::Point &origin, const gfx::Rect& damage, - XID target); - -#if defined(TOOLKIT_GTK) - // Paint the backing store into the target's |dest_rect|. - void PaintToRect(const gfx::Rect& dest_rect, GdkDrawable* target); -#endif - - // BackingStore implementation. - virtual size_t MemorySize() OVERRIDE; - virtual void PaintToBackingStore( - RenderProcessHost* process, - TransportDIB::Id bitmap, - const gfx::Rect& bitmap_rect, - const std::vector<gfx::Rect>& copy_rects, - float scale_factor, - const base::Closure& completion_callback, - bool* scheduled_completion_callback) OVERRIDE; - virtual bool CopyFromBackingStore(const gfx::Rect& rect, - skia::PlatformBitmap* output) OVERRIDE; - virtual void ScrollBackingStore(const gfx::Vector2d& delta, - const gfx::Rect& clip_rect, - const gfx::Size& view_size) OVERRIDE; - - private: - // Paints the bitmap from the renderer onto the backing store without - // using Xrender to composite the pixmaps. - void PaintRectWithoutXrender(TransportDIB* bitmap, - const gfx::Rect& bitmap_rect, - const std::vector<gfx::Rect>& copy_rects); - - // This is the connection to the X server where this backing store will be - // displayed. - XDisplay* const display_; - // What flavor, if any, MIT-SHM (X shared memory) support we have. - const ui::SharedMemorySupport shared_memory_support_; - // If this is true, then we can use Xrender to composite our pixmaps. - const bool use_render_; - // If |use_render_| is false, this is the number of bits-per-pixel for |depth| - int pixmap_bpp_; - // if |use_render_| is false, we need the Visual to get the RGB masks. - void* const visual_; - // This is the depth of the target window. - const int visual_depth_; - // The parent window (probably a GtkDrawingArea) for this backing store. - const XID root_window_; - // This is a handle to the server side pixmap which is our backing store. - XID pixmap_; - // This is the RENDER picture pointing at |pixmap_|. - XID picture_; - // This is a default graphic context, used in XCopyArea - void* pixmap_gc_; - - DISALLOW_COPY_AND_ASSIGN(BackingStoreGtk); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_ diff --git a/content/browser/renderer_host/gtk_im_context_wrapper.cc b/content/browser/renderer_host/gtk_im_context_wrapper.cc deleted file mode 100644 index 3601b8d..0000000 --- a/content/browser/renderer_host/gtk_im_context_wrapper.cc +++ /dev/null @@ -1,665 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/gtk_im_context_wrapper.h" - -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include <algorithm> - -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "content/browser/renderer_host/render_widget_host_impl.h" -#include "content/browser/renderer_host/render_widget_host_view_gtk.h" -#include "content/public/browser/native_web_keyboard_event.h" -#include "third_party/WebKit/public/web/WebCompositionUnderline.h" -#include "ui/base/ime/composition_text_util_pango.h" -#include "ui/gfx/gtk_util.h" -#include "ui/gfx/rect.h" - -namespace content { -namespace { - -// Copied from third_party/WebKit/Source/WebCore/page/EventHandler.cpp -// -// Match key code of composition keydown event on windows. -// IE sends VK_PROCESSKEY which has value 229; -// -// Please refer to following documents for detals: -// - Virtual-Key Codes -// http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx -// - How the IME System Works -// http://msdn.microsoft.com/en-us/library/cc194848.aspx -// - ImmGetVirtualKey Function -// http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx -const int kCompositionEventKeyCode = 229; - -} // namespace - -// ui::CompositionUnderline should be identical to -// blink::WebCompositionUnderline, so that we can do reinterpret_cast safely. -// TODO(suzhe): remove it after migrating all code in chrome to use -// ui::CompositionUnderline. -COMPILE_ASSERT(sizeof(ui::CompositionUnderline) == - sizeof(blink::WebCompositionUnderline), - ui_CompositionUnderline__WebKit_WebCompositionUnderline_diff); - -GtkIMContextWrapper::GtkIMContextWrapper(RenderWidgetHostViewGtk* host_view) - : host_view_(host_view), - context_(gtk_im_multicontext_new()), - context_simple_(gtk_im_context_simple_new()), - is_focused_(false), - is_composing_text_(false), - is_enabled_(false), - is_in_key_event_handler_(false), - is_composition_changed_(false), - suppress_next_commit_(false), - last_key_code_(0), - last_key_was_up_(false), - last_key_filtered_no_result_(false) { - DCHECK(context_); - DCHECK(context_simple_); - - // context_ and context_simple_ share the same callback handlers. - // All data come from them are treated equally. - // context_ is for full input method support. - // context_simple_ is for supporting dead/compose keys when input method is - // disabled by webkit, eg. in password input box. - g_signal_connect(context_, "preedit-start", - G_CALLBACK(HandlePreeditStartThunk), this); - g_signal_connect(context_, "preedit-end", - G_CALLBACK(HandlePreeditEndThunk), this); - g_signal_connect(context_, "preedit-changed", - G_CALLBACK(HandlePreeditChangedThunk), this); - g_signal_connect(context_, "commit", - G_CALLBACK(HandleCommitThunk), this); - g_signal_connect(context_, "retrieve-surrounding", - G_CALLBACK(HandleRetrieveSurroundingThunk), this); - - g_signal_connect(context_simple_, "preedit-start", - G_CALLBACK(HandlePreeditStartThunk), this); - g_signal_connect(context_simple_, "preedit-end", - G_CALLBACK(HandlePreeditEndThunk), this); - g_signal_connect(context_simple_, "preedit-changed", - G_CALLBACK(HandlePreeditChangedThunk), this); - g_signal_connect(context_simple_, "commit", - G_CALLBACK(HandleCommitThunk), this); - g_signal_connect(context_simple_, "retrieve-surrounding", - G_CALLBACK(HandleRetrieveSurroundingThunk), this); - - GtkWidget* widget = host_view->GetNativeView(); - DCHECK(widget); - - g_signal_connect(widget, "realize", - G_CALLBACK(HandleHostViewRealizeThunk), this); - g_signal_connect(widget, "unrealize", - G_CALLBACK(HandleHostViewUnrealizeThunk), this); - - // Set client window if the widget is already realized. - HandleHostViewRealize(widget); -} - -GtkIMContextWrapper::~GtkIMContextWrapper() { - if (context_) - g_object_unref(context_); - if (context_simple_) - g_object_unref(context_simple_); -} - -void GtkIMContextWrapper::ProcessKeyEvent(GdkEventKey* event) { - suppress_next_commit_ = false; - - // Indicates preedit-changed and commit signal handlers that we are - // processing a key event. - is_in_key_event_handler_ = true; - // Reset this flag so that we can know if preedit is changed after - // processing this key event. - is_composition_changed_ = false; - // Clear it so that we can know if something needs committing after - // processing this key event. - commit_text_.clear(); - - // According to Document Object Model (DOM) Level 3 Events Specification - // Appendix A: Keyboard events and key identifiers - // http://www.w3.org/TR/DOM-Level-3-Events/keyset.html: - // The event sequence would be: - // 1. keydown - // 2. textInput - // 3. keyup - // - // So keydown must be sent to webkit before sending input method result, - // while keyup must be sent afterwards. - // However on Windows, if a keydown event has been processed by IME, its - // virtual keycode will be changed to VK_PROCESSKEY(0xE5) before being sent - // to application. - // To emulate the windows behavior as much as possible, we need to send the - // key event to the GtkIMContext object first, and decide whether or not to - // send the original key event to webkit according to the result from IME. - // - // If IME is enabled by WebKit, this event will be dispatched to context_ - // to get full IME support. Otherwise it'll be dispatched to - // context_simple_, so that dead/compose keys can still work. - // - // It sends a "commit" signal when it has a character to be inserted - // even when we use a US keyboard so that we can send a Char event - // (or an IME event) to the renderer in our "commit"-signal handler. - // We should send a KeyDown (or a KeyUp) event before dispatching this - // event to the GtkIMContext object (and send a Char event) so that WebKit - // can dispatch the JavaScript events in the following order: onkeydown(), - // onkeypress(), and onkeyup(). (Many JavaScript pages assume this.) - gboolean filtered = false; - if (is_enabled_) { - filtered = gtk_im_context_filter_keypress(context_, event); - } else { - filtered = gtk_im_context_filter_keypress(context_simple_, event); - } - - // Reset this flag here, as it's only used in input method callbacks. - is_in_key_event_handler_ = false; - - NativeWebKeyboardEvent wke(reinterpret_cast<GdkEvent*>(event)); - - // If the key event was handled by the input method, then we need to prevent - // RenderView::UnhandledKeyboardEvent() from processing it. - // Otherwise unexpected result may occur. For example if it's a - // Backspace key event, the browser may go back to previous page. - // We just send all keyup events to the browser to avoid breaking the - // browser's MENU key function, which is actually the only keyup event - // handled in the browser. - if (filtered && event->type == GDK_KEY_PRESS) - wke.skip_in_browser = true; - - const int key_code = wke.windowsKeyCode; - const bool has_result = HasInputMethodResult(); - - // Send filtered keydown event before sending IME result. - // In order to workaround http://crosbug.com/6582, we only send a filtered - // keydown event if it generated any input method result. - if (event->type == GDK_KEY_PRESS && filtered && has_result) - ProcessFilteredKeyPressEvent(&wke); - - // Send IME results. In most cases, it's only available if the key event - // is filtered by IME. But in rare cases, an unfiltered key event may also - // generate IME results. - // Any IME results generated by a unfiltered key down event must be sent - // before the key down event, to avoid some tricky issues. For example, - // when using latin-post input method, pressing 'a' then Backspace, may - // generate following events in sequence: - // 1. keydown 'a' (filtered) - // 2. preedit changed to "a" - // 3. keyup 'a' (unfiltered) - // 4. keydown Backspace (unfiltered) - // 5. commit "a" - // 6. preedit end - // 7. keyup Backspace (unfiltered) - // - // In this case, the input box will be in a strange state if keydown - // Backspace is sent to webkit before commit "a" and preedit end. - if (has_result) - ProcessInputMethodResult(event, filtered); - - // Send unfiltered keydown and keyup events after sending IME result. - if (event->type == GDK_KEY_PRESS && !filtered) { - ProcessUnfilteredKeyPressEvent(&wke); - } else if (event->type == GDK_KEY_RELEASE) { - // In order to workaround http://crosbug.com/6582, we need to suppress - // the keyup event if corresponding keydown event was suppressed, or - // the last key event was a keyup event with the same keycode. - const bool suppress = (last_key_code_ == key_code) && - (last_key_was_up_ || last_key_filtered_no_result_); - - if (!suppress) - host_view_->ForwardKeyboardEvent(wke); - } - - last_key_code_ = key_code; - last_key_was_up_ = (event->type == GDK_KEY_RELEASE); - last_key_filtered_no_result_ = (filtered && !has_result); -} - -void GtkIMContextWrapper::UpdateInputMethodState( - ui::TextInputType type, - bool can_compose_inline) { - suppress_next_commit_ = false; - - // The renderer has updated its IME status. - // Control the GtkIMContext object according to this status. - if (!context_) - return; - - DCHECK(!is_in_key_event_handler_); - - bool is_enabled = (type != ui::TEXT_INPUT_TYPE_NONE && - type != ui::TEXT_INPUT_TYPE_PASSWORD); - if (is_enabled_ != is_enabled) { - is_enabled_ = is_enabled; - if (is_enabled && is_focused_) - gtk_im_context_focus_in(context_); - else - gtk_im_context_focus_out(context_); - } - - if (is_enabled) { - // If the focused element supports inline rendering of composition text, - // we receive and send related events to it. Otherwise, the events related - // to the updates of composition text are directed to the candidate window. - gtk_im_context_set_use_preedit(context_, can_compose_inline); - } -} - -void GtkIMContextWrapper::UpdateCaretBounds( - const gfx::Rect& caret_bounds) { - if (is_enabled_) { - // Updates the position of the IME candidate window. - // The position sent from the renderer is a relative one, so we need to - // attach the GtkIMContext object to this window before changing the - // position. - GdkRectangle cursor_rect(caret_bounds.ToGdkRectangle()); - gtk_im_context_set_cursor_location(context_, &cursor_rect); - } -} - -void GtkIMContextWrapper::OnFocusIn() { - if (is_focused_) - return; - - // Tracks the focused state so that we can give focus to the - // GtkIMContext object correctly later when IME is enabled by WebKit. - is_focused_ = true; - - last_key_code_ = 0; - last_key_was_up_ = false; - last_key_filtered_no_result_ = false; - - // Notify the GtkIMContext object of this focus-in event only if IME is - // enabled by WebKit. - if (is_enabled_) - gtk_im_context_focus_in(context_); - - // context_simple_ is always enabled. - // Actually it doesn't care focus state at all. - gtk_im_context_focus_in(context_simple_); - - // Enables RenderWidget's IME related events, so that we can be notified - // when WebKit wants to enable or disable IME. - if (host_view_->GetRenderWidgetHost()) { - RenderWidgetHostImpl::From( - host_view_->GetRenderWidgetHost())->SetInputMethodActive(true); - } -} - -void GtkIMContextWrapper::OnFocusOut() { - if (!is_focused_) - return; - - // Tracks the focused state so that we won't give focus to the - // GtkIMContext object unexpectly. - is_focused_ = false; - - // Notify the GtkIMContext object of this focus-out event only if IME is - // enabled by WebKit. - if (is_enabled_) { - // To reset the GtkIMContext object and prevent data loss. - ConfirmComposition(); - gtk_im_context_focus_out(context_); - } - - // To make sure it'll be in correct state when focused in again. - gtk_im_context_reset(context_simple_); - gtk_im_context_focus_out(context_simple_); - - is_composing_text_ = false; - - // Disable RenderWidget's IME related events to save bandwidth. - if (host_view_->GetRenderWidgetHost()) { - RenderWidgetHostImpl::From( - host_view_->GetRenderWidgetHost())->SetInputMethodActive(false); - } -} - -GtkWidget* GtkIMContextWrapper::BuildInputMethodsGtkMenu() { - GtkWidget* submenu = gtk_menu_new(); - gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(context_), - GTK_MENU_SHELL(submenu)); - return submenu; -} - -void GtkIMContextWrapper::CancelComposition() { - if (!is_enabled_) - return; - - DCHECK(!is_in_key_event_handler_); - - // To prevent any text from being committed when resetting the |context_|; - is_in_key_event_handler_ = true; - suppress_next_commit_ = true; - - gtk_im_context_reset(context_); - gtk_im_context_reset(context_simple_); - - if (is_focused_) { - // Some input methods may not honour the reset call. Focusing out/in the - // |context_| to make sure it gets reset correctly. - gtk_im_context_focus_out(context_); - gtk_im_context_focus_in(context_); - } - - is_composing_text_ = false; - composition_.Clear(); - commit_text_.clear(); - - is_in_key_event_handler_ = false; -} - -bool GtkIMContextWrapper::NeedCommitByForwardingCharEvent() const { - // If there is no composition text and has only one character to be - // committed, then the character will be send to webkit as a Char event - // instead of a confirmed composition text. - // It should be fine to handle BMP character only, as non-BMP characters - // can always be committed as confirmed composition text. - return !is_composing_text_ && commit_text_.length() == 1; -} - -bool GtkIMContextWrapper::HasInputMethodResult() const { - return commit_text_.length() || is_composition_changed_; -} - -void GtkIMContextWrapper::ProcessFilteredKeyPressEvent( - NativeWebKeyboardEvent* wke) { - // If IME has filtered this event, then replace virtual key code with - // VK_PROCESSKEY. See comment in ProcessKeyEvent() for details. - // It's only required for keydown events. - // To emulate windows behavior, when input method is enabled, if the commit - // text can be emulated by a Char event, then don't do this replacement. - if (!NeedCommitByForwardingCharEvent()) { - wke->windowsKeyCode = kCompositionEventKeyCode; - // keyidentifier must be updated accordingly, otherwise this key event may - // still be processed by webkit. - wke->setKeyIdentifierFromWindowsKeyCode(); - } - host_view_->ForwardKeyboardEvent(*wke); -} - -void GtkIMContextWrapper::ProcessUnfilteredKeyPressEvent( - NativeWebKeyboardEvent* wke) { - // Send keydown event as it, because it's not filtered by IME. - host_view_->ForwardKeyboardEvent(*wke); - - // IME is disabled by WebKit or the GtkIMContext object cannot handle - // this key event. - // This case is caused by two reasons: - // 1. The given key event is a control-key event, (e.g. return, page up, - // page down, tab, arrows, etc.) or; - // 2. The given key event is not a control-key event but printable - // characters aren't assigned to the event, (e.g. alt+d, etc.) - // Create a Char event manually from this key event and send it to the - // renderer when this Char event contains a printable character which - // should be processed by WebKit. - // isSystemKey will be set to true if this key event has Alt modifier, - // see WebInputEventFactory::keyboardEvent() for details. - if (wke->text[0]) { - wke->type = blink::WebInputEvent::Char; - wke->skip_in_browser = true; - host_view_->ForwardKeyboardEvent(*wke); - } -} - -void GtkIMContextWrapper::ProcessInputMethodResult(const GdkEventKey* event, - bool filtered) { - RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( - host_view_->GetRenderWidgetHost()); - if (!host) - return; - - bool committed = false; - // We do commit before preedit change, so that we can optimize some - // unnecessary preedit changes. - if (commit_text_.length()) { - if (filtered && NeedCommitByForwardingCharEvent()) { - // Send a Char event when we input a composed character without IMEs - // so that this event is to be dispatched to onkeypress() handlers, - // autofill, etc. - // Only commit text generated by a filtered key down event can be sent - // as a Char event, because a unfiltered key down event will probably - // generate another Char event. - // TODO(james.su@gmail.com): Is it necessary to support non BMP chars - // here? - NativeWebKeyboardEvent char_event(commit_text_[0], - event->state, - base::Time::Now().ToDoubleT()); - char_event.skip_in_browser = true; - host_view_->ForwardKeyboardEvent(char_event); - } else { - committed = true; - // Send an IME event. - // Unlike a Char event, an IME event is NOT dispatched to onkeypress() - // handlers or autofill. - host->ImeConfirmComposition( - commit_text_,gfx::Range::InvalidRange(),false); - // Set this flag to false, as this composition session has been - // finished. - is_composing_text_ = false; - } - } - - // Send preedit text only if it's changed. - // If a text has been committed, then we don't need to send the empty - // preedit text again. - if (is_composition_changed_) { - if (composition_.text.length()) { - // Another composition session has been started. - is_composing_text_ = true; - // TODO(suzhe): convert both renderer_host and renderer to use - // ui::CompositionText. - const std::vector<blink::WebCompositionUnderline>& underlines = - reinterpret_cast<const std::vector<blink::WebCompositionUnderline>&>( - composition_.underlines); - host->ImeSetComposition(composition_.text, underlines, - composition_.selection.start(), - composition_.selection.end()); - } else if (!committed) { - host->ImeCancelComposition(); - } - } -} - -void GtkIMContextWrapper::ConfirmComposition() { - if (!is_enabled_) - return; - - DCHECK(!is_in_key_event_handler_); - - if (is_composing_text_) { - if (host_view_->GetRenderWidgetHost()) { - RenderWidgetHostImpl::From( - host_view_->GetRenderWidgetHost())->ImeConfirmComposition( - base::string16(), gfx::Range::InvalidRange(), false); - } - - // Reset the input method. - CancelComposition(); - } -} - -void GtkIMContextWrapper::HandleCommit(const base::string16& text) { - if (suppress_next_commit_) - return; - - // Append the text to the buffer, because commit signal might be fired - // multiple times when processing a key event. - commit_text_.append(text); - // Nothing needs to do, if it's currently in ProcessKeyEvent() - // handler, which will send commit text to webkit later. Otherwise, - // we need send it here. - // It's possible that commit signal is fired without a key event, for - // example when user input via a voice or handwriting recognition software. - // In this case, the text must be committed directly. - if (!is_in_key_event_handler_ && host_view_->GetRenderWidgetHost()) { - // Workaround http://crbug.com/45478 by sending fake key down/up events. - SendFakeCompositionKeyEvent(blink::WebInputEvent::RawKeyDown); - RenderWidgetHostImpl::From( - host_view_->GetRenderWidgetHost())->ImeConfirmComposition( - text, gfx::Range::InvalidRange(), false); - SendFakeCompositionKeyEvent(blink::WebInputEvent::KeyUp); - } -} - -void GtkIMContextWrapper::HandlePreeditStart() { - // Ignore preedit related signals triggered by CancelComposition() method. - if (suppress_next_commit_) - return; - is_composing_text_ = true; -} - -void GtkIMContextWrapper::HandlePreeditChanged(const gchar* text, - PangoAttrList* attrs, - int cursor_position) { - // Ignore preedit related signals triggered by CancelComposition() method. - if (suppress_next_commit_) - return; - - // Don't set is_composition_changed_ to false if there is no change, because - // this handler might be called multiple times with the same data. - is_composition_changed_ = true; - composition_.Clear(); - - ui::ExtractCompositionTextFromGtkPreedit(text, attrs, cursor_position, - &composition_); - - // TODO(suzhe): due to a bug of webkit, we currently can't use selection range - // with composition string. See: https://bugs.webkit.org/show_bug.cgi?id=40805 - composition_.selection = gfx::Range(cursor_position); - - // In case we are using a buggy input method which doesn't fire - // "preedit_start" signal. - if (composition_.text.length()) - is_composing_text_ = true; - - // Nothing needs to do, if it's currently in ProcessKeyEvent() - // handler, which will send preedit text to webkit later. - // Otherwise, we need send it here if it's been changed. - if (!is_in_key_event_handler_ && is_composing_text_ && - host_view_->GetRenderWidgetHost()) { - // Workaround http://crbug.com/45478 by sending fake key down/up events. - SendFakeCompositionKeyEvent(blink::WebInputEvent::RawKeyDown); - // TODO(suzhe): convert both renderer_host and renderer to use - // ui::CompositionText. - const std::vector<blink::WebCompositionUnderline>& underlines = - reinterpret_cast<const std::vector<blink::WebCompositionUnderline>&>( - composition_.underlines); - RenderWidgetHostImpl::From( - host_view_->GetRenderWidgetHost())->ImeSetComposition( - composition_.text, underlines, composition_.selection.start(), - composition_.selection.end()); - SendFakeCompositionKeyEvent(blink::WebInputEvent::KeyUp); - } -} - -void GtkIMContextWrapper::HandlePreeditEnd() { - if (composition_.text.length()) { - // The composition session has been finished. - composition_.Clear(); - is_composition_changed_ = true; - - // If there is still a preedit text when firing "preedit-end" signal, - // we need inform webkit to clear it. - // It's only necessary when it's not in ProcessKeyEvent (). - if (!is_in_key_event_handler_ && host_view_->GetRenderWidgetHost()) { - RenderWidgetHostImpl::From( - host_view_->GetRenderWidgetHost())->ImeCancelComposition(); - } - } - - // Don't set is_composing_text_ to false here, because "preedit_end" - // signal may be fired before "commit" signal. -} - -gboolean GtkIMContextWrapper::HandleRetrieveSurrounding(GtkIMContext* context) { - if (!is_enabled_) - return TRUE; - - std::string text; - size_t cursor_index = 0; - - if (!is_enabled_ || !host_view_->RetrieveSurrounding(&text, &cursor_index)) { - gtk_im_context_set_surrounding(context, "", 0, 0); - return TRUE; - } - - gtk_im_context_set_surrounding(context, text.c_str(), text.length(), - cursor_index); - - return TRUE; -} - -void GtkIMContextWrapper::HandleHostViewRealize(GtkWidget* widget) { - // We should only set im context's client window once, because when setting - // client window.im context may destroy and recreate its internal states and - // objects. - GdkWindow* gdk_window = gtk_widget_get_window(widget); - if (gdk_window) { - gtk_im_context_set_client_window(context_, gdk_window); - gtk_im_context_set_client_window(context_simple_, gdk_window); - } -} - -void GtkIMContextWrapper::HandleHostViewUnrealize() { - gtk_im_context_set_client_window(context_, NULL); - gtk_im_context_set_client_window(context_simple_, NULL); -} - -void GtkIMContextWrapper::SendFakeCompositionKeyEvent( - blink::WebInputEvent::Type type) { - NativeWebKeyboardEvent fake_event; - fake_event.windowsKeyCode = kCompositionEventKeyCode; - fake_event.skip_in_browser = true; - fake_event.type = type; - host_view_->ForwardKeyboardEvent(fake_event); -} - -void GtkIMContextWrapper::HandleCommitThunk( - GtkIMContext* context, gchar* text, GtkIMContextWrapper* self) { - self->HandleCommit(base::UTF8ToUTF16(text)); -} - -void GtkIMContextWrapper::HandlePreeditStartThunk( - GtkIMContext* context, GtkIMContextWrapper* self) { - self->HandlePreeditStart(); -} - -void GtkIMContextWrapper::HandlePreeditChangedThunk( - GtkIMContext* context, GtkIMContextWrapper* self) { - gchar* text = NULL; - PangoAttrList* attrs = NULL; - gint cursor_position = 0; - gtk_im_context_get_preedit_string(context, &text, &attrs, &cursor_position); - self->HandlePreeditChanged(text, attrs, cursor_position); - g_free(text); - pango_attr_list_unref(attrs); -} - -void GtkIMContextWrapper::HandlePreeditEndThunk( - GtkIMContext* context, GtkIMContextWrapper* self) { - self->HandlePreeditEnd(); -} - -gboolean GtkIMContextWrapper::HandleRetrieveSurroundingThunk( - GtkIMContext* context, GtkIMContextWrapper* self) { - return self->HandleRetrieveSurrounding(context); -} - -void GtkIMContextWrapper::HandleHostViewRealizeThunk( - GtkWidget* widget, GtkIMContextWrapper* self) { - self->HandleHostViewRealize(widget); -} - -void GtkIMContextWrapper::HandleHostViewUnrealizeThunk( - GtkWidget* widget, GtkIMContextWrapper* self) { - self->HandleHostViewUnrealize(); -} - -} // namespace content diff --git a/content/browser/renderer_host/gtk_im_context_wrapper.h b/content/browser/renderer_host/gtk_im_context_wrapper.h deleted file mode 100644 index 8bd027f..0000000 --- a/content/browser/renderer_host/gtk_im_context_wrapper.h +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ -#define CONTENT_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ - -#include <gdk/gdk.h> -#include <pango/pango-attributes.h> -#include <vector> - -#include "base/basictypes.h" -#include "base/gtest_prod_util.h" -#include "base/strings/string16.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -#include "ui/base/ime/composition_text.h" -#include "ui/base/ime/text_input_type.h" - -typedef struct _GtkIMContext GtkIMContext; -typedef struct _GtkWidget GtkWidget; - -namespace gfx { -class Rect; -} - -namespace content { -class RenderWidgetHostViewGtk; -struct NativeWebKeyboardEvent; - -// This class is a convenience wrapper for GtkIMContext. -// It creates and manages two GtkIMContext instances, one is GtkIMMulticontext, -// for plain text input box, another is GtkIMContextSimple, for password input -// box. -// -// This class is in charge of dispatching key events to these two GtkIMContext -// instances and handling signals emitted by them. Key events then will be -// forwarded to renderer along with input method results via corresponding host -// view. -// -// This class is used solely by RenderWidgetHostViewGtk. -class GtkIMContextWrapper { - public: - explicit GtkIMContextWrapper(RenderWidgetHostViewGtk* host_view); - ~GtkIMContextWrapper(); - - // Processes a gdk key event received by |host_view|. - void ProcessKeyEvent(GdkEventKey* event); - - void UpdateInputMethodState(ui::TextInputType type, - bool can_compose_inline); - void UpdateCaretBounds(const gfx::Rect& caret_bounds); - void OnFocusIn(); - void OnFocusOut(); - bool is_focused() const { return is_focused_; } - - GtkWidget* BuildInputMethodsGtkMenu(); - - void CancelComposition(); - - void ConfirmComposition(); - - private: - // Check if a text needs commit by forwarding a char event instead of - // by confirming as a composition text. - bool NeedCommitByForwardingCharEvent() const; - - // Check if the input method returned any result, eg. preedit and commit text. - bool HasInputMethodResult() const; - - void ProcessFilteredKeyPressEvent(NativeWebKeyboardEvent* wke); - void ProcessUnfilteredKeyPressEvent(NativeWebKeyboardEvent* wke); - - // Processes result returned from input method after filtering a key event. - // |filtered| indicates if the key event was filtered by the input method. - void ProcessInputMethodResult(const GdkEventKey* event, bool filtered); - - // Real code of "commit" signal handler. - void HandleCommit(const base::string16& text); - - // Real code of "preedit-start" signal handler. - void HandlePreeditStart(); - - // Real code of "preedit-changed" signal handler. - void HandlePreeditChanged(const gchar* text, - PangoAttrList* attrs, - int cursor_position); - - // Real code of "preedit-end" signal handler. - void HandlePreeditEnd(); - - // Real code of "retrieve-surrounding" signal handler. - gboolean HandleRetrieveSurrounding(GtkIMContext* context); - - // Real code of "realize" signal handler, used for setting im context's client - // window. - void HandleHostViewRealize(GtkWidget* widget); - - // Real code of "unrealize" signal handler, used for unsetting im context's - // client window. - void HandleHostViewUnrealize(); - - // Sends a fake composition key event with specified event type. A composition - // key event is a key event with special key code 229. - void SendFakeCompositionKeyEvent(blink::WebInputEvent::Type type); - - // Signal handlers of GtkIMContext object. - static void HandleCommitThunk(GtkIMContext* context, gchar* text, - GtkIMContextWrapper* self); - static void HandlePreeditStartThunk(GtkIMContext* context, - GtkIMContextWrapper* self); - static void HandlePreeditChangedThunk(GtkIMContext* context, - GtkIMContextWrapper* self); - static void HandlePreeditEndThunk(GtkIMContext* context, - GtkIMContextWrapper* self); - static gboolean HandleRetrieveSurroundingThunk(GtkIMContext* context, - GtkIMContextWrapper* self); - - // Signal handlers connecting to |host_view_|'s native view widget. - static void HandleHostViewRealizeThunk(GtkWidget* widget, - GtkIMContextWrapper* self); - static void HandleHostViewUnrealizeThunk(GtkWidget* widget, - GtkIMContextWrapper* self); - - // The parent object. - RenderWidgetHostViewGtk* host_view_; - - // The GtkIMContext object. - // In terms of the DOM event specification Appendix A - // <http://www.w3.org/TR/DOM-Level-3-Events/keyset.html>, - // GTK uses a GtkIMContext object for the following two purposes: - // 1. Composing Latin characters (A.1.2), and; - // 2. Composing CJK characters with an IME (A.1.3). - // Many JavaScript pages assume composed Latin characters are dispatched to - // their onkeypress() handlers but not dispatched CJK characters composed - // with an IME. To emulate this behavior, we should monitor the status of - // this GtkIMContext object and prevent sending Char events when a - // GtkIMContext object sends a "commit" signal with the CJK characters - // composed by an IME. - GtkIMContext* context_; - - // A GtkIMContextSimple object, for supporting dead/compose keys when input - // method is disabled, eg. in password input box. - GtkIMContext* context_simple_; - - // Whether or not this widget is focused. - bool is_focused_; - - // Whether or not the above GtkIMContext is composing a text with an IME. - // This flag is used in "commit" signal handler of the GtkIMContext object, - // which determines how to submit the result text to WebKit according to this - // flag. - // If this flag is true or there are more than one characters in the result, - // then the result text will be committed to WebKit as a confirmed - // composition. Otherwise, it'll be forwarded as a key event. - // - // The GtkIMContext object sends a "preedit_start" before it starts composing - // a text and a "preedit_end" signal after it finishes composing it. - // "preedit_start" signal is monitored to turn it on. - // We don't monitor "preedit_end" signal to turn it off, because an input - // method may fire "preedit_end" signal before "commit" signal. - // A buggy input method may not fire "preedit_start" and/or "preedit_end" - // at all, so this flag will also be set to true when "preedit_changed" signal - // is fired with non-empty preedit text. - bool is_composing_text_; - - // Whether or not the IME is enabled. - bool is_enabled_; - - // Whether or not it's currently running inside key event handler. - // If it's true, then preedit-changed and commit handler will backup the - // preedit or commit text instead of sending them down to webkit. - // key event handler will send them later. - bool is_in_key_event_handler_; - - // The most recent composition text information retrieved from context_; - ui::CompositionText composition_; - - // Whether or not the composition has been changed since last key event. - bool is_composition_changed_; - - // Stores a copy of the most recent commit text received by commit signal - // handler. - base::string16 commit_text_; - - // If it's true then the next "commit" signal will be suppressed. - // It's only used to workaround http://crbug.com/50485. - // TODO(suzhe): Remove it after input methods get fixed. - bool suppress_next_commit_; - - // Information of the last key event, for working around - // http://crosbug.com/6582 - int last_key_code_; - bool last_key_was_up_; - bool last_key_filtered_no_result_; - - DISALLOW_COPY_AND_ASSIGN(GtkIMContextWrapper); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ diff --git a/content/browser/renderer_host/gtk_key_bindings_handler.cc b/content/browser/renderer_host/gtk_key_bindings_handler.cc deleted file mode 100644 index 3830364..0000000 --- a/content/browser/renderer_host/gtk_key_bindings_handler.cc +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/gtk_key_bindings_handler.h" - -#include <gdk/gdkkeysyms.h> - -#include <string> - -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "content/public/browser/native_web_keyboard_event.h" - -namespace content { - -GtkKeyBindingsHandler::GtkKeyBindingsHandler(GtkWidget* parent_widget) - : handler_(CreateNewHandler()) { - DCHECK(GTK_IS_FIXED(parent_widget)); - // We need add the |handler_| object into gtk widget hierarchy, so that - // gtk_bindings_activate_event() can find correct display and keymaps from - // the |handler_| object. - gtk_fixed_put(GTK_FIXED(parent_widget), handler_.get(), -1, -1); -} - -GtkKeyBindingsHandler::~GtkKeyBindingsHandler() { - handler_.Destroy(); -} - -bool GtkKeyBindingsHandler::Match(const NativeWebKeyboardEvent& wke, - EditCommands* edit_commands) { - if (wke.type == blink::WebInputEvent::Char || !wke.os_event) - return false; - - edit_commands_.clear(); - // If this key event matches a predefined key binding, corresponding signal - // will be emitted. - gtk_bindings_activate_event(GTK_OBJECT(handler_.get()), &wke.os_event->key); - - bool matched = !edit_commands_.empty(); - if (edit_commands) - edit_commands->swap(edit_commands_); - return matched; -} - -GtkWidget* GtkKeyBindingsHandler::CreateNewHandler() { - Handler* handler = - static_cast<Handler*>(g_object_new(HandlerGetType(), NULL)); - - handler->owner = this; - - // We don't need to show the |handler| object on screen, so set its size to - // zero. - gtk_widget_set_size_request(GTK_WIDGET(handler), 0, 0); - - // Prevents it from handling any events by itself. - gtk_widget_set_sensitive(GTK_WIDGET(handler), FALSE); - gtk_widget_set_events(GTK_WIDGET(handler), 0); - gtk_widget_set_can_focus(GTK_WIDGET(handler), TRUE); - - return GTK_WIDGET(handler); -} - -void GtkKeyBindingsHandler::EditCommandMatched( - const std::string& name, const std::string& value) { - edit_commands_.push_back(EditCommand(name, value)); -} - -void GtkKeyBindingsHandler::HandlerInit(Handler *self) { - self->owner = NULL; -} - -void GtkKeyBindingsHandler::HandlerClassInit(HandlerClass *klass) { - GtkTextViewClass* text_view_class = GTK_TEXT_VIEW_CLASS(klass); - GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass); - - // Overrides all virtual methods related to editor key bindings. - text_view_class->backspace = BackSpace; - text_view_class->copy_clipboard = CopyClipboard; - text_view_class->cut_clipboard = CutClipboard; - text_view_class->delete_from_cursor = DeleteFromCursor; - text_view_class->insert_at_cursor = InsertAtCursor; - text_view_class->move_cursor = MoveCursor; - text_view_class->paste_clipboard = PasteClipboard; - text_view_class->set_anchor = SetAnchor; - text_view_class->toggle_overwrite = ToggleOverwrite; - widget_class->show_help = ShowHelp; - - // "move-focus", "move-viewport", "select-all" and "toggle-cursor-visible" - // have no corresponding virtual methods. Since glib 2.18 (gtk 2.14), - // g_signal_override_class_handler() is introduced to override a signal - // handler. - g_signal_override_class_handler("move-focus", - G_TYPE_FROM_CLASS(klass), - G_CALLBACK(MoveFocus)); - - g_signal_override_class_handler("move-viewport", - G_TYPE_FROM_CLASS(klass), - G_CALLBACK(MoveViewport)); - - g_signal_override_class_handler("select-all", - G_TYPE_FROM_CLASS(klass), - G_CALLBACK(SelectAll)); - - g_signal_override_class_handler("toggle-cursor-visible", - G_TYPE_FROM_CLASS(klass), - G_CALLBACK(ToggleCursorVisible)); -} - -GType GtkKeyBindingsHandler::HandlerGetType() { - static volatile gsize type_id_volatile = 0; - if (g_once_init_enter(&type_id_volatile)) { - GType type_id = g_type_register_static_simple( - GTK_TYPE_TEXT_VIEW, - g_intern_static_string("GtkKeyBindingsHandler"), - sizeof(HandlerClass), - reinterpret_cast<GClassInitFunc>(HandlerClassInit), - sizeof(Handler), - reinterpret_cast<GInstanceInitFunc>(HandlerInit), - static_cast<GTypeFlags>(0)); - g_once_init_leave(&type_id_volatile, type_id); - } - return type_id_volatile; -} - -GtkKeyBindingsHandler* GtkKeyBindingsHandler::GetHandlerOwner( - GtkTextView* text_view) { - Handler* handler = G_TYPE_CHECK_INSTANCE_CAST( - text_view, HandlerGetType(), Handler); - DCHECK(handler); - return handler->owner; -} - -void GtkKeyBindingsHandler::BackSpace(GtkTextView* text_view) { - GetHandlerOwner(text_view) - ->EditCommandMatched("DeleteBackward", std::string()); -} - -void GtkKeyBindingsHandler::CopyClipboard(GtkTextView* text_view) { - GetHandlerOwner(text_view)->EditCommandMatched("Copy", std::string()); -} - -void GtkKeyBindingsHandler::CutClipboard(GtkTextView* text_view) { - GetHandlerOwner(text_view)->EditCommandMatched("Cut", std::string()); -} - -void GtkKeyBindingsHandler::DeleteFromCursor( - GtkTextView* text_view, GtkDeleteType type, gint count) { - if (!count) - return; - - const char *commands[3] = { NULL, NULL, NULL }; - switch (type) { - case GTK_DELETE_CHARS: - commands[0] = (count > 0 ? "DeleteForward" : "DeleteBackward"); - break; - case GTK_DELETE_WORD_ENDS: - commands[0] = (count > 0 ? "DeleteWordForward" : "DeleteWordBackward"); - break; - case GTK_DELETE_WORDS: - if (count > 0) { - commands[0] = "MoveWordForward"; - commands[1] = "DeleteWordBackward"; - } else { - commands[0] = "MoveWordBackward"; - commands[1] = "DeleteWordForward"; - } - break; - case GTK_DELETE_DISPLAY_LINES: - commands[0] = "MoveToBeginningOfLine"; - commands[1] = "DeleteToEndOfLine"; - break; - case GTK_DELETE_DISPLAY_LINE_ENDS: - commands[0] = (count > 0 ? "DeleteToEndOfLine" : - "DeleteToBeginningOfLine"); - break; - case GTK_DELETE_PARAGRAPH_ENDS: - commands[0] = (count > 0 ? "DeleteToEndOfParagraph" : - "DeleteToBeginningOfParagraph"); - break; - case GTK_DELETE_PARAGRAPHS: - commands[0] = "MoveToBeginningOfParagraph"; - commands[1] = "DeleteToEndOfParagraph"; - break; - default: - // GTK_DELETE_WHITESPACE has no corresponding editor command. - return; - } - - GtkKeyBindingsHandler* owner = GetHandlerOwner(text_view); - if (count < 0) - count = -count; - for (; count > 0; --count) { - for (const char* const* p = commands; *p; ++p) - owner->EditCommandMatched(*p, std::string()); - } -} - -void GtkKeyBindingsHandler::InsertAtCursor(GtkTextView* text_view, - const gchar* str) { - if (str && *str) - GetHandlerOwner(text_view)->EditCommandMatched("InsertText", str); -} - -void GtkKeyBindingsHandler::MoveCursor( - GtkTextView* text_view, GtkMovementStep step, gint count, - gboolean extend_selection) { - if (!count) - return; - - std::string command; - switch (step) { - case GTK_MOVEMENT_LOGICAL_POSITIONS: - command = (count > 0 ? "MoveForward" : "MoveBackward"); - break; - case GTK_MOVEMENT_VISUAL_POSITIONS: - command = (count > 0 ? "MoveRight" : "MoveLeft"); - break; - case GTK_MOVEMENT_WORDS: - command = (count > 0 ? "MoveWordRight" : "MoveWordLeft"); - break; - case GTK_MOVEMENT_DISPLAY_LINES: - command = (count > 0 ? "MoveDown" : "MoveUp"); - break; - case GTK_MOVEMENT_DISPLAY_LINE_ENDS: - command = (count > 0 ? "MoveToEndOfLine" : "MoveToBeginningOfLine"); - break; - case GTK_MOVEMENT_PARAGRAPH_ENDS: - command = (count > 0 ? "MoveToEndOfParagraph" : - "MoveToBeginningOfParagraph"); - break; - case GTK_MOVEMENT_PAGES: - command = (count > 0 ? "MovePageDown" : "MovePageUp"); - break; - case GTK_MOVEMENT_BUFFER_ENDS: - command = (count > 0 ? "MoveToEndOfDocument" : - "MoveToBeginningOfDocument"); - break; - default: - // GTK_MOVEMENT_PARAGRAPHS and GTK_MOVEMENT_HORIZONTAL_PAGES have - // no corresponding editor commands. - return; - } - - GtkKeyBindingsHandler* owner = GetHandlerOwner(text_view); - if (extend_selection) - command.append("AndModifySelection"); - if (count < 0) - count = -count; - for (; count > 0; --count) - owner->EditCommandMatched(command, std::string()); -} - -void GtkKeyBindingsHandler::MoveViewport( - GtkTextView* text_view, GtkScrollStep step, gint count) { - // Not supported by webkit. -} - -void GtkKeyBindingsHandler::PasteClipboard(GtkTextView* text_view) { - GetHandlerOwner(text_view)->EditCommandMatched("Paste", std::string()); -} - -void GtkKeyBindingsHandler::SelectAll(GtkTextView* text_view, gboolean select) { - if (select) - GetHandlerOwner(text_view)->EditCommandMatched("SelectAll", std::string()); - else - GetHandlerOwner(text_view)->EditCommandMatched("Unselect", std::string()); -} - -void GtkKeyBindingsHandler::SetAnchor(GtkTextView* text_view) { - GetHandlerOwner(text_view)->EditCommandMatched("SetMark", std::string()); -} - -void GtkKeyBindingsHandler::ToggleCursorVisible(GtkTextView* text_view) { - // Not supported by webkit. -} - -void GtkKeyBindingsHandler::ToggleOverwrite(GtkTextView* text_view) { - // Not supported by webkit. -} - -gboolean GtkKeyBindingsHandler::ShowHelp(GtkWidget* widget, - GtkWidgetHelpType arg1) { - // Just for disabling the default handler. - return FALSE; -} - -void GtkKeyBindingsHandler::MoveFocus(GtkWidget* widget, - GtkDirectionType arg1) { - // Just for disabling the default handler. -} - -} // namespace content diff --git a/content/browser/renderer_host/gtk_key_bindings_handler.h b/content/browser/renderer_host/gtk_key_bindings_handler.h deleted file mode 100644 index 9006f5d..0000000 --- a/content/browser/renderer_host/gtk_key_bindings_handler.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ -#define CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ - -#include <gtk/gtk.h> - -#include <string> - -#include "content/common/edit_command.h" -#include "content/common/content_export.h" -#include "ui/base/gtk/owned_widget_gtk.h" - -namespace content { -struct NativeWebKeyboardEvent; - -// This class is a convenience class for handling editor key bindings defined -// in gtk keyboard theme. -// In gtk, only GtkEntry and GtkTextView support customizing editor key bindings -// through keyboard theme. And in gtk keyboard theme definition file, each key -// binding must be bound to a specific class or object. So existing keyboard -// themes only define editor key bindings exactly for GtkEntry and GtkTextView. -// Then, the only way for us to intercept editor key bindings defined in -// keyboard theme, is to create a GtkEntry or GtkTextView object and call -// gtk_bindings_activate_event() against it for the key events. If a key event -// matches a predefined key binding, corresponding signal will be emitted. -// GtkTextView is used here because it supports more key bindings than GtkEntry, -// but in order to minimize the side effect of using a GtkTextView object, a new -// class derived from GtkTextView is used, which overrides all signals related -// to key bindings, to make sure GtkTextView won't receive them. -// -// See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed -// definition of webkit edit commands. -// See webkit/glue/editor_client_impl.cc for key bindings predefined in our -// webkit glue. -class CONTENT_EXPORT GtkKeyBindingsHandler { - public: - explicit GtkKeyBindingsHandler(GtkWidget* parent_widget); - ~GtkKeyBindingsHandler(); - - // Matches a key event against predefined gtk key bindings, false will be - // returned if the key event doesn't correspond to a predefined key binding. - // Edit commands matched with |wke| will be stored in |edit_commands|. - bool Match(const NativeWebKeyboardEvent& wke, - EditCommands* edit_commands); - - private: - // Object structure of Handler class, which is derived from GtkTextView. - struct Handler { - GtkTextView parent_object; - GtkKeyBindingsHandler *owner; - }; - - // Class structure of Handler class. - struct HandlerClass { - GtkTextViewClass parent_class; - }; - - // Creates a new instance of Handler class. - GtkWidget* CreateNewHandler(); - - // Adds an edit command to the key event. - void EditCommandMatched(const std::string& name, const std::string& value); - - // Initializes Handler structure. - static void HandlerInit(Handler *self); - - // Initializes HandlerClass structure. - static void HandlerClassInit(HandlerClass *klass); - - // Registeres Handler class to GObject type system and return its type id. - static GType HandlerGetType(); - - // Gets the GtkKeyBindingsHandler object which owns the Handler object. - static GtkKeyBindingsHandler* GetHandlerOwner(GtkTextView* text_view); - - // Handler of "backspace" signal. - static void BackSpace(GtkTextView* text_view); - - // Handler of "copy-clipboard" signal. - static void CopyClipboard(GtkTextView* text_view); - - // Handler of "cut-clipboard" signal. - static void CutClipboard(GtkTextView* text_view); - - // Handler of "delete-from-cursor" signal. - static void DeleteFromCursor(GtkTextView* text_view, GtkDeleteType type, - gint count); - - // Handler of "insert-at-cursor" signal. - static void InsertAtCursor(GtkTextView* text_view, const gchar* str); - - // Handler of "move-cursor" signal. - static void MoveCursor(GtkTextView* text_view, GtkMovementStep step, - gint count, gboolean extend_selection); - - // Handler of "move-viewport" signal. - static void MoveViewport(GtkTextView* text_view, GtkScrollStep step, - gint count); - - // Handler of "paste-clipboard" signal. - static void PasteClipboard(GtkTextView* text_view); - - // Handler of "select-all" signal. - static void SelectAll(GtkTextView* text_view, gboolean select); - - // Handler of "set-anchor" signal. - static void SetAnchor(GtkTextView* text_view); - - // Handler of "toggle-cursor-visible" signal. - static void ToggleCursorVisible(GtkTextView* text_view); - - // Handler of "toggle-overwrite" signal. - static void ToggleOverwrite(GtkTextView* text_view); - - // Handler of "show-help" signal. - static gboolean ShowHelp(GtkWidget* widget, GtkWidgetHelpType arg1); - - // Handler of "move-focus" signal. - static void MoveFocus(GtkWidget* widget, GtkDirectionType arg1); - - ui::OwnedWidgetGtk handler_; - - // Buffer to store the match results. - EditCommands edit_commands_; -}; - -} // namespace content - -#endif // CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ diff --git a/content/browser/renderer_host/gtk_key_bindings_handler_unittest.cc b/content/browser/renderer_host/gtk_key_bindings_handler_unittest.cc deleted file mode 100644 index fed67d5..0000000 --- a/content/browser/renderer_host/gtk_key_bindings_handler_unittest.cc +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/gtk_key_bindings_handler.h" - -#include <gdk/gdkkeysyms.h> -#include <string> -#include <utility> -#include <vector> - -#include "base/basictypes.h" -#include "base/file_util.h" -#include "base/logging.h" -#include "base/path_service.h" -#include "base/strings/string_util.h" -#include "content/common/edit_command.h" -#include "content/public/browser/native_web_keyboard_event.h" -#include "content/public/common/content_paths.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace content { - -class GtkKeyBindingsHandlerTest : public testing::Test { - protected: - struct EditCommand { - const char* name; - const char* value; - }; - - GtkKeyBindingsHandlerTest() - : window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)), - handler_(NULL) { - base::FilePath gtkrc; - PathService::Get(DIR_TEST_DATA, >krc); - gtkrc = gtkrc.AppendASCII("gtk_key_bindings_test_gtkrc"); - EXPECT_TRUE(base::PathExists(gtkrc)); - - gtk_rc_parse(gtkrc.value().c_str()); - - GtkWidget* fixed = gtk_fixed_new(); - handler_ = new GtkKeyBindingsHandler(fixed); - gtk_container_add(GTK_CONTAINER(window_), fixed); - gtk_widget_show(fixed); - gtk_widget_show(window_); - } - virtual ~GtkKeyBindingsHandlerTest() { - gtk_widget_destroy(window_); - delete handler_; - } - - NativeWebKeyboardEvent NewNativeWebKeyboardEvent(guint keyval, guint state) { - GdkKeymap* keymap = - gdk_keymap_get_for_display(gtk_widget_get_display(window_)); - - GdkKeymapKey *keys = NULL; - gint n_keys = 0; - if (gdk_keymap_get_entries_for_keyval(keymap, keyval, &keys, &n_keys)) { - GdkEventKey event; - event.type = GDK_KEY_PRESS; - event.window = NULL; - event.send_event = 0; - event.time = 0; - event.state = state; - event.keyval = keyval; - event.length = 0; - event.string = NULL; - event.hardware_keycode = keys[0].keycode; - event.group = keys[0].group; - event.is_modifier = 0; - g_free(keys); - return NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(&event)); - } - LOG(ERROR) << "Failed to create key event for keyval:" << keyval; - return NativeWebKeyboardEvent(); - } - - void TestKeyBinding(const NativeWebKeyboardEvent& event, - const EditCommand expected_result[], - size_t size) { - EditCommands result; - ASSERT_TRUE(handler_->Match(event, &result)); - ASSERT_EQ(size, result.size()); - for (size_t i = 0; i < size; ++i) { - ASSERT_STREQ(expected_result[i].name, result[i].name.c_str()); - ASSERT_STREQ(expected_result[i].value, result[i].value.c_str()); - } - } - - protected: - GtkWidget* window_; - GtkKeyBindingsHandler* handler_; -}; - -TEST_F(GtkKeyBindingsHandlerTest, MoveCursor) { - static const EditCommand kEditCommands[] = { - // "move-cursor" (logical-positions, -2, 0) - { "MoveBackward", "" }, - { "MoveBackward", "" }, - // "move-cursor" (logical-positions, 2, 0) - { "MoveForward", "" }, - { "MoveForward", "" }, - // "move-cursor" (visual-positions, -1, 1) - { "MoveLeftAndModifySelection", "" }, - // "move-cursor" (visual-positions, 1, 1) - { "MoveRightAndModifySelection", "" }, - // "move-cursor" (words, -1, 0) - { "MoveWordLeft", "" }, - // "move-cursor" (words, 1, 0) - { "MoveWordRight", "" }, - // "move-cursor" (display-lines, -1, 0) - { "MoveUp", "" }, - // "move-cursor" (display-lines, 1, 0) - { "MoveDown", "" }, - // "move-cursor" (display-line-ends, -1, 0) - { "MoveToBeginningOfLine", "" }, - // "move-cursor" (display-line-ends, 1, 0) - { "MoveToEndOfLine", "" }, - // "move-cursor" (paragraph-ends, -1, 0) - { "MoveToBeginningOfParagraph", "" }, - // "move-cursor" (paragraph-ends, 1, 0) - { "MoveToEndOfParagraph", "" }, - // "move-cursor" (pages, -1, 0) - { "MovePageUp", "" }, - // "move-cursor" (pages, 1, 0) - { "MovePageDown", "" }, - // "move-cursor" (buffer-ends, -1, 0) - { "MoveToBeginningOfDocument", "" }, - // "move-cursor" (buffer-ends, 1, 0) - { "MoveToEndOfDocument", "" } - }; - - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_1, GDK_CONTROL_MASK), - kEditCommands, arraysize(kEditCommands)); -} - -TEST_F(GtkKeyBindingsHandlerTest, DeleteFromCursor) { - static const EditCommand kEditCommands[] = { - // "delete-from-cursor" (chars, -2) - { "DeleteBackward", "" }, - { "DeleteBackward", "" }, - // "delete-from-cursor" (chars, 2) - { "DeleteForward", "" }, - { "DeleteForward", "" }, - // "delete-from-cursor" (word-ends, -1) - { "DeleteWordBackward", "" }, - // "delete-from-cursor" (word-ends, 1) - { "DeleteWordForward", "" }, - // "delete-from-cursor" (words, -1) - { "MoveWordBackward", "" }, - { "DeleteWordForward", "" }, - // "delete-from-cursor" (words, 1) - { "MoveWordForward", "" }, - { "DeleteWordBackward", "" }, - // "delete-from-cursor" (display-lines, -1) - { "MoveToBeginningOfLine", "" }, - { "DeleteToEndOfLine", "" }, - // "delete-from-cursor" (display-lines, 1) - { "MoveToBeginningOfLine", "" }, - { "DeleteToEndOfLine", "" }, - // "delete-from-cursor" (display-line-ends, -1) - { "DeleteToBeginningOfLine", "" }, - // "delete-from-cursor" (display-line-ends, 1) - { "DeleteToEndOfLine", "" }, - // "delete-from-cursor" (paragraph-ends, -1) - { "DeleteToBeginningOfParagraph", "" }, - // "delete-from-cursor" (paragraph-ends, 1) - { "DeleteToEndOfParagraph", "" }, - // "delete-from-cursor" (paragraphs, -1) - { "MoveToBeginningOfParagraph", "" }, - { "DeleteToEndOfParagraph", "" }, - // "delete-from-cursor" (paragraphs, 1) - { "MoveToBeginningOfParagraph", "" }, - { "DeleteToEndOfParagraph", "" }, - }; - - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_2, GDK_CONTROL_MASK), - kEditCommands, arraysize(kEditCommands)); -} - -TEST_F(GtkKeyBindingsHandlerTest, OtherActions) { - static const EditCommand kBackspace[] = { - { "DeleteBackward", "" } - }; - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_3, GDK_CONTROL_MASK), - kBackspace, arraysize(kBackspace)); - - static const EditCommand kCopyClipboard[] = { - { "Copy", "" } - }; - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_4, GDK_CONTROL_MASK), - kCopyClipboard, arraysize(kCopyClipboard)); - - static const EditCommand kCutClipboard[] = { - { "Cut", "" } - }; - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_5, GDK_CONTROL_MASK), - kCutClipboard, arraysize(kCutClipboard)); - - static const EditCommand kInsertAtCursor[] = { - { "InsertText", "hello" } - }; - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_6, GDK_CONTROL_MASK), - kInsertAtCursor, arraysize(kInsertAtCursor)); - - static const EditCommand kPasteClipboard[] = { - { "Paste", "" } - }; - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_7, GDK_CONTROL_MASK), - kPasteClipboard, arraysize(kPasteClipboard)); - - static const EditCommand kSelectAll[] = { - { "Unselect", "" }, - { "SelectAll", "" } - }; - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_8, GDK_CONTROL_MASK), - kSelectAll, arraysize(kSelectAll)); - - static const EditCommand kSetAnchor[] = { - { "SetMark", "" } - }; - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_9, GDK_CONTROL_MASK), - kSetAnchor, arraysize(kSetAnchor)); -} - -} // namespace content diff --git a/content/browser/renderer_host/gtk_plugin_container.cc b/content/browser/renderer_host/gtk_plugin_container.cc deleted file mode 100644 index 0b83f2e..0000000 --- a/content/browser/renderer_host/gtk_plugin_container.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/gtk_plugin_container.h" - -#include <gtk/gtk.h> - -#include "base/basictypes.h" - -namespace content { - -namespace { - -// NOTE: This class doesn't have constructors/destructors, it is created -// through GLib's object management. -class GtkPluginContainer : public GtkSocket { - public: - // Sets the requested size of the widget. - void set_size(int width, int height) { - width_ = width; - height_ = height; - } - - // Casts a widget into a GtkPluginContainer, after checking the type. - template <class T> - static GtkPluginContainer *CastChecked(T *instance) { - return G_TYPE_CHECK_INSTANCE_CAST(instance, GetType(), GtkPluginContainer); - } - - // Create and register our custom container type with GTK. - static GType GetType() { - static GType type = 0; // We only want to register our type once. - if (!type) { - static const GTypeInfo info = { - sizeof(GtkSocketClass), - NULL, NULL, - static_cast<GClassInitFunc>(&ClassInit), - NULL, NULL, - sizeof(GtkPluginContainer), - 0, &InstanceInit, - }; - type = g_type_register_static(GTK_TYPE_SOCKET, - "GtkPluginContainer", - &info, - static_cast<GTypeFlags>(0)); - } - return type; - } - - // Implementation of the class initializer. - static void ClassInit(gpointer klass, gpointer class_data_unusued) { - GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(klass); - widget_class->size_request = &HandleSizeRequest; - } - - // Implementation of the instance initializer (constructor). - static void InstanceInit(GTypeInstance *instance, gpointer klass) { - GtkPluginContainer *container = CastChecked(instance); - container->set_size(0, 0); - } - - // Report our allocation size during size requisition. - static void HandleSizeRequest(GtkWidget* widget, - GtkRequisition* requisition) { - GtkPluginContainer *container = CastChecked(widget); - requisition->width = container->width_; - requisition->height = container->height_; - } - - int width_; - int height_; - DISALLOW_IMPLICIT_CONSTRUCTORS(GtkPluginContainer); -}; - -} // namespace - -// Create a new instance of our GTK widget object. -GtkWidget* gtk_plugin_container_new() { - return GTK_WIDGET(g_object_new(GtkPluginContainer::GetType(), NULL)); -} - -void gtk_plugin_container_set_size(GtkWidget *widget, int width, int height) { - GtkPluginContainer::CastChecked(widget)->set_size(width, height); - // Signal the parent that the size request has changed. - gtk_widget_queue_resize_no_redraw(widget); -} - -} // namespace content diff --git a/content/browser/renderer_host/gtk_plugin_container.h b/content/browser/renderer_host/gtk_plugin_container.h deleted file mode 100644 index 1713cd4..0000000 --- a/content/browser/renderer_host/gtk_plugin_container.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_GTK_PLUGIN_CONTAINER_H_ -#define CONTENT_BROWSER_RENDERER_HOST_GTK_PLUGIN_CONTAINER_H_ - -// Windowed plugins are embedded via XEmbed, which is implemented by -// GtkPlug/GtkSocket. But we want to control sizing and positioning -// directly, so we need a subclass of GtkSocket that sidesteps the -// size_request handler. -// -// The custom size_request handler just reports the size set by -// gtk_plugin_container_set_size. - -typedef struct _GtkWidget GtkWidget; - -namespace content { - -// Return a new GtkPluginContainer. -// Intentionally GTK-style here since we're creating a custom GTK widget. -// This is a GtkSocket subclass; see its documentation for available methods. -GtkWidget* gtk_plugin_container_new(); - -// Sets the size of the GtkPluginContainer. -void gtk_plugin_container_set_size(GtkWidget *widget, int width, int height); - -} // namespace content - -#endif // CONTENT_BROWSER_RENDERER_HOST_GTK_PLUGIN_CONTAINER_H_ diff --git a/content/browser/renderer_host/gtk_plugin_container_manager.cc b/content/browser/renderer_host/gtk_plugin_container_manager.cc deleted file mode 100644 index 8614911..0000000 --- a/content/browser/renderer_host/gtk_plugin_container_manager.cc +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/gtk_plugin_container_manager.h" - -#include <gtk/gtk.h> - -#include "base/logging.h" -#include "content/browser/renderer_host/gtk_plugin_container.h" -#include "content/common/webplugin_geometry.h" -#include "ui/gfx/gtk_compat.h" -#include "ui/gfx/gtk_util.h" - -namespace content { - -GtkPluginContainerManager::GtkPluginContainerManager() : host_widget_(NULL) {} - -GtkPluginContainerManager::~GtkPluginContainerManager() {} - -GtkWidget* GtkPluginContainerManager::CreatePluginContainer( - gfx::PluginWindowHandle id) { - DCHECK(host_widget_); - GtkWidget *widget = gtk_plugin_container_new(); - plugin_window_to_widget_map_.insert(std::make_pair(id, widget)); - - // The Realize callback is responsible for adding the plug into the socket. - // The reason is 2-fold: - // - the plug can't be added until the socket is realized, but this may not - // happen until the socket is attached to a top-level window, which isn't the - // case for background tabs. - // - when dragging tabs, the socket gets unrealized, which breaks the XEMBED - // connection. We need to make it again when the tab is reattached, and the - // socket gets realized again. - // - // Note, the RealizeCallback relies on the plugin_window_to_widget_map_ to - // have the mapping. - g_signal_connect(widget, "realize", - G_CALLBACK(RealizeCallback), this); - - // Don't destroy the widget when the plug is removed. - g_signal_connect(widget, "plug-removed", - G_CALLBACK(gtk_true), NULL); - - gtk_container_add(GTK_CONTAINER(host_widget_), widget); - gtk_widget_show(widget); - - return widget; -} - -void GtkPluginContainerManager::DestroyPluginContainer( - gfx::PluginWindowHandle id) { - DCHECK(host_widget_); - GtkWidget* widget = MapIDToWidget(id); - if (widget) - gtk_widget_destroy(widget); - - plugin_window_to_widget_map_.erase(id); -} - -void GtkPluginContainerManager::MovePluginContainer( - const WebPluginGeometry& move) { - DCHECK(host_widget_); - GtkWidget *widget = MapIDToWidget(move.window); - if (!widget) - return; - - DCHECK(gtk_widget_get_has_window(widget)); - - if (!move.visible) { - gtk_widget_hide(widget); - return; - } - - gtk_widget_show(widget); - - if (!move.rects_valid) - return; - - // TODO(piman): if the widget hasn't been realized (e.g. the tab has been - // torn off and the parent gtk widget has been detached from the hierarchy), - // we lose the cutout information. - if (gtk_widget_get_realized(widget)) { - GdkRectangle clip_rect = move.clip_rect.ToGdkRectangle(); - GdkRegion* clip_region = gdk_region_rectangle(&clip_rect); - gfx::SubtractRectanglesFromRegion(clip_region, move.cutout_rects); - gdk_window_shape_combine_region(gtk_widget_get_window(widget), - clip_region, 0, 0); - gdk_region_destroy(clip_region); - } - - // Update the window position. Resizing is handled by WebPluginDelegate. - // TODO(deanm): Verify that we only need to move and not resize. - // TODO(evanm): we should cache the last shape and position and skip all - // of this business in the common case where nothing has changed. - int current_x, current_y; - - // Until the above TODO is resolved, we can grab the last position - // off of the GtkFixed with a bit of hackery. - GValue value = {0}; - g_value_init(&value, G_TYPE_INT); - gtk_container_child_get_property(GTK_CONTAINER(host_widget_), widget, - "x", &value); - current_x = g_value_get_int(&value); - gtk_container_child_get_property(GTK_CONTAINER(host_widget_), widget, - "y", &value); - current_y = g_value_get_int(&value); - g_value_unset(&value); - - if (move.window_rect.x() != current_x || - move.window_rect.y() != current_y) { - // Calling gtk_fixed_move unnecessarily is a no-no, as it causes the - // parent window to repaint! - gtk_fixed_move(GTK_FIXED(host_widget_), - widget, - move.window_rect.x(), - move.window_rect.y()); - } - - gtk_plugin_container_set_size(widget, - move.window_rect.width(), - move.window_rect.height()); -} - -GtkWidget* GtkPluginContainerManager::MapIDToWidget( - gfx::PluginWindowHandle id) { - PluginWindowToWidgetMap::const_iterator i = - plugin_window_to_widget_map_.find(id); - if (i != plugin_window_to_widget_map_.end()) - return i->second; - - LOG(ERROR) << "Request for widget host for unknown window id " << id; - - return NULL; -} - -gfx::PluginWindowHandle GtkPluginContainerManager::MapWidgetToID( - GtkWidget* widget) { - for (PluginWindowToWidgetMap::const_iterator i = - plugin_window_to_widget_map_.begin(); - i != plugin_window_to_widget_map_.end(); ++i) { - if (i->second == widget) - return i->first; - } - - LOG(ERROR) << "Request for id for unknown widget"; - return 0; -} - -// static -void GtkPluginContainerManager::RealizeCallback(GtkWidget* widget, - void* user_data) { - GtkPluginContainerManager* plugin_container_manager = - static_cast<GtkPluginContainerManager*>(user_data); - - gfx::PluginWindowHandle id = plugin_container_manager->MapWidgetToID(widget); - if (id) - gtk_socket_add_id(GTK_SOCKET(widget), id); -} - -} // namespace content diff --git a/content/browser/renderer_host/gtk_plugin_container_manager.h b/content/browser/renderer_host/gtk_plugin_container_manager.h deleted file mode 100644 index bd0e7c1..0000000 --- a/content/browser/renderer_host/gtk_plugin_container_manager.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_GTK_PLUGIN_CONTAINER_MANAGER_H_ -#define CONTENT_BROWSER_RENDERER_HOST_GTK_PLUGIN_CONTAINER_MANAGER_H_ - -#include <gtk/gtk.h> -#include <map> - -#include "ui/gfx/native_widget_types.h" - -typedef struct _GtkWidget GtkWidget; - -namespace content { -struct WebPluginGeometry; - -// Helper class that creates and manages plugin containers (GtkSocket). -class GtkPluginContainerManager { - public: - GtkPluginContainerManager(); - ~GtkPluginContainerManager(); - - // Sets the widget that will host the plugin containers. Must be a GtkFixed. - void set_host_widget(GtkWidget *widget) { host_widget_ = widget; } - - // Creates a new plugin container, for a given plugin XID. - GtkWidget* CreatePluginContainer(gfx::PluginWindowHandle id); - - // Destroys a plugin container, given the plugin XID. - void DestroyPluginContainer(gfx::PluginWindowHandle id); - - // Takes an update from WebKit about a plugin's position and side and moves - // the plugin accordingly. - void MovePluginContainer(const WebPluginGeometry& move); - - private: - // Maps a plugin XID to the corresponding container widget. - GtkWidget* MapIDToWidget(gfx::PluginWindowHandle id); - - // Maps a container widget to the corresponding plugin XID. - gfx::PluginWindowHandle MapWidgetToID(GtkWidget* widget); - - // Callback for when the plugin container gets realized, at which point it - // plugs the plugin XID. - static void RealizeCallback(GtkWidget *widget, void *user_data); - - // Parent of the plugin containers. - GtkWidget* host_widget_; - - // A map that associates plugin containers to the plugin XID. - typedef std::map<gfx::PluginWindowHandle, GtkWidget*> PluginWindowToWidgetMap; - PluginWindowToWidgetMap plugin_window_to_widget_map_; -}; - -} // namespace content - -#endif // CONTENT_BROWSER_RENDERER_HOST_GTK_PLUGIN_CONTAINER_MANAGER_H_ diff --git a/content/browser/renderer_host/gtk_window_utils.cc b/content/browser/renderer_host/gtk_window_utils.cc deleted file mode 100644 index 240c59d..0000000 --- a/content/browser/renderer_host/gtk_window_utils.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/gtk_window_utils.h" - -#include <X11/Xlib.h> -#include <gdk/gdkx.h> -#include <gtk/gtk.h> - -#include <vector> - -#include "third_party/WebKit/public/platform/WebScreenInfo.h" -#include "ui/base/x/x11_util.h" -#include "ui/gfx/gtk_compat.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/x/x11_types.h" - -namespace content { - -namespace { - -// Returns the region of |window|'s desktop that isn't occupied by docks or -// panels. Returns an empty rect on failure. -gfx::Rect GetWorkArea(Window window) { - Window root = ui::GetX11RootWindow(); - int desktop = -1; - if (!ui::GetIntProperty(window, "_NET_WM_DESKTOP", &desktop)) { - // Hack for ion3: _NET_WM_DESKTOP doesn't get set on individual windows, but - // _NET_CURRENT_DESKTOP and _NET_WORKAREA do get set. - ui::GetIntProperty(root, "_NET_CURRENT_DESKTOP", &desktop); - } - if (desktop < 0) - return gfx::Rect(); - - std::vector<int> property; - if (!ui::GetIntArrayProperty(root, "_NET_WORKAREA", &property)) - return gfx::Rect(); - - size_t start_index = 4 * desktop; - if (property.size() < start_index + 4) - return gfx::Rect(); - - return gfx::Rect(property[start_index], property[start_index + 1], - property[start_index + 2], property[start_index + 3]); -} - -blink::WebScreenInfo GetScreenInfo(XDisplay* display, int screenNumber) { - // XDisplayWidth() and XDisplayHeight() return cached values. To ensure that - // we return the correct dimensions after the screen is resized, query the - // root window's geometry each time. - Window root = RootWindow(display, screenNumber); - Window root_ret; - int x, y; - unsigned int width, height, border, depth; - XGetGeometry( - display, root, &root_ret, &x, &y, &width, &height, &border, &depth); - - blink::WebScreenInfo results; - results.depthPerComponent = 8; // Assume 8bpp, which is usually right. - results.depth = depth; - results.isMonochrome = depth == 1; - results.rect = blink::WebRect(x, y, width, height); - results.availableRect = results.rect; - return results; -} - -} // namespace - -void GetScreenInfoFromNativeWindow( - GdkWindow* gdk_window, blink::WebScreenInfo* results) { - GdkScreen* screen = gdk_window_get_screen(gdk_window); - *results = GetScreenInfo(gdk_x11_drawable_get_xdisplay(gdk_window), - gdk_x11_screen_get_screen_number(screen)); - - int monitor_number = gdk_screen_get_monitor_at_window(screen, gdk_window); - GdkRectangle monitor_rect; - gdk_screen_get_monitor_geometry(screen, monitor_number, &monitor_rect); - results->rect = blink::WebRect(monitor_rect.x, monitor_rect.y, - monitor_rect.width, monitor_rect.height); - - gfx::Rect available_rect = results->rect; - gfx::Rect work_area = GetWorkArea(GDK_WINDOW_XID(gdk_window)); - if (!work_area.IsEmpty()) - available_rect.Intersect(work_area); - results->availableRect = available_rect; -} - -} // namespace content diff --git a/content/browser/renderer_host/gtk_window_utils.h b/content/browser/renderer_host/gtk_window_utils.h deleted file mode 100644 index 93f1d68..0000000 --- a/content/browser/renderer_host/gtk_window_utils.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_GTK_WINDOW_UTILS_H_ -#define CONTENT_BROWSER_RENDERER_HOST_GTK_WINDOW_UTILS_H_ - -#include "content/common/content_export.h" - -typedef struct _GdkDrawable GdkWindow; - -namespace blink { -struct WebScreenInfo; -} - -namespace content { - -CONTENT_EXPORT void GetScreenInfoFromNativeWindow( - GdkWindow* gdk_window, blink::WebScreenInfo* results); - -} // namespace content - -#endif // CONTENT_BROWSER_RENDERER_HOST_GTK_WINDOW_UTILS_H_ diff --git a/content/browser/renderer_host/input/web_input_event_builders_gtk.cc b/content/browser/renderer_host/input/web_input_event_builders_gtk.cc deleted file mode 100644 index d5c2bde..0000000 --- a/content/browser/renderer_host/input/web_input_event_builders_gtk.cc +++ /dev/null @@ -1,603 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/input/web_input_event_builders_gtk.h" - -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "base/logging.h" -#include "content/browser/renderer_host/input/web_input_event_util_posix.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -#include "ui/events/keycodes/keyboard_code_conversion_gtk.h" - -using blink::WebInputEvent; -using blink::WebMouseEvent; -using blink::WebMouseWheelEvent; -using blink::WebKeyboardEvent; - -namespace { - -// For click count tracking. -static int num_clicks = 0; -static GdkWindow* last_click_event_window = 0; -static gint last_click_time = 0; -static gint last_click_x = 0; -static gint last_click_y = 0; -static WebMouseEvent::Button last_click_button = WebMouseEvent::ButtonNone; - -bool ShouldForgetPreviousClick(GdkWindow* window, gint time, gint x, gint y) { - static GtkSettings* settings = gtk_settings_get_default(); - - if (window != last_click_event_window) - return true; - - gint double_click_time = 250; - gint double_click_distance = 5; - g_object_get(G_OBJECT(settings), - "gtk-double-click-time", - &double_click_time, - "gtk-double-click-distance", - &double_click_distance, - NULL); - return (time - last_click_time) > double_click_time || - std::abs(x - last_click_x) > double_click_distance || - std::abs(y - last_click_y) > double_click_distance; -} - -void ResetClickCountState() { - num_clicks = 0; - last_click_event_window = 0; - last_click_time = 0; - last_click_x = 0; - last_click_y = 0; - last_click_button = blink::WebMouseEvent::ButtonNone; -} - -bool IsKeyPadKeyval(guint keyval) { - // Keypad keyvals all fall into one range. - return keyval >= GDK_KP_Space && keyval <= GDK_KP_9; -} - -double GdkEventTimeToWebEventTime(guint32 time) { - // Convert from time in ms to time in sec. - return time / 1000.0; -} - -int GdkStateToWebEventModifiers(guint state) { - int modifiers = 0; - if (state & GDK_SHIFT_MASK) - modifiers |= WebInputEvent::ShiftKey; - if (state & GDK_CONTROL_MASK) - modifiers |= WebInputEvent::ControlKey; - if (state & GDK_MOD1_MASK) - modifiers |= WebInputEvent::AltKey; - if (state & GDK_META_MASK) - modifiers |= WebInputEvent::MetaKey; - if (state & GDK_BUTTON1_MASK) - modifiers |= WebInputEvent::LeftButtonDown; - if (state & GDK_BUTTON2_MASK) - modifiers |= WebInputEvent::MiddleButtonDown; - if (state & GDK_BUTTON3_MASK) - modifiers |= WebInputEvent::RightButtonDown; - if (state & GDK_LOCK_MASK) - modifiers |= WebInputEvent::CapsLockOn; - if (state & GDK_MOD2_MASK) - modifiers |= WebInputEvent::NumLockOn; - return modifiers; -} - -ui::KeyboardCode GdkEventToWindowsKeyCode(const GdkEventKey* event) { - static const unsigned int kHardwareCodeToGDKKeyval[] = { - 0, // 0x00: - 0, // 0x01: - 0, // 0x02: - 0, // 0x03: - 0, // 0x04: - 0, // 0x05: - 0, // 0x06: - 0, // 0x07: - 0, // 0x08: - 0, // 0x09: GDK_Escape - GDK_1, // 0x0A: GDK_1 - GDK_2, // 0x0B: GDK_2 - GDK_3, // 0x0C: GDK_3 - GDK_4, // 0x0D: GDK_4 - GDK_5, // 0x0E: GDK_5 - GDK_6, // 0x0F: GDK_6 - GDK_7, // 0x10: GDK_7 - GDK_8, // 0x11: GDK_8 - GDK_9, // 0x12: GDK_9 - GDK_0, // 0x13: GDK_0 - GDK_minus, // 0x14: GDK_minus - GDK_equal, // 0x15: GDK_equal - 0, // 0x16: GDK_BackSpace - 0, // 0x17: GDK_Tab - GDK_q, // 0x18: GDK_q - GDK_w, // 0x19: GDK_w - GDK_e, // 0x1A: GDK_e - GDK_r, // 0x1B: GDK_r - GDK_t, // 0x1C: GDK_t - GDK_y, // 0x1D: GDK_y - GDK_u, // 0x1E: GDK_u - GDK_i, // 0x1F: GDK_i - GDK_o, // 0x20: GDK_o - GDK_p, // 0x21: GDK_p - GDK_bracketleft, // 0x22: GDK_bracketleft - GDK_bracketright, // 0x23: GDK_bracketright - 0, // 0x24: GDK_Return - 0, // 0x25: GDK_Control_L - GDK_a, // 0x26: GDK_a - GDK_s, // 0x27: GDK_s - GDK_d, // 0x28: GDK_d - GDK_f, // 0x29: GDK_f - GDK_g, // 0x2A: GDK_g - GDK_h, // 0x2B: GDK_h - GDK_j, // 0x2C: GDK_j - GDK_k, // 0x2D: GDK_k - GDK_l, // 0x2E: GDK_l - GDK_semicolon, // 0x2F: GDK_semicolon - GDK_apostrophe, // 0x30: GDK_apostrophe - GDK_grave, // 0x31: GDK_grave - 0, // 0x32: GDK_Shift_L - GDK_backslash, // 0x33: GDK_backslash - GDK_z, // 0x34: GDK_z - GDK_x, // 0x35: GDK_x - GDK_c, // 0x36: GDK_c - GDK_v, // 0x37: GDK_v - GDK_b, // 0x38: GDK_b - GDK_n, // 0x39: GDK_n - GDK_m, // 0x3A: GDK_m - GDK_comma, // 0x3B: GDK_comma - GDK_period, // 0x3C: GDK_period - GDK_slash, // 0x3D: GDK_slash - 0, // 0x3E: GDK_Shift_R - 0, // 0x3F: - 0, // 0x40: - 0, // 0x41: - 0, // 0x42: - 0, // 0x43: - 0, // 0x44: - 0, // 0x45: - 0, // 0x46: - 0, // 0x47: - 0, // 0x48: - 0, // 0x49: - 0, // 0x4A: - 0, // 0x4B: - 0, // 0x4C: - 0, // 0x4D: - 0, // 0x4E: - 0, // 0x4F: - 0, // 0x50: - 0, // 0x51: - 0, // 0x52: - 0, // 0x53: - 0, // 0x54: - 0, // 0x55: - 0, // 0x56: - 0, // 0x57: - 0, // 0x58: - 0, // 0x59: - 0, // 0x5A: - 0, // 0x5B: - 0, // 0x5C: - 0, // 0x5D: - 0, // 0x5E: - 0, // 0x5F: - 0, // 0x60: - 0, // 0x61: - 0, // 0x62: - 0, // 0x63: - 0, // 0x64: - 0, // 0x65: - 0, // 0x66: - 0, // 0x67: - 0, // 0x68: - 0, // 0x69: - 0, // 0x6A: - 0, // 0x6B: - 0, // 0x6C: - 0, // 0x6D: - 0, // 0x6E: - 0, // 0x6F: - 0, // 0x70: - 0, // 0x71: - 0, // 0x72: - GDK_Super_L, // 0x73: GDK_Super_L - GDK_Super_R, // 0x74: GDK_Super_R - }; - - // |windows_key_code| has to include a valid virtual-key code even when we - // use non-US layouts, e.g. even when we type an 'A' key of a US keyboard - // on the Hebrew layout, |windows_key_code| should be VK_A. - // On the other hand, |event->keyval| value depends on the current - // GdkKeymap object, i.e. when we type an 'A' key of a US keyboard on - // the Hebrew layout, |event->keyval| becomes GDK_hebrew_shin and this - // ui::WindowsKeyCodeForGdkKeyCode() call returns 0. - // To improve compatibilty with Windows, we use |event->hardware_keycode| - // for retrieving its Windows key-code for the keys when the - // WebCore::windows_key_codeForEvent() call returns 0. - // We shouldn't use |event->hardware_keycode| for keys that GdkKeymap - // objects cannot change because |event->hardware_keycode| doesn't change - // even when we change the layout options, e.g. when we swap a control - // key and a caps-lock key, GTK doesn't swap their - // |event->hardware_keycode| values but swap their |event->keyval| values. - ui::KeyboardCode windows_key_code = - ui::WindowsKeyCodeForGdkKeyCode(event->keyval); - if (windows_key_code) - return windows_key_code; - - if (event->hardware_keycode < arraysize(kHardwareCodeToGDKKeyval)) { - int keyval = kHardwareCodeToGDKKeyval[event->hardware_keycode]; - if (keyval) - return ui::WindowsKeyCodeForGdkKeyCode(keyval); - } - - // This key is one that keyboard-layout drivers cannot change. - // Use |event->keyval| to retrieve its |windows_key_code| value. - return ui::WindowsKeyCodeForGdkKeyCode(event->keyval); -} - -// Normalizes event->state to make it Windows/Mac compatible. Since the way -// of setting modifier mask on X is very different than Windows/Mac as shown -// in http://crbug.com/127142#c8, the normalization is necessary. -guint NormalizeEventState(const GdkEventKey* event) { - guint mask = 0; - switch (GdkEventToWindowsKeyCode(event)) { - case ui::VKEY_CONTROL: - case ui::VKEY_LCONTROL: - case ui::VKEY_RCONTROL: - mask = GDK_CONTROL_MASK; - break; - case ui::VKEY_SHIFT: - case ui::VKEY_LSHIFT: - case ui::VKEY_RSHIFT: - mask = GDK_SHIFT_MASK; - break; - case ui::VKEY_MENU: - case ui::VKEY_LMENU: - case ui::VKEY_RMENU: - mask = GDK_MOD1_MASK; - break; - case ui::VKEY_CAPITAL: - mask = GDK_LOCK_MASK; - break; - default: - return event->state; - } - if (event->type == GDK_KEY_PRESS) - return event->state | mask; - return event->state & ~mask; -} - -// Gets the corresponding control character of a specified key code. See: -// http://en.wikipedia.org/wiki/Control_characters -// We emulate Windows behavior here. -int GetControlCharacter(ui::KeyboardCode windows_key_code, bool shift) { - if (windows_key_code >= ui::VKEY_A && windows_key_code <= ui::VKEY_Z) { - // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A - return windows_key_code - ui::VKEY_A + 1; - } - if (shift) { - // following graphics chars require shift key to input. - switch (windows_key_code) { - // ctrl-@ maps to \x00 (Null byte) - case ui::VKEY_2: - return 0; - // ctrl-^ maps to \x1E (Record separator, Information separator two) - case ui::VKEY_6: - return 0x1E; - // ctrl-_ maps to \x1F (Unit separator, Information separator one) - case ui::VKEY_OEM_MINUS: - return 0x1F; - // Returns 0 for all other keys to avoid inputting unexpected chars. - default: - return 0; - } - } else { - switch (windows_key_code) { - // ctrl-[ maps to \x1B (Escape) - case ui::VKEY_OEM_4: - return 0x1B; - // ctrl-\ maps to \x1C (File separator, Information separator four) - case ui::VKEY_OEM_5: - return 0x1C; - // ctrl-] maps to \x1D (Group separator, Information separator three) - case ui::VKEY_OEM_6: - return 0x1D; - // ctrl-Enter maps to \x0A (Line feed) - case ui::VKEY_RETURN: - return 0x0A; - // Returns 0 for all other keys to avoid inputting unexpected chars. - default: - return 0; - } - } -} - -} // namespace - -namespace content { - -// WebKeyboardEvent ----------------------------------------------------------- - -WebKeyboardEvent WebKeyboardEventBuilder::Build(const GdkEventKey* event) { - WebKeyboardEvent result; - - result.timeStampSeconds = GdkEventTimeToWebEventTime(event->time); - result.modifiers = GdkStateToWebEventModifiers(NormalizeEventState(event)); - - switch (event->type) { - case GDK_KEY_RELEASE: - result.type = WebInputEvent::KeyUp; - break; - case GDK_KEY_PRESS: - result.type = WebInputEvent::RawKeyDown; - break; - default: - NOTREACHED(); - } - - // According to MSDN: - // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx - // Key events with Alt modifier and F10 are system key events. - // We just emulate this behavior. It's necessary to prevent webkit from - // processing keypress event generated by alt-d, etc. - // F10 is not special on Linux, so don't treat it as system key. - if (result.modifiers & WebInputEvent::AltKey) - result.isSystemKey = true; - - // The key code tells us which physical key was pressed (for example, the - // A key went down or up). It does not determine whether A should be lower - // or upper case. This is what text does, which should be the keyval. - ui::KeyboardCode windows_key_code = GdkEventToWindowsKeyCode(event); - result.windowsKeyCode = GetWindowsKeyCodeWithoutLocation(windows_key_code); - result.modifiers |= GetLocationModifiersFromWindowsKeyCode(windows_key_code); - result.nativeKeyCode = event->hardware_keycode; - - if (result.windowsKeyCode == ui::VKEY_RETURN) { - // We need to treat the enter key as a key press of character \r. This - // is apparently just how webkit handles it and what it expects. - result.unmodifiedText[0] = '\r'; - } else { - // FIXME: fix for non BMP chars - result.unmodifiedText[0] = - static_cast<int>(gdk_keyval_to_unicode(event->keyval)); - } - - // If ctrl key is pressed down, then control character shall be input. - if (result.modifiers & WebInputEvent::ControlKey) { - result.text[0] = - GetControlCharacter(ui::KeyboardCode(result.windowsKeyCode), - result.modifiers & WebInputEvent::ShiftKey); - } else { - result.text[0] = result.unmodifiedText[0]; - } - - result.setKeyIdentifierFromWindowsKeyCode(); - - // FIXME: Do we need to set IsAutoRepeat? - if (IsKeyPadKeyval(event->keyval)) - result.modifiers |= WebInputEvent::IsKeyPad; - - return result; -} - -WebKeyboardEvent WebKeyboardEventBuilder::Build(wchar_t character, - int state, - double timeStampSeconds) { - // keyboardEvent(const GdkEventKey*) depends on the GdkEventKey object and - // it is hard to use/ it from signal handlers which don't use GdkEventKey - // objects (e.g. GtkIMContext signal handlers.) For such handlers, this - // function creates a WebInputEvent::Char event without using a - // GdkEventKey object. - WebKeyboardEvent result; - result.type = blink::WebInputEvent::Char; - result.timeStampSeconds = timeStampSeconds; - result.modifiers = GdkStateToWebEventModifiers(state); - result.windowsKeyCode = character; - result.nativeKeyCode = character; - result.text[0] = character; - result.unmodifiedText[0] = character; - - // According to MSDN: - // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx - // Key events with Alt modifier and F10 are system key events. - // We just emulate this behavior. It's necessary to prevent webkit from - // processing keypress event generated by alt-d, etc. - // F10 is not special on Linux, so don't treat it as system key. - if (result.modifiers & WebInputEvent::AltKey) - result.isSystemKey = true; - - return result; -} - -// WebMouseEvent -------------------------------------------------------------- - -WebMouseEvent WebMouseEventBuilder::Build(const GdkEventButton* event) { - WebMouseEvent result; - - result.timeStampSeconds = GdkEventTimeToWebEventTime(event->time); - - result.modifiers = GdkStateToWebEventModifiers(event->state); - result.x = static_cast<int>(event->x); - result.y = static_cast<int>(event->y); - result.windowX = result.x; - result.windowY = result.y; - result.globalX = static_cast<int>(event->x_root); - result.globalY = static_cast<int>(event->y_root); - result.clickCount = 0; - - switch (event->type) { - case GDK_BUTTON_PRESS: - result.type = WebInputEvent::MouseDown; - break; - case GDK_BUTTON_RELEASE: - result.type = WebInputEvent::MouseUp; - break; - case GDK_3BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - default: - NOTREACHED(); - } - - result.button = WebMouseEvent::ButtonNone; - if (event->button == 1) - result.button = WebMouseEvent::ButtonLeft; - else if (event->button == 2) - result.button = WebMouseEvent::ButtonMiddle; - else if (event->button == 3) - result.button = WebMouseEvent::ButtonRight; - - if (result.type == WebInputEvent::MouseDown) { - bool forgetPreviousClick = ShouldForgetPreviousClick( - event->window, event->time, event->x, event->y); - - if (!forgetPreviousClick && result.button == last_click_button) { - ++num_clicks; - } else { - num_clicks = 1; - - last_click_event_window = event->window; - last_click_x = event->x; - last_click_y = event->y; - last_click_button = result.button; - } - last_click_time = event->time; - } - result.clickCount = num_clicks; - - return result; -} - -WebMouseEvent WebMouseEventBuilder::Build(const GdkEventMotion* event) { - WebMouseEvent result; - - result.timeStampSeconds = GdkEventTimeToWebEventTime(event->time); - result.modifiers = GdkStateToWebEventModifiers(event->state); - result.x = static_cast<int>(event->x); - result.y = static_cast<int>(event->y); - result.windowX = result.x; - result.windowY = result.y; - result.globalX = static_cast<int>(event->x_root); - result.globalY = static_cast<int>(event->y_root); - - switch (event->type) { - case GDK_MOTION_NOTIFY: - result.type = WebInputEvent::MouseMove; - break; - default: - NOTREACHED(); - } - - result.button = WebMouseEvent::ButtonNone; - if (event->state & GDK_BUTTON1_MASK) - result.button = WebMouseEvent::ButtonLeft; - else if (event->state & GDK_BUTTON2_MASK) - result.button = WebMouseEvent::ButtonMiddle; - else if (event->state & GDK_BUTTON3_MASK) - result.button = WebMouseEvent::ButtonRight; - - if (ShouldForgetPreviousClick(event->window, event->time, event->x, event->y)) - ResetClickCountState(); - - return result; -} - -WebMouseEvent WebMouseEventBuilder::Build(const GdkEventCrossing* event) { - WebMouseEvent result; - - result.timeStampSeconds = GdkEventTimeToWebEventTime(event->time); - result.modifiers = GdkStateToWebEventModifiers(event->state); - result.x = static_cast<int>(event->x); - result.y = static_cast<int>(event->y); - result.windowX = result.x; - result.windowY = result.y; - result.globalX = static_cast<int>(event->x_root); - result.globalY = static_cast<int>(event->y_root); - - switch (event->type) { - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - // Note that if we sent MouseEnter or MouseLeave to WebKit, it - // wouldn't work - they don't result in the proper JavaScript events. - // MouseMove does the right thing. - result.type = WebInputEvent::MouseMove; - break; - default: - NOTREACHED(); - } - - result.button = WebMouseEvent::ButtonNone; - if (event->state & GDK_BUTTON1_MASK) - result.button = WebMouseEvent::ButtonLeft; - else if (event->state & GDK_BUTTON2_MASK) - result.button = WebMouseEvent::ButtonMiddle; - else if (event->state & GDK_BUTTON3_MASK) - result.button = WebMouseEvent::ButtonRight; - - if (ShouldForgetPreviousClick(event->window, event->time, event->x, event->y)) - ResetClickCountState(); - - return result; -} - -// WebMouseWheelEvent --------------------------------------------------------- - -float WebMouseWheelEventBuilder::ScrollbarPixelsPerTick() { - // How much should we scroll per mouse wheel event? - // - Windows uses 3 lines by default and obeys a system setting. - // - Mozilla has a pref that lets you either use the "system" number of lines - // to scroll, or lets the user override it. - // For the "system" number of lines, it appears they've hardcoded 3. - // See case NS_MOUSE_SCROLL in content/events/src/nsEventStateManager.cpp - // and InitMouseScrollEvent in widget/src/gtk2/nsCommonWidget.cpp . - // - Gtk makes the scroll amount a function of the size of the scroll bar, - // which is not available to us here. - // Instead, we pick a number that empirically matches Firefox's behavior. - return 160.0f / 3.0f; -} - -WebMouseWheelEvent WebMouseWheelEventBuilder::Build( - const GdkEventScroll* event) { - WebMouseWheelEvent result; - - result.type = WebInputEvent::MouseWheel; - result.button = WebMouseEvent::ButtonNone; - - result.timeStampSeconds = GdkEventTimeToWebEventTime(event->time); - result.modifiers = GdkStateToWebEventModifiers(event->state); - result.x = static_cast<int>(event->x); - result.y = static_cast<int>(event->y); - result.windowX = result.x; - result.windowY = result.y; - result.globalX = static_cast<int>(event->x_root); - result.globalY = static_cast<int>(event->y_root); - - static const float scrollbarPixelsPerTick = ScrollbarPixelsPerTick(); - switch (event->direction) { - case GDK_SCROLL_UP: - result.deltaY = scrollbarPixelsPerTick; - result.wheelTicksY = 1; - break; - case GDK_SCROLL_DOWN: - result.deltaY = -scrollbarPixelsPerTick; - result.wheelTicksY = -1; - break; - case GDK_SCROLL_LEFT: - result.deltaX = scrollbarPixelsPerTick; - result.wheelTicksX = 1; - break; - case GDK_SCROLL_RIGHT: - result.deltaX = -scrollbarPixelsPerTick; - result.wheelTicksX = -1; - break; - } - - return result; -} - -} // namespace content diff --git a/content/browser/renderer_host/input/web_input_event_builders_gtk.h b/content/browser/renderer_host/input/web_input_event_builders_gtk.h deleted file mode 100644 index 0d0250b..0000000 --- a/content/browser/renderer_host/input/web_input_event_builders_gtk.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_WEB_INPUT_EVENT_BUILDERS_GTK_H_ -#define CONTENT_BROWSER_RENDERER_HOST_INPUT_WEB_INPUT_EVENT_BUILDERS_GTK_H_ - -#include "content/common/content_export.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -#include "ui/events/keycodes/keyboard_codes.h" - -typedef struct _GdkEventButton GdkEventButton; -typedef struct _GdkEventMotion GdkEventMotion; -typedef struct _GdkEventCrossing GdkEventCrossing; -typedef struct _GdkEventScroll GdkEventScroll; -typedef struct _GdkEventKey GdkEventKey; - -namespace content { - -class CONTENT_EXPORT WebKeyboardEventBuilder { - public: - static blink::WebKeyboardEvent Build(const GdkEventKey* event); - static blink::WebKeyboardEvent Build(wchar_t character, - int state, - double time_secs); -}; - -class CONTENT_EXPORT WebMouseEventBuilder { - public: - static blink::WebMouseEvent Build(const GdkEventButton* event); - static blink::WebMouseEvent Build(const GdkEventMotion* event); - static blink::WebMouseEvent Build(const GdkEventCrossing* event); -}; - -class CONTENT_EXPORT WebMouseWheelEventBuilder { - public: - static float ScrollbarPixelsPerTick(); - static blink::WebMouseWheelEvent Build( - const GdkEventScroll* event); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_WEB_INPUT_EVENT_BUILDERS_GTK_H diff --git a/content/browser/renderer_host/input/web_input_event_builders_gtk_unittest.cc b/content/browser/renderer_host/input/web_input_event_builders_gtk_unittest.cc deleted file mode 100644 index b5e2d42..0000000 --- a/content/browser/renderer_host/input/web_input_event_builders_gtk_unittest.cc +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/input/web_input_event_builders_gtk.h" - -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> - -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -#include "ui/events/keycodes/keyboard_code_conversion_gtk.h" - -using blink::WebInputEvent; -using blink::WebKeyboardEvent; -using blink::WebMouseEvent; -using content::WebMouseEventBuilder; -using content::WebKeyboardEventBuilder; - -namespace { - -TEST(WebMouseEventBuilderTest, DoubleClick) { - GdkEventButton first_click; - first_click.type = GDK_BUTTON_PRESS; - first_click.window = static_cast<GdkWindow*>(GINT_TO_POINTER(1)); - first_click.x = first_click.y = first_click.x_root = first_click.y_root = 100; - first_click.state = 0; - first_click.time = 0; - first_click.button = 1; - - // Single click works. - WebMouseEvent first_click_events = - WebMouseEventBuilder::Build(&first_click); - EXPECT_EQ(1, first_click_events.clickCount); - - // Make sure double click works. - GdkEventButton second_click = first_click; - second_click.time = first_click.time + 100; - WebMouseEvent second_click_events = - WebMouseEventBuilder::Build(&second_click); - EXPECT_EQ(2, second_click_events.clickCount); - - // Reset the click count. - first_click.time += 10000; - first_click_events = WebMouseEventBuilder::Build(&first_click); - EXPECT_EQ(1, first_click_events.clickCount); - - // Two clicks with a long gap in between aren't counted as a double click. - second_click = first_click; - second_click.time = first_click.time + 1000; - second_click_events = WebMouseEventBuilder::Build(&second_click); - EXPECT_EQ(1, second_click_events.clickCount); - - // Reset the click count. - first_click.time += 10000; - first_click_events = WebMouseEventBuilder::Build(&first_click); - EXPECT_EQ(1, first_click_events.clickCount); - - // Two clicks far apart (horizontally) aren't counted as a double click. - second_click = first_click; - second_click.time = first_click.time + 1; - second_click.x = first_click.x + 100; - second_click_events = WebMouseEventBuilder::Build(&second_click); - EXPECT_EQ(1, second_click_events.clickCount); - - // Reset the click count. - first_click.time += 10000; - first_click_events = WebMouseEventBuilder::Build(&first_click); - EXPECT_EQ(1, first_click_events.clickCount); - - // Two clicks far apart (vertically) aren't counted as a double click. - second_click = first_click; - second_click.time = first_click.time + 1; - second_click.x = first_click.y + 100; - second_click_events = WebMouseEventBuilder::Build(&second_click); - EXPECT_EQ(1, second_click_events.clickCount); - - // Reset the click count. - first_click.time += 10000; - first_click_events = WebMouseEventBuilder::Build(&first_click); - EXPECT_EQ(1, first_click_events.clickCount); - - // Two clicks on different windows aren't a double click. - second_click = first_click; - second_click.time = first_click.time + 1; - second_click.window = static_cast<GdkWindow*>(GINT_TO_POINTER(2)); - second_click_events = WebMouseEventBuilder::Build(&second_click); - EXPECT_EQ(1, second_click_events.clickCount); -} - -TEST(WebMouseEventBuilderTest, MouseUpClickCount) { - GdkEventButton mouse_down; - memset(&mouse_down, 0, sizeof(mouse_down)); - mouse_down.type = GDK_BUTTON_PRESS; - mouse_down.window = static_cast<GdkWindow*>(GINT_TO_POINTER(1)); - mouse_down.x = mouse_down.y = mouse_down.x_root = mouse_down.y_root = 100; - mouse_down.time = 0; - mouse_down.button = 1; - - // Properly set the last click time, so that the internal state won't be - // affected by previous tests. - WebMouseEventBuilder::Build(&mouse_down); - - mouse_down.time += 10000; - GdkEventButton mouse_up = mouse_down; - mouse_up.type = GDK_BUTTON_RELEASE; - WebMouseEvent mouse_down_event; - WebMouseEvent mouse_up_event; - - // Click for three times. - for (int i = 1; i < 4; ++i) { - mouse_down.time += 100; - mouse_down_event = WebMouseEventBuilder::Build(&mouse_down); - EXPECT_EQ(i, mouse_down_event.clickCount); - - mouse_up.time = mouse_down.time + 50; - mouse_up_event = WebMouseEventBuilder::Build(&mouse_up); - EXPECT_EQ(i, mouse_up_event.clickCount); - } - - // Reset the click count. - mouse_down.time += 10000; - mouse_down_event = WebMouseEventBuilder::Build(&mouse_down); - EXPECT_EQ(1, mouse_down_event.clickCount); - - // Moving the cursor for a significant distance will reset the click count to - // 0. - GdkEventMotion mouse_move; - memset(&mouse_move, 0, sizeof(mouse_move)); - mouse_move.type = GDK_MOTION_NOTIFY; - mouse_move.window = mouse_down.window; - mouse_move.time = mouse_down.time; - mouse_move.x = mouse_move.y = mouse_move.x_root = mouse_move.y_root = - mouse_down.x + 100; - WebMouseEventBuilder::Build(&mouse_move); - - mouse_up.time = mouse_down.time + 50; - mouse_up_event = WebMouseEventBuilder::Build(&mouse_up); - EXPECT_EQ(0, mouse_up_event.clickCount); - - // Reset the click count. - mouse_down.time += 10000; - mouse_down_event = WebMouseEventBuilder::Build(&mouse_down); - EXPECT_EQ(1, mouse_down_event.clickCount); - - // Moving the cursor with a significant delay will reset the click count to 0. - mouse_move.time = mouse_down.time + 1000; - mouse_move.x = mouse_move.y = mouse_move.x_root = mouse_move.y_root = - mouse_down.x; - WebMouseEventBuilder::Build(&mouse_move); - - mouse_up.time = mouse_move.time + 50; - mouse_up_event = WebMouseEventBuilder::Build(&mouse_up); - EXPECT_EQ(0, mouse_up_event.clickCount); -} - -TEST(WebKeyboardEventBuilderTest, NumPadConversion) { - // Construct a GDK input event for the numpad "5" key. - char five[] = "5"; - GdkEventKey gdk_event; - memset(&gdk_event, 0, sizeof(GdkEventKey)); - gdk_event.type = GDK_KEY_PRESS; - gdk_event.keyval = GDK_KP_5; - gdk_event.string = five; - - // Numpad flag should be set on the WebKeyboardEvent. - WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(&gdk_event); - EXPECT_TRUE(web_event.modifiers & WebInputEvent::IsKeyPad); -} - -} // anonymous namespace diff --git a/content/browser/renderer_host/native_web_keyboard_event_gtk.cc b/content/browser/renderer_host/native_web_keyboard_event_gtk.cc deleted file mode 100644 index 74ce6a3..0000000 --- a/content/browser/renderer_host/native_web_keyboard_event_gtk.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/public/browser/native_web_keyboard_event.h" - -#include <gdk/gdk.h> - -#include "content/browser/renderer_host/input/web_input_event_builders_gtk.h" - -namespace { - -void CopyEventTo(gfx::NativeEvent in, gfx::NativeEvent* out) { - *out = in ? gdk_event_copy(in) : NULL; -} - -void FreeEvent(gfx::NativeEvent event) { - if (event) - gdk_event_free(event); -} - -} // namespace - -namespace content { - -NativeWebKeyboardEvent::NativeWebKeyboardEvent() - : os_event(NULL), - skip_in_browser(false), - match_edit_command(false) { -} - -NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) - : WebKeyboardEvent(WebKeyboardEventBuilder::Build(&native_event->key)), - skip_in_browser(false), - match_edit_command(false) { - CopyEventTo(native_event, &os_event); -} - -NativeWebKeyboardEvent::NativeWebKeyboardEvent(wchar_t character, - int state, - double time_stamp_seconds) - : WebKeyboardEvent(WebKeyboardEventBuilder::Build(character, - state, - time_stamp_seconds)), - os_event(NULL), - skip_in_browser(false), - match_edit_command(false) { -} - -NativeWebKeyboardEvent::NativeWebKeyboardEvent( - const NativeWebKeyboardEvent& other) - : WebKeyboardEvent(other), - skip_in_browser(other.skip_in_browser), - match_edit_command(other.match_edit_command) { - CopyEventTo(other.os_event, &os_event); -} - -NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( - const NativeWebKeyboardEvent& other) { - WebKeyboardEvent::operator=(other); - - FreeEvent(os_event); - CopyEventTo(other.os_event, &os_event); - - skip_in_browser = other.skip_in_browser; - match_edit_command = other.match_edit_command; - - return *this; -} - -NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { - FreeEvent(os_event); -} - -} // namespace content diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 62750cf..a1fb9f8 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -1292,8 +1292,6 @@ TransportDIB* RenderProcessHostImpl::MapTransportDIB( FILE_MAP_READ | FILE_MAP_WRITE, FALSE, 0); return TransportDIB::Map(section); -#elif defined(TOOLKIT_GTK) - return TransportDIB::Map(dib_id.shmkey); #elif defined(OS_ANDROID) return TransportDIB::Map(dib_id); #else @@ -1332,11 +1330,7 @@ TransportDIB* RenderProcessHostImpl::GetTransportDIB( } } -#if defined(TOOLKIT_GTK) - smallest_iterator->second->Detach(); -#else delete smallest_iterator->second; -#endif cached_dibs_.erase(smallest_iterator); } @@ -1346,15 +1340,8 @@ TransportDIB* RenderProcessHostImpl::GetTransportDIB( } void RenderProcessHostImpl::ClearTransportDIBCache() { -#if defined(TOOLKIT_GTK) - std::map<TransportDIB::Id, TransportDIB*>::const_iterator dib = - cached_dibs_.begin(); - for (; dib != cached_dibs_.end(); ++dib) - dib->second->Detach(); -#else STLDeleteContainerPairSecondPointers( cached_dibs_.begin(), cached_dibs_.end()); -#endif cached_dibs_.clear(); } diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index c7e66db..aee32a0 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc @@ -69,9 +69,7 @@ #include "ui/snapshot/snapshot.h" #include "webkit/common/webpreferences.h" -#if defined(TOOLKIT_GTK) -#include "content/browser/renderer_host/backing_store_gtk.h" -#elif defined(OS_MACOSX) +#if defined(OS_MACOSX) #include "content/browser/renderer_host/backing_store_mac.h" #elif defined(OS_WIN) #include "content/common/plugin_constants_win.h" @@ -761,17 +759,7 @@ void RenderWidgetHostImpl::UnlockBackingStore() { } #endif -#if defined(TOOLKIT_GTK) -bool RenderWidgetHostImpl::CopyFromBackingStoreToGtkWindow( - const gfx::Rect& dest_rect, GdkWindow* target) { - BackingStore* backing_store = GetBackingStore(false); - if (!backing_store) - return false; - (static_cast<BackingStoreGtk*>(backing_store))->PaintToRect( - dest_rect, target); - return true; -} -#elif defined(OS_MACOSX) +#if defined(OS_MACOSX) gfx::Size RenderWidgetHostImpl::GetBackingStoreSize() { BackingStore* backing_store = GetBackingStore(false); return backing_store ? backing_store->size() : gfx::Size(); diff --git a/content/browser/renderer_host/render_widget_host_view_base.cc b/content/browser/renderer_host/render_widget_host_view_base.cc index 4ce7eac..197960f 100644 --- a/content/browser/renderer_host/render_widget_host_view_base.cc +++ b/content/browser/renderer_host/render_widget_host_view_base.cc @@ -34,13 +34,6 @@ #include "ui/gfx/win/hwnd_util.h" #endif -#if defined(TOOLKIT_GTK) -#include <gdk/gdkx.h> -#include <gtk/gtk.h> - -#include "content/browser/renderer_host/gtk_window_utils.h" -#endif - namespace content { // static diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.cc b/content/browser/renderer_host/render_widget_host_view_gtk.cc deleted file mode 100644 index e8e713e..0000000 --- a/content/browser/renderer_host/render_widget_host_view_gtk.cc +++ /dev/null @@ -1,1621 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/render_widget_host_view_gtk.h" - -#include <cairo/cairo.h> -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> -#include <gdk/gdkx.h> -#include <gtk/gtk.h> - -#include <algorithm> -#include <string> - -#include "base/bind_helpers.h" -#include "base/command_line.h" -#include "base/debug/trace_event.h" -#include "base/logging.h" -#include "base/message_loop/message_loop.h" -#include "base/metrics/histogram.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_offset_string_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "base/time/time.h" -#include "content/browser/accessibility/browser_accessibility_gtk.h" -#include "content/browser/accessibility/browser_accessibility_manager_gtk.h" -#include "content/browser/renderer_host/backing_store_gtk.h" -#include "content/browser/renderer_host/gtk_im_context_wrapper.h" -#include "content/browser/renderer_host/gtk_key_bindings_handler.h" -#include "content/browser/renderer_host/gtk_window_utils.h" -#include "content/browser/renderer_host/input/web_input_event_builders_gtk.h" -#include "content/browser/renderer_host/render_view_host_delegate.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/common/cursors/webcursor_gtk_data.h" -#include "content/common/gpu/gpu_messages.h" -#include "content/common/input_messages.h" -#include "content/common/view_messages.h" -#include "content/common/webplugin_geometry.h" -#include "content/public/browser/native_web_keyboard_event.h" -#include "content/public/common/content_switches.h" -#include "skia/ext/platform_canvas.h" -#include "third_party/WebKit/public/platform/WebScreenInfo.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -#include "ui/base/clipboard/scoped_clipboard_writer.h" -#include "ui/base/x/active_window_watcher_x.h" -#include "ui/base/x/x11_util.h" -#include "ui/gfx/gtk_compat.h" -#include "ui/gfx/gtk_native_view_id_manager.h" -#include "ui/gfx/gtk_preserve_window.h" -#include "ui/gfx/text_elider.h" - -using blink::WebMouseWheelEvent; -using blink::WebScreenInfo; - -#error "The GTK+ port will be deleted later this week. If you are seeing this, you are trying to compile it. Please check your gyp flags for 'use_aura=0' and remove them." - -namespace content { -namespace { - -// Paint rects on Linux are bounded by the maximum size of a shared memory -// region. By default that's 32MB, but many distros increase it significantly -// (i.e. to 256MB). -// -// We fetch the maximum value from /proc/sys/kernel/shmmax at runtime and, if -// we exceed that, then we limit the height of the paint rect in the renderer. -// -// These constants are here to ensure that, in the event that we exceed it, we -// end up with something a little more square. Previously we had 4000x4000, but -// people's monitor setups are actually exceeding that these days. -const int kMaxWindowWidth = 10000; -const int kMaxWindowHeight = 10000; - -const GdkColor kBGColor = -#if defined(NDEBUG) - { 0, 0xff * 257, 0xff * 257, 0xff * 257 }; -#else - { 0, 0x00 * 257, 0xff * 257, 0x00 * 257 }; -#endif - -// Returns the spinning cursor used for loading state. -GdkCursor* GetMozSpinningCursor() { - static GdkCursor* moz_spinning_cursor = NULL; - if (!moz_spinning_cursor) { - const GdkColor fg = { 0, 0, 0, 0 }; - const GdkColor bg = { 65535, 65535, 65535, 65535 }; - GdkPixmap* source = gdk_bitmap_create_from_data( - NULL, reinterpret_cast<const gchar*>(moz_spinning_bits), 32, 32); - GdkPixmap* mask = gdk_bitmap_create_from_data( - NULL, reinterpret_cast<const gchar*>(moz_spinning_mask_bits), 32, 32); - moz_spinning_cursor = - gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, 2, 2); - g_object_unref(source); - g_object_unref(mask); - } - return moz_spinning_cursor; -} - -bool MovedToPoint(const blink::WebMouseEvent& mouse_event, - const gfx::Point& center) { - return mouse_event.globalX == center.x() && - mouse_event.globalY == center.y(); -} - -} // namespace - -// This class is a simple convenience wrapper for Gtk functions. It has only -// static methods. -class RenderWidgetHostViewGtkWidget { - public: - static AtkObject* GetAccessible(void* userdata) { - return (static_cast<RenderWidgetHostViewGtk*>(userdata))-> - GetAccessible(); - } - - static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { - GtkWidget* widget = gtk_preserve_window_new(); - gtk_widget_set_name(widget, "chrome-render-widget-host-view"); - // We manually double-buffer in Paint() because Paint() may or may not be - // called in repsonse to an "expose-event" signal. - gtk_widget_set_double_buffered(widget, FALSE); - gtk_widget_set_redraw_on_allocate(widget, FALSE); - gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); - // Allow the browser window to be resized freely. - gtk_widget_set_size_request(widget, 0, 0); - - gtk_widget_add_events(widget, GDK_EXPOSURE_MASK | - GDK_STRUCTURE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_FOCUS_CHANGE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); - gtk_widget_set_can_focus(widget, TRUE); - - g_signal_connect(widget, "expose-event", - G_CALLBACK(OnExposeEvent), host_view); - g_signal_connect(widget, "realize", - G_CALLBACK(OnRealize), host_view); - g_signal_connect(widget, "configure-event", - G_CALLBACK(OnConfigureEvent), host_view); - g_signal_connect(widget, "size-allocate", - G_CALLBACK(OnSizeAllocate), host_view); - g_signal_connect(widget, "key-press-event", - G_CALLBACK(OnKeyPressReleaseEvent), host_view); - g_signal_connect(widget, "key-release-event", - G_CALLBACK(OnKeyPressReleaseEvent), host_view); - g_signal_connect(widget, "focus-in-event", - G_CALLBACK(OnFocusIn), host_view); - g_signal_connect(widget, "focus-out-event", - G_CALLBACK(OnFocusOut), host_view); - g_signal_connect(widget, "grab-notify", - G_CALLBACK(OnGrabNotify), host_view); - g_signal_connect(widget, "button-press-event", - G_CALLBACK(OnButtonPressReleaseEvent), host_view); - g_signal_connect(widget, "button-release-event", - G_CALLBACK(OnButtonPressReleaseEvent), host_view); - g_signal_connect(widget, "motion-notify-event", - G_CALLBACK(OnMouseMoveEvent), host_view); - g_signal_connect(widget, "enter-notify-event", - G_CALLBACK(OnCrossingEvent), host_view); - g_signal_connect(widget, "leave-notify-event", - G_CALLBACK(OnCrossingEvent), host_view); - g_signal_connect(widget, "client-event", - G_CALLBACK(OnClientEvent), host_view); - - - // Connect after so that we are called after the handler installed by the - // WebContentsView which handles zoom events. - g_signal_connect_after(widget, "scroll-event", - G_CALLBACK(OnMouseScrollEvent), host_view); - - // Route calls to get_accessible to the view. - gtk_preserve_window_set_accessible_factory( - GTK_PRESERVE_WINDOW(widget), GetAccessible, host_view); - - return widget; - } - - private: - static gboolean OnExposeEvent(GtkWidget* widget, - GdkEventExpose* expose, - RenderWidgetHostViewGtk* host_view) { - if (host_view->host_->is_hidden()) - return FALSE; - const gfx::Rect damage_rect(expose->area); - host_view->Paint(damage_rect); - return FALSE; - } - - static gboolean OnRealize(GtkWidget* widget, - RenderWidgetHostViewGtk* host_view) { - // Use GtkSignalRegistrar to register events on a widget we don't - // control the lifetime of, auto disconnecting at our end of our life. - host_view->signals_.Connect(gtk_widget_get_toplevel(widget), - "configure-event", - G_CALLBACK(OnConfigureEvent), host_view); - return FALSE; - } - - static gboolean OnConfigureEvent(GtkWidget* widget, - GdkEventConfigure* event, - RenderWidgetHostViewGtk* host_view) { - host_view->MarkCachedWidgetCenterStale(); - host_view->UpdateScreenInfo(host_view->GetNativeView()); - return FALSE; - } - - static gboolean OnSizeAllocate(GtkWidget* widget, - GdkRectangle* allocation, - RenderWidgetHostViewGtk* host_view) { - if (!host_view->IsPopup() && !host_view->is_fullscreen_) - host_view->SetSize(gfx::Size(allocation->width, allocation->height)); - return FALSE; - } - - static gboolean OnKeyPressReleaseEvent(GtkWidget* widget, - GdkEventKey* event, - RenderWidgetHostViewGtk* host_view) { - TRACE_EVENT0("browser", - "RenderWidgetHostViewGtkWidget::OnKeyPressReleaseEvent"); - // Force popups or fullscreen windows to close on Escape so they won't keep - // the keyboard grabbed or be stuck onscreen if the renderer is hanging. - bool should_close_on_escape = - (host_view->IsPopup() && host_view->NeedsInputGrab()) || - host_view->is_fullscreen_; - if (should_close_on_escape && GDK_Escape == event->keyval) { - host_view->host_->Shutdown(); - } else { - // Send key event to input method. - host_view->im_context_->ProcessKeyEvent(event); - } - - // We return TRUE because we did handle the event. If it turns out webkit - // can't handle the event, we'll deal with it in - // RenderView::UnhandledKeyboardEvent(). - return TRUE; - } - - static gboolean OnFocusIn(GtkWidget* widget, - GdkEventFocus* focus, - RenderWidgetHostViewGtk* host_view) { - host_view->ShowCurrentCursor(); - RenderWidgetHostImpl* host = - RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); - host->GotFocus(); - host->SetActive(true); - - // The only way to enable a GtkIMContext object is to call its focus in - // handler. - host_view->im_context_->OnFocusIn(); - - return TRUE; - } - - static gboolean OnFocusOut(GtkWidget* widget, - GdkEventFocus* focus, - RenderWidgetHostViewGtk* host_view) { - // Whenever we lose focus, set the cursor back to that of our parent window, - // which should be the default arrow. - gdk_window_set_cursor(gtk_widget_get_window(widget), NULL); - // If we are showing a context menu, maintain the illusion that webkit has - // focus. - if (!host_view->IsShowingContextMenu()) { - RenderWidgetHostImpl* host = - RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); - host->SetActive(false); - host->Blur(); - } - - // Prevents us from stealing input context focus in OnGrabNotify() handler. - host_view->was_imcontext_focused_before_grab_ = false; - - // Disable the GtkIMContext object. - host_view->im_context_->OnFocusOut(); - - host_view->set_last_mouse_down(NULL); - - return TRUE; - } - - // Called when we are shadowed or unshadowed by a keyboard grab (which will - // occur for activatable popups, such as dropdown menus). Popup windows do not - // take focus, so we never get a focus out or focus in event when they are - // shown, and must rely on this signal instead. - static void OnGrabNotify(GtkWidget* widget, gboolean was_grabbed, - RenderWidgetHostViewGtk* host_view) { - if (was_grabbed) { - if (host_view->was_imcontext_focused_before_grab_) - host_view->im_context_->OnFocusIn(); - } else { - host_view->was_imcontext_focused_before_grab_ = - host_view->im_context_->is_focused(); - if (host_view->was_imcontext_focused_before_grab_) { - gdk_window_set_cursor(gtk_widget_get_window(widget), NULL); - host_view->im_context_->OnFocusOut(); - } - } - } - - static gboolean OnButtonPressReleaseEvent( - GtkWidget* widget, - GdkEventButton* event, - RenderWidgetHostViewGtk* host_view) { - TRACE_EVENT0("browser", - "RenderWidgetHostViewGtkWidget::OnButtonPressReleaseEvent"); - - if (event->type != GDK_BUTTON_RELEASE) - host_view->set_last_mouse_down(event); - - if (!(event->button == 1 || event->button == 2 || event->button == 3)) - return FALSE; // We do not forward any other buttons to the renderer. - if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) - return FALSE; - - // If we don't have focus already, this mouse click will focus us. - if (!gtk_widget_is_focus(widget)) - host_view->host_->OnPointerEventActivate(); - - // Confirm existing composition text on mouse click events, to make sure - // the input caret won't be moved with an ongoing composition session. - if (event->type != GDK_BUTTON_RELEASE) - host_view->im_context_->ConfirmComposition(); - - // We want to translate the coordinates of events that do not originate - // from this widget to be relative to the top left of the widget. - GtkWidget* event_widget = gtk_get_event_widget( - reinterpret_cast<GdkEvent*>(event)); - if (event_widget != widget) { - int x = 0; - int y = 0; - gtk_widget_get_pointer(widget, &x, &y); - // If the mouse event happens outside our popup, force the popup to - // close. We do this so a hung renderer doesn't prevent us from - // releasing the x pointer grab. - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); - bool click_in_popup = x >= 0 && y >= 0 && x < allocation.width && - y < allocation.height; - // Only Shutdown on mouse downs. Mouse ups can occur outside the render - // view if the user drags for DnD or while using the scrollbar on a select - // dropdown. Don't shutdown if we are not a popup. - if (event->type != GDK_BUTTON_RELEASE && host_view->IsPopup() && - !host_view->is_popup_first_mouse_release_ && !click_in_popup) { - host_view->host_->Shutdown(); - return FALSE; - } - event->x = x; - event->y = y; - } - - // TODO(evanm): why is this necessary here but not in test shell? - // This logic is the same as GtkButton. - if (event->type == GDK_BUTTON_PRESS && !gtk_widget_has_focus(widget)) - gtk_widget_grab_focus(widget); - - host_view->is_popup_first_mouse_release_ = false; - RenderWidgetHostImpl* widget_host = - RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); - if (widget_host) - widget_host->ForwardMouseEvent(WebMouseEventBuilder::Build(event)); - - // Although we did handle the mouse event, we need to let other handlers - // run (in particular the one installed by WebContentsViewGtk). - return FALSE; - } - - static gboolean OnMouseMoveEvent(GtkWidget* widget, - GdkEventMotion* event, - RenderWidgetHostViewGtk* host_view) { - TRACE_EVENT0("browser", - "RenderWidgetHostViewGtkWidget::OnMouseMoveEvent"); - // We want to translate the coordinates of events that do not originate - // from this widget to be relative to the top left of the widget. - GtkWidget* event_widget = gtk_get_event_widget( - reinterpret_cast<GdkEvent*>(event)); - if (event_widget != widget) { - int x = 0; - int y = 0; - gtk_widget_get_pointer(widget, &x, &y); - event->x = x; - event->y = y; - } - - host_view->ModifyEventForEdgeDragging(widget, event); - - blink::WebMouseEvent mouse_event = WebMouseEventBuilder::Build(event); - - if (host_view->mouse_locked_) { - gfx::Point center = host_view->GetWidgetCenter(); - - bool moved_to_center = MovedToPoint(mouse_event, center); - if (moved_to_center) - host_view->mouse_has_been_warped_to_new_center_ = true; - - host_view->ModifyEventMovementAndCoords(&mouse_event); - - if (!moved_to_center && - (mouse_event.movementX || mouse_event.movementY)) { - GdkDisplay* display = gtk_widget_get_display(widget); - GdkScreen* screen = gtk_widget_get_screen(widget); - gdk_display_warp_pointer(display, screen, center.x(), center.y()); - if (host_view->mouse_has_been_warped_to_new_center_) - RenderWidgetHostImpl::From( - host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); - } - } else { // Mouse is not locked. - host_view->ModifyEventMovementAndCoords(&mouse_event); - // Do not send mouse events while the mouse cursor is being warped back - // to the unlocked location. - if (!host_view->mouse_is_being_warped_to_unlocked_position_) { - RenderWidgetHostImpl::From( - host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); - } - } - return FALSE; - } - - static gboolean OnCrossingEvent(GtkWidget* widget, - GdkEventCrossing* event, - RenderWidgetHostViewGtk* host_view) { - TRACE_EVENT0("browser", - "RenderWidgetHostViewGtkWidget::OnCrossingEvent"); - const int any_button_mask = - GDK_BUTTON1_MASK | - GDK_BUTTON2_MASK | - GDK_BUTTON3_MASK | - GDK_BUTTON4_MASK | - GDK_BUTTON5_MASK; - - // Only forward crossing events if the mouse button is not down. - // (When the mouse button is down, the proper events are already being - // sent by ButtonPressReleaseEvent and MouseMoveEvent, above, and if we - // additionally send this crossing event with the state indicating the - // button is down, it causes problems with drag and drop in WebKit.) - if (!(event->state & any_button_mask)) { - blink::WebMouseEvent mouse_event = WebMouseEventBuilder::Build(event); - host_view->ModifyEventMovementAndCoords(&mouse_event); - // When crossing out and back into a render view the movement values - // must represent the instantaneous movement of the mouse, not the jump - // from the exit to re-entry point. - mouse_event.movementX = 0; - mouse_event.movementY = 0; - RenderWidgetHostImpl::From( - host_view->GetRenderWidgetHost())->ForwardMouseEvent(mouse_event); - } - - return FALSE; - } - - static gboolean OnClientEvent(GtkWidget* widget, - GdkEventClient* event, - RenderWidgetHostViewGtk* host_view) { - VLOG(1) << "client event type: " << event->message_type - << " data_format: " << event->data_format - << " data: " << event->data.l; - return TRUE; - } - - // Return the net up / down (or left / right) distance represented by events - // in the events will be removed from the queue. We only look at the top of - // queue...any other type of event will cause us not to look farther. - // If there is a change to the set of modifier keys or scroll axis - // in the events we will stop looking as well. - static int GetPendingScrollDelta(bool vert, guint current_event_state) { - int num_clicks = 0; - GdkEvent* event; - bool event_coalesced = true; - while ((event = gdk_event_get()) && event_coalesced) { - event_coalesced = false; - if (event->type == GDK_SCROLL) { - GdkEventScroll scroll = event->scroll; - if (scroll.state & GDK_SHIFT_MASK) { - if (scroll.direction == GDK_SCROLL_UP) - scroll.direction = GDK_SCROLL_LEFT; - else if (scroll.direction == GDK_SCROLL_DOWN) - scroll.direction = GDK_SCROLL_RIGHT; - } - if (vert) { - if (scroll.direction == GDK_SCROLL_UP || - scroll.direction == GDK_SCROLL_DOWN) { - if (scroll.state == current_event_state) { - num_clicks += (scroll.direction == GDK_SCROLL_UP ? 1 : -1); - gdk_event_free(event); - event_coalesced = true; - } - } - } else { - if (scroll.direction == GDK_SCROLL_LEFT || - scroll.direction == GDK_SCROLL_RIGHT) { - if (scroll.state == current_event_state) { - num_clicks += (scroll.direction == GDK_SCROLL_LEFT ? 1 : -1); - gdk_event_free(event); - event_coalesced = true; - } - } - } - } - } - // If we have an event left we put it back on the queue. - if (event) { - gdk_event_put(event); - gdk_event_free(event); - } - return num_clicks * WebMouseWheelEventBuilder::ScrollbarPixelsPerTick(); - } - - static gboolean OnMouseScrollEvent(GtkWidget* widget, - GdkEventScroll* event, - RenderWidgetHostViewGtk* host_view) { - TRACE_EVENT0("browser", - "RenderWidgetHostViewGtkWidget::OnMouseScrollEvent"); - // If the user is holding shift, translate it into a horizontal scroll. We - // don't care what other modifiers the user may be holding (zooming is - // handled at the WebContentsView level). - if (event->state & GDK_SHIFT_MASK) { - if (event->direction == GDK_SCROLL_UP) - event->direction = GDK_SCROLL_LEFT; - else if (event->direction == GDK_SCROLL_DOWN) - event->direction = GDK_SCROLL_RIGHT; - } - - WebMouseWheelEvent web_event = WebMouseWheelEventBuilder::Build(event); - const float pixelsPerTick = - WebMouseWheelEventBuilder::ScrollbarPixelsPerTick(); - // We peek ahead at the top of the queue to look for additional pending - // scroll events. - if (event->direction == GDK_SCROLL_UP || - event->direction == GDK_SCROLL_DOWN) { - if (event->direction == GDK_SCROLL_UP) - web_event.deltaY = pixelsPerTick; - else - web_event.deltaY = -pixelsPerTick; - web_event.deltaY += GetPendingScrollDelta(true, event->state); - } else { - if (event->direction == GDK_SCROLL_LEFT) - web_event.deltaX = pixelsPerTick; - else - web_event.deltaX = -pixelsPerTick; - web_event.deltaX += GetPendingScrollDelta(false, event->state); - } - RenderWidgetHostImpl::From( - host_view->GetRenderWidgetHost())->ForwardWheelEvent(web_event); - return FALSE; - } - - DISALLOW_IMPLICIT_CONSTRUCTORS(RenderWidgetHostViewGtkWidget); -}; - -RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host) - : host_(RenderWidgetHostImpl::From(widget_host)), - about_to_validate_and_paint_(false), - is_loading_(false), - parent_(NULL), - is_popup_first_mouse_release_(true), - was_imcontext_focused_before_grab_(false), - do_x_grab_(false), - is_fullscreen_(false), - made_active_(false), - mouse_is_being_warped_to_unlocked_position_(false), - destroy_handler_id_(0), - dragged_at_horizontal_edge_(0), - dragged_at_vertical_edge_(0), - compositing_surface_(gfx::kNullPluginWindow), - last_mouse_down_(NULL) { - host_->SetView(this); -} - -RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { - UnlockMouse(); - set_last_mouse_down(NULL); - view_.Destroy(); -} - -bool RenderWidgetHostViewGtk::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewGtk, message) - IPC_MESSAGE_HANDLER(ViewHostMsg_CreatePluginContainer, - OnCreatePluginContainer) - IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyPluginContainer, - OnDestroyPluginContainer) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void RenderWidgetHostViewGtk::InitAsChild( - gfx::NativeView parent_view) { - DoSharedInit(); - gtk_widget_show(view_.get()); -} - -void RenderWidgetHostViewGtk::InitAsPopup( - RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { - // If we aren't a popup, then |window| will be leaked. - DCHECK(IsPopup()); - - DoSharedInit(); - parent_ = parent_host_view->GetNativeView(); - GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_POPUP)); - gtk_container_add(GTK_CONTAINER(window), view_.get()); - DoPopupOrFullscreenInit(window, pos); - - // Grab all input for the app. If a click lands outside the bounds of the - // popup, WebKit will notice and destroy us. The underlying X window needs to - // be created and mapped by the above code before we can grab the input - // devices. - if (NeedsInputGrab()) { - // If our parent is in a widget hierarchy that ends with a window, add - // ourselves to the same window group to make sure that our GTK grab - // covers it. - GtkWidget* toplevel = gtk_widget_get_toplevel(parent_); - if (toplevel && - GTK_WIDGET_TOPLEVEL(toplevel) && - GTK_IS_WINDOW(toplevel)) { - gtk_window_group_add_window( - gtk_window_get_group(GTK_WINDOW(toplevel)), window); - } - - // Install an application-level GTK grab to make sure that we receive all of - // the app's input. - gtk_grab_add(view_.get()); - - // We need to install an X grab as well. However if the app already has an X - // grab (as in the case of extension popup), an app grab will suffice. - do_x_grab_ = !gdk_pointer_is_grabbed(); - if (do_x_grab_) { - // Install the grab on behalf our parent window if it and all of its - // ancestors are mapped; otherwise, just use ourselves (maybe we're being - // shown on behalf of an inactive tab). - GdkWindow* grab_window = gtk_widget_get_window(parent_); - if (!grab_window || !gdk_window_is_viewable(grab_window)) - grab_window = gtk_widget_get_window(view_.get()); - - gdk_pointer_grab( - grab_window, - TRUE, // Only events outside of the window are reported with - // respect to |parent_->window|. - static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK), - NULL, - NULL, - GDK_CURRENT_TIME); - // We grab keyboard events too so things like alt+tab are eaten. - gdk_keyboard_grab(grab_window, TRUE, GDK_CURRENT_TIME); - } - } -} - -void RenderWidgetHostViewGtk::InitAsFullscreen( - RenderWidgetHostView* reference_host_view) { - DCHECK(reference_host_view); - DoSharedInit(); - - is_fullscreen_ = true; - GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); - gtk_window_set_decorated(window, FALSE); - destroy_handler_id_ = g_signal_connect(GTK_WIDGET(window), - "destroy", - G_CALLBACK(OnDestroyThunk), - this); - gtk_container_add(GTK_CONTAINER(window), view_.get()); - - // Try to move and resize the window to cover the screen in case the window - // manager doesn't support _NET_WM_STATE_FULLSCREEN. - GdkScreen* screen = gtk_window_get_screen(window); - GdkWindow* ref_gdk_window = gtk_widget_get_window( - reference_host_view->GetNativeView()); - - gfx::Rect bounds; - if (ref_gdk_window) { - const int monitor_id = gdk_screen_get_monitor_at_window(screen, - ref_gdk_window); - GdkRectangle monitor_rect; - gdk_screen_get_monitor_geometry(screen, monitor_id, &monitor_rect); - bounds = gfx::Rect(monitor_rect); - } else { - bounds = gfx::Rect( - 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen)); - } - gtk_window_move(window, bounds.x(), bounds.y()); - gtk_window_resize(window, bounds.width(), bounds.height()); - gtk_window_fullscreen(window); - DoPopupOrFullscreenInit(window, bounds); -} - -RenderWidgetHost* RenderWidgetHostViewGtk::GetRenderWidgetHost() const { - return host_; -} - -void RenderWidgetHostViewGtk::WasShown() { - if (!host_ || !host_->is_hidden()) - return; - - if (web_contents_switch_paint_time_.is_null()) - web_contents_switch_paint_time_ = base::TimeTicks::Now(); - - host_->WasShown(); -} - -void RenderWidgetHostViewGtk::WasHidden() { - if (!host_ || host_->is_hidden()) - return; - - // If we have a renderer, then inform it that we are being hidden so it can - // reduce its resource utilization. - host_->WasHidden(); - - web_contents_switch_paint_time_ = base::TimeTicks(); -} - -void RenderWidgetHostViewGtk::SetSize(const gfx::Size& size) { - int width = std::min(size.width(), kMaxWindowWidth); - int height = std::min(size.height(), kMaxWindowHeight); - if (IsPopup()) { - // We're a popup, honor the size request. - gtk_widget_set_size_request(view_.get(), width, height); - } - - // Update the size of the RWH. - if (requested_size_.width() != width || - requested_size_.height() != height) { - requested_size_ = gfx::Size(width, height); - host_->SendScreenRects(); - host_->WasResized(); - } -} - -void RenderWidgetHostViewGtk::SetBounds(const gfx::Rect& rect) { - // This is called when webkit has sent us a Move message. - if (IsPopup()) { - gtk_window_move(GTK_WINDOW(gtk_widget_get_toplevel(view_.get())), - rect.x(), rect.y()); - } - - SetSize(rect.size()); -} - -gfx::NativeView RenderWidgetHostViewGtk::GetNativeView() const { - return view_.get(); -} - -gfx::NativeViewId RenderWidgetHostViewGtk::GetNativeViewId() const { - return GtkNativeViewManager::GetInstance()->GetIdForWidget(view_.get()); -} - -gfx::NativeViewAccessible RenderWidgetHostViewGtk::GetNativeViewAccessible() { - NOTIMPLEMENTED(); - return NULL; -} - -void RenderWidgetHostViewGtk::MovePluginWindows( - const gfx::Vector2d& scroll_offset, - const std::vector<WebPluginGeometry>& moves) { - for (size_t i = 0; i < moves.size(); ++i) { - plugin_container_manager_.MovePluginContainer(moves[i]); - } -} - -void RenderWidgetHostViewGtk::Focus() { - gtk_widget_grab_focus(view_.get()); -} - -void RenderWidgetHostViewGtk::Blur() { - // TODO(estade): We should be clearing native focus as well, but I know of no - // way to do that without focusing another widget. - host_->Blur(); -} - -bool RenderWidgetHostViewGtk::HasFocus() const { - return gtk_widget_has_focus(view_.get()); -} - -void RenderWidgetHostViewGtk::ActiveWindowChanged(GdkWindow* window) { - GdkWindow* our_window = gtk_widget_get_parent_window(view_.get()); - - if (our_window == window) - made_active_ = true; - - // If the window was previously active, but isn't active anymore, shut it - // down. - if (is_fullscreen_ && our_window != window && made_active_) - host_->Shutdown(); -} - -bool RenderWidgetHostViewGtk::Send(IPC::Message* message) { - return host_->Send(message); -} - -bool RenderWidgetHostViewGtk::IsSurfaceAvailableForCopy() const { - return true; -} - -void RenderWidgetHostViewGtk::Show() { - gtk_widget_show(view_.get()); - WasShown(); -} - -void RenderWidgetHostViewGtk::Hide() { - gtk_widget_hide(view_.get()); - WasHidden(); -} - -bool RenderWidgetHostViewGtk::IsShowing() { - return gtk_widget_get_visible(view_.get()); -} - -gfx::Rect RenderWidgetHostViewGtk::GetViewBounds() const { - GdkWindow* gdk_window = gtk_widget_get_window(view_.get()); - if (!gdk_window) - return gfx::Rect(requested_size_); - GdkRectangle window_rect; - gdk_window_get_origin(gdk_window, &window_rect.x, &window_rect.y); - return gfx::Rect(window_rect.x, window_rect.y, - requested_size_.width(), requested_size_.height()); -} - -void RenderWidgetHostViewGtk::UpdateCursor(const WebCursor& cursor) { - // Optimize the common case, where the cursor hasn't changed. - // However, we can switch between different pixmaps, so only on the - // non-pixmap branch. - if (current_cursor_.GetCursorType() != GDK_CURSOR_IS_PIXMAP && - current_cursor_.GetCursorType() == cursor.GetCursorType()) { - return; - } - - current_cursor_ = cursor; - ShowCurrentCursor(); -} - -void RenderWidgetHostViewGtk::SetIsLoading(bool is_loading) { - is_loading_ = is_loading; - // Only call ShowCurrentCursor() when it will actually change the cursor. - if (current_cursor_.GetCursorType() == GDK_LAST_CURSOR) - ShowCurrentCursor(); -} - -void RenderWidgetHostViewGtk::TextInputTypeChanged( - ui::TextInputType type, - ui::TextInputMode input_mode, - bool can_compose_inline) { - im_context_->UpdateInputMethodState(type, can_compose_inline); -} - -void RenderWidgetHostViewGtk::ImeCancelComposition() { - im_context_->CancelComposition(); -} - -void RenderWidgetHostViewGtk::DidUpdateBackingStore( - const gfx::Rect& scroll_rect, - const gfx::Vector2d& scroll_delta, - const std::vector<gfx::Rect>& copy_rects, - const std::vector<ui::LatencyInfo>& latency_info) { - TRACE_EVENT0("ui::gtk", "RenderWidgetHostViewGtk::DidUpdateBackingStore"); - for (size_t i = 0; i < latency_info.size(); i++) - software_latency_info_.push_back(latency_info[i]); - - if (host_->is_hidden()) - return; - - // TODO(darin): Implement the equivalent of Win32's ScrollWindowEX. Can that - // be done using XCopyArea? Perhaps similar to - // BackingStore::ScrollBackingStore? - if (about_to_validate_and_paint_) - invalid_rect_.Union(scroll_rect); - else - Paint(scroll_rect); - - for (size_t i = 0; i < copy_rects.size(); ++i) { - // Avoid double painting. NOTE: This is only relevant given the call to - // Paint(scroll_rect) above. - gfx::Rect rect = gfx::SubtractRects(copy_rects[i], scroll_rect); - if (rect.IsEmpty()) - continue; - - if (about_to_validate_and_paint_) - invalid_rect_.Union(rect); - else - Paint(rect); - } -} - -void RenderWidgetHostViewGtk::RenderProcessGone(base::TerminationStatus status, - int error_code) { - Destroy(); - plugin_container_manager_.set_host_widget(NULL); -} - -void RenderWidgetHostViewGtk::Destroy() { - if (compositing_surface_ != gfx::kNullPluginWindow) { - GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); - manager->ReleasePermanentXID(compositing_surface_); - } - - if (do_x_grab_) { - // Undo the X grab. - GdkDisplay* display = gtk_widget_get_display(parent_); - gdk_display_pointer_ungrab(display, GDK_CURRENT_TIME); - gdk_display_keyboard_ungrab(display, GDK_CURRENT_TIME); - } - - if (view_.get()) { - // If this is a popup or fullscreen widget, then we need to destroy the - // window that we created to hold it. - if (IsPopup() || is_fullscreen_) { - GtkWidget* window = gtk_widget_get_parent(view_.get()); - - ui::ActiveWindowWatcherX::RemoveObserver(this); - - // Disconnect the destroy handler so that we don't try to shutdown twice. - if (is_fullscreen_) - g_signal_handler_disconnect(window, destroy_handler_id_); - - gtk_widget_destroy(window); - } - - // Remove |view_| from all containers now, so nothing else can hold a - // reference to |view_|'s widget except possibly a gtk signal handler if - // this code is currently executing within the context of a gtk signal - // handler. Note that |view_| is still alive after this call. It will be - // deallocated in the destructor. - // See http://crbug.com/11847 for details. - gtk_widget_destroy(view_.get()); - } - - // The RenderWidgetHost's destruction led here, so don't call it. - host_ = NULL; - - base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} - -void RenderWidgetHostViewGtk::SetTooltipText( - const base::string16& tooltip_text) { - // Maximum number of characters we allow in a tooltip. - const int kMaxTooltipLength = 8 << 10; - // Clamp the tooltip length to kMaxTooltipLength so that we don't - // accidentally DOS the user with a mega tooltip (since GTK doesn't do - // this itself). - // I filed https://bugzilla.gnome.org/show_bug.cgi?id=604641 upstream. - const base::string16 clamped_tooltip = - gfx::TruncateString(tooltip_text, kMaxTooltipLength); - - if (clamped_tooltip.empty()) { - gtk_widget_set_has_tooltip(view_.get(), FALSE); - } else { - gtk_widget_set_tooltip_text(view_.get(), - base::UTF16ToUTF8(clamped_tooltip).c_str()); - } -} - -void RenderWidgetHostViewGtk::SelectionChanged(const base::string16& text, - size_t offset, - const gfx::Range& range) { - RenderWidgetHostViewBase::SelectionChanged(text, offset, range); - - if (text.empty() || range.is_empty()) - return; - size_t pos = range.GetMin() - offset; - size_t n = range.length(); - - DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; - if (pos >= text.length()) { - NOTREACHED() << "The text can not cover range."; - return; - } - - // Set the CLIPBOARD_TYPE SELECTION to the ui::Clipboard. - ui::ScopedClipboardWriter clipboard_writer( - ui::Clipboard::GetForCurrentThread(), - ui::CLIPBOARD_TYPE_SELECTION); - clipboard_writer.WriteText(text.substr(pos, n)); -} - -void RenderWidgetHostViewGtk::SelectionBoundsChanged( - const ViewHostMsg_SelectionBounds_Params& params) { - im_context_->UpdateCaretBounds( - gfx::UnionRects(params.anchor_rect, params.focus_rect)); -} - -void RenderWidgetHostViewGtk::ScrollOffsetChanged() { -} - -GdkEventButton* RenderWidgetHostViewGtk::GetLastMouseDown() { - return last_mouse_down_; -} - -gfx::NativeView RenderWidgetHostViewGtk::BuildInputMethodsGtkMenu() { - return im_context_->BuildInputMethodsGtkMenu(); -} - -void RenderWidgetHostViewGtk::OnDestroy(GtkWidget* widget) { - DCHECK(is_fullscreen_); - host_->Shutdown(); -} - -bool RenderWidgetHostViewGtk::NeedsInputGrab() { - return popup_type_ == blink::WebPopupTypeSelect; -} - -bool RenderWidgetHostViewGtk::IsPopup() const { - return popup_type_ != blink::WebPopupTypeNone; -} - -void RenderWidgetHostViewGtk::DoSharedInit() { - view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); - im_context_.reset(new GtkIMContextWrapper(this)); - plugin_container_manager_.set_host_widget(view_.get()); - key_bindings_handler_.reset(new GtkKeyBindingsHandler(view_.get())); -} - -void RenderWidgetHostViewGtk::DoPopupOrFullscreenInit(GtkWindow* window, - const gfx::Rect& bounds) { - requested_size_.SetSize(std::min(bounds.width(), kMaxWindowWidth), - std::min(bounds.height(), kMaxWindowHeight)); - host_->WasResized(); - - ui::ActiveWindowWatcherX::AddObserver(this); - - // Don't set the size when we're going fullscreen. This can confuse the - // window manager into thinking we're resizing a fullscreen window and - // therefore not fullscreen anymore. - if (!is_fullscreen_) { - gtk_widget_set_size_request( - view_.get(), requested_size_.width(), requested_size_.height()); - - // Don't allow the window to be resized. This also forces the window to - // shrink down to the size of its child contents. - gtk_window_set_resizable(window, FALSE); - gtk_window_set_default_size(window, -1, -1); - gtk_window_move(window, bounds.x(), bounds.y()); - } - - gtk_widget_show_all(GTK_WIDGET(window)); -} - -BackingStore* RenderWidgetHostViewGtk::AllocBackingStore( - const gfx::Size& size) { - gint depth = gdk_visual_get_depth(gtk_widget_get_visual(view_.get())); - return new BackingStoreGtk(host_, size, - ui::GetVisualFromGtkWidget(view_.get()), - depth); -} - -// NOTE: |output| is initialized with the size of |src_subrect|, and |dst_size| -// is ignored on GTK. -void RenderWidgetHostViewGtk::CopyFromCompositingSurface( - const gfx::Rect& src_subrect, - const gfx::Size& /* dst_size */, - const base::Callback<void(bool, const SkBitmap&)>& callback, - SkBitmap::Config config) { - if (config != SkBitmap::kARGB_8888_Config) { - NOTIMPLEMENTED(); - callback.Run(false, SkBitmap()); - } - // Grab the snapshot from the renderer as that's the only reliable way to - // readback from the GPU for this platform right now. - GetRenderWidgetHost()->GetSnapshotFromRenderer(src_subrect, callback); -} - -void RenderWidgetHostViewGtk::CopyFromCompositingSurfaceToVideoFrame( - const gfx::Rect& src_subrect, - const scoped_refptr<media::VideoFrame>& target, - const base::Callback<void(bool)>& callback) { - NOTIMPLEMENTED(); - callback.Run(false); -} - -bool RenderWidgetHostViewGtk::CanCopyToVideoFrame() const { - return false; -} - -void RenderWidgetHostViewGtk::AcceleratedSurfaceInitialized(int host_id, - int route_id) { -} - -void RenderWidgetHostViewGtk::AcceleratedSurfaceBuffersSwapped( - const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, - int gpu_host_id) { - AcceleratedSurfaceMsg_BufferPresented_Params ack_params; - ack_params.sync_point = 0; - RenderWidgetHostImpl::AcknowledgeBufferPresent( - params.route_id, gpu_host_id, ack_params); - RenderWidgetHostImpl::CompositorFrameDrawn(params.latency_info); -} - -void RenderWidgetHostViewGtk::AcceleratedSurfacePostSubBuffer( - const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, - int gpu_host_id) { - AcceleratedSurfaceMsg_BufferPresented_Params ack_params; - ack_params.sync_point = 0; - RenderWidgetHostImpl::AcknowledgeBufferPresent( - params.route_id, gpu_host_id, ack_params); - RenderWidgetHostImpl::CompositorFrameDrawn(params.latency_info); -} - -void RenderWidgetHostViewGtk::AcceleratedSurfaceSuspend() { -} - -void RenderWidgetHostViewGtk::AcceleratedSurfaceRelease() { -} - -bool RenderWidgetHostViewGtk::HasAcceleratedSurface( - const gfx::Size& desired_size) { - // TODO(jbates) Implement this so this view can use GetBackingStore for both - // software and GPU frames. Defaulting to false just makes GetBackingStore - // only useable for software frames. - return false; -} - -void RenderWidgetHostViewGtk::SetBackground(const SkBitmap& background) { - RenderWidgetHostViewBase::SetBackground(background); - Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); -} - -void RenderWidgetHostViewGtk::ModifyEventForEdgeDragging( - GtkWidget* widget, GdkEventMotion* event) { - // If the widget is aligned with an edge of the monitor its on and the user - // attempts to drag past that edge we track the number of times it has - // occurred, so that we can force the widget to scroll when it otherwise - // would be unable to, by modifying the (x,y) position in the drag - // event that we forward on to webkit. If we get a move that's no longer a - // drag or a drag indicating the user is no longer at that edge we stop - // altering the drag events. - int new_dragged_at_horizontal_edge = 0; - int new_dragged_at_vertical_edge = 0; - // Used for checking the edges of the monitor. We cache the values to save - // roundtrips to the X server. - CR_DEFINE_STATIC_LOCAL(gfx::Size, drag_monitor_size, ()); - if (event->state & GDK_BUTTON1_MASK) { - if (drag_monitor_size.IsEmpty()) { - // We can safely cache the monitor size for the duration of a drag. - GdkScreen* screen = gtk_widget_get_screen(widget); - int monitor = - gdk_screen_get_monitor_at_point(screen, event->x_root, event->y_root); - GdkRectangle geometry; - gdk_screen_get_monitor_geometry(screen, monitor, &geometry); - drag_monitor_size.SetSize(geometry.width, geometry.height); - } - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); - // Check X and Y independently, as the user could be dragging into a corner. - if (event->x == 0 && event->x_root == 0) { - new_dragged_at_horizontal_edge = dragged_at_horizontal_edge_ - 1; - } else if (allocation.width - 1 == static_cast<gint>(event->x) && - drag_monitor_size.width() - 1 == static_cast<gint>(event->x_root)) { - new_dragged_at_horizontal_edge = dragged_at_horizontal_edge_ + 1; - } - - if (event->y == 0 && event->y_root == 0) { - new_dragged_at_vertical_edge = dragged_at_vertical_edge_ - 1; - } else if (allocation.height - 1 == static_cast<gint>(event->y) && - drag_monitor_size.height() - 1 == static_cast<gint>(event->y_root)) { - new_dragged_at_vertical_edge = dragged_at_vertical_edge_ + 1; - } - - event->x_root += new_dragged_at_horizontal_edge; - event->x += new_dragged_at_horizontal_edge; - event->y_root += new_dragged_at_vertical_edge; - event->y += new_dragged_at_vertical_edge; - } else { - // Clear whenever we get a non-drag mouse move. - drag_monitor_size.SetSize(0, 0); - } - dragged_at_horizontal_edge_ = new_dragged_at_horizontal_edge; - dragged_at_vertical_edge_ = new_dragged_at_vertical_edge; -} - -void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) { - TRACE_EVENT0("ui::gtk", "RenderWidgetHostViewGtk::Paint"); - - // If the GPU process is rendering directly into the View, - // call the compositor directly. - RenderWidgetHostImpl* render_widget_host = - RenderWidgetHostImpl::From(GetRenderWidgetHost()); - if (render_widget_host->is_accelerated_compositing_active()) { - host_->ScheduleComposite(); - return; - } - - GdkWindow* window = gtk_widget_get_window(view_.get()); - DCHECK(!about_to_validate_and_paint_); - - invalid_rect_ = damage_rect; - about_to_validate_and_paint_ = true; - - // If the size of our canvas is (0,0), then we don't want to block here. We - // are doing one of our first paints and probably have animations going on. - bool force_create = !host_->empty(); - BackingStoreGtk* backing_store = static_cast<BackingStoreGtk*>( - host_->GetBackingStore(force_create)); - // Calling GetBackingStore maybe have changed |invalid_rect_|... - about_to_validate_and_paint_ = false; - - gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); - paint_rect.Intersect(invalid_rect_); - - if (backing_store) { - // Only render the widget if it is attached to a window; there's a short - // period where this object isn't attached to a window but hasn't been - // Destroy()ed yet and it receives paint messages... - if (window) { - backing_store->XShowRect(gfx::Point(0, 0), - paint_rect, ui::GetX11WindowFromGtkWidget(view_.get())); - } - if (!whiteout_start_time_.is_null()) { - base::TimeDelta whiteout_duration = base::TimeTicks::Now() - - whiteout_start_time_; - UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); - - // Reset the start time to 0 so that we start recording again the next - // time the backing store is NULL... - whiteout_start_time_ = base::TimeTicks(); - } - if (!web_contents_switch_paint_time_.is_null()) { - base::TimeDelta web_contents_switch_paint_duration = - base::TimeTicks::Now() - web_contents_switch_paint_time_; - UMA_HISTOGRAM_TIMES("MPArch.RWH_TabSwitchPaintDuration", - web_contents_switch_paint_duration); - // Reset web_contents_switch_paint_time_ to 0 so future tab selections are - // recorded. - web_contents_switch_paint_time_ = base::TimeTicks(); - } - - for (size_t i = 0; i < software_latency_info_.size(); i++) { - software_latency_info_[i].AddLatencyNumber( - ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); - render_widget_host->FrameSwapped(software_latency_info_[i]); - } - software_latency_info_.clear(); - } else { - if (window) - gdk_window_clear(window); - if (whiteout_start_time_.is_null()) - whiteout_start_time_ = base::TimeTicks::Now(); - } -} - -void RenderWidgetHostViewGtk::ShowCurrentCursor() { - // The widget may not have a window. If that's the case, abort mission. This - // is the same issue as that explained above in Paint(). - if (!gtk_widget_get_window(view_.get())) - return; - - // TODO(port): WebKit bug https://bugs.webkit.org/show_bug.cgi?id=16388 is - // that calling gdk_window_set_cursor repeatedly is expensive. We should - // avoid it here where possible. - GdkCursor* gdk_cursor; - if (current_cursor_.GetCursorType() == GDK_LAST_CURSOR) { - // Use MOZ_CURSOR_SPINNING if we are showing the default cursor and - // the page is loading. - gdk_cursor = is_loading_ ? GetMozSpinningCursor() : NULL; - } else { - gdk_cursor = current_cursor_.GetNativeCursor(); - } - gdk_window_set_cursor(gtk_widget_get_window(view_.get()), gdk_cursor); -} - -void RenderWidgetHostViewGtk::SetHasHorizontalScrollbar( - bool has_horizontal_scrollbar) { -} - -void RenderWidgetHostViewGtk::SetScrollOffsetPinning( - bool is_pinned_to_left, bool is_pinned_to_right) { -} - - -void RenderWidgetHostViewGtk::OnAcceleratedCompositingStateChange() { - bool activated = host_->is_accelerated_compositing_active(); - GtkPreserveWindow* widget = reinterpret_cast<GtkPreserveWindow*>(view_.get()); - - gtk_preserve_window_delegate_resize(widget, activated); -} - -void RenderWidgetHostViewGtk::GetScreenInfo(WebScreenInfo* results) { - GdkWindow* gdk_window = gtk_widget_get_window(view_.get()); - if (!gdk_window) { - GdkDisplay* display = gdk_display_get_default(); - gdk_window = gdk_display_get_default_group(display); - } - if (!gdk_window) - return; - GetScreenInfoFromNativeWindow(gdk_window, results); -} - -gfx::Rect RenderWidgetHostViewGtk::GetBoundsInRootWindow() { - GtkWidget* toplevel = gtk_widget_get_toplevel(view_.get()); - if (!toplevel) - return GetViewBounds(); - - GdkRectangle frame_extents; - GdkWindow* gdk_window = gtk_widget_get_window(toplevel); - if (!gdk_window) - return GetViewBounds(); - - gdk_window_get_frame_extents(gdk_window, &frame_extents); - return gfx::Rect(frame_extents.x, frame_extents.y, - frame_extents.width, frame_extents.height); -} - -gfx::GLSurfaceHandle RenderWidgetHostViewGtk::GetCompositingSurface() { - if (compositing_surface_ == gfx::kNullPluginWindow) { - GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); - gfx::NativeViewId view_id = GetNativeViewId(); - - if (!manager->GetPermanentXIDForId(&compositing_surface_, view_id)) { - DLOG(ERROR) << "Can't find XID for view id " << view_id; - } - } - return gfx::GLSurfaceHandle(compositing_surface_, gfx::NATIVE_TRANSPORT); -} - -void RenderWidgetHostViewGtk::ResizeCompositingSurface(const gfx::Size& size) { - GtkWidget* widget = view_.get(); - GdkWindow* window = gtk_widget_get_window(widget); - if (window) { - Display* display = GDK_WINDOW_XDISPLAY(window); - gdk_window_resize(window, size.width(), size.height()); - XSync(display, False); - } -} - -bool RenderWidgetHostViewGtk::LockMouse() { - if (mouse_locked_) - return true; - - mouse_locked_ = true; - - // Release any current grab. - GtkWidget* current_grab_window = gtk_grab_get_current(); - if (current_grab_window) { - gtk_grab_remove(current_grab_window); - LOG(WARNING) << "Locking Mouse with gdk_pointer_grab, " - << "but had to steal grab from another window"; - } - - GtkWidget* widget = view_.get(); - GdkWindow* window = gtk_widget_get_window(widget); - GdkCursor* cursor = gdk_cursor_new(GDK_BLANK_CURSOR); - - GdkGrabStatus grab_status = - gdk_pointer_grab(window, - FALSE, // owner_events - static_cast<GdkEventMask>( - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK), - window, // confine_to - cursor, - GDK_CURRENT_TIME); - - if (grab_status != GDK_GRAB_SUCCESS) { - LOG(WARNING) << "Failed to grab pointer for LockMouse. " - << "gdk_pointer_grab returned: " << grab_status; - mouse_locked_ = false; - return false; - } - - // Clear the tooltip window. - SetTooltipText(base::string16()); - - // Ensure that the widget center location will be relevant for this mouse - // lock session. It is updated whenever the window geometry moves - // but may be out of date due to switching tabs. - MarkCachedWidgetCenterStale(); - - // Ensure that if we were previously warping the cursor to a specific point - // that we no longer track doing so when entering lock. It should be cleared - // by the cursor moving to the warp point, and this shouldn't be necessary. - // But, this is a small effort to ensure robustness in the event a warp isn't - // completed. - mouse_is_being_warped_to_unlocked_position_ = false; - - return true; -} - -void RenderWidgetHostViewGtk::UnlockMouse() { - if (!mouse_locked_) - return; - - mouse_locked_ = false; - - GtkWidget* widget = view_.get(); - GdkDisplay* display = gtk_widget_get_display(widget); - GdkScreen* screen = gtk_widget_get_screen(widget); - gdk_display_pointer_ungrab(display, GDK_CURRENT_TIME); - gdk_display_warp_pointer(display, screen, - unlocked_global_mouse_position_.x(), - unlocked_global_mouse_position_.y()); - mouse_is_being_warped_to_unlocked_position_ = true; - - if (host_) - host_->LostMouseLock(); -} - -void RenderWidgetHostViewGtk::ForwardKeyboardEvent( - const NativeWebKeyboardEvent& event) { - if (!host_) - return; - - EditCommands edit_commands; - if (!event.skip_in_browser && - key_bindings_handler_->Match(event, &edit_commands)) { - Send(new InputMsg_SetEditCommandsForNextKeyEvent( - host_->GetRoutingID(), edit_commands)); - NativeWebKeyboardEvent copy_event(event); - copy_event.match_edit_command = true; - host_->ForwardKeyboardEvent(copy_event); - return; - } - - host_->ForwardKeyboardEvent(event); -} - -bool RenderWidgetHostViewGtk::RetrieveSurrounding(std::string* text, - size_t* cursor_index) { - if (!selection_range_.IsValid()) - return false; - - size_t offset = selection_range_.GetMin() - selection_text_offset_; - DCHECK(offset <= selection_text_.length()); - - if (offset == selection_text_.length()) { - *text = base::UTF16ToUTF8(selection_text_); - *cursor_index = text->length(); - return true; - } - - *text = base::UTF16ToUTF8AndAdjustOffset( - base::StringPiece16(selection_text_), &offset); - if (offset == base::string16::npos) { - NOTREACHED() << "Invalid offset in UTF16 string."; - return false; - } - *cursor_index = offset; - return true; -} - -void RenderWidgetHostViewGtk::set_last_mouse_down(GdkEventButton* event) { - GdkEventButton* temp = NULL; - if (event) { - temp = reinterpret_cast<GdkEventButton*>( - gdk_event_copy(reinterpret_cast<GdkEvent*>(event))); - } - - if (last_mouse_down_) - gdk_event_free(reinterpret_cast<GdkEvent*>(last_mouse_down_)); - - last_mouse_down_ = temp; -} - -void RenderWidgetHostViewGtk::MarkCachedWidgetCenterStale() { - widget_center_valid_ = false; - mouse_has_been_warped_to_new_center_ = false; -} - -gfx::Point RenderWidgetHostViewGtk::GetWidgetCenter() { - if (widget_center_valid_) - return widget_center_; - - GdkWindow* window = gtk_widget_get_window(view_.get()); - gint window_x = 0; - gint window_y = 0; - gdk_window_get_origin(window, &window_x, &window_y); - gint window_w = gdk_window_get_width(window); - gint window_h = gdk_window_get_height(window); - widget_center_.SetPoint(window_x + window_w / 2, - window_y + window_h / 2); - widget_center_valid_ = true; - return widget_center_; -} - -void RenderWidgetHostViewGtk::ModifyEventMovementAndCoords( - blink::WebMouseEvent* event) { - // Movement is computed by taking the difference of the new cursor position - // and the previous. Under mouse lock the cursor will be warped back to the - // center so that we are not limited by clipping boundaries. - // We do not measure movement as the delta from cursor to center because - // we may receive more mouse movement events before our warp has taken - // effect. - event->movementX = event->globalX - global_mouse_position_.x(); - event->movementY = event->globalY - global_mouse_position_.y(); - - // While the cursor is being warped back to the unlocked position, suppress - // the movement member data. - if (mouse_is_being_warped_to_unlocked_position_) { - event->movementX = 0; - event->movementY = 0; - if (MovedToPoint(*event, unlocked_global_mouse_position_)) - mouse_is_being_warped_to_unlocked_position_ = false; - } - - global_mouse_position_.SetPoint(event->globalX, event->globalY); - - // Under mouse lock, coordinates of mouse are locked to what they were when - // mouse lock was entered. - if (mouse_locked_) { - event->x = unlocked_mouse_position_.x(); - event->y = unlocked_mouse_position_.y(); - event->windowX = unlocked_mouse_position_.x(); - event->windowY = unlocked_mouse_position_.y(); - event->globalX = unlocked_global_mouse_position_.x(); - event->globalY = unlocked_global_mouse_position_.y(); - } else if (!mouse_is_being_warped_to_unlocked_position_) { - unlocked_mouse_position_.SetPoint(event->windowX, event->windowY); - unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// RenderWidgetHostView, public: - -// static -RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( - RenderWidgetHost* widget) { - return new RenderWidgetHostViewGtk(widget); -} - -// static -void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { - GdkWindow* gdk_window = - gdk_display_get_default_group(gdk_display_get_default()); - GetScreenInfoFromNativeWindow(gdk_window, results); -} - -void RenderWidgetHostViewGtk::SetAccessibilityFocus(int acc_obj_id) { - if (!host_) - return; - - host_->AccessibilitySetFocus(acc_obj_id); -} - -void RenderWidgetHostViewGtk::AccessibilityDoDefaultAction(int acc_obj_id) { - if (!host_) - return; - - host_->AccessibilityDoDefaultAction(acc_obj_id); -} - -void RenderWidgetHostViewGtk::AccessibilityScrollToMakeVisible( - int acc_obj_id, gfx::Rect subfocus) { - if (!host_) - return; - - host_->AccessibilityScrollToMakeVisible(acc_obj_id, subfocus); -} - -void RenderWidgetHostViewGtk::AccessibilityScrollToPoint( - int acc_obj_id, gfx::Point point) { - if (!host_) - return; - - host_->AccessibilityScrollToPoint(acc_obj_id, point); -} - -void RenderWidgetHostViewGtk::AccessibilitySetTextSelection( - int acc_obj_id, int start_offset, int end_offset) { - if (!host_) - return; - - host_->AccessibilitySetTextSelection(acc_obj_id, start_offset, end_offset); -} - -gfx::Point RenderWidgetHostViewGtk::GetLastTouchEventLocation() const { - // Not needed on Linux. - return gfx::Point(); -} - -void RenderWidgetHostViewGtk::FatalAccessibilityTreeError() { - if (host_) { - host_->FatalAccessibilityTreeError(); - SetBrowserAccessibilityManager(NULL); - } else { - CHECK(FALSE); - } -} - -void RenderWidgetHostViewGtk::CreateBrowserAccessibilityManagerIfNeeded() { - if (!GetBrowserAccessibilityManager()) { - GtkWidget* parent = gtk_widget_get_parent(view_.get()); - SetBrowserAccessibilityManager( - new BrowserAccessibilityManagerGtk( - parent, - BrowserAccessibilityManagerGtk::GetEmptyDocument(), - this)); - } -} - -AtkObject* RenderWidgetHostViewGtk::GetAccessible() { - if (!GetBrowserAccessibilityManager()) { - GtkWidget* parent = gtk_widget_get_parent(view_.get()); - SetBrowserAccessibilityManager( - new BrowserAccessibilityManagerGtk( - parent, - BrowserAccessibilityManagerGtk::GetEmptyDocument(), - this)); - } - BrowserAccessibilityGtk* root = - GetBrowserAccessibilityManager()->GetRoot()->ToBrowserAccessibilityGtk(); - - atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); - return root->GetAtkObject(); -} - -void RenderWidgetHostViewGtk::OnCreatePluginContainer( - gfx::PluginWindowHandle id) { - plugin_container_manager_.CreatePluginContainer(id); -} - -void RenderWidgetHostViewGtk::OnDestroyPluginContainer( - gfx::PluginWindowHandle id) { - plugin_container_manager_.DestroyPluginContainer(id); -} - -SkBitmap::Config RenderWidgetHostViewGtk::PreferredReadbackFormat() { - return SkBitmap::kARGB_8888_Config; -} - -} // namespace content diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.h b/content/browser/renderer_host/render_widget_host_view_gtk.h deleted file mode 100644 index a142c5a..0000000 --- a/content/browser/renderer_host/render_widget_host_view_gtk.h +++ /dev/null @@ -1,341 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_ -#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_ - -#include <gdk/gdk.h> - -#include <string> -#include <vector> - -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "content/browser/accessibility/browser_accessibility_manager.h" -#include "content/browser/renderer_host/gtk_plugin_container_manager.h" -#include "content/browser/renderer_host/render_widget_host_view_base.h" -#include "content/common/content_export.h" -#include "content/common/cursors/webcursor.h" -#include "ipc/ipc_sender.h" -#include "ui/base/gtk/gtk_signal.h" -#include "ui/base/gtk/gtk_signal_registrar.h" -#include "ui/base/gtk/owned_widget_gtk.h" -#include "ui/base/x/active_window_watcher_x_observer.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" - -typedef struct _GtkClipboard GtkClipboard; -typedef struct _GtkSelectionData GtkSelectionData; - -namespace content { -class GtkIMContextWrapper; -class GtkKeyBindingsHandler; -class RenderWidgetHost; -class RenderWidgetHostImpl; -struct NativeWebKeyboardEvent; - -// ----------------------------------------------------------------------------- -// See comments in render_widget_host_view.h about this class and its members. -// ----------------------------------------------------------------------------- -class CONTENT_EXPORT RenderWidgetHostViewGtk - : public RenderWidgetHostViewBase, - public BrowserAccessibilityDelegate, - public ui::ActiveWindowWatcherXObserver, - public IPC::Sender { - public: - virtual ~RenderWidgetHostViewGtk(); - - // RenderWidgetHostView implementation. - virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; - virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE; - virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE; - virtual void SetSize(const gfx::Size& size) OVERRIDE; - virtual void SetBounds(const gfx::Rect& rect) OVERRIDE; - virtual gfx::NativeView GetNativeView() const OVERRIDE; - virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; - virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; - virtual bool HasFocus() const OVERRIDE; - virtual bool IsSurfaceAvailableForCopy() const OVERRIDE; - virtual void Show() OVERRIDE; - virtual void Hide() OVERRIDE; - virtual bool IsShowing() OVERRIDE; - virtual gfx::Rect GetViewBounds() const OVERRIDE; - virtual GdkEventButton* GetLastMouseDown() OVERRIDE; - virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE; - virtual void SetBackground(const SkBitmap& background) OVERRIDE; - - // RenderWidgetHostViewPort implementation. - virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, - const gfx::Rect& pos) OVERRIDE; - virtual void InitAsFullscreen( - RenderWidgetHostView* reference_host_view) OVERRIDE; - virtual void WasShown() OVERRIDE; - virtual void WasHidden() OVERRIDE; - virtual void MovePluginWindows( - const gfx::Vector2d& scroll_offset, - const std::vector<WebPluginGeometry>& moves) OVERRIDE; - virtual void Focus() OVERRIDE; - virtual void Blur() OVERRIDE; - virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE; - virtual void SetIsLoading(bool is_loading) OVERRIDE; - virtual void TextInputTypeChanged(ui::TextInputType type, - ui::TextInputMode input_mode, - bool can_compose_inline) OVERRIDE; - virtual void ImeCancelComposition() OVERRIDE; - virtual void DidUpdateBackingStore( - const gfx::Rect& scroll_rect, - const gfx::Vector2d& scroll_delta, - const std::vector<gfx::Rect>& copy_rects, - const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE; - virtual void RenderProcessGone(base::TerminationStatus status, - int error_code) OVERRIDE; - virtual void Destroy() OVERRIDE; - virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) {} - virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE; - virtual void SelectionChanged(const base::string16& text, - size_t offset, - const gfx::Range& range) OVERRIDE; - virtual void SelectionBoundsChanged( - const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE; - virtual void ScrollOffsetChanged() OVERRIDE; - virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; - virtual void CopyFromCompositingSurface( - const gfx::Rect& src_subrect, - const gfx::Size& dst_size, - const base::Callback<void(bool, const SkBitmap&)>& callback, - SkBitmap::Config config) OVERRIDE; - virtual void CopyFromCompositingSurfaceToVideoFrame( - const gfx::Rect& src_subrect, - const scoped_refptr<media::VideoFrame>& target, - const base::Callback<void(bool)>& callback) OVERRIDE; - virtual bool CanCopyToVideoFrame() const OVERRIDE; - virtual void OnAcceleratedCompositingStateChange() OVERRIDE; - virtual void AcceleratedSurfaceInitialized(int host_id, - int route_id) OVERRIDE; - virtual void AcceleratedSurfaceBuffersSwapped( - const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, - int gpu_host_id) OVERRIDE; - virtual void AcceleratedSurfacePostSubBuffer( - const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, - int gpu_host_id) OVERRIDE; - virtual void AcceleratedSurfaceSuspend() OVERRIDE; - virtual void AcceleratedSurfaceRelease() OVERRIDE; - virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE; - virtual void SetHasHorizontalScrollbar( - bool has_horizontal_scrollbar) OVERRIDE; - virtual void SetScrollOffsetPinning( - bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE; - virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE; - virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE; - virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE; - virtual void ResizeCompositingSurface(const gfx::Size&) OVERRIDE; - virtual bool LockMouse() OVERRIDE; - virtual void UnlockMouse() OVERRIDE; - virtual void CreateBrowserAccessibilityManagerIfNeeded() OVERRIDE; - - // ActiveWindowWatcherXObserver implementation. - virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; - - // IPC::Sender implementation: - virtual bool Send(IPC::Message* message) OVERRIDE; - - // If the widget is aligned with an edge of the monitor its on and the user - // attempts to drag past that edge we track the number of times it has - // occurred, so that we can force the widget to scroll when it otherwise - // would be unable to. - void ModifyEventForEdgeDragging(GtkWidget* widget, GdkEventMotion* event); - - // Mouse events always provide a movementX/Y which needs to be computed. - // Also, mouse lock requires knowledge of last unlocked cursor coordinates. - // State is stored on the host view to do this, and the mouse event modified. - void ModifyEventMovementAndCoords(blink::WebMouseEvent* event); - - void Paint(const gfx::Rect&); - - // Called by GtkIMContextWrapper to forward a keyboard event to renderer. - // On Linux (not ChromeOS): - // Before calling RenderWidgetHost::ForwardKeyboardEvent(), this method - // calls GtkKeyBindingsHandler::Match() against the event and send matched - // edit commands to renderer by calling - // RenderWidgetHost::ForwardEditCommandsForNextKeyEvent(). - void ForwardKeyboardEvent(const NativeWebKeyboardEvent& event); - - bool RetrieveSurrounding(std::string* text, size_t* cursor_index); - - // BrowserAccessibilityDelegate implementation. - virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE; - virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE; - virtual void AccessibilityScrollToMakeVisible( - int acc_obj_id, gfx::Rect subfocus) OVERRIDE; - virtual void AccessibilityScrollToPoint( - int acc_obj_id, gfx::Point point) OVERRIDE; - virtual void AccessibilitySetTextSelection( - int acc_obj_id, int start_offset, int end_offset) OVERRIDE; - virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE; - virtual void FatalAccessibilityTreeError() OVERRIDE; - - virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE; - - // Get the root of the AtkObject* tree for accessibility. - AtkObject* GetAccessible(); - - protected: - friend class RenderWidgetHostView; - - // Should construct only via RenderWidgetHostView::CreateViewForWidget. - explicit RenderWidgetHostViewGtk(RenderWidgetHost* widget); - - private: - friend class RenderWidgetHostViewGtkWidget; - - CHROMEGTK_CALLBACK_0(RenderWidgetHostViewGtk, - void, - OnDestroy); - - // Returns whether the widget needs an input grab (GTK+ and X) to work - // properly. - bool NeedsInputGrab(); - - // Returns whether this render view is a popup (<select> dropdown or - // autocomplete window). - bool IsPopup() const; - - // Do initialization needed by all InitAs*() methods. - void DoSharedInit(); - - // Do initialization needed just by InitAsPopup() and InitAsFullscreen(). - // We move and resize |window| to |bounds| and show it and its contents. - void DoPopupOrFullscreenInit(GtkWindow* window, const gfx::Rect& bounds); - - // Update the display cursor for the render view. - void ShowCurrentCursor(); - - void set_last_mouse_down(GdkEventButton* event); - - // Cause the next query for the widget center to recompute the cached value. - void MarkCachedWidgetCenterStale(); - - void OnCreatePluginContainer(gfx::PluginWindowHandle id); - void OnDestroyPluginContainer(gfx::PluginWindowHandle id); - - gfx::Point GetWidgetCenter(); - - // The model object. - RenderWidgetHostImpl* host_; - - // The native UI widget. - ui::OwnedWidgetGtk view_; - - // This is true when we are currently painting and thus should handle extra - // paint requests by expanding the invalid rect rather than actually - // painting. - bool about_to_validate_and_paint_; - - // This is the rectangle which we'll paint. - gfx::Rect invalid_rect_; - - // Whether we are currently loading. - bool is_loading_; - - // The cursor for the page. This is passed up from the renderer. - WebCursor current_cursor_; - - // The time at which this view started displaying white pixels as a result of - // not having anything to paint (empty backing store from renderer). This - // value returns true for is_null() if we are not recording whiteout times. - base::TimeTicks whiteout_start_time_; - - // The time it took after this view was selected for it to be fully painted. - base::TimeTicks web_contents_switch_paint_time_; - - // The native view of our parent widget. Used only for popups. - GtkWidget* parent_; - - // We ignore the first mouse release on popups so the popup will remain open. - bool is_popup_first_mouse_release_; - - // Whether or not this widget's input context was focused before being - // shadowed by another widget. Used in OnGrabNotify() handler to track the - // focused state correctly. - bool was_imcontext_focused_before_grab_; - - // True if we are responsible for creating an X grab. This will only be used - // for <select> dropdowns. It should be true for most such cases, but false - // for extension popups. - bool do_x_grab_; - - // Is the widget fullscreen? - bool is_fullscreen_; - - // Has the window ever been marked active? Only valid for fullscreen or - // popup windows. - bool made_active_; - - // Used to record the last position of the mouse. - // While the mouse is locked, they store the last known position just as mouse - // lock was entered. - // Relative to the upper-left corner of the view. - gfx::Point unlocked_mouse_position_; - // Relative to the upper-left corner of the screen. - gfx::Point unlocked_global_mouse_position_; - // Last hidden cursor position. Relative to screen. - gfx::Point global_mouse_position_; - // Indicates when mouse motion is valid after the widget has moved. - bool mouse_has_been_warped_to_new_center_; - // Indicates the cursor has been warped to the unlocked position, - // but a move event has not yet been received for it there. - bool mouse_is_being_warped_to_unlocked_position_; - - // For full-screen windows we have a OnDestroy handler that we need to remove, - // so we keep it ID here. - unsigned long destroy_handler_id_; - - // A convenience wrapper object for GtkIMContext; - scoped_ptr<GtkIMContextWrapper> im_context_; - - // A convenience object for handling editor key bindings defined in gtk - // keyboard theme. - scoped_ptr<GtkKeyBindingsHandler> key_bindings_handler_; - - // Helper class that lets us allocate plugin containers and move them. - GtkPluginContainerManager plugin_container_manager_; - - // The size that we want the renderer to be. We keep this in a separate - // variable because resizing in GTK+ is async. - gfx::Size requested_size_; - - // The latest reported center of the widget, use GetWidgetCenter() to access. - gfx::Point widget_center_; - // If the window moves the widget_center will not be valid until we recompute. - bool widget_center_valid_; - - // The number of times the user has dragged against horizontal edge of the - // monitor (if the widget is aligned with that edge). Negative values - // indicate the left edge, positive the right. - int dragged_at_horizontal_edge_; - - // The number of times the user has dragged against vertical edge of the - // monitor (if the widget is aligned with that edge). Negative values - // indicate the top edge, positive the bottom. - int dragged_at_vertical_edge_; - - gfx::PluginWindowHandle compositing_surface_; - - // The event for the last mouse down we handled. We need this for context - // menus and drags. - GdkEventButton* last_mouse_down_; - - // Instance of accessibility information for the root of the AtkObject - // tree representation of the WebKit render tree. - scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_; - - ui::GtkSignalRegistrar signals_; - - std::vector<ui::LatencyInfo> software_latency_info_; -}; - -} // namespace content - -#endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_ diff --git a/content/browser/web_contents/drag_utils_gtk.cc b/content/browser/web_contents/drag_utils_gtk.cc deleted file mode 100644 index 279ae9d..0000000 --- a/content/browser/web_contents/drag_utils_gtk.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/web_contents/drag_utils_gtk.h" - -using blink::WebDragOperationsMask; -using blink::WebDragOperation; -using blink::WebDragOperationNone; -using blink::WebDragOperationCopy; -using blink::WebDragOperationLink; -using blink::WebDragOperationMove; - -namespace content { - -GdkDragAction WebDragOpToGdkDragAction(WebDragOperationsMask op) { - GdkDragAction action = static_cast<GdkDragAction>(0); - if (op & WebDragOperationCopy) - action = static_cast<GdkDragAction>(action | GDK_ACTION_COPY); - if (op & WebDragOperationLink) - action = static_cast<GdkDragAction>(action | GDK_ACTION_LINK); - if (op & WebDragOperationMove) - action = static_cast<GdkDragAction>(action | GDK_ACTION_MOVE); - return action; -} - -WebDragOperationsMask GdkDragActionToWebDragOp(GdkDragAction action) { - WebDragOperationsMask op = WebDragOperationNone; - if (action & GDK_ACTION_COPY) - op = static_cast<WebDragOperationsMask>(op | WebDragOperationCopy); - if (action & GDK_ACTION_LINK) - op = static_cast<WebDragOperationsMask>(op | WebDragOperationLink); - if (action & GDK_ACTION_MOVE) - op = static_cast<WebDragOperationsMask>(op | WebDragOperationMove); - return op; -} - -} // namespace content diff --git a/content/browser/web_contents/drag_utils_gtk.h b/content/browser/web_contents/drag_utils_gtk.h deleted file mode 100644 index f6d8839..0000000 --- a/content/browser/web_contents/drag_utils_gtk.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_WEB_CONTENTS_DRAG_UTILS_GTK_H_ -#define CONTENT_BROWSER_WEB_CONTENTS_DRAG_UTILS_GTK_H_ - -#include <gtk/gtk.h> - -#include "content/common/content_export.h" -#include "third_party/WebKit/public/web/WebDragOperation.h" - -namespace content { - -// Convenience methods for converting between web drag operations and the GDK -// equivalent. -CONTENT_EXPORT GdkDragAction WebDragOpToGdkDragAction( - blink::WebDragOperationsMask op); -CONTENT_EXPORT blink::WebDragOperationsMask GdkDragActionToWebDragOp( - GdkDragAction action); - -} // namespace content - -#endif // CONTENT_BROWSER_WEB_CONTENTS_DRAG_UTILS_GTK_H_ diff --git a/content/browser/web_contents/web_contents_view_gtk.cc b/content/browser/web_contents/web_contents_view_gtk.cc deleted file mode 100644 index 1e77e9f..0000000 --- a/content/browser/web_contents/web_contents_view_gtk.cc +++ /dev/null @@ -1,421 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/web_contents/web_contents_view_gtk.h" - -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include <algorithm> - -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "build/build_config.h" -#include "content/browser/frame_host/interstitial_page_impl.h" -#include "content/browser/renderer_host/render_view_host_factory.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/renderer_host/render_widget_host_view_gtk.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/browser/web_contents/web_drag_dest_gtk.h" -#include "content/browser/web_contents/web_drag_source_gtk.h" -#include "content/public/browser/web_contents_delegate.h" -#include "content/public/browser/web_contents_view_delegate.h" -#include "content/public/common/drop_data.h" -#include "ui/base/gtk/gtk_expanded_container.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -using blink::WebDragOperation; -using blink::WebDragOperationsMask; - -namespace content { -namespace { - -// Called when the mouse leaves the widget. We notify our delegate. -gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event, - WebContentsImpl* web_contents) { - if (web_contents->GetDelegate()) - web_contents->GetDelegate()->ContentsMouseEvent( - web_contents, gfx::Point(event->x_root, event->y_root), false); - return FALSE; -} - -// Called when the mouse moves within the widget. We notify our delegate. -gboolean OnMouseMove(GtkWidget* widget, GdkEventMotion* event, - WebContentsImpl* web_contents) { - if (web_contents->GetDelegate()) - web_contents->GetDelegate()->ContentsMouseEvent( - web_contents, gfx::Point(event->x_root, event->y_root), true); - return FALSE; -} - -// See tab_contents_view_views.cc for discussion of mouse scroll zooming. -gboolean OnMouseScroll(GtkWidget* widget, GdkEventScroll* event, - WebContentsImpl* web_contents) { - if ((event->state & gtk_accelerator_get_default_mod_mask()) != - GDK_CONTROL_MASK) { - return FALSE; - } - - WebContentsDelegate* delegate = web_contents->GetDelegate(); - if (!delegate) - return FALSE; - - if (!(event->direction == GDK_SCROLL_DOWN || - event->direction == GDK_SCROLL_UP)) { - return FALSE; - } - - delegate->ContentsZoomChange(event->direction == GDK_SCROLL_UP); - return TRUE; -} - -} // namespace - -WebContentsViewPort* CreateWebContentsView( - WebContentsImpl* web_contents, - WebContentsViewDelegate* delegate, - RenderViewHostDelegateView** render_view_host_delegate_view) { - WebContentsViewGtk* rv = new WebContentsViewGtk(web_contents, delegate); - *render_view_host_delegate_view = rv; - return rv; -} - -WebContentsViewGtk::WebContentsViewGtk( - WebContentsImpl* web_contents, - WebContentsViewDelegate* delegate) - : web_contents_(web_contents), - expanded_(gtk_expanded_container_new()), - delegate_(delegate) { - gtk_widget_set_name(expanded_.get(), "chrome-web-contents-view"); - g_signal_connect(expanded_.get(), "size-allocate", - G_CALLBACK(OnSizeAllocateThunk), this); - g_signal_connect(expanded_.get(), "child-size-request", - G_CALLBACK(OnChildSizeRequestThunk), this); - - gtk_widget_show(expanded_.get()); - drag_source_.reset(new WebDragSourceGtk(web_contents)); - - if (delegate_) - delegate_->Initialize(expanded_.get(), &focus_store_); -} - -WebContentsViewGtk::~WebContentsViewGtk() { - expanded_.Destroy(); -} - -gfx::NativeView WebContentsViewGtk::GetNativeView() const { - if (delegate_) - return delegate_->GetNativeView(); - - return expanded_.get(); -} - -gfx::NativeView WebContentsViewGtk::GetContentNativeView() const { - RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); - if (!rwhv) - return NULL; - return rwhv->GetNativeView(); -} - -gfx::NativeWindow WebContentsViewGtk::GetTopLevelNativeWindow() const { - GtkWidget* window = gtk_widget_get_ancestor(GetNativeView(), GTK_TYPE_WINDOW); - return window ? GTK_WINDOW(window) : NULL; -} - -void WebContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { - // This is used for positioning the download shelf arrow animation, - // as well as sizing some other widgets in Windows. In GTK the size is - // managed for us, so it appears to be only used for the download shelf - // animation. - int x = 0; - int y = 0; - GdkWindow* expanded_window = gtk_widget_get_window(expanded_.get()); - if (expanded_window) - gdk_window_get_origin(expanded_window, &x, &y); - - GtkAllocation allocation; - gtk_widget_get_allocation(expanded_.get(), &allocation); - out->SetRect(x + allocation.x, y + allocation.y, - requested_size_.width(), requested_size_.height()); -} - -void WebContentsViewGtk::OnTabCrashed(base::TerminationStatus status, - int error_code) { -} - -void WebContentsViewGtk::Focus() { - if (web_contents_->ShowingInterstitialPage()) { - web_contents_->GetInterstitialPage()->Focus(); - } else if (delegate_) { - delegate_->Focus(); - } -} - -void WebContentsViewGtk::SetInitialFocus() { - if (web_contents_->FocusLocationBarByDefault()) - web_contents_->SetFocusToLocationBar(false); - else - Focus(); -} - -void WebContentsViewGtk::StoreFocus() { - focus_store_.Store(GetNativeView()); -} - -void WebContentsViewGtk::RestoreFocus() { - if (focus_store_.widget()) - gtk_widget_grab_focus(focus_store_.widget()); - else - SetInitialFocus(); -} - -DropData* WebContentsViewGtk::GetDropData() const { - if (!drag_dest_) - return NULL; - return drag_dest_->current_drop_data(); -} - -gfx::Rect WebContentsViewGtk::GetViewBounds() const { - gfx::Rect rect; - GdkWindow* window = gtk_widget_get_window(GetNativeView()); - if (!window) { - rect.SetRect(0, 0, requested_size_.width(), requested_size_.height()); - return rect; - } - int x = 0, y = 0, w, h; - gdk_window_get_geometry(window, &x, &y, &w, &h, NULL); - rect.SetRect(x, y, w, h); - return rect; -} - -void WebContentsViewGtk::CreateView( - const gfx::Size& initial_size, gfx::NativeView context) { - requested_size_ = initial_size; -} - -RenderWidgetHostView* WebContentsViewGtk::CreateViewForWidget( - RenderWidgetHost* render_widget_host) { - if (render_widget_host->GetView()) { - // During testing, the view will already be set up in most cases to the - // test view, so we don't want to clobber it with a real one. To verify that - // this actually is happening (and somebody isn't accidentally creating the - // view twice), we check for the RVH Factory, which will be set when we're - // making special ones (which go along with the special views). - DCHECK(RenderViewHostFactory::has_factory()); - return render_widget_host->GetView(); - } - - RenderWidgetHostView* view = - RenderWidgetHostView::CreateViewForWidget(render_widget_host); - view->InitAsChild(NULL); - gfx::NativeView content_view = view->GetNativeView(); - g_signal_connect(content_view, "focus", G_CALLBACK(OnFocusThunk), this); - g_signal_connect(content_view, "leave-notify-event", - G_CALLBACK(OnLeaveNotify), web_contents_); - g_signal_connect(content_view, "motion-notify-event", - G_CALLBACK(OnMouseMove), web_contents_); - g_signal_connect(content_view, "scroll-event", - G_CALLBACK(OnMouseScroll), web_contents_); - gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | - GDK_POINTER_MOTION_MASK); - InsertIntoContentArea(content_view); - - if (render_widget_host->IsRenderView()) { - RenderViewHost* rvh = RenderViewHost::From(render_widget_host); - // If |rvh| is already the current render view host for the web contents, we - // need to initialize |drag_dest_| for drags to be properly handled. - // Otherwise, |drag_dest_| will be updated in RenderViewSwappedIn. The - // reason we can't simply check that this isn't a swapped-out view is - // because there are navigations that create non-swapped-out views that may - // never be displayed, e.g. a navigation that becomes a download. - if (rvh == web_contents_->GetRenderViewHost()) { - UpdateDragDest(rvh); - } - } - - return view; -} - -RenderWidgetHostView* WebContentsViewGtk::CreateViewForPopupWidget( - RenderWidgetHost* render_widget_host) { - return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); -} - -void WebContentsViewGtk::SetPageTitle(const base::string16& title) { - // Set the window name to include the page title so it's easier to spot - // when debugging (e.g. via xwininfo -tree). - gfx::NativeView content_view = GetContentNativeView(); - if (content_view) { - GdkWindow* content_window = gtk_widget_get_window(content_view); - if (content_window) { - gdk_window_set_title(content_window, base::UTF16ToUTF8(title).c_str()); - } - } -} - -void WebContentsViewGtk::SizeContents(const gfx::Size& size) { - // We don't need to manually set the size of of widgets in GTK+, but we do - // need to pass the sizing information on to the RWHV which will pass the - // sizing information on to the renderer. - requested_size_ = size; - RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetSize(size); -} - -void WebContentsViewGtk::RenderViewCreated(RenderViewHost* host) { -} - -void WebContentsViewGtk::RenderViewSwappedIn(RenderViewHost* host) { - UpdateDragDest(host); -} - -void WebContentsViewGtk::SetOverscrollControllerEnabled(bool enabled) { -} - -WebContents* WebContentsViewGtk::web_contents() { - return web_contents_; -} - -void WebContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { - if (!drag_dest_) - return; - drag_dest_->UpdateDragStatus(operation); -} - -void WebContentsViewGtk::GotFocus() { - // This is only used in the views FocusManager stuff but it bleeds through - // all subclasses. http://crbug.com/21875 -} - -// This is called when the renderer asks us to take focus back (i.e., it has -// iterated past the last focusable element on the page). -void WebContentsViewGtk::TakeFocus(bool reverse) { - if (!web_contents_->GetDelegate()) - return; - if (!web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse) && - GetTopLevelNativeWindow()) { - gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), - reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD); - } -} - -void WebContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { - gtk_container_add(GTK_CONTAINER(expanded_.get()), widget); -} - -void WebContentsViewGtk::UpdateDragDest(RenderViewHost* host) { - // Drag-and-drop is entirely managed by BrowserPluginGuest for guest - // processes in a largely platform independent way. WebDragDestGtk - // will result in spurious messages being sent to the guest process which - // will violate assumptions. - if (host->GetProcess() && host->GetProcess()->IsGuest()) { - DCHECK(!drag_dest_); - return; - } - - gfx::NativeView content_view = host->GetView()->GetNativeView(); - - // If the host is already used by the drag_dest_, there's no point in deleting - // the old one to create an identical copy. - if (drag_dest_.get() && drag_dest_->widget() == content_view) - return; - - // Clear the currently connected drag drop signals by deleting the old - // drag_dest_ before creating the new one. - drag_dest_.reset(); - // Create the new drag_dest_. - drag_dest_.reset(new WebDragDestGtk(web_contents_, content_view)); - - if (delegate_) - drag_dest_->set_delegate(delegate_->GetDragDestDelegate()); -} - -// Called when the content view gtk widget is tabbed to, or after the call to -// gtk_widget_child_focus() in TakeFocus(). We return true -// and grab focus if we don't have it. The call to -// FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to -// webkit. -gboolean WebContentsViewGtk::OnFocus(GtkWidget* widget, - GtkDirectionType focus) { - // Give our view wrapper first chance at this event. - if (delegate_) { - gboolean return_value = FALSE; - if (delegate_->OnNativeViewFocusEvent(widget, focus, &return_value)) - return return_value; - } - - // If we already have focus, let the next widget have a shot at it. We will - // reach this situation after the call to gtk_widget_child_focus() in - // TakeFocus(). - if (gtk_widget_is_focus(widget)) - return FALSE; - - gtk_widget_grab_focus(widget); - bool reverse = focus == GTK_DIR_TAB_BACKWARD; - web_contents_->FocusThroughTabTraversal(reverse); - return TRUE; -} - -void WebContentsViewGtk::ShowContextMenu(RenderFrameHost* render_frame_host, - const ContextMenuParams& params) { - if (delegate_) - delegate_->ShowContextMenu(render_frame_host, params); - else - DLOG(ERROR) << "Cannot show context menus without a delegate."; -} - -// Render view DnD ------------------------------------------------------------- - -void WebContentsViewGtk::StartDragging(const DropData& drop_data, - WebDragOperationsMask ops, - const gfx::ImageSkia& image, - const gfx::Vector2d& image_offset, - const DragEventSourceInfo& event_info) { - DCHECK(GetContentNativeView()); - - RenderWidgetHostViewGtk* view_gtk = static_cast<RenderWidgetHostViewGtk*>( - web_contents_->GetRenderWidgetHostView()); - if (!view_gtk || !view_gtk->GetLastMouseDown() || - !drag_source_->StartDragging(drop_data, ops, view_gtk->GetLastMouseDown(), - *image.bitmap(), image_offset)) { - web_contents_->SystemDragEnded(); - } -} - -// ----------------------------------------------------------------------------- - -void WebContentsViewGtk::OnChildSizeRequest(GtkWidget* widget, - GtkWidget* child, - GtkRequisition* requisition) { - if (web_contents_->GetDelegate()) { - requisition->height += - web_contents_->GetDelegate()->GetExtraRenderViewHeight(); - } -} - -void WebContentsViewGtk::OnSizeAllocate(GtkWidget* widget, - GtkAllocation* allocation) { - int width = allocation->width; - int height = allocation->height; - // |delegate()| can be NULL here during browser teardown. - if (web_contents_->GetDelegate()) - height += web_contents_->GetDelegate()->GetExtraRenderViewHeight(); - gfx::Size size(width, height); - requested_size_ = size; - - // We manually tell our RWHV to resize the renderer content. This avoids - // spurious resizes from GTK+. - RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetSize(size); - if (web_contents_->GetInterstitialPage()) - web_contents_->GetInterstitialPage()->SetSize(size); -} - -} // namespace content diff --git a/content/browser/web_contents/web_contents_view_gtk.h b/content/browser/web_contents/web_contents_view_gtk.h deleted file mode 100644 index ad575a3..0000000 --- a/content/browser/web_contents/web_contents_view_gtk.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_ -#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_ - -#include <gtk/gtk.h> - -#include <vector> - -#include "base/memory/scoped_ptr.h" -#include "content/common/content_export.h" -#include "content/common/drag_event_source_info.h" -#include "content/port/browser/render_view_host_delegate_view.h" -#include "content/port/browser/web_contents_view_port.h" -#include "ui/base/gtk/focus_store_gtk.h" -#include "ui/base/gtk/gtk_signal.h" -#include "ui/base/gtk/owned_widget_gtk.h" - -namespace content { - -class WebContents; -class WebContentsImpl; -class WebContentsViewDelegate; -class WebDragDestDelegate; -class WebDragDestGtk; -class WebDragSourceGtk; - -class CONTENT_EXPORT WebContentsViewGtk - : public WebContentsViewPort, - public RenderViewHostDelegateView { - public: - // The corresponding WebContentsImpl is passed in the constructor, and manages - // our lifetime. This doesn't need to be the case, but is this way currently - // because that's what was easiest when they were split. We optionally take - // |wrapper| which creates an intermediary widget layer for features from the - // Embedding layer that lives with the WebContentsView. - WebContentsViewGtk(WebContentsImpl* web_contents, - WebContentsViewDelegate* delegate); - virtual ~WebContentsViewGtk(); - - WebContentsViewDelegate* delegate() const { return delegate_.get(); } - WebContents* web_contents(); - - // WebContentsView implementation -------------------------------------------- - - virtual gfx::NativeView GetNativeView() const OVERRIDE; - virtual gfx::NativeView GetContentNativeView() const OVERRIDE; - virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; - virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE; - virtual void OnTabCrashed(base::TerminationStatus status, - int error_code) OVERRIDE; - virtual void SizeContents(const gfx::Size& size) OVERRIDE; - virtual void Focus() OVERRIDE; - virtual void SetInitialFocus() OVERRIDE; - virtual void StoreFocus() OVERRIDE; - virtual void RestoreFocus() OVERRIDE; - virtual DropData* GetDropData() const OVERRIDE; - virtual gfx::Rect GetViewBounds() const OVERRIDE; - - // WebContentsViewPort implementation ---------------------------------------- - virtual void CreateView( - const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE; - virtual RenderWidgetHostView* CreateViewForWidget( - RenderWidgetHost* render_widget_host) OVERRIDE; - virtual RenderWidgetHostView* CreateViewForPopupWidget( - RenderWidgetHost* render_widget_host) OVERRIDE; - virtual void SetPageTitle(const base::string16& title) OVERRIDE; - virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE; - virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE; - virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE; - - // Backend implementation of RenderViewHostDelegateView. - virtual void ShowContextMenu(RenderFrameHost* render_frame_host, - const ContextMenuParams& params) OVERRIDE; - virtual void StartDragging(const DropData& drop_data, - blink::WebDragOperationsMask allowed_ops, - const gfx::ImageSkia& image, - const gfx::Vector2d& image_offset, - const DragEventSourceInfo& event_info) OVERRIDE; - virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE; - virtual void GotFocus() OVERRIDE; - virtual void TakeFocus(bool reverse) OVERRIDE; - - private: - // Insert the given widget into the content area. Should only be used for - // web pages and the like (including interstitials and sad tab). Note that - // this will be perfectly happy to insert overlapping render views, so care - // should be taken that the correct one is hidden/shown. - void InsertIntoContentArea(GtkWidget* widget); - - // Replaces, or updates, the existing WebDragDestGtk with one for |new_host|. - // This must be called when swapping in, or creating a swapped in, RVH. - void UpdateDragDest(RenderViewHost* new_host); - - // Handle focus traversal on the render widget native view. Can be overridden - // by subclasses. - CHROMEGTK_CALLBACK_1(WebContentsViewGtk, gboolean, OnFocus, GtkDirectionType); - - // Used to adjust the size of its children when the size of |expanded_| is - // changed. - CHROMEGTK_CALLBACK_2(WebContentsViewGtk, void, OnChildSizeRequest, - GtkWidget*, GtkRequisition*); - - // Used to propagate the size change of |expanded_| to our RWHV to resize the - // renderer content. - CHROMEGTK_CALLBACK_1(WebContentsViewGtk, void, OnSizeAllocate, - GtkAllocation*); - - // The WebContentsImpl whose contents we display. - WebContentsImpl* web_contents_; - - // This container holds the tab's web page views. It is a GtkExpandedContainer - // so that we can control the size of the web pages. - ui::OwnedWidgetGtk expanded_; - - ui::FocusStoreGtk focus_store_; - - // The helper object that handles drag destination related interactions with - // GTK. - scoped_ptr<WebDragDestGtk> drag_dest_; - - // Object responsible for handling drags from the page for us. - scoped_ptr<WebDragSourceGtk> drag_source_; - - // Our optional views wrapper. If non-NULL, we return this widget as our - // GetNativeView() and insert |expanded_| as its child in the GtkWidget - // hierarchy. - scoped_ptr<WebContentsViewDelegate> delegate_; - - // The size we want the view to be. We keep this in a separate variable - // because resizing in GTK+ is async. - gfx::Size requested_size_; - - DISALLOW_COPY_AND_ASSIGN(WebContentsViewGtk); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_ diff --git a/content/browser/web_contents/web_drag_dest_gtk.cc b/content/browser/web_contents/web_drag_dest_gtk.cc deleted file mode 100644 index 2fae686..0000000 --- a/content/browser/web_contents/web_drag_dest_gtk.cc +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/web_contents/web_drag_dest_gtk.h" - -#include <string> - -#include "base/bind.h" -#include "base/files/file_path.h" -#include "base/message_loop/message_loop.h" -#include "base/strings/utf_string_conversions.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/web_contents/drag_utils_gtk.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/public/browser/web_contents_delegate.h" -#include "content/public/browser/web_drag_dest_delegate.h" -#include "content/public/common/url_constants.h" -#include "net/base/filename_util.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -#include "ui/base/clipboard/custom_data_helper.h" -#include "ui/base/dragdrop/gtk_dnd_util.h" -#include "ui/base/gtk/gtk_screen_util.h" - -using blink::WebDragOperation; -using blink::WebDragOperationNone; - -namespace content { - -namespace { -const int kNumGtkHandlers = 5; - -int GetModifierFlags(GtkWidget* widget) { - int modifier_state = 0; - GdkModifierType state; - gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, &state); - - if (state & GDK_SHIFT_MASK) - modifier_state |= blink::WebInputEvent::ShiftKey; - if (state & GDK_CONTROL_MASK) - modifier_state |= blink::WebInputEvent::ControlKey; - if (state & GDK_MOD1_MASK) - modifier_state |= blink::WebInputEvent::AltKey; - if (state & GDK_META_MASK) - modifier_state |= blink::WebInputEvent::MetaKey; - return modifier_state; -} - -} // namespace - -WebDragDestGtk::WebDragDestGtk(WebContents* web_contents, GtkWidget* widget) - : web_contents_(web_contents), - widget_(widget), - context_(NULL), - data_requests_(0), - delegate_(NULL), - canceled_(false), - method_factory_(this) { - gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), - NULL, 0, - static_cast<GdkDragAction>(GDK_ACTION_COPY | - GDK_ACTION_LINK | - GDK_ACTION_MOVE)); - - // If adding a handler, make sure to update kNumGtkHandlers and add it to the - // |handlers_| array so that it can be disconnected later on. - handlers_.reset(new int[kNumGtkHandlers]); - handlers_.get()[0] = g_signal_connect( - widget, "drag-motion", G_CALLBACK(OnDragMotionThunk), this); - handlers_.get()[1] = g_signal_connect( - widget, "drag-leave", G_CALLBACK(OnDragLeaveThunk), this); - handlers_.get()[2] = g_signal_connect( - widget, "drag-drop", G_CALLBACK(OnDragDropThunk), this); - handlers_.get()[3] = g_signal_connect( - widget, "drag-data-received", G_CALLBACK(OnDragDataReceivedThunk), this); - // TODO(tony): Need a drag-data-delete handler for moving content out of - // the WebContents. http://crbug.com/38989 - - handlers_.get()[4] = g_signal_connect( - widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); -} - -WebDragDestGtk::~WebDragDestGtk() { - if (widget_) { - gtk_drag_dest_unset(widget_); - for (int i = 0; i < kNumGtkHandlers; ++i) - g_signal_handler_disconnect(widget_, handlers_.get()[i]); - } -} - -void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { - if (context_) { - is_drop_target_ = operation != WebDragOperationNone; - gdk_drag_status(context_, WebDragOpToGdkDragAction(operation), - drag_over_time_); - } -} - -void WebDragDestGtk::DragLeave() { - GetRenderViewHost()->DragTargetDragLeave(); - if (delegate()) - delegate()->OnDragLeave(); - - drop_data_.reset(); -} - -gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender, - GdkDragContext* context, - gint x, gint y, - guint time) { - if (context_ != context) { - context_ = context; - drop_data_.reset(new DropData); - is_drop_target_ = false; - - if (delegate()) - delegate()->DragInitialize(web_contents_); - - // text/plain must come before text/uri-list. This is a hack that works in - // conjunction with OnDragDataReceived. Since some file managers populate - // text/plain with file URLs when dragging files, we want to handle - // text/uri-list after text/plain so that the plain text can be cleared if - // it's a file drag. - // Similarly, renderer taint must occur before anything else so we can - // ignore potentially forged filenames when handling text/uri-list. - static int supported_targets[] = { - ui::RENDERER_TAINT, - ui::TEXT_PLAIN, - ui::TEXT_URI_LIST, - ui::TEXT_HTML, - ui::NETSCAPE_URL, - ui::CHROME_NAMED_URL, - // TODO(estade): support image drags? - ui::CUSTOM_DATA, - }; - - // Add the delegate's requested target if applicable. Need to do this here - // since gtk_drag_get_data will dispatch to our drag-data-received. - data_requests_ = arraysize(supported_targets) + (delegate() ? 1 : 0); - for (size_t i = 0; i < arraysize(supported_targets); ++i) { - gtk_drag_get_data(widget_, context, - ui::GetAtomForTarget(supported_targets[i]), - time); - } - - if (delegate()) { - gtk_drag_get_data(widget_, context, delegate()->GetBookmarkTargetAtom(), - time); - } - } else if (data_requests_ == 0) { - if (canceled_) - return FALSE; - - GetRenderViewHost()->DragTargetDragOver( - ui::ClientPoint(widget_), - ui::ScreenPoint(widget_), - GdkDragActionToWebDragOp(context->actions), - GetModifierFlags(widget_)); - - if (delegate()) - delegate()->OnDragOver(); - - drag_over_time_ = time; - } - - // Pretend we are a drag destination because we don't want to wait for - // the renderer to tell us if we really are or not. - return TRUE; -} - -void WebDragDestGtk::OnDragDataReceived( - GtkWidget* sender, GdkDragContext* context, gint x, gint y, - GtkSelectionData* data, guint info, guint time) { - // We might get the data from an old get_data() request that we no longer - // care about. - if (context != context_) - return; - - data_requests_--; - - // Decode the data. - gint data_length = gtk_selection_data_get_length(data); - const guchar* raw_data = gtk_selection_data_get_data(data); - GdkAtom target = gtk_selection_data_get_target(data); - if (raw_data && data_length > 0) { - // If the source can't provide us with valid data for a requested target, - // raw_data will be NULL. - if (target == ui::GetAtomForTarget(ui::RENDERER_TAINT)) { - drop_data_->did_originate_from_renderer = true; - } else if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { - guchar* text = gtk_selection_data_get_text(data); - if (text) { - drop_data_->text = base::NullableString16( - base::UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))), - false); - g_free(text); - } - } else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { - gchar** uris = gtk_selection_data_get_uris(data); - if (uris) { - drop_data_->url = GURL(); - for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { - // Most file managers populate text/uri-list with file URLs when - // dragging files. To avoid exposing file system paths to web content, - // file URLs are never set as the URL content for the drop. - // TODO(estade): Can the filenames have a non-UTF8 encoding? - GURL url(*uri_iter); - base::FilePath file_path; - if (url.SchemeIs(kFileScheme) && - net::FileURLToFilePath(url, &file_path)) { - drop_data_->filenames.push_back( - ui::FileInfo(file_path, base::FilePath())); - // This is a hack. Some file managers also populate text/plain with - // a file URL when dragging files, so we clear it to avoid exposing - // it to the web content. - drop_data_->text = base::NullableString16(); - } else if (!drop_data_->url.is_valid()) { - // Also set the first non-file URL as the URL content for the drop. - drop_data_->url = url; - } - } - g_strfreev(uris); - } - } else if (target == ui::GetAtomForTarget(ui::TEXT_HTML)) { - // TODO(estade): Can the html have a non-UTF8 encoding? - drop_data_->html = base::NullableString16( - base::UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data), - data_length)), - false); - // We leave the base URL empty. - } else if (target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) { - std::string netscape_url(reinterpret_cast<const char*>(raw_data), - data_length); - size_t split = netscape_url.find_first_of('\n'); - if (split != std::string::npos) { - drop_data_->url = GURL(netscape_url.substr(0, split)); - if (split < netscape_url.size() - 1) { - drop_data_->url_title = - base::UTF8ToUTF16(netscape_url.substr(split + 1)); - } - } - } else if (target == ui::GetAtomForTarget(ui::CHROME_NAMED_URL)) { - ui::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title); - } else if (target == ui::GetAtomForTarget(ui::CUSTOM_DATA)) { - ui::ReadCustomDataIntoMap( - raw_data, data_length, &drop_data_->custom_data); - } - } - - if (data_requests_ == 0) { - // Give the delegate an opportunity to cancel the drag. - canceled_ = !web_contents_->GetDelegate()->CanDragEnter( - web_contents_, - *drop_data_, - GdkDragActionToWebDragOp(context->actions)); - if (canceled_) { - drag_over_time_ = time; - UpdateDragStatus(WebDragOperationNone); - drop_data_.reset(); - return; - } - } - - // For CHROME_BOOKMARK_ITEM, we have to handle the case where the drag source - // doesn't have any data available for us. In this case we try to synthesize a - // URL bookmark. - // Note that bookmark drag data is encoded in the same format for both - // GTK and Views, hence we can share the same logic here. - if (delegate() && target == delegate()->GetBookmarkTargetAtom()) { - if (raw_data && data_length > 0) { - delegate()->OnReceiveDataFromGtk(data); - } else { - delegate()->OnReceiveProcessedData(drop_data_->url, - drop_data_->url_title); - } - } - - if (data_requests_ == 0) { - // Tell the renderer about the drag. - // |x| and |y| are seemingly arbitrary at this point. - GetRenderViewHost()->DragTargetDragEnter( - *drop_data_.get(), - ui::ClientPoint(widget_), - ui::ScreenPoint(widget_), - GdkDragActionToWebDragOp(context->actions), - GetModifierFlags(widget_)); - - if (delegate()) - delegate()->OnDragEnter(); - - drag_over_time_ = time; - } -} - -// The drag has left our widget; forward this information to the renderer. -void WebDragDestGtk::OnDragLeave(GtkWidget* sender, GdkDragContext* context, - guint time) { - // Set |context_| to NULL to make sure we will recognize the next DragMotion - // as an enter. - context_ = NULL; - - if (canceled_) - return; - - // Sometimes we get a drag-leave event before getting a drag-data-received - // event. In that case, we don't want to bother the renderer with a - // DragLeave event. - if (data_requests_ != 0) - return; - - // When GTK sends us a drag-drop signal, it is shortly (and synchronously) - // preceded by a drag-leave. The renderer doesn't like getting the signals - // in this order so delay telling it about the drag-leave till we are sure - // we are not getting a drop as well. - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&WebDragDestGtk::DragLeave, method_factory_.GetWeakPtr())); -} - -// Called by GTK when the user releases the mouse, executing a drop. -gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context, - gint x, gint y, guint time) { - // Cancel that drag leave! - method_factory_.InvalidateWeakPtrs(); - - GetRenderViewHost()-> - DragTargetDrop(ui::ClientPoint(widget_), ui::ScreenPoint(widget_), - GetModifierFlags(widget_)); - - if (delegate()) - delegate()->OnDrop(); - - // The second parameter is just an educated guess as to whether or not the - // drag succeeded, but at least we will get the drag-end animation right - // sometimes. - gtk_drag_finish(context, is_drop_target_, FALSE, time); - - return TRUE; -} - -RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { - return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); -} - -} // namespace content diff --git a/content/browser/web_contents/web_drag_dest_gtk.h b/content/browser/web_contents/web_drag_dest_gtk.h deleted file mode 100644 index 7258e1b..0000000 --- a/content/browser/web_contents/web_drag_dest_gtk.h +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_DEST_GTK_H_ -#define CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_DEST_GTK_H_ - -#include <gtk/gtk.h> - -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "content/common/content_export.h" -#include "content/public/common/drop_data.h" -#include "third_party/WebKit/public/web/WebDragOperation.h" -#include "ui/base/gtk/gtk_signal.h" - -namespace content { - -class RenderViewHostImpl; -class WebContents; -class WebDragDestDelegate; - -// A helper class that handles DnD for drops in the renderer. In GTK parlance, -// this handles destination-side DnD, but not source-side DnD. -class CONTENT_EXPORT WebDragDestGtk { - public: - WebDragDestGtk(WebContents* web_contents, GtkWidget* widget); - ~WebDragDestGtk(); - - DropData* current_drop_data() const { return drop_data_.get(); } - - // This is called when the renderer responds to a drag motion event. We must - // update the system drag cursor. - void UpdateDragStatus(blink::WebDragOperation operation); - - // Informs the renderer when a system drag has left the render view. - // See OnDragLeave(). - void DragLeave(); - - WebDragDestDelegate* delegate() const { return delegate_; } - void set_delegate(WebDragDestDelegate* delegate) { delegate_ = delegate; } - - GtkWidget* widget() const { return widget_; } - - private: - RenderViewHostImpl* GetRenderViewHost() const; - - // Called when a system drag crosses over the render view. As there is no drag - // enter event, we treat it as an enter event (and not a regular motion event) - // when |context_| is NULL. - CHROMEGTK_CALLBACK_4(WebDragDestGtk, gboolean, OnDragMotion, GdkDragContext*, - gint, gint, guint); - - // We make a series of requests for the drag data when the drag first enters - // the render view. This is the callback that is used to give us the data - // for each individual target. When |data_requests_| reaches 0, we know we - // have attained all the data, and we can finally tell the renderer about the - // drag. - CHROMEGTK_CALLBACK_6(WebDragDestGtk, void, OnDragDataReceived, - GdkDragContext*, gint, gint, GtkSelectionData*, - guint, guint); - - // The drag has left our widget; forward this information to the renderer. - CHROMEGTK_CALLBACK_2(WebDragDestGtk, void, OnDragLeave, GdkDragContext*, - guint); - - // Called by GTK when the user releases the mouse, executing a drop. - CHROMEGTK_CALLBACK_4(WebDragDestGtk, gboolean, OnDragDrop, GdkDragContext*, - gint, gint, guint); - - WebContents* web_contents_; - - // The render view. - GtkWidget* widget_; - - // The current drag context for system drags over our render view, or NULL if - // there is no system drag or the system drag is not over our render view. - GdkDragContext* context_; - - // The data for the current drag, or NULL if |context_| is NULL. - scoped_ptr<DropData> drop_data_; - - // The number of outstanding drag data requests we have sent to the drag - // source. - int data_requests_; - - // The last time we sent a message to the renderer related to a drag motion. - gint drag_over_time_; - - // Whether the cursor is over a drop target, according to the last message we - // got from the renderer. - bool is_drop_target_; - - // Stores Handler IDs for the gtk signal handlers. We have to cancel the - // signal handlers when this WebDragDestGtk is deleted so that if, later on, - // we re-create the drag dest with the same widget, we don't get callbacks to - // deleted functions. - scoped_ptr<int[]> handlers_; - - // A delegate that can receive drag information about drag events. - WebDragDestDelegate* delegate_; - - // True if the drag has been canceled. - bool canceled_; - - base::WeakPtrFactory<WebDragDestGtk> method_factory_; - - DISALLOW_COPY_AND_ASSIGN(WebDragDestGtk); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_DEST_GTK_H_ diff --git a/content/browser/web_contents/web_drag_source_gtk.cc b/content/browser/web_contents/web_drag_source_gtk.cc deleted file mode 100644 index 1c4e589..0000000 --- a/content/browser/web_contents/web_drag_source_gtk.cc +++ /dev/null @@ -1,388 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/web_contents/web_drag_source_gtk.h" - -#include <string> - -#include "base/files/file.h" -#include "base/nix/mime_util_xdg.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_restrictions.h" -#include "content/browser/download/drag_download_file.h" -#include "content/browser/download/drag_download_util.h" -#include "content/browser/renderer_host/render_view_host_delegate.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/web_contents/drag_utils_gtk.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/public/browser/content_browser_client.h" -#include "content/public/browser/web_contents_view.h" -#include "content/public/common/content_client.h" -#include "content/public/common/drop_data.h" -#include "net/base/filename_util.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/clipboard/custom_data_helper.h" -#include "ui/base/dragdrop/gtk_dnd_util.h" -#include "ui/base/gtk/gtk_screen_util.h" -#include "ui/gfx/gtk_compat.h" -#include "ui/gfx/gtk_util.h" - -using blink::WebDragOperation; -using blink::WebDragOperationsMask; -using blink::WebDragOperationNone; - -namespace content { - -WebDragSourceGtk::WebDragSourceGtk(WebContents* web_contents) - : web_contents_(static_cast<WebContentsImpl*>(web_contents)), - drag_pixbuf_(NULL), - drag_failed_(false), - drag_widget_(gtk_invisible_new()), - drag_context_(NULL), - drag_icon_(gtk_window_new(GTK_WINDOW_POPUP)) { - signals_.Connect(drag_widget_, "drag-failed", - G_CALLBACK(OnDragFailedThunk), this); - signals_.Connect(drag_widget_, "drag-begin", - G_CALLBACK(OnDragBeginThunk), - this); - signals_.Connect(drag_widget_, "drag-end", - G_CALLBACK(OnDragEndThunk), this); - signals_.Connect(drag_widget_, "drag-data-get", - G_CALLBACK(OnDragDataGetThunk), this); - - signals_.Connect(drag_icon_, "expose-event", - G_CALLBACK(OnDragIconExposeThunk), this); -} - -WebDragSourceGtk::~WebDragSourceGtk() { - // Break the current drag, if any. - if (drop_data_) { - gtk_grab_add(drag_widget_); - gtk_grab_remove(drag_widget_); - drop_data_.reset(); - } - - gtk_widget_destroy(drag_widget_); - gtk_widget_destroy(drag_icon_); -} - -bool WebDragSourceGtk::StartDragging(const DropData& drop_data, - WebDragOperationsMask allowed_ops, - GdkEventButton* last_mouse_down, - const SkBitmap& image, - const gfx::Vector2d& image_offset) { - // Guard against re-starting before previous drag completed. - if (drag_context_) { - NOTREACHED(); - return false; - } - - int targets_mask = ui::RENDERER_TAINT; - - if (!drop_data.text.string().empty()) - targets_mask |= ui::TEXT_PLAIN; - if (drop_data.url.is_valid()) { - targets_mask |= ui::TEXT_URI_LIST; - targets_mask |= ui::CHROME_NAMED_URL; - targets_mask |= ui::NETSCAPE_URL; - } - if (!drop_data.html.string().empty()) - targets_mask |= ui::TEXT_HTML; - if (!drop_data.file_contents.empty()) - targets_mask |= ui::CHROME_WEBDROP_FILE_CONTENTS; - if (!drop_data.download_metadata.empty() && - ParseDownloadMetadata(drop_data.download_metadata, - &wide_download_mime_type_, - &download_file_name_, - &download_url_)) { - targets_mask |= ui::DIRECT_SAVE_FILE; - } - if (!drop_data.custom_data.empty()) - targets_mask |= ui::CUSTOM_DATA; - - // NOTE: Begin a drag even if no targets present. Otherwise, things like - // draggable list elements will not work. - - drop_data_.reset(new DropData(drop_data)); - - // The image we get from WebKit makes heavy use of alpha-shading. This looks - // bad on non-compositing WMs. Fall back to the default drag icon. - if (!image.isNull() && ui::IsScreenComposited()) - drag_pixbuf_ = gfx::GdkPixbufFromSkBitmap(image); - image_offset_ = image_offset; - - GtkTargetList* list = ui::GetTargetListFromCodeMask(targets_mask); - if (targets_mask & ui::CHROME_WEBDROP_FILE_CONTENTS) { - // Looking up the mime type can hit the disk. http://crbug.com/84896 - base::ThreadRestrictions::ScopedAllowIO allow_io; - drag_file_mime_type_ = gdk_atom_intern( - base::nix::GetDataMimeType(drop_data.file_contents).c_str(), FALSE); - gtk_target_list_add(list, drag_file_mime_type_, - 0, ui::CHROME_WEBDROP_FILE_CONTENTS); - } - - drag_failed_ = false; - // If we don't pass an event, GDK won't know what event time to start grabbing - // mouse events. Technically it's the mouse motion event and not the mouse - // down event that causes the drag, but there's no reliable way to know - // *which* motion event initiated the drag, so this will have to do. - // TODO(estade): This can sometimes be very far off, e.g. if the user clicks - // and holds and doesn't start dragging for a long time. I doubt it matters - // much, but we should probably look into the possibility of getting the - // initiating event from webkit. - drag_context_ = gtk_drag_begin(drag_widget_, list, - WebDragOpToGdkDragAction(allowed_ops), - 1, // Drags are always initiated by the left button. - reinterpret_cast<GdkEvent*>(last_mouse_down)); - // The drag adds a ref; let it own the list. - gtk_target_list_unref(list); - - // Sometimes the drag fails to start; |context| will be NULL and we won't - // get a drag-end signal. - if (!drag_context_) { - drag_failed_ = true; - drop_data_.reset(); - return false; - } - - return true; -} - -void WebDragSourceGtk::OnDragDataGet(GtkWidget* sender, - GdkDragContext* context, - GtkSelectionData* selection_data, - guint target_type, - guint time) { - const int kBitsPerByte = 8; - - switch (target_type) { - case ui::TEXT_PLAIN: { - std::string utf8_text = base::UTF16ToUTF8(drop_data_->text.string()); - gtk_selection_data_set_text(selection_data, utf8_text.c_str(), - utf8_text.length()); - break; - } - - case ui::TEXT_HTML: { - // TODO(estade): change relative links to be absolute using - // |html_base_url|. - std::string utf8_text = base::UTF16ToUTF8(drop_data_->html.string()); - gtk_selection_data_set(selection_data, - ui::GetAtomForTarget(ui::TEXT_HTML), - kBitsPerByte, - reinterpret_cast<const guchar*>(utf8_text.c_str()), - utf8_text.length()); - break; - } - - case ui::TEXT_URI_LIST: - case ui::CHROME_NAMED_URL: - case ui::NETSCAPE_URL: { - ui::WriteURLWithName(selection_data, drop_data_->url, - drop_data_->url_title, target_type); - break; - } - - case ui::CHROME_WEBDROP_FILE_CONTENTS: { - gtk_selection_data_set( - selection_data, - drag_file_mime_type_, kBitsPerByte, - reinterpret_cast<const guchar*>(drop_data_->file_contents.data()), - drop_data_->file_contents.length()); - break; - } - - case ui::DIRECT_SAVE_FILE: { - char status_code = 'E'; - - // Retrieves the full file path (in file URL format) provided by the - // drop target by reading from the source window's XdndDirectSave0 - // property. - gint file_url_len = 0; - guchar* file_url_value = NULL; - if (gdk_property_get(context->source_window, - ui::GetAtomForTarget(ui::DIRECT_SAVE_FILE), - ui::GetAtomForTarget(ui::TEXT_PLAIN_NO_CHARSET), - 0, - 1024, - FALSE, - NULL, - NULL, - &file_url_len, - &file_url_value) && - file_url_value) { - // Convert from the file url to the file path. - GURL file_url(std::string(reinterpret_cast<char*>(file_url_value), - file_url_len)); - g_free(file_url_value); - base::FilePath file_path; - if (net::FileURLToFilePath(file_url, &file_path)) { - // Open the file. - base::File file(CreateFileForDrop(&file_path)); - if (file.IsValid()) { - // Start downloading the file to the stream. - scoped_refptr<DragDownloadFile> drag_file_downloader = - new DragDownloadFile( - file_path, - file.Pass(), - download_url_, - Referrer(web_contents_->GetURL(), - drop_data_->referrer_policy), - web_contents_->GetEncoding(), - web_contents_); - drag_file_downloader->Start( - new PromiseFileFinalizer(drag_file_downloader.get())); - - // Set the status code to success. - status_code = 'S'; - } - } - - // Return the status code to the file manager. - gtk_selection_data_set(selection_data, - gtk_selection_data_get_target(selection_data), - kBitsPerByte, - reinterpret_cast<guchar*>(&status_code), - 1); - } - break; - } - - case ui::CUSTOM_DATA: { - Pickle custom_data; - ui::WriteCustomDataToPickle(drop_data_->custom_data, &custom_data); - gtk_selection_data_set( - selection_data, - ui::GetAtomForTarget(ui::CUSTOM_DATA), - kBitsPerByte, - reinterpret_cast<const guchar*>(custom_data.data()), - custom_data.size()); - break; - } - - case ui::RENDERER_TAINT: { - static const char kPlaceholder[] = "x"; - gtk_selection_data_set( - selection_data, - ui::GetAtomForTarget(ui::RENDERER_TAINT), - kBitsPerByte, - reinterpret_cast<const guchar*>(kPlaceholder), - strlen(kPlaceholder)); - break; - } - - default: - NOTREACHED(); - } -} - -gboolean WebDragSourceGtk::OnDragFailed(GtkWidget* sender, - GdkDragContext* context, - GtkDragResult result) { - drag_failed_ = true; - - gfx::Point root = ui::ScreenPoint(GetContentNativeView()); - gfx::Point client = ui::ClientPoint(GetContentNativeView()); - - if (web_contents_) { - web_contents_->DragSourceEndedAt( - client.x(), client.y(), root.x(), root.y(), - WebDragOperationNone); - } - - // Let the native failure animation run. - return FALSE; -} - -void WebDragSourceGtk::OnDragBegin(GtkWidget* sender, - GdkDragContext* drag_context) { - if (!download_url_.is_empty()) { - // Generate the file name based on both mime type and proposed file name. - std::string default_name = - GetContentClient()->browser()->GetDefaultDownloadName(); - base::FilePath generated_download_file_name = - net::GenerateFileName(download_url_, - std::string(), - std::string(), - download_file_name_.value(), - base::UTF16ToUTF8(wide_download_mime_type_), - default_name); - - // Pass the file name to the drop target by setting the source window's - // XdndDirectSave0 property. - gdk_property_change(drag_context->source_window, - ui::GetAtomForTarget(ui::DIRECT_SAVE_FILE), - ui::GetAtomForTarget(ui::TEXT_PLAIN_NO_CHARSET), - 8, - GDK_PROP_MODE_REPLACE, - reinterpret_cast<const guchar*>( - generated_download_file_name.value().c_str()), - generated_download_file_name.value().length()); - } - - if (drag_pixbuf_) { - gtk_widget_set_size_request(drag_icon_, - gdk_pixbuf_get_width(drag_pixbuf_), - gdk_pixbuf_get_height(drag_pixbuf_)); - - // We only need to do this once. - if (!gtk_widget_get_realized(drag_icon_)) { - GdkScreen* screen = gtk_widget_get_screen(drag_icon_); - GdkColormap* rgba = gdk_screen_get_rgba_colormap(screen); - if (rgba) - gtk_widget_set_colormap(drag_icon_, rgba); - } - - gtk_drag_set_icon_widget(drag_context, drag_icon_, - image_offset_.x(), image_offset_.y()); - } -} - -void WebDragSourceGtk::OnDragEnd(GtkWidget* sender, - GdkDragContext* drag_context) { - if (drag_pixbuf_) { - g_object_unref(drag_pixbuf_); - drag_pixbuf_ = NULL; - } - - if (!download_url_.is_empty()) { - gdk_property_delete(drag_context->source_window, - ui::GetAtomForTarget(ui::DIRECT_SAVE_FILE)); - } - - if (!drag_failed_) { - gfx::Point root = ui::ScreenPoint(GetContentNativeView()); - gfx::Point client = ui::ClientPoint(GetContentNativeView()); - - if (web_contents_) { - web_contents_->DragSourceEndedAt( - client.x(), client.y(), root.x(), root.y(), - GdkDragActionToWebDragOp(drag_context->action)); - } - } - - web_contents_->SystemDragEnded(); - - drop_data_.reset(); - drag_context_ = NULL; -} - -gfx::NativeView WebDragSourceGtk::GetContentNativeView() const { - return web_contents_->GetView()->GetContentNativeView(); -} - -gboolean WebDragSourceGtk::OnDragIconExpose(GtkWidget* sender, - GdkEventExpose* event) { - cairo_t* cr = gdk_cairo_create(event->window); - gdk_cairo_rectangle(cr, &event->area); - cairo_clip(cr); - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0); - cairo_paint(cr); - cairo_destroy(cr); - - return TRUE; -} - -} // namespace content diff --git a/content/browser/web_contents/web_drag_source_gtk.h b/content/browser/web_contents/web_drag_source_gtk.h deleted file mode 100644 index 94687c1..0000000 --- a/content/browser/web_contents/web_drag_source_gtk.h +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_ -#define CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_ - -#include <gtk/gtk.h> - -#include "base/basictypes.h" -#include "base/files/file_path.h" -#include "base/strings/string16.h" -#include "content/common/content_export.h" -#include "content/public/browser/web_contents.h" -#include "third_party/WebKit/public/web/WebDragOperation.h" -#include "ui/base/gtk/gtk_signal.h" -#include "ui/base/gtk/gtk_signal_registrar.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gfx/vector2d.h" -#include "url/gurl.h" - -class SkBitmap; - -namespace content { - -class RenderViewHostImpl; -class WebContentsImpl; -struct DropData; - -// WebDragSourceGtk takes care of managing the drag from a WebContents -// with Gtk. -class CONTENT_EXPORT WebDragSourceGtk { - public: - explicit WebDragSourceGtk(WebContents* web_contents); - virtual ~WebDragSourceGtk(); - - // Starts a drag for the WebContents this WebDragSourceGtk was created for. - // Returns false if the drag could not be started. - bool StartDragging(const DropData& drop_data, - blink::WebDragOperationsMask allowed_ops, - GdkEventButton* last_mouse_down, - const SkBitmap& image, - const gfx::Vector2d& image_offset); - - private: - CHROMEGTK_CALLBACK_2(WebDragSourceGtk, gboolean, OnDragFailed, - GdkDragContext*, GtkDragResult); - CHROMEGTK_CALLBACK_1(WebDragSourceGtk, void, OnDragBegin, - GdkDragContext*); - CHROMEGTK_CALLBACK_1(WebDragSourceGtk, void, OnDragEnd, - GdkDragContext*); - CHROMEGTK_CALLBACK_4(WebDragSourceGtk, void, OnDragDataGet, - GdkDragContext*, GtkSelectionData*, guint, guint); - CHROMEGTK_CALLBACK_1(WebDragSourceGtk, gboolean, OnDragIconExpose, - GdkEventExpose*); - - gfx::NativeView GetContentNativeView() const; - - // The tab we're manging the drag for. - WebContentsImpl* web_contents_; - - // The drop data for the current drag (for drags that originate in the render - // view). Non-NULL iff there is a current drag. - scoped_ptr<DropData> drop_data_; - - // The image used for depicting the drag, and the offset between the cursor - // and the top left pixel. - GdkPixbuf* drag_pixbuf_; - gfx::Vector2d image_offset_; - - // The mime type for the file contents of the current drag (if any). - GdkAtom drag_file_mime_type_; - - // Whether the current drag has failed. Meaningless if we are not the source - // for a current drag. - bool drag_failed_; - - // This is the widget we use to initiate drags. Since we don't use the - // renderer widget, we can persist drags even when our contents is switched - // out. We can't use an OwnedWidgetGtk because the GtkInvisible widget - // initialization code sinks the reference. - GtkWidget* drag_widget_; - - // Context created once drag starts. A NULL value indicates that there is - // no drag currently in progress. - GdkDragContext* drag_context_; - - // The file mime type for a drag-out download. - base::string16 wide_download_mime_type_; - - // The file name to be saved to for a drag-out download. - base::FilePath download_file_name_; - - // The URL to download from for a drag-out download. - GURL download_url_; - - // The widget that provides visual feedback for the drag. We can't use - // an OwnedWidgetGtk because the GtkWindow initialization code sinks - // the reference. - GtkWidget* drag_icon_; - - ui::GtkSignalRegistrar signals_; - - DISALLOW_COPY_AND_ASSIGN(WebDragSourceGtk); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_ diff --git a/content/child/npapi/webplugin_delegate_impl_gtk.cc b/content/child/npapi/webplugin_delegate_impl_gtk.cc deleted file mode 100644 index 8c93f7d..0000000 --- a/content/child/npapi/webplugin_delegate_impl_gtk.cc +++ /dev/null @@ -1,751 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/child/npapi/webplugin_delegate_impl.h" - -#include <gdk/gdkx.h> -#include <gtk/gtk.h> - -#include <string> -#include <vector> - -#include "base/metrics/stats_counters.h" -#include "content/child/npapi/plugin_instance.h" -#include "content/child/npapi/webplugin.h" -#include "content/common/cursors/webcursor.h" -#include "content/public/common/content_constants.h" -#include "skia/ext/platform_canvas.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -#include "ui/gfx/blit.h" -#include "ui/gfx/gtk_compat.h" - -#include "third_party/npapi/bindings/npapi_x11.h" - -using blink::WebKeyboardEvent; -using blink::WebInputEvent; -using blink::WebMouseEvent; - -namespace content { - -WebPluginDelegateImpl::WebPluginDelegateImpl( - WebPlugin* plugin, - PluginInstance* instance) - : windowed_handle_(0), - windowed_did_set_window_(false), - windowless_(false), - plugin_(plugin), - instance_(instance), - windowless_shm_pixmap_(None), - pixmap_(NULL), - first_event_time_(-1.0), - plug_(NULL), - socket_(NULL), - quirks_(0), - handle_event_depth_(0), - first_set_window_call_(true), - plugin_has_focus_(false), - has_webkit_focus_(false), - containing_view_has_focus_(true), - creation_succeeded_(false) { - memset(&window_, 0, sizeof(window_)); - if (instance_->mime_type() == kFlashPluginSwfMimeType) { - // Flash is tied to Firefox's whacky behavior with windowless plugins. See - // comments in WindowlessPaint. - // TODO(viettrungluu): PLUGIN_QUIRK_WINDOWLESS_NO_RIGHT_CLICK: Don't allow - // right-clicks in windowless content since Flash 10.1 (initial release, at - // least) hangs in that case. Remove this once Flash is fixed. - quirks_ |= PLUGIN_QUIRK_WINDOWLESS_OFFSET_WINDOW_TO_DRAW - | PLUGIN_QUIRK_WINDOWLESS_INVALIDATE_AFTER_SET_WINDOW - | PLUGIN_QUIRK_WINDOWLESS_NO_RIGHT_CLICK; - } - - // TODO(evanm): I played with this for quite a while but couldn't - // figure out a way to make Flash not crash unless I didn't call - // NPP_SetWindow. - // However, after piman's grand refactor of windowed plugins, maybe - // this is no longer necessary. - quirks_ |= PLUGIN_QUIRK_DONT_SET_NULL_WINDOW_HANDLE_ON_DESTROY; -} - -WebPluginDelegateImpl::~WebPluginDelegateImpl() { - DestroyInstance(); - - if (!windowless_) - WindowedDestroyWindow(); - - if (window_.ws_info) { - // We only ever use ws_info as an NPSetWindowCallbackStruct. - delete static_cast<NPSetWindowCallbackStruct*>(window_.ws_info); - } - - if (pixmap_) { - g_object_unref(pixmap_); - pixmap_ = NULL; - } -} - -bool WebPluginDelegateImpl::PlatformInitialize() { - gfx::PluginWindowHandle handle = - windowless_ ? 0 : gtk_plug_get_id(GTK_PLUG(plug_)); - plugin_->SetWindow(handle); - return true; -} - -void WebPluginDelegateImpl::PlatformDestroyInstance() { - // Nothing to do here. -} - -void WebPluginDelegateImpl::Paint(SkCanvas* canvas, const gfx::Rect& rect) { - if (!windowless_ || !skia::SupportsPlatformPaint(canvas)) - return; - skia::ScopedPlatformPaint scoped_platform_paint(canvas); - cairo_t* context = scoped_platform_paint.GetPlatformSurface(); - WindowlessPaint(context, rect); -} - -bool WebPluginDelegateImpl::WindowedCreatePlugin() { - DCHECK(!windowed_handle_); - DCHECK(!plug_); - - // NPP_GetValue() might write 4 bytes of data to this variable. Don't use a - // single byte bool, use an int instead and make sure it is initialized. - int xembed = 0; - NPError err = instance_->NPP_GetValue(NPPVpluginNeedsXEmbed, &xembed); - if (err != NPERR_NO_ERROR || !xembed) { - NOTIMPLEMENTED() << " windowed plugin but without xembed. " - "See http://code.google.com/p/chromium/issues/detail?id=38229"; - return false; - } - - // Passing 0 as the socket XID creates a plug without plugging it in a socket - // yet, so that it can be latter added with gtk_socket_add_id(). - plug_ = gtk_plug_new(0); - gtk_widget_show(plug_); - socket_ = gtk_socket_new(); - gtk_widget_show(socket_); - gtk_container_add(GTK_CONTAINER(plug_), socket_); - gtk_widget_show_all(plug_); - - // Prevent the plug from being destroyed if the browser kills the container - // window. - g_signal_connect(plug_, "delete-event", G_CALLBACK(gtk_true), NULL); - // Prevent the socket from being destroyed when the plugin removes itself. - g_signal_connect(socket_, "plug_removed", G_CALLBACK(gtk_true), NULL); - - windowed_handle_ = gtk_socket_get_id(GTK_SOCKET(socket_)); - - window_.window = reinterpret_cast<void*>(windowed_handle_); - - if (!window_.ws_info) - window_.ws_info = new NPSetWindowCallbackStruct; - NPSetWindowCallbackStruct* extra = - static_cast<NPSetWindowCallbackStruct*>(window_.ws_info); - extra->type = NP_SETWINDOW; - extra->display = GDK_DISPLAY(); - int screen = DefaultScreen(GDK_DISPLAY()); - extra->visual = DefaultVisual(GDK_DISPLAY(), screen); - extra->depth = DefaultDepth(GDK_DISPLAY(), screen); - extra->colormap = DefaultColormap(GDK_DISPLAY(), screen); - - return true; -} - -void WebPluginDelegateImpl::WindowedDestroyWindow() { - if (plug_) { - plugin_->WillDestroyWindow(gtk_plug_get_id(GTK_PLUG(plug_))); - - gtk_widget_destroy(plug_); - plug_ = NULL; - socket_ = NULL; - windowed_handle_ = 0; - } -} - -bool WebPluginDelegateImpl::WindowedReposition( - const gfx::Rect& window_rect, - const gfx::Rect& clip_rect) { - if (window_rect == window_rect_ && clip_rect == clip_rect_) - return false; - - window_rect_ = window_rect; - clip_rect_ = clip_rect; - - return true; -} - -void WebPluginDelegateImpl::WindowedSetWindow() { - if (!instance_.get()) - return; - - if (!windowed_handle_) { - NOTREACHED(); - return; - } - - // See https://bugzilla.mozilla.org/show_bug.cgi?id=108347 - // If we call NPP_SetWindow with a <= 0 width or height, problems arise in - // Flash (and possibly other plugins). - // TODO(piman): the Mozilla code suggests that for the Java plugin, we should - // still call NPP_SetWindow in that case. We need to verify that. - if (window_rect_.width() <= 0 || window_rect_.height() <= 0) { - return; - } - - instance()->set_window_handle(windowed_handle_); - - DCHECK(!instance()->windowless()); - - window_.clipRect.top = clip_rect_.y(); - window_.clipRect.left = clip_rect_.x(); - window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height(); - window_.clipRect.right = clip_rect_.x() + clip_rect_.width(); - window_.height = window_rect_.height(); - window_.width = window_rect_.width(); - window_.x = window_rect_.x(); - window_.y = window_rect_.y(); - window_.type = NPWindowTypeWindow; - - // Reset this flag before entering the instance in case of side-effects. - windowed_did_set_window_ = true; - - NPError err = instance()->NPP_SetWindow(&window_); - DCHECK(err == NPERR_NO_ERROR); -} - -void WebPluginDelegateImpl::WindowlessUpdateGeometry( - const gfx::Rect& window_rect, - const gfx::Rect& clip_rect) { - // Only resend to the instance if the geometry has changed. - if (window_rect == window_rect_ && clip_rect == clip_rect_) - return; - - clip_rect_ = clip_rect; - window_rect_ = window_rect; - WindowlessSetWindow(); -} - -void WebPluginDelegateImpl::EnsurePixmapAtLeastSize(int width, int height) { - if (pixmap_) { - gint cur_width, cur_height; - gdk_pixmap_get_size(pixmap_, &cur_width, &cur_height); - if (cur_width >= width && cur_height >= height) - return; // We are already the appropriate size. - - // Otherwise, we need to recreate ourselves. - g_object_unref(pixmap_); - pixmap_ = NULL; - } - - // |sys_visual| is owned by gdk; we shouldn't free it. - GdkVisual* sys_visual = gdk_visual_get_system(); - pixmap_ = gdk_pixmap_new(NULL, // use width/height/depth params - std::max(1, width), std::max(1, height), - sys_visual->depth); - // TODO(erg): Replace this with GdkVisual when we move to GTK3. - GdkColormap* colormap = gdk_colormap_new(gdk_visual_get_system(), - FALSE); - gdk_drawable_set_colormap(pixmap_, colormap); - // The GdkDrawable now owns the GdkColormap. - g_object_unref(colormap); -} - -#ifdef DEBUG_RECTANGLES -namespace { - -// Draw a rectangle on a Cairo context. -// Useful for debugging various rectangles involved in drawing plugins. -void DrawDebugRectangle(cairo_t* cairo, - const gfx::Rect& rect, - float r, float g, float b) { - cairo_set_source_rgba(cairo, r, g, b, 0.5); - cairo_rectangle(cairo, rect.x(), rect.y(), - rect.width(), rect.height()); - cairo_stroke(cairo); -} - -} // namespace -#endif - -void WebPluginDelegateImpl::WindowlessPaint(cairo_t* context, - const gfx::Rect& damage_rect) { - // Compare to: - // http://mxr.mozilla.org/firefox/source/layout/generic/nsObjectFrame.cpp: - // nsPluginInstanceOwner::Renderer::NativeDraw(). - - DCHECK(context); - - // TODO(darin): we should avoid calling NPP_SetWindow here since it may - // cause page layout to be invalidated. - - // The actual dirty region is just the intersection of the plugin window and - // the clip window with the damage region. However, the plugin wants to draw - // relative to the containing window's origin, so our pixmap must be from the - // window's origin down to the bottom-right edge of the dirty region. - // - // Typical case: - // X-----------------------------------+-----------------------------+ - // | | | - // | pixmap +-------------------+ | - // | | damage | window | - // | | | | - // | +---+-------------------+-------------+ | - // | | | | clip | | - // | +---+---+-------------------+----------+ | | - // | | | | | | | | - // | | | | draw | | | | - // | | | | | | | | - // +-------+---+---+-------------------+----------+--+ | - // | | | | | | - // | | +-------------------+ | | - // | | | | - // | | plugin | | - // | +--------------------------------------+ | - // | | - // | | - // +-----------------------------------------------------------------+ - // X = origin - // - // NPAPI doesn't properly define which coordinates each of - // - window.clipRect, window.x and window.y in the SetWindow call - // - x and y in GraphicsExpose HandleEvent call - // are relative to, nor does it define what the pixmap is relative to. - // - // Any sane values for them just don't work with the flash plugin. Firefox - // has some interesting behavior. Experiments showed that: - // - window.clipRect is always in the same space as window.x and window.y - // - in the first SetWindow call, or when scrolling, window.x and window.y are - // the coordinates of the plugin relative to the window. - // - whenever only a part of the plugin is drawn, Firefox issues a SetWindow - // call before each GraphicsExpose event, that sets the drawing origin to - // (0, 0) as if the plugin was scrolled to be partially out of the view. The - // GraphicsExpose event has coordinates relative to the "window" (assuming - // that virtual scroll). The pixmap is also relative to the window. It always - // sets the clip rect to the draw rect. - // - // Attempts to deviate from that makes Flash render at the wrong place in the - // pixmap, or render the wrong pixels. - // - // Flash plugin: - // X-----------------------------------------------------------------+ - // | | - // | +-------------------+ "real" window | - // | | damage | | - // | | | | - // | +---+-------------------+-------------+ | - // | | | | "real" clip | | - // | +---+---O===================#==========#==#===============# - // | | | H draw | | | H - // | | | H = pixmap | | | H - // | | | H = "apparent" clip | | | H - // | + +---#-------------------+----------+--+ H - // | | H | | H - // | | H-------------------+ | H - // | | H | H - // | | H plugin | H - // | +-------#------------------------------+ H - // | H H - // | H "apparent" window H - // +---------------#=================================================# - // X = "real" origin - // O = "apparent" origin - // "real" means as seen by Chrome - // "apparent" means as seen by the plugin. - - gfx::Rect draw_rect = gfx::IntersectRects(window_rect_, damage_rect); - - // clip_rect_ is relative to the plugin - gfx::Rect clip_rect_window = clip_rect_; - clip_rect_window.Offset(window_rect_.x(), window_rect_.y()); - draw_rect.Intersect(clip_rect_window); - - // These offsets represent by how much the view is shifted to accomodate - // Flash (the coordinates of X relative to O in the diagram above). - int offset_x = 0; - int offset_y = 0; - if (quirks_ & PLUGIN_QUIRK_WINDOWLESS_OFFSET_WINDOW_TO_DRAW) { - offset_x = -draw_rect.x(); - offset_y = -draw_rect.y(); - window_.clipRect.top = 0; - window_.clipRect.left = 0; - window_.clipRect.bottom = draw_rect.height(); - window_.clipRect.right = draw_rect.width(); - window_.height = window_rect_.height(); - window_.width = window_rect_.width(); - window_.x = window_rect_.x() - draw_rect.x(); - window_.y = window_rect_.y() - draw_rect.y(); - window_.type = NPWindowTypeDrawable; - DCHECK(window_.ws_info); - NPError err = instance()->NPP_SetWindow(&window_); - DCHECK_EQ(err, NPERR_NO_ERROR); - } - - gfx::Rect pixmap_draw_rect = draw_rect; - pixmap_draw_rect.Offset(offset_x, offset_y); - - gfx::Rect pixmap_rect(0, 0, - pixmap_draw_rect.right(), - pixmap_draw_rect.bottom()); - - // Construct the paint message, targeting the pixmap. - NPEvent np_event = {0}; - XGraphicsExposeEvent& event = np_event.xgraphicsexpose; - event.type = GraphicsExpose; - event.x = pixmap_draw_rect.x(); - event.y = pixmap_draw_rect.y(); - event.width = pixmap_draw_rect.width(); - event.height = pixmap_draw_rect.height(); - event.display = GDK_DISPLAY(); - - if (windowless_shm_pixmap_ != None) { - Pixmap pixmap = None; - GC xgc = NULL; - Display* display = event.display; - gfx::Rect plugin_draw_rect = draw_rect; - - // Make plugin_draw_rect relative to the plugin window. - plugin_draw_rect.Offset(-window_rect_.x(), -window_rect_.y()); - - // In case the drawing area does not start with the plugin window origin, - // we can not let the plugin directly draw over the shared memory pixmap. - if (plugin_draw_rect.x() != pixmap_draw_rect.x() || - plugin_draw_rect.y() != pixmap_draw_rect.y()) { - pixmap = XCreatePixmap(display, windowless_shm_pixmap_, - std::max(1, pixmap_rect.width()), - std::max(1, pixmap_rect.height()), - DefaultDepth(display, DefaultScreen(display))); - xgc = XCreateGC(display, windowless_shm_pixmap_, 0, NULL); - // Copy the current image into the pixmap, so the plugin can draw over it. - XCopyArea(display, windowless_shm_pixmap_, pixmap, xgc, - plugin_draw_rect.x(), plugin_draw_rect.y(), - pixmap_draw_rect.width(), pixmap_draw_rect.height(), - pixmap_draw_rect.x(), pixmap_draw_rect.y()); - - event.drawable = pixmap; - } else { - event.drawable = windowless_shm_pixmap_; - } - - // Tell the plugin to paint into the pixmap. - base::StatsRate plugin_paint("Plugin.Paint"); - base::StatsScope<base::StatsRate> scope(plugin_paint); - instance()->NPP_HandleEvent(&np_event); - - if (pixmap != None) { - // Copy the rendered image pixmap back into the shm pixmap - // and thus the drawing buffer. - XCopyArea(display, pixmap, windowless_shm_pixmap_, xgc, - pixmap_draw_rect.x(), pixmap_draw_rect.y(), - pixmap_draw_rect.width(), pixmap_draw_rect.height(), - plugin_draw_rect.x(), plugin_draw_rect.y()); - XSync(display, FALSE); - if (xgc) - XFreeGC(display, xgc); - XFreePixmap(display, pixmap); - } else { - XSync(display, FALSE); - } - } else { - EnsurePixmapAtLeastSize(pixmap_rect.width(), pixmap_rect.height()); - - // Copy the current image into the pixmap, so the plugin can draw over - // this background. - cairo_t* cairo = gdk_cairo_create(pixmap_); - BlitContextToContext(cairo, pixmap_draw_rect, context, draw_rect.origin()); - cairo_destroy(cairo); - - event.drawable = GDK_PIXMAP_XID(pixmap_); - - // Tell the plugin to paint into the pixmap. - base::StatsRate plugin_paint("Plugin.Paint"); - base::StatsScope<base::StatsRate> scope(plugin_paint); - instance()->NPP_HandleEvent(&np_event); - - cairo_save(context); - // Now copy the rendered image pixmap back into the drawing buffer. - gdk_cairo_set_source_pixmap(context, pixmap_, -offset_x, -offset_y); - cairo_rectangle(context, draw_rect.x(), draw_rect.y(), - draw_rect.width(), draw_rect.height()); - cairo_clip(context); - cairo_paint(context); - -#ifdef DEBUG_RECTANGLES - // Draw some debugging rectangles. - // Pixmap rect = blue. - DrawDebugRectangle(context, pixmap_rect, 0, 0, 1); - // Drawing rect = red. - DrawDebugRectangle(context, draw_rect, 1, 0, 0); -#endif - cairo_restore(context); - } -} - -void WebPluginDelegateImpl::WindowlessSetWindow() { - if (!instance()) - return; - - if (window_rect_.IsEmpty()) // wait for geometry to be set. - return; - - DCHECK(instance()->windowless()); - // Mozilla docs say that this window param is not used for windowless - // plugins; rather, the window is passed during the GraphicsExpose event. - DCHECK_EQ(window_.window, static_cast<void*>(NULL)); - - window_.clipRect.top = clip_rect_.y() + window_rect_.y(); - window_.clipRect.left = clip_rect_.x() + window_rect_.x(); - window_.clipRect.bottom = - clip_rect_.y() + clip_rect_.height() + window_rect_.y(); - window_.clipRect.right = - clip_rect_.x() + clip_rect_.width() + window_rect_.x(); - window_.height = window_rect_.height(); - window_.width = window_rect_.width(); - window_.x = window_rect_.x(); - window_.y = window_rect_.y(); - window_.type = NPWindowTypeDrawable; - - if (!window_.ws_info) - window_.ws_info = new NPSetWindowCallbackStruct; - NPSetWindowCallbackStruct* extra = - static_cast<NPSetWindowCallbackStruct*>(window_.ws_info); - extra->display = GDK_DISPLAY(); - int screen = DefaultScreen(GDK_DISPLAY()); - extra->visual = DefaultVisual(GDK_DISPLAY(), screen); - extra->depth = DefaultDepth(GDK_DISPLAY(), screen); - extra->colormap = DefaultColormap(GDK_DISPLAY(), screen); - - NPError err = instance()->NPP_SetWindow(&window_); - DCHECK(err == NPERR_NO_ERROR); - if (quirks_ & PLUGIN_QUIRK_WINDOWLESS_INVALIDATE_AFTER_SET_WINDOW) { - // After a NPP_SetWindow, Flash cancels its timer that generates the - // invalidates until it gets a paint event, but doesn't explicitly call - // NPP_InvalidateRect. - plugin_->InvalidateRect(clip_rect_); - } -} - -bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) { - DCHECK(instance()->windowless()); - - NPEvent np_event = {0}; - XFocusChangeEvent& event = np_event.xfocus; - event.type = focused ? FocusIn : FocusOut; - event.display = GDK_DISPLAY(); - // Same values as Firefox. .serial and .window stay 0. - event.mode = -1; - event.detail = NotifyDetailNone; - instance()->NPP_HandleEvent(&np_event); - return true; -} - -// Converts a WebInputEvent::Modifiers bitfield into a -// corresponding X modifier state. -static int GetXModifierState(int modifiers) { - int x_state = 0; - if (modifiers & WebInputEvent::ControlKey) - x_state |= ControlMask; - if (modifiers & WebInputEvent::ShiftKey) - x_state |= ShiftMask; - if (modifiers & WebInputEvent::AltKey) - x_state |= Mod1Mask; - if (modifiers & WebInputEvent::MetaKey) - x_state |= Mod2Mask; - if (modifiers & WebInputEvent::LeftButtonDown) - x_state |= Button1Mask; - if (modifiers & WebInputEvent::MiddleButtonDown) - x_state |= Button2Mask; - if (modifiers & WebInputEvent::RightButtonDown) - x_state |= Button3Mask; - // TODO(piman@google.com): There are other modifiers, e.g. Num Lock, that - // should be set (and Firefox does), but we didn't keep the information in - // the WebKit event. - return x_state; -} - -static bool NPEventFromWebMouseEvent(const WebMouseEvent& event, - Time timestamp, - NPEvent* np_event) { - np_event->xany.display = GDK_DISPLAY(); - // NOTE: Firefox keeps xany.serial and xany.window as 0. - - int modifier_state = GetXModifierState(event.modifiers); - - Window root = GDK_ROOT_WINDOW(); - switch (event.type) { - case WebInputEvent::MouseMove: { - np_event->type = MotionNotify; - XMotionEvent& motion_event = np_event->xmotion; - motion_event.root = root; - motion_event.time = timestamp; - motion_event.x = event.x; - motion_event.y = event.y; - motion_event.x_root = event.globalX; - motion_event.y_root = event.globalY; - motion_event.state = modifier_state; - motion_event.is_hint = NotifyNormal; - motion_event.same_screen = True; - break; - } - case WebInputEvent::MouseLeave: - case WebInputEvent::MouseEnter: { - if (event.type == WebInputEvent::MouseEnter) { - np_event->type = EnterNotify; - } else { - np_event->type = LeaveNotify; - } - XCrossingEvent& crossing_event = np_event->xcrossing; - crossing_event.root = root; - crossing_event.time = timestamp; - crossing_event.x = event.x; - crossing_event.y = event.y; - crossing_event.x_root = event.globalX; - crossing_event.y_root = event.globalY; - crossing_event.mode = -1; // This is what Firefox sets it to. - crossing_event.detail = NotifyDetailNone; - crossing_event.same_screen = True; - // TODO(piman@google.com): set this to the correct value. Firefox does. I - // don't know where to get the information though, we get focus - // notifications, but no unfocus. - crossing_event.focus = 0; - crossing_event.state = modifier_state; - break; - } - case WebInputEvent::MouseUp: - case WebInputEvent::MouseDown: { - if (event.type == WebInputEvent::MouseDown) { - np_event->type = ButtonPress; - } else { - np_event->type = ButtonRelease; - } - XButtonEvent& button_event = np_event->xbutton; - button_event.root = root; - button_event.time = timestamp; - button_event.x = event.x; - button_event.y = event.y; - button_event.x_root = event.globalX; - button_event.y_root = event.globalY; - button_event.state = modifier_state; - switch (event.button) { - case WebMouseEvent::ButtonLeft: - button_event.button = Button1; - break; - case WebMouseEvent::ButtonMiddle: - button_event.button = Button2; - break; - case WebMouseEvent::ButtonRight: - button_event.button = Button3; - break; - default: - NOTREACHED(); - } - button_event.same_screen = True; - break; - } - default: - NOTREACHED(); - return false; - } - return true; -} - -static bool NPEventFromWebKeyboardEvent(const WebKeyboardEvent& event, - Time timestamp, - NPEvent* np_event) { - np_event->xany.display = GDK_DISPLAY(); - // NOTE: Firefox keeps xany.serial and xany.window as 0. - - switch (event.type) { - case WebKeyboardEvent::KeyDown: - np_event->type = KeyPress; - break; - case WebKeyboardEvent::KeyUp: - np_event->type = KeyRelease; - break; - default: - NOTREACHED(); - return false; - } - XKeyEvent& key_event = np_event->xkey; - key_event.send_event = False; - key_event.display = GDK_DISPLAY(); - // NOTE: Firefox keeps xany.serial and xany.window as 0. - // TODO(piman@google.com): is this right for multiple screens ? - key_event.root = DefaultRootWindow(key_event.display); - key_event.time = timestamp; - // NOTE: We don't have the correct information for x/y/x_root/y_root. Firefox - // doesn't have it either, so we pass the same values. - key_event.x = 0; - key_event.y = 0; - key_event.x_root = -1; - key_event.y_root = -1; - key_event.state = GetXModifierState(event.modifiers); - key_event.keycode = event.nativeKeyCode; - key_event.same_screen = True; - return true; -} - -static bool NPEventFromWebInputEvent(const WebInputEvent& event, - Time timestamp, - NPEvent* np_event) { - switch (event.type) { - case WebInputEvent::MouseMove: - case WebInputEvent::MouseLeave: - case WebInputEvent::MouseEnter: - case WebInputEvent::MouseDown: - case WebInputEvent::MouseUp: - if (event.size < sizeof(WebMouseEvent)) { - NOTREACHED(); - return false; - } - return NPEventFromWebMouseEvent( - *static_cast<const WebMouseEvent*>(&event), timestamp, np_event); - case WebInputEvent::KeyDown: - case WebInputEvent::KeyUp: - if (event.size < sizeof(WebKeyboardEvent)) { - NOTREACHED(); - return false; - } - return NPEventFromWebKeyboardEvent( - *static_cast<const WebKeyboardEvent*>(&event), timestamp, np_event); - default: - return false; - } -} - -bool WebPluginDelegateImpl::PlatformHandleInputEvent( - const WebInputEvent& event, WebCursor::CursorInfo* cursor_info) { - - if (first_event_time_ < 0.0) - first_event_time_ = event.timeStampSeconds; - Time timestamp = static_cast<Time>( - (event.timeStampSeconds - first_event_time_) * 1.0e3); - NPEvent np_event = {0}; - if (!NPEventFromWebInputEvent(event, timestamp, &np_event)) { - return false; - } - // See comment about PLUGIN_QUIRK_WINDOWLESS_NO_RIGHT_CLICK in constructor. - if (windowless_ && - (quirks_ & PLUGIN_QUIRK_WINDOWLESS_NO_RIGHT_CLICK) && - (np_event.type == ButtonPress || np_event.type == ButtonRelease) && - (np_event.xbutton.button == Button3)) { - return false; - } - - bool ret = instance()->NPP_HandleEvent(&np_event) != 0; - - // Flash always returns false, even when the event is handled. - ret = true; - -#if 0 - if (event->event == WM_MOUSEMOVE) { - // Snag a reference to the current cursor ASAP in case the plugin modified - // it. There is a nasty race condition here with the multiprocess browser - // as someone might be setting the cursor in the main process as well. - *cursor = current_windowless_cursor_; - } -#endif - - return ret; -} - -} // namespace content diff --git a/content/common/cursors/webcursor.h b/content/common/cursors/webcursor.h index 29710a3..a5e2aed 100644 --- a/content/common/cursors/webcursor.h +++ b/content/common/cursors/webcursor.h @@ -23,8 +23,6 @@ typedef struct HINSTANCE__* HINSTANCE; typedef struct HICON__* HICON; typedef HICON HCURSOR; -#elif defined(TOOLKIT_GTK) -typedef struct _GdkCursor GdkCursor; #elif defined(OS_MACOSX) #ifdef __OBJC__ @class NSCursor; @@ -117,16 +115,6 @@ class CONTENT_EXPORT WebCursor { // with the WebCursor instance. HCURSOR GetCursor(HINSTANCE module_handle); -#elif defined(TOOLKIT_GTK) - // Return the stock GdkCursorType for this cursor, or GDK_CURSOR_IS_PIXMAP - // if it's a custom cursor. Return GDK_LAST_CURSOR to indicate that the cursor - // should be set to the system default. - // Returns an int so we don't need to include GDK headers in this header file. - int GetCursorType() const; - - // Return a new GdkCursor* for this cursor. Only valid if GetCursorType - // returns GDK_CURSOR_IS_PIXMAP. - GdkCursor* GetCustomCursor(); #elif defined(OS_MACOSX) // Initialize this from the given Cocoa NSCursor. void InitFromNSCursor(NSCursor* cursor); @@ -188,9 +176,6 @@ class CONTENT_EXPORT WebCursor { #elif defined(OS_WIN) // A custom cursor created from custom bitmap data by Webkit. HCURSOR custom_cursor_; -#elif defined(TOOLKIT_GTK) - // A custom cursor created that should be unref'ed from the destructor. - GdkCursor* unref_; #endif }; diff --git a/content/common/cursors/webcursor_gtk.cc b/content/common/cursors/webcursor_gtk.cc deleted file mode 100644 index a20db7b..0000000 --- a/content/common/cursors/webcursor_gtk.cc +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/common/cursors/webcursor.h" - -#include <gdk/gdk.h> -#include <gtk/gtk.h> - -#include "base/logging.h" -#include "third_party/WebKit/public/platform/WebCursorInfo.h" -#include "ui/gfx/gtk_util.h" - -using blink::WebCursorInfo; - -namespace { - -// webcursor_gtk_data.h is taken directly from WebKit's CursorGtk.h. -#include "content/common/cursors/webcursor_gtk_data.h" - -// This helper function is taken directly from WebKit's CursorGtk.cpp. -// It attempts to create a custom cursor from the data inlined in -// webcursor_gtk_data.h. -GdkCursor* GetInlineCustomCursor(CustomCursorType type) { - static GdkCursor* CustomCursorsGdk[G_N_ELEMENTS(CustomCursors)]; - GdkCursor* cursor = CustomCursorsGdk[type]; - if (cursor) - return cursor; - const CustomCursor& custom = CustomCursors[type]; - cursor = gdk_cursor_new_from_name(gdk_display_get_default(), custom.name); - if (!cursor) { - const GdkColor fg = { 0, 0, 0, 0 }; - const GdkColor bg = { 65535, 65535, 65535, 65535 }; - GdkPixmap* source = gdk_bitmap_create_from_data( - NULL, reinterpret_cast<const gchar*>(custom.bits), 32, 32); - GdkPixmap* mask = gdk_bitmap_create_from_data( - NULL, reinterpret_cast<const gchar*>(custom.mask_bits), 32, 32); - cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, - custom.hot_x, custom.hot_y); - g_object_unref(source); - g_object_unref(mask); - } - CustomCursorsGdk[type] = cursor; - return cursor; -} - -} // namespace - -namespace content { - -int WebCursor::GetCursorType() const { - // http://library.gnome.org/devel/gdk/2.12/gdk-Cursors.html has images - // of the default X theme, but beware that the user's cursor theme can - // change everything. - switch (type_) { - case WebCursorInfo::TypePointer: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeCross: - return GDK_CROSS; - case WebCursorInfo::TypeHand: - return GDK_HAND2; - case WebCursorInfo::TypeIBeam: - return GDK_XTERM; - case WebCursorInfo::TypeWait: - return GDK_WATCH; - case WebCursorInfo::TypeHelp: - return GDK_QUESTION_ARROW; - case WebCursorInfo::TypeEastResize: - return GDK_RIGHT_SIDE; - case WebCursorInfo::TypeNorthResize: - return GDK_TOP_SIDE; - case WebCursorInfo::TypeNorthEastResize: - return GDK_TOP_RIGHT_CORNER; - case WebCursorInfo::TypeNorthWestResize: - return GDK_TOP_LEFT_CORNER; - case WebCursorInfo::TypeSouthResize: - return GDK_BOTTOM_SIDE; - case WebCursorInfo::TypeSouthEastResize: - return GDK_BOTTOM_RIGHT_CORNER; - case WebCursorInfo::TypeSouthWestResize: - return GDK_BOTTOM_LEFT_CORNER; - case WebCursorInfo::TypeWestResize: - return GDK_LEFT_SIDE; - case WebCursorInfo::TypeNorthSouthResize: - return GDK_SB_V_DOUBLE_ARROW; - case WebCursorInfo::TypeEastWestResize: - return GDK_SB_H_DOUBLE_ARROW; - case WebCursorInfo::TypeNorthEastSouthWestResize: - case WebCursorInfo::TypeNorthWestSouthEastResize: - // There isn't really a useful cursor available for these. - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeColumnResize: - return GDK_SB_H_DOUBLE_ARROW; // TODO(evanm): is this correct? - case WebCursorInfo::TypeRowResize: - return GDK_SB_V_DOUBLE_ARROW; // TODO(evanm): is this correct? - case WebCursorInfo::TypeMiddlePanning: - return GDK_FLEUR; - case WebCursorInfo::TypeEastPanning: - return GDK_SB_RIGHT_ARROW; - case WebCursorInfo::TypeNorthPanning: - return GDK_SB_UP_ARROW; - case WebCursorInfo::TypeNorthEastPanning: - return GDK_TOP_RIGHT_CORNER; - case WebCursorInfo::TypeNorthWestPanning: - return GDK_TOP_LEFT_CORNER; - case WebCursorInfo::TypeSouthPanning: - return GDK_SB_DOWN_ARROW; - case WebCursorInfo::TypeSouthEastPanning: - return GDK_BOTTOM_RIGHT_CORNER; - case WebCursorInfo::TypeSouthWestPanning: - return GDK_BOTTOM_LEFT_CORNER; - case WebCursorInfo::TypeWestPanning: - return GDK_SB_LEFT_ARROW; - case WebCursorInfo::TypeMove: - return GDK_FLEUR; - case WebCursorInfo::TypeVerticalText: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeCell: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeContextMenu: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeAlias: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeProgress: - return GDK_WATCH; - case WebCursorInfo::TypeNoDrop: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeCopy: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeNone: - return GDK_BLANK_CURSOR; - case WebCursorInfo::TypeNotAllowed: - return GDK_LAST_CURSOR; - case WebCursorInfo::TypeZoomIn: - case WebCursorInfo::TypeZoomOut: - case WebCursorInfo::TypeGrab: - case WebCursorInfo::TypeGrabbing: - case WebCursorInfo::TypeCustom: - return GDK_CURSOR_IS_PIXMAP; - } - NOTREACHED(); - return GDK_LAST_CURSOR; -} - -gfx::NativeCursor WebCursor::GetNativeCursor() { - int type = GetCursorType(); - if (type == GDK_CURSOR_IS_PIXMAP) - return GetCustomCursor(); - return gfx::GetCursor(type); -} - -GdkCursor* WebCursor::GetCustomCursor() { - switch (type_) { - case WebCursorInfo::TypeZoomIn: - return GetInlineCustomCursor(CustomCursorZoomIn); - case WebCursorInfo::TypeZoomOut: - return GetInlineCustomCursor(CustomCursorZoomOut); - case WebCursorInfo::TypeGrab: - return GetInlineCustomCursor(CustomCursorGrab); - case WebCursorInfo::TypeGrabbing: - return GetInlineCustomCursor(CustomCursorGrabbing); - } - - if (type_ != WebCursorInfo::TypeCustom) { - NOTREACHED(); - return NULL; - } - - if (custom_size_.width() == 0 || custom_size_.height() == 0) { - // Some websites specify cursor images that are 0 sized, such as Bing Maps. - // Don't crash on this; just use the default cursor. - return NULL; - } - - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, - custom_size_.width(), custom_size_.height()); - bitmap.allocPixels(); - memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); - - GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); - GdkCursor* cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), - pixbuf, - hotspot_.x(), - hotspot_.y()); - - g_object_unref(pixbuf); - - if (unref_) - gdk_cursor_unref(unref_); - unref_ = cursor; - return cursor; -} - -void WebCursor::InitPlatformData() { - unref_ = NULL; - return; -} - -bool WebCursor::SerializePlatformData(Pickle* pickle) const { - return true; -} - -bool WebCursor::DeserializePlatformData(PickleIterator* iter) { - return true; -} - -bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { - return true; -} - -void WebCursor::CleanupPlatformData() { - if (unref_) { - gdk_cursor_unref(unref_); - unref_ = NULL; - } - return; -} - -void WebCursor::CopyPlatformData(const WebCursor& other) { - if (other.unref_) - unref_ = gdk_cursor_ref(other.unref_); - return; -} - -} // namespace content diff --git a/content/common/cursors/webcursor_gtk_data.h b/content/common/cursors/webcursor_gtk_data.h deleted file mode 100644 index c92e026..0000000 --- a/content/common/cursors/webcursor_gtk_data.h +++ /dev/null @@ -1,311 +0,0 @@ -// This file is a cut'n'paste from WebKit/WebCore/platform/gtk/CursorGtk.h, -// with slight modifications to fit within Chrome. Its original -// copyright is below. - -// This file intentionally doesn't have a header guard, since it is just -// data to be used within a C++ file. - -/* - * Copyright (C) 2001 Tim Copperfield <timecop@network.email.ne.jp> - * Copyright (C) 2007 Christian Dywan <christian@twotoasts.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -/* - These cursors are copied from Mozilla code: - http://lxr.mozilla.org/mozilla1.8/source/widget/src/gtk2/nsGtkCursors.h -*/ - -/* MOZ_CURSOR_VERTICAL_TEXT */ -static const uint8 moz_vertical_text_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, - 0x06, 0x60, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_vertical_text_mask_bits[] = { - 0x07, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, - 0xff, 0xff, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, - 0x0f, 0xf0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_CONTEXT_MENU */ -static const uint8 moz_menu_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0xfd, 0x00, 0x00, - 0xfc, 0xff, 0x00, 0x00, 0x7c, 0x84, 0x00, 0x00, 0x6c, 0xfc, 0x00, 0x00, - 0xc4, 0x84, 0x00, 0x00, 0xc0, 0xfc, 0x00, 0x00, 0x80, 0x85, 0x00, 0x00, - 0x80, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_menu_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0xfd, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, - 0xfe, 0xff, 0x01, 0x00, 0xfe, 0xff, 0x01, 0x00, 0xfe, 0xfe, 0x01, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, - 0xc0, 0xff, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_COPY */ -static const uint8 moz_copy_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x03, 0x00, 0x00, 0x7c, 0x30, 0x00, 0x00, 0x6c, 0x30, 0x00, 0x00, - 0xc4, 0xfc, 0x00, 0x00, 0xc0, 0xfc, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, - 0x80, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_copy_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, - 0xfe, 0x37, 0x00, 0x00, 0xfe, 0x7b, 0x00, 0x00, 0xfe, 0xfc, 0x00, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x00, 0x00, - 0xc0, 0x7b, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_ALIAS */ -static const uint8 moz_alias_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x03, 0x00, 0x00, 0x7c, 0xf0, 0x00, 0x00, 0x6c, 0xe0, 0x00, 0x00, - 0xc4, 0xf0, 0x00, 0x00, 0xc0, 0xb0, 0x00, 0x00, 0x80, 0x19, 0x00, 0x00, - 0x80, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_alias_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, - 0xfe, 0xf7, 0x00, 0x00, 0xfe, 0xfb, 0x01, 0x00, 0xfe, 0xf0, 0x01, 0x00, - 0xee, 0xf9, 0x01, 0x00, 0xe4, 0xf9, 0x01, 0x00, 0xc0, 0xbf, 0x00, 0x00, - 0xc0, 0x3f, 0x00, 0x00, 0x80, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_ZOOM_IN */ -static const uint8 moz_zoom_in_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x62, 0x04, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0xf9, 0x09, 0x00, 0x00, - 0xf9, 0x09, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0x62, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x0c, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_zoom_in_mask_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, - 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_ZOOM_OUT */ -static const uint8 moz_zoom_out_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0xf9, 0x09, 0x00, 0x00, - 0xf9, 0x09, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x0c, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_zoom_out_mask_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, - 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_HAND_GRAB */ -static const uint8 moz_hand_grab_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, - 0x60, 0x39, 0x00, 0x00, 0x90, 0x49, 0x00, 0x00, 0x90, 0x49, 0x01, 0x00, - 0x20, 0xc9, 0x02, 0x00, 0x20, 0x49, 0x02, 0x00, 0x58, 0x40, 0x02, 0x00, - 0x64, 0x00, 0x02, 0x00, 0x44, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, - 0x10, 0x00, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, - 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_hand_grab_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x60, 0x3f, 0x00, 0x00, - 0xf0, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf8, 0xff, 0x03, 0x00, - 0xf0, 0xff, 0x07, 0x00, 0xf8, 0xff, 0x07, 0x00, 0xfc, 0xff, 0x07, 0x00, - 0xfe, 0xff, 0x07, 0x00, 0xfe, 0xff, 0x03, 0x00, 0xfc, 0xff, 0x03, 0x00, - 0xf8, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x01, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_HAND_GRABBING */ -static const uint8 moz_hand_grabbing_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x36, 0x00, 0x00, 0x20, 0xc9, 0x00, 0x00, 0x20, 0x40, 0x01, 0x00, - 0x40, 0x00, 0x01, 0x00, 0x60, 0x00, 0x01, 0x00, 0x10, 0x00, 0x01, 0x00, - 0x10, 0x00, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, - 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_hand_grabbing_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x36, 0x00, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x03, 0x00, - 0xe0, 0xff, 0x03, 0x00, 0xf0, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x03, 0x00, - 0xf8, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x01, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -enum CustomCursorType { - CustomCursorCopy = 0, - CustomCursorAlias, - CustomCursorContextMenu, - CustomCursorZoomIn, - CustomCursorZoomOut, - CustomCursorVerticalText, - CustomCursorGrab, - CustomCursorGrabbing, -}; - -typedef struct { - const char* name; - const uint8* bits; - const uint8* mask_bits; - int hot_x; - int hot_y; -} CustomCursor; - -// create custom pixmap cursor from cursors in nsGTKCursorData.h -static const CustomCursor CustomCursors[] = { - { "copy", moz_copy_bits, moz_copy_mask_bits, 2, 2 }, - { "alias", moz_alias_bits, moz_alias_mask_bits, 2, 2 }, - { "context-menu", moz_menu_bits, moz_menu_mask_bits, 2, 2 }, - { "zoom-in", moz_zoom_in_bits, moz_zoom_in_mask_bits, 6, 6 }, - { "zoom-out", moz_zoom_out_bits, moz_zoom_out_mask_bits, 6, 6 }, - { "vertical-text", moz_vertical_text_bits, moz_vertical_text_mask_bits, 8, 4}, - { "grab", moz_hand_grab_bits, moz_hand_grab_mask_bits, 10, 10 }, - { "grabbing", moz_hand_grabbing_bits, moz_hand_grabbing_mask_bits, 10, 10 } -}; - -// This cursor intentionally left out of above structs. It is only used by -// RenderWidgetHostViewGtk. For an explanation see -// http://vektor-sigma.livejournal.com/1137.html (where it is referred -// to as left_ptr_watch). - -/* MOZ_CURSOR_SPINNING */ -static const uint8 moz_spinning_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x3b, 0x00, 0x00, 0x7c, 0x38, 0x00, 0x00, 0x6c, 0x54, 0x00, 0x00, - 0xc4, 0xdc, 0x00, 0x00, 0xc0, 0x44, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, - 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uint8 moz_spinning_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x3b, 0x00, 0x00, - 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, - 0xc0, 0x7f, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/content/common/gpu/client/gl_helper_benchmark.cc b/content/common/gpu/client/gl_helper_benchmark.cc index b55ae1f..b930bb0 100644 --- a/content/common/gpu/client/gl_helper_benchmark.cc +++ b/content/common/gpu/client/gl_helper_benchmark.cc @@ -37,10 +37,6 @@ #include "base/mac/scoped_nsautorelease_pool.h" #endif -#if defined(TOOLKIT_GTK) -#include "ui/gfx/gtk_util.h" -#endif - namespace content { using blink::WebGLId; @@ -317,9 +313,6 @@ int main(int argc, char** argv) { #if defined(OS_MACOSX) base::mac::ScopedNSAutoreleasePool pool; #endif -#if defined(TOOLKIT_GTK) - gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); -#endif gfx::GLSurface::InitializeOneOff(); return content::UnitTestTestSuite(suite).Run(); diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 181fa82..dcac8c8 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -224,7 +224,6 @@ 'browser/accessibility/accessibility_tree_formatter.cc', 'browser/accessibility/accessibility_tree_formatter.h', 'browser/accessibility/accessibility_tree_formatter_android.cc', - 'browser/accessibility/accessibility_tree_formatter_gtk.cc', 'browser/accessibility/accessibility_tree_formatter_mac.mm', 'browser/accessibility/accessibility_tree_formatter_utils_win.cc', 'browser/accessibility/accessibility_tree_formatter_utils_win.h', @@ -238,16 +237,12 @@ 'browser/accessibility/browser_accessibility_cocoa.h', 'browser/accessibility/browser_accessibility_cocoa.mm', 'browser/accessibility/browser_accessibility_delegate_mac.h', - 'browser/accessibility/browser_accessibility_gtk.cc', - 'browser/accessibility/browser_accessibility_gtk.h', 'browser/accessibility/browser_accessibility_mac.h', 'browser/accessibility/browser_accessibility_mac.mm', 'browser/accessibility/browser_accessibility_manager.cc', 'browser/accessibility/browser_accessibility_manager.h', 'browser/accessibility/browser_accessibility_manager_android.cc', 'browser/accessibility/browser_accessibility_manager_android.h', - 'browser/accessibility/browser_accessibility_manager_gtk.cc', - 'browser/accessibility/browser_accessibility_manager_gtk.h', 'browser/accessibility/browser_accessibility_manager_mac.h', 'browser/accessibility/browser_accessibility_manager_mac.mm', 'browser/accessibility/browser_accessibility_manager_win.cc', @@ -863,8 +858,6 @@ 'browser/renderer_host/backing_store.h', 'browser/renderer_host/backing_store_aura.cc', 'browser/renderer_host/backing_store_aura.h', - 'browser/renderer_host/backing_store_gtk.cc', - 'browser/renderer_host/backing_store_gtk.h', 'browser/renderer_host/backing_store_mac.h', 'browser/renderer_host/backing_store_mac.mm', 'browser/renderer_host/backing_store_manager.cc', @@ -900,16 +893,6 @@ 'browser/renderer_host/gamepad_browser_message_filter.h', 'browser/renderer_host/gpu_message_filter.cc', 'browser/renderer_host/gpu_message_filter.h', - 'browser/renderer_host/gtk_im_context_wrapper.cc', - 'browser/renderer_host/gtk_im_context_wrapper.h', - 'browser/renderer_host/gtk_key_bindings_handler.cc', - 'browser/renderer_host/gtk_key_bindings_handler.h', - 'browser/renderer_host/gtk_plugin_container.cc', - 'browser/renderer_host/gtk_plugin_container.h', - 'browser/renderer_host/gtk_plugin_container_manager.cc', - 'browser/renderer_host/gtk_plugin_container_manager.h', - 'browser/renderer_host/gtk_window_utils.cc', - 'browser/renderer_host/gtk_window_utils.h', 'browser/renderer_host/image_transport_factory_android.cc', 'browser/renderer_host/image_transport_factory_android.h', 'browser/renderer_host/ime_adapter_android.cc', @@ -959,8 +942,6 @@ 'browser/renderer_host/input/touchscreen_tap_suppression_controller_stub.cc', 'browser/renderer_host/input/web_input_event_builders_android.cc', 'browser/renderer_host/input/web_input_event_builders_android.h', - 'browser/renderer_host/input/web_input_event_builders_gtk.cc', - 'browser/renderer_host/input/web_input_event_builders_gtk.h', 'browser/renderer_host/input/web_input_event_builders_win.cc', 'browser/renderer_host/input/web_input_event_builders_win.h', 'browser/renderer_host/input/web_input_event_util.cc', @@ -1028,7 +1009,6 @@ 'browser/renderer_host/native_web_keyboard_event.cc', 'browser/renderer_host/native_web_keyboard_event_android.cc', 'browser/renderer_host/native_web_keyboard_event_aura.cc', - 'browser/renderer_host/native_web_keyboard_event_gtk.cc', 'browser/renderer_host/native_web_keyboard_event_mac.mm', 'browser/renderer_host/overscroll_configuration.cc', 'browser/renderer_host/overscroll_controller.cc', @@ -1119,8 +1099,6 @@ 'browser/renderer_host/render_widget_host_view_aura.h', 'browser/renderer_host/render_widget_host_view_base.cc', 'browser/renderer_host/render_widget_host_view_base.h', - 'browser/renderer_host/render_widget_host_view_gtk.cc', - 'browser/renderer_host/render_widget_host_view_gtk.h', 'browser/renderer_host/render_widget_host_view_mac_dictionary_helper.h', 'browser/renderer_host/render_widget_host_view_mac_dictionary_helper.mm', 'browser/renderer_host/render_widget_host_view_mac_editcommand_helper.h', @@ -1311,8 +1289,6 @@ 'browser/web_contents/aura/shadow_layer_delegate.h', 'browser/web_contents/aura/window_slider.cc', 'browser/web_contents/aura/window_slider.h', - 'browser/web_contents/drag_utils_gtk.cc', - 'browser/web_contents/drag_utils_gtk.h', 'browser/web_contents/touch_editable_impl_aura.cc', 'browser/web_contents/touch_editable_impl_aura.h', 'browser/web_contents/web_contents_android.cc', @@ -1323,18 +1299,12 @@ 'browser/web_contents/web_contents_view_android.h', 'browser/web_contents/web_contents_view_aura.cc', 'browser/web_contents/web_contents_view_aura.h', - 'browser/web_contents/web_contents_view_gtk.cc', - 'browser/web_contents/web_contents_view_gtk.h', 'browser/web_contents/web_contents_view_guest.cc', 'browser/web_contents/web_contents_view_guest.h', 'browser/web_contents/web_contents_view_mac.h', 'browser/web_contents/web_contents_view_mac.mm', - 'browser/web_contents/web_drag_dest_gtk.cc', - 'browser/web_contents/web_drag_dest_gtk.h', 'browser/web_contents/web_drag_dest_mac.h', 'browser/web_contents/web_drag_dest_mac.mm', - 'browser/web_contents/web_drag_source_gtk.cc', - 'browser/web_contents/web_drag_source_gtk.h', 'browser/web_contents/web_drag_source_mac.h', 'browser/web_contents/web_drag_source_mac.mm', 'browser/web_contents/web_drag_utils_win.cc', @@ -1551,15 +1521,6 @@ }, }, }], - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - # For FcLangSetAdd call in render_sandbox_host_linux.cc - '../build/linux/system.gyp:fontconfig', - '../build/linux/system.gyp:gtk', - # For XShm* in backing_store_x.cc - '../build/linux/system.gyp:x11', - ], - }], ['OS=="linux"', { 'dependencies': [ '../sandbox/sandbox.gyp:libc_urandom_override', @@ -1657,8 +1618,6 @@ 'browser/geolocation/wifi_data_provider_linux.cc', 'browser/power_save_blocker_ozone.cc', 'browser/power_save_blocker_x11.cc', - 'browser/renderer_host/gtk_key_bindings_handler.cc', - 'browser/renderer_host/gtk_key_bindings_handler.h', ], }], ['os_bsd==1', { @@ -1682,8 +1641,6 @@ '../ui/base/strings/ui_strings.gyp:ui_strings', ], 'sources/': [ - ['exclude', '^browser/renderer_host/gtk_im_context_wrapper.cc'], - ['exclude', '^browser/renderer_host/gtk_im_context_wrapper.h'], ['exclude', '^browser/renderer_host/input/touchpad_tap_suppression_controller.cc'], ], }, { diff --git a/content/content_child.gypi b/content/content_child.gypi index 4146d7f..575e5ff 100644 --- a/content/content_child.gypi +++ b/content/content_child.gypi @@ -116,7 +116,6 @@ 'child/npapi/webplugin_delegate_impl.h', 'child/npapi/webplugin_delegate_impl_android.cc', 'child/npapi/webplugin_delegate_impl_aura.cc', - 'child/npapi/webplugin_delegate_impl_gtk.cc', 'child/npapi/webplugin_delegate_impl_mac.mm', 'child/npapi/webplugin_delegate_impl_win.cc', 'child/npapi/webplugin_ime_win.cc', diff --git a/content/content_common.gypi b/content/content_common.gypi index 85c3aac9..6ac2b75 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -172,8 +172,6 @@ 'common/cursors/webcursor_aura.cc', 'common/cursors/webcursor_aurawin.cc', 'common/cursors/webcursor_aurax11.cc', - 'common/cursors/webcursor_gtk.cc', - 'common/cursors/webcursor_gtk_data.h', 'common/cursors/webcursor_mac.mm', 'common/cursors/webcursor_ozone.cc', 'common/cursors/webcursor_win.cc', @@ -555,11 +553,6 @@ 'content.gyp:common_aidl', ], }], - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - '../build/linux/system.gyp:gtk', - ], - }], ['use_pango == 1', { 'dependencies': [ '../build/linux/system.gyp:pangocairo', diff --git a/content/content_plugin.gypi b/content/content_plugin.gypi index 5f7e4a9..9219580 100644 --- a/content/content_plugin.gypi +++ b/content/content_plugin.gypi @@ -46,11 +46,6 @@ '<(DEPTH)/third_party/wtl/include', ], }], - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - '../build/linux/system.gyp:gtk', - ], - }], ['use_x11 == 1', { 'dependencies': [ '../build/linux/system.gyp:xext', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index b2cd6f3..4d0b1ce 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -561,11 +561,6 @@ 'renderer/input_tag_speech_dispatcher.h', ] }], - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - '../build/linux/system.gyp:gtk', - ], - }], ['OS=="mac"', { 'sources!': [ 'common/process_watcher_posix.cc', diff --git a/content/content_shell.gypi b/content/content_shell.gypi index c84d485..e319a37 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -108,9 +108,7 @@ 'shell/browser/shell_devtools_frontend.h', 'shell/browser/shell_download_manager_delegate.cc', 'shell/browser/shell_download_manager_delegate.h', - 'shell/browser/shell_gtk.cc', 'shell/browser/shell.h', - 'shell/browser/shell_javascript_dialog_gtk.cc', 'shell/browser/shell_javascript_dialog.h', 'shell/browser/shell_javascript_dialog_mac.mm', 'shell/browser/shell_javascript_dialog_manager.cc', @@ -119,7 +117,6 @@ 'shell/browser/shell_layout_tests_android.cc', 'shell/browser/shell_layout_tests_android.h', 'shell/browser/shell_login_dialog.cc', - 'shell/browser/shell_login_dialog_gtk.cc', 'shell/browser/shell_login_dialog.h', 'shell/browser/shell_login_dialog_mac.mm', 'shell/browser/shell_mac.mm', @@ -144,7 +141,6 @@ 'shell/browser/shell_views.cc', 'shell/browser/shell_web_contents_view_delegate_android.cc', 'shell/browser/shell_web_contents_view_delegate_creator.h', - 'shell/browser/shell_web_contents_view_delegate_gtk.cc', 'shell/browser/shell_web_contents_view_delegate.h', 'shell/browser/shell_web_contents_view_delegate_mac.mm', 'shell/browser/shell_web_contents_view_delegate_win.cc', @@ -321,9 +317,6 @@ '../ui/base/strings/ui_strings.gyp:ui_strings', '../ui/events/events.gyp:events', ], - 'sources/': [ - ['exclude', 'shell/browser/shell_gtk.cc'], - ], 'conditions': [ ['toolkit_views==1', { 'dependencies': [ @@ -570,11 +563,6 @@ '../sandbox/sandbox.gyp:sandbox', ], }], # OS=="win" or toolkit_uses_gtk == 1 - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - '<(DEPTH)/build/linux/system.gyp:gtk', - ], - }], # toolkit_uses_gtk ['OS=="mac"', { 'product_name': '<(content_shell_product_name)', 'dependencies!': [ diff --git a/content/content_tests.gypi b/content/content_tests.gypi index fc0d3a3..cfdda71 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -281,11 +281,6 @@ '../third_party/webrtc/modules/modules.gyp:video_capture_module', ], }], - ['toolkit_uses_gtk == 1', { - 'dependencies': [ - '../build/linux/system.gyp:gtk', - ], - }], ['use_glib == 1', { 'dependencies': [ '../build/linux/system.gyp:glib', @@ -464,7 +459,6 @@ 'browser/quota/mock_quota_manager_proxy.h', 'browser/quota/mock_quota_manager_unittest.cc', 'browser/renderer_host/compositing_iosurface_transformer_mac_unittest.cc', - 'browser/renderer_host/gtk_key_bindings_handler_unittest.cc', 'browser/renderer_host/input/gesture_event_queue_unittest.cc', 'browser/renderer_host/input/input_router_impl_unittest.cc', 'browser/renderer_host/input/mock_input_ack_handler.cc', @@ -501,7 +495,6 @@ 'browser/renderer_host/software_frame_manager_unittest.cc', 'browser/renderer_host/text_input_client_mac_unittest.mm', 'browser/renderer_host/web_input_event_aura_unittest.cc', - 'browser/renderer_host/input/web_input_event_builders_gtk_unittest.cc', 'browser/renderer_host/websocket_dispatcher_host_unittest.cc', 'browser/resolve_proxy_msg_helper_unittest.cc', 'browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc', @@ -821,7 +814,6 @@ }], ['chromeos==1', { 'sources/': [ - ['exclude', '^browser/renderer_host/gtk_key_bindings_handler_unittest.cc'], ['exclude', '^browser/geolocation/wifi_data_provider_linux_unittest.cc'], ], }], diff --git a/content/plugin/plugin_thread.cc b/content/plugin/plugin_thread.cc index 2573256..0a6a1c5 100644 --- a/content/plugin/plugin_thread.cc +++ b/content/plugin/plugin_thread.cc @@ -6,9 +6,7 @@ #include "build/build_config.h" -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> -#elif defined(OS_MACOSX) +#if defined(OS_MACOSX) #include <CoreFoundation/CoreFoundation.h> #endif @@ -31,10 +29,6 @@ #include "third_party/WebKit/public/web/WebKit.h" #include "ipc/ipc_channel_handle.h" -#if defined(TOOLKIT_GTK) -#include "ui/gfx/gtk_util.h" -#endif - #if defined(USE_X11) #include "ui/base/x/x11_util.h" #endif @@ -83,31 +77,6 @@ PluginThread::PluginThread() switches::kPluginPath); lazy_tls.Pointer()->Set(this); -#if defined(TOOLKIT_GTK) - { - // XEmbed plugins assume they are hosted in a Gtk application, so we need - // to initialize Gtk in the plugin process. - // g_thread_init API is deprecated since glib 2.31.0, see release note: - // http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041.html -#if !(GLIB_CHECK_VERSION(2, 31, 0)) - g_thread_init(NULL); -#endif - - // Flash has problems receiving clicks with newer GTKs due to the - // client-side windows change. To be safe, we just always set the - // backwards-compat environment variable. - setenv("GDK_NATIVE_WINDOWS", "1", 1); - - gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); - - // GTK after 2.18 resets the environment variable. But if we're using - // nspluginwrapper, that means it'll spawn its subprocess without the - // environment variable! So set it again. - setenv("GDK_NATIVE_WINDOWS", "1", 1); - } - - ui::SetDefaultX11ErrorHandlers(); -#endif PatchNPNFunctions(); diff --git a/content/public/browser/render_widget_host_view.h b/content/public/browser/render_widget_host_view.h index 7c89136..821dc21 100644 --- a/content/public/browser/render_widget_host_view.h +++ b/content/public/browser/render_widget_host_view.h @@ -13,10 +13,6 @@ #include "third_party/WebKit/public/web/WebInputEvent.h" #include "ui/gfx/native_widget_types.h" -#if defined(TOOLKIT_GTK) -#include <gdk/gdk.h> -#endif - class GURL; namespace gfx { @@ -151,13 +147,6 @@ class CONTENT_EXPORT RenderWidgetHostView { // Stops speaking, if it is currently in progress. virtual void StopSpeaking() = 0; #endif // defined(OS_MACOSX) - -#if defined(TOOLKIT_GTK) - // Gets the event for the last mouse down. - virtual GdkEventButton* GetLastMouseDown() = 0; - // Builds a submenu containing all the gtk input method commands. - virtual gfx::NativeView BuildInputMethodsGtkMenu() = 0; -#endif // defined(TOOLKIT_GTK) }; } // namespace content diff --git a/content/public/browser/web_contents_view_delegate.h b/content/public/browser/web_contents_view_delegate.h index f813291..c2f00d7 100644 --- a/content/public/browser/web_contents_view_delegate.h +++ b/content/public/browser/web_contents_view_delegate.h @@ -5,9 +5,7 @@ #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_ #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_ -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> -#elif defined(OS_MACOSX) +#if defined(OS_MACOSX) #import <Cocoa/Cocoa.h> #endif @@ -54,25 +52,6 @@ class CONTENT_EXPORT WebContentsViewDelegate { virtual bool Focus() = 0; virtual void TakeFocus(bool reverse) = 0; virtual void SizeChanged(const gfx::Size& size) = 0; -#elif defined(TOOLKIT_GTK) - // Initializes the WebContentsViewDelegate. - virtual void Initialize(GtkWidget* expanded_container, - ui::FocusStoreGtk* focus_store) = 0; - - // Returns the top widget that contains |view| passed in from WrapView. This - // is exposed through WebContentsViewGtk::GetNativeView() when a wrapper is - // supplied to a WebContentsViewGtk. - virtual gfx::NativeView GetNativeView() const = 0; - - // Handles a focus event from the renderer process. - virtual void Focus() = 0; - - // Gives the delegate a first chance at focus events from our render widget - // host, before the main view invokes its default behaviour. Returns TRUE if - // |return_value| has been set and that value should be returned to GTK+. - virtual gboolean OnNativeViewFocusEvent(GtkWidget* widget, - GtkDirectionType type, - gboolean* return_value) = 0; #elif defined(OS_MACOSX) // Returns a newly-created delegate for the RenderWidgetHostViewMac, to handle // events on the responder chain. diff --git a/content/public/browser/web_drag_dest_delegate.h b/content/public/browser/web_drag_dest_delegate.h index b1d4c61..0f13c94 100644 --- a/content/public/browser/web_drag_dest_delegate.h +++ b/content/public/browser/web_drag_dest_delegate.h @@ -5,10 +5,6 @@ #ifndef CONTENT_PUBLIC_BROWSER_WEB_DRAG_DEST_DELEGATE_H_ #define CONTENT_PUBLIC_BROWSER_WEB_DRAG_DEST_DELEGATE_H_ -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> -#endif // TOOLKIT_GTK - #include "base/strings/string16.h" class GURL; @@ -36,20 +32,11 @@ class WebDragDestDelegate { // This should also clear any state kept about this drag. virtual void OnDragLeave() = 0; -#if defined(TOOLKIT_GTK) - // Returns the bookmark atom type. GTK and Views return different values here. - virtual GdkAtom GetBookmarkTargetAtom() const = 0; - - // Called when WebDragDestkGtk detects that there's bookmark data in a - // drag. Not every drag will trigger these. - virtual void OnReceiveDataFromGtk(GtkSelectionData* data) = 0; - virtual void OnReceiveProcessedData(const GURL& url, - const base::string16& title) = 0; -#elif defined(USE_AURA) +#if defined(USE_AURA) // Called at the start of every drag to supply the data associated with the // drag. virtual void OnReceiveDragData(const ui::OSExchangeData& data) = 0; -#endif // TOOLKIT_GTK +#endif // USE_AURA virtual ~WebDragDestDelegate() {} }; diff --git a/content/renderer/npapi/webplugin_delegate_proxy.cc b/content/renderer/npapi/webplugin_delegate_proxy.cc index 9ed8276..1a78e76 100644 --- a/content/renderer/npapi/webplugin_delegate_proxy.cc +++ b/content/renderer/npapi/webplugin_delegate_proxy.cc @@ -4,9 +4,7 @@ #include "content/renderer/npapi/webplugin_delegate_proxy.h" -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> -#elif defined(USE_X11) +#if defined(USE_X11) #include <cairo/cairo.h> #endif diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc index 5a7ac7f..445b109 100644 --- a/content/renderer/render_view_browsertest.cc +++ b/content/renderer/render_view_browsertest.cc @@ -52,10 +52,6 @@ #include "ui/gfx/codec/jpeg_codec.h" #include "ui/gfx/range/range.h" -#if defined(OS_LINUX) && !defined(USE_AURA) -#include "ui/base/gtk/event_synthesis_gtk.h" -#endif - #if defined(USE_AURA) #include "ui/events/event.h" #endif @@ -270,39 +266,6 @@ class RenderViewImplTest : public RenderViewTest { flags); output->assign(1, static_cast<base::char16>(c)); return 1; -#elif defined(TOOLKIT_GTK) - // We ignore |layout|, which means we are only testing the layout of the - // current locale. TODO(estade): fix this to respect |layout|. - std::vector<GdkEvent*> events; - ui::SynthesizeKeyPressEvents( - NULL, static_cast<ui::KeyboardCode>(key_code), - modifiers & (MockKeyboard::LEFT_CONTROL | MockKeyboard::RIGHT_CONTROL), - modifiers & (MockKeyboard::LEFT_SHIFT | MockKeyboard::RIGHT_SHIFT), - modifiers & (MockKeyboard::LEFT_ALT | MockKeyboard::RIGHT_ALT), - &events); - - guint32 unicode_key = 0; - for (size_t i = 0; i < events.size(); ++i) { - // Only send the up/down events for key press itself (skip the up/down - // events for the modifier keys). - if ((i + 1) == (events.size() / 2) || i == (events.size() / 2)) { - unicode_key = gdk_keyval_to_unicode(events[i]->key.keyval); - NativeWebKeyboardEvent webkit_event(events[i]); - SendNativeKeyEvent(webkit_event); - - // Need to add a char event after the key down. - if (webkit_event.type == blink::WebInputEvent::RawKeyDown) { - NativeWebKeyboardEvent char_event = webkit_event; - char_event.type = blink::WebInputEvent::Char; - char_event.skip_in_browser = true; - SendNativeKeyEvent(char_event); - } - } - gdk_event_free(events[i]); - } - - output->assign(1, static_cast<base::char16>(unicode_key)); - return 1; #else NOTIMPLEMENTED(); return L'\0'; diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 45942b1..d923dbb 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -3365,17 +3365,11 @@ void RenderViewImpl::OnSetRendererPrefs( renderer_preferences_ = renderer_prefs; UpdateFontRenderingFromRendererPrefs(); -#if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) +#if defined(USE_DEFAULT_RENDER_THEME) if (renderer_prefs.use_custom_colors) { WebColorName name = blink::WebColorWebkitFocusRingColor; blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); -#if defined(TOOLKIT_GTK) - ui::NativeTheme::instance()->SetScrollbarColors( - renderer_prefs.thumb_inactive_color, - renderer_prefs.thumb_active_color, - renderer_prefs.track_color); -#endif // defined(TOOLKIT_GTK) if (webview()) { webview()->setSelectionColors( diff --git a/content/shell/browser/shell.h b/content/shell/browser/shell.h index 1156f21..4acffff4 100644 --- a/content/shell/browser/shell.h +++ b/content/shell/browser/shell.h @@ -18,12 +18,7 @@ #include "ui/gfx/native_widget_types.h" #include "ui/gfx/size.h" -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> -#include "ui/base/gtk/gtk_signal.h" - -typedef struct _GtkToolItem GtkToolItem; -#elif defined(OS_ANDROID) +#if defined(OS_ANDROID) #include "base/android/scoped_java_ref.h" #elif defined(USE_AURA) #if defined(OS_CHROMEOS) @@ -71,7 +66,7 @@ class Shell : public WebContentsDelegate, void ShowDevToolsForElementAt(int x, int y); void ShowDevToolsForTest(const std::string& settings); void CloseDevTools(); -#if defined(TOOLKIT_GTK) || defined(OS_MACOSX) +#if defined(OS_MACOSX) // Resizes the web content view to the given dimensions. void SizeTo(const gfx::Size& content_size); #endif diff --git a/content/shell/browser/shell_download_manager_delegate.cc b/content/shell/browser/shell_download_manager_delegate.cc index 7c47ade..45f86f3 100644 --- a/content/shell/browser/shell_download_manager_delegate.cc +++ b/content/shell/browser/shell_download_manager_delegate.cc @@ -4,10 +4,6 @@ #include "content/shell/browser/shell_download_manager_delegate.h" -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> -#endif - #if defined(OS_WIN) #include <windows.h> #include <commdlg.h> @@ -190,30 +186,6 @@ void ShellDownloadManagerDelegate::ChooseDownloadPath( if (GetSaveFileName(&save_as)) result = base::FilePath(std::wstring(save_as.lpstrFile)); -#elif defined(TOOLKIT_GTK) - GtkWidget *dialog; - gfx::NativeWindow parent_window; - std::string base_name = base::FilePath(suggested_path).BaseName().value(); - - parent_window = item->GetWebContents()->GetView()->GetTopLevelNativeWindow(); - dialog = gtk_file_chooser_dialog_new("Save File", - parent_window, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), - TRUE); - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), - base_name.c_str()); - - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - char *filename; - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - result = base::FilePath(filename); - g_free(filename); - } - gtk_widget_destroy(dialog); #else NOTIMPLEMENTED(); #endif diff --git a/content/shell/browser/shell_gtk.cc b/content/shell/browser/shell_gtk.cc deleted file mode 100644 index f9c8db4..0000000 --- a/content/shell/browser/shell_gtk.cc +++ /dev/null @@ -1,351 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/shell/browser/shell.h" - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "base/logging.h" -#include "base/strings/string_piece.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/native_web_keyboard_event.h" -#include "content/public/browser/render_widget_host_view.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_view.h" -#include "content/public/common/renderer_preferences.h" -#include "content/shell/browser/shell_browser_context.h" -#include "content/shell/browser/shell_content_browser_client.h" - -namespace content { - -namespace { - -// Callback for Debug > Show web inspector... menu item. -gboolean ShowWebInspectorActivated(GtkWidget* widget, Shell* shell) { - shell->ShowDevTools(); - return FALSE; // Don't stop this message. -} - -GtkWidget* AddMenuEntry(GtkWidget* menu_widget, const char* text, - GCallback callback, Shell* shell) { - GtkWidget* entry = gtk_menu_item_new_with_label(text); - g_signal_connect(entry, "activate", callback, shell); - gtk_menu_shell_append(GTK_MENU_SHELL(menu_widget), entry); - return entry; -} - -GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) { - GtkWidget* menu_widget = gtk_menu_new(); - GtkWidget* menu_header = gtk_menu_item_new_with_label(text); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_header), menu_widget); - gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_header); - return menu_widget; -} - -GtkWidget* CreateMenuBar(Shell* shell) { - GtkWidget* menu_bar = gtk_menu_bar_new(); - GtkWidget* debug_menu = CreateMenu(menu_bar, "Debug"); - AddMenuEntry(debug_menu, "Show web inspector...", - G_CALLBACK(ShowWebInspectorActivated), shell); - return menu_bar; -} - -} // namespace - -void Shell::PlatformInitialize(const gfx::Size& default_window_size) { -} - -void Shell::PlatformExit() { -} - -void Shell::PlatformCleanUp() { - // Nothing to clean up; GTK will clean up the widgets shortly after. -} - -void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { - if (headless_) - return; - - GtkToolItem* item = NULL; - switch (control) { - case BACK_BUTTON: - item = back_button_; - break; - case FORWARD_BUTTON: - item = forward_button_; - break; - case STOP_BUTTON: - item = stop_button_; - break; - default: - NOTREACHED() << "Unknown UI control"; - return; - } - gtk_widget_set_sensitive(GTK_WIDGET(item), is_enabled); -} - -void Shell::PlatformSetAddressBarURL(const GURL& url) { - if (headless_) - return; - - gtk_entry_set_text(GTK_ENTRY(url_edit_view_), url.spec().c_str()); -} - -void Shell::PlatformSetIsLoading(bool loading) { - if (headless_) - return; - - if (loading) - gtk_spinner_start(GTK_SPINNER(spinner_)); - else - gtk_spinner_stop(GTK_SPINNER(spinner_)); -} - -void Shell::PlatformCreateWindow(int width, int height) { - ui_elements_height_ = 0; - if (headless_) { - content_size_ = gfx::Size(width, height); - return; - } - - window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); - gtk_window_set_title(window_, "Content Shell"); - g_signal_connect(G_OBJECT(window_), "destroy", - G_CALLBACK(OnWindowDestroyedThunk), this); - - vbox_ = gtk_vbox_new(FALSE, 0); - - // Create the menu bar. - GtkWidget* menu_bar = CreateMenuBar(this); - gtk_box_pack_start(GTK_BOX(vbox_), menu_bar, FALSE, FALSE, 0); - - // Create the object that mediates accelerators. - GtkAccelGroup* accel_group = gtk_accel_group_new(); - gtk_window_add_accel_group(GTK_WINDOW(window_), accel_group); - - // Set global window handling accelerators: - gtk_accel_group_connect( - accel_group, GDK_w, GDK_CONTROL_MASK, - GTK_ACCEL_VISIBLE, - g_cclosure_new(G_CALLBACK(OnCloseWindowKeyPressedThunk), - this, NULL)); - - gtk_accel_group_connect( - accel_group, GDK_n, GDK_CONTROL_MASK, - GTK_ACCEL_VISIBLE, - g_cclosure_new(G_CALLBACK(OnNewWindowKeyPressedThunk), - this, NULL)); - - gtk_accel_group_connect( - accel_group, GDK_F5, (GdkModifierType)0, - GTK_ACCEL_VISIBLE, - g_cclosure_new(G_CALLBACK(OnReloadKeyPressedThunk), - this, NULL)); - - GtkWidget* toolbar = gtk_toolbar_new(); - // Turn off the labels on the toolbar buttons. - gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); - - back_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK); - g_signal_connect(back_button_, "clicked", - G_CALLBACK(&OnBackButtonClickedThunk), this); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), back_button_, -1 /* append */); - gtk_widget_add_accelerator(GTK_WIDGET(back_button_), "clicked", accel_group, - GDK_Left, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); - - forward_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD); - g_signal_connect(forward_button_, "clicked", - G_CALLBACK(&OnForwardButtonClickedThunk), this); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), forward_button_, -1 /* append */); - gtk_widget_add_accelerator(GTK_WIDGET(forward_button_), "clicked", - accel_group, - GDK_Right, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); - - reload_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH); - g_signal_connect(reload_button_, "clicked", - G_CALLBACK(&OnReloadButtonClickedThunk), this); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), reload_button_, -1 /* append */); - gtk_widget_add_accelerator(GTK_WIDGET(reload_button_), "clicked", - accel_group, - GDK_r, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - - stop_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_STOP); - g_signal_connect(stop_button_, "clicked", - G_CALLBACK(&OnStopButtonClickedThunk), this); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), stop_button_, -1 /* append */); - - url_edit_view_ = gtk_entry_new(); - g_signal_connect(G_OBJECT(url_edit_view_), "activate", - G_CALLBACK(&OnURLEntryActivateThunk), this); - - gtk_accel_group_connect( - accel_group, GDK_l, GDK_CONTROL_MASK, - GTK_ACCEL_VISIBLE, - g_cclosure_new(G_CALLBACK(OnHighlightURLViewThunk), - this, NULL)); - - GtkToolItem* tool_item = gtk_tool_item_new(); - gtk_container_add(GTK_CONTAINER(tool_item), url_edit_view_); - gtk_tool_item_set_expand(tool_item, TRUE); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1 /* append */); - - // Center a 20x20 spinner in a 26x24 area. - GtkWidget* spinner_alignment = gtk_alignment_new(0.5, 0.5, 0, 0); - gtk_alignment_set_padding(GTK_ALIGNMENT(spinner_alignment), 2, 2, 4, 4); - spinner_ = gtk_spinner_new(); - gtk_widget_set_size_request(spinner_, 20, 20); - gtk_container_add(GTK_CONTAINER(spinner_alignment), spinner_); - - spinner_item_ = gtk_tool_item_new(); - gtk_container_add(GTK_CONTAINER(spinner_item_), spinner_alignment); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), spinner_item_, -1 /* append */); - - gtk_box_pack_start(GTK_BOX(vbox_), toolbar, FALSE, FALSE, 0); - - gtk_container_add(GTK_CONTAINER(window_), vbox_); - - // Trigger layout of the UI elements, so that we can measure their - // heights. The width and height passed to this method are meant for the web - // contents view, not the top-level window. Since Gtk only seems to provide a - // suitable resizing function for top-level windows, we need to know how to - // convert from web contents view size to top-level window size. - gtk_widget_show_all(GTK_WIDGET(vbox_)); - - // Measure the heights of the UI elements, now that they have been laid out. - GtkRequisition elm_size; - gtk_widget_size_request(menu_bar, &elm_size); - ui_elements_height_ += elm_size.height; - gtk_widget_size_request(toolbar, &elm_size); - ui_elements_height_ += elm_size.height; - - // We're ready to set an initial window size. - SizeTo(gfx::Size(width, height)); - - // Finally, show the window. - gtk_widget_show_all(GTK_WIDGET(window_)); -} - -void Shell::PlatformSetContents() { - if (headless_) { - SizeTo(content_size_); - return; - } - - WebContentsView* content_view = web_contents_->GetView(); - gtk_container_add(GTK_CONTAINER(vbox_), content_view->GetNativeView()); -} - -void Shell::SizeTo(const gfx::Size& content_size) { - content_size_ = content_size; - - if (window_) { - gtk_window_resize(window_, - content_size.width(), - content_size.height() + ui_elements_height_); - } else if (web_contents_) { - RenderWidgetHostView* render_widget_host_view = - web_contents_->GetRenderWidgetHostView(); - if (render_widget_host_view) - render_widget_host_view->SetSize(content_size); - } -} - -void Shell::PlatformResizeSubViews() { - // Not needed; the subviews are bound. -} - -bool Shell::PlatformHandleContextMenu( - const content::ContextMenuParams& params) { - return false; -} - -void Shell::Close() { - if (headless_) { - delete this; - return; - } - - gtk_widget_destroy(GTK_WIDGET(window_)); -} - -void Shell::OnBackButtonClicked(GtkWidget* widget) { - GoBackOrForward(-1); -} - -void Shell::OnForwardButtonClicked(GtkWidget* widget) { - GoBackOrForward(1); -} - -void Shell::OnReloadButtonClicked(GtkWidget* widget) { - Reload(); -} - -void Shell::OnStopButtonClicked(GtkWidget* widget) { - Stop(); -} - -void Shell::OnURLEntryActivate(GtkWidget* entry) { - const gchar* str = gtk_entry_get_text(GTK_ENTRY(entry)); - GURL url(str); - if (!url.has_scheme()) - url = GURL(std::string("http://") + std::string(str)); - if (url.is_valid()) - LoadURL(url); -} - -// Callback for when the main window is destroyed. -gboolean Shell::OnWindowDestroyed(GtkWidget* window) { - delete this; - return FALSE; // Don't stop this message. -} - -gboolean Shell::OnCloseWindowKeyPressed(GtkAccelGroup* accel_group, - GObject* acceleratable, - guint keyval, - GdkModifierType modifier) { - gtk_widget_destroy(GTK_WIDGET(window_)); - return TRUE; -} - -gboolean Shell::OnNewWindowKeyPressed(GtkAccelGroup* accel_group, - GObject* acceleratable, - guint keyval, - GdkModifierType modifier) { - ShellBrowserContext* browser_context = - ShellContentBrowserClient::Get()->browser_context(); - Shell::CreateNewWindow(browser_context, - GURL(), - NULL, - MSG_ROUTING_NONE, - gfx::Size()); - return TRUE; -} - -gboolean Shell::OnHighlightURLView(GtkAccelGroup* accel_group, - GObject* acceleratable, - guint keyval, - GdkModifierType modifier) { - gtk_widget_grab_focus(GTK_WIDGET(url_edit_view_)); - return TRUE; -} - -gboolean Shell::OnReloadKeyPressed(GtkAccelGroup* accel_group, - GObject* acceleratable, - guint keyval, - GdkModifierType modifier) { - Reload(); - return TRUE; -} - -void Shell::PlatformSetTitle(const base::string16& title) { - if (headless_) - return; - - std::string title_utf8 = base::UTF16ToUTF8(title); - gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str()); -} - -} // namespace content diff --git a/content/shell/browser/shell_javascript_dialog.h b/content/shell/browser/shell_javascript_dialog.h index 233296b..b2d4d42 100644 --- a/content/shell/browser/shell_javascript_dialog.h +++ b/content/shell/browser/shell_javascript_dialog.h @@ -7,10 +7,6 @@ #include "content/public/browser/javascript_dialog_manager.h" -#if defined(TOOLKIT_GTK) -#include "ui/base/gtk/gtk_signal.h" -#endif - #if defined(OS_MACOSX) #if __OBJC__ @class ShellJavaScriptDialogHelper; @@ -50,10 +46,6 @@ class ShellJavaScriptDialog { base::string16 default_prompt_text_; static INT_PTR CALLBACK DialogProc(HWND dialog, UINT message, WPARAM wparam, LPARAM lparam); -#elif defined(TOOLKIT_GTK) - GtkWidget* gtk_dialog_; - gfx::NativeWindow parent_window_; - CHROMEGTK_CALLBACK_1(ShellJavaScriptDialog, void, OnResponse, int); #endif DISALLOW_COPY_AND_ASSIGN(ShellJavaScriptDialog); diff --git a/content/shell/browser/shell_javascript_dialog_gtk.cc b/content/shell/browser/shell_javascript_dialog_gtk.cc deleted file mode 100644 index 14326ca..0000000 --- a/content/shell/browser/shell_javascript_dialog_gtk.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/shell/browser/shell_javascript_dialog.h" - -#include <gtk/gtk.h> - -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "content/shell/app/resource.h" -#include "content/shell/browser/shell.h" -#include "content/shell/browser/shell_javascript_dialog_manager.h" - -namespace { - -const char kPromptTextId[] = "content_shell_prompt_text"; - -// If there's a text entry in the dialog, get the text from the first one and -// return it. -base::string16 GetPromptText(GtkDialog* dialog) { - GtkWidget* widget = static_cast<GtkWidget*>( - g_object_get_data(G_OBJECT(dialog), kPromptTextId)); - if (widget) - return base::UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(widget))); - return base::string16(); -} - -} // namespace - - -namespace content { - -ShellJavaScriptDialog::ShellJavaScriptDialog( - ShellJavaScriptDialogManager* manager, - gfx::NativeWindow parent_window, - JavaScriptMessageType message_type, - const base::string16& message_text, - const base::string16& default_prompt_text, - const JavaScriptDialogManager::DialogClosedCallback& callback) - : manager_(manager), - callback_(callback), - parent_window_(parent_window) { - GtkButtonsType buttons = GTK_BUTTONS_NONE; - GtkMessageType gtk_message_type = GTK_MESSAGE_OTHER; - - switch (message_type) { - case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: - buttons = GTK_BUTTONS_NONE; - gtk_message_type = GTK_MESSAGE_WARNING; - break; - - case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: - buttons = GTK_BUTTONS_CANCEL; - gtk_message_type = GTK_MESSAGE_QUESTION; - break; - - case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: - buttons = GTK_BUTTONS_CANCEL; - gtk_message_type = GTK_MESSAGE_QUESTION; - break; - - default: - NOTREACHED(); - } - - gtk_dialog_ = gtk_message_dialog_new(parent_window_, - GTK_DIALOG_MODAL, - gtk_message_type, - buttons, - "%s", - base::UTF16ToUTF8(message_text).c_str()); - g_signal_connect(gtk_dialog_, - "delete-event", - G_CALLBACK(gtk_widget_hide_on_delete), - NULL); - gtk_window_set_title(GTK_WINDOW(gtk_dialog_), "JavaScript"); - - GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), - GTK_STOCK_OK, - GTK_RESPONSE_OK); - - if (message_type != content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) - gtk_widget_grab_focus(ok_button); - - if (message_type == content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { - GtkWidget* content_area = - gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_)); - GtkWidget* text_box = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(text_box), - base::UTF16ToUTF8(default_prompt_text).c_str()); - gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0); - g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); - gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); - } - - gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); - g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); - gtk_widget_show_all(GTK_WIDGET(gtk_dialog_)); -} - -ShellJavaScriptDialog::~ShellJavaScriptDialog() { -} - -void ShellJavaScriptDialog::Cancel() { -} - -void ShellJavaScriptDialog::OnResponse(GtkWidget* dialog, int response_id) { - switch (response_id) { - case GTK_RESPONSE_OK: - callback_.Run(true, GetPromptText(GTK_DIALOG(dialog))); - break; - case GTK_RESPONSE_CANCEL: - case GTK_RESPONSE_DELETE_EVENT: - callback_.Run(false, base::string16()); - break; - default: - NOTREACHED(); - } - - gtk_widget_destroy(dialog); - - manager_->DialogClosed(this); -} - -} // namespace content diff --git a/content/shell/browser/shell_login_dialog.h b/content/shell/browser/shell_login_dialog.h index db70cb6..76ad054 100644 --- a/content/shell/browser/shell_login_dialog.h +++ b/content/shell/browser/shell_login_dialog.h @@ -9,10 +9,6 @@ #include "base/strings/string16.h" #include "content/public/browser/resource_dispatcher_host_login_delegate.h" -#if defined(TOOLKIT_GTK) -#include "ui/base/gtk/gtk_signal.h" -#endif - #if defined(OS_MACOSX) #if __OBJC__ @class ShellLoginDialogHelper; @@ -85,11 +81,6 @@ class ShellLoginDialog : public ResourceDispatcherHostLoginDelegate { #if defined(OS_MACOSX) // Threading: UI thread. ShellLoginDialogHelper* helper_; // owned -#elif defined(TOOLKIT_GTK) - GtkWidget* username_entry_; - GtkWidget* password_entry_; - GtkWidget* root_; - CHROMEGTK_CALLBACK_1(ShellLoginDialog, void, OnResponse, int); #endif }; diff --git a/content/shell/browser/shell_login_dialog_gtk.cc b/content/shell/browser/shell_login_dialog_gtk.cc deleted file mode 100644 index 7ac1f58..0000000 --- a/content/shell/browser/shell_login_dialog_gtk.cc +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/shell/browser/shell_login_dialog.h" - -#include <gtk/gtk.h> - -#include "base/logging.h" -#include "base/strings/string16.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/resource_dispatcher_host.h" -#include "content/public/browser/resource_request_info.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_view.h" -#include "ui/base/gtk/gtk_hig_constants.h" - -namespace content { - -void ShellLoginDialog::PlatformCreateDialog(const base::string16& message) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - int render_process_id; - int render_frame_id; - if (!ResourceRequestInfo::ForRequest(request_)->GetAssociatedRenderFrame( - &render_process_id, &render_frame_id)) { - NOTREACHED(); - } - - WebContents* web_contents = NULL; - RenderFrameHost* render_frame_host = - RenderFrameHost::FromID(render_process_id, render_frame_id); - web_contents = WebContents::FromRenderFrameHost(render_frame_host); - DCHECK(web_contents); - - gfx::NativeWindow parent_window = - web_contents->GetView()->GetTopLevelNativeWindow(); - - root_ = gtk_message_dialog_new(parent_window, - GTK_DIALOG_MODAL, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK_CANCEL, - "Please log in."); - - GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(root_)); - GtkWidget* label = gtk_label_new(base::UTF16ToUTF8(message).c_str()); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0); - - username_entry_ = gtk_entry_new(); - gtk_entry_set_activates_default(GTK_ENTRY(username_entry_), TRUE); - - password_entry_ = gtk_entry_new(); - gtk_entry_set_activates_default(GTK_ENTRY(password_entry_), TRUE); - gtk_entry_set_visibility(GTK_ENTRY(password_entry_), FALSE); - - GtkWidget* table = gtk_table_new(2, 2, FALSE); - gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing); - gtk_table_set_row_spacings(GTK_TABLE(table), ui::kControlSpacing); - - GtkWidget* username_label = gtk_label_new("Username:"); - gtk_misc_set_alignment(GTK_MISC(username_label), 0, 0.5); - - gtk_table_attach(GTK_TABLE(table), username_label, 0, 1, 0, 1, GTK_FILL, - GTK_FILL, 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), username_entry_, 1, 2, 0, 1); - - GtkWidget* password_label = gtk_label_new("Password:"); - gtk_misc_set_alignment(GTK_MISC(password_label), 0, 0.5); - - gtk_table_attach(GTK_TABLE(table), password_label, 0, 1, 1, 2, GTK_FILL, - GTK_FILL, 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), password_entry_, 1, 2, 1, 2); - - gtk_box_pack_start(GTK_BOX(content_area), table, FALSE, FALSE, 0); - - g_signal_connect(root_, "response", G_CALLBACK(OnResponseThunk), this); - gtk_widget_grab_focus(username_entry_); - gtk_widget_show_all(GTK_WIDGET(root_)); -} - -void ShellLoginDialog::PlatformCleanUp() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); -} - -void ShellLoginDialog::PlatformRequestCancelled() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); -} - -void ShellLoginDialog::OnResponse(GtkWidget* sender, int response_id) { - switch (response_id) { - case GTK_RESPONSE_OK: - UserAcceptedAuth( - base::UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(username_entry_))), - base::UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(password_entry_)))); - break; - case GTK_RESPONSE_CANCEL: - case GTK_RESPONSE_DELETE_EVENT: - UserCancelledAuth(); - break; - default: - NOTREACHED(); - } - - gtk_widget_destroy(root_); -} - -} // namespace content diff --git a/content/shell/browser/shell_web_contents_view_delegate.h b/content/shell/browser/shell_web_contents_view_delegate.h index 7233e13..6181864 100644 --- a/content/shell/browser/shell_web_contents_view_delegate.h +++ b/content/shell/browser/shell_web_contents_view_delegate.h @@ -9,11 +9,6 @@ #include "content/public/browser/web_contents_view_delegate.h" #include "content/public/common/context_menu_params.h" -#if defined(TOOLKIT_GTK) -#include "ui/base/gtk/gtk_signal.h" -#include "ui/base/gtk/owned_widget_gtk.h" -#endif - namespace content { class ShellWebContentsViewDelegate : public WebContentsViewDelegate { @@ -26,15 +21,7 @@ class ShellWebContentsViewDelegate : public WebContentsViewDelegate { const ContextMenuParams& params) OVERRIDE; virtual WebDragDestDelegate* GetDragDestDelegate() OVERRIDE; -#if defined(TOOLKIT_GTK) - virtual void Initialize(GtkWidget* expanded_container, - ui::FocusStoreGtk* focus_store) OVERRIDE; - virtual gfx::NativeView GetNativeView() const OVERRIDE; - virtual void Focus() OVERRIDE; - virtual gboolean OnNativeViewFocusEvent(GtkWidget* widget, - GtkDirectionType type, - gboolean* return_value) OVERRIDE; -#elif defined(OS_MACOSX) +#if defined(OS_MACOSX) virtual NSObject<RenderWidgetHostViewMacDelegate>* CreateRenderWidgetHostViewDelegate( RenderWidgetHost* render_widget_host) OVERRIDE; @@ -52,30 +39,6 @@ class ShellWebContentsViewDelegate : public WebContentsViewDelegate { WebContents* web_contents_; ContextMenuParams params_; -#if defined(TOOLKIT_GTK) - ui::OwnedWidgetGtk floating_; - GtkWidget* expanded_container_; - - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnBackMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnForwardMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnReloadMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnOpenURLMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnCutMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnCopyMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnPasteMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnDeleteMenuActivated); - CHROMEGTK_CALLBACK_0(ShellWebContentsViewDelegate, void, - OnInspectMenuActivated); -#endif - DISALLOW_COPY_AND_ASSIGN(ShellWebContentsViewDelegate); }; diff --git a/content/shell/browser/shell_web_contents_view_delegate_gtk.cc b/content/shell/browser/shell_web_contents_view_delegate_gtk.cc deleted file mode 100644 index 5f03f7be..0000000 --- a/content/shell/browser/shell_web_contents_view_delegate_gtk.cc +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/shell/browser/shell_web_contents_view_delegate.h" - -#include "base/command_line.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/render_widget_host_view.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_view.h" -#include "content/public/common/context_menu_params.h" -#include "content/shell/browser/shell.h" -#include "content/shell/browser/shell_browser_context.h" -#include "content/shell/browser/shell_browser_main_parts.h" -#include "content/shell/browser/shell_content_browser_client.h" -#include "content/shell/browser/shell_devtools_frontend.h" -#include "content/shell/browser/shell_web_contents_view_delegate_creator.h" -#include "content/shell/common/shell_switches.h" -#include "third_party/WebKit/public/web/WebContextMenuData.h" -#include "ui/base/gtk/focus_store_gtk.h" -#include "ui/base/gtk/gtk_floating_container.h" - -using blink::WebContextMenuData; - -namespace content { - -WebContentsViewDelegate* CreateShellWebContentsViewDelegate( - WebContents* web_contents) { - return new ShellWebContentsViewDelegate(web_contents); -} - -ShellWebContentsViewDelegate::ShellWebContentsViewDelegate( - WebContents* web_contents) - : web_contents_(web_contents), - floating_(gtk_floating_container_new()) { -} - -ShellWebContentsViewDelegate::~ShellWebContentsViewDelegate() { - floating_.Destroy(); -} - -void ShellWebContentsViewDelegate::ShowContextMenu( - RenderFrameHost* render_frame_host, - const ContextMenuParams& params) { - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) - return; - - GtkWidget* menu = gtk_menu_new(); - - params_ = params; - bool has_link = !params_.unfiltered_link_url.is_empty(); - bool has_selection = !params_.selection_text.empty(); - - if (params_.media_type == WebContextMenuData::MediaTypeNone && - !has_link && - !has_selection && - !params_.is_editable) { - GtkWidget* back_menu = gtk_menu_item_new_with_label("Back"); - gtk_menu_append(GTK_MENU(menu), back_menu); - g_signal_connect(back_menu, - "activate", - G_CALLBACK(OnBackMenuActivatedThunk), - this); - gtk_widget_set_sensitive(back_menu, - web_contents_->GetController().CanGoBack()); - - GtkWidget* forward_menu = gtk_menu_item_new_with_label("Forward"); - gtk_menu_append(GTK_MENU(menu), forward_menu); - g_signal_connect(forward_menu, - "activate", - G_CALLBACK(OnForwardMenuActivatedThunk), - this); - gtk_widget_set_sensitive(forward_menu, - web_contents_->GetController().CanGoForward()); - - GtkWidget* reload_menu = gtk_menu_item_new_with_label("Reload"); - gtk_menu_append(GTK_MENU(menu), reload_menu); - g_signal_connect(reload_menu, - "activate", - G_CALLBACK(OnReloadMenuActivatedThunk), - this); - - GtkWidget* navigate_separator = gtk_separator_menu_item_new(); - gtk_menu_append(GTK_MENU(menu), navigate_separator); - } - - if (has_link) { - GtkWidget* open_menu = gtk_menu_item_new_with_label("Open in New Window"); - gtk_menu_append(GTK_MENU(menu), open_menu); - g_signal_connect(open_menu, - "activate", - G_CALLBACK(OnOpenURLMenuActivatedThunk), - this); - - GtkWidget* link_separator = gtk_separator_menu_item_new(); - gtk_menu_append(GTK_MENU(menu), link_separator); - } - - if (params_.is_editable) { - GtkWidget* cut_menu = gtk_menu_item_new_with_label("Cut"); - gtk_menu_append(GTK_MENU(menu), cut_menu); - g_signal_connect(cut_menu, - "activate", - G_CALLBACK(OnCutMenuActivatedThunk), - this); - gtk_widget_set_sensitive( - cut_menu, - params_.edit_flags & WebContextMenuData::CanCut); - - GtkWidget* copy_menu = gtk_menu_item_new_with_label("Copy"); - gtk_menu_append(GTK_MENU(menu), copy_menu); - g_signal_connect(copy_menu, - "activate", - G_CALLBACK(OnCopyMenuActivatedThunk), - this); - gtk_widget_set_sensitive( - copy_menu, - params_.edit_flags & WebContextMenuData::CanCopy); - - GtkWidget* paste_menu = gtk_menu_item_new_with_label("Paste"); - gtk_menu_append(GTK_MENU(menu), paste_menu); - g_signal_connect(paste_menu, - "activate", - G_CALLBACK(OnPasteMenuActivatedThunk), - this); - gtk_widget_set_sensitive( - paste_menu, - params_.edit_flags & WebContextMenuData::CanPaste); - - GtkWidget* delete_menu = gtk_menu_item_new_with_label("Delete"); - gtk_menu_append(GTK_MENU(menu), delete_menu); - g_signal_connect(delete_menu, - "activate", - G_CALLBACK(OnDeleteMenuActivatedThunk), - this); - gtk_widget_set_sensitive( - delete_menu, - params_.edit_flags & WebContextMenuData::CanDelete); - - GtkWidget* edit_separator = gtk_separator_menu_item_new(); - gtk_menu_append(GTK_MENU(menu), edit_separator); - } else if (has_selection) { - GtkWidget* copy_menu = gtk_menu_item_new_with_label("Copy"); - gtk_menu_append(GTK_MENU(menu), copy_menu); - g_signal_connect(copy_menu, - "activate", - G_CALLBACK(OnCopyMenuActivatedThunk), - this); - - GtkWidget* copy_separator = gtk_separator_menu_item_new(); - gtk_menu_append(GTK_MENU(menu), copy_separator); - } - - GtkWidget* inspect_menu = gtk_menu_item_new_with_label("Inspect..."); - gtk_menu_append(GTK_MENU(menu), inspect_menu); - g_signal_connect(inspect_menu, - "activate", - G_CALLBACK(OnInspectMenuActivatedThunk), - this); - - gtk_widget_show_all(menu); - - gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, GDK_CURRENT_TIME); -} - -WebDragDestDelegate* ShellWebContentsViewDelegate::GetDragDestDelegate() { - return NULL; -} - -void ShellWebContentsViewDelegate::Initialize(GtkWidget* expanded_container, - ui::FocusStoreGtk* focus_store) { - expanded_container_ = expanded_container; - - gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_container_); - gtk_widget_show(floating_.get()); -} - -gfx::NativeView ShellWebContentsViewDelegate::GetNativeView() const { - return floating_.get(); -} - -void ShellWebContentsViewDelegate::Focus() { - GtkWidget* widget = web_contents_->GetView()->GetContentNativeView(); - if (widget) - gtk_widget_grab_focus(widget); -} - -gboolean ShellWebContentsViewDelegate::OnNativeViewFocusEvent( - GtkWidget* widget, - GtkDirectionType type, - gboolean* return_value) { - return false; -} - -void ShellWebContentsViewDelegate::OnBackMenuActivated(GtkWidget* widget) { - web_contents_->GetController().GoToOffset(-1); - web_contents_->GetView()->Focus(); -} - -void ShellWebContentsViewDelegate::OnForwardMenuActivated(GtkWidget* widget) { - web_contents_->GetController().GoToOffset(1); - web_contents_->GetView()->Focus(); -} - -void ShellWebContentsViewDelegate::OnReloadMenuActivated(GtkWidget* widget) { - web_contents_->GetController().Reload(false); - web_contents_->GetView()->Focus(); -} - -void ShellWebContentsViewDelegate::OnOpenURLMenuActivated(GtkWidget* widget) { - ShellBrowserContext* browser_context = - ShellContentBrowserClient::Get()->browser_context(); - Shell::CreateNewWindow(browser_context, - params_.link_url, - NULL, - MSG_ROUTING_NONE, - gfx::Size()); -} - -void ShellWebContentsViewDelegate::OnCutMenuActivated(GtkWidget* widget) { - web_contents_->Cut(); -} - -void ShellWebContentsViewDelegate::OnCopyMenuActivated(GtkWidget* widget) { - web_contents_->Copy(); -} - -void ShellWebContentsViewDelegate::OnPasteMenuActivated(GtkWidget* widget) { - web_contents_->Paste(); -} - -void ShellWebContentsViewDelegate::OnDeleteMenuActivated(GtkWidget* widget) { - web_contents_->Delete(); -} - -void ShellWebContentsViewDelegate::OnInspectMenuActivated(GtkWidget* widget) { - ShellDevToolsFrontend::Show(web_contents_); -} - -} // namespace content diff --git a/content/utility/utility_main.cc b/content/utility/utility_main.cc index a522427..a57ea9c 100644 --- a/content/utility/utility_main.cc +++ b/content/utility/utility_main.cc @@ -18,12 +18,6 @@ #include "sandbox/win/src/sandbox.h" #endif -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> - -#include "ui/gfx/gtk_util.h" -#endif - namespace content { // Mainline routine for running as the utility process. @@ -39,34 +33,6 @@ int UtilityMain(const MainFunctionParams& parameters) { LinuxSandbox::InitializeSandbox(); #endif -#if defined(OS_POSIX) - // The utility process is used to load plugins (see OnLoadPlugins() in - // utility_thread_impl.cc). Some plugins expect the browser to have loaded - // GLib/GTK. - // Due to bugs in GLib we need to initialize GLib/GTK before we start threads, - // see crbug.com/309093. - -#if defined(TOOLKIT_GTK) - bool is_sandboxed = false; - -#if defined(OS_LINUX) - // On Linux, we only initialize GLib/GTK if we're not sandboxed. - is_sandboxed = !parameters.command_line.HasSwitch(switches::kNoSandbox); -#endif - - if (!is_sandboxed) { - // g_thread_init() is deprecated since glib 2.31.0, please see release note: - // http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041.html -#if !(GLIB_CHECK_VERSION(2, 31, 0)) - if (!g_thread_get_initialized()) { - g_thread_init(NULL); - } -#endif - gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); - } -#endif -#endif - ChildProcess utility_process; utility_process.set_main_thread(new UtilityThreadImpl()); |