| 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 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/browser/ui/view_ids.h" | 37 #include "chrome/browser/ui/view_ids.h" |
| 38 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" | 38 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" |
| 39 #include "chrome/browser/ui/views/browser_dialogs.h" | 39 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 40 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 40 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 41 #include "chrome/browser/ui/views/location_bar/autofill_credit_card_view.h" | 41 #include "chrome/browser/ui/views/location_bar/autofill_credit_card_view.h" |
| 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" | 45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
| 46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 47 #include "chrome/browser/ui/views/location_bar/mic_search_view.h" | |
| 48 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | 47 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| 49 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 48 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 50 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 49 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 51 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h" | 50 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h" |
| 52 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 53 #include "chrome/browser/ui/views/location_bar/star_view.h" | 52 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 54 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 53 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 55 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 54 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
| 56 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 55 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 57 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" | 56 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 72 #include "ui/base/theme_provider.h" | 71 #include "ui/base/theme_provider.h" |
| 73 #include "ui/gfx/canvas.h" | 72 #include "ui/gfx/canvas.h" |
| 74 #include "ui/gfx/color_utils.h" | 73 #include "ui/gfx/color_utils.h" |
| 75 #include "ui/gfx/image/image.h" | 74 #include "ui/gfx/image/image.h" |
| 76 #include "ui/gfx/image/image_skia_operations.h" | 75 #include "ui/gfx/image/image_skia_operations.h" |
| 77 #include "ui/gfx/skia_util.h" | 76 #include "ui/gfx/skia_util.h" |
| 78 #include "ui/native_theme/native_theme.h" | 77 #include "ui/native_theme/native_theme.h" |
| 79 #include "ui/views/background.h" | 78 #include "ui/views/background.h" |
| 80 #include "ui/views/border.h" | 79 #include "ui/views/border.h" |
| 81 #include "ui/views/button_drag_utils.h" | 80 #include "ui/views/button_drag_utils.h" |
| 81 #include "ui/views/controls/button/image_button.h" |
| 82 #include "ui/views/controls/label.h" | 82 #include "ui/views/controls/label.h" |
| 83 #include "ui/views/controls/textfield/textfield.h" | 83 #include "ui/views/controls/textfield/textfield.h" |
| 84 #include "ui/views/widget/widget.h" | 84 #include "ui/views/widget/widget.h" |
| 85 #include "ui/views/window/non_client_view.h" | 85 #include "ui/views/window/non_client_view.h" |
| 86 | 86 |
| 87 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
| 88 #include "base/win/scoped_hdc.h" | 88 #include "base/win/scoped_hdc.h" |
| 89 #include "base/win/scoped_select_object.h" | 89 #include "base/win/scoped_select_object.h" |
| 90 #include "ui/native_theme/native_theme_win.h" | 90 #include "ui/native_theme/native_theme_win.h" |
| 91 #endif | 91 #endif |
| (...skipping 128 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::InitTouchableLocationBarChildView(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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 316 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
| 308 suggested_text_view_->SetVisible(false); | 317 suggested_text_view_->SetVisible(false); |
| 309 AddChildView(suggested_text_view_); | 318 AddChildView(suggested_text_view_); |
| 310 | 319 |
| 311 keyword_hint_view_ = new KeywordHintView( | 320 keyword_hint_view_ = new KeywordHintView( |
| 312 profile_, font, font_y_offset, | 321 profile_, font, font_y_offset, |
| 313 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), | 322 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), |
| 314 background_color); | 323 background_color); |
| 315 AddChildView(keyword_hint_view_); | 324 AddChildView(keyword_hint_view_); |
| 316 | 325 |
| 317 mic_search_view_ = new MicSearchView(this); | 326 mic_search_view_ = new views::ImageButton(this); |
| 327 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); |
| 328 mic_search_view_->set_accessibility_focusable(true); |
| 329 mic_search_view_->SetTooltipText( |
| 330 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); |
| 331 mic_search_view_->SetImage( |
| 332 views::Button::STATE_NORMAL, |
| 333 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 334 IDR_OMNIBOX_MIC_SEARCH)); |
| 335 mic_search_view_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 336 views::ImageButton::ALIGN_MIDDLE); |
| 318 mic_search_view_->SetVisible(false); | 337 mic_search_view_->SetVisible(false); |
| 338 InitTouchableLocationBarChildView(mic_search_view_); |
| 319 AddChildView(mic_search_view_); | 339 AddChildView(mic_search_view_); |
| 320 | 340 |
| 321 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 341 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 322 ContentSettingImageView* content_blocked_view = | 342 ContentSettingImageView* content_blocked_view = |
| 323 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, | 343 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, |
| 324 bubble_font, bubble_font_y_offset, | 344 bubble_font, bubble_font_y_offset, |
| 325 text_color, background_color); | 345 text_color, background_color); |
| 326 content_setting_views_.push_back(content_blocked_view); | 346 content_setting_views_.push_back(content_blocked_view); |
| 327 content_blocked_view->SetVisible(false); | 347 content_blocked_view->SetVisible(false); |
| 328 AddChildView(content_blocked_view); | 348 AddChildView(content_blocked_view); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 } else if (model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { | 729 } else if (model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { |
| 710 ev_bubble_view_->SetLabel(model_->GetEVCertName()); | 730 ev_bubble_view_->SetLabel(model_->GetEVCertName()); |
| 711 // The largest fraction of the omnibox that can be taken by the EV bubble. | 731 // The largest fraction of the omnibox that can be taken by the EV bubble. |
| 712 const double kMaxBubbleFraction = 0.5; | 732 const double kMaxBubbleFraction = 0.5; |
| 713 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, | 733 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
| 714 kMaxBubbleFraction, kBubblePadding, | 734 kMaxBubbleFraction, kBubblePadding, |
| 715 item_padding, 0, ev_bubble_view_); | 735 item_padding, 0, ev_bubble_view_); |
| 716 } else { | 736 } else { |
| 717 leading_decorations.AddDecoration( | 737 leading_decorations.AddDecoration( |
| 718 vertical_edge_thickness(), location_height, | 738 vertical_edge_thickness(), location_height, |
| 719 location_icon_view_->GetBuiltInHorizontalPadding(), | 739 GetBuiltInHorizontalPaddingForChildViews(), |
| 720 location_icon_view_); | 740 location_icon_view_); |
| 721 } | 741 } |
| 722 | 742 |
| 723 if (star_view_ && star_view_->visible()) { | 743 if (star_view_ && star_view_->visible()) { |
| 724 trailing_decorations.AddDecoration( | 744 trailing_decorations.AddDecoration( |
| 725 vertical_edge_thickness(), location_height, | 745 vertical_edge_thickness(), location_height, |
| 726 star_view_->GetBuiltInHorizontalPadding(), star_view_); | 746 GetBuiltInHorizontalPaddingForChildViews(), star_view_); |
| 727 } | 747 } |
| 728 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) { | 748 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) { |
| 729 trailing_decorations.AddDecoration( | 749 trailing_decorations.AddDecoration( |
| 730 vertical_edge_thickness(), location_height, | 750 vertical_edge_thickness(), location_height, |
| 731 script_bubble_icon_view_->GetBuiltInHorizontalPadding(), | 751 GetBuiltInHorizontalPaddingForChildViews(), |
| 732 script_bubble_icon_view_); | 752 script_bubble_icon_view_); |
| 733 } | 753 } |
| 734 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { | 754 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { |
| 735 trailing_decorations.AddDecoration( | 755 trailing_decorations.AddDecoration( |
| 736 vertical_edge_thickness(), location_height, | 756 vertical_edge_thickness(), location_height, |
| 737 open_pdf_in_reader_view_->GetBuiltInHorizontalPadding(), | 757 GetBuiltInHorizontalPaddingForChildViews(), |
| 738 open_pdf_in_reader_view_); | 758 open_pdf_in_reader_view_); |
| 739 } | 759 } |
| 740 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 760 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 741 i != page_action_views_.end(); ++i) { | 761 i != page_action_views_.end(); ++i) { |
| 742 if ((*i)->visible()) { | 762 if ((*i)->visible()) { |
| 743 trailing_decorations.AddDecoration( | 763 trailing_decorations.AddDecoration( |
| 744 vertical_edge_thickness(), location_height, | 764 vertical_edge_thickness(), location_height, |
| 745 (*i)->GetBuiltInHorizontalPadding(), (*i)); | 765 GetBuiltInHorizontalPaddingForChildViews(), (*i)); |
| 746 } | 766 } |
| 747 } | 767 } |
| 748 if (zoom_view_->visible()) { | 768 if (zoom_view_->visible()) { |
| 749 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 769 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
| 750 location_height, 0, zoom_view_); | 770 location_height, 0, zoom_view_); |
| 751 } | 771 } |
| 752 for (ContentSettingViews::const_reverse_iterator i( | 772 for (ContentSettingViews::const_reverse_iterator i( |
| 753 content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 773 content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
| 754 ++i) { | 774 ++i) { |
| 755 if ((*i)->visible()) { | 775 if ((*i)->visible()) { |
| 756 trailing_decorations.AddDecoration( | 776 trailing_decorations.AddDecoration( |
| 757 bubble_location_y, bubble_height, false, 0, item_padding, | 777 bubble_location_y, bubble_height, false, 0, item_padding, |
| 758 item_padding, (*i)->GetBuiltInHorizontalPadding(), (*i)); | 778 item_padding, GetBuiltInHorizontalPaddingForChildViews(), (*i)); |
| 759 } | 779 } |
| 760 } | 780 } |
| 761 if (autofill_credit_card_view_->visible()) { | 781 if (autofill_credit_card_view_->visible()) { |
| 762 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 782 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
| 763 location_height, 0, | 783 location_height, 0, |
| 764 autofill_credit_card_view_); | 784 autofill_credit_card_view_); |
| 765 } | 785 } |
| 766 if (mic_search_view_->visible()) { | 786 if (mic_search_view_->visible()) { |
| 767 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 787 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
| 768 location_height, 0, mic_search_view_); | 788 location_height, 0, mic_search_view_); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 } | 1091 } |
| 1072 | 1092 |
| 1073 InstantController* LocationBarView::GetInstant() { | 1093 InstantController* LocationBarView::GetInstant() { |
| 1074 return delegate_->GetInstant(); | 1094 return delegate_->GetInstant(); |
| 1075 } | 1095 } |
| 1076 | 1096 |
| 1077 WebContents* LocationBarView::GetWebContents() const { | 1097 WebContents* LocationBarView::GetWebContents() const { |
| 1078 return delegate_->GetWebContents(); | 1098 return delegate_->GetWebContents(); |
| 1079 } | 1099 } |
| 1080 | 1100 |
| 1101 // static |
| 1102 int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() { |
| 1103 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? |
| 1104 GetItemPadding() / 2 : 0; |
| 1105 } |
| 1106 |
| 1081 int LocationBarView::GetHorizontalEdgeThickness() const { | 1107 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 1082 // In maximized popup mode, there isn't any edge. | 1108 // In maximized popup mode, there isn't any edge. |
| 1083 return (is_popup_mode_ && browser_ && browser_->window() && | 1109 return (is_popup_mode_ && browser_ && browser_->window() && |
| 1084 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); | 1110 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); |
| 1085 } | 1111 } |
| 1086 | 1112 |
| 1087 void LocationBarView::RefreshContentSettingViews() { | 1113 void LocationBarView::RefreshContentSettingViews() { |
| 1088 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 1114 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 1089 i != content_setting_views_.end(); ++i) { | 1115 i != content_setting_views_.end(); ++i) { |
| 1090 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); | 1116 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 const ToolbarModel::SecurityLevel security_level = | 1252 const ToolbarModel::SecurityLevel security_level = |
| 1227 model_->GetSecurityLevel(false); | 1253 model_->GetSecurityLevel(false); |
| 1228 const SkColor text_color = GetColor(security_level, TEXT); | 1254 const SkColor text_color = GetColor(security_level, TEXT); |
| 1229 const SkColor background_color = GetColor(security_level, BACKGROUND); | 1255 const SkColor background_color = GetColor(security_level, BACKGROUND); |
| 1230 | 1256 |
| 1231 for (PageActionViews::const_iterator | 1257 for (PageActionViews::const_iterator |
| 1232 page_action_view = page_action_views_.begin(); | 1258 page_action_view = page_action_views_.begin(); |
| 1233 page_action_view != page_action_views_.end(); | 1259 page_action_view != page_action_views_.end(); |
| 1234 ++page_action_view) { | 1260 ++page_action_view) { |
| 1235 gfx::Rect bounds = (*page_action_view)->bounds(); | 1261 gfx::Rect bounds = (*page_action_view)->bounds(); |
| 1236 int horizontal_padding = GetItemPadding() - | 1262 int horizontal_padding = |
| 1237 (*page_action_view)->GetBuiltInHorizontalPadding(); | 1263 GetItemPadding() - GetBuiltInHorizontalPaddingForChildViews(); |
| 1238 // Make the bounding rectangle include the whole vertical range of the | 1264 // Make the bounding rectangle include the whole vertical range of the |
| 1239 // location bar, and the mid-point pixels between adjacent page actions. | 1265 // location bar, and the mid-point pixels between adjacent page actions. |
| 1240 // | 1266 // |
| 1241 // For odd horizontal_paddings, "horizontal_padding + 1" includes the | 1267 // For odd horizontal_paddings, "horizontal_padding + 1" includes the |
| 1242 // mid-point between two page actions in the bounding rectangle. For even | 1268 // mid-point between two page actions in the bounding rectangle. For even |
| 1243 // paddings, the +1 is dropped, which is right since there is no pixel at | 1269 // paddings, the +1 is dropped, which is right since there is no pixel at |
| 1244 // the mid-point. | 1270 // the mid-point. |
| 1245 bounds.Inset(-(horizontal_padding + 1) / 2, 0); | 1271 bounds.Inset(-(horizontal_padding + 1) / 2, 0); |
| 1246 location_bar_util::PaintExtensionActionBackground( | 1272 location_bar_util::PaintExtensionActionBackground( |
| 1247 *(*page_action_view)->image_view()->page_action(), | 1273 *(*page_action_view)->image_view()->page_action(), |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1528 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
| 1503 int total_height = | 1529 int total_height = |
| 1504 use_preferred_size ? GetPreferredSize().height() : height(); | 1530 use_preferred_size ? GetPreferredSize().height() : height(); |
| 1505 return std::max(total_height - (vertical_edge_thickness() * 2), 0); | 1531 return std::max(total_height - (vertical_edge_thickness() * 2), 0); |
| 1506 } | 1532 } |
| 1507 | 1533 |
| 1508 bool LocationBarView::HasValidSuggestText() const { | 1534 bool LocationBarView::HasValidSuggestText() const { |
| 1509 return suggested_text_view_->visible() && | 1535 return suggested_text_view_->visible() && |
| 1510 !suggested_text_view_->size().IsEmpty(); | 1536 !suggested_text_view_->size().IsEmpty(); |
| 1511 } | 1537 } |
| OLD | NEW |