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

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

Issue 11648024: Clean-up positioning and spacing in chrome/browser/ui/views/location_bar/location_bar_view.cc (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed executable bit. Created 7 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
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/chrome_browser_ui.gypi » ('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/command_line.h" 10 #include "base/command_line.h"
(...skipping 21 matching lines...) Expand all
32 #include "chrome/browser/ui/omnibox/location_bar_util.h" 32 #include "chrome/browser/ui/omnibox/location_bar_util.h"
33 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 33 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
34 #include "chrome/browser/ui/view_ids.h" 34 #include "chrome/browser/ui/view_ids.h"
35 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" 35 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h"
36 #include "chrome/browser/ui/views/browser_dialogs.h" 36 #include "chrome/browser/ui/views/browser_dialogs.h"
37 #include "chrome/browser/ui/views/extensions/extension_popup.h" 37 #include "chrome/browser/ui/views/extensions/extension_popup.h"
38 #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"
39 #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"
40 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 40 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
41 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 41 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
42 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
42 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 43 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
43 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" 44 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
44 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 45 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
45 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 46 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
46 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h" 47 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h"
47 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
48 #include "chrome/browser/ui/views/location_bar/star_view.h" 49 #include "chrome/browser/ui/views/location_bar/star_view.h"
49 #include "chrome/browser/ui/views/location_bar/web_intents_button_view.h" 50 #include "chrome/browser/ui/views/location_bar/web_intents_button_view.h"
50 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
51 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 52 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 0, GetThemeProvider()->GetImageSkiaNamed(sizing_image_id)->height()); 634 0, GetThemeProvider()->GetImageSkiaNamed(sizing_image_id)->height());
634 } 635 }
635 636
636 void LocationBarView::Layout() { 637 void LocationBarView::Layout() {
637 if (!location_entry_.get()) 638 if (!location_entry_.get())
638 return; 639 return;
639 640
640 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. 641 // TODO(jhawkins): Remove once crbug.com/101994 is fixed.
641 CHECK(location_icon_view_); 642 CHECK(location_icon_view_);
642 643
643 // TODO(sky): baseline layout.
644 int location_y = kVerticalEdgeThickness;
645 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 644 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
646 // to position our child views in this case, because other things may be 645 // to position our child views in this case, because other things may be
647 // positioned relative to them (e.g. the "bookmark added" bubble if the user 646 // positioned relative to them (e.g. the "bookmark added" bubble if the user
648 // hits ctrl-d). 647 // hits ctrl-d).
649 int location_height = GetInternalHeight(false); 648 int location_height = GetInternalHeight(false);
650 649
651 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the 650 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the
652 // omnibox' parent, so there isn't any edge to account for at all. 651 // omnibox' parent, so there isn't any edge to account for at all.
653 const int kEdgeThickness = (mode_ == NORMAL) ? 652 const int kEdgeThickness = (mode_ == NORMAL) ?
654 kNormalHorizontalEdgeThickness : 0; 653 kNormalHorizontalEdgeThickness : 0;
655 // The edit has 1 px of horizontal whitespace inside it before the text. 654 // The edit has 1 px of horizontal whitespace inside it before the text.
656 const int kEditInternalSpace = 1; 655 const int kEditInternalSpace = 1;
657 // The space between an item and the edit is the normal item space, minus the 656 // The space between an item and the edit is the normal item space, minus the
658 // edit's built-in space (so the apparent space will be the same). 657 // edit's built-in space (so the apparent space will be the same).
659 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace; 658 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace;
660 const int kEdgeEditPadding = GetEdgeItemPadding() - kEditInternalSpace; 659 const int kEdgeEditPadding = GetEdgeItemPadding() - kEditInternalSpace;
661 const int kBubbleVerticalPadding = (mode_ == POPUP) ? 660 const int kBubbleVerticalPadding = (mode_ == POPUP) ?
662 -1 : kBubbleHorizontalPadding; 661 -1 : kBubbleHorizontalPadding;
662 // The largest fraction of the omnibox that can be taken by resizable
663 // bubble decorations such as the EV_SECURE decoration.
664 const double kMaxBubbleFraction = 0.5;
665 const int kBubbleLocationY = kVerticalEdgeThickness + kBubbleVerticalPadding;
663 666
664 // Start by reserving the padding at the right edge. 667 LocationBarLayout left_decorations(LocationBarLayout::LEFT_EDGE,
665 int entry_width = width() - kEdgeThickness; 668 kItemEditPadding, kEdgeEditPadding);
666 // No need for edge item padding with action box as it fills 669 LocationBarLayout right_decorations(LocationBarLayout::RIGHT_EDGE,
667 // all the area on the right. 670 kItemEditPadding, kEdgeEditPadding);
668 if (!action_box_button_view_)
669 entry_width -= GetEdgeItemPadding();
670 671
671 // |location_icon_view_| is visible except when |ev_bubble_view_| or 672 selected_keyword_view_->SetVisible(false);
672 // |selected_keyword_view_| are visible.
673 int location_icon_width = 0;
674 int ev_bubble_width = 0;
675 location_icon_view_->SetVisible(false); 673 location_icon_view_->SetVisible(false);
676 ev_bubble_view_->SetVisible(false); 674 ev_bubble_view_->SetVisible(false);
675 keyword_hint_view_->SetVisible(false);
677 676
678 const string16 keyword(location_entry_->model()->keyword()); 677 const string16 keyword(location_entry_->model()->keyword());
679 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); 678 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
680 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; 679 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
680 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
681 if (show_selected_keyword) { 681 if (show_selected_keyword) {
682 // Assume the keyword might be hidden. 682 left_decorations.AddDecoration(
683 entry_width -= (kEdgeThickness + kEdgeEditPadding); 683 kBubbleLocationY, 0, true, 0, kBubbleHorizontalPadding,
684 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { 684 GetItemPadding(), 0, selected_keyword_view_);
685 ev_bubble_view_->SetVisible(true);
686 ev_bubble_view_->SetLabel(model_->GetEVCertName());
687 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width();
688 // We'll adjust this width and take it out of |entry_width| below.
689 } else {
690 location_icon_view_->SetVisible(true);
691 location_icon_width = location_icon_view_->GetPreferredSize().width();
692 entry_width -= (kEdgeThickness + GetEdgeItemPadding() +
693 location_icon_width + kItemEditPadding);
694 }
695
696 if (action_box_button_view_) {
697 action_box_button_view_->SetVisible(true);
698 entry_width -= action_box_button_view_->width() + GetItemPadding();
699 }
700 if (star_view_ && star_view_->visible())
701 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding();
702
703 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) {
704 entry_width -= script_bubble_icon_view_->GetPreferredSize().width() +
705 GetItemPadding();
706 }
707
708 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
709 entry_width -= open_pdf_in_reader_view_->GetPreferredSize().width() +
710 GetItemPadding();
711 }
712 for (PageActionViews::const_iterator i(page_action_views_.begin());
713 i != page_action_views_.end(); ++i) {
714 if ((*i)->visible())
715 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
716 }
717 if (zoom_view_->visible())
718 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding();
719 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
720 i != content_setting_views_.end(); ++i) {
721 if ((*i)->visible())
722 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
723 }
724 if (web_intents_button_view_->visible()) {
725 entry_width -= web_intents_button_view_->GetPreferredSize().width() +
726 GetItemPadding();
727 }
728 // The gap between the edit and whatever is to its right is shortened.
729 entry_width += kEditInternalSpace;
730
731 // Size the EV bubble after taking star/page actions/content settings out of
732 // |entry_width| so we won't take too much space.
733 if (ev_bubble_width) {
734 // Try to elide the bubble to be no larger than half the total available
735 // space, but never elide it any smaller than 150 px.
736 static const int kMinElidedBubbleWidth = 150;
737 static const double kMaxBubbleFraction = 0.5;
738 const int total_padding =
739 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding;
740 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
741 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
742 entry_width -= (total_padding + ev_bubble_width);
743 }
744
745 const int max_edit_width = location_entry_->GetMaxEditWidth(entry_width);
746 if (max_edit_width < 0)
747 return;
748
749 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
750 selected_keyword_view_->SetVisible(show_selected_keyword);
751 keyword_hint_view_->SetVisible(show_keyword_hint);
752 if (show_selected_keyword) {
753 if (selected_keyword_view_->keyword() != keyword) { 685 if (selected_keyword_view_->keyword() != keyword) {
754 selected_keyword_view_->SetKeyword(keyword); 686 selected_keyword_view_->SetKeyword(keyword);
755 const TemplateURL* template_url = 687 const TemplateURL* template_url =
756 TemplateURLServiceFactory::GetForProfile(profile_)-> 688 TemplateURLServiceFactory::GetForProfile(profile_)->
757 GetTemplateURLForKeyword(keyword); 689 GetTemplateURLForKeyword(keyword);
758 if (template_url && template_url->IsExtensionKeyword()) { 690 if (template_url && template_url->IsExtensionKeyword()) {
759 gfx::Image image = extensions::OmniboxAPI::Get(profile_)-> 691 gfx::Image image = extensions::OmniboxAPI::Get(profile_)->
760 GetOmniboxIcon(template_url->GetExtensionId()); 692 GetOmniboxIcon(template_url->GetExtensionId());
761 selected_keyword_view_->SetImage(image.AsImageSkia()); 693 selected_keyword_view_->SetImage(image.AsImageSkia());
762 selected_keyword_view_->set_is_extension_icon(true); 694 selected_keyword_view_->set_is_extension_icon(true);
763 } else { 695 } else {
764 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 696 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
765 selected_keyword_view_->SetImage( 697 selected_keyword_view_->SetImage(
766 *rb.GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); 698 *rb.GetImageSkiaNamed(IDR_OMNIBOX_SEARCH));
767 selected_keyword_view_->set_is_extension_icon(false); 699 selected_keyword_view_->set_is_extension_icon(false);
768 } 700 }
769 } 701 }
770 } else if (show_keyword_hint) { 702 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) {
703 ev_bubble_view_->SetLabel(model_->GetEVCertName());
704 left_decorations.AddDecoration(
705 kBubbleLocationY, 0, false, kMaxBubbleFraction,
706 kBubbleHorizontalPadding, GetItemPadding(), 0, ev_bubble_view_);
707 } else {
708 left_decorations.AddDecoration(
709 location_height, location_icon_view_->GetBuiltInHorizontalPadding(),
710 location_icon_view_);
711 }
712
713 if (action_box_button_view_) {
714 right_decorations.AddDecoration(
715 kVerticalEdgeThickness - ActionBoxButtonView::kBorderOverlap, 0, false,
716 0, 0, 0, 0, action_box_button_view_);
717 }
718 if (star_view_ && star_view_->visible()) {
719 right_decorations.AddDecoration(
720 location_height, star_view_->GetBuiltInHorizontalPadding(),
721 star_view_);
722 }
723 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) {
724 right_decorations.AddDecoration(
725 location_height,
726 script_bubble_icon_view_->GetBuiltInHorizontalPadding(),
727 script_bubble_icon_view_);
728 }
729 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
730 right_decorations.AddDecoration(
731 location_height,
732 open_pdf_in_reader_view_->GetBuiltInHorizontalPadding(),
733 open_pdf_in_reader_view_);
734 }
735 for (PageActionViews::const_iterator i(page_action_views_.begin());
736 i != page_action_views_.end(); ++i) {
737 if ((*i)->visible()) {
738 right_decorations.AddDecoration(
739 location_height, (*i)->GetBuiltInHorizontalPadding(), (*i));
740 }
741 }
742 if (zoom_view_->visible())
743 right_decorations.AddDecoration(location_height, 0, zoom_view_);
744 for (ContentSettingViews::const_reverse_iterator
745 i(content_setting_views_.rbegin()); i != content_setting_views_.rend();
746 ++i) {
747 if ((*i)->visible()) {
748 right_decorations.AddDecoration(
749 kBubbleLocationY, 0, false, 0, GetEdgeItemPadding(), GetItemPadding(),
750 (*i)->GetBuiltInHorizontalPadding(), (*i));
751 }
752 }
753 if (web_intents_button_view_->visible()) {
754 right_decorations.AddDecoration(
755 kBubbleLocationY, 0, false, 0, GetEdgeItemPadding(), GetItemPadding(),
756 web_intents_button_view_->GetBuiltInHorizontalPadding(),
757 web_intents_button_view_);
758 }
759 if (show_keyword_hint) {
760 right_decorations.AddDecoration(
761 kVerticalEdgeThickness, 0, true, 0, GetEdgeItemPadding(),
762 GetItemPadding(), 0, keyword_hint_view_);
771 if (keyword_hint_view_->keyword() != keyword) 763 if (keyword_hint_view_->keyword() != keyword)
772 keyword_hint_view_->SetKeyword(keyword); 764 keyword_hint_view_->SetKeyword(keyword);
773 } 765 }
774 766
775 // Lay out items to the right of the edit field. 767 // Perform layout.
776 int offset = width() - kEdgeThickness; 768 int full_width = width() - 2 * kEdgeThickness;
777 if (action_box_button_view_) { 769 int entry_width = full_width;
778 offset -= action_box_button_view_->width(); 770 left_decorations.LayoutPass1(&entry_width);
779 action_box_button_view_->SetPosition( 771 right_decorations.LayoutPass1(&entry_width);
780 gfx::Point(offset, 772 left_decorations.LayoutPass2(&entry_width);
781 kVerticalEdgeThickness - 773 right_decorations.LayoutPass2(&entry_width);
782 ActionBoxButtonView::kBorderOverlap));
783 offset -= GetItemPadding();
784 } else {
785 offset -= GetEdgeItemPadding();
786 }
787 774
788 if (star_view_ && star_view_->visible()) { 775 int available_width = entry_width - location_entry_->TextWidth();
789 offset += star_view_->GetBuiltInHorizontalPadding(); 776 // The bounds must be wide enough for all the decorations to fit.
790 int star_width = star_view_->GetPreferredSize().width(); 777 gfx::Rect location_bounds(kEdgeThickness, kVerticalEdgeThickness,
791 offset -= star_width; 778 std::max(full_width, full_width - entry_width),
792 star_view_->SetBounds(offset, location_y, star_width, location_height); 779 location_height);
793 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding(); 780 left_decorations.LayoutPass3(&location_bounds, &available_width);
794 } 781 right_decorations.LayoutPass3(&location_bounds, &available_width);
795
796 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) {
797 offset += script_bubble_icon_view_->GetBuiltInHorizontalPadding();
798 int width = script_bubble_icon_view_->GetPreferredSize().width();
799 offset -= width;
800 script_bubble_icon_view_->SetBounds(
801 offset, location_y, width, location_height);
802 offset -= GetItemPadding() -
803 script_bubble_icon_view_->GetBuiltInHorizontalPadding();
804 }
805
806 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
807 offset += open_pdf_in_reader_view_->GetBuiltInHorizontalPadding();
808 int icon_width = open_pdf_in_reader_view_->GetPreferredSize().width();
809 offset -= icon_width;
810 open_pdf_in_reader_view_->SetBounds(offset, location_y,
811 icon_width, location_height);
812 offset -= GetItemPadding() -
813 open_pdf_in_reader_view_->GetBuiltInHorizontalPadding();
814 }
815
816 for (PageActionViews::const_iterator i(page_action_views_.begin());
817 i != page_action_views_.end(); ++i) {
818 if ((*i)->visible()) {
819 offset += (*i)->GetBuiltInHorizontalPadding();
820 int page_action_width = (*i)->GetPreferredSize().width();
821 offset -= page_action_width;
822 (*i)->SetBounds(offset, location_y, page_action_width, location_height);
823 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding();
824 }
825 }
826
827 if (zoom_view_->visible()) {
828 int zoom_width = zoom_view_->GetPreferredSize().width();
829 offset -= zoom_width;
830 zoom_view_->SetBounds(offset, location_y, zoom_width, location_height);
831 offset -= GetItemPadding();
832 }
833
834 // We use a reverse_iterator here because we're laying out the views from
835 // right to left but in the vector they're ordered left to right.
836 for (ContentSettingViews::const_reverse_iterator
837 i(content_setting_views_.rbegin()); i != content_setting_views_.rend();
838 ++i) {
839 if ((*i)->visible()) {
840 offset += (*i)->GetBuiltInHorizontalPadding();
841 int content_blocked_width = (*i)->GetPreferredSize().width();
842 offset -= content_blocked_width;
843 (*i)->SetBounds(offset, location_y + kBubbleVerticalPadding,
844 content_blocked_width, (*i)->GetPreferredSize().height());
845 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding();
846 }
847 }
848
849 // Now the web intents button.
850 if (web_intents_button_view_->visible()) {
851 offset += web_intents_button_view_->GetBuiltInHorizontalPadding();
852 int width = web_intents_button_view_->GetPreferredSize().width();
853 offset -= width;
854 web_intents_button_view_->SetBounds(
855 offset, location_y + kBubbleVerticalPadding, width,
856 web_intents_button_view_->GetPreferredSize().height());
857 offset -= GetItemPadding() -
858 web_intents_button_view_->GetBuiltInHorizontalPadding();
859 }
860
861 // Now lay out items to the left of the edit field.
862 if (location_icon_view_->visible()) {
863 location_icon_view_->SetBounds(
864 kEdgeThickness + GetEdgeItemPadding() -
865 location_icon_view_->GetBuiltInHorizontalPadding(),
866 location_y, location_icon_width, location_height);
867 offset = location_icon_view_->bounds().right() + kItemEditPadding -
868 location_icon_view_->GetBuiltInHorizontalPadding();
869 } else if (ev_bubble_view_->visible()) {
870 ev_bubble_view_->SetBounds(kEdgeThickness + kBubbleHorizontalPadding,
871 location_y + kBubbleVerticalPadding, ev_bubble_width,
872 ev_bubble_view_->GetPreferredSize().height());
873 offset = ev_bubble_view_->bounds().right() + kItemEditPadding;
874 } else {
875 offset = kEdgeThickness +
876 (show_selected_keyword ? kBubbleHorizontalPadding : kEdgeEditPadding);
877 }
878
879 // Now lay out the edit field and views that autocollapse to give it more
880 // room.
881 gfx::Rect location_bounds(offset, location_y, entry_width, location_height);
882 if (show_selected_keyword) {
883 selected_keyword_view_->SetBounds(0, location_y + kBubbleVerticalPadding,
884 0, selected_keyword_view_->GetPreferredSize().height());
885 LayoutView(selected_keyword_view_, kItemEditPadding,
886 AvailableWidth(max_edit_width), true, &location_bounds);
887 location_bounds.set_x(selected_keyword_view_->visible() ?
888 (offset + selected_keyword_view_->width() + kItemEditPadding) :
889 (kEdgeThickness + kEdgeEditPadding));
890 } else if (show_keyword_hint) {
891 keyword_hint_view_->SetBounds(0, location_y, 0, location_height);
892 // Tricky: |entry_width| has already been enlarged by |kEditInternalSpace|.
893 // But if we add a trailing view, it needs to have that enlargement be to
894 // its left. So we undo the enlargement, then include it in the padding for
895 // the added view.
896 location_bounds.Inset(0, 0, kEditInternalSpace, 0);
897 LayoutView(keyword_hint_view_, kItemEditPadding,
898 AvailableWidth(max_edit_width), false, &location_bounds);
899 if (!keyword_hint_view_->visible()) {
900 // Put back the enlargement that we undid above.
901 location_bounds.Inset(0, 0, -kEditInternalSpace, 0);
902 }
903 }
904 782
905 // Layout out the suggested text view right aligned to the location 783 // Layout out the suggested text view right aligned to the location
906 // entry. Only show the suggested text if we can fit the text from one 784 // entry. Only show the suggested text if we can fit the text from one
907 // character before the end of the selection to the end of the text and the 785 // character before the end of the selection to the end of the text and the
908 // suggested text. If we can't it means either the suggested text is too big, 786 // suggested text. If we can't it means either the suggested text is too big,
909 // or the user has scrolled. 787 // or the user has scrolled.
910 788
911 // TODO(sky): We could potentially combine this with the previous step to 789 // TODO(sky): We could potentially adjust this to take into account suggested
912 // force using minimum size if necessary, but currently the chance of showing 790 // text to force using minimum size if necessary, but currently the chance of
913 // keyword hints and suggested text is minimal and we're not confident this 791 // showing keyword hints and suggested text is minimal and we're not confident
914 // is the right approach for suggested text. 792 // this is the right approach for suggested text.
915 if (suggested_text_view_) { 793 if (suggested_text_view_) {
916 // TODO(sky): need to layout when the user changes caret position. 794 // TODO(sky): need to layout when the user changes caret position.
917 int suggested_text_width = 795 int suggested_text_width =
918 suggested_text_view_->GetPreferredSize().width(); 796 suggested_text_view_->GetPreferredSize().width();
919 int vis_text_width = location_entry_->WidthOfTextAfterCursor(); 797 if (suggested_text_width > available_width) {
920 if (vis_text_width + suggested_text_width > entry_width) {
921 // Hide the suggested text if the user has scrolled or we can't fit all 798 // Hide the suggested text if the user has scrolled or we can't fit all
922 // the suggested text. 799 // the suggested text.
923 suggested_text_view_->SetBounds(0, 0, 0, 0); 800 suggested_text_view_->SetBounds(0, 0, 0, 0);
924 } else { 801 } else {
925 int location_needed_width = location_entry_->TextWidth(); 802 int location_needed_width = location_entry_->TextWidth();
926 #if defined(USE_AURA) 803 #if defined(USE_AURA)
927 // TODO(sky): fix this. The +1 comes from the width of the cursor, without 804 // TODO(sky): fix this. The +1 comes from the width of the cursor, without
928 // the text ends up shifting to the left. 805 // the text ends up shifting to the left.
929 location_needed_width++; 806 location_needed_width++;
930 #endif 807 #endif
931 location_bounds.set_width(std::min(location_needed_width, 808 location_bounds.set_width(
932 entry_width - suggested_text_width)); 809 std::min(location_needed_width,
810 location_bounds.width() - suggested_text_width));
933 // TODO(sky): figure out why this needs the -1. 811 // TODO(sky): figure out why this needs the -1.
934 suggested_text_view_->SetBounds(location_bounds.right() - 1, 812 suggested_text_view_->SetBounds(location_bounds.right() - 1,
935 location_bounds.y(), 813 location_bounds.y(),
936 suggested_text_width, 814 suggested_text_width,
937 location_bounds.height()); 815 location_bounds.height());
938 } 816 }
939 } 817 }
940 818
941 location_entry_view_->SetBoundsRect(location_bounds); 819 location_entry_view_->SetBoundsRect(location_bounds);
942 } 820 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 } 1001 }
1124 1002
1125 InstantController* LocationBarView::GetInstant() { 1003 InstantController* LocationBarView::GetInstant() {
1126 return delegate_->GetInstant(); 1004 return delegate_->GetInstant();
1127 } 1005 }
1128 1006
1129 WebContents* LocationBarView::GetWebContents() const { 1007 WebContents* LocationBarView::GetWebContents() const {
1130 return delegate_->GetWebContents(); 1008 return delegate_->GetWebContents();
1131 } 1009 }
1132 1010
1133 int LocationBarView::AvailableWidth(int location_bar_width) {
1134 return location_bar_width - location_entry_->TextWidth();
1135 }
1136
1137 void LocationBarView::LayoutView(views::View* view,
1138 int padding,
1139 int available_width,
1140 bool leading,
1141 gfx::Rect* bounds) {
1142 DCHECK(view && bounds);
1143 gfx::Size view_size = view->GetPreferredSize();
1144 if ((view_size.width() + padding) > available_width)
1145 view_size = view->GetMinimumSize();
1146 int desired_width = view_size.width() + padding;
1147 view->SetVisible(desired_width < bounds->width());
1148 if (view->visible()) {
1149 view->SetBounds(
1150 leading ? bounds->x() : (bounds->right() - view_size.width()),
1151 view->y(), view_size.width(), view->height());
1152 bounds->set_width(bounds->width() - desired_width);
1153 }
1154 }
1155
1156 void LocationBarView::RefreshContentSettingViews() { 1011 void LocationBarView::RefreshContentSettingViews() {
1157 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 1012 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
1158 i != content_setting_views_.end(); ++i) { 1013 i != content_setting_views_.end(); ++i) {
1159 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); 1014 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents());
1160 } 1015 }
1161 } 1016 }
1162 1017
1163 void LocationBarView::DeletePageActionViews() { 1018 void LocationBarView::DeletePageActionViews() {
1164 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1019 for (PageActionViews::const_iterator i(page_action_views_.begin());
1165 i != page_action_views_.end(); ++i) 1020 i != page_action_views_.end(); ++i)
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 int LocationBarView::GetInternalHeight(bool use_preferred_size) { 1433 int LocationBarView::GetInternalHeight(bool use_preferred_size) {
1579 int total_height = 1434 int total_height =
1580 use_preferred_size ? GetPreferredSize().height() : height(); 1435 use_preferred_size ? GetPreferredSize().height() : height();
1581 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); 1436 return std::max(total_height - (kVerticalEdgeThickness * 2), 0);
1582 } 1437 }
1583 1438
1584 bool LocationBarView::HasValidSuggestText() const { 1439 bool LocationBarView::HasValidSuggestText() const {
1585 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1440 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1586 !suggested_text_view_->text().empty(); 1441 !suggested_text_view_->text().empty();
1587 } 1442 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698