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

Side by Side Diff: chrome/browser/ui/webui/options2/font_settings_handler2.cc

Issue 9838055: Fixed bidi RTL check failures on font settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sets the directionality from the contents of the font strings. Created 8 years, 8 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
« no previous file with comments | « chrome/browser/ui/webui/bidi_checker_web_ui_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options2/font_settings_handler2.h" 5 #include "chrome/browser/ui/webui/options2/font_settings_handler2.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { 128 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) {
129 content::GetFontListAsync( 129 content::GetFontListAsync(
130 base::Bind(&FontSettingsHandler::FontsListHasLoaded, 130 base::Bind(&FontSettingsHandler::FontsListHasLoaded,
131 base::Unretained(this))); 131 base::Unretained(this)));
132 } 132 }
133 133
134 void FontSettingsHandler::FontsListHasLoaded( 134 void FontSettingsHandler::FontsListHasLoaded(
135 scoped_ptr<base::ListValue> list) { 135 scoped_ptr<base::ListValue> list) {
136 // Selects the directionality for the fonts in the given list.
137 for (size_t i = 0; i < list->GetSize(); i++) {
138 ListValue* font;
139 bool has_font = list->GetList(i, &font);
140 DCHECK(has_font);
141 string16 value;
142 bool has_value = font->GetString(1, &value);
143 DCHECK(has_value);
144 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value);
145 font->Append(Value::CreateStringValue(has_rtl_chars ? "rtl" : "ltr"));
146 }
147
136 ListValue encoding_list; 148 ListValue encoding_list;
137 const std::vector<CharacterEncoding::EncodingInfo>* encodings; 149 const std::vector<CharacterEncoding::EncodingInfo>* encodings;
138 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 150 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
139 encodings = CharacterEncoding::GetCurrentDisplayEncodings( 151 encodings = CharacterEncoding::GetCurrentDisplayEncodings(
140 g_browser_process->GetApplicationLocale(), 152 g_browser_process->GetApplicationLocale(),
141 pref_service->GetString(prefs::kStaticEncodings), 153 pref_service->GetString(prefs::kStaticEncodings),
142 pref_service->GetString(prefs::kRecentlySelectedEncoding)); 154 pref_service->GetString(prefs::kRecentlySelectedEncoding));
143 DCHECK(encodings); 155 DCHECK(encodings);
144 DCHECK(!encodings->empty()); 156 DCHECK(!encodings->empty());
145 157
146 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; 158 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it;
147 for (it = encodings->begin(); it != encodings->end(); ++it) { 159 for (it = encodings->begin(); it != encodings->end(); ++it) {
148 ListValue* option = new ListValue(); 160 ListValue* option = new ListValue();
149 if (it->encoding_id) { 161 if (it->encoding_id) {
150 int cmd_id = it->encoding_id; 162 int cmd_id = it->encoding_id;
151 std::string encoding = 163 std::string encoding =
152 CharacterEncoding::GetCanonicalEncodingNameByCommandId(cmd_id); 164 CharacterEncoding::GetCanonicalEncodingNameByCommandId(cmd_id);
153 string16 name = it->encoding_display_name; 165 string16 name = it->encoding_display_name;
154 base::i18n::AdjustStringForLocaleDirection(&name); 166 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(name);
155 option->Append(Value::CreateStringValue(encoding)); 167 option->Append(Value::CreateStringValue(encoding));
156 option->Append(Value::CreateStringValue(name)); 168 option->Append(Value::CreateStringValue(name));
169 option->Append(Value::CreateStringValue(has_rtl_chars ? "rtl" : "ltr"));
157 } else { 170 } else {
158 // Add empty name/value to indicate a separator item. 171 // Add empty name/value to indicate a separator item.
159 option->Append(Value::CreateStringValue("")); 172 option->Append(Value::CreateStringValue(""));
160 option->Append(Value::CreateStringValue("")); 173 option->Append(Value::CreateStringValue(""));
161 } 174 }
162 encoding_list.Append(option); 175 encoding_list.Append(option);
163 } 176 }
164 177
165 ListValue selected_values; 178 ListValue selected_values;
166 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( 179 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 "FontSettings.setUpFixedFontSample", font_value, size_value); 243 "FontSettings.setUpFixedFontSample", font_value, size_value);
231 } 244 }
232 245
233 void FontSettingsHandler::SetUpMinimumFontSample() { 246 void FontSettingsHandler::SetUpMinimumFontSample() {
234 base::FundamentalValue size_value(minimum_font_size_.GetValue()); 247 base::FundamentalValue size_value(minimum_font_size_.GetValue());
235 web_ui()->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", 248 web_ui()->CallJavascriptFunction("FontSettings.setUpMinimumFontSample",
236 size_value); 249 size_value);
237 } 250 }
238 251
239 } // namespace options2 252 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/bidi_checker_web_ui_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698