From 16d51df40992e767f4df3cd8a0d50fcf15a20c4c Mon Sep 17 00:00:00 2001 From: "phajdan.jr@chromium.org" Date: Tue, 2 Mar 2010 09:16:44 +0000 Subject: 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 --- chrome/browser/app_modal_dialog_gtk.cc | 2 +- .../autocomplete/autocomplete_edit_view_gtk.cc | 2 +- .../autocomplete/autocomplete_popup_view_gtk.cc | 2 +- chrome/browser/autofill/autofill_dialog_gtk.cc | 2 +- .../browser/automation/automation_provider_gtk.cc | 2 +- chrome/browser/automation/ui_controls_linux.cc | 2 +- chrome/browser/browser_main.cc | 2 +- chrome/browser/cookie_modal_dialog_gtk.cc | 2 +- chrome/browser/dock_info_gtk.cc | 2 +- chrome/browser/gtk/about_chrome_dialog.cc | 2 +- chrome/browser/gtk/back_forward_button_gtk.cc | 2 +- chrome/browser/gtk/bookmark_bar_gtk.cc | 2 +- .../browser/gtk/bookmark_bar_instructions_gtk.cc | 2 +- chrome/browser/gtk/bookmark_bubble_gtk.cc | 2 +- chrome/browser/gtk/bookmark_editor_gtk.cc | 8 +- chrome/browser/gtk/bookmark_manager_gtk.cc | 2 +- chrome/browser/gtk/bookmark_manager_gtk.h | 2 +- chrome/browser/gtk/bookmark_menu_controller_gtk.cc | 2 +- chrome/browser/gtk/bookmark_utils_gtk.cc | 2 +- chrome/browser/gtk/browser_actions_toolbar_gtk.cc | 2 +- chrome/browser/gtk/browser_titlebar.cc | 2 +- chrome/browser/gtk/browser_toolbar_gtk.cc | 2 +- chrome/browser/gtk/browser_window_gtk.cc | 4 +- chrome/browser/gtk/certificate_manager.cc | 2 +- chrome/browser/gtk/certificate_viewer.cc | 2 +- .../browser/gtk/clear_browsing_data_dialog_gtk.cc | 2 +- chrome/browser/gtk/constrained_window_gtk.cc | 2 +- chrome/browser/gtk/content_blocked_bubble_gtk.cc | 4 +- .../gtk/create_application_shortcuts_dialog_gtk.cc | 2 +- chrome/browser/gtk/custom_button.cc | 2 +- .../browser/gtk/download_in_progress_dialog_gtk.cc | 2 +- chrome/browser/gtk/download_item_gtk.cc | 2 +- chrome/browser/gtk/download_shelf_gtk.cc | 2 +- chrome/browser/gtk/edit_search_engine_dialog.cc | 2 +- chrome/browser/gtk/extension_install_prompt_gtk.cc | 4 +- .../browser/gtk/extension_installed_bubble_gtk.cc | 2 +- chrome/browser/gtk/external_protocol_dialog_gtk.cc | 2 +- chrome/browser/gtk/find_bar_gtk.cc | 4 +- chrome/browser/gtk/first_run_bubble.cc | 2 +- chrome/browser/gtk/first_run_dialog.cc | 2 +- chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc | 2 +- chrome/browser/gtk/go_button_gtk.cc | 2 +- chrome/browser/gtk/gtk_chrome_link_button.cc | 2 +- chrome/browser/gtk/gtk_tree.cc | 294 +++++++ chrome/browser/gtk/gtk_tree.h | 165 ++++ chrome/browser/gtk/gtk_util.cc | 874 +++++++++++++++++++++ chrome/browser/gtk/gtk_util.h | 277 +++++++ chrome/browser/gtk/html_dialog_gtk.cc | 2 +- chrome/browser/gtk/hung_renderer_dialog_gtk.cc | 2 +- chrome/browser/gtk/import_dialog_gtk.cc | 2 +- chrome/browser/gtk/import_lock_dialog_gtk.cc | 4 +- chrome/browser/gtk/import_progress_dialog_gtk.cc | 2 +- chrome/browser/gtk/info_bubble_gtk.cc | 2 +- chrome/browser/gtk/infobar_container_gtk.cc | 2 +- chrome/browser/gtk/infobar_gtk.cc | 2 +- chrome/browser/gtk/keyword_editor_view.cc | 6 +- chrome/browser/gtk/keyword_editor_view_unittest.cc | 2 +- chrome/browser/gtk/location_bar_view_gtk.cc | 2 +- chrome/browser/gtk/menu_bar_helper.cc | 2 +- chrome/browser/gtk/menu_gtk.cc | 2 +- .../browser/gtk/notifications/balloon_view_gtk.cc | 4 +- .../browser/gtk/options/advanced_contents_gtk.cc | 2 +- chrome/browser/gtk/options/advanced_page_gtk.cc | 4 +- .../gtk/options/content_exception_editor.cc | 2 +- .../gtk/options/content_exceptions_window_gtk.cc | 2 +- .../gtk/options/content_exceptions_window_gtk.h | 2 +- .../browser/gtk/options/content_filter_page_gtk.cc | 2 +- chrome/browser/gtk/options/content_page_gtk.cc | 2 +- .../gtk/options/content_settings_window_gtk.cc | 2 +- .../browser/gtk/options/cookie_filter_page_gtk.cc | 2 +- chrome/browser/gtk/options/cookies_view.cc | 2 +- chrome/browser/gtk/options/cookies_view.h | 2 +- .../gtk/options/fonts_languages_window_gtk.cc | 2 +- chrome/browser/gtk/options/fonts_page_gtk.cc | 4 +- chrome/browser/gtk/options/general_page_gtk.cc | 2 +- chrome/browser/gtk/options/languages_page_gtk.cc | 2 +- chrome/browser/gtk/options/languages_page_gtk.h | 2 +- chrome/browser/gtk/options/options_layout_gtk.cc | 2 +- chrome/browser/gtk/options/options_window_gtk.cc | 2 +- .../gtk/options/passwords_exceptions_page_gtk.cc | 4 +- .../gtk/options/passwords_exceptions_window_gtk.cc | 2 +- chrome/browser/gtk/options/passwords_page_gtk.cc | 4 +- .../browser/gtk/options/url_picker_dialog_gtk.cc | 4 +- chrome/browser/gtk/options/url_picker_dialog_gtk.h | 2 +- chrome/browser/gtk/page_info_window_gtk.cc | 4 +- chrome/browser/gtk/process_singleton_dialog.cc | 2 +- chrome/browser/gtk/repost_form_warning_gtk.cc | 2 +- chrome/browser/gtk/rounded_window.cc | 2 +- chrome/browser/gtk/status_bubble_gtk.cc | 2 +- chrome/browser/gtk/tab_contents_drag_source.cc | 2 +- .../browser/gtk/tabs/dragged_tab_controller_gtk.cc | 4 +- chrome/browser/gtk/tabs/dragged_tab_gtk.cc | 4 +- chrome/browser/gtk/tabs/tab_renderer_gtk.cc | 2 +- chrome/browser/gtk/tabs/tab_strip_gtk.cc | 4 +- chrome/browser/gtk/task_manager_gtk.cc | 4 +- .../browser/gtk/theme_install_bubble_view_gtk.cc | 2 +- chrome/browser/gtk/toolbar_star_toggle_gtk.cc | 2 +- chrome/browser/jankometer.cc | 2 +- chrome/browser/js_modal_dialog_gtk.cc | 2 +- chrome/browser/login_prompt_gtk.cc | 2 +- .../renderer_host/gtk_im_context_wrapper.cc | 6 +- .../renderer_host/render_view_host_delegate.cc | 2 +- .../renderer_host/render_widget_host_view_gtk.cc | 2 +- chrome/browser/renderer_preferences_util.cc | 2 +- .../browser/tab_contents/tab_contents_view_gtk.cc | 2 +- chrome/browser/tab_contents/web_drag_dest_gtk.cc | 2 +- .../views/autocomplete/autocomplete_popup_gtk.cc | 8 +- chrome/chrome_browser.gypi | 8 + chrome/chrome_common.gypi | 4 - chrome/common/gtk_tree.cc | 294 ------- chrome/common/gtk_tree.h | 165 ---- chrome/common/gtk_util.cc | 874 --------------------- chrome/common/gtk_util.h | 277 ------- chrome/common/platform_util_linux.cc | 2 +- 114 files changed, 1748 insertions(+), 1744 deletions(-) create mode 100644 chrome/browser/gtk/gtk_tree.cc create mode 100644 chrome/browser/gtk/gtk_tree.h create mode 100644 chrome/browser/gtk/gtk_util.cc create mode 100644 chrome/browser/gtk/gtk_util.h delete mode 100644 chrome/common/gtk_tree.cc delete mode 100644 chrome/common/gtk_tree.h delete mode 100644 chrome/common/gtk_util.cc delete mode 100644 chrome/common/gtk_util.h (limited to 'chrome') diff --git a/chrome/browser/app_modal_dialog_gtk.cc b/chrome/browser/app_modal_dialog_gtk.cc index 2cdcf00..b0268e6 100644 --- a/chrome/browser/app_modal_dialog_gtk.cc +++ b/chrome/browser/app_modal_dialog_gtk.cc @@ -12,9 +12,9 @@ #include "base/string_util.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" -#include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 9b0b902..a805539 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -23,10 +23,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/defaults.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/toolbar_model.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index 13c62d2..773a809 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -22,10 +22,10 @@ #include "chrome/browser/autocomplete/autocomplete_popup_model.h" #include "chrome/browser/bubble_positioner.h" #include "chrome/browser/defaults.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/autofill/autofill_dialog_gtk.cc b/chrome/browser/autofill/autofill_dialog_gtk.cc index a94513a..25d33d9 100644 --- a/chrome/browser/autofill/autofill_dialog_gtk.cc +++ b/chrome/browser/autofill/autofill_dialog_gtk.cc @@ -15,8 +15,8 @@ #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/autofill/credit_card.h" #include "chrome/browser/autofill/form_group.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" -#include "chrome/common/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/automation/automation_provider_gtk.cc b/chrome/browser/automation/automation_provider_gtk.cc index cc7050c..eaed3b5 100644 --- a/chrome/browser/automation/automation_provider_gtk.cc +++ b/chrome/browser/automation/automation_provider_gtk.cc @@ -10,8 +10,8 @@ #include "base/gfx/rect.h" #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/gtk/browser_window_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/view_id_util.h" -#include "chrome/common/gtk_util.h" #include "chrome/test/automation/automation_messages.h" void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc index f0e04a1..ae4c072 100644 --- a/chrome/browser/automation/ui_controls_linux.cc +++ b/chrome/browser/automation/ui_controls_linux.cc @@ -11,7 +11,7 @@ #include "base/keyboard_code_conversion_gtk.h" #include "base/logging.h" #include "base/message_loop.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/test/automation/automation_constants.h" #if defined(TOOLKIT_VIEWS) diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 5814816..8c218b0 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -82,7 +82,7 @@ #endif #if defined(OS_POSIX) && !defined(OS_MACOSX) -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #endif // TODO(port): several win-only methods have been pulled out of this, but diff --git a/chrome/browser/cookie_modal_dialog_gtk.cc b/chrome/browser/cookie_modal_dialog_gtk.cc index db04888..3fcf37b 100644 --- a/chrome/browser/cookie_modal_dialog_gtk.cc +++ b/chrome/browser/cookie_modal_dialog_gtk.cc @@ -7,9 +7,9 @@ #include "app/l10n_util.h" #include "base/logging.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/views/cookie_prompt_view.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/dock_info_gtk.cc b/chrome/browser/dock_info_gtk.cc index 6923e25..b831119 100644 --- a/chrome/browser/dock_info_gtk.cc +++ b/chrome/browser/dock_info_gtk.cc @@ -12,7 +12,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/gtk/browser_window_gtk.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" //////////////////////////////////////////////////////////////////////////////// // BaseWindowFinder diff --git a/chrome/browser/gtk/about_chrome_dialog.cc b/chrome/browser/gtk/about_chrome_dialog.cc index c17f084..587d1f8 100644 --- a/chrome/browser/gtk/about_chrome_dialog.cc +++ b/chrome/browser/gtk/about_chrome_dialog.cc @@ -14,9 +14,9 @@ #include "chrome/browser/gtk/cairo_cached_surface.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/platform_util.h" #include "chrome/common/url_constants.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/back_forward_button_gtk.cc b/chrome/browser/gtk/back_forward_button_gtk.cc index fb16d9f..abd71f8 100644 --- a/chrome/browser/gtk/back_forward_button_gtk.cc +++ b/chrome/browser/gtk/back_forward_button_gtk.cc @@ -13,9 +13,9 @@ #include "chrome/browser/back_forward_menu_model.h" #include "chrome/browser/browser.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 65cc871..280de08 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -25,6 +25,7 @@ #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/import_dialog_gtk.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/gtk/rounded_window.h" @@ -39,7 +40,6 @@ #include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "grit/app_resources.h" diff --git a/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc b/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc index 271dd59..d5ca8d1 100644 --- a/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc @@ -11,7 +11,7 @@ #include "base/observer_list.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc index e49b6b2..355d314 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.cc +++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc @@ -17,10 +17,10 @@ #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/info_bubble_gtk.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc index b976579..f73ed6a 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk.cc +++ b/chrome/browser/gtk/bookmark_editor_gtk.cc @@ -11,15 +11,15 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/string_util.h" +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/gtk/bookmark_tree_model.h" #include "chrome/browser/gtk/bookmark_utils_gtk.h" #include "chrome/browser/gtk/gtk_theme_provider.h" -#include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/bookmarks/bookmark_utils.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/history/history.h" -#include "chrome/browser/profile.h" #include "chrome/browser/net/url_fixer_upper.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/profile.h" #include "googleurl/src/gurl.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index 8eb2104..b856ace 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -21,13 +21,13 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/gtk/bookmark_tree_model.h" #include "chrome/browser/gtk/bookmark_utils_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/sync/sync_ui_util.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h index 2b45bc4..2c664b3 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.h +++ b/chrome/browser/gtk/bookmark_manager_gtk.h @@ -14,9 +14,9 @@ #include "base/task.h" #include "chrome/browser/bookmarks/bookmark_context_menu_controller.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" +#include "chrome/browser/gtk/gtk_tree.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/shell_dialogs.h" -#include "chrome/common/gtk_tree.h" #include "testing/gtest/include/gtest/gtest_prod.h" class BookmarkModel; diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc index 06bf2ef..a5f6066 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc @@ -15,10 +15,10 @@ #include "chrome/browser/gtk/bookmark_utils_gtk.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/page_navigator.h" -#include "chrome/common/gtk_util.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc index 05aef12..c7d5770 100644 --- a/chrome/browser/gtk/bookmark_utils_gtk.cc +++ b/chrome/browser/gtk/bookmark_utils_gtk.cc @@ -15,8 +15,8 @@ #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" namespace { diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc index 365a8b0..6ff99cf 100644 --- a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc @@ -16,12 +16,12 @@ #include "chrome/browser/gtk/extension_popup_gtk.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_action.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index d51341c..8e47ad4 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -23,6 +23,7 @@ #include "chrome/browser/gtk/browser_window_gtk.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/gtk/nine_box.h" #include "chrome/browser/gtk/standard_menus.h" @@ -31,7 +32,6 @@ #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "grit/app_resources.h" diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 05d10e1..9df751f 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -31,6 +31,7 @@ #include "chrome/browser/gtk/go_button_gtk.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/location_bar_view_gtk.h" #include "chrome/browser/gtk/standard_menus.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" @@ -41,7 +42,6 @@ #include "chrome/browser/profile.h" #include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 258dcc6..8fdd70f 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -51,9 +51,10 @@ #include "chrome/browser/gtk/edit_search_engine_dialog.h" #include "chrome/browser/gtk/find_bar_gtk.h" #include "chrome/browser/gtk/fullscreen_exit_bubble_gtk.h" -#include "chrome/browser/gtk/gtk_floating_container.h" #include "chrome/browser/gtk/go_button_gtk.h" +#include "chrome/browser/gtk/gtk_floating_container.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/html_dialog_gtk.h" #include "chrome/browser/gtk/import_dialog_gtk.h" #include "chrome/browser/gtk/info_bubble_gtk.h" @@ -78,7 +79,6 @@ #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/window_sizer.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "grit/app_resources.h" diff --git a/chrome/browser/gtk/certificate_manager.cc b/chrome/browser/gtk/certificate_manager.cc index c842c1c..5ce7440 100644 --- a/chrome/browser/gtk/certificate_manager.cc +++ b/chrome/browser/gtk/certificate_manager.cc @@ -10,7 +10,7 @@ #include "app/l10n_util.h" #include "chrome/browser/gtk/certificate_viewer.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "grit/generated_resources.h" namespace { diff --git a/chrome/browser/gtk/certificate_viewer.cc b/chrome/browser/gtk/certificate_viewer.cc index 836921a..a4cc92b 100644 --- a/chrome/browser/gtk/certificate_viewer.cc +++ b/chrome/browser/gtk/certificate_viewer.cc @@ -18,7 +18,7 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/browser/cert_store.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h" #include "chrome/third_party/mozilla_security_manager/nsNSSCertificate.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc b/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc index 183f641..44ccb21 100644 --- a/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc +++ b/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc @@ -13,9 +13,9 @@ #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" #include "chrome/browser/gtk/browser_window_gtk.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/constrained_window_gtk.cc b/chrome/browser/gtk/constrained_window_gtk.cc index c6380d6..cd562b1 100644 --- a/chrome/browser/gtk/constrained_window_gtk.cc +++ b/chrome/browser/gtk/constrained_window_gtk.cc @@ -4,9 +4,9 @@ #include "chrome/browser/gtk/constrained_window_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" -#include "chrome/common/gtk_util.h" ConstrainedWindowGtk::ConstrainedWindowGtk( TabContents* owner, ConstrainedWindowGtkDelegate* delegate) diff --git a/chrome/browser/gtk/content_blocked_bubble_gtk.cc b/chrome/browser/gtk/content_blocked_bubble_gtk.cc index 1817ed6..3bc1873 100644 --- a/chrome/browser/gtk/content_blocked_bubble_gtk.cc +++ b/chrome/browser/gtk/content_blocked_bubble_gtk.cc @@ -8,15 +8,15 @@ #include "app/l10n_util.h" #include "chrome/browser/blocked_popup_container.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" +#include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/content_settings_window_gtk.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/content_settings.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" -#include "chrome/browser/gtk/gtk_theme_provider.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc index 096a23f..b1ea27c 100644 --- a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc +++ b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc @@ -6,8 +6,8 @@ #include "app/l10n_util.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/shell_integration.h" -#include "chrome/common/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc index ea2607d..5a591d3 100644 --- a/chrome/browser/gtk/custom_button.cc +++ b/chrome/browser/gtk/custom_button.cc @@ -13,7 +13,7 @@ #include "chrome/browser/gtk/cairo_cached_surface.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/gtk/download_in_progress_dialog_gtk.cc b/chrome/browser/gtk/download_in_progress_dialog_gtk.cc index 41c6413..3c81df1 100644 --- a/chrome/browser/gtk/download_in_progress_dialog_gtk.cc +++ b/chrome/browser/gtk/download_in_progress_dialog_gtk.cc @@ -11,8 +11,8 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 3f4f32c..d1eb597 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -26,10 +26,10 @@ #include "chrome/browser/gtk/download_item_drag.h" #include "chrome/browser/gtk/download_shelf_gtk.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/gtk/nine_box.h" #include "chrome/browser/gtk/standard_menus.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc index 0aa3c23..19ea3c8d 100644 --- a/chrome/browser/gtk/download_shelf_gtk.cc +++ b/chrome/browser/gtk/download_shelf_gtk.cc @@ -15,8 +15,8 @@ #include "chrome/browser/gtk/download_item_gtk.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/gtk/edit_search_engine_dialog.cc b/chrome/browser/gtk/edit_search_engine_dialog.cc index 6830b63..735f071 100644 --- a/chrome/browser/gtk/edit_search_engine_dialog.cc +++ b/chrome/browser/gtk/edit_search_engine_dialog.cc @@ -11,12 +11,12 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/edit_search_engine_controller.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/common/gtk_util.h" #include "googleurl/src/gurl.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/extension_install_prompt_gtk.cc b/chrome/browser/gtk/extension_install_prompt_gtk.cc index 26a8b90..ef93811 100644 --- a/chrome/browser/gtk/extension_install_prompt_gtk.cc +++ b/chrome/browser/gtk/extension_install_prompt_gtk.cc @@ -10,9 +10,9 @@ #include "base/string_util.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" -#include "chrome/browser/gtk/browser_window_gtk.h" #include "chrome/browser/extensions/extension_install_ui.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/browser_window_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/common/extensions/extension.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/extension_installed_bubble_gtk.cc b/chrome/browser/gtk/extension_installed_bubble_gtk.cc index e0becb4..784c45a 100644 --- a/chrome/browser/gtk/extension_installed_bubble_gtk.cc +++ b/chrome/browser/gtk/extension_installed_bubble_gtk.cc @@ -13,9 +13,9 @@ #include "chrome/browser/gtk/browser_toolbar_gtk.h" #include "chrome/browser/gtk/browser_window_gtk.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/location_bar_view_gtk.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/external_protocol_dialog_gtk.cc b/chrome/browser/gtk/external_protocol_dialog_gtk.cc index 3111b3a..153ffa9 100644 --- a/chrome/browser/gtk/external_protocol_dialog_gtk.cc +++ b/chrome/browser/gtk/external_protocol_dialog_gtk.cc @@ -10,10 +10,10 @@ #include "base/histogram.h" #include "base/message_loop.h" #include "chrome/browser/external_protocol_handler.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tab_contents/tab_util.h" -#include "chrome/common/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index 8cd5606..300c6db 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -11,21 +11,21 @@ #include "app/resource_bundle.h" #include "base/string_util.h" #include "chrome/browser/browser.h" -#include "chrome/browser/profile.h" #include "chrome/browser/find_bar_controller.h" #include "chrome/browser/gtk/browser_window_gtk.h" #include "chrome/browser/gtk/cairo_cached_surface.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_floating_container.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/nine_box.h" #include "chrome/browser/gtk/slide_animator_gtk.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/gtk/view_id_util.h" +#include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/gtk/first_run_bubble.cc b/chrome/browser/gtk/first_run_bubble.cc index 86d7d88..9e3a918 100644 --- a/chrome/browser/gtk/first_run_bubble.cc +++ b/chrome/browser/gtk/first_run_bubble.cc @@ -9,9 +9,9 @@ #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/options_window.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/first_run_dialog.cc b/chrome/browser/gtk/first_run_dialog.cc index d8c1375..ae3481d 100644 --- a/chrome/browser/gtk/first_run_dialog.cc +++ b/chrome/browser/gtk/first_run_dialog.cc @@ -8,9 +8,9 @@ #include "app/resource_bundle.h" #include "base/message_loop.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/process_singleton.h" #include "chrome/browser/shell_integration.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/platform_util.h" #include "chrome/installer/util/google_update_settings.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc b/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc index 4dcab57..4594fa4 100644 --- a/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc +++ b/chrome/browser/gtk/fullscreen_exit_bubble_gtk.cc @@ -8,8 +8,8 @@ #include "app/l10n_util.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_floating_container.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/rounded_window.h" -#include "chrome/common/gtk_util.h" #include "grit/app_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/go_button_gtk.cc b/chrome/browser/gtk/go_button_gtk.cc index 0bfb416..eba8f82 100644 --- a/chrome/browser/gtk/go_button_gtk.cc +++ b/chrome/browser/gtk/go_button_gtk.cc @@ -11,10 +11,10 @@ #include "chrome/browser/browser.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/location_bar_view_gtk.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/gtk/gtk_chrome_link_button.cc b/chrome/browser/gtk/gtk_chrome_link_button.cc index f62aa71..a3b08ef 100644 --- a/chrome/browser/gtk/gtk_chrome_link_button.cc +++ b/chrome/browser/gtk/gtk_chrome_link_button.cc @@ -7,7 +7,7 @@ #include #include "base/logging.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" static const gchar* kLinkMarkup = "%s"; diff --git a/chrome/browser/gtk/gtk_tree.cc b/chrome/browser/gtk/gtk_tree.cc new file mode 100644 index 0000000..b638027 --- /dev/null +++ b/chrome/browser/gtk/gtk_tree.cc @@ -0,0 +1,294 @@ +// 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/browser/gtk/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* 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(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 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(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/browser/gtk/gtk_tree.h b/chrome/browser/gtk/gtk_tree.h new file mode 100644 index 0000000..744d83e --- /dev/null +++ b/chrome/browser/gtk/gtk_tree.h @@ -0,0 +1,165 @@ +// 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_BROWSER_GTK_GTK_TREE_H_ +#define CHROME_BROWSER_GTK_GTK_TREE_H_ + +#include +#include +#include + +#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* 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 pixbufs_; +}; + +} // namespace gtk_tree + +#endif // CHROME_BROWSER_GTK_GTK_TREE_H_ diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc new file mode 100644 index 0000000..465202b --- /dev/null +++ b/chrome/browser/gtk/gtk_util.cc @@ -0,0 +1,874 @@ +// 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/browser/gtk/gtk_util.h" + +#include +#include + +#include +#include + +#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[] = "%s"; + +// 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::iterator it = + cursor_cache_.begin(); it != cursor_cache_.end(); ++it) { + gdk_cursor_unref(it->second); + } + cursor_cache_.clear(); + } + + GdkCursor* GetCursorImpl(GdkCursorType type) { + std::map::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 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* 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( + pango_font_metrics_get_approximate_char_width(metrics) * + width_chars / PANGO_SCALE); + } + if (height) { + *height = static_cast( + (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 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::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 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::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 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/browser/gtk/gtk_util.h b/chrome/browser/gtk/gtk_util.h new file mode 100644 index 0000000..a51470f --- /dev/null +++ b/chrome/browser/gtk/gtk_util.h @@ -0,0 +1,277 @@ +// 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_BROWSER_GTK_GTK_UTIL_H_ +#define CHROME_BROWSER_GTK_GTK_UTIL_H_ + +#include +#include +#include + +#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* 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_BROWSER_GTK_GTK_UTIL_H_ diff --git a/chrome/browser/gtk/html_dialog_gtk.cc b/chrome/browser/gtk/html_dialog_gtk.cc index a303a07..dd4c3db 100644 --- a/chrome/browser/gtk/html_dialog_gtk.cc +++ b/chrome/browser/gtk/html_dialog_gtk.cc @@ -9,9 +9,9 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/dom_ui/html_dialog_ui.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "ipc/ipc_message.h" // static diff --git a/chrome/browser/gtk/hung_renderer_dialog_gtk.cc b/chrome/browser/gtk/hung_renderer_dialog_gtk.cc index faf5116..a0480cf 100644 --- a/chrome/browser/gtk/hung_renderer_dialog_gtk.cc +++ b/chrome/browser/gtk/hung_renderer_dialog_gtk.cc @@ -11,10 +11,10 @@ #include "app/resource_bundle.h" #include "base/process_util.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/result_codes.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/import_dialog_gtk.cc b/chrome/browser/gtk/import_dialog_gtk.cc index fb3d92d..8aadc09 100644 --- a/chrome/browser/gtk/import_dialog_gtk.cc +++ b/chrome/browser/gtk/import_dialog_gtk.cc @@ -9,7 +9,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/import_lock_dialog_gtk.cc b/chrome/browser/gtk/import_lock_dialog_gtk.cc index 748dab3..dac4123 100644 --- a/chrome/browser/gtk/import_lock_dialog_gtk.cc +++ b/chrome/browser/gtk/import_lock_dialog_gtk.cc @@ -7,10 +7,10 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/message_loop.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/importer/importer.h" -#include "chrome/common/gtk_util.h" -#include "grit/generated_resources.h" #include "grit/chromium_strings.h" +#include "grit/generated_resources.h" // static void ImportLockDialogGtk::Show(GtkWindow* parent, ImporterHost* importer_host) { diff --git a/chrome/browser/gtk/import_progress_dialog_gtk.cc b/chrome/browser/gtk/import_progress_dialog_gtk.cc index beb897c..3d1f48e 100644 --- a/chrome/browser/gtk/import_progress_dialog_gtk.cc +++ b/chrome/browser/gtk/import_progress_dialog_gtk.cc @@ -6,7 +6,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/info_bubble_gtk.cc b/chrome/browser/gtk/info_bubble_gtk.cc index fdac85a..87c9ff6 100644 --- a/chrome/browser/gtk/info_bubble_gtk.cc +++ b/chrome/browser/gtk/info_bubble_gtk.cc @@ -14,7 +14,7 @@ #include "base/gfx/rect.h" #include "base/logging.h" #include "chrome/browser/gtk/gtk_theme_provider.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/common/notification_service.h" namespace { diff --git a/chrome/browser/gtk/infobar_container_gtk.cc b/chrome/browser/gtk/infobar_container_gtk.cc index 07d7618..88cf033 100644 --- a/chrome/browser/gtk/infobar_container_gtk.cc +++ b/chrome/browser/gtk/infobar_container_gtk.cc @@ -8,10 +8,10 @@ #include "chrome/browser/browser_window.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/infobar_gtk.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" namespace { diff --git a/chrome/browser/gtk/infobar_gtk.cc b/chrome/browser/gtk/infobar_gtk.cc index 859984f..0a86908 100644 --- a/chrome/browser/gtk/infobar_gtk.cc +++ b/chrome/browser/gtk/infobar_gtk.cc @@ -11,9 +11,9 @@ #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/infobar_container_gtk.h" #include "chrome/browser/tab_contents/infobar_delegate.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" namespace { diff --git a/chrome/browser/gtk/keyword_editor_view.cc b/chrome/browser/gtk/keyword_editor_view.cc index f88409b..1ebefb9 100644 --- a/chrome/browser/gtk/keyword_editor_view.cc +++ b/chrome/browser/gtk/keyword_editor_view.cc @@ -11,14 +11,14 @@ #include "base/message_loop.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" #include "chrome/browser/gtk/edit_search_engine_dialog.h" -#include "chrome/browser/profile.h" +#include "chrome/browser/gtk/gtk_tree.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/metrics/user_metrics.h" +#include "chrome/browser/profile.h" #include "chrome/browser/search_engines/keyword_editor_controller.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/search_engines/template_url_table_model.h" -#include "chrome/common/gtk_tree.h" -#include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/keyword_editor_view_unittest.cc b/chrome/browser/gtk/keyword_editor_view_unittest.cc index aa15362..8f2cd93 100644 --- a/chrome/browser/gtk/keyword_editor_view_unittest.cc +++ b/chrome/browser/gtk/keyword_editor_view_unittest.cc @@ -10,10 +10,10 @@ #include #include "base/string_util.h" +#include "chrome/browser/gtk/gtk_tree.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/search_engines/template_url_table_model.h" -#include "chrome/common/gtk_tree.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index e6efa7c..b622115 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -30,6 +30,7 @@ #include "chrome/browser/gtk/extension_popup_gtk.h" #include "chrome/browser/gtk/first_run_bubble.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/rounded_window.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" @@ -37,7 +38,6 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_action.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/gtk/menu_bar_helper.cc b/chrome/browser/gtk/menu_bar_helper.cc index 7940f39..54fa555 100644 --- a/chrome/browser/gtk/menu_bar_helper.cc +++ b/chrome/browser/gtk/menu_bar_helper.cc @@ -7,7 +7,7 @@ #include #include "base/logging.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" namespace { diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 7d1f0ef..11d82de 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -12,8 +12,8 @@ #include "base/message_loop.h" #include "base/stl_util-inl.h" #include "base/string_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/standard_menus.h" -#include "chrome/common/gtk_util.h" #include "third_party/skia/include/core/SkBitmap.h" using gtk_util::ConvertAcceleratorsFromWindowsStyle; diff --git a/chrome/browser/gtk/notifications/balloon_view_gtk.cc b/chrome/browser/gtk/notifications/balloon_view_gtk.cc index 9cb4038..8ab3555 100644 --- a/chrome/browser/gtk/notifications/balloon_view_gtk.cc +++ b/chrome/browser/gtk/notifications/balloon_view_gtk.cc @@ -15,13 +15,14 @@ #include "app/slide_animation.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/info_bubble_gtk.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/gtk/nine_box.h" @@ -33,7 +34,6 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" diff --git a/chrome/browser/gtk/options/advanced_contents_gtk.cc b/chrome/browser/gtk/options/advanced_contents_gtk.cc index 35d3856..bed7964 100644 --- a/chrome/browser/gtk/options/advanced_contents_gtk.cc +++ b/chrome/browser/gtk/options/advanced_contents_gtk.cc @@ -21,6 +21,7 @@ #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" #include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/content_settings_window_gtk.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" #include "chrome/browser/net/dns_global.h" @@ -31,7 +32,6 @@ #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/process_watcher.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/options/advanced_page_gtk.cc b/chrome/browser/gtk/options/advanced_page_gtk.cc index 9bc8040..4c9d437 100644 --- a/chrome/browser/gtk/options/advanced_page_gtk.cc +++ b/chrome/browser/gtk/options/advanced_page_gtk.cc @@ -5,10 +5,10 @@ #include "chrome/browser/gtk/options/advanced_page_gtk.h" #include "app/l10n_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/options_util.h" -#include "chrome/common/gtk_util.h" -#include "grit/generated_resources.h" #include "grit/chromium_strings.h" +#include "grit/generated_resources.h" AdvancedPageGtk::AdvancedPageGtk(Profile* profile) : OptionsPageBase(profile), diff --git a/chrome/browser/gtk/options/content_exception_editor.cc b/chrome/browser/gtk/options/content_exception_editor.cc index c4ae975..9547f49 100644 --- a/chrome/browser/gtk/options/content_exception_editor.cc +++ b/chrome/browser/gtk/options/content_exception_editor.cc @@ -8,8 +8,8 @@ #include "app/resource_bundle.h" #include "base/message_loop.h" #include "chrome/browser/content_exceptions_table_model.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/host_content_settings_map.h" -#include "chrome/common/gtk_util.h" #include "googleurl/src/url_canon.h" #include "googleurl/src/url_parse.h" #include "grit/app_resources.h" diff --git a/chrome/browser/gtk/options/content_exceptions_window_gtk.cc b/chrome/browser/gtk/options/content_exceptions_window_gtk.cc index 3ded33d..869ab20 100644 --- a/chrome/browser/gtk/options/content_exceptions_window_gtk.cc +++ b/chrome/browser/gtk/options/content_exceptions_window_gtk.cc @@ -7,8 +7,8 @@ #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" #include "base/message_loop.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/content_exception_editor.h" -#include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/options/content_exceptions_window_gtk.h b/chrome/browser/gtk/options/content_exceptions_window_gtk.h index c6073c3..59f0e75 100644 --- a/chrome/browser/gtk/options/content_exceptions_window_gtk.h +++ b/chrome/browser/gtk/options/content_exceptions_window_gtk.h @@ -11,10 +11,10 @@ #include "base/scoped_ptr.h" #include "chrome/browser/content_exceptions_table_model.h" +#include "chrome/browser/gtk/gtk_tree.h" #include "chrome/browser/gtk/options/content_exception_editor.h" #include "chrome/common/content_settings.h" #include "chrome/common/content_settings_types.h" -#include "chrome/common/gtk_tree.h" class HostContentSettingsMap; diff --git a/chrome/browser/gtk/options/content_filter_page_gtk.cc b/chrome/browser/gtk/options/content_filter_page_gtk.cc index b575325..f591356 100644 --- a/chrome/browser/gtk/options/content_filter_page_gtk.cc +++ b/chrome/browser/gtk/options/content_filter_page_gtk.cc @@ -5,11 +5,11 @@ #include "chrome/browser/gtk/options/content_filter_page_gtk.h" #include "app/l10n_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/profile.h" #include "chrome/browser/gtk/options/content_exceptions_window_gtk.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/options/content_page_gtk.cc b/chrome/browser/gtk/options/content_page_gtk.cc index edbb9fc..d7ce179 100644 --- a/chrome/browser/gtk/options/content_page_gtk.cc +++ b/chrome/browser/gtk/options/content_page_gtk.cc @@ -15,12 +15,12 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/import_dialog_gtk.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" #include "chrome/browser/gtk/options/passwords_exceptions_window_gtk.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/sync/sync_ui_util.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" diff --git a/chrome/browser/gtk/options/content_settings_window_gtk.cc b/chrome/browser/gtk/options/content_settings_window_gtk.cc index 8334a9f..9f1cfa3 100644 --- a/chrome/browser/gtk/options/content_settings_window_gtk.cc +++ b/chrome/browser/gtk/options/content_settings_window_gtk.cc @@ -12,10 +12,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" #include "chrome/browser/gtk/browser_window_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/common/content_settings_types.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/options/cookie_filter_page_gtk.cc b/chrome/browser/gtk/options/cookie_filter_page_gtk.cc index 07de705..db925d7 100644 --- a/chrome/browser/gtk/options/cookie_filter_page_gtk.cc +++ b/chrome/browser/gtk/options/cookie_filter_page_gtk.cc @@ -9,12 +9,12 @@ #include "chrome/browser/browsing_data_local_storage_helper.h" #include "chrome/browser/gtk/browser_window_gtk.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/content_exceptions_window_gtk.h" #include "chrome/browser/gtk/options/cookies_view.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/options/cookies_view.cc b/chrome/browser/gtk/options/cookies_view.cc index a5735f7..c045326 100644 --- a/chrome/browser/gtk/options/cookies_view.cc +++ b/chrome/browser/gtk/options/cookies_view.cc @@ -14,7 +14,7 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/cookies_tree_model.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "grit/generated_resources.h" namespace { diff --git a/chrome/browser/gtk/options/cookies_view.h b/chrome/browser/gtk/options/cookies_view.h index 6aedbf6..4686a50 100644 --- a/chrome/browser/gtk/options/cookies_view.h +++ b/chrome/browser/gtk/options/cookies_view.h @@ -15,7 +15,7 @@ #include "chrome/browser/browsing_data_appcache_helper.h" #include "chrome/browser/browsing_data_database_helper.h" #include "chrome/browser/browsing_data_local_storage_helper.h" -#include "chrome/common/gtk_tree.h" +#include "chrome/browser/gtk/gtk_tree.h" #include "net/base/cookie_monster.h" #include "testing/gtest/include/gtest/gtest_prod.h" diff --git a/chrome/browser/gtk/options/fonts_languages_window_gtk.cc b/chrome/browser/gtk/options/fonts_languages_window_gtk.cc index 5898b4a..8e4253e 100644 --- a/chrome/browser/gtk/options/fonts_languages_window_gtk.cc +++ b/chrome/browser/gtk/options/fonts_languages_window_gtk.cc @@ -8,10 +8,10 @@ #include "app/l10n_util.h" #include "base/message_loop.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/gtk/options/fonts_page_gtk.h" #include "chrome/browser/gtk/options/languages_page_gtk.h" -#include "chrome/common/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/options/fonts_page_gtk.cc b/chrome/browser/gtk/options/fonts_page_gtk.cc index 03931b9..941e252 100644 --- a/chrome/browser/gtk/options/fonts_page_gtk.cc +++ b/chrome/browser/gtk/options/fonts_page_gtk.cc @@ -4,13 +4,13 @@ #include "chrome/browser/gtk/options/fonts_page_gtk.h" +#include "app/gfx/font.h" #include "app/l10n_util.h" #include "app/l10n_util_collator.h" -#include "app/gfx/font.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc index 8fed28c..8aecafe 100644 --- a/chrome/browser/gtk/options/general_page_gtk.cc +++ b/chrome/browser/gtk/options/general_page_gtk.cc @@ -9,6 +9,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/keyword_editor_view.h" #include "chrome/browser/gtk/list_store_favicon_loader.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" @@ -19,7 +20,6 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/session_startup_pref.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" diff --git a/chrome/browser/gtk/options/languages_page_gtk.cc b/chrome/browser/gtk/options/languages_page_gtk.cc index 2f17c9c..a8c97e4 100644 --- a/chrome/browser/gtk/options/languages_page_gtk.cc +++ b/chrome/browser/gtk/options/languages_page_gtk.cc @@ -11,10 +11,10 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/language_combobox_model.h" #include "chrome/browser/language_order_table_model.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/spellcheck_common.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/options/languages_page_gtk.h b/chrome/browser/gtk/options/languages_page_gtk.h index 4c396f3..dc44006 100644 --- a/chrome/browser/gtk/options/languages_page_gtk.h +++ b/chrome/browser/gtk/options/languages_page_gtk.h @@ -17,9 +17,9 @@ #include #include "base/scoped_ptr.h" +#include "chrome/browser/gtk/gtk_tree.h" #include "chrome/browser/pref_member.h" #include "chrome/browser/options_page_base.h" -#include "chrome/common/gtk_tree.h" #include "testing/gtest/include/gtest/gtest_prod.h" class LanguageComboboxModel; diff --git a/chrome/browser/gtk/options/options_layout_gtk.cc b/chrome/browser/gtk/options/options_layout_gtk.cc index 4fe42b9..07fe2e1 100644 --- a/chrome/browser/gtk/options/options_layout_gtk.cc +++ b/chrome/browser/gtk/options/options_layout_gtk.cc @@ -4,7 +4,7 @@ #include "chrome/browser/gtk/options/options_layout_gtk.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" OptionsLayoutBuilderGtk::OptionsLayoutBuilderGtk() { page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); diff --git a/chrome/browser/gtk/options/options_window_gtk.cc b/chrome/browser/gtk/options/options_window_gtk.cc index 58498a2..5bd2409 100644 --- a/chrome/browser/gtk/options/options_window_gtk.cc +++ b/chrome/browser/gtk/options/options_window_gtk.cc @@ -14,6 +14,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/advanced_page_gtk.h" #include "chrome/browser/gtk/options/content_page_gtk.h" #include "chrome/browser/gtk/options/general_page_gtk.h" @@ -21,7 +22,6 @@ #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/window_sizer.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc index 265289e..6b62087 100644 --- a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc +++ b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc @@ -7,9 +7,9 @@ #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "chrome/browser/gtk/gtk_tree.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/pref_service.h" -#include "chrome/common/gtk_tree.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "grit/app_resources.h" diff --git a/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc b/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc index fc93954..1abcf72 100644 --- a/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc +++ b/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc @@ -12,11 +12,11 @@ #include "base/message_loop.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/passwords_exceptions_page_gtk.h" #include "chrome/browser/gtk/options/passwords_page_gtk.h" #include "chrome/browser/options_window.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/gtk/options/passwords_page_gtk.cc b/chrome/browser/gtk/options/passwords_page_gtk.cc index 023ebb0..a0112e7 100644 --- a/chrome/browser/gtk/options/passwords_page_gtk.cc +++ b/chrome/browser/gtk/options/passwords_page_gtk.cc @@ -7,9 +7,9 @@ #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "chrome/browser/gtk/gtk_tree.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/pref_service.h" -#include "chrome/common/gtk_tree.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "grit/app_resources.h" diff --git a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc index 7177434..6e3b1c5 100644 --- a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc +++ b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc @@ -8,13 +8,13 @@ #include "app/l10n_util.h" #include "base/message_loop.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" +#include "chrome/browser/gtk/gtk_tree.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/options/url_picker_dialog_gtk.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/possible_url_model.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" -#include "chrome/common/gtk_tree.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "googleurl/src/gurl.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/options/url_picker_dialog_gtk.h b/chrome/browser/gtk/options/url_picker_dialog_gtk.h index 8da397d..3c12f95 100644 --- a/chrome/browser/gtk/options/url_picker_dialog_gtk.h +++ b/chrome/browser/gtk/options/url_picker_dialog_gtk.h @@ -9,8 +9,8 @@ #include "base/basictypes.h" #include "base/callback.h" +#include "chrome/browser/gtk/gtk_tree.h" #include "chrome/browser/history/history.h" -#include "chrome/common/gtk_tree.h" class AccessibleWidgetHelper; class GURL; diff --git a/chrome/browser/gtk/page_info_window_gtk.cc b/chrome/browser/gtk/page_info_window_gtk.cc index dfae04f..673f25d 100644 --- a/chrome/browser/gtk/page_info_window_gtk.cc +++ b/chrome/browser/gtk/page_info_window_gtk.cc @@ -11,11 +11,11 @@ #include "base/compiler_specific.h" #include "base/string_util.h" #include "chrome/browser/gtk/certificate_viewer.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/page_info_model.h" #include "chrome/browser/page_info_window.h" -#include "chrome/common/gtk_util.h" -#include "grit/locale_settings.h" #include "grit/generated_resources.h" +#include "grit/locale_settings.h" #include "grit/theme_resources.h" namespace { diff --git a/chrome/browser/gtk/process_singleton_dialog.cc b/chrome/browser/gtk/process_singleton_dialog.cc index 3710e0b..26fc1b4 100644 --- a/chrome/browser/gtk/process_singleton_dialog.cc +++ b/chrome/browser/gtk/process_singleton_dialog.cc @@ -6,7 +6,7 @@ #include "app/l10n_util.h" #include "base/message_loop.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "grit/chromium_strings.h" // static diff --git a/chrome/browser/gtk/repost_form_warning_gtk.cc b/chrome/browser/gtk/repost_form_warning_gtk.cc index a518f1d..5245866 100644 --- a/chrome/browser/gtk/repost_form_warning_gtk.cc +++ b/chrome/browser/gtk/repost_form_warning_gtk.cc @@ -6,8 +6,8 @@ #include "app/l10n_util.h" #include "base/message_loop.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/rounded_window.cc b/chrome/browser/gtk/rounded_window.cc index c512a0e..06cae21 100644 --- a/chrome/browser/gtk/rounded_window.cc +++ b/chrome/browser/gtk/rounded_window.cc @@ -8,7 +8,7 @@ #include #include "app/l10n_util.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" namespace gtk_util { diff --git a/chrome/browser/gtk/status_bubble_gtk.cc b/chrome/browser/gtk/status_bubble_gtk.cc index 94cd392..c238a66 100644 --- a/chrome/browser/gtk/status_bubble_gtk.cc +++ b/chrome/browser/gtk/status_bubble_gtk.cc @@ -12,9 +12,9 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/rounded_window.h" #include "chrome/browser/gtk/slide_animator_gtk.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "googleurl/src/gurl.h" diff --git a/chrome/browser/gtk/tab_contents_drag_source.cc b/chrome/browser/gtk/tab_contents_drag_source.cc index 22b78b2..490a524 100644 --- a/chrome/browser/gtk/tab_contents_drag_source.cc +++ b/chrome/browser/gtk/tab_contents_drag_source.cc @@ -11,11 +11,11 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/drag_download_file.h" #include "chrome/browser/download/drag_download_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" -#include "chrome/common/gtk_util.h" #include "net/base/file_stream.h" #include "net/base/net_util.h" #include "webkit/glue/webdropdata.h" diff --git a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc index f153455..9835423 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc @@ -9,11 +9,11 @@ #include "base/callback.h" #include "chrome/browser/browser.h" #include "chrome/browser/gtk/browser_window_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/tabs/dragged_tab_gtk.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" -#include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/common/notification_service.h" #include "chrome/common/platform_util.h" diff --git a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc index 56a83bf..67b6cf5 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc @@ -12,13 +12,13 @@ #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" #include "chrome/browser/browser_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" +#include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/backing_store_x.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tabs/tab_strip_model.h" -#include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/x11_util.h" #include "third_party/skia/include/core/SkShader.h" diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index 151e13a..b8f8e54 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -18,9 +18,9 @@ #include "chrome/browser/gtk/bookmark_utils_gtk.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 858b88b..3a811c8 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -6,9 +6,9 @@ #include -#include "app/gtk_dnd_util.h" #include "app/gfx/canvas_paint.h" #include "app/gfx/gtk_util.h" +#include "app/gtk_dnd_util.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/slide_animation.h" @@ -18,10 +18,10 @@ #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "grit/app_resources.h" diff --git a/chrome/browser/gtk/task_manager_gtk.cc b/chrome/browser/gtk/task_manager_gtk.cc index 18418f6..acddba5 100644 --- a/chrome/browser/gtk/task_manager_gtk.cc +++ b/chrome/browser/gtk/task_manager_gtk.cc @@ -21,12 +21,12 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_tree.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/memory_purger.h" #include "chrome/browser/pref_service.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/gtk_tree.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "grit/app_resources.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/gtk/theme_install_bubble_view_gtk.cc b/chrome/browser/gtk/theme_install_bubble_view_gtk.cc index 7586f07..3d9befb 100644 --- a/chrome/browser/gtk/theme_install_bubble_view_gtk.cc +++ b/chrome/browser/gtk/theme_install_bubble_view_gtk.cc @@ -8,8 +8,8 @@ #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/rounded_window.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc index e6b983a..5c1f931 100644 --- a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc +++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc @@ -12,9 +12,9 @@ #include "chrome/browser/gtk/browser_toolbar_gtk.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc index d0473da..4c81d7b 100644 --- a/chrome/browser/jankometer.cc +++ b/chrome/browser/jankometer.cc @@ -22,7 +22,7 @@ #include "chrome/common/chrome_switches.h" #if defined(OS_LINUX) -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #endif using base::TimeDelta; diff --git a/chrome/browser/js_modal_dialog_gtk.cc b/chrome/browser/js_modal_dialog_gtk.cc index 01aff6e..4fc5bd8 100644 --- a/chrome/browser/js_modal_dialog_gtk.cc +++ b/chrome/browser/js_modal_dialog_gtk.cc @@ -10,9 +10,9 @@ #include "app/message_box_flags.h" #include "base/logging.h" #include "base/string_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" -#include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/login_prompt_gtk.cc b/chrome/browser/login_prompt_gtk.cc index a99ad41..0614140 100644 --- a/chrome/browser/login_prompt_gtk.cc +++ b/chrome/browser/login_prompt_gtk.cc @@ -9,13 +9,13 @@ #include "app/l10n_util.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/gtk/constrained_window_gtk.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/login_model.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_util.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "net/url_request/url_request.h" diff --git a/chrome/browser/renderer_host/gtk_im_context_wrapper.cc b/chrome/browser/renderer_host/gtk_im_context_wrapper.cc index 4b14e8a..3921059 100644 --- a/chrome/browser/renderer_host/gtk_im_context_wrapper.cc +++ b/chrome/browser/renderer_host/gtk_im_context_wrapper.cc @@ -13,12 +13,12 @@ #include "base/logging.h" #include "base/string_util.h" #include "chrome/app/chrome_dll_resource.h" -#include "chrome/common/gtk_util.h" -#include "chrome/common/native_web_keyboard_event.h" -#include "chrome/common/render_messages.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" +#include "chrome/common/native_web_keyboard_event.h" +#include "chrome/common/render_messages.h" #include "grit/generated_resources.h" GtkIMContextWrapper::GtkIMContextWrapper(RenderWidgetHostViewGtk* host_view) diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc index 620e156..dcf26f5 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.cc +++ b/chrome/browser/renderer_host/render_view_host_delegate.cc @@ -11,7 +11,7 @@ #include "webkit/glue/webpreferences.h" #if defined(OS_LINUX) -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #endif RenderViewHostDelegate::View* RenderViewHostDelegate::GetViewDelegate() { diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index a5792b4..89c8c8b 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -25,13 +25,13 @@ #include "base/string_util.h" #include "base/task.h" #include "base/time.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/renderer_host/backing_store_x.h" #include "chrome/browser/renderer_host/gpu_view_host.h" #include "chrome/browser/renderer_host/gtk_im_context_wrapper.h" #include "chrome/browser/renderer_host/gtk_key_bindings_handler.h" #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/video_layer_x.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/native_web_keyboard_event.h" #include "chrome/common/x11_util.h" #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" diff --git a/chrome/browser/renderer_preferences_util.cc b/chrome/browser/renderer_preferences_util.cc index 28b4c05..dd29afc 100644 --- a/chrome/browser/renderer_preferences_util.cc +++ b/chrome/browser/renderer_preferences_util.cc @@ -8,7 +8,7 @@ #if defined(OS_LINUX) #include "chrome/browser/gtk/gtk_theme_provider.h" -#include "chrome/common/gtk_util.h" +#include "chrome/browser/gtk/gtk_util.h" #endif namespace renderer_preferences_util { diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index bc0e6fc..e52053d 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -21,6 +21,7 @@ #include "chrome/browser/gtk/gtk_expanded_container.h" #include "chrome/browser/gtk/gtk_floating_container.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/sad_tab_gtk.h" #include "chrome/browser/gtk/tab_contents_drag_source.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -31,7 +32,6 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/web_drag_dest_gtk.h" -#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" diff --git a/chrome/browser/tab_contents/web_drag_dest_gtk.cc b/chrome/browser/tab_contents/web_drag_dest_gtk.cc index d12f907..e379339 100644 --- a/chrome/browser/tab_contents/web_drag_dest_gtk.cc +++ b/chrome/browser/tab_contents/web_drag_dest_gtk.cc @@ -7,9 +7,9 @@ #include "app/gtk_dnd_util.h" #include "base/file_path.h" #include "base/string_util.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gtk_util.h" #include "net/base/net_util.h" using WebKit::WebDragOperation; diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc b/chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc index f178bc2..7f3f0c6 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc @@ -1,14 +1,14 @@ -// 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. +// 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/browser/views/autocomplete/autocomplete_popup_gtk.h" #include "app/gfx/insets.h" #include "chrome/browser/autocomplete/autocomplete_edit_view.h" #include "chrome/browser/autocomplete/autocomplete_popup_model.h" +#include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" -#include "chrome/common/gtk_util.h" //////////////////////////////////////////////////////////////////////////////// // AutocompletePopupGtk, public: diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 677af2c..fe76e2e 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1108,6 +1108,10 @@ 'browser/gtk/gtk_floating_container.h', 'browser/gtk/gtk_theme_provider.cc', 'browser/gtk/gtk_theme_provider.h', + 'browser/gtk/gtk_tree.cc', + 'browser/gtk/gtk_tree.h', + 'browser/gtk/gtk_util.cc', + 'browser/gtk/gtk_util.h', 'browser/gtk/html_dialog_gtk.cc', 'browser/gtk/html_dialog_gtk.h', 'browser/gtk/hung_renderer_dialog_gtk.cc', @@ -2725,6 +2729,10 @@ ['include', '^browser/gtk/gtk_chrome_link_button.h'], ['include', '^browser/gtk/gtk_theme_provider.cc'], ['include', '^browser/gtk/gtk_theme_provider.h'], + ['include', '^browser/gtk/gtk_tree.cc'], + ['include', '^browser/gtk/gtk_tree.h'], + ['include', '^browser/gtk/gtk_util.cc'], + ['include', '^browser/gtk/gtk_util.h'], ['include', '^browser/gtk/hung_renderer_dialog_gtk.cc'], ['include', '^browser/gtk/import_dialog_gtk.cc'], ['include', '^browser/gtk/import_dialog_gtk.h'], diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 566bfe3..f8772cc 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -204,10 +204,6 @@ 'common/gears_api.h', 'common/gpu_plugin.cc', 'common/gpu_plugin.h', - 'common/gtk_tree.cc', - 'common/gtk_tree.h', - 'common/gtk_util.cc', - 'common/gtk_util.h', 'common/jstemplate_builder.cc', 'common/jstemplate_builder.h', 'common/libxml_utils.cc', 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* 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(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 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(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 -#include -#include - -#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* 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 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 -#include - -#include -#include - -#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[] = "%s"; - -// 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::iterator it = - cursor_cache_.begin(); it != cursor_cache_.end(); ++it) { - gdk_cursor_unref(it->second); - } - cursor_cache_.clear(); - } - - GdkCursor* GetCursorImpl(GdkCursorType type) { - std::map::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 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* 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( - pango_font_metrics_get_approximate_char_width(metrics) * - width_chars / PANGO_SCALE); - } - if (height) { - *height = static_cast( - (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 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::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 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::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 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 -#include -#include - -#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* 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" -- cgit v1.1