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

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

Issue 11418229: alternate ntp: implement right-aligned search token (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better commments Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | 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/command_line.h" 10 #include "base/command_line.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/search_engines/template_url.h" 24 #include "chrome/browser/search_engines/template_url.h"
25 #include "chrome/browser/search_engines/template_url_service.h" 25 #include "chrome/browser/search_engines/template_url_service.h"
26 #include "chrome/browser/search_engines/template_url_service_factory.h" 26 #include "chrome/browser/search_engines/template_url_service_factory.h"
27 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_tabstrip.h" 29 #include "chrome/browser/ui/browser_tabstrip.h"
30 #include "chrome/browser/ui/omnibox/location_bar_util.h" 30 #include "chrome/browser/ui/omnibox/location_bar_util.h"
31 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 31 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
32 #include "chrome/browser/ui/search/search.h"
32 #include "chrome/browser/ui/tab_contents/tab_contents.h" 33 #include "chrome/browser/ui/tab_contents/tab_contents.h"
33 #include "chrome/browser/ui/view_ids.h" 34 #include "chrome/browser/ui/view_ids.h"
34 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" 35 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h"
35 #include "chrome/browser/ui/views/browser_dialogs.h" 36 #include "chrome/browser/ui/views/browser_dialogs.h"
36 #include "chrome/browser/ui/views/extensions/extension_popup.h" 37 #include "chrome/browser/ui/views/extensions/extension_popup.h"
37 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" 38 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h"
38 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 39 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
39 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 40 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
40 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 41 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
41 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 42 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 const int kBubbleVerticalPadding = (mode_ == POPUP) ? 662 const int kBubbleVerticalPadding = (mode_ == POPUP) ?
662 -1 : kBubbleHorizontalPadding; 663 -1 : kBubbleHorizontalPadding;
663 664
664 // Start by reserving the padding at the right edge. 665 // Start by reserving the padding at the right edge.
665 int entry_width = width() - kEdgeThickness; 666 int entry_width = width() - kEdgeThickness;
666 // No need for edge item padding with action box as it fills 667 // No need for edge item padding with action box as it fills
667 // all the area on the right. 668 // all the area on the right.
668 if (!action_box_button_view_) 669 if (!action_box_button_view_)
669 entry_width -= GetEdgeItemPadding(); 670 entry_width -= GetEdgeItemPadding();
670 671
671 // |location_icon_view_| is visible except when |ev_bubble_view_| or 672 // |location_icon_view_| is visible except when |ev_bubble_view_| on the left
672 // |selected_keyword_view_| are visible. 673 // of edit or |selected_keyword_view_| are visible; if |ev_bubble_view_| is
674 // visible on the right of edit, |location_icon_view_| could be visible too
675 // (see comments below for instant extended API).
673 int location_icon_width = 0; 676 int location_icon_width = 0;
674 int ev_bubble_width = 0; 677 int ev_bubble_width = 0;
675 location_icon_view_->SetVisible(false); 678 location_icon_view_->SetVisible(false);
676 ev_bubble_view_->SetVisible(false); 679 ev_bubble_view_->SetVisible(false);
677 680
678 const string16 keyword(location_entry_->model()->keyword()); 681 const string16 keyword(location_entry_->model()->keyword());
679 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); 682 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
680 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; 683 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
681 if (show_selected_keyword) { 684 if (show_selected_keyword) {
682 // Assume the keyword might be hidden. 685 // Assume the keyword might be hidden.
683 entry_width -= (kEdgeThickness + kEdgeEditPadding); 686 entry_width -= (kEdgeThickness + kEdgeEditPadding);
684 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { 687 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) {
685 ev_bubble_view_->SetVisible(true); 688 ev_bubble_view_->SetVisible(true);
686 ev_bubble_view_->SetLabel(model_->GetEVCertName()); 689 ev_bubble_view_->SetLabel(model_->GetEVCertName());
687 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); 690 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width();
688 // We'll adjust this width and take it out of |entry_width| below. 691 // We'll adjust this width and take it out of |entry_width| below.
689 } else { 692 } else {
690 location_icon_view_->SetVisible(true); 693 location_icon_view_->SetVisible(true);
691 location_icon_width = location_icon_view_->GetPreferredSize().width(); 694 location_icon_width = location_icon_view_->GetPreferredSize().width();
692 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + 695 entry_width -= (kEdgeThickness + GetEdgeItemPadding() +
693 location_icon_width + kItemEditPadding); 696 location_icon_width + kItemEditPadding);
697
698 // For instant extended API, omnibox could be secure and replacing the url
699 // with query terms, in which case, show the ev bubble view with the search
700 // provider name on the right of the edit box.
701 if (chrome::search::IsInstantExtendedAPIEnabled(profile_) &&
702 model_->GetSecurityLevel() == ToolbarModel::SECURE &&
703 model_->WouldReplaceSearchURLWithSearchTerms()) {
704 const TemplateURL* template_url =
705 TemplateURLServiceFactory::GetForProfile(profile_)->
706 GetDefaultSearchProvider();
707 if (template_url) {
708 ev_bubble_view_->SetVisible(true);
709 ev_bubble_view_->SetLabel(l10n_util::GetStringFUTF16(
710 IDS_OMNIBOX_EV_SEARCH_TEXT, template_url->short_name()));
711 // We'll adjust this width and take it out of |entry_width| below.
712 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width();
beaudoin 2012/11/29 15:07:50 Could we go with just a bool or an enum here and k
kuan 2012/11/29 16:48:27 Done.
713 }
714 }
694 } 715 }
695 716
696 if (action_box_button_view_) { 717 if (action_box_button_view_) {
697 action_box_button_view_->SetVisible(true); 718 action_box_button_view_->SetVisible(true);
698 entry_width -= action_box_button_view_->width() + GetItemPadding(); 719 entry_width -= action_box_button_view_->width() + GetItemPadding();
699 } 720 }
721
722 // Remember |entry_width| before considering the decorations between right of
723 // edit box and action box, so as to know if there are decorations to the left
724 // of the EV bubble that's showing on the right of edit box.
725 int entry_width_for_left_of_action_box = entry_width;
beaudoin 2012/11/29 15:07:50 Comment and variable name here are hard to underst
kuan 2012/11/29 16:48:27 Done. i tried your bool approach before, but felt
beaudoin 2012/11/30 01:24:30 Ack.
726
700 if (star_view_ && star_view_->visible()) 727 if (star_view_ && star_view_->visible())
701 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); 728 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding();
702 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { 729 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
703 entry_width -= open_pdf_in_reader_view_->GetPreferredSize().width() + 730 entry_width -= open_pdf_in_reader_view_->GetPreferredSize().width() +
704 GetItemPadding(); 731 GetItemPadding();
705 } 732 }
706 for (PageActionViews::const_iterator i(page_action_views_.begin()); 733 for (PageActionViews::const_iterator i(page_action_views_.begin());
707 i != page_action_views_.end(); ++i) { 734 i != page_action_views_.end(); ++i) {
708 if ((*i)->visible()) 735 if ((*i)->visible())
709 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 736 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
710 } 737 }
711 if (zoom_view_->visible()) 738 if (zoom_view_->visible())
712 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); 739 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding();
713 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 740 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
714 i != content_setting_views_.end(); ++i) { 741 i != content_setting_views_.end(); ++i) {
715 if ((*i)->visible()) 742 if ((*i)->visible())
716 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 743 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
717 } 744 }
718 if (web_intents_button_view_->visible()) { 745 if (web_intents_button_view_->visible()) {
719 entry_width -= web_intents_button_view_->GetPreferredSize().width() + 746 entry_width -= web_intents_button_view_->GetPreferredSize().width() +
720 GetItemPadding(); 747 GetItemPadding();
721 } 748 }
749
750 bool has_icons_left_of_action_box =
751 entry_width_for_left_of_action_box != entry_width;
752
722 // The gap between the edit and whatever is to its right is shortened. 753 // The gap between the edit and whatever is to its right is shortened.
723 entry_width += kEditInternalSpace; 754 entry_width += kEditInternalSpace;
724 755
725 // Size the EV bubble after taking star/page actions/content settings out of 756 // Size the EV bubble after taking star/page actions/content settings out of
726 // |entry_width| so we won't take too much space. 757 // |entry_width| so we won't take too much space.
727 if (ev_bubble_width) { 758 if (ev_bubble_width) {
728 // Try to elide the bubble to be no larger than half the total available 759 // Try to elide the bubble to be no larger than half the total available
729 // space, but never elide it any smaller than 150 px. 760 // space, but never elide it any smaller than 150 px.
730 static const int kMinElidedBubbleWidth = 150; 761 static const int kMinElidedBubbleWidth = 150;
731 static const double kMaxBubbleFraction = 0.5; 762 static const double kMaxBubbleFraction = 0.5;
732 const int total_padding = 763 int total_padding = 0;
733 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; 764 if (location_icon_width == 0) { // EV bubble is on the left of edit box.
beaudoin 2012/11/29 15:07:50 Again, I think a bool/enum would make this much ea
kuan 2012/11/29 16:48:27 Done.
765 total_padding = kEdgeThickness + kBubbleHorizontalPadding +
766 kItemEditPadding;
767 } else { // EV bubble is on the right of edit box.
768 if (!action_box_button_view_) // EV bubble is first from the right.
769 total_padding = kEdgeThickness + kBubbleHorizontalPadding;
770 else // EV bubble is left of action box.
771 total_padding = GetItemPadding();
772 if (has_icons_left_of_action_box) // Has icons on left of EV bubble.
773 total_padding += GetItemPadding();
774 else // EV bubble is beside edit box.
775 total_padding += kItemEditPadding;
776 }
734 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, 777 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
735 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); 778 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
736 entry_width -= (total_padding + ev_bubble_width); 779 entry_width -= (total_padding + ev_bubble_width);
737 } 780 }
738 781
739 const int max_edit_width = location_entry_->GetMaxEditWidth(entry_width); 782 const int max_edit_width = location_entry_->GetMaxEditWidth(entry_width);
740 if (max_edit_width < 0) 783 if (max_edit_width < 0)
741 return; 784 return;
742 785
743 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; 786 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
(...skipping 17 matching lines...) Expand all
761 selected_keyword_view_->set_is_extension_icon(false); 804 selected_keyword_view_->set_is_extension_icon(false);
762 } 805 }
763 } 806 }
764 } else if (show_keyword_hint) { 807 } else if (show_keyword_hint) {
765 if (keyword_hint_view_->keyword() != keyword) 808 if (keyword_hint_view_->keyword() != keyword)
766 keyword_hint_view_->SetKeyword(keyword); 809 keyword_hint_view_->SetKeyword(keyword);
767 } 810 }
768 811
769 // Lay out items to the right of the edit field. 812 // Lay out items to the right of the edit field.
770 int offset = width() - kEdgeThickness; 813 int offset = width() - kEdgeThickness;
814 bool ev_bubble_on_right = ev_bubble_width > 0 && location_icon_width > 0;
beaudoin 2012/11/29 15:07:50 I would set that bool much earlier, as soon as you
kuan 2012/11/29 16:48:27 Done.
771 if (action_box_button_view_) { 815 if (action_box_button_view_) {
772 offset -= action_box_button_view_->width(); 816 offset -= action_box_button_view_->width();
773 action_box_button_view_->SetPosition( 817 action_box_button_view_->SetPosition(
774 gfx::Point(offset, 818 gfx::Point(offset,
775 kVerticalEdgeThickness - 819 kVerticalEdgeThickness -
776 ActionBoxButtonView::kBorderOverlap)); 820 ActionBoxButtonView::kBorderOverlap));
777 offset -= GetItemPadding(); 821 offset -= GetItemPadding();
822 } else if (ev_bubble_on_right) {
823 offset -= kBubbleHorizontalPadding;
778 } else { 824 } else {
779 offset -= GetEdgeItemPadding(); 825 offset -= GetEdgeItemPadding();
780 } 826 }
781 827
828 if (ev_bubble_on_right) {
829 offset -= ev_bubble_width;
830 ev_bubble_view_->SetBounds(offset, location_y + kBubbleVerticalPadding,
831 ev_bubble_width,
832 ev_bubble_view_->GetPreferredSize().height());
833 offset -= GetItemPadding();
834 }
835
782 if (star_view_ && star_view_->visible()) { 836 if (star_view_ && star_view_->visible()) {
783 offset += star_view_->GetBuiltInHorizontalPadding(); 837 offset += star_view_->GetBuiltInHorizontalPadding();
784 int star_width = star_view_->GetPreferredSize().width(); 838 int star_width = star_view_->GetPreferredSize().width();
785 offset -= star_width; 839 offset -= star_width;
786 star_view_->SetBounds(offset, location_y, star_width, location_height); 840 star_view_->SetBounds(offset, location_y, star_width, location_height);
787 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding(); 841 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding();
788 } 842 }
789 843
790 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { 844 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
791 offset += open_pdf_in_reader_view_->GetBuiltInHorizontalPadding(); 845 offset += open_pdf_in_reader_view_->GetBuiltInHorizontalPadding();
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 int LocationBarView::GetInternalHeight(bool use_preferred_size) { 1572 int LocationBarView::GetInternalHeight(bool use_preferred_size) {
1519 int total_height = 1573 int total_height =
1520 use_preferred_size ? GetPreferredSize().height() : height(); 1574 use_preferred_size ? GetPreferredSize().height() : height();
1521 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); 1575 return std::max(total_height - (kVerticalEdgeThickness * 2), 0);
1522 } 1576 }
1523 1577
1524 bool LocationBarView::HasValidSuggestText() const { 1578 bool LocationBarView::HasValidSuggestText() const {
1525 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1579 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1526 !suggested_text_view_->text().empty(); 1580 !suggested_text_view_->text().empty();
1527 } 1581 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698