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

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

Issue 2555623002: Last round of cleaning up MD layout constants. (Closed)
Patch Set: pkasting review, remove debug code, rebase Created 4 years 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
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 213
214 // Make sure children with layers are clipped. See http://crbug.com/589497 214 // Make sure children with layers are clipped. See http://crbug.com/589497
215 SetPaintToLayer(true); 215 SetPaintToLayer(true);
216 layer()->SetFillsBoundsOpaquely(false); 216 layer()->SetFillsBoundsOpaquely(false);
217 layer()->SetMasksToBounds(true); 217 layer()->SetMasksToBounds(true);
218 218
219 // Determine the main font. 219 // Determine the main font.
220 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( 220 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList(
221 ResourceBundle::BaseFont); 221 ResourceBundle::BaseFont);
222 const int current_font_size = font_list.GetFontSize(); 222 const int current_font_size = font_list.GetFontSize();
223 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); 223 constexpr int kDesiredFontSize = 14;
224 if (current_font_size != desired_font_size) { 224 if (current_font_size != kDesiredFontSize) {
225 font_list = 225 font_list =
226 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); 226 font_list.DeriveWithSizeDelta(kDesiredFontSize - current_font_size);
227 } 227 }
228 // Shrink large fonts to make them fit. 228 // Shrink large fonts to make them fit.
229 // TODO(pkasting): Stretch the location bar instead in this case. 229 // TODO(pkasting): Stretch the location bar instead in this case.
230 const int vertical_padding = GetTotalVerticalPadding(); 230 const int vertical_padding = GetTotalVerticalPadding();
231 const int location_height = 231 const int location_height =
232 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); 232 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0);
233 font_list = font_list.DeriveWithHeightUpperBound(location_height); 233 font_list = font_list.DeriveWithHeightUpperBound(location_height);
234 234
235 // Determine the font for use inside the bubbles. 235 // Determine the font for use inside the bubbles.
236 const int bubble_padding = 236 const int bubble_padding =
237 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + 237 kBubbleVerticalPadding +
238 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); 238 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING);
239 const int bubble_height = location_height - (bubble_padding * 2); 239 const int bubble_height = location_height - (bubble_padding * 2);
240 240
241 const SkColor background_color = GetColor(BACKGROUND); 241 const SkColor background_color = GetColor(BACKGROUND);
242 location_icon_view_ = new LocationIconView(font_list, this); 242 location_icon_view_ = new LocationIconView(font_list, this);
243 location_icon_view_->set_drag_controller(this); 243 location_icon_view_->set_drag_controller(this);
244 AddChildView(location_icon_view_); 244 AddChildView(location_icon_view_);
245 245
246 // Initialize the Omnibox view. 246 // Initialize the Omnibox view.
247 omnibox_view_ = new OmniboxViewViews( 247 omnibox_view_ = new OmniboxViewViews(
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 483
484 gfx::Size LocationBarView::GetPreferredSize() const { 484 gfx::Size LocationBarView::GetPreferredSize() const {
485 // Compute minimum height. 485 // Compute minimum height.
486 gfx::Size min_size(0, GetLayoutConstant(LOCATION_BAR_HEIGHT)); 486 gfx::Size min_size(0, GetLayoutConstant(LOCATION_BAR_HEIGHT));
487 487
488 if (!IsInitialized()) 488 if (!IsInitialized())
489 return min_size; 489 return min_size;
490 490
491 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 491 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
492 492
493 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
494
495 // Compute width of omnibox-leading content. 493 // Compute width of omnibox-leading content.
496 const int edge_thickness = GetHorizontalEdgeThickness(); 494 const int edge_thickness = GetHorizontalEdgeThickness();
497 int leading_width = edge_thickness; 495 int leading_width = edge_thickness;
498 if (ShouldShowKeywordBubble()) { 496 if (ShouldShowKeywordBubble()) {
499 // The selected keyword view can collapse completely. 497 // The selected keyword view can collapse completely.
500 } else if (ShouldShowSecurityChip()) { 498 } else if (ShouldShowSecurityChip()) {
501 base::string16 security_text = GetSecurityText(); 499 base::string16 security_text = GetSecurityText();
502 leading_width += 500 leading_width +=
503 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); 501 location_icon_view_->GetMinimumSizeForLabelText(security_text).width();
504 } else { 502 } else {
505 leading_width += padding + location_icon_view_->GetMinimumSize().width(); 503 leading_width +=
504 kHorizontalPadding + location_icon_view_->GetMinimumSize().width();
506 } 505 }
507 506
508 // Compute width of omnibox-trailing content. 507 // Compute width of omnibox-trailing content.
509 int trailing_width = edge_thickness; 508 int trailing_width = edge_thickness;
510 trailing_width += IncrementalMinimumWidth(star_view_) + 509 trailing_width += IncrementalMinimumWidth(star_view_) +
511 IncrementalMinimumWidth(translate_icon_view_) + 510 IncrementalMinimumWidth(translate_icon_view_) +
512 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 511 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
513 IncrementalMinimumWidth(save_credit_card_icon_view_) + 512 IncrementalMinimumWidth(save_credit_card_icon_view_) +
514 IncrementalMinimumWidth(manage_passwords_icon_view_) + 513 IncrementalMinimumWidth(manage_passwords_icon_view_) +
515 IncrementalMinimumWidth(zoom_view_); 514 IncrementalMinimumWidth(zoom_view_);
516 for (const auto& action_view : page_action_views_) 515 for (const auto& action_view : page_action_views_)
517 trailing_width += IncrementalMinimumWidth(action_view.get()); 516 trailing_width += IncrementalMinimumWidth(action_view.get());
518 for (auto i = content_setting_views_.begin(); 517 for (auto i = content_setting_views_.begin();
519 i != content_setting_views_.end(); ++i) { 518 i != content_setting_views_.end(); ++i) {
520 trailing_width += IncrementalMinimumWidth((*i)); 519 trailing_width += IncrementalMinimumWidth((*i));
521 } 520 }
522 521
523 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + 522 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() +
524 2 * padding - omnibox_view_->GetInsets().width() + 523 2 * kHorizontalPadding -
525 trailing_width); 524 omnibox_view_->GetInsets().width() + trailing_width);
526 return min_size; 525 return min_size;
527 } 526 }
528 527
529 void LocationBarView::Layout() { 528 void LocationBarView::Layout() {
530 if (!IsInitialized()) 529 if (!IsInitialized())
531 return; 530 return;
532 531
533 selected_keyword_view_->SetVisible(false); 532 selected_keyword_view_->SetVisible(false);
534 location_icon_view_->SetVisible(false); 533 location_icon_view_->SetVisible(false);
535 keyword_hint_view_->SetVisible(false); 534 keyword_hint_view_->SetVisible(false);
536 535
537 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 536 constexpr int item_padding = kHorizontalPadding;
538 const int edge_thickness = GetHorizontalEdgeThickness();
539 537
540 LocationBarLayout leading_decorations( 538 LocationBarLayout leading_decorations(
541 LocationBarLayout::LEFT_EDGE, item_padding, 539 LocationBarLayout::LEFT_EDGE, item_padding,
542 item_padding - omnibox_view_->GetInsets().left()); 540 item_padding - omnibox_view_->GetInsets().left());
543 LocationBarLayout trailing_decorations( 541 LocationBarLayout trailing_decorations(
544 LocationBarLayout::RIGHT_EDGE, item_padding, 542 LocationBarLayout::RIGHT_EDGE, item_padding,
545 item_padding - omnibox_view_->GetInsets().right()); 543 item_padding - omnibox_view_->GetInsets().right());
546 544
547 const base::string16 keyword(omnibox_view_->model()->keyword()); 545 const base::string16 keyword(omnibox_view_->model()->keyword());
548 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 546 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // IME composition is in progress. 624 // IME composition is in progress.
627 if (!keyword.empty() && omnibox_view_->model()->is_keyword_hint() && 625 if (!keyword.empty() && omnibox_view_->model()->is_keyword_hint() &&
628 !omnibox_view_->IsImeComposing()) { 626 !omnibox_view_->IsImeComposing()) {
629 trailing_decorations.AddDecoration(vertical_padding, location_height, true, 627 trailing_decorations.AddDecoration(vertical_padding, location_height, true,
630 0, item_padding, item_padding, 628 0, item_padding, item_padding,
631 keyword_hint_view_); 629 keyword_hint_view_);
632 if (keyword_hint_view_->keyword() != keyword) 630 if (keyword_hint_view_->keyword() != keyword)
633 keyword_hint_view_->SetKeyword(keyword); 631 keyword_hint_view_->SetKeyword(keyword);
634 } 632 }
635 633
634 const int edge_thickness = GetHorizontalEdgeThickness();
635
636 // Perform layout. 636 // Perform layout.
637 int full_width = width() - (2 * edge_thickness); 637 int full_width = width() - (2 * edge_thickness);
638 638
639 int entry_width = full_width; 639 int entry_width = full_width;
640 leading_decorations.LayoutPass1(&entry_width); 640 leading_decorations.LayoutPass1(&entry_width);
641 trailing_decorations.LayoutPass1(&entry_width); 641 trailing_decorations.LayoutPass1(&entry_width);
642 leading_decorations.LayoutPass2(&entry_width); 642 leading_decorations.LayoutPass2(&entry_width);
643 trailing_decorations.LayoutPass2(&entry_width); 643 trailing_decorations.LayoutPass2(&entry_width);
644 644
645 int location_needed_width = omnibox_view_->GetTextWidth(); 645 int location_needed_width = omnibox_view_->GetTextWidth();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 721 }
722 722
723 WebContents* LocationBarView::GetWebContents() { 723 WebContents* LocationBarView::GetWebContents() {
724 return delegate_->GetWebContents(); 724 return delegate_->GetWebContents();
725 } 725 }
726 726
727 //////////////////////////////////////////////////////////////////////////////// 727 ////////////////////////////////////////////////////////////////////////////////
728 // LocationBarView, private: 728 // LocationBarView, private:
729 729
730 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { 730 int LocationBarView::IncrementalMinimumWidth(views::View* view) const {
731 return view->visible() ? 731 return view->visible() ? (kHorizontalPadding + view->GetMinimumSize().width())
732 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + 732 : 0;
733 view->GetMinimumSize().width()) : 0;
734 } 733 }
735 734
736 int LocationBarView::GetHorizontalEdgeThickness() const { 735 int LocationBarView::GetHorizontalEdgeThickness() const {
737 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); 736 return is_popup_mode_
737 ? 0
738 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip;
738 } 739 }
739 740
740 int LocationBarView::GetTotalVerticalPadding() const { 741 int LocationBarView::GetTotalVerticalPadding() const {
741 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) + 742 constexpr int kInteriorPadding = 1;
742 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); 743 return BackgroundWith1PxBorder::kLocationBarBorderThicknessDip +
744 kInteriorPadding;
743 } 745 }
744 746
745 void LocationBarView::RefreshLocationIcon() { 747 void LocationBarView::RefreshLocationIcon() {
746 // |omnibox_view_| may not be ready yet if Init() has not been called. The 748 // |omnibox_view_| may not be ready yet if Init() has not been called. The
747 // icon will be set soon by OnChanged(). 749 // icon will be set soon by OnChanged().
748 if (!omnibox_view_) 750 if (!omnibox_view_)
749 return; 751 return;
750 752
751 security_state::SecurityLevel security_level = 753 security_state::SecurityLevel security_level =
752 GetToolbarModel()->GetSecurityLevel(false); 754 GetToolbarModel()->GetSecurityLevel(false);
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 canvas->DrawRoundRect(focus_rect, 1177 canvas->DrawRoundRect(focus_rect,
1176 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); 1178 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint);
1177 } 1179 }
1178 if (!is_popup_mode_) 1180 if (!is_popup_mode_)
1179 return; // The background and border are painted by our Background. 1181 return; // The background and border are painted by our Background.
1180 1182
1181 // Fill the location bar background color behind the border. Parts of the 1183 // Fill the location bar background color behind the border. Parts of the
1182 // border images are meant to rest atop the toolbar background and parts atop 1184 // border images are meant to rest atop the toolbar background and parts atop
1183 // the omnibox background, so we can't just blindly fill our entire bounds. 1185 // the omnibox background, so we can't just blindly fill our entire bounds.
1184 gfx::Rect bounds(GetContentsBounds()); 1186 gfx::Rect bounds(GetContentsBounds());
1185 bounds.Inset( 1187 bounds.Inset(GetHorizontalEdgeThickness(),
1186 GetHorizontalEdgeThickness(), 1188 is_popup_mode_
1187 is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS)); 1189 ? 0
1190 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip);
1188 SkColor background_color(GetColor(BACKGROUND)); 1191 SkColor background_color(GetColor(BACKGROUND));
1189 canvas->FillRect(bounds, background_color); 1192 canvas->FillRect(bounds, background_color);
1190 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); 1193 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord());
1191 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); 1194 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false);
1192 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); 1195 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true);
1193 } 1196 }
1194 1197
1195 //////////////////////////////////////////////////////////////////////////////// 1198 ////////////////////////////////////////////////////////////////////////////////
1196 // LocationBarView, private views::DragController implementation: 1199 // LocationBarView, private views::DragController implementation:
1197 1200
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 // LocationBarView, private TemplateURLServiceObserver implementation: 1264 // LocationBarView, private TemplateURLServiceObserver implementation:
1262 1265
1263 void LocationBarView::OnTemplateURLServiceChanged() { 1266 void LocationBarView::OnTemplateURLServiceChanged() {
1264 template_url_service_->RemoveObserver(this); 1267 template_url_service_->RemoveObserver(this);
1265 template_url_service_ = nullptr; 1268 template_url_service_ = nullptr;
1266 // If the browser is no longer active, let's not show the info bubble, as this 1269 // If the browser is no longer active, let's not show the info bubble, as this
1267 // would make the browser the active window again. 1270 // would make the browser the active window again.
1268 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1271 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1269 ShowFirstRunBubble(); 1272 ShowFirstRunBubble();
1270 } 1273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698