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

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: nits part 2 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/profiles/new_avatar_button.cc » ('j') | 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/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/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 namespace { 103 namespace {
104 104
105 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN; 105 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN;
106 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN; 106 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN;
107 107
108 // The search button images are made to look as if they overlay the normal edge 108 // The search button images are made to look as if they overlay the normal edge
109 // images, but to align things, the search button needs to be inset horizontally 109 // images, but to align things, the search button needs to be inset horizontally
110 // by 1 px. 110 // by 1 px.
111 const int kSearchButtonInset = 1; 111 const int kSearchButtonInset = 1;
112 112
113 // Given a containing |height| and a |base_font_list|, shrinks the font size
114 // until the font list will fit within |height| while having its cap height
115 // vertically centered. Returns the correctly-sized font list.
116 //
117 // The expected layout:
118 // +--------+-----------------------------------------------+------------+
119 // | | y offset | space |
120 // | +--------+-------------------+------------------+ above |
121 // | | | | internal leading | cap height |
122 // | box | font | ascent (baseline) +------------------+------------+
123 // | height | height | | cap height |
124 // | | |-------------------+------------------+------------+
125 // | | | descent (height - baseline) | space |
126 // | +--------+--------------------------------------+ below |
127 // | | space at bottom | cap height |
128 // +--------+-----------------------------------------------+------------+
129 // Goal:
130 // center of box height == center of cap height
131 // (i.e. space above cap height == space below cap height)
132 // Restrictions:
133 // y offset >= 0
134 // space at bottom >= 0
135 // (i.e. Entire font must be visible inside the box.)
136 gfx::FontList GetLargestFontListWithHeightBound(
137 const gfx::FontList& base_font_list,
138 int height) {
139 gfx::FontList font_list = base_font_list;
140 for (int font_size = font_list.GetFontSize(); font_size > 1; --font_size) {
141 const int internal_leading =
142 font_list.GetBaseline() - font_list.GetCapHeight();
143 // Some platforms don't support getting the cap height, and simply return
144 // the entire font ascent from GetCapHeight(). Centering the ascent makes
145 // the font look too low, so if GetCapHeight() returns the ascent, center
146 // the entire font height instead.
147 const int space =
148 height - ((internal_leading != 0) ?
149 font_list.GetCapHeight() : font_list.GetHeight());
150 const int y_offset = space / 2 - internal_leading;
151 const int space_at_bottom = height - (y_offset + font_list.GetHeight());
152 if ((y_offset >= 0) && (space_at_bottom >= 0))
153 break;
154 font_list = font_list.DeriveWithSizeDelta(-1);
155 }
156 return font_list;
157 }
158
159 int GetEditLeadingInternalSpace() { 113 int GetEditLeadingInternalSpace() {
160 // The textfield has 1 px of whitespace before the text in the RTL case only. 114 // The textfield has 1 px of whitespace before the text in the RTL case only.
161 return base::i18n::IsRTL() ? 1 : 0; 115 return base::i18n::IsRTL() ? 1 : 0;
162 } 116 }
163 117
164 // Functor for moving BookmarkManagerPrivate page actions to the right via 118 // Functor for moving BookmarkManagerPrivate page actions to the right via
165 // stable_partition. 119 // stable_partition.
166 class IsPageActionViewRightAligned { 120 class IsPageActionViewRightAligned {
167 public: 121 public:
168 explicit IsPageActionViewRightAligned( 122 explicit IsPageActionViewRightAligned(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 ResourceBundle::BaseFont); 224 ResourceBundle::BaseFont);
271 const int current_font_size = font_list.GetFontSize(); 225 const int current_font_size = font_list.GetFontSize();
272 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize; 226 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize;
273 if (current_font_size != desired_font_size) { 227 if (current_font_size != desired_font_size) {
274 font_list = 228 font_list =
275 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); 229 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size);
276 } 230 }
277 // Shrink large fonts to make them fit. 231 // Shrink large fonts to make them fit.
278 // TODO(pkasting): Stretch the location bar instead in this case. 232 // TODO(pkasting): Stretch the location bar instead in this case.
279 const int location_height = GetInternalHeight(true); 233 const int location_height = GetInternalHeight(true);
280 font_list = GetLargestFontListWithHeightBound(font_list, location_height); 234 font_list = font_list.DeriveWithHeightUpperBound(location_height);
281 235
282 // Determine the font for use inside the bubbles. The bubble background 236 // Determine the font for use inside the bubbles. The bubble background
283 // images have 1 px thick edges, which we don't want to overlap. 237 // images have 1 px thick edges, which we don't want to overlap.
284 const int kBubbleInteriorVerticalPadding = 1; 238 const int kBubbleInteriorVerticalPadding = 1;
285 const int bubble_vertical_padding = 239 const int bubble_vertical_padding =
286 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2; 240 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2;
287 const gfx::FontList bubble_font_list( 241 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound(
288 GetLargestFontListWithHeightBound( 242 location_height - bubble_vertical_padding));
289 font_list, location_height - bubble_vertical_padding));
290 243
291 const SkColor background_color = 244 const SkColor background_color =
292 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); 245 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND);
293 ev_bubble_view_ = new EVBubbleView( 246 ev_bubble_view_ = new EVBubbleView(
294 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), 247 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT),
295 background_color, this); 248 background_color, this);
296 ev_bubble_view_->set_drag_controller(this); 249 ev_bubble_view_->set_drag_controller(this);
297 AddChildView(ev_bubble_view_); 250 AddChildView(ev_bubble_view_);
298 251
299 // Initialize the Omnibox view. 252 // Initialize the Omnibox view.
(...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 1652
1700 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1653 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1701 const SearchModel::State& new_state) { 1654 const SearchModel::State& new_state) {
1702 const bool visible = !GetToolbarModel()->input_in_progress() && 1655 const bool visible = !GetToolbarModel()->input_in_progress() &&
1703 new_state.voice_search_supported; 1656 new_state.voice_search_supported;
1704 if (mic_search_view_->visible() != visible) { 1657 if (mic_search_view_->visible() != visible) {
1705 mic_search_view_->SetVisible(visible); 1658 mic_search_view_->SetVisible(visible);
1706 Layout(); 1659 Layout();
1707 } 1660 }
1708 } 1661 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/profiles/new_avatar_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698