summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/fonts_languages_window.h26
-rw-r--r--chrome/browser/gtk/options/fonts_languages_window_gtk.cc136
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc22
-rw-r--r--chrome/browser/views/options/fonts_languages_window_view.cc39
-rw-r--r--chrome/browser/views/options/fonts_languages_window_view.h14
-rw-r--r--chrome/chrome.gyp4
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc11
7 files changed, 225 insertions, 27 deletions
diff --git a/chrome/browser/fonts_languages_window.h b/chrome/browser/fonts_languages_window.h
new file mode 100644
index 0000000..81f01e8
--- /dev/null
+++ b/chrome/browser/fonts_languages_window.h
@@ -0,0 +1,26 @@
+// 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_FONTS_LANGUAGES_WINDOW_H_
+#define CHROME_BROWSER_FONTS_LANGUAGES_WINDOW_H_
+
+#include "base/gfx/native_widget_types.h"
+
+class Profile;
+
+// An identifier for Fonts and Languages page. These are treated as indices into
+// the list of available tabs to be displayed.
+enum FontsLanguagesPage {
+ FONTS_ENCODING_PAGE = 0,
+ LANGUAGES_PAGE
+};
+
+// Show the Fonts and Languages window selecting the specified page. If a
+// Fonts and Languages window is currently open, this just activates it instead
+// of opening a new one.
+void ShowFontsLanguagesWindow(gfx::NativeWindow window,
+ FontsLanguagesPage page,
+ Profile* profile);
+
+#endif // CHROME_BROWSER_FONTS_LANGUAGES_WINDOW_H_
diff --git a/chrome/browser/gtk/options/fonts_languages_window_gtk.cc b/chrome/browser/gtk/options/fonts_languages_window_gtk.cc
new file mode 100644
index 0000000..a5d3a49
--- /dev/null
+++ b/chrome/browser/gtk/options/fonts_languages_window_gtk.cc
@@ -0,0 +1,136 @@
+// 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/fonts_languages_window.h"
+
+#include <gtk/gtk.h>
+
+#include "app/l10n_util.h"
+#include "base/message_loop.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/gtk_util.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+
+///////////////////////////////////////////////////////////////////////////////
+// FontsLanguagesWindowGtk
+//
+// The contents of the Options dialog window.
+
+class FontsLanguagesWindowGtk {
+ public:
+ explicit FontsLanguagesWindowGtk(Profile* profile);
+ ~FontsLanguagesWindowGtk();
+
+ // Shows the tab corresponding to the specified |page|.
+ void ShowTabPage(FontsLanguagesPage page);
+
+ private:
+ static void OnWindowDestroy(GtkWidget* widget,
+ FontsLanguagesWindowGtk* window);
+
+ // The fonts and languages dialog.
+ GtkWidget *dialog_;
+
+ // The container of the option pages.
+ GtkWidget *notebook_;
+
+ // The Profile associated with these options.
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(FontsLanguagesWindowGtk);
+};
+
+static FontsLanguagesWindowGtk* instance_ = NULL;
+
+///////////////////////////////////////////////////////////////////////////////
+// FontsLanguagesWindowGtk, public:
+
+FontsLanguagesWindowGtk::FontsLanguagesWindowGtk(Profile* profile)
+ // Always show preferences for the original profile. Most state when off
+ // the record comes from the original profile, but we explicitly use
+ // the original profile to avoid potential problems.
+ : profile_(profile->GetOriginalProfile()) {
+ dialog_ = gtk_dialog_new_with_buttons(
+ l10n_util::GetStringFUTF8(IDS_FONT_LANGUAGE_SETTING_WINDOWS_TITLE,
+ l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str(),
+ // Prefs window is shared between all browser windows.
+ NULL,
+ // Non-modal.
+ GTK_DIALOG_NO_SEPARATOR,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_CLOSE,
+ NULL);
+ gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1);
+ gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox),
+ gtk_util::kContentAreaSpacing);
+
+ notebook_ = gtk_notebook_new();
+
+ // Fonts and Encoding tab.
+ gtk_notebook_append_page(
+ GTK_NOTEBOOK(notebook_),
+ gtk_label_new("TODO content"),
+ gtk_label_new(
+ l10n_util::GetStringUTF8(
+ IDS_FONT_LANGUAGE_SETTING_FONT_TAB_TITLE).c_str()));
+
+ // Langauges tab.
+ gtk_notebook_append_page(
+ GTK_NOTEBOOK(notebook_),
+ gtk_label_new("TODO content"),
+ gtk_label_new(
+ l10n_util::GetStringUTF8(
+ IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE).c_str()));
+
+ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_);
+
+ // Show the notebook.
+ gtk_widget_show_all(dialog_);
+
+ // We only have one button and don't do any special handling, so just hook it
+ // directly to gtk_widget_destroy.
+ g_signal_connect_swapped(dialog_, "response", G_CALLBACK(gtk_widget_destroy),
+ dialog_);
+
+ g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this);
+}
+
+FontsLanguagesWindowGtk::~FontsLanguagesWindowGtk() {
+}
+
+void FontsLanguagesWindowGtk::ShowTabPage(FontsLanguagesPage page) {
+ // Bring options window to front if it already existed and isn't already
+ // in front.
+ gtk_window_present(GTK_WINDOW(dialog_));
+
+ // If the page is out of bounds, reset to the first tab.
+ if (page < 0 || page >= gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_)))
+ page = FONTS_ENCODING_PAGE;
+
+ // Switch the tab to the selected |page|.
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook_), page);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// FontsLanguagesWindowGtk, private:
+
+// static
+void FontsLanguagesWindowGtk::OnWindowDestroy(GtkWidget* widget,
+ FontsLanguagesWindowGtk* window) {
+ instance_ = NULL;
+ MessageLoop::current()->DeleteSoon(FROM_HERE, window);
+}
+
+void ShowFontsLanguagesWindow(gfx::NativeWindow window,
+ FontsLanguagesPage page,
+ Profile* profile) {
+ DCHECK(profile);
+ // If there's already an existing fonts and language window, activate it and
+ // switch to the specified page.
+ if (!instance_)
+ instance_ = new FontsLanguagesWindowGtk(profile);
+
+ instance_->ShowTabPage(page);
+}
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index f7505a7..ecb3eba 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -12,6 +12,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/fonts_languages_window.h"
#include "chrome/browser/page_info_window.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -26,10 +27,6 @@
#include "net/base/escape.h"
#include "net/base/net_util.h"
-#if defined(OS_WIN)
-#include "chrome/browser/views/options/fonts_languages_window_view.h"
-#endif
-
RenderViewContextMenu::RenderViewContextMenu(
TabContents* tab_contents,
const ContextMenuParams& params)
@@ -556,23 +553,12 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) {
params_.misspelled_word);
break;
- case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS: {
-#if defined(OS_WIN)
- // TODO(yusukes): This should be moved to some shared place of commands
- // for the options stuff so that we don't have to do all this work here.
- FontsLanguagesWindowView* window_ = new FontsLanguagesWindowView(
- profile_);
- views::Window::CreateChromeWindow(
+ case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
+ ShowFontsLanguagesWindow(
platform_util::GetTopLevel(
source_tab_contents_->GetContentNativeView()),
- gfx::Rect(), window_)->Show();
- window_->SelectLanguagesTab();
-#else
- // TODO(port): need views::Window
- NOTIMPLEMENTED() << "IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS";
-#endif
+ LANGUAGES_PAGE, profile_);
break;
- }
case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
default:
diff --git a/chrome/browser/views/options/fonts_languages_window_view.cc b/chrome/browser/views/options/fonts_languages_window_view.cc
index cf26d1f..a9fb957 100644
--- a/chrome/browser/views/options/fonts_languages_window_view.cc
+++ b/chrome/browser/views/options/fonts_languages_window_view.cc
@@ -53,6 +53,12 @@ std::wstring FontsLanguagesWindowView::GetWindowTitle() const {
l10n_util::GetString(IDS_PRODUCT_NAME));
}
+void FontsLanguagesWindowView::WindowClosing() {
+ // Clear the static instance so that the next time ShowOptionsWindow() is
+ // called a new window is opened.
+ instance_ = NULL;
+}
+
views::View* FontsLanguagesWindowView::GetContentsView() {
return this;
}
@@ -72,8 +78,20 @@ gfx::Size FontsLanguagesWindowView::GetPreferredSize() {
IDS_FONTSLANG_DIALOG_HEIGHT_LINES));
}
-void FontsLanguagesWindowView::SelectLanguagesTab() {
- tabs_->SelectTabForContents(languages_page_);
+void FontsLanguagesWindowView::ShowTabPage(FontsLanguagesPage page) {
+ // If the window is not yet visible, we need to show it (it will become
+ // active), otherwise just bring it to the front.
+ if (!window()->IsVisible()) {
+ window()->Show();
+ } else {
+ window()->Activate();
+ }
+
+ // If the page is out of bounds, reset to the first tab.
+ if (page < 0 || page >= tabs_->GetTabCount())
+ page = FONTS_ENCODING_PAGE;
+
+ tabs_->SelectTabAt(page);
}
void FontsLanguagesWindowView::ViewHierarchyChanged(
@@ -99,3 +117,20 @@ void FontsLanguagesWindowView::Init() {
tabs_->AddTab(l10n_util::GetString(
IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE), languages_page_);
}
+
+void ShowFontsLanguagesWindow(gfx::NativeWindow window,
+ FontsLanguagesPage page,
+ Profile* profile) {
+ DCHECK(profile);
+
+ // If there's already an existing fonts and language window, activate it and
+ // switch to the specified page.
+ // TODO(beng): note this is not multi-simultaneous-profile-safe. When we care
+ // about this case this will have to be fixed.
+ if (!instance_) {
+ instance_ = new FontsLanguagesWindowView(profile);
+ views::Window::CreateChromeWindow(window, gfx::Rect(), instance_);
+ // The window is alive by itself now...
+ }
+ instance_->ShowTabPage(page);
+}
diff --git a/chrome/browser/views/options/fonts_languages_window_view.h b/chrome/browser/views/options/fonts_languages_window_view.h
index e33d74a..46ec91b 100644
--- a/chrome/browser/views/options/fonts_languages_window_view.h
+++ b/chrome/browser/views/options/fonts_languages_window_view.h
@@ -1,10 +1,11 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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_FONTS_LANGUAGE_WINDOW_H__
-#define CHROME_BROWSER_FONTS_LANGUAGE_WINDOW_H__
+#ifndef CHROME_BROWSER_VIEWS_OPTIONS_FONTS_LANGUAGES_WINDOW_VIEW_H_
+#define CHROME_BROWSER_VIEWS_OPTIONS_FONTS_LANGUAGES_WINDOW_VIEW_H_
+#include "chrome/browser/fonts_languages_window.h"
#include "views/controls/tabbed_pane.h"
#include "views/view.h"
#include "views/window/dialog_delegate.h"
@@ -32,13 +33,14 @@ class FontsLanguagesWindowView : public views::View,
virtual bool IsModal() const { return true; }
virtual std::wstring GetWindowTitle() const;
virtual views::View* GetContentsView();
+ virtual void WindowClosing();
// views::View overrides:
virtual void Layout();
virtual gfx::Size GetPreferredSize();
- // Selects the Languages tab.
- void SelectLanguagesTab();
+ // Shows the tab corresponding to the specified |page|.
+ void ShowTabPage(FontsLanguagesPage page);
protected:
// views::View overrides:
@@ -66,4 +68,4 @@ class FontsLanguagesWindowView : public views::View,
DISALLOW_EVIL_CONSTRUCTORS(FontsLanguagesWindowView);
};
-#endif // #ifndef CHROME_BROWSER_FONTS_LANGUAGE_WINDOW_H__
+#endif // CHROME_BROWSER_VIEWS_OPTIONS_FONTS_LANGUAGES_WINDOW_VIEW_H_
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 7bb23ec..e4670fa 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -925,6 +925,7 @@
'browser/first_run_mac.mm',
'browser/first_run_win.cc',
'browser/first_run_gtk.cc',
+ 'browser/fonts_languages_window.h',
'browser/gears_integration.cc',
'browser/gears_integration.h',
'browser/google_update.cc',
@@ -1009,8 +1010,9 @@
'browser/gtk/menu_gtk.h',
'browser/gtk/nine_box.cc',
'browser/gtk/nine_box.h',
- 'browser/gtk/options/content_page_gtk.cc',
+ 'browser/gtk/options/content_page_gtk.cc',
'browser/gtk/options/content_page_gtk.h',
+ 'browser/gtk/options/fonts_languages_window_gtk.cc',
'browser/gtk/options/general_page_gtk.cc',
'browser/gtk/options/general_page_gtk.h',
'browser/gtk/options/options_layout_gtk.cc',
diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc
index 94910ce..8b4b46a 100644
--- a/chrome/common/temp_scaffolding_stubs.cc
+++ b/chrome/common/temp_scaffolding_stubs.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/download/download_request_dialog_delegate.h"
#include "chrome/browser/download/download_request_manager.h"
#include "chrome/browser/first_run.h"
+#include "chrome/browser/fonts_languages_window.h"
#include "chrome/browser/hung_renderer_dialog.h"
#include "chrome/browser/memory_details.h"
#include "chrome/browser/options_window.h"
@@ -337,6 +338,16 @@ void DockInfo::AdjustOtherWindowBounds() const {
//------------------------------------------------------------------------------
+#if defined(OS_MACOSX)
+void ShowFontsLanguagesWindow(gfx::NativeWindow window,
+ FontsLanguagesPage page,
+ Profile* profile) {
+ NOTIMPLEMENTED();
+}
+#endif
+
+//------------------------------------------------------------------------------
+
#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
namespace views {