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

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: addressed beaudoin's comments 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 #if defined(USE_AURA) 92 #if defined(USE_AURA)
92 #include "ui/compositor/layer.h" 93 #include "ui/compositor/layer.h"
93 #include "ui/compositor/scoped_layer_animation_settings.h" 94 #include "ui/compositor/scoped_layer_animation_settings.h"
94 #endif 95 #endif
95 96
96 using content::WebContents; 97 using content::WebContents;
97 using views::View; 98 using views::View;
98 99
99 namespace { 100 namespace {
100 101
102 // Location of EV bubble wrt edit box, in the LTR direction.
103 // The value is a combination of bit masks.
104 enum EVBubbleLocation {
105 EV_BUBBLE_HIDE = 0, // Not visible.
106 EV_BUBBLE_LEFT = 1 << 0, // On left of edit box.
107 EV_BUBBLE_RIGHT = 1 << 1, // On right of edit box.
108 EV_BUBBLE_BESIDE_EDGE = 1 << 2, // Beside left or right edge of location bar.
109 EV_BUBBLE_BESIDE_EDIT = 1 << 3, // Beside left or right of edit box.
110 };
111
101 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { 112 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) {
102 WebContents* contents = delegate->GetWebContents(); 113 WebContents* contents = delegate->GetWebContents();
103 return browser::FindBrowserWithWebContents(contents); 114 return browser::FindBrowserWithWebContents(contents);
104 } 115 }
105 116
106 // Height of the location bar's round corner region. 117 // Height of the location bar's round corner region.
107 const int kBorderRoundCornerHeight = 5; 118 const int kBorderRoundCornerHeight = 5;
108 // Width of location bar's round corner region. 119 // Width of location bar's round corner region.
109 const int kBorderRoundCornerWidth = 4; 120 const int kBorderRoundCornerWidth = 4;
110 // Radius of the round corners inside the location bar. 121 // Radius of the round corners inside the location bar.
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 const int kBubbleVerticalPadding = (mode_ == POPUP) ? 672 const int kBubbleVerticalPadding = (mode_ == POPUP) ?
662 -1 : kBubbleHorizontalPadding; 673 -1 : kBubbleHorizontalPadding;
663 674
664 // Start by reserving the padding at the right edge. 675 // Start by reserving the padding at the right edge.
665 int entry_width = width() - kEdgeThickness; 676 int entry_width = width() - kEdgeThickness;
666 // No need for edge item padding with action box as it fills 677 // No need for edge item padding with action box as it fills
667 // all the area on the right. 678 // all the area on the right.
668 if (!action_box_button_view_) 679 if (!action_box_button_view_)
669 entry_width -= GetEdgeItemPadding(); 680 entry_width -= GetEdgeItemPadding();
670 681
671 // |location_icon_view_| is visible except when |ev_bubble_view_| or 682 // |location_icon_view_| is visible except when |ev_bubble_view_| on the left
672 // |selected_keyword_view_| are visible. 683 // of edit or |selected_keyword_view_| are visible; if |ev_bubble_view_| is
684 // visible on the right of edit, |location_icon_view_| could be visible too
685 // (see comments below for instant extended API).
673 int location_icon_width = 0; 686 int location_icon_width = 0;
674 int ev_bubble_width = 0; 687 int ev_bubble_loc = EV_BUBBLE_HIDE;
675 location_icon_view_->SetVisible(false); 688 location_icon_view_->SetVisible(false);
676 ev_bubble_view_->SetVisible(false); 689 ev_bubble_view_->SetVisible(false);
677 690
678 const string16 keyword(location_entry_->model()->keyword()); 691 const string16 keyword(location_entry_->model()->keyword());
679 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); 692 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
680 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; 693 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
681 if (show_selected_keyword) { 694 if (show_selected_keyword) {
682 // Assume the keyword might be hidden. 695 // Assume the keyword might be hidden.
683 entry_width -= (kEdgeThickness + kEdgeEditPadding); 696 entry_width -= (kEdgeThickness + kEdgeEditPadding);
684 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { 697 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) {
685 ev_bubble_view_->SetVisible(true); 698 ev_bubble_view_->SetVisible(true);
686 ev_bubble_view_->SetLabel(model_->GetEVCertName()); 699 ev_bubble_view_->SetLabel(model_->GetEVCertName());
687 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); 700 ev_bubble_loc = EV_BUBBLE_LEFT | EV_BUBBLE_BESIDE_EDGE |
688 // We'll adjust this width and take it out of |entry_width| below. 701 EV_BUBBLE_BESIDE_EDIT;
689 } else { 702 } else {
690 location_icon_view_->SetVisible(true); 703 location_icon_view_->SetVisible(true);
691 location_icon_width = location_icon_view_->GetPreferredSize().width(); 704 location_icon_width = location_icon_view_->GetPreferredSize().width();
692 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + 705 entry_width -= (kEdgeThickness + GetEdgeItemPadding() +
693 location_icon_width + kItemEditPadding); 706 location_icon_width + kItemEditPadding);
707
708 // For instant extended API, omnibox could be secure and replacing the url
709 // with query terms, in which case, show the ev bubble view with the search
710 // provider name on the right of the edit box.
711 if (chrome::search::IsInstantExtendedAPIEnabled(profile_) &&
712 model_->GetSecurityLevel() == ToolbarModel::SECURE &&
713 model_->WouldReplaceSearchURLWithSearchTerms()) {
714 const TemplateURL* template_url =
715 TemplateURLServiceFactory::GetForProfile(profile_)->
716 GetDefaultSearchProvider();
717 if (template_url) {
718 ev_bubble_view_->SetVisible(true);
719 ev_bubble_view_->SetLabel(l10n_util::GetStringFUTF16(
720 IDS_OMNIBOX_EV_SEARCH_TEXT, template_url->short_name()));
721 ev_bubble_loc = EV_BUBBLE_RIGHT;
722 if (!action_box_button_view_)
723 ev_bubble_loc |= EV_BUBBLE_BESIDE_EDGE;
724 // We'll determine if EV bubble is beside edit box later.
dhollowa 2012/11/29 17:01:26 nit: "Determine...below".
kuan 2012/11/29 17:19:20 Done.
725 }
726 }
694 } 727 }
695 728
696 if (action_box_button_view_) { 729 if (action_box_button_view_) {
697 action_box_button_view_->SetVisible(true); 730 action_box_button_view_->SetVisible(true);
698 entry_width -= action_box_button_view_->width() + GetItemPadding(); 731 entry_width -= action_box_button_view_->width() + GetItemPadding();
699 } 732 }
733
734 // Remember |entry_width| before considering the decorations between right of
735 // edit box and action box, so as to determine if any other decoration is
736 // added, which will help determine if right EV bubble is beside the edit box.
737 int entry_width_for_left_of_action_box = entry_width;
738
700 if (star_view_ && star_view_->visible()) 739 if (star_view_ && star_view_->visible())
701 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); 740 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding();
702 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { 741 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
703 entry_width -= open_pdf_in_reader_view_->GetPreferredSize().width() + 742 entry_width -= open_pdf_in_reader_view_->GetPreferredSize().width() +
704 GetItemPadding(); 743 GetItemPadding();
705 } 744 }
706 for (PageActionViews::const_iterator i(page_action_views_.begin()); 745 for (PageActionViews::const_iterator i(page_action_views_.begin());
707 i != page_action_views_.end(); ++i) { 746 i != page_action_views_.end(); ++i) {
708 if ((*i)->visible()) 747 if ((*i)->visible())
709 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 748 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
710 } 749 }
711 if (zoom_view_->visible()) 750 if (zoom_view_->visible())
712 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); 751 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding();
713 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 752 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
714 i != content_setting_views_.end(); ++i) { 753 i != content_setting_views_.end(); ++i) {
715 if ((*i)->visible()) 754 if ((*i)->visible())
716 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 755 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
717 } 756 }
718 if (web_intents_button_view_->visible()) { 757 if (web_intents_button_view_->visible()) {
719 entry_width -= web_intents_button_view_->GetPreferredSize().width() + 758 entry_width -= web_intents_button_view_->GetPreferredSize().width() +
720 GetItemPadding(); 759 GetItemPadding();
721 } 760 }
761
762 // If EV bubble is on right of edit box and no decoration has been added
763 // between right of edit box and action box, EV bubble is beside edit box.
764 if (ev_bubble_loc & EV_BUBBLE_RIGHT &&
765 entry_width_for_left_of_action_box == entry_width) {
766 ev_bubble_loc |= EV_BUBBLE_BESIDE_EDIT;
767 }
768
722 // The gap between the edit and whatever is to its right is shortened. 769 // The gap between the edit and whatever is to its right is shortened.
723 entry_width += kEditInternalSpace; 770 entry_width += kEditInternalSpace;
724 771
725 // Size the EV bubble after taking star/page actions/content settings out of 772 // Size the EV bubble after taking star/page actions/content settings out of
726 // |entry_width| so we won't take too much space. 773 // |entry_width| so we won't take too much space.
727 if (ev_bubble_width) { 774 int ev_bubble_width = 0;
775 if (ev_bubble_loc != EV_BUBBLE_HIDE) {
776 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width();
728 // Try to elide the bubble to be no larger than half the total available 777 // 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. 778 // space, but never elide it any smaller than 150 px.
730 static const int kMinElidedBubbleWidth = 150; 779 static const int kMinElidedBubbleWidth = 150;
731 static const double kMaxBubbleFraction = 0.5; 780 static const double kMaxBubbleFraction = 0.5;
732 const int total_padding = 781 int total_padding = 0;
733 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; 782 if (ev_bubble_loc & EV_BUBBLE_BESIDE_EDGE)
783 total_padding += kEdgeThickness + kBubbleHorizontalPadding;
784 else
785 total_padding += GetItemPadding();
786 if (ev_bubble_loc & EV_BUBBLE_BESIDE_EDIT)
787 total_padding += kItemEditPadding;
788 else
789 total_padding += GetItemPadding();
734 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, 790 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
735 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); 791 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
736 entry_width -= (total_padding + ev_bubble_width); 792 entry_width -= (total_padding + ev_bubble_width);
737 } 793 }
738 794
739 const int max_edit_width = location_entry_->GetMaxEditWidth(entry_width); 795 const int max_edit_width = location_entry_->GetMaxEditWidth(entry_width);
740 if (max_edit_width < 0) 796 if (max_edit_width < 0)
741 return; 797 return;
742 798
743 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; 799 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
(...skipping 24 matching lines...) Expand all
768 824
769 // Lay out items to the right of the edit field. 825 // Lay out items to the right of the edit field.
770 int offset = width() - kEdgeThickness; 826 int offset = width() - kEdgeThickness;
771 if (action_box_button_view_) { 827 if (action_box_button_view_) {
772 offset -= action_box_button_view_->width(); 828 offset -= action_box_button_view_->width();
773 action_box_button_view_->SetPosition( 829 action_box_button_view_->SetPosition(
774 gfx::Point(offset, 830 gfx::Point(offset,
775 kVerticalEdgeThickness - 831 kVerticalEdgeThickness -
776 ActionBoxButtonView::kBorderOverlap)); 832 ActionBoxButtonView::kBorderOverlap));
777 offset -= GetItemPadding(); 833 offset -= GetItemPadding();
834 } else if (ev_bubble_loc & EV_BUBBLE_RIGHT) {
835 offset -= kBubbleHorizontalPadding;
778 } else { 836 } else {
779 offset -= GetEdgeItemPadding(); 837 offset -= GetEdgeItemPadding();
780 } 838 }
781 839
840 if (ev_bubble_loc & EV_BUBBLE_RIGHT) {
841 offset -= ev_bubble_width;
842 ev_bubble_view_->SetBounds(offset, location_y + kBubbleVerticalPadding,
843 ev_bubble_width,
844 ev_bubble_view_->GetPreferredSize().height());
845 offset -= GetItemPadding();
846 }
847
782 if (star_view_ && star_view_->visible()) { 848 if (star_view_ && star_view_->visible()) {
783 offset += star_view_->GetBuiltInHorizontalPadding(); 849 offset += star_view_->GetBuiltInHorizontalPadding();
784 int star_width = star_view_->GetPreferredSize().width(); 850 int star_width = star_view_->GetPreferredSize().width();
785 offset -= star_width; 851 offset -= star_width;
786 star_view_->SetBounds(offset, location_y, star_width, location_height); 852 star_view_->SetBounds(offset, location_y, star_width, location_height);
787 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding(); 853 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding();
788 } 854 }
789 855
790 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { 856 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
791 offset += open_pdf_in_reader_view_->GetBuiltInHorizontalPadding(); 857 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) { 1584 int LocationBarView::GetInternalHeight(bool use_preferred_size) {
1519 int total_height = 1585 int total_height =
1520 use_preferred_size ? GetPreferredSize().height() : height(); 1586 use_preferred_size ? GetPreferredSize().height() : height();
1521 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); 1587 return std::max(total_height - (kVerticalEdgeThickness * 2), 0);
1522 } 1588 }
1523 1589
1524 bool LocationBarView::HasValidSuggestText() const { 1590 bool LocationBarView::HasValidSuggestText() const {
1525 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1591 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1526 !suggested_text_view_->text().empty(); 1592 !suggested_text_view_->text().empty();
1527 } 1593 }
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