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

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: Removes ResourceBundle::Delegate::GetFontList. Created 7 years, 4 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 // the primary font will fit within |height| while having its cap height
119 // the |font_y_offset| needed to produce this centering. 119 // vertically centered. Returns the |font_y_offset| needed to produce this
120 // centering.
120 void CalculateFontAndOffsetForHeight(int height, 121 void CalculateFontAndOffsetForHeight(int height,
121 gfx::Font* font, 122 gfx::FontList* font_list,
122 int* font_y_offset) { 123 int* font_y_offset) {
123 #if defined(OS_WIN) 124 #if defined(OS_WIN)
124 base::win::ScopedGetDC screen_dc(NULL); 125 base::win::ScopedGetDC screen_dc(NULL);
125 #endif 126 #endif
126 127
127 while (true) { 128 while (true) {
128 // TODO(pkasting): Expand the gfx::Font metrics (and underlying Skia 129 // TODO(pkasting): Expand the gfx::Font metrics (and underlying Skia
129 // metrics) enough to expose the cap height directly. 130 // metrics) enough to expose the cap height directly.
130 #if defined(OS_WIN) 131 #if defined(OS_WIN)
131 base::win::ScopedSelectObject font_in_dc(screen_dc, font->GetNativeFont()); 132 const gfx::Font& font = font_list->GetPrimaryFont();
133 base::win::ScopedSelectObject font_in_dc(screen_dc, font.GetNativeFont());
132 TEXTMETRIC tm = {0}; 134 TEXTMETRIC tm = {0};
133 GetTextMetrics(screen_dc, &tm); 135 GetTextMetrics(screen_dc, &tm);
134 int cap_height = font->GetBaseline() - tm.tmInternalLeading; 136 int cap_height = font.GetBaseline() - tm.tmInternalLeading;
135 *font_y_offset = ((height - cap_height) / 2) - tm.tmInternalLeading; 137 *font_y_offset = ((height - cap_height) / 2) - tm.tmInternalLeading;
136 #else 138 #else
137 // Without cap height available, we fall back to centering the full height. 139 // Without cap height available, we fall back to centering the full height.
138 *font_y_offset = (height - font->GetHeight()) / 2; 140 *font_y_offset = (height - font_list->GetHeight()) / 2;
139 #endif 141 #endif
140 142
143 const int font_size = font_list->GetFontSize();
141 if (((*font_y_offset >= 0) && 144 if (((*font_y_offset >= 0) &&
142 ((*font_y_offset + font->GetHeight()) <= height)) || 145 ((*font_y_offset + font_list->GetHeight()) <= height)) ||
143 (font->GetFontSize() <= 1)) 146 (font_size <= 1))
144 return; 147 return;
145 *font = font->DeriveFont(-1); 148 *font_list = font_list->DeriveFontListWithSize(font_size - 1);
146 } 149 }
147 } 150 }
148 151
149 } // namespace 152 } // namespace
150 153
151 154
152 // LocationBarView ----------------------------------------------------------- 155 // LocationBarView -----------------------------------------------------------
153 156
154 // static 157 // static
155 const int LocationBarView::kNormalEdgeThickness = 2; 158 const int LocationBarView::kNormalEdgeThickness = 2;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void LocationBarView::Init() { 230 void LocationBarView::Init() {
228 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're 231 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're
229 // not prepared for that. 232 // not prepared for that.
230 DCHECK(GetWidget()); 233 DCHECK(GetWidget());
231 234
232 location_icon_view_ = new LocationIconView(this); 235 location_icon_view_ = new LocationIconView(this);
233 location_icon_view_->set_drag_controller(this); 236 location_icon_view_->set_drag_controller(this);
234 AddChildView(location_icon_view_); 237 AddChildView(location_icon_view_);
235 238
236 // Determine the main font. 239 // Determine the main font.
237 gfx::Font font(ui::ResourceBundle::GetSharedInstance().GetFont( 240 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList(
238 ui::ResourceBundle::BaseFont)); 241 ResourceBundle::BaseFont);
239 const int current_font_size = font.GetFontSize(); 242 const int current_font_size = font_list.GetFontSize();
240 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize; 243 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize;
241 if (current_font_size < desired_font_size) 244 if (current_font_size < desired_font_size)
242 font = font.DeriveFont(desired_font_size - current_font_size); 245 font_list = font_list.DeriveFontListWithSize(desired_font_size);
243 // Shrink large fonts to make them fit. 246 // Shrink large fonts to make them fit.
244 // TODO(pkasting): Stretch the location bar instead in this case. 247 // TODO(pkasting): Stretch the location bar instead in this case.
245 int location_height = GetInternalHeight(true); 248 int location_height = GetInternalHeight(true);
246 int font_y_offset; 249 int font_y_offset;
247 CalculateFontAndOffsetForHeight(location_height, &font, &font_y_offset); 250 CalculateFontAndOffsetForHeight(location_height, &font_list, &font_y_offset);
251 const gfx::Font& font = font_list.GetPrimaryFont();
248 252
249 // Determine the font for use inside the bubbles. 253 // Determine the font for use inside the bubbles.
250 gfx::Font bubble_font(font); 254 gfx::FontList bubble_font_list(font_list);
251 int bubble_font_y_offset; 255 int bubble_font_y_offset;
252 // The bubble background images have 1 px thick edges, which we don't want to 256 // The bubble background images have 1 px thick edges, which we don't want to
253 // overlap. 257 // overlap.
254 const int kBubbleInteriorVerticalPadding = 1; 258 const int kBubbleInteriorVerticalPadding = 1;
255 CalculateFontAndOffsetForHeight( 259 CalculateFontAndOffsetForHeight(
256 location_height - ((kBubblePadding + kBubbleInteriorVerticalPadding) * 2), 260 location_height - ((kBubblePadding + kBubbleInteriorVerticalPadding) * 2),
257 &bubble_font, &bubble_font_y_offset); 261 &bubble_font_list, &bubble_font_y_offset);
258 bubble_font_y_offset += kBubbleInteriorVerticalPadding; 262 bubble_font_y_offset += kBubbleInteriorVerticalPadding;
263 const gfx::Font& bubble_font = font_list.GetPrimaryFont();
259 264
260 const SkColor background_color = 265 const SkColor background_color =
261 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); 266 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND);
262 ev_bubble_view_ = new EVBubbleView( 267 ev_bubble_view_ = new EVBubbleView(
263 bubble_font, bubble_font_y_offset, 268 bubble_font, bubble_font_y_offset,
264 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), background_color, this); 269 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), background_color, this);
265 ev_bubble_view_->set_drag_controller(this); 270 ev_bubble_view_->set_drag_controller(this);
266 AddChildView(ev_bubble_view_); 271 AddChildView(ev_bubble_view_);
267 272
268 // Initialize the Omnibox view. 273 // Initialize the Omnibox view.
269 location_entry_.reset(CreateOmniboxView(this, model_, profile_, 274 location_entry_.reset(CreateOmniboxView(this, model_, profile_,
270 command_updater_, is_popup_mode_, this, font, font_y_offset)); 275 command_updater_, is_popup_mode_, this, font_list, font_y_offset));
271 SetLocationEntryFocusable(true); 276 SetLocationEntryFocusable(true);
272 location_entry_view_ = location_entry_->AddToView(this); 277 location_entry_view_ = location_entry_->AddToView(this);
273 278
274 // Initialize the inline autocomplete view which is visible only when IME is 279 // 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. 280 // turned on. Use the same font with the omnibox and highlighted background.
276 ime_inline_autocomplete_view_ = new views::Label(string16(), font); 281 ime_inline_autocomplete_view_ = new views::Label(string16(), font);
277 ime_inline_autocomplete_view_->set_border( 282 ime_inline_autocomplete_view_->set_border(
278 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); 283 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0));
279 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 284 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
280 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 285 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 int LocationBarView::GetInternalHeight(bool use_preferred_size) { 1506 int LocationBarView::GetInternalHeight(bool use_preferred_size) {
1502 int total_height = 1507 int total_height =
1503 use_preferred_size ? GetPreferredSize().height() : height(); 1508 use_preferred_size ? GetPreferredSize().height() : height();
1504 return std::max(total_height - (vertical_edge_thickness() * 2), 0); 1509 return std::max(total_height - (vertical_edge_thickness() * 2), 0);
1505 } 1510 }
1506 1511
1507 bool LocationBarView::HasValidSuggestText() const { 1512 bool LocationBarView::HasValidSuggestText() const {
1508 return suggested_text_view_->visible() && 1513 return suggested_text_view_->visible() &&
1509 !suggested_text_view_->size().IsEmpty(); 1514 !suggested_text_view_->size().IsEmpty();
1510 } 1515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698