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

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

Issue 2642893002: Adjust positioning of location bar icons. (Closed)
Patch Set: nits Created 3 years, 11 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
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 // Compute width of omnibox-leading content. 455 // Compute width of omnibox-leading content.
456 const int edge_thickness = GetHorizontalEdgeThickness(); 456 const int edge_thickness = GetHorizontalEdgeThickness();
457 int leading_width = edge_thickness; 457 int leading_width = edge_thickness;
458 if (ShouldShowKeywordBubble()) { 458 if (ShouldShowKeywordBubble()) {
459 // The selected keyword view can collapse completely. 459 // The selected keyword view can collapse completely.
460 } else if (ShouldShowLocationIconText()) { 460 } else if (ShouldShowLocationIconText()) {
461 leading_width += 461 leading_width +=
462 location_icon_view_->GetMinimumSizeForLabelText(GetLocationIconText()) 462 location_icon_view_->GetMinimumSizeForLabelText(GetLocationIconText())
463 .width(); 463 .width();
464 } else { 464 } else {
465 leading_width += 465 leading_width += GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) +
466 kHorizontalPadding + location_icon_view_->GetMinimumSize().width(); 466 location_icon_view_->GetMinimumSize().width();
467 } 467 }
468 468
469 // Compute width of omnibox-trailing content. 469 // Compute width of omnibox-trailing content.
470 int trailing_width = edge_thickness; 470 int trailing_width = edge_thickness;
471 trailing_width += IncrementalMinimumWidth(star_view_) + 471 trailing_width += IncrementalMinimumWidth(star_view_) +
472 IncrementalMinimumWidth(translate_icon_view_) + 472 IncrementalMinimumWidth(translate_icon_view_) +
473 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 473 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
474 IncrementalMinimumWidth(save_credit_card_icon_view_) + 474 IncrementalMinimumWidth(save_credit_card_icon_view_) +
475 IncrementalMinimumWidth(manage_passwords_icon_view_) + 475 IncrementalMinimumWidth(manage_passwords_icon_view_) +
476 IncrementalMinimumWidth(zoom_view_); 476 IncrementalMinimumWidth(zoom_view_);
477 for (const auto& action_view : page_action_views_) 477 for (const auto& action_view : page_action_views_)
478 trailing_width += IncrementalMinimumWidth(action_view.get()); 478 trailing_width += IncrementalMinimumWidth(action_view.get());
479 for (auto i = content_setting_views_.begin(); 479 for (auto i = content_setting_views_.begin();
480 i != content_setting_views_.end(); ++i) { 480 i != content_setting_views_.end(); ++i) {
481 trailing_width += IncrementalMinimumWidth((*i)); 481 trailing_width += IncrementalMinimumWidth((*i));
482 } 482 }
483 483
484 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + 484 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() +
485 2 * kHorizontalPadding - 485 2 * GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) -
486 omnibox_view_->GetInsets().width() + trailing_width); 486 omnibox_view_->GetInsets().width() + trailing_width);
487 return min_size; 487 return min_size;
488 } 488 }
489 489
490 void LocationBarView::Layout() { 490 void LocationBarView::Layout() {
491 if (!IsInitialized()) 491 if (!IsInitialized())
492 return; 492 return;
493 493
494 selected_keyword_view_->SetVisible(false); 494 selected_keyword_view_->SetVisible(false);
495 location_icon_view_->SetVisible(false); 495 location_icon_view_->SetVisible(false);
496 keyword_hint_view_->SetVisible(false); 496 keyword_hint_view_->SetVisible(false);
497 497
498 constexpr int item_padding = kHorizontalPadding; 498 const int item_padding = GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING);
499 499
500 LocationBarLayout leading_decorations( 500 LocationBarLayout leading_decorations(
501 LocationBarLayout::LEFT_EDGE, item_padding, 501 LocationBarLayout::LEFT_EDGE, item_padding,
502 item_padding - omnibox_view_->GetInsets().left()); 502 item_padding - omnibox_view_->GetInsets().left());
503 LocationBarLayout trailing_decorations( 503 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE,
504 LocationBarLayout::RIGHT_EDGE, item_padding, 504 item_padding, item_padding);
505 item_padding - omnibox_view_->GetInsets().right());
506 505
507 const base::string16 keyword(omnibox_view_->model()->keyword()); 506 const base::string16 keyword(omnibox_view_->model()->keyword());
508 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 507 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
509 // to position our child views in this case, because other things may be 508 // to position our child views in this case, because other things may be
510 // positioned relative to them (e.g. the "bookmark added" bubble if the user 509 // positioned relative to them (e.g. the "bookmark added" bubble if the user
511 // hits ctrl-d). 510 // hits ctrl-d).
512 const int vertical_padding = GetTotalVerticalPadding(); 511 const int vertical_padding = GetTotalVerticalPadding();
513 const int location_height = std::max(height() - (vertical_padding * 2), 0); 512 const int location_height = std::max(height() - (vertical_padding * 2), 0);
514 513
515 location_icon_view_->SetLabel(base::string16()); 514 location_icon_view_->SetLabel(base::string16());
516 if (ShouldShowKeywordBubble()) { 515 if (ShouldShowKeywordBubble()) {
517 leading_decorations.AddDecoration(vertical_padding, location_height, true, 516 leading_decorations.AddDecoration(vertical_padding, location_height, true,
518 0, 0, item_padding, 517 0, item_padding, item_padding,
519 selected_keyword_view_); 518 selected_keyword_view_);
520 if (selected_keyword_view_->keyword() != keyword) { 519 if (selected_keyword_view_->keyword() != keyword) {
521 selected_keyword_view_->SetKeyword(keyword); 520 selected_keyword_view_->SetKeyword(keyword);
522 const TemplateURL* template_url = 521 const TemplateURL* template_url =
523 TemplateURLServiceFactory::GetForProfile(profile())-> 522 TemplateURLServiceFactory::GetForProfile(profile())->
524 GetTemplateURLForKeyword(keyword); 523 GetTemplateURLForKeyword(keyword);
525 if (template_url && 524 if (template_url &&
526 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { 525 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) {
527 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 526 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
528 GetOmniboxIcon(template_url->GetExtensionId()); 527 GetOmniboxIcon(template_url->GetExtensionId());
529 selected_keyword_view_->SetImage(image.AsImageSkia()); 528 selected_keyword_view_->SetImage(image.AsImageSkia());
530 } else { 529 } else {
531 selected_keyword_view_->ResetImage(); 530 selected_keyword_view_->ResetImage();
532 } 531 }
533 } 532 }
534 } else if (ShouldShowLocationIconText()) { 533 } else if (ShouldShowLocationIconText()) {
535 location_icon_view_->SetLabel(GetLocationIconText()); 534 location_icon_view_->SetLabel(GetLocationIconText());
536 // The largest fraction of the omnibox that can be taken by the EV bubble. 535 // The largest fraction of the omnibox that can be taken by the EV bubble.
537 const double kMaxBubbleFraction = 0.5; 536 const double kMaxBubbleFraction = 0.5;
538 leading_decorations.AddDecoration(vertical_padding, location_height, false, 537 leading_decorations.AddDecoration(vertical_padding, location_height, false,
539 kMaxBubbleFraction, 0, item_padding, 538 kMaxBubbleFraction, item_padding,
540 location_icon_view_); 539 item_padding, location_icon_view_);
541 } else { 540 } else {
542 leading_decorations.AddDecoration(vertical_padding, location_height, 541 leading_decorations.AddDecoration(vertical_padding, location_height,
543 location_icon_view_); 542 location_icon_view_);
544 } 543 }
545 544
546 if (star_view_->visible()) { 545 if (star_view_->visible()) {
547 trailing_decorations.AddDecoration(vertical_padding, location_height, 546 trailing_decorations.AddDecoration(vertical_padding, location_height,
548 star_view_); 547 star_view_);
549 } 548 }
550 if (translate_icon_view_->visible()) { 549 if (translate_icon_view_->visible()) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 683 }
685 684
686 WebContents* LocationBarView::GetWebContents() { 685 WebContents* LocationBarView::GetWebContents() {
687 return delegate_->GetWebContents(); 686 return delegate_->GetWebContents();
688 } 687 }
689 688
690 //////////////////////////////////////////////////////////////////////////////// 689 ////////////////////////////////////////////////////////////////////////////////
691 // LocationBarView, private: 690 // LocationBarView, private:
692 691
693 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { 692 int LocationBarView::IncrementalMinimumWidth(views::View* view) const {
694 return view->visible() ? (kHorizontalPadding + view->GetMinimumSize().width()) 693 return view->visible() ? (GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) +
694 view->GetMinimumSize().width())
695 : 0; 695 : 0;
696 } 696 }
697 697
698 int LocationBarView::GetHorizontalEdgeThickness() const { 698 int LocationBarView::GetHorizontalEdgeThickness() const {
699 return is_popup_mode_ 699 return is_popup_mode_
700 ? 0 700 ? 0
701 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip; 701 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip;
702 } 702 }
703 703
704 int LocationBarView::GetTotalVerticalPadding() const { 704 int LocationBarView::GetTotalVerticalPadding() const {
705 constexpr int kInteriorPadding = 1;
706 return BackgroundWith1PxBorder::kLocationBarBorderThicknessDip + 705 return BackgroundWith1PxBorder::kLocationBarBorderThicknessDip +
707 kInteriorPadding; 706 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING);
708 } 707 }
709 708
710 void LocationBarView::RefreshLocationIcon() { 709 void LocationBarView::RefreshLocationIcon() {
711 // |omnibox_view_| may not be ready yet if Init() has not been called. The 710 // |omnibox_view_| may not be ready yet if Init() has not been called. The
712 // icon will be set soon by OnChanged(). 711 // icon will be set soon by OnChanged().
713 if (!omnibox_view_) 712 if (!omnibox_view_)
714 return; 713 return;
715 714
716 security_state::SecurityLevel security_level = 715 security_state::SecurityLevel security_level =
717 GetToolbarModel()->GetSecurityLevel(false); 716 GetToolbarModel()->GetSecurityLevel(false);
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 // LocationBarView, private TemplateURLServiceObserver implementation: 1230 // LocationBarView, private TemplateURLServiceObserver implementation:
1232 1231
1233 void LocationBarView::OnTemplateURLServiceChanged() { 1232 void LocationBarView::OnTemplateURLServiceChanged() {
1234 template_url_service_->RemoveObserver(this); 1233 template_url_service_->RemoveObserver(this);
1235 template_url_service_ = nullptr; 1234 template_url_service_ = nullptr;
1236 // If the browser is no longer active, let's not show the info bubble, as this 1235 // If the browser is no longer active, let's not show the info bubble, as this
1237 // would make the browser the active window again. 1236 // would make the browser the active window again.
1238 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1237 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1239 ShowFirstRunBubble(); 1238 ShowFirstRunBubble();
1240 } 1239 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_result_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698