summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 09:16:44 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 09:16:44 +0000
commit16d51df40992e767f4df3cd8a0d50fcf15a20c4c (patch)
treee7d032e5ccf51e42dc95f89c403d1921d70d2b03 /chrome/common
parent88301f32ceb483810043b4d426d1a853d00f3035 (diff)
downloadchromium_src-16d51df40992e767f4df3cd8a0d50fcf15a20c4c.zip
chromium_src-16d51df40992e767f4df3cd8a0d50fcf15a20c4c.tar.gz
chromium_src-16d51df40992e767f4df3cd8a0d50fcf15a20c4c.tar.bz2
Next part of bad dependency removal (chrome/common -> chrome/browser)
This change introduces one more dependency on chrome/browser, but it seems simpler to move gtk_util first and then fix it. TEST=none BUG=none Review URL: http://codereview.chromium.org/661271 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/gtk_tree.cc294
-rw-r--r--chrome/common/gtk_tree.h165
-rw-r--r--chrome/common/gtk_util.cc874
-rw-r--r--chrome/common/gtk_util.h277
-rw-r--r--chrome/common/platform_util_linux.cc2
5 files changed, 1 insertions, 1611 deletions
diff --git a/chrome/common/gtk_tree.cc b/chrome/common/gtk_tree.cc
deleted file mode 100644
index a1ff19f..0000000
--- a/chrome/common/gtk_tree.cc
+++ /dev/null
@@ -1,294 +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 "chrome/common/gtk_tree.h"
-
-#include "app/gfx/gtk_util.h"
-#include "app/table_model.h"
-#include "base/logging.h"
-#include "base/string_util.h"
-#include "chrome/browser/gtk/gtk_theme_provider.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-
-namespace gtk_tree {
-
-gint GetRowNumForPath(GtkTreePath* path) {
- gint* indices = gtk_tree_path_get_indices(path);
- if (!indices) {
- NOTREACHED();
- return -1;
- }
- return indices[0];
-}
-
-gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter) {
- GtkTreePath* path = gtk_tree_model_get_path(model, iter);
- int row = GetRowNumForPath(path);
- gtk_tree_path_free(path);
- return row;
-}
-
-gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model,
- GtkTreePath* sort_path) {
- GtkTreePath *child_path = gtk_tree_model_sort_convert_path_to_child_path(
- GTK_TREE_MODEL_SORT(sort_model), sort_path);
- int row = GetRowNumForPath(child_path);
- gtk_tree_path_free(child_path);
- return row;
-}
-
-void SelectAndFocusRowNum(int row, GtkTreeView* tree_view) {
- GtkTreeModel* model = gtk_tree_view_get_model(tree_view);
- if (!model) {
- NOTREACHED();
- return;
- }
- GtkTreeIter iter;
- if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
- NOTREACHED();
- return;
- }
- GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
- gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
- gtk_tree_path_free(path);
-}
-
-bool RemoveRecursively(GtkTreeStore* tree_store, GtkTreeIter* iter) {
- GtkTreeIter child;
- if (gtk_tree_model_iter_children(GTK_TREE_MODEL(tree_store), &child, iter)) {
- while (true) {
- if (!RemoveRecursively(tree_store, &child))
- break;
- }
- }
- return gtk_tree_store_remove(tree_store, iter);
-}
-
-void GetSelectedIndicies(GtkTreeSelection* selection, std::set<int>* out) {
- GList* list = gtk_tree_selection_get_selected_rows(
- selection, NULL);
- GList* node;
- for (node = list; node != NULL; node = node->next) {
- out->insert(
- gtk_tree::GetRowNumForPath(static_cast<GtkTreePath*>(node->data)));
- }
- g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(list);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// TableAdapter
-
-TableAdapter::TableAdapter(Delegate* delegate, GtkListStore* list_store,
- TableModel* table_model)
- : delegate_(delegate), list_store_(list_store), table_model_(table_model) {
- if (table_model)
- table_model->SetObserver(this);
-}
-
-void TableAdapter::SetModel(TableModel* table_model) {
- table_model_ = table_model;
- table_model_->SetObserver(this);
-}
-
-void TableAdapter::AddNodeToList(int row) {
- GtkTreeIter iter;
- if (row == 0) {
- gtk_list_store_prepend(list_store_, &iter);
- } else {
- GtkTreeIter sibling;
- gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store_), &sibling, NULL,
- row - 1);
- gtk_list_store_insert_after(list_store_, &iter, &sibling);
- }
-
- delegate_->SetColumnValues(row, &iter);
-}
-
-void TableAdapter::OnModelChanged() {
- delegate_->OnAnyModelUpdateStart();
- gtk_list_store_clear(list_store_);
- delegate_->OnModelChanged();
- for (int i = 0; i < table_model_->RowCount(); ++i)
- AddNodeToList(i);
- delegate_->OnAnyModelUpdate();
-}
-
-void TableAdapter::OnItemsChanged(int start, int length) {
- delegate_->OnAnyModelUpdateStart();
- GtkTreeIter iter;
- bool rv = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store_), &iter,
- NULL, start);
- for (int i = 0; i < length; ++i) {
- if (!rv) {
- NOTREACHED();
- return;
- }
- delegate_->SetColumnValues(start + i, &iter);
- rv = gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store_), &iter);
- }
- delegate_->OnAnyModelUpdate();
-}
-
-void TableAdapter::OnItemsAdded(int start, int length) {
- delegate_->OnAnyModelUpdateStart();
- for (int i = 0; i < length; ++i) {
- AddNodeToList(start + i);
- }
- delegate_->OnAnyModelUpdate();
-}
-
-void TableAdapter::OnItemsRemoved(int start, int length) {
- delegate_->OnAnyModelUpdateStart();
- GtkTreeIter iter;
- bool rv = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store_), &iter,
- NULL, start);
- for (int i = 0; i < length; ++i) {
- if (!rv) {
- NOTREACHED();
- return;
- }
- rv = gtk_list_store_remove(list_store_, &iter);
- }
- delegate_->OnAnyModelUpdate();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// TreeAdapter
-
-TreeAdapter::TreeAdapter(Delegate* delegate, TreeModel* tree_model)
- : delegate_(delegate),
- tree_model_(tree_model) {
- tree_store_ = gtk_tree_store_new(COL_COUNT,
- GDK_TYPE_PIXBUF,
- G_TYPE_STRING,
- G_TYPE_POINTER);
- tree_model->AddObserver(this);
-
- std::vector<SkBitmap> icons;
- tree_model->GetIcons(&icons);
- for (size_t i = 0; i < icons.size(); ++i) {
- pixbufs_.push_back(gfx::GdkPixbufFromSkBitmap(&icons[i]));
- }
-}
-
-TreeAdapter::~TreeAdapter() {
- g_object_unref(tree_store_);
- for (size_t i = 0; i < pixbufs_.size(); ++i)
- g_object_unref(pixbufs_[i]);
-}
-
-void TreeAdapter::Init() {
- gtk_tree_store_clear(tree_store_);
- Fill(NULL, tree_model_->GetRoot());
-}
-
-
-TreeModelNode* TreeAdapter::GetNode(GtkTreeIter* iter) {
- TreeModelNode* node;
- gtk_tree_model_get(GTK_TREE_MODEL(tree_store_), iter,
- COL_NODE_PTR, &node,
- -1);
- return node;
-}
-
-void TreeAdapter::FillRow(GtkTreeIter* iter, TreeModelNode* node) {
- GdkPixbuf* pixbuf = NULL;
- int icon_index = tree_model_->GetIconIndex(node);
- if (icon_index >= 0 && icon_index < static_cast<int>(pixbufs_.size()))
- pixbuf = pixbufs_[icon_index];
- else
- pixbuf = GtkThemeProvider::GetFolderIcon(true);
- gtk_tree_store_set(tree_store_, iter,
- COL_ICON, pixbuf,
- COL_TITLE, WideToUTF8(node->GetTitle()).c_str(),
- COL_NODE_PTR, node,
- -1);
-}
-
-void TreeAdapter::Fill(GtkTreeIter* parent_iter, TreeModelNode* parent_node) {
- if (parent_iter)
- FillRow(parent_iter, parent_node);
- GtkTreeIter iter;
- int child_count = tree_model_->GetChildCount(parent_node);
- for (int i = 0; i < child_count; ++i) {
- TreeModelNode* node = tree_model_->GetChild(parent_node, i);
- gtk_tree_store_append(tree_store_, &iter, parent_iter);
- Fill(&iter, node);
- }
-}
-
-GtkTreePath* TreeAdapter::GetTreePath(TreeModelNode* node) {
- GtkTreePath* path = gtk_tree_path_new();
- TreeModelNode* parent = node;
- while (parent) {
- parent = tree_model_->GetParent(parent);
- if (parent) {
- int idx = tree_model_->IndexOfChild(parent, node);
- gtk_tree_path_prepend_index(path, idx);
- node = parent;
- }
- }
- return path;
-}
-
-bool TreeAdapter::GetTreeIter(TreeModelNode* node, GtkTreeIter* iter) {
- GtkTreePath* path = GetTreePath(node);
- bool rv = false;
- // Check the path ourselves since gtk_tree_model_get_iter prints a warning if
- // given an empty path. The path will be empty when it points to the root
- // node and we are using SetRootShown(false).
- if (gtk_tree_path_get_depth(path) > 0)
- rv = gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store_), iter, path);
- gtk_tree_path_free(path);
- return rv;
-}
-
-void TreeAdapter::TreeNodesAdded(TreeModel* model,
- TreeModelNode* parent,
- int start,
- int count) {
- delegate_->OnAnyModelUpdateStart();
- GtkTreeIter parent_iter;
- GtkTreeIter* parent_iter_ptr = NULL;
- GtkTreeIter iter;
- if (GetTreeIter(parent, &parent_iter))
- parent_iter_ptr = &parent_iter;
- for (int i = 0; i < count; ++i) {
- gtk_tree_store_insert(tree_store_, &iter, parent_iter_ptr, start + i);
- Fill(&iter, tree_model_->GetChild(parent, start + i));
- }
- delegate_->OnAnyModelUpdate();
-}
-
-void TreeAdapter::TreeNodesRemoved(TreeModel* model,
- TreeModelNode* parent,
- int start,
- int count) {
- delegate_->OnAnyModelUpdateStart();
- GtkTreeIter iter;
- GtkTreePath* path = GetTreePath(parent);
- gtk_tree_path_append_index(path, start);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store_), &iter, path);
- gtk_tree_path_free(path);
- for (int i = 0; i < count; ++i) {
- RemoveRecursively(tree_store_, &iter);
- }
- delegate_->OnAnyModelUpdate();
-}
-
-void TreeAdapter::TreeNodeChildrenReordered(TreeModel* model,
- TreeModelNode* parent) {
- NOTIMPLEMENTED();
-}
-
-void TreeAdapter::TreeNodeChanged(TreeModel* model, TreeModelNode* node) {
- delegate_->OnAnyModelUpdateStart();
- GtkTreeIter iter;
- if (GetTreeIter(node, &iter))
- FillRow(&iter, node);
- delegate_->OnAnyModelUpdate();
-}
-
-} // namespace gtk_tree
diff --git a/chrome/common/gtk_tree.h b/chrome/common/gtk_tree.h
deleted file mode 100644
index 4c2f38e..0000000
--- a/chrome/common/gtk_tree.h
+++ /dev/null
@@ -1,165 +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 CHROME_COMMON_GTK_TREE_H_
-#define CHROME_COMMON_GTK_TREE_H_
-
-#include <gtk/gtk.h>
-#include <set>
-#include <vector>
-
-#include "app/table_model_observer.h"
-#include "app/tree_model.h"
-#include "base/basictypes.h"
-
-class TableModel;
-
-namespace gtk_tree {
-
-// Get the row number corresponding to |path|.
-gint GetRowNumForPath(GtkTreePath* path);
-
-// Get the row number corresponding to |iter|.
-gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter);
-
-// Get the row number in the child tree model corresponding to |sort_path| in
-// the parent tree model.
-gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model,
- GtkTreePath* sort_path);
-
-// Select the given row by number.
-void SelectAndFocusRowNum(int row, GtkTreeView* tree_view);
-
-// Remove the row and all its children from the |tree_store|. If there is a
-// following row, |iter| will be updated to point to the it and the return value
-// will be true, otherwise the return will be false and |iter| is no longer
-// valid.
-bool RemoveRecursively(GtkTreeStore* tree_store, GtkTreeIter* iter);
-
-// Writes all the indexes of selected rows into |out|.
-void GetSelectedIndicies(GtkTreeSelection* selection, std::set<int>* out);
-
-// A helper class for populating a GtkListStore from a TableModel.
-class TableAdapter : public TableModelObserver {
- public:
- class Delegate {
- public:
- // Should fill in the column and row.
- virtual void SetColumnValues(int row, GtkTreeIter* iter) = 0;
-
- // Called after any change to the TableModel but before the corresponding
- // change to the GtkListStore.
- virtual void OnAnyModelUpdateStart() {}
-
- // Called after any change to the TableModel.
- virtual void OnAnyModelUpdate() {}
-
- // When the TableModel has been completely changed, called by OnModelChanged
- // after clearing the list store. Can be overriden by the delegate if it
- // needs to do extra initialization before the list store is populated.
- virtual void OnModelChanged() {}
-
- protected:
- virtual ~Delegate() {}
- };
-
- // |table_model| may be NULL.
- explicit TableAdapter(Delegate* delegate, GtkListStore* list_store,
- TableModel* table_model);
- virtual ~TableAdapter() {}
-
- // Replace the TableModel with a different one. If the list store currenty
- // has items this would cause weirdness, so this should generally only be
- // called during the Delegate's OnModelChanged call, or if the adapter was
- // created with a NULL |table_model|.
- void SetModel(TableModel* table_model);
-
- // TableModelObserver implementation.
- virtual void OnModelChanged();
- virtual void OnItemsChanged(int start, int length);
- virtual void OnItemsAdded(int start, int length);
- virtual void OnItemsRemoved(int start, int length);
-
- private:
- // Add the values from |row| of the TableModel.
- void AddNodeToList(int row);
-
- Delegate* delegate_;
- GtkListStore* list_store_;
- TableModel* table_model_;
-
- DISALLOW_COPY_AND_ASSIGN(TableAdapter);
-};
-
-// A helper class for populating a GtkTreeStore from a TreeModel.
-// TODO(mattm): support SetRootShown(true)
-// TODO(mattm): implement TreeNodeChildrenReordered
-class TreeAdapter : public TreeModelObserver {
- public:
- // Column ids for |tree_store_|.
- enum {
- COL_ICON,
- COL_TITLE,
- COL_NODE_PTR,
- COL_COUNT,
- };
-
- class Delegate {
- public:
- // Called after any change to the TreeModel but before the corresponding
- // change to the GtkTreeStore.
- virtual void OnAnyModelUpdateStart() {}
-
- // Called after any change to the GtkTreeStore.
- virtual void OnAnyModelUpdate() {}
- };
-
- TreeAdapter(Delegate* delegate, TreeModel* tree_model);
- virtual ~TreeAdapter();
-
- // Populate the tree store from the |tree_model_|.
- void Init();
-
- // Return the tree store.
- GtkTreeStore* tree_store() { return tree_store_; }
-
- // Get the TreeModelNode corresponding to iter in the tree store.
- TreeModelNode* GetNode(GtkTreeIter* iter);
-
- // TreeModelObserver implementation.
- virtual void TreeNodesAdded(TreeModel* model,
- TreeModelNode* parent,
- int start,
- int count);
- virtual void TreeNodesRemoved(TreeModel* model,
- TreeModelNode* parent,
- int start,
- int count);
- virtual void TreeNodeChildrenReordered(TreeModel* model,
- TreeModelNode* parent);
- virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node);
-
- private:
- // Fill the tree store values for a given node.
- void FillRow(GtkTreeIter* iter, TreeModelNode* node);
-
- // Fill the tree store for a row and all its descendants.
- void Fill(GtkTreeIter* parent_iter, TreeModelNode* parent_node);
-
- // Get the GtkTreePath in the tree store for the given node.
- // The returned path should be freed with gtk_tree_path_free.
- GtkTreePath* GetTreePath(TreeModelNode* node);
-
- // Get the GtkTreeIter in the tree store for the given node.
- bool GetTreeIter(TreeModelNode* node, GtkTreeIter* iter);
-
- Delegate* delegate_;
- GtkTreeStore* tree_store_;
- TreeModel* tree_model_;
- std::vector<GdkPixbuf*> pixbufs_;
-};
-
-} // namespace gtk_tree
-
-#endif // CHROME_COMMON_GTK_TREE_H_
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
deleted file mode 100644
index cdc637d..0000000
--- a/chrome/common/gtk_util.cc
+++ /dev/null
@@ -1,874 +0,0 @@
-// Copyright (c) 2010 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 "chrome/common/gtk_util.h"
-
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
-
-#include <cstdarg>
-#include <map>
-
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "base/linux_util.h"
-#include "base/logging.h"
-#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_window.h"
-#include "chrome/browser/gtk/cairo_cached_surface.h"
-#include "chrome/browser/gtk/gtk_theme_provider.h"
-#include "chrome/common/renderer_preferences.h"
-#include "chrome/common/x11_util.h"
-#include "grit/theme_resources.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/skia/include/core/SkColor.h"
-
-namespace {
-
-const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>";
-
-// Callback used in RemoveAllChildren.
-void RemoveWidget(GtkWidget* widget, gpointer container) {
- gtk_container_remove(GTK_CONTAINER(container), widget);
-}
-
-// These two functions are copped almost directly from gtk core. The only
-// difference is that they accept middle clicks.
-gboolean OnMouseButtonPressed(GtkWidget* widget, GdkEventButton* event,
- gpointer userdata) {
- if (event->type == GDK_BUTTON_PRESS) {
- if (gtk_button_get_focus_on_click(GTK_BUTTON(widget)) &&
- !GTK_WIDGET_HAS_FOCUS(widget)) {
- gtk_widget_grab_focus(widget);
- }
-
- gint button_mask = GPOINTER_TO_INT(userdata);
- if (button_mask && (1 << event->button))
- gtk_button_pressed(GTK_BUTTON(widget));
- }
-
- return TRUE;
-}
-
-gboolean OnMouseButtonReleased(GtkWidget* widget, GdkEventButton* event,
- gpointer userdata) {
- gint button_mask = GPOINTER_TO_INT(userdata);
- if (button_mask && (1 << event->button))
- gtk_button_released(GTK_BUTTON(widget));
-
- return TRUE;
-}
-
-// Ownership of |icon_list| is passed to the caller.
-GList* GetIconList() {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- GList* icon_list = NULL;
- icon_list = g_list_append(icon_list, rb.GetPixbufNamed(IDR_PRODUCT_ICON_32));
- icon_list = g_list_append(icon_list, rb.GetPixbufNamed(IDR_PRODUCT_LOGO_16));
- return icon_list;
-}
-
-// A process wide singleton that manages our usage of gdk
-// cursors. gdk_cursor_new() hits the disk in several places and GdkCursor
-// instances can be reused throughout the process.
-class GdkCursorCache {
- public:
- ~GdkCursorCache() {
- for (std::map<GdkCursorType, GdkCursor*>::iterator it =
- cursor_cache_.begin(); it != cursor_cache_.end(); ++it) {
- gdk_cursor_unref(it->second);
- }
- cursor_cache_.clear();
- }
-
- GdkCursor* GetCursorImpl(GdkCursorType type) {
- std::map<GdkCursorType, GdkCursor*>::iterator it = cursor_cache_.find(type);
- GdkCursor* cursor = NULL;
- if (it == cursor_cache_.end()) {
- cursor = gdk_cursor_new(type);
- cursor_cache_.insert(std::make_pair(type, cursor));
- } else {
- cursor = it->second;
- }
-
- // Add a reference to the returned cursor because our consumers mix us with
- // gdk_cursor_new(). Both the normal constructor and GetCursorImpls() need
- // to be paired with a gdk_cursor_unref() so ref it here (as we own the ref
- // that comes from gdk_cursor_new().
- gdk_cursor_ref(cursor);
-
- return cursor;
- }
-
- std::map<GdkCursorType, GdkCursor*> cursor_cache_;
-};
-
-// Expose event handler for a container that simply suppresses the default
-// drawing and propagates the expose event to the container's children.
-gboolean PaintNoBackground(GtkWidget* widget,
- GdkEventExpose* event,
- gpointer unused) {
- GList* children = gtk_container_get_children(GTK_CONTAINER(widget));
- for (GList* item = children; item; item = item->next) {
- gtk_container_propagate_expose(GTK_CONTAINER(widget),
- GTK_WIDGET(item->data),
- event);
- }
- g_list_free(children);
-
- return TRUE;
-}
-
-void OnLabelAllocate(GtkWidget* label, GtkAllocation* allocation,
- gpointer user_data) {
- gtk_widget_set_size_request(label, allocation->width, -1);
-}
-
-} // namespace
-
-namespace event_utils {
-
-WindowOpenDisposition DispositionFromEventFlags(guint event_flags) {
- if ((event_flags & GDK_BUTTON2_MASK) || (event_flags & GDK_CONTROL_MASK)) {
- return (event_flags & GDK_SHIFT_MASK) ?
- NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
- }
-
- if (event_flags & GDK_SHIFT_MASK)
- return NEW_WINDOW;
- return false /*event.IsAltDown()*/ ? SAVE_TO_DISK : CURRENT_TAB;
-}
-
-} // namespace event_utils
-
-namespace gtk_util {
-
-GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels,
- const char* text, ...) {
- va_list ap;
- va_start(ap, text);
- GtkWidget* table = gtk_table_new(0, 2, FALSE);
- gtk_table_set_col_spacing(GTK_TABLE(table), 0, kLabelSpacing);
- gtk_table_set_row_spacings(GTK_TABLE(table), kControlSpacing);
-
- for (guint row = 0; text; ++row) {
- gtk_table_resize(GTK_TABLE(table), row + 1, 2);
- GtkWidget* control = va_arg(ap, GtkWidget*);
- GtkWidget* label = gtk_label_new(text);
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- if (labels)
- labels->push_back(label);
-
- gtk_table_attach(GTK_TABLE(table), label,
- 0, 1, row, row + 1,
- GTK_FILL, GTK_FILL,
- 0, 0);
- gtk_table_attach_defaults(GTK_TABLE(table), control,
- 1, 2, row, row + 1);
- text = va_arg(ap, const char*);
- }
- va_end(ap);
-
- return table;
-}
-
-GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
- int top, int bottom, int left, int right) {
- // Use a GtkEventBox to get the background painted. However, we can't just
- // use a container border, since it won't paint there. Use an alignment
- // inside to get the sizes exactly of how we want the border painted.
- GtkWidget* ebox = gtk_event_box_new();
- if (color)
- gtk_widget_modify_bg(ebox, GTK_STATE_NORMAL, color);
- GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
- gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), top, bottom, left, right);
- gtk_container_add(GTK_CONTAINER(alignment), child);
- gtk_container_add(GTK_CONTAINER(ebox), alignment);
- return ebox;
-}
-
-GtkWidget* LeftAlignMisc(GtkWidget* misc) {
- gtk_misc_set_alignment(GTK_MISC(misc), 0, 0.5);
- return misc;
-}
-
-GtkWidget* CreateBoldLabel(const std::string& text) {
- GtkWidget* label = gtk_label_new(NULL);
- char* markup = g_markup_printf_escaped(kBoldLabelMarkup, text.c_str());
- gtk_label_set_markup(GTK_LABEL(label), markup);
- g_free(markup);
-
- return LeftAlignMisc(label);
-}
-
-void GetWidgetSizeFromResources(GtkWidget* widget, int width_chars,
- int height_lines, int* width, int* height) {
- DCHECK(GTK_WIDGET_REALIZED(widget))
- << " widget must be realized to compute font metrics correctly";
-
- double chars = 0;
- if (width)
- StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars);
-
- double lines = 0;
- if (height)
- StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines);
-
- GetWidgetSizeFromCharacters(widget, chars, lines, width, height);
-}
-
-void GetWidgetSizeFromCharacters(GtkWidget* widget, double width_chars,
- double height_lines, int* width, int* height) {
- DCHECK(GTK_WIDGET_REALIZED(widget))
- << " widget must be realized to compute font metrics correctly";
- PangoContext* context = gtk_widget_create_pango_context(widget);
- PangoFontMetrics* metrics = pango_context_get_metrics(context,
- widget->style->font_desc, pango_context_get_language(context));
- if (width) {
- *width = static_cast<int>(
- pango_font_metrics_get_approximate_char_width(metrics) *
- width_chars / PANGO_SCALE);
- }
- if (height) {
- *height = static_cast<int>(
- (pango_font_metrics_get_ascent(metrics) +
- pango_font_metrics_get_descent(metrics)) *
- height_lines / PANGO_SCALE);
- }
- pango_font_metrics_unref(metrics);
- g_object_unref(context);
-}
-
-void SetWindowSizeFromResources(GtkWindow* window,
- int width_id, int height_id, bool resizable) {
- int width = -1;
- int height = -1;
- gtk_util::GetWidgetSizeFromResources(GTK_WIDGET(window), width_id, height_id,
- (width_id != -1) ? &width : NULL,
- (height_id != -1) ? &height : NULL);
-
- if (resizable) {
- gtk_window_set_default_size(window, width, height);
- } else {
- // For a non-resizable window, GTK tries to snap the window size
- // to the minimum size around the content. We still want to set
- // the *minimum* window size to allow windows with long titles to
- // be wide enough to display their titles, but if GTK needs to
- // make the window *wider* due to very wide controls, we should
- // allow that too.
- GdkGeometry geometry;
- geometry.min_width = width;
- geometry.min_height = height;
- gtk_window_set_geometry_hints(window, GTK_WIDGET(window),
- &geometry, GDK_HINT_MIN_SIZE);
- }
- gtk_window_set_resizable(window, resizable ? TRUE : FALSE);
-}
-
-void CenterOverWindow(GtkWindow* window, GtkWindow* parent) {
- gfx::Rect frame_bounds = gtk_util::GetWidgetScreenBounds(GTK_WIDGET(parent));
- gfx::Point origin = frame_bounds.origin();
- gfx::Size size = gtk_util::GetWidgetSize(GTK_WIDGET(window));
- origin.Offset(
- (frame_bounds.width() - size.width()) / 2,
- (frame_bounds.height() - size.height()) / 2);
-
- // Prevent moving window out of monitor bounds.
- GdkScreen* screen = gtk_window_get_screen(parent);
- if (screen) {
- // It would be better to check against workarea for given monitor
- // but getting workarea for particular monitor is tricky.
- gint monitor = gdk_screen_get_monitor_at_window(screen,
- GTK_WIDGET(parent)->window);
- GdkRectangle rect;
- gdk_screen_get_monitor_geometry(screen, monitor, &rect);
-
- // Check the right bottom corner.
- if (origin.x() > rect.x + rect.width - size.width())
- origin.set_x(rect.x + rect.width - size.width());
- if (origin.y() > rect.y + rect.height - size.height())
- origin.set_y(rect.y + rect.height - size.height());
-
- // Check the left top corner.
- if (origin.x() < rect.x)
- origin.set_x(rect.x);
- if (origin.y() < rect.y)
- origin.set_y(rect.y);
- }
-
- gtk_window_move(window, origin.x(), origin.y());
-
- // Move to user expected desktop if window is already visible.
- if (GTK_WIDGET(window)->window) {
- x11_util::ChangeWindowDesktop(
- x11_util::GetX11WindowFromGtkWidget(GTK_WIDGET(window)),
- x11_util::GetX11WindowFromGtkWidget(GTK_WIDGET(parent)));
- }
-}
-
-void MakeAppModalWindowGroup() {
-#if GTK_CHECK_VERSION(2, 14, 0)
- // Older versions of GTK+ don't give us gtk_window_group_list() which is what
- // we need to add current non-browser modal dialogs to the list. If
- // we have 2.14+ we can do things the correct way.
- GtkWindowGroup* window_group = gtk_window_group_new();
- for (BrowserList::const_iterator it = BrowserList::begin();
- it != BrowserList::end(); ++it) {
- // List all windows in this current group
- GtkWindowGroup* old_group =
- gtk_window_get_group((*it)->window()->GetNativeHandle());
-
- GList* all_windows = gtk_window_group_list_windows(old_group);
- for (GList* window = all_windows; window; window = window->next) {
- gtk_window_group_add_window(window_group, GTK_WINDOW(window->data));
- }
- g_list_free(all_windows);
- }
- g_object_unref(window_group);
-#else
- // Otherwise just grab all browser windows and be slightly broken.
- GtkWindowGroup* window_group = gtk_window_group_new();
- for (BrowserList::const_iterator it = BrowserList::begin();
- it != BrowserList::end(); ++it) {
- gtk_window_group_add_window(window_group,
- (*it)->window()->GetNativeHandle());
- }
- g_object_unref(window_group);
-#endif
-}
-
-void AppModalDismissedUngroupWindows() {
-#if GTK_CHECK_VERSION(2, 14, 0)
- if (BrowserList::begin() != BrowserList::end()) {
- std::vector<GtkWindow*> transient_windows;
-
- // All windows should be part of one big modal group right now.
- GtkWindowGroup* window_group = gtk_window_get_group(
- (*BrowserList::begin())->window()->GetNativeHandle());
- GList* windows = gtk_window_group_list_windows(window_group);
-
- for (GList* item = windows; item; item = item->next) {
- GtkWindow* window = GTK_WINDOW(item->data);
- GtkWindow* transient_for = gtk_window_get_transient_for(window);
- if (transient_for) {
- transient_windows.push_back(window);
- } else {
- GtkWindowGroup* window_group = gtk_window_group_new();
- gtk_window_group_add_window(window_group, window);
- g_object_unref(window_group);
- }
- }
-
- // Put each transient window in the same group as its transient parent.
- for (std::vector<GtkWindow*>::iterator it = transient_windows.begin();
- it != transient_windows.end(); ++it) {
- GtkWindow* transient_parent = gtk_window_get_transient_for(*it);
- GtkWindowGroup* group = gtk_window_get_group(transient_parent);
- gtk_window_group_add_window(group, *it);
- }
- }
-#else
- // This is slightly broken in the case where a different window had a dialog,
- // but its the best we can do since we don't have newer gtk stuff.
- for (BrowserList::const_iterator it = BrowserList::begin();
- it != BrowserList::end(); ++it) {
- GtkWindowGroup* window_group = gtk_window_group_new();
- gtk_window_group_add_window(window_group,
- (*it)->window()->GetNativeHandle());
- g_object_unref(window_group);
- }
-#endif
-}
-
-void RemoveAllChildren(GtkWidget* container) {
- gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container);
-}
-
-void ForceFontSizePixels(GtkWidget* widget, double size_pixels) {
- GtkStyle* style = widget->style;
- PangoFontDescription* font_desc = style->font_desc;
- // pango_font_description_set_absolute_size sets the font size in device
- // units, which for us is pixels.
- pango_font_description_set_absolute_size(font_desc,
- PANGO_SCALE * size_pixels);
- gtk_widget_modify_font(widget, font_desc);
-}
-
-gfx::Point GetWidgetScreenPosition(GtkWidget* widget) {
- if (!widget->window) {
- NOTREACHED() << "Must only be called on realized widgets.";
- return gfx::Point(0, 0);
- }
-
- gint x, y;
- gdk_window_get_origin(widget->window, &x, &y);
-
- if (!GTK_IS_WINDOW(widget)) {
- x += widget->allocation.x;
- y += widget->allocation.y;
- }
-
- return gfx::Point(x, y);
-}
-
-gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) {
- gfx::Point position = GetWidgetScreenPosition(widget);
- return gfx::Rect(position.x(), position.y(),
- widget->allocation.width, widget->allocation.height);
-}
-
-gfx::Size GetWidgetSize(GtkWidget* widget) {
- GtkRequisition size;
- gtk_widget_size_request(widget, &size);
- return gfx::Size(size.width, size.height);
-}
-
-void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p) {
- DCHECK(widget);
- DCHECK(p);
-
- gfx::Point position = GetWidgetScreenPosition(widget);
- p->SetPoint(p->x() + position.x(), p->y() + position.y());
-}
-
-void InitRCStyles() {
- static const char kRCText[] =
- // Make our dialogs styled like the GNOME HIG.
- //
- // TODO(evanm): content-area-spacing was introduced in a later
- // version of GTK, so we need to set that manually on all dialogs.
- // Perhaps it would make sense to have a shared FixupDialog() function.
- "style \"gnome-dialog\" {\n"
- " xthickness = 12\n"
- " GtkDialog::action-area-border = 0\n"
- " GtkDialog::button-spacing = 6\n"
- " GtkDialog::content-area-spacing = 18\n"
- " GtkDialog::content-area-border = 12\n"
- "}\n"
- // Note we set it at the "application" priority, so users can override.
- "widget \"GtkDialog\" style : application \"gnome-dialog\"\n"
-
- // Make our about dialog special, so the image is flush with the edge.
- "style \"about-dialog\" {\n"
- " GtkDialog::action-area-border = 12\n"
- " GtkDialog::button-spacing = 6\n"
- " GtkDialog::content-area-spacing = 18\n"
- " GtkDialog::content-area-border = 0\n"
- "}\n"
- "widget \"about-dialog\" style : application \"about-dialog\"\n";
-
- gtk_rc_parse_string(kRCText);
-}
-
-void CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, bool pack_at_end,
- int padding) {
- GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(centering_vbox), widget, TRUE, FALSE, 0);
- if (pack_at_end)
- gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, padding);
- else
- gtk_box_pack_start(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, padding);
-}
-
-std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
- std::string ret;
- ret.reserve(label.length() * 2);
- for (size_t i = 0; i < label.length(); ++i) {
- if ('_' == label[i]) {
- ret.push_back('_');
- ret.push_back('_');
- } else if ('&' == label[i]) {
- if (i + 1 < label.length() && '&' == label[i + 1]) {
- ret.push_back(label[i]);
- ++i;
- } else {
- ret.push_back('_');
- }
- } else {
- ret.push_back(label[i]);
- }
- }
-
- return ret;
-}
-
-bool IsScreenComposited() {
- GdkScreen* screen = gdk_screen_get_default();
- return gdk_screen_is_composited(screen) == TRUE;
-}
-
-void EnumerateTopLevelWindows(x11_util::EnumerateWindowsDelegate* delegate) {
- std::vector<XID> stack;
- if (!x11_util::GetXWindowStack(&stack)) {
- // Window Manager doesn't support _NET_CLIENT_LIST_STACKING, so fall back
- // to old school enumeration of all X windows. Some WMs parent 'top-level'
- // windows in unnamed actual top-level windows (ion WM), so extend the
- // search depth to all children of top-level windows.
- const int kMaxSearchDepth = 1;
- x11_util::EnumerateAllWindows(delegate, kMaxSearchDepth);
- return;
- }
-
- std::vector<XID>::iterator iter;
- for (iter = stack.begin(); iter != stack.end(); iter++) {
- if (delegate->ShouldStopIterating(*iter))
- return;
- }
-}
-
-void SetButtonClickableByMouseButtons(GtkWidget* button,
- bool left, bool middle, bool right) {
- gint button_mask = 0;
- if (left)
- button_mask |= 1 << 1;
- if (middle)
- button_mask |= 1 << 2;
- if (right)
- button_mask |= 1 << 3;
- void* userdata = GINT_TO_POINTER(button_mask);
-
- g_signal_connect(button, "button-press-event",
- G_CALLBACK(OnMouseButtonPressed), userdata);
- g_signal_connect(button, "button-release-event",
- G_CALLBACK(OnMouseButtonReleased), userdata);
-}
-
-void SetButtonTriggersNavigation(GtkWidget* button) {
- SetButtonClickableByMouseButtons(button, true, true, false);
-}
-
-int MirroredLeftPointForRect(GtkWidget* widget, const gfx::Rect& bounds) {
- if (l10n_util::GetTextDirection() != l10n_util::RIGHT_TO_LEFT) {
- return bounds.x();
- }
- return widget->allocation.width - bounds.x() - bounds.width();
-}
-
-int MirroredXCoordinate(GtkWidget* widget, int x) {
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
- return widget->allocation.width - x;
- }
- return x;
-}
-
-bool WidgetContainsCursor(GtkWidget* widget) {
- gint x = 0;
- gint y = 0;
- gtk_widget_get_pointer(widget, &x, &y);
-
- // To quote the gtk docs:
- //
- // Widget coordinates are a bit odd; for historical reasons, they are
- // defined as widget->window coordinates for widgets that are not
- // GTK_NO_WINDOW widgets, and are relative to widget->allocation.x,
- // widget->allocation.y for widgets that are GTK_NO_WINDOW widgets.
- //
- // So the base is always (0,0).
- gfx::Rect widget_allocation(0, 0, widget->allocation.width,
- widget->allocation.height);
- return widget_allocation.Contains(x, y);
-}
-
-void SetWindowIcon(GtkWindow* window) {
- GList* icon_list = GetIconList();
- gtk_window_set_icon_list(window, icon_list);
- g_list_free(icon_list);
-}
-
-void SetDefaultWindowIcon() {
- GList* icon_list = GetIconList();
- gtk_window_set_default_icon_list(icon_list);
- g_list_free(icon_list);
-}
-
-GtkWidget* AddButtonToDialog(GtkWidget* dialog, const gchar* text,
- const gchar* stock_id, gint response_id) {
- GtkWidget* button = gtk_button_new_with_label(text);
- gtk_button_set_image(GTK_BUTTON(button),
- gtk_image_new_from_stock(stock_id,
- GTK_ICON_SIZE_BUTTON));
- gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button,
- response_id);
- return button;
-}
-
-void SetLabelColor(GtkWidget* label, const GdkColor* color) {
- gtk_widget_modify_fg(label, GTK_STATE_NORMAL, color);
- gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, color);
- gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, color);
- gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, color);
-}
-
-GtkWidget* IndentWidget(GtkWidget* content) {
- GtkWidget* content_alignment = gtk_alignment_new(0.0, 0.5, 1.0, 1.0);
- gtk_alignment_set_padding(GTK_ALIGNMENT(content_alignment), 0, 0,
- gtk_util::kGroupIndent, 0);
- gtk_container_add(GTK_CONTAINER(content_alignment), content);
- return content_alignment;
-}
-
-void UpdateGtkFontSettings(RendererPreferences* prefs) {
- DCHECK(prefs);
-
- // From http://library.gnome.org/devel/gtk/unstable/GtkSettings.html, this is
- // the default value for gtk-cursor-blink-time.
- static const gint kGtkDefaultCursorBlinkTime = 1200;
-
- gint cursor_blink_time = kGtkDefaultCursorBlinkTime;
- gboolean cursor_blink = TRUE;
- gint antialias = 0;
- gint hinting = 0;
- gchar* hint_style = NULL;
- gchar* rgba_style = NULL;
- g_object_get(gtk_settings_get_default(),
- "gtk-cursor-blink-time", &cursor_blink_time,
- "gtk-cursor-blink", &cursor_blink,
- "gtk-xft-antialias", &antialias,
- "gtk-xft-hinting", &hinting,
- "gtk-xft-hintstyle", &hint_style,
- "gtk-xft-rgba", &rgba_style,
- NULL);
-
- // Set some reasonable defaults.
- prefs->should_antialias_text = true;
- prefs->hinting = RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT;
- prefs->subpixel_rendering =
- RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT;
-
- if (cursor_blink) {
- // Dividing by 2*1000ms follows the WebKit GTK port and makes the blink
- // frequency appear similar to the omnibox. Without this the blink is too
- // slow.
- prefs->caret_blink_interval = cursor_blink_time / 2000.;
- } else {
- prefs->caret_blink_interval = 0;
- }
-
- // g_object_get() doesn't tell us whether the properties were present or not,
- // but if they aren't (because gnome-settings-daemon isn't running), we'll get
- // NULL values for the strings.
- if (hint_style && rgba_style) {
- prefs->should_antialias_text = antialias;
-
- if (hinting == 0 || strcmp(hint_style, "hintnone") == 0) {
- prefs->hinting = RENDERER_PREFERENCES_HINTING_NONE;
- } else if (strcmp(hint_style, "hintslight") == 0) {
- prefs->hinting = RENDERER_PREFERENCES_HINTING_SLIGHT;
- } else if (strcmp(hint_style, "hintmedium") == 0) {
- prefs->hinting = RENDERER_PREFERENCES_HINTING_MEDIUM;
- } else if (strcmp(hint_style, "hintfull") == 0) {
- prefs->hinting = RENDERER_PREFERENCES_HINTING_FULL;
- }
-
- if (strcmp(rgba_style, "none") == 0) {
- prefs->subpixel_rendering = RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE;
- } else if (strcmp(rgba_style, "rgb") == 0) {
- prefs->subpixel_rendering = RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB;
- } else if (strcmp(rgba_style, "bgr") == 0) {
- prefs->subpixel_rendering = RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR;
- } else if (strcmp(rgba_style, "vrgb") == 0) {
- prefs->subpixel_rendering = RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB;
- } else if (strcmp(rgba_style, "vbgr") == 0) {
- prefs->subpixel_rendering = RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR;
- }
- }
-
- if (hint_style)
- g_free(hint_style);
- if (rgba_style)
- g_free(rgba_style);
-}
-
-gfx::Point ScreenPoint(GtkWidget* widget) {
- int x, y;
- gdk_display_get_pointer(gtk_widget_get_display(widget), NULL, &x, &y,
- NULL);
- return gfx::Point(x, y);
-}
-
-gfx::Point ClientPoint(GtkWidget* widget) {
- int x, y;
- gtk_widget_get_pointer(widget, &x, &y);
- return gfx::Point(x, y);
-}
-
-GdkPoint MakeBidiGdkPoint(gint x, gint y, gint width, bool ltr) {
- GdkPoint point = {ltr ? x : width - x, y};
- return point;
-}
-
-void DrawTextEntryBackground(GtkWidget* offscreen_entry,
- GtkWidget* widget_to_draw_on,
- GdkRectangle* dirty_rec,
- GdkRectangle* rec) {
- GtkStyle* gtk_owned_style = gtk_rc_get_style(offscreen_entry);
- // GTK owns the above and we're going to have to make our own copy of it
- // that we can edit.
- GtkStyle* our_style = gtk_style_copy(gtk_owned_style);
- our_style = gtk_style_attach(our_style, widget_to_draw_on->window);
-
- // TODO(erg): Draw the focus ring if appropriate...
-
- // We're using GTK rendering; draw a GTK entry widget onto the background.
- gtk_paint_shadow(our_style, widget_to_draw_on->window,
- GTK_STATE_NORMAL, GTK_SHADOW_IN, dirty_rec,
- widget_to_draw_on, "entry",
- rec->x, rec->y, rec->width, rec->height);
-
- // Draw the interior background (not all themes draw the entry background
- // above; this is a noop on themes that do).
- gint xborder = our_style->xthickness;
- gint yborder = our_style->ythickness;
- gtk_paint_flat_box(our_style, widget_to_draw_on->window,
- GTK_STATE_NORMAL, GTK_SHADOW_NONE, dirty_rec,
- widget_to_draw_on, "entry_bg",
- rec->x + xborder, rec->y + yborder,
- rec->width - 2 * xborder,
- rec->height - 2 * yborder);
-
- g_object_unref(our_style);
-}
-
-void DrawThemedToolbarBackground(GtkWidget* widget,
- cairo_t* cr,
- GdkEventExpose* event,
- const gfx::Point& tabstrip_origin,
- GtkThemeProvider* theme_provider) {
- // Fill the entire region with the toolbar color.
- GdkColor color = theme_provider->GetGdkColor(
- BrowserThemeProvider::COLOR_TOOLBAR);
- gdk_cairo_set_source_color(cr, &color);
- cairo_fill(cr);
-
- // The toolbar is supposed to blend in with the active tab, so we have to pass
- // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the
- // tab strip.
- CairoCachedSurface* background = theme_provider->GetSurfaceNamed(
- IDR_THEME_TOOLBAR, widget);
- background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y());
- // We tile the toolbar background in both directions.
- cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
- cairo_rectangle(cr,
- tabstrip_origin.x(),
- tabstrip_origin.y(),
- event->area.x + event->area.width - tabstrip_origin.x(),
- event->area.y + event->area.height - tabstrip_origin.y());
- cairo_fill(cr);
-}
-
-GdkColor AverageColors(GdkColor color_one, GdkColor color_two) {
- GdkColor average_color;
- average_color.pixel = 0;
- average_color.red = (color_one.red + color_two.red) / 2;
- average_color.green = (color_one.green + color_two.green) / 2;
- average_color.blue = (color_one.blue + color_two.blue) / 2;
- return average_color;
-}
-
-void SetAlwaysShowImage(GtkWidget* image_menu_item) {
- // Compile time check: if it's available, just use the API.
- // GTK_CHECK_VERSION is TRUE if the passed version is compatible.
-#if GTK_CHECK_VERSION(2, 16, 1)
- gtk_image_menu_item_set_always_show_image(
- GTK_IMAGE_MENU_ITEM(image_menu_item), TRUE);
-#else
- // Run time check: if the API is not available, set the property manually.
- // This will still only work with GTK 2.16+ as the property doesn't exist
- // in earlier versions.
- // gtk_check_version() returns NULL if the passed version is compatible.
- if (!gtk_check_version(2, 16, 1)) {
- GValue true_value = { 0 };
- g_value_init(&true_value, G_TYPE_BOOLEAN);
- g_value_set_boolean(&true_value, TRUE);
- g_object_set_property(G_OBJECT(image_menu_item), "always-show-image",
- &true_value);
- }
-#endif
-}
-
-GdkCursor* GetCursor(GdkCursorType type) {
- static GdkCursorCache impl;
- return impl.GetCursorImpl(type);
-}
-
-void StackPopupWindow(GtkWidget* popup, GtkWidget* toplevel) {
- DCHECK(GTK_IS_WINDOW(popup) && GTK_WIDGET_TOPLEVEL(popup) &&
- GTK_WIDGET_REALIZED(popup));
- DCHECK(GTK_IS_WINDOW(toplevel) && GTK_WIDGET_TOPLEVEL(toplevel) &&
- GTK_WIDGET_REALIZED(toplevel));
-
- // Stack the |popup| window directly above the |toplevel| window.
- // The popup window is a direct child of the root window, so we need to
- // find a similar ancestor for the toplevel window (which might have been
- // reparented by a window manager). We grab the server while we're doing
- // this -- otherwise, we'll get an error if the window manager reparents the
- // toplevel window right after we call GetHighestAncestorWindow().
- gdk_x11_display_grab(gtk_widget_get_display(toplevel));
- XID toplevel_window_base = x11_util::GetHighestAncestorWindow(
- x11_util::GetX11WindowFromGtkWidget(toplevel),
- x11_util::GetX11RootWindow());
- if (toplevel_window_base) {
- XID window_xid = x11_util::GetX11WindowFromGtkWidget(popup);
- XID window_parent = x11_util::GetParentWindow(window_xid);
- if (window_parent == x11_util::GetX11RootWindow()) {
- x11_util::RestackWindow(window_xid, toplevel_window_base, true);
- } else {
- // The window manager shouldn't reparent override-redirect windows.
- DLOG(ERROR) << "override-redirect window " << window_xid
- << "'s parent is " << window_parent
- << ", rather than root window "
- << x11_util::GetX11RootWindow();
- }
- }
- gdk_x11_display_ungrab(gtk_widget_get_display(toplevel));
-}
-
-gfx::Rect GetWidgetRectRelativeToToplevel(GtkWidget* widget) {
- DCHECK(GTK_WIDGET_REALIZED(widget));
-
- GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
- DCHECK(toplevel);
- DCHECK(GTK_WIDGET_REALIZED(toplevel));
-
- gint x = 0, y = 0;
- gtk_widget_translate_coordinates(widget,
- toplevel,
- 0, 0,
- &x, &y);
- return gfx::Rect(x, y, widget->allocation.width, widget->allocation.height);
-}
-
-void ApplyMessageDialogQuirks(GtkWidget* dialog) {
- if (gtk_window_get_modal(GTK_WINDOW(dialog))) {
- // Work around a KDE 3 window manager bug.
- scoped_ptr<base::EnvironmentVariableGetter> env(
- base::EnvironmentVariableGetter::Create());
- if (base::DESKTOP_ENVIRONMENT_KDE3 == GetDesktopEnvironment(env.get()))
- gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
- }
-}
-
-void SuppressDefaultPainting(GtkWidget* container) {
- g_signal_connect(container, "expose-event",
- G_CALLBACK(PaintNoBackground), NULL);
-}
-
-void WrapLabelAtAllocationHack(GtkWidget* label) {
- g_signal_connect(label, "size-allocate",
- G_CALLBACK(OnLabelAllocate), NULL);
-}
-
-WindowOpenDisposition DispositionForCurrentButtonPressEvent() {
- GdkEvent* event = gtk_get_current_event();
- if (!event) {
- NOTREACHED();
- return NEW_FOREGROUND_TAB;
- }
-
- guint state = event->button.state;
- gdk_event_free(event);
- return event_utils::DispositionFromEventFlags(state);
-}
-
-} // namespace gtk_util
diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h
deleted file mode 100644
index 40cab80..0000000
--- a/chrome/common/gtk_util.h
+++ /dev/null
@@ -1,277 +0,0 @@
-// Copyright (c) 2010 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 CHROME_COMMON_GTK_UTIL_H_
-#define CHROME_COMMON_GTK_UTIL_H_
-
-#include <gtk/gtk.h>
-#include <string>
-#include <vector>
-
-#include "base/gfx/point.h"
-#include "base/gfx/rect.h"
-#include "chrome/common/x11_util.h"
-#include "webkit/glue/window_open_disposition.h"
-
-typedef struct _GtkWidget GtkWidget;
-
-class GtkThemeProvider;
-struct RendererPreferences; // from common/renderer_preferences.h
-
-namespace event_utils {
-
-// Translates event flags into what kind of disposition they represent.
-// For example, a middle click would mean to open a background tab.
-// event_flags are the state in the GdkEvent structure.
-WindowOpenDisposition DispositionFromEventFlags(guint state);
-
-} // namespace event_utils
-
-namespace gtk_util {
-
-// Constants relating to the layout of dialog windows:
-// (See http://library.gnome.org/devel/hig-book/stable/design-window.html.en)
-
-// Spacing between controls of the same group.
-const int kControlSpacing = 6;
-
-// Horizontal spacing between a label and its control.
-const int kLabelSpacing = 12;
-
-// Indent of the controls within each group.
-const int kGroupIndent = 12;
-
-// Space around the outside of a dialog's contents.
-const int kContentAreaBorder = 12;
-
-// Spacing between groups of controls.
-const int kContentAreaSpacing = 18;
-
-// Horizontal Spacing between controls in a form.
-const int kFormControlSpacing = 10;
-
-// Create a table of labeled controls, using proper spacing and alignment.
-// Arguments should be pairs of const char*, GtkWidget*, concluding with a
-// NULL. The first argument is a vector in which to place all labels
-// produced. It can be NULL if you don't need to keep track of the label
-// widgets. The second argument is a color to force the label text to. It can
-// be NULL to get the system default.
-//
-// For example:
-// controls = CreateLabeledControlsGroup(NULL,
-// "Name:", title_entry_,
-// "Folder:", folder_combobox_,
-// NULL);
-GtkWidget* CreateLabeledControlsGroup(
- std::vector<GtkWidget*>* labels,
- const char* text, ...);
-
-// Create a GtkBin with |child| as its child widget. This bin will paint a
-// border of color |color| with the sizes specified in pixels.
-GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
- int top, int bottom, int left, int right);
-
-// Left-align the given GtkMisc and return the same pointer.
-GtkWidget* LeftAlignMisc(GtkWidget* misc);
-
-// Create a left-aligned label with the given text in bold.
-GtkWidget* CreateBoldLabel(const std::string& text);
-
-// Calculates the size of given widget based on the size specified in
-// number of characters/lines (in locale specific resource file) and
-// font metrics.
-// NOTE: Make sure to realize |widget| before using this method, or a
-// default font size will be used instead of the actual font size.
-void GetWidgetSizeFromResources(GtkWidget* widget, int width_chars,
- int height_lines, int* width, int* height);
-
-// As above, but uses number of characters/lines directly rather than looking
-// up a resource.
-void GetWidgetSizeFromCharacters(GtkWidget* widget, double width_chars,
- double height_lines, int* width, int* height);
-
-// As above, but a convenience method for configuring dialog size.
-// |width_id| and |height_id| are resource IDs for the size. If either of these
-// are set to -1, the respective size will be set to the widget default.
-// |resizable| also controls whether the dialog will be resizable
-// (this info is also necessary for getting the width-setting code
-// right).
-void SetWindowSizeFromResources(GtkWindow* window,
- int width_id, int height_id, bool resizable);
-
-// Places |window| approximately over center of |parent|, it also moves window
-// to parent's desktop. Use this only for non-modal dialogs, such as the
-// options window and content settings window; otherwise you should be using
-// transient_for.
-void CenterOverWindow(GtkWindow* window, GtkWindow* parent);
-
-// Puts all browser windows in one window group; this will make any dialog
-// spawned app modal.
-void MakeAppModalWindowGroup();
-
-// Called after an app modal dialog that used MakeAppModalWindowGroup() was
-// dismissed. Returns each browser window to its own window group.
-void AppModalDismissedUngroupWindows();
-
-// Remove all children from this container.
-void RemoveAllChildren(GtkWidget* container);
-
-// Force the font size of the widget to |size_pixels|.
-void ForceFontSizePixels(GtkWidget* widget, double size_pixels);
-
-// Gets the position of a gtk widget in screen coordinates.
-gfx::Point GetWidgetScreenPosition(GtkWidget* widget);
-
-// Returns the bounds of the specified widget in screen coordinates.
-gfx::Rect GetWidgetScreenBounds(GtkWidget* widget);
-
-// Retuns size of the |widget| without window manager decorations.
-gfx::Size GetWidgetSize(GtkWidget* widget);
-
-// Converts a point in a widget to screen coordinates. The point |p| is
-// relative to the widget's top-left origin.
-void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p);
-
-// Initialize some GTK settings so that our dialogs are consistent.
-void InitRCStyles();
-
-// Stick the widget in the given hbox without expanding vertically. The widget
-// is packed at the start of the hbox. This is useful for widgets that would
-// otherwise expand to fill the vertical space of the hbox (e.g. buttons).
-void CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, bool pack_at_end,
- int padding);
-
-// Change windows accelerator style to GTK style. (GTK uses _ for
-// accelerators. Windows uses & with && as an escape for &.)
-std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label);
-
-// Returns true if the screen is composited, false otherwise.
-bool IsScreenComposited();
-
-// Enumerates the top-level gdk windows of the current display.
-void EnumerateTopLevelWindows(x11_util::EnumerateWindowsDelegate* delegate);
-
-// Set that clicking the button with the given mouse buttons will cause a click
-// event.
-// NOTE: If you need to connect to the button-press-event or
-// button-release-event signals, do so before calling this function.
-void SetButtonClickableByMouseButtons(GtkWidget* button,
- bool left, bool middle, bool right);
-
-// Set that a button causes a page navigation. In particular, it will accept
-// middle clicks. Warning: only call this *after* you have connected your
-// own handlers for button-press and button-release events, or you will not get
-// those events.
-void SetButtonTriggersNavigation(GtkWidget* button);
-
-// Returns the mirrored x value for |bounds| if the layout is RTL; otherwise,
-// the original value is returned unchanged.
-int MirroredLeftPointForRect(GtkWidget* widget, const gfx::Rect& bounds);
-
-// Returns the mirrored x value for the point |x| if the layout is RTL;
-// otherwise, the original value is returned unchanged.
-int MirroredXCoordinate(GtkWidget* widget, int x);
-
-// Returns true if the pointer is currently inside the widget.
-bool WidgetContainsCursor(GtkWidget* widget);
-
-// Sets the icon of |window| to the product icon (potentially used in window
-// border or alt-tab list).
-void SetWindowIcon(GtkWindow* window);
-
-// Sets the default window icon for windows created in this app.
-void SetDefaultWindowIcon();
-
-// Adds an action button with the given text to the dialog. Only useful when you
-// want a stock icon but not the stock text to go with it. Returns the button.
-GtkWidget* AddButtonToDialog(GtkWidget* dialog, const gchar* text,
- const gchar* stock_id, gint response_id);
-
-// Sets all the foreground color states of |label| to |color|.
-void SetLabelColor(GtkWidget* label, const GdkColor* color);
-
-// Adds the given widget to an alignment identing it by |kGroupIndent|.
-GtkWidget* IndentWidget(GtkWidget* content);
-
-// Sets (or resets) the font settings in |prefs| (used when creating new
-// renderers) based on GtkSettings (which itself comes from XSETTINGS).
-void UpdateGtkFontSettings(RendererPreferences* prefs);
-
-// Get the current location of the mouse cursor relative to the screen.
-gfx::Point ScreenPoint(GtkWidget* widget);
-
-// Get the current location of the mouse cursor relative to the widget.
-gfx::Point ClientPoint(GtkWidget* widget);
-
-// Reverses a point in RTL mode. Used in making vectors of GdkPoints for window
-// shapes.
-GdkPoint MakeBidiGdkPoint(gint x, gint y, gint width, bool ltr);
-
-// Draws a GTK text entry with the style parameters of GtkEntry
-// |offscreen_entry| onto |widget_to_draw_on| in the rectangle |rec|. Drawing
-// is only done in the clip rectangle |dirty_rec|.
-void DrawTextEntryBackground(GtkWidget* offscreen_entry,
- GtkWidget* widget_to_draw_on,
- GdkRectangle* dirty_rec,
- GdkRectangle* rec);
-
-// Draws the background of the toolbar area subject to the expose rectangle
-// |event| and starting image tiling from |tabstrip_origin|.
-void DrawThemedToolbarBackground(GtkWidget* widget,
- cairo_t* cr,
- GdkEventExpose* event,
- const gfx::Point& tabstrip_origin,
- GtkThemeProvider* provider);
-
-// Returns the two colors averaged together.
-GdkColor AverageColors(GdkColor color_one, GdkColor color_two);
-
-// Show the image for the given menu item, even if the user's default is to not
-// show images. Only to be used for favicons or other menus where the image is
-// crucial to its functionality.
-void SetAlwaysShowImage(GtkWidget* image_menu_item);
-
-// Returns a static instance of a GdkCursor* object, sharable across the
-// process. Returns a GdkCursor with a +1 refcount, as if it was just created
-// with gdk_cursor_new(); owner must gdk_cursor_unref() it when done with it.
-GdkCursor* GetCursor(GdkCursorType type);
-
-// Stacks a |popup| window directly on top of a |toplevel| window.
-void StackPopupWindow(GtkWidget* popup, GtkWidget* toplevel);
-
-// Get a rectangle corresponding to a widget's allocation relative to its
-// toplevel window's origin.
-gfx::Rect GetWidgetRectRelativeToToplevel(GtkWidget* widget);
-
-// A helper function for gtk_message_dialog_new() to work around a KDE 3 window
-// manager bugs. You should always call it after creating a dialog with
-// gtk_message_dialog_new.
-void ApplyMessageDialogQuirks(GtkWidget* dialog);
-
-// Don't allow the widget to paint anything, and instead propagate the expose
-// to its children. This is similar to calling
-//
-// gtk_widget_set_app_paintable(container, TRUE);
-//
-// except that it will always work, and it should be called after any custom
-// expose events are connected.
-void SuppressDefaultPainting(GtkWidget* container);
-
-// Set the label to use a request size equal to the allocation size. This
-// causes the label to wrap at the width of the container it is in, instead of
-// at the default width.
-// This is called a hack because the gtk docs state that it is logically
-// inconsistent for a widget to make its size request depend on its allocation.
-// It does, however, have the intended effect of wrapping the label at the
-// proper width.
-void WrapLabelAtAllocationHack(GtkWidget* label);
-
-// Get the window open disposition from the state in gtk_get_current_event().
-// This is designed to be called inside a "clicked" event handler. It is an
-// error to call it when gtk_get_current_event() won't return a GdkEventButton*.
-WindowOpenDisposition DispositionForCurrentButtonPressEvent();
-
-} // namespace gtk_util
-
-#endif // CHROME_COMMON_GTK_UTIL_H_
diff --git a/chrome/common/platform_util_linux.cc b/chrome/common/platform_util_linux.cc
index 816fca7..34cc70f 100644
--- a/chrome/common/platform_util_linux.cc
+++ b/chrome/common/platform_util_linux.cc
@@ -9,7 +9,7 @@
#include "base/file_util.h"
#include "base/process_util.h"
#include "base/string_util.h"
-#include "chrome/common/gtk_util.h"
+#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/common/process_watcher.h"
#include "googleurl/src/gurl.h"