Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 browser_->search_model()->AddObserver(this); | 220 browser_->search_model()->AddObserver(this); |
| 221 } | 221 } |
| 222 | 222 |
| 223 LocationBarView::~LocationBarView() { | 223 LocationBarView::~LocationBarView() { |
| 224 if (template_url_service_) | 224 if (template_url_service_) |
| 225 template_url_service_->RemoveObserver(this); | 225 template_url_service_->RemoveObserver(this); |
| 226 if (browser_) | 226 if (browser_) |
| 227 browser_->search_model()->RemoveObserver(this); | 227 browser_->search_model()->RemoveObserver(this); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // static | |
| 231 void LocationBarView::InitTouchableLocationBarView(views::View* view) { | |
| 232 int horizontal_padding = GetBuiltInHorizontalPaddingForChildViews(); | |
| 233 if (horizontal_padding != 0) { | |
| 234 view->set_border(views::Border::CreateEmptyBorder( | |
| 235 3, horizontal_padding, 3, horizontal_padding)); | |
| 236 } | |
| 237 } | |
| 238 | |
| 230 void LocationBarView::Init() { | 239 void LocationBarView::Init() { |
| 231 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're | 240 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're |
| 232 // not prepared for that. | 241 // not prepared for that. |
| 233 DCHECK(GetWidget()); | 242 DCHECK(GetWidget()); |
| 234 | 243 |
| 235 location_icon_view_ = new LocationIconView(this); | 244 location_icon_view_ = new LocationIconView(this); |
| 236 location_icon_view_->set_drag_controller(this); | 245 location_icon_view_->set_drag_controller(this); |
| 237 AddChildView(location_icon_view_); | 246 AddChildView(location_icon_view_); |
| 238 | 247 |
| 239 // Determine the main font. | 248 // Determine the main font. |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 } else if (model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { | 718 } else if (model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { |
| 710 ev_bubble_view_->SetLabel(model_->GetEVCertName()); | 719 ev_bubble_view_->SetLabel(model_->GetEVCertName()); |
| 711 // The largest fraction of the omnibox that can be taken by the EV bubble. | 720 // The largest fraction of the omnibox that can be taken by the EV bubble. |
| 712 const double kMaxBubbleFraction = 0.5; | 721 const double kMaxBubbleFraction = 0.5; |
| 713 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, | 722 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
| 714 kMaxBubbleFraction, kBubblePadding, | 723 kMaxBubbleFraction, kBubblePadding, |
| 715 item_padding, 0, ev_bubble_view_); | 724 item_padding, 0, ev_bubble_view_); |
| 716 } else { | 725 } else { |
| 717 leading_decorations.AddDecoration( | 726 leading_decorations.AddDecoration( |
| 718 vertical_edge_thickness(), location_height, | 727 vertical_edge_thickness(), location_height, |
| 719 location_icon_view_->GetBuiltInHorizontalPadding(), | 728 GetBuiltInHorizontalPaddingForChildViews(), |
| 720 location_icon_view_); | 729 location_icon_view_); |
| 721 } | 730 } |
| 722 | 731 |
| 723 if (star_view_ && star_view_->visible()) { | 732 if (star_view_ && star_view_->visible()) { |
| 724 trailing_decorations.AddDecoration( | 733 trailing_decorations.AddDecoration( |
| 725 vertical_edge_thickness(), location_height, | 734 vertical_edge_thickness(), location_height, |
| 726 star_view_->GetBuiltInHorizontalPadding(), star_view_); | 735 GetBuiltInHorizontalPaddingForChildViews(), star_view_); |
| 727 } | 736 } |
| 728 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) { | 737 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) { |
| 729 trailing_decorations.AddDecoration( | 738 trailing_decorations.AddDecoration( |
| 730 vertical_edge_thickness(), location_height, | 739 vertical_edge_thickness(), location_height, |
| 731 script_bubble_icon_view_->GetBuiltInHorizontalPadding(), | 740 GetBuiltInHorizontalPaddingForChildViews(), |
| 732 script_bubble_icon_view_); | 741 script_bubble_icon_view_); |
| 733 } | 742 } |
| 734 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { | 743 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { |
| 735 trailing_decorations.AddDecoration( | 744 trailing_decorations.AddDecoration( |
| 736 vertical_edge_thickness(), location_height, | 745 vertical_edge_thickness(), location_height, |
| 737 open_pdf_in_reader_view_->GetBuiltInHorizontalPadding(), | 746 GetBuiltInHorizontalPaddingForChildViews(), |
| 738 open_pdf_in_reader_view_); | 747 open_pdf_in_reader_view_); |
| 739 } | 748 } |
| 740 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 749 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 741 i != page_action_views_.end(); ++i) { | 750 i != page_action_views_.end(); ++i) { |
| 742 if ((*i)->visible()) { | 751 if ((*i)->visible()) { |
| 743 trailing_decorations.AddDecoration( | 752 trailing_decorations.AddDecoration( |
| 744 vertical_edge_thickness(), location_height, | 753 vertical_edge_thickness(), location_height, |
| 745 (*i)->GetBuiltInHorizontalPadding(), (*i)); | 754 GetBuiltInHorizontalPaddingForChildViews(), (*i)); |
| 746 } | 755 } |
| 747 } | 756 } |
| 748 if (zoom_view_->visible()) { | 757 if (zoom_view_->visible()) { |
| 749 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 758 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
| 750 location_height, 0, zoom_view_); | 759 location_height, 0, zoom_view_); |
| 751 } | 760 } |
| 752 for (ContentSettingViews::const_reverse_iterator i( | 761 for (ContentSettingViews::const_reverse_iterator i( |
| 753 content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 762 content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
| 754 ++i) { | 763 ++i) { |
| 755 if ((*i)->visible()) { | 764 if ((*i)->visible()) { |
| 756 trailing_decorations.AddDecoration( | 765 trailing_decorations.AddDecoration( |
| 757 bubble_location_y, bubble_height, false, 0, item_padding, | 766 bubble_location_y, bubble_height, false, 0, item_padding, |
| 758 item_padding, (*i)->GetBuiltInHorizontalPadding(), (*i)); | 767 item_padding, GetBuiltInHorizontalPaddingForChildViews(), (*i)); |
| 759 } | 768 } |
| 760 } | 769 } |
| 761 if (autofill_credit_card_view_->visible()) { | 770 if (autofill_credit_card_view_->visible()) { |
| 762 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 771 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
| 763 location_height, 0, | 772 location_height, 0, |
| 764 autofill_credit_card_view_); | 773 autofill_credit_card_view_); |
| 765 } | 774 } |
| 766 if (mic_search_view_->visible()) { | 775 if (mic_search_view_->visible()) { |
| 767 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 776 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
| 768 location_height, 0, mic_search_view_); | 777 location_height, 0, mic_search_view_); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1075 } | 1084 } |
| 1076 | 1085 |
| 1077 WebContents* LocationBarView::GetWebContents() const { | 1086 WebContents* LocationBarView::GetWebContents() const { |
| 1078 return delegate_->GetWebContents(); | 1087 return delegate_->GetWebContents(); |
| 1079 } | 1088 } |
| 1080 | 1089 |
| 1081 gfx::Rect LocationBarView::GetOmniboxBounds() const { | 1090 gfx::Rect LocationBarView::GetOmniboxBounds() const { |
| 1082 return bounds(); | 1091 return bounds(); |
| 1083 } | 1092 } |
| 1084 | 1093 |
| 1094 // static | |
| 1095 int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() { | |
| 1096 return ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? GetItemPadding() / 2 : 0; | |
|
Peter Kasting
2013/08/06 20:32:42
Nit: Parens around binary subexpr
tfarina
2013/08/07 18:42:53
Done.
tfarina
2013/08/07 18:42:53
Done.
| |
| 1097 } | |
| 1098 | |
| 1085 int LocationBarView::GetHorizontalEdgeThickness() const { | 1099 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 1086 // In maximized popup mode, there isn't any edge. | 1100 // In maximized popup mode, there isn't any edge. |
| 1087 return (is_popup_mode_ && browser_ && browser_->window() && | 1101 return (is_popup_mode_ && browser_ && browser_->window() && |
| 1088 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); | 1102 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); |
| 1089 } | 1103 } |
| 1090 | 1104 |
| 1091 void LocationBarView::RefreshContentSettingViews() { | 1105 void LocationBarView::RefreshContentSettingViews() { |
| 1092 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 1106 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 1093 i != content_setting_views_.end(); ++i) { | 1107 i != content_setting_views_.end(); ++i) { |
| 1094 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); | 1108 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 const ToolbarModel::SecurityLevel security_level = | 1244 const ToolbarModel::SecurityLevel security_level = |
| 1231 model_->GetSecurityLevel(false); | 1245 model_->GetSecurityLevel(false); |
| 1232 const SkColor text_color = GetColor(security_level, TEXT); | 1246 const SkColor text_color = GetColor(security_level, TEXT); |
| 1233 const SkColor background_color = GetColor(security_level, BACKGROUND); | 1247 const SkColor background_color = GetColor(security_level, BACKGROUND); |
| 1234 | 1248 |
| 1235 for (PageActionViews::const_iterator | 1249 for (PageActionViews::const_iterator |
| 1236 page_action_view = page_action_views_.begin(); | 1250 page_action_view = page_action_views_.begin(); |
| 1237 page_action_view != page_action_views_.end(); | 1251 page_action_view != page_action_views_.end(); |
| 1238 ++page_action_view) { | 1252 ++page_action_view) { |
| 1239 gfx::Rect bounds = (*page_action_view)->bounds(); | 1253 gfx::Rect bounds = (*page_action_view)->bounds(); |
| 1240 int horizontal_padding = GetItemPadding() - | 1254 int horizontal_padding = |
| 1241 (*page_action_view)->GetBuiltInHorizontalPadding(); | 1255 GetItemPadding() - GetBuiltInHorizontalPaddingForChildViews(); |
| 1242 // Make the bounding rectangle include the whole vertical range of the | 1256 // Make the bounding rectangle include the whole vertical range of the |
| 1243 // location bar, and the mid-point pixels between adjacent page actions. | 1257 // location bar, and the mid-point pixels between adjacent page actions. |
| 1244 // | 1258 // |
| 1245 // For odd horizontal_paddings, "horizontal_padding + 1" includes the | 1259 // For odd horizontal_paddings, "horizontal_padding + 1" includes the |
| 1246 // mid-point between two page actions in the bounding rectangle. For even | 1260 // mid-point between two page actions in the bounding rectangle. For even |
| 1247 // paddings, the +1 is dropped, which is right since there is no pixel at | 1261 // paddings, the +1 is dropped, which is right since there is no pixel at |
| 1248 // the mid-point. | 1262 // the mid-point. |
| 1249 bounds.Inset(-(horizontal_padding + 1) / 2, 0); | 1263 bounds.Inset(-(horizontal_padding + 1) / 2, 0); |
| 1250 location_bar_util::PaintExtensionActionBackground( | 1264 location_bar_util::PaintExtensionActionBackground( |
| 1251 *(*page_action_view)->image_view()->page_action(), | 1265 *(*page_action_view)->image_view()->page_action(), |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1506 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1520 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
| 1507 int total_height = | 1521 int total_height = |
| 1508 use_preferred_size ? GetPreferredSize().height() : height(); | 1522 use_preferred_size ? GetPreferredSize().height() : height(); |
| 1509 return std::max(total_height - (vertical_edge_thickness() * 2), 0); | 1523 return std::max(total_height - (vertical_edge_thickness() * 2), 0); |
| 1510 } | 1524 } |
| 1511 | 1525 |
| 1512 bool LocationBarView::HasValidSuggestText() const { | 1526 bool LocationBarView::HasValidSuggestText() const { |
| 1513 return suggested_text_view_->visible() && | 1527 return suggested_text_view_->visible() && |
| 1514 !suggested_text_view_->size().IsEmpty(); | 1528 !suggested_text_view_->size().IsEmpty(); |
| 1515 } | 1529 } |
| OLD | NEW |