Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1690)

Side by Side Diff: chrome/browser/ui/views/options/fonts_languages_window_view.cc

Issue 6670011: Options: Remove the GTK and Views native options code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/options/fonts_languages_window_view.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/views/options/fonts_page_view.h"
10 #include "chrome/browser/ui/views/options/languages_page_view.h"
11 #include "chrome/common/chrome_constants.h"
12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14 #include "grit/locale_settings.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "views/controls/tabbed_pane/tabbed_pane.h"
17 #include "views/window/window.h"
18
19 // static
20 static FontsLanguagesWindowView* instance_ = NULL;
21 static const int kDialogPadding = 7;
22
23 ///////////////////////////////////////////////////////////////////////////////
24 // FontsLanguagesWindowView, public:
25
26 FontsLanguagesWindowView::FontsLanguagesWindowView(Profile* profile)
27 // Always show preferences for the original profile. Most state when off
28 // the record comes from the original profile, but we explicitly use
29 // the original profile to avoid potential problems.
30 : profile_(profile->GetOriginalProfile()),
31 fonts_page_(NULL),
32 languages_page_(NULL) {
33 }
34
35 FontsLanguagesWindowView::~FontsLanguagesWindowView() {
36 }
37
38 ///////////////////////////////////////////////////////////////////////////////
39 // FontsLanguagesWindowView, views::DialogDelegate implementation:
40
41 bool FontsLanguagesWindowView::Accept() {
42 fonts_page_->SaveChanges();
43 languages_page_->SaveChanges();
44 return true;
45 }
46
47 ///////////////////////////////////////////////////////////////////////////////
48 // FontsLanguagesWindowView, views::WindowDelegate implementation:
49
50 std::wstring FontsLanguagesWindowView::GetWindowTitle() const {
51 return UTF16ToWide(
52 l10n_util::GetStringUTF16(IDS_FONT_LANGUAGE_SETTING_WINDOWS_TITLE));
53 }
54
55 void FontsLanguagesWindowView::WindowClosing() {
56 // Clear the static instance so that the next time ShowOptionsWindow() is
57 // called a new window is opened.
58 instance_ = NULL;
59 }
60
61 views::View* FontsLanguagesWindowView::GetContentsView() {
62 return this;
63 }
64
65 ///////////////////////////////////////////////////////////////////////////////
66 // FontsLanguagesWindowView, views::View overrides:
67
68 void FontsLanguagesWindowView::Layout() {
69 tabs_->SetBounds(kDialogPadding, kDialogPadding,
70 width() - (2 * kDialogPadding),
71 height() - (2 * kDialogPadding));
72 }
73
74 gfx::Size FontsLanguagesWindowView::GetPreferredSize() {
75 return gfx::Size(views::Window::GetLocalizedContentsSize(
76 IDS_FONTSLANG_DIALOG_WIDTH_CHARS,
77 IDS_FONTSLANG_DIALOG_HEIGHT_LINES));
78 }
79
80 void FontsLanguagesWindowView::ShowTabPage(FontsLanguagesPage page) {
81 // If the window is not yet visible, we need to show it (it will become
82 // active), otherwise just bring it to the front.
83 if (!window()->IsVisible()) {
84 window()->Show();
85 } else {
86 window()->Activate();
87 }
88
89 // If the page is out of bounds, reset to the first tab.
90 if (page < 0 || page >= tabs_->GetTabCount())
91 page = FONTS_ENCODING_PAGE;
92
93 tabs_->SelectTabAt(page);
94 }
95
96 void FontsLanguagesWindowView::ViewHierarchyChanged(
97 bool is_add, views::View* parent, views::View* child) {
98 // Can't init before we're inserted into a Container, because we require
99 // a HWND to parent native child controls to.
100 if (is_add && child == this)
101 Init();
102 }
103
104 ///////////////////////////////////////////////////////////////////////////////
105 // FontsLanguagesWindowView, private:
106
107 void FontsLanguagesWindowView::Init() {
108 tabs_ = new views::TabbedPane;
109 AddChildView(tabs_);
110
111 fonts_page_ = new FontsPageView(profile_);
112 tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16(
113 IDS_FONT_LANGUAGE_SETTING_FONT_TAB_TITLE)), fonts_page_);
114
115 languages_page_ = new LanguagesPageView(profile_);
116 tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16(
117 IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE)), languages_page_);
118 }
119
120 void ShowFontsLanguagesWindow(gfx::NativeWindow window,
121 FontsLanguagesPage page,
122 Profile* profile) {
123 DCHECK(profile);
124
125 // If there's already an existing fonts and language window, activate it and
126 // switch to the specified page.
127 // TODO(beng): note this is not multi-simultaneous-profile-safe. When we care
128 // about this case this will have to be fixed.
129 if (!instance_) {
130 instance_ = new FontsLanguagesWindowView(profile);
131 views::Window::CreateChromeWindow(window, gfx::Rect(), instance_);
132 }
133 instance_->ShowTabPage(page);
134 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/options/fonts_languages_window_view.h ('k') | chrome/browser/ui/views/options/fonts_page_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698