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

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

Issue 247193002: Remove touch layout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 }; 182 };
183 183
184 } // namespace 184 } // namespace
185 185
186 186
187 // LocationBarView ----------------------------------------------------------- 187 // LocationBarView -----------------------------------------------------------
188 188
189 // static 189 // static
190 const int LocationBarView::kNormalEdgeThickness = 2; 190 const int LocationBarView::kNormalEdgeThickness = 2;
191 const int LocationBarView::kPopupEdgeThickness = 1; 191 const int LocationBarView::kPopupEdgeThickness = 1;
192 const int LocationBarView::kItemPadding = 3;
192 const int LocationBarView::kIconInternalPadding = 2; 193 const int LocationBarView::kIconInternalPadding = 2;
193 const int LocationBarView::kBubblePadding = 1; 194 const int LocationBarView::kBubblePadding = 1;
194 const char LocationBarView::kViewClassName[] = "LocationBarView"; 195 const char LocationBarView::kViewClassName[] = "LocationBarView";
195 196
196 LocationBarView::LocationBarView(Browser* browser, 197 LocationBarView::LocationBarView(Browser* browser,
197 Profile* profile, 198 Profile* profile,
198 CommandUpdater* command_updater, 199 CommandUpdater* command_updater,
199 Delegate* delegate, 200 Delegate* delegate,
200 bool is_popup_mode) 201 bool is_popup_mode)
201 : LocationBar(profile), 202 : LocationBar(profile),
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 parent()->height() - views::NonClientFrameView::kClientEdgeThickness); 659 parent()->height() - views::NonClientFrameView::kClientEdgeThickness);
659 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); 660 views::View::ConvertPointToScreen(parent(), top_left_screen_coord);
660 *popup_width = parent()->width(); 661 *popup_width = parent()->width();
661 662
662 gfx::Rect location_bar_bounds(bounds()); 663 gfx::Rect location_bar_bounds(bounds());
663 location_bar_bounds.Inset(kNormalEdgeThickness, 0); 664 location_bar_bounds.Inset(kNormalEdgeThickness, 0);
664 *left_margin = location_bar_bounds.x(); 665 *left_margin = location_bar_bounds.x();
665 *right_margin = *popup_width - location_bar_bounds.right(); 666 *right_margin = *popup_width - location_bar_bounds.right();
666 } 667 }
667 668
668 // static
669 int LocationBarView::GetItemPadding() {
670 const int kTouchItemPadding = 8;
671 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH)
672 return kTouchItemPadding;
673
674 const int kDesktopItemPadding = 3;
675 return kDesktopItemPadding;
676 }
677
678 //////////////////////////////////////////////////////////////////////////////// 669 ////////////////////////////////////////////////////////////////////////////////
679 // LocationBarView, public LocationBar implementation: 670 // LocationBarView, public LocationBar implementation:
680 671
681 void LocationBarView::FocusLocation(bool select_all) { 672 void LocationBarView::FocusLocation(bool select_all) {
682 omnibox_view_->SetFocus(); 673 omnibox_view_->SetFocus();
683 if (select_all) 674 if (select_all)
684 omnibox_view_->SelectAll(true); 675 omnibox_view_->SelectAll(true);
685 } 676 }
686 677
687 void LocationBarView::Revert() { 678 void LocationBarView::Revert() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 if (!IsInitialized()) 732 if (!IsInitialized())
742 return; 733 return;
743 734
744 animated_host_label_->SetVisible(false); 735 animated_host_label_->SetVisible(false);
745 origin_chip_view_->SetVisible(origin_chip_view_->ShouldShow()); 736 origin_chip_view_->SetVisible(origin_chip_view_->ShouldShow());
746 selected_keyword_view_->SetVisible(false); 737 selected_keyword_view_->SetVisible(false);
747 location_icon_view_->SetVisible(false); 738 location_icon_view_->SetVisible(false);
748 ev_bubble_view_->SetVisible(false); 739 ev_bubble_view_->SetVisible(false);
749 keyword_hint_view_->SetVisible(false); 740 keyword_hint_view_->SetVisible(false);
750 741
751 const int item_padding = GetItemPadding();
752
753 // The textfield has 1 px of whitespace before the text in the RTL case only. 742 // The textfield has 1 px of whitespace before the text in the RTL case only.
754 const int kEditLeadingInternalSpace = base::i18n::IsRTL() ? 1 : 0; 743 const int kEditLeadingInternalSpace = base::i18n::IsRTL() ? 1 : 0;
755 LocationBarLayout leading_decorations( 744 LocationBarLayout leading_decorations(
756 LocationBarLayout::LEFT_EDGE, item_padding - kEditLeadingInternalSpace); 745 LocationBarLayout::LEFT_EDGE, kItemPadding - kEditLeadingInternalSpace);
757 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, 746 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE,
758 item_padding); 747 kItemPadding);
759 748
760 // Show and position the animated host label used in the show and hide URL 749 // Show and position the animated host label used in the show and hide URL
761 // animations. 750 // animations.
762 if (show_url_animation_->is_animating() || 751 if (show_url_animation_->is_animating() ||
763 hide_url_animation_->is_animating()) { 752 hide_url_animation_->is_animating()) {
764 const GURL url = GetWebContents()->GetURL(); 753 const GURL url = GetWebContents()->GetURL();
765 const base::string16 host = 754 const base::string16 host =
766 OriginChip::LabelFromURLForProfile(url, profile()); 755 OriginChip::LabelFromURLForProfile(url, profile());
767 animated_host_label_->SetText(host); 756 animated_host_label_->SetText(host);
768 757
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 const bool is_keyword_hint(omnibox_view_->model()->is_keyword_hint()); 794 const bool is_keyword_hint(omnibox_view_->model()->is_keyword_hint());
806 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; 795 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding;
807 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 796 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
808 // to position our child views in this case, because other things may be 797 // to position our child views in this case, because other things may be
809 // positioned relative to them (e.g. the "bookmark added" bubble if the user 798 // positioned relative to them (e.g. the "bookmark added" bubble if the user
810 // hits ctrl-d). 799 // hits ctrl-d).
811 const int location_height = GetInternalHeight(false); 800 const int location_height = GetInternalHeight(false);
812 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); 801 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0);
813 if (!keyword.empty() && !is_keyword_hint) { 802 if (!keyword.empty() && !is_keyword_hint) {
814 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, 803 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0,
815 kBubblePadding, item_padding, 0, 804 kBubblePadding, kItemPadding, 0,
816 selected_keyword_view_); 805 selected_keyword_view_);
817 if (selected_keyword_view_->keyword() != keyword) { 806 if (selected_keyword_view_->keyword() != keyword) {
818 selected_keyword_view_->SetKeyword(keyword); 807 selected_keyword_view_->SetKeyword(keyword);
819 const TemplateURL* template_url = 808 const TemplateURL* template_url =
820 TemplateURLServiceFactory::GetForProfile(profile())-> 809 TemplateURLServiceFactory::GetForProfile(profile())->
821 GetTemplateURLForKeyword(keyword); 810 GetTemplateURLForKeyword(keyword);
822 if (template_url && 811 if (template_url &&
823 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 812 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
824 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 813 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
825 GetOmniboxIcon(template_url->GetExtensionId()); 814 GetOmniboxIcon(template_url->GetExtensionId());
826 selected_keyword_view_->SetImage(image.AsImageSkia()); 815 selected_keyword_view_->SetImage(image.AsImageSkia());
827 selected_keyword_view_->set_is_extension_icon(true); 816 selected_keyword_view_->set_is_extension_icon(true);
828 } else { 817 } else {
829 selected_keyword_view_->SetImage( 818 selected_keyword_view_->SetImage(
830 *(GetThemeProvider()->GetImageSkiaNamed(IDR_OMNIBOX_SEARCH))); 819 *(GetThemeProvider()->GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)));
831 selected_keyword_view_->set_is_extension_icon(false); 820 selected_keyword_view_->set_is_extension_icon(false);
832 } 821 }
833 } 822 }
834 } else if (!toolbar_origin_chip_view_ && 823 } else if (!toolbar_origin_chip_view_ &&
835 !chrome::ShouldDisplayOriginChipV2() && 824 !chrome::ShouldDisplayOriginChipV2() &&
836 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE)) { 825 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE)) {
837 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); 826 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName());
838 // The largest fraction of the omnibox that can be taken by the EV bubble. 827 // The largest fraction of the omnibox that can be taken by the EV bubble.
839 const double kMaxBubbleFraction = 0.5; 828 const double kMaxBubbleFraction = 0.5;
840 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, 829 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false,
841 kMaxBubbleFraction, kBubblePadding, 830 kMaxBubbleFraction, kBubblePadding,
842 item_padding, 0, ev_bubble_view_); 831 kItemPadding, 0, ev_bubble_view_);
843 } else if (!origin_chip_view_->visible()) { 832 } else if (!origin_chip_view_->visible()) {
844 leading_decorations.AddDecoration( 833 leading_decorations.AddDecoration(
845 vertical_edge_thickness(), location_height, 834 vertical_edge_thickness(), location_height,
846 GetBuiltInHorizontalPaddingForChildViews(), 835 GetBuiltInHorizontalPaddingForChildViews(),
847 location_icon_view_); 836 location_icon_view_);
848 } 837 }
849 838
850 if (star_view_->visible()) { 839 if (star_view_->visible()) {
851 trailing_decorations.AddDecoration( 840 trailing_decorations.AddDecoration(
852 vertical_edge_thickness(), location_height, 841 vertical_edge_thickness(), location_height,
(...skipping 26 matching lines...) Expand all
879 } 868 }
880 if (zoom_view_->visible()) { 869 if (zoom_view_->visible()) {
881 trailing_decorations.AddDecoration(vertical_edge_thickness(), 870 trailing_decorations.AddDecoration(vertical_edge_thickness(),
882 location_height, 0, zoom_view_); 871 location_height, 0, zoom_view_);
883 } 872 }
884 for (ContentSettingViews::const_reverse_iterator i( 873 for (ContentSettingViews::const_reverse_iterator i(
885 content_setting_views_.rbegin()); i != content_setting_views_.rend(); 874 content_setting_views_.rbegin()); i != content_setting_views_.rend();
886 ++i) { 875 ++i) {
887 if ((*i)->visible()) { 876 if ((*i)->visible()) {
888 trailing_decorations.AddDecoration( 877 trailing_decorations.AddDecoration(
889 bubble_location_y, bubble_height, false, 0, item_padding, 878 bubble_location_y, bubble_height, false, 0, kItemPadding,
890 item_padding, GetBuiltInHorizontalPaddingForChildViews(), (*i)); 879 kItemPadding, GetBuiltInHorizontalPaddingForChildViews(), (*i));
891 } 880 }
892 } 881 }
893 if (generated_credit_card_view_->visible()) { 882 if (generated_credit_card_view_->visible()) {
894 trailing_decorations.AddDecoration(vertical_edge_thickness(), 883 trailing_decorations.AddDecoration(vertical_edge_thickness(),
895 location_height, 0, 884 location_height, 0,
896 generated_credit_card_view_); 885 generated_credit_card_view_);
897 } 886 }
898 if (mic_search_view_->visible()) { 887 if (mic_search_view_->visible()) {
899 trailing_decorations.AddDecoration(vertical_edge_thickness(), 888 trailing_decorations.AddDecoration(vertical_edge_thickness(),
900 location_height, 0, mic_search_view_); 889 location_height, 0, mic_search_view_);
901 } 890 }
902 // Because IMEs may eat the tab key, we don't show "press tab to search" while 891 // Because IMEs may eat the tab key, we don't show "press tab to search" while
903 // IME composition is in progress. 892 // IME composition is in progress.
904 if (!keyword.empty() && is_keyword_hint && !omnibox_view_->IsImeComposing()) { 893 if (!keyword.empty() && is_keyword_hint && !omnibox_view_->IsImeComposing()) {
905 trailing_decorations.AddDecoration(vertical_edge_thickness(), 894 trailing_decorations.AddDecoration(vertical_edge_thickness(),
906 location_height, true, 0, item_padding, 895 location_height, true, 0, kItemPadding,
907 item_padding, 0, keyword_hint_view_); 896 kItemPadding, 0, keyword_hint_view_);
908 if (keyword_hint_view_->keyword() != keyword) 897 if (keyword_hint_view_->keyword() != keyword)
909 keyword_hint_view_->SetKeyword(keyword); 898 keyword_hint_view_->SetKeyword(keyword);
910 } 899 }
911 900
912 // Perform layout. 901 // Perform layout.
913 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 902 const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
914 int full_width = width() - horizontal_edge_thickness - origin_chip_width; 903 int full_width = width() - horizontal_edge_thickness - origin_chip_width;
915 904
916 // The search button images are made to look as if they overlay the normal 905 // The search button images are made to look as if they overlay the normal
917 // edge images, but to align things, the search button needs to be inset 906 // edge images, but to align things, the search button needs to be inset
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 } 1059 }
1071 1060
1072 WebContents* LocationBarView::GetWebContents() { 1061 WebContents* LocationBarView::GetWebContents() {
1073 return delegate_->GetWebContents(); 1062 return delegate_->GetWebContents();
1074 } 1063 }
1075 1064
1076 //////////////////////////////////////////////////////////////////////////////// 1065 ////////////////////////////////////////////////////////////////////////////////
1077 // LocationBarView, private: 1066 // LocationBarView, private:
1078 1067
1079 // static 1068 // static
1080 int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() { 1069 int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() {
sky 2014/04/24 03:29:02 Can we remove this too?
oshima 2014/04/25 14:16:26 Done.
1081 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? 1070 return 0;
1082 GetItemPadding() / 2 : 0;
1083 } 1071 }
1084 1072
1085 int LocationBarView::GetHorizontalEdgeThickness() const { 1073 int LocationBarView::GetHorizontalEdgeThickness() const {
1086 // In maximized popup mode, there isn't any edge. 1074 // In maximized popup mode, there isn't any edge.
1087 return (is_popup_mode_ && browser_ && browser_->window() && 1075 return (is_popup_mode_ && browser_ && browser_->window() &&
1088 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); 1076 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness();
1089 } 1077 }
1090 1078
1091 bool LocationBarView::RefreshContentSettingViews() { 1079 bool LocationBarView::RefreshContentSettingViews() {
1092 bool visibility_changed = false; 1080 bool visibility_changed = false;
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1690 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1703 const SearchModel::State& new_state) { 1691 const SearchModel::State& new_state) {
1704 const bool visible = !GetToolbarModel()->input_in_progress() && 1692 const bool visible = !GetToolbarModel()->input_in_progress() &&
1705 new_state.voice_search_supported; 1693 new_state.voice_search_supported;
1706 if (mic_search_view_->visible() != visible) { 1694 if (mic_search_view_->visible() != visible) {
1707 mic_search_view_->SetVisible(visible); 1695 mic_search_view_->SetVisible(visible);
1708 Layout(); 1696 Layout();
1709 } 1697 }
1710 } 1698 }
1711 1699
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698