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

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

Issue 470053004: [Win, Linux] Always display the avatar button text at the same size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: maybe made test better? Created 6 years, 3 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 namespace { 106 namespace {
107 107
108 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN; 108 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN;
109 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN; 109 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN;
110 110
111 // The search button images are made to look as if they overlay the normal edge 111 // The search button images are made to look as if they overlay the normal edge
112 // images, but to align things, the search button needs to be inset horizontally 112 // images, but to align things, the search button needs to be inset horizontally
113 // by 1 px. 113 // by 1 px.
114 const int kSearchButtonInset = 1; 114 const int kSearchButtonInset = 1;
115 115
116 // Given a containing |height| and a |base_font_list|, shrinks the font size
117 // until the font list will fit within |height| while having its cap height
118 // vertically centered. Returns the correctly-sized font list.
119 //
120 // The expected layout:
121 // +--------+-----------------------------------------------+------------+
122 // | | y offset | space |
123 // | +--------+-------------------+------------------+ above |
124 // | | | | internal leading | cap height |
125 // | box | font | ascent (baseline) +------------------+------------+
126 // | height | height | | cap height |
127 // | | |-------------------+------------------+------------+
128 // | | | descent (height - baseline) | space |
129 // | +--------+--------------------------------------+ below |
130 // | | space at bottom | cap height |
131 // +--------+-----------------------------------------------+------------+
132 // Goal:
133 // center of box height == center of cap height
134 // (i.e. space above cap height == space below cap height)
135 // Restrictions:
136 // y offset >= 0
137 // space at bottom >= 0
138 // (i.e. Entire font must be visible inside the box.)
139 gfx::FontList GetLargestFontListWithHeightBound(
140 const gfx::FontList& base_font_list,
141 int height) {
142 gfx::FontList font_list = base_font_list;
143 for (int font_size = font_list.GetFontSize(); font_size > 1; --font_size) {
144 const int internal_leading =
145 font_list.GetBaseline() - font_list.GetCapHeight();
146 // Some platforms don't support getting the cap height, and simply return
147 // the entire font ascent from GetCapHeight(). Centering the ascent makes
148 // the font look too low, so if GetCapHeight() returns the ascent, center
149 // the entire font height instead.
150 const int space =
151 height - ((internal_leading != 0) ?
152 font_list.GetCapHeight() : font_list.GetHeight());
153 const int y_offset = space / 2 - internal_leading;
154 const int space_at_bottom = height - (y_offset + font_list.GetHeight());
155 if ((y_offset >= 0) && (space_at_bottom >= 0))
156 break;
157 font_list = font_list.DeriveWithSizeDelta(-1);
158 }
159 return font_list;
160 }
161
162 int GetEditLeadingInternalSpace() { 116 int GetEditLeadingInternalSpace() {
163 // The textfield has 1 px of whitespace before the text in the RTL case only. 117 // The textfield has 1 px of whitespace before the text in the RTL case only.
164 return base::i18n::IsRTL() ? 1 : 0; 118 return base::i18n::IsRTL() ? 1 : 0;
165 } 119 }
166 120
167 // Functor for moving BookmarkManagerPrivate page actions to the right via 121 // Functor for moving BookmarkManagerPrivate page actions to the right via
168 // stable_partition. 122 // stable_partition.
169 class IsPageActionViewRightAligned { 123 class IsPageActionViewRightAligned {
170 public: 124 public:
171 explicit IsPageActionViewRightAligned( 125 explicit IsPageActionViewRightAligned(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 ResourceBundle::BaseFont); 228 ResourceBundle::BaseFont);
275 const int current_font_size = font_list.GetFontSize(); 229 const int current_font_size = font_list.GetFontSize();
276 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize; 230 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize;
277 if (current_font_size != desired_font_size) { 231 if (current_font_size != desired_font_size) {
278 font_list = 232 font_list =
279 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); 233 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size);
280 } 234 }
281 // Shrink large fonts to make them fit. 235 // Shrink large fonts to make them fit.
282 // TODO(pkasting): Stretch the location bar instead in this case. 236 // TODO(pkasting): Stretch the location bar instead in this case.
283 const int location_height = GetInternalHeight(true); 237 const int location_height = GetInternalHeight(true);
284 font_list = GetLargestFontListWithHeightBound(font_list, location_height); 238 font_list = font_list.DeriveWithHeightUpperBound(location_height);
285 239
286 // Determine the font for use inside the bubbles. The bubble background 240 // Determine the font for use inside the bubbles. The bubble background
287 // images have 1 px thick edges, which we don't want to overlap. 241 // images have 1 px thick edges, which we don't want to overlap.
288 const int kBubbleInteriorVerticalPadding = 1; 242 const int kBubbleInteriorVerticalPadding = 1;
289 const int bubble_vertical_padding = 243 const int bubble_vertical_padding =
290 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2; 244 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2;
291 const gfx::FontList bubble_font_list( 245 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound(
292 GetLargestFontListWithHeightBound( 246 location_height - bubble_vertical_padding));
293 font_list, location_height - bubble_vertical_padding));
294 247
295 const SkColor background_color = 248 const SkColor background_color =
296 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); 249 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND);
297 ev_bubble_view_ = new EVBubbleView( 250 ev_bubble_view_ = new EVBubbleView(
298 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), 251 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT),
299 background_color, this); 252 background_color, this);
300 ev_bubble_view_->set_drag_controller(this); 253 ev_bubble_view_->set_drag_controller(this);
301 AddChildView(ev_bubble_view_); 254 AddChildView(ev_bubble_view_);
302 255
303 // Initialize the Omnibox view. 256 // Initialize the Omnibox view.
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 1715
1763 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1716 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1764 const SearchModel::State& new_state) { 1717 const SearchModel::State& new_state) {
1765 const bool visible = !GetToolbarModel()->input_in_progress() && 1718 const bool visible = !GetToolbarModel()->input_in_progress() &&
1766 new_state.voice_search_supported; 1719 new_state.voice_search_supported;
1767 if (mic_search_view_->visible() != visible) { 1720 if (mic_search_view_->visible() != visible) {
1768 mic_search_view_->SetVisible(visible); 1721 mic_search_view_->SetVisible(visible);
1769 Layout(); 1722 Layout();
1770 } 1723 }
1771 } 1724 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/profiles/new_avatar_button.cc » ('j') | ui/gfx/font_list.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698