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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 19666006: Supports FontList in Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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
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/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 using views::View; 107 using views::View;
108 108
109 109
110 namespace { 110 namespace {
111 111
112 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { 112 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) {
113 WebContents* contents = delegate->GetWebContents(); 113 WebContents* contents = delegate->GetWebContents();
114 return contents ? chrome::FindBrowserWithWebContents(contents) : NULL; 114 return contents ? chrome::FindBrowserWithWebContents(contents) : NULL;
115 } 115 }
116 116
117 // Given a containing |height| and a base |font|, shrinks the font until it will 117 // Given a containing |height| and a base |font_list|, shrinks the fonts until
118 // fit within |height| while having its cap height vertically centered. Returns 118 // it will fit within |height| while having its cap height vertically centered.
119 // the |font_y_offset| needed to produce this centering. 119 // Returns the |font_y_offset| needed to produce this centering.
120 void CalculateFontAndOffsetForHeight(int height, 120 void CalculateFontAndOffsetForHeight(int height,
121 gfx::Font* font, 121 gfx::FontList* font_list,
122 int* font_y_offset) { 122 int* font_y_offset) {
123 #if defined(OS_WIN) 123 #if defined(OS_WIN)
124 base::win::ScopedGetDC screen_dc(NULL); 124 base::win::ScopedGetDC screen_dc(NULL);
125 #endif 125 #endif
126 126
127 while (true) { 127 while (true) {
128 // TODO(pkasting): Expand the gfx::Font metrics (and underlying Skia 128 // TODO(pkasting): Expand the gfx::Font metrics (and underlying Skia
129 // metrics) enough to expose the cap height directly. 129 // metrics) enough to expose the cap height directly.
130 #if defined(OS_WIN) 130 #if defined(OS_WIN)
131 base::win::ScopedSelectObject font_in_dc(screen_dc, font->GetNativeFont()); 131 const gfx::Font& font = font_list->GetPrimaryFont();
132 base::win::ScopedSelectObject font_in_dc(screen_dc, font.GetNativeFont());
132 TEXTMETRIC tm = {0}; 133 TEXTMETRIC tm = {0};
133 GetTextMetrics(screen_dc, &tm); 134 GetTextMetrics(screen_dc, &tm);
134 int cap_height = font->GetBaseline() - tm.tmInternalLeading; 135 int cap_height = font.GetBaseline() - tm.tmInternalLeading;
135 *font_y_offset = ((height - cap_height) / 2) - tm.tmInternalLeading; 136 *font_y_offset = ((height - cap_height) / 2) - tm.tmInternalLeading;
136 #else 137 #else
137 // Without cap height available, we fall back to centering the full height. 138 // Without cap height available, we fall back to centering the full height.
138 *font_y_offset = (height - font->GetHeight()) / 2; 139 *font_y_offset = (height - font_list->GetHeight()) / 2;
139 #endif 140 #endif
140 141
141 if (((*font_y_offset >= 0) && 142 if (((*font_y_offset >= 0) &&
142 ((*font_y_offset + font->GetHeight()) <= height)) || 143 ((*font_y_offset + font_list->GetHeight()) <= height)) ||
143 (font->GetFontSize() <= 1)) 144 (font_list->GetPrimaryFont().GetFontSize() <= 1))
144 return; 145 return;
145 *font = font->DeriveFont(-1); 146 *font_list = font_list->DeriveFontListWithSize(
147 font_list->GetPrimaryFont().GetFontSize() - 1);
msw 2013/07/23 19:51:54 Alexei, is it possible that this loop's terminal c
146 } 148 }
147 } 149 }
148 150
149 } // namespace 151 } // namespace
150 152
151 153
152 // LocationBarView ----------------------------------------------------------- 154 // LocationBarView -----------------------------------------------------------
153 155
154 // static 156 // static
155 const int LocationBarView::kNormalEdgeThickness = 2; 157 const int LocationBarView::kNormalEdgeThickness = 2;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void LocationBarView::Init() { 229 void LocationBarView::Init() {
228 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're 230 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're
229 // not prepared for that. 231 // not prepared for that.
230 DCHECK(GetWidget()); 232 DCHECK(GetWidget());
231 233
232 location_icon_view_ = new LocationIconView(this); 234 location_icon_view_ = new LocationIconView(this);
233 location_icon_view_->set_drag_controller(this); 235 location_icon_view_->set_drag_controller(this);
234 AddChildView(location_icon_view_); 236 AddChildView(location_icon_view_);
235 237
236 // Determine the main font. 238 // Determine the main font.
237 gfx::Font font(ui::ResourceBundle::GetSharedInstance().GetFont( 239 #if defined(OS_CHROMEOS)
msw 2013/07/23 19:51:54 All platforms should invoke the same codepath if p
Yuki 2013/07/24 09:17:05 Thanks. I specify BaseFont as the same as before.
240 // Uses the default fonts which is IDS_UI_FONT_FAMILY_CROS.
241 gfx::FontList font_list;
242 #else
243 gfx::FontList font_list(ui::ResourceBundle::GetSharedInstance().GetFont(
238 ui::ResourceBundle::BaseFont)); 244 ui::ResourceBundle::BaseFont));
239 const int current_font_size = font.GetFontSize(); 245 #endif
246 const int current_font_size = font_list.GetPrimaryFont().GetFontSize();
240 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize; 247 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize;
241 if (current_font_size < desired_font_size) 248 if (current_font_size < desired_font_size)
242 font = font.DeriveFont(desired_font_size - current_font_size); 249 font_list = font_list.DeriveFontListWithSize(desired_font_size);
243 // Shrink large fonts to make them fit. 250 // Shrink large fonts to make them fit.
244 // TODO(pkasting): Stretch the location bar instead in this case. 251 // TODO(pkasting): Stretch the location bar instead in this case.
245 int location_height = GetInternalHeight(true); 252 int location_height = GetInternalHeight(true);
246 int font_y_offset; 253 int font_y_offset;
247 CalculateFontAndOffsetForHeight(location_height, &font, &font_y_offset); 254 CalculateFontAndOffsetForHeight(location_height, &font_list, &font_y_offset);
248 255
249 // Determine the font for use inside the bubbles. 256 // Determine the font for use inside the bubbles.
250 gfx::Font bubble_font(font); 257 gfx::FontList bubble_font_list(font_list);
251 int bubble_font_y_offset; 258 int bubble_font_y_offset;
252 // The bubble background images have 1 px thick edges, which we don't want to 259 // The bubble background images have 1 px thick edges, which we don't want to
253 // overlap. 260 // overlap.
254 const int kBubbleInteriorVerticalPadding = 1; 261 const int kBubbleInteriorVerticalPadding = 1;
255 CalculateFontAndOffsetForHeight( 262 CalculateFontAndOffsetForHeight(
256 location_height - ((kBubblePadding + kBubbleInteriorVerticalPadding) * 2), 263 location_height - ((kBubblePadding + kBubbleInteriorVerticalPadding) * 2),
257 &bubble_font, &bubble_font_y_offset); 264 &bubble_font_list, &bubble_font_y_offset);
258 bubble_font_y_offset += kBubbleInteriorVerticalPadding; 265 bubble_font_y_offset += kBubbleInteriorVerticalPadding;
259 266
260 const SkColor background_color = 267 const SkColor background_color =
261 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); 268 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND);
262 ev_bubble_view_ = new EVBubbleView( 269 ev_bubble_view_ = new EVBubbleView(
msw 2013/07/23 19:51:54 Is it okay that EVBubbleView, views::Label, Select
Yuki 2013/07/24 09:17:05 In the ideal situation, we should NEVER use GetPri
263 bubble_font, bubble_font_y_offset, 270 bubble_font_list.GetPrimaryFont(), bubble_font_y_offset,
264 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), background_color, this); 271 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), background_color, this);
265 ev_bubble_view_->set_drag_controller(this); 272 ev_bubble_view_->set_drag_controller(this);
266 AddChildView(ev_bubble_view_); 273 AddChildView(ev_bubble_view_);
267 274
268 // Initialize the Omnibox view. 275 // Initialize the Omnibox view.
269 location_entry_.reset(CreateOmniboxView(this, model_, profile_, 276 location_entry_.reset(CreateOmniboxView(this, model_, profile_,
270 command_updater_, is_popup_mode_, this, font, font_y_offset)); 277 command_updater_, is_popup_mode_, this, font_list, font_y_offset));
271 SetLocationEntryFocusable(true); 278 SetLocationEntryFocusable(true);
272 location_entry_view_ = location_entry_->AddToView(this); 279 location_entry_view_ = location_entry_->AddToView(this);
273 280
274 // Initialize the inline autocomplete view which is visible only when IME is 281 // Initialize the inline autocomplete view which is visible only when IME is
275 // turned on. Use the same font with the omnibox and highlighted background. 282 // turned on. Use the same font with the omnibox and highlighted background.
276 ime_inline_autocomplete_view_ = new views::Label(string16(), font); 283 ime_inline_autocomplete_view_ = new views::Label(string16(),
284 font_list.GetPrimaryFont());
277 ime_inline_autocomplete_view_->set_border( 285 ime_inline_autocomplete_view_->set_border(
278 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); 286 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0));
279 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 287 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
280 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 288 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
281 ime_inline_autocomplete_view_->set_background( 289 ime_inline_autocomplete_view_->set_background(
282 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 290 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
283 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 291 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
284 ime_inline_autocomplete_view_->SetEnabledColor( 292 ime_inline_autocomplete_view_->SetEnabledColor(
285 GetNativeTheme()->GetSystemColor( 293 GetNativeTheme()->GetSystemColor(
286 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 294 ui::NativeTheme::kColorId_TextfieldSelectionColor));
287 ime_inline_autocomplete_view_->SetVisible(false); 295 ime_inline_autocomplete_view_->SetVisible(false);
288 AddChildView(ime_inline_autocomplete_view_); 296 AddChildView(ime_inline_autocomplete_view_);
289 297
290 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); 298 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT);
291 selected_keyword_view_ = new SelectedKeywordView( 299 selected_keyword_view_ = new SelectedKeywordView(
292 bubble_font, bubble_font_y_offset, text_color, background_color, 300 bubble_font_list.GetPrimaryFont(), bubble_font_y_offset, text_color,
293 profile_); 301 background_color, profile_);
294 AddChildView(selected_keyword_view_); 302 AddChildView(selected_keyword_view_);
295 303
296 suggested_text_view_ = new views::Label(string16(), font); 304 suggested_text_view_ = new views::Label(string16(),
305 font_list.GetPrimaryFont());
297 suggested_text_view_->set_border( 306 suggested_text_view_->set_border(
298 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); 307 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0));
299 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 308 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
300 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 309 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
301 suggested_text_view_->SetEnabledColor(GetColor( 310 suggested_text_view_->SetEnabledColor(GetColor(
302 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 311 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT));
303 suggested_text_view_->SetVisible(false); 312 suggested_text_view_->SetVisible(false);
304 AddChildView(suggested_text_view_); 313 AddChildView(suggested_text_view_);
305 314
306 keyword_hint_view_ = new KeywordHintView( 315 keyword_hint_view_ = new KeywordHintView(
307 profile_, font, font_y_offset, 316 profile_, font_list.GetPrimaryFont(), font_y_offset,
308 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), 317 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT),
309 background_color); 318 background_color);
310 AddChildView(keyword_hint_view_); 319 AddChildView(keyword_hint_view_);
311 320
312 mic_search_view_ = new MicSearchView(this); 321 mic_search_view_ = new MicSearchView(this);
313 mic_search_view_->SetVisible(false); 322 mic_search_view_->SetVisible(false);
314 AddChildView(mic_search_view_); 323 AddChildView(mic_search_view_);
315 324
316 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 325 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
317 ContentSettingImageView* content_blocked_view = 326 ContentSettingImageView* content_blocked_view =
318 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, 327 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this,
319 bubble_font, bubble_font_y_offset, 328 bubble_font_list.GetPrimaryFont(),
320 text_color, background_color); 329 bubble_font_y_offset, text_color,
330 background_color);
321 content_setting_views_.push_back(content_blocked_view); 331 content_setting_views_.push_back(content_blocked_view);
322 content_blocked_view->SetVisible(false); 332 content_blocked_view->SetVisible(false);
323 AddChildView(content_blocked_view); 333 AddChildView(content_blocked_view);
324 } 334 }
325 335
326 autofill_credit_card_view_ = new AutofillCreditCardView(model_, delegate_); 336 autofill_credit_card_view_ = new AutofillCreditCardView(model_, delegate_);
327 AddChildView(autofill_credit_card_view_); 337 AddChildView(autofill_credit_card_view_);
328 338
329 zoom_view_ = new ZoomView(model_, delegate_); 339 zoom_view_ = new ZoomView(model_, delegate_);
330 zoom_view_->set_id(VIEW_ID_ZOOM_BUTTON); 340 zoom_view_->set_id(VIEW_ID_ZOOM_BUTTON);
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 int LocationBarView::GetInternalHeight(bool use_preferred_size) { 1511 int LocationBarView::GetInternalHeight(bool use_preferred_size) {
1502 int total_height = 1512 int total_height =
1503 use_preferred_size ? GetPreferredSize().height() : height(); 1513 use_preferred_size ? GetPreferredSize().height() : height();
1504 return std::max(total_height - (vertical_edge_thickness() * 2), 0); 1514 return std::max(total_height - (vertical_edge_thickness() * 2), 0);
1505 } 1515 }
1506 1516
1507 bool LocationBarView::HasValidSuggestText() const { 1517 bool LocationBarView::HasValidSuggestText() const {
1508 return suggested_text_view_->visible() && 1518 return suggested_text_view_->visible() &&
1509 !suggested_text_view_->size().IsEmpty(); 1519 !suggested_text_view_->size().IsEmpty();
1510 } 1520 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h » ('j') | ui/gfx/render_text.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698