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 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/search_engines/template_url.h" | 25 #include "chrome/browser/search_engines/template_url.h" |
| 26 #include "chrome/browser/search_engines/template_url_service.h" | 26 #include "chrome/browser/search_engines/template_url_service.h" |
| 27 #include "chrome/browser/search_engines/template_url_service_factory.h" | 27 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/browser_tabstrip.h" | 30 #include "chrome/browser/ui/browser_tabstrip.h" |
| 31 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 31 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| 32 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 32 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 33 #include "chrome/browser/ui/search/search.h" | |
| 33 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 34 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 34 #include "chrome/browser/ui/view_ids.h" | 35 #include "chrome/browser/ui/view_ids.h" |
| 35 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" | 36 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" |
| 36 #include "chrome/browser/ui/views/browser_dialogs.h" | 37 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 37 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 38 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 38 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" | 39 #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" | 40 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 40 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 41 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| 41 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 42 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.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" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 location_entry_view_(NULL), | 183 location_entry_view_(NULL), |
| 183 selected_keyword_view_(NULL), | 184 selected_keyword_view_(NULL), |
| 184 suggested_text_view_(NULL), | 185 suggested_text_view_(NULL), |
| 185 keyword_hint_view_(NULL), | 186 keyword_hint_view_(NULL), |
| 186 zoom_view_(NULL), | 187 zoom_view_(NULL), |
| 187 open_pdf_in_reader_view_(NULL), | 188 open_pdf_in_reader_view_(NULL), |
| 188 script_bubble_icon_view_(NULL), | 189 script_bubble_icon_view_(NULL), |
| 189 star_view_(NULL), | 190 star_view_(NULL), |
| 190 web_intents_button_view_(NULL), | 191 web_intents_button_view_(NULL), |
| 191 action_box_button_view_(NULL), | 192 action_box_button_view_(NULL), |
| 193 search_bubble_view_(NULL), | |
| 192 mode_(mode), | 194 mode_(mode), |
| 193 show_focus_rect_(false), | 195 show_focus_rect_(false), |
| 194 template_url_service_(NULL), | 196 template_url_service_(NULL), |
| 195 animation_offset_(0) { | 197 animation_offset_(0) { |
| 196 set_id(VIEW_ID_LOCATION_BAR); | 198 set_id(VIEW_ID_LOCATION_BAR); |
| 197 | 199 |
| 198 if (mode_ == NORMAL) { | 200 if (mode_ == NORMAL) { |
| 199 background_painter_.reset( | 201 background_painter_.reset( |
| 200 views::Painter::CreateImagePainter( | 202 views::Painter::CreateImagePainter( |
| 201 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 203 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 AddChildView(script_bubble_icon_view_); | 300 AddChildView(script_bubble_icon_view_); |
| 299 script_bubble_icon_view_->SetVisible(false); | 301 script_bubble_icon_view_->SetVisible(false); |
| 300 | 302 |
| 301 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { | 303 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { |
| 302 // Note: condition above means that the star icon is hidden in popups and in | 304 // Note: condition above means that the star icon is hidden in popups and in |
| 303 // the app launcher. | 305 // the app launcher. |
| 304 star_view_ = new StarView(command_updater_); | 306 star_view_ = new StarView(command_updater_); |
| 305 AddChildView(star_view_); | 307 AddChildView(star_view_); |
| 306 star_view_->SetVisible(true); | 308 star_view_->SetVisible(true); |
| 307 } | 309 } |
| 310 | |
| 308 if (extensions::FeatureSwitch::action_box()->IsEnabled() && | 311 if (extensions::FeatureSwitch::action_box()->IsEnabled() && |
| 309 mode_ == NORMAL && browser_) { | 312 mode_ == NORMAL && browser_) { |
| 310 action_box_button_view_ = new ActionBoxButtonView(browser_, | 313 action_box_button_view_ = new ActionBoxButtonView(browser_, |
| 311 gfx::Point(kNormalHorizontalEdgeThickness, kVerticalEdgeThickness)); | 314 gfx::Point(kNormalHorizontalEdgeThickness, kVerticalEdgeThickness)); |
| 312 AddChildView(action_box_button_view_); | 315 AddChildView(action_box_button_view_); |
| 313 | 316 |
| 314 if (star_view_) | 317 if (star_view_) |
| 315 star_view_->SetVisible(false); | 318 star_view_->SetVisible(false); |
| 316 } | 319 } |
| 317 | 320 |
| 321 if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) { | |
|
Peter Kasting
2012/12/05 21:13:20
I don't think you should check this here. Let the
kuan
2012/12/11 21:10:29
Done.
| |
| 322 search_bubble_view_ = new IconLabelBubbleView( | |
| 323 kSelectedKeywordBackgroundImages, -1, | |
| 324 GetColor(ToolbarModel::NONE, TEXT)); | |
| 325 AddChildView(search_bubble_view_); | |
| 326 search_bubble_view_->SetFont(font_); | |
| 327 search_bubble_view_->SetVisible(false); | |
| 328 } | |
| 329 | |
| 318 registrar_.Add(this, | 330 registrar_.Add(this, |
| 319 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 331 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
| 320 content::Source<Profile>(profile_)); | 332 content::Source<Profile>(profile_)); |
| 321 | 333 |
| 322 // Initialize the location entry. We do this to avoid a black flash which is | 334 // Initialize the location entry. We do this to avoid a black flash which is |
| 323 // visible when the location entry has just been initialized. | 335 // visible when the location entry has just been initialized. |
| 324 Update(NULL); | 336 Update(NULL); |
| 325 | 337 |
| 326 OnChanged(); | 338 OnChanged(); |
| 327 } | 339 } |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); | 739 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); |
| 728 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 740 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 729 i != content_setting_views_.end(); ++i) { | 741 i != content_setting_views_.end(); ++i) { |
| 730 if ((*i)->visible()) | 742 if ((*i)->visible()) |
| 731 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); | 743 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
| 732 } | 744 } |
| 733 if (web_intents_button_view_->visible()) { | 745 if (web_intents_button_view_->visible()) { |
| 734 entry_width -= web_intents_button_view_->GetPreferredSize().width() + | 746 entry_width -= web_intents_button_view_->GetPreferredSize().width() + |
| 735 GetItemPadding(); | 747 GetItemPadding(); |
| 736 } | 748 } |
| 749 if (search_bubble_view_) { | |
|
Peter Kasting
2012/12/05 21:13:20
This conditional can be removed once you make the
kuan
2012/12/11 21:10:29
Done.
| |
| 750 search_bubble_view_->SetVisible(false); | |
|
Peter Kasting
2012/12/05 21:13:20
You should be controlling the visibility of this o
kuan
2012/12/11 21:10:29
Done.
| |
| 751 if (model_->GetSecurityLevel() == ToolbarModel::SECURE && | |
|
Peter Kasting
2012/12/05 21:13:20
Nit: Again, I don't think you should check this.
kuan
2012/12/11 21:10:29
Done.
| |
| 752 model_->WouldReplaceSearchURLWithSearchTerms()) { | |
| 753 const TemplateURL* template_url = | |
| 754 TemplateURLServiceFactory::GetForProfile(profile_)-> | |
| 755 GetDefaultSearchProvider(); | |
| 756 if (template_url) { | |
| 757 search_bubble_view_->SetLabel(l10n_util::GetStringFUTF16( | |
| 758 IDS_OMNIBOX_EV_SEARCH_TEXT, template_url->short_name())); | |
| 759 search_bubble_view_->SetVisible(true); | |
| 760 entry_width -= search_bubble_view_->GetPreferredSize().width() + | |
| 761 GetItemPadding(); | |
| 762 } | |
| 763 } | |
| 764 } | |
| 737 // The gap between the edit and whatever is to its right is shortened. | 765 // The gap between the edit and whatever is to its right is shortened. |
| 738 entry_width += kEditInternalSpace; | 766 entry_width += kEditInternalSpace; |
| 739 | 767 |
| 740 // Size the EV bubble after taking star/page actions/content settings out of | 768 // Size the EV bubble after taking star/page actions/content settings out of |
| 741 // |entry_width| so we won't take too much space. | 769 // |entry_width| so we won't take too much space. |
| 742 if (ev_bubble_width) { | 770 if (ev_bubble_width) { |
| 743 // Try to elide the bubble to be no larger than half the total available | 771 // Try to elide the bubble to be no larger than half the total available |
| 744 // space, but never elide it any smaller than 150 px. | 772 // space, but never elide it any smaller than 150 px. |
| 745 static const int kMinElidedBubbleWidth = 150; | 773 static const int kMinElidedBubbleWidth = 150; |
| 746 static const double kMaxBubbleFraction = 0.5; | 774 static const double kMaxBubbleFraction = 0.5; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 offset += web_intents_button_view_->GetBuiltInHorizontalPadding(); | 888 offset += web_intents_button_view_->GetBuiltInHorizontalPadding(); |
| 861 int width = web_intents_button_view_->GetPreferredSize().width(); | 889 int width = web_intents_button_view_->GetPreferredSize().width(); |
| 862 offset -= width; | 890 offset -= width; |
| 863 web_intents_button_view_->SetBounds( | 891 web_intents_button_view_->SetBounds( |
| 864 offset, location_y + kBubbleVerticalPadding, width, | 892 offset, location_y + kBubbleVerticalPadding, width, |
| 865 web_intents_button_view_->GetPreferredSize().height()); | 893 web_intents_button_view_->GetPreferredSize().height()); |
| 866 offset -= GetItemPadding() - | 894 offset -= GetItemPadding() - |
| 867 web_intents_button_view_->GetBuiltInHorizontalPadding(); | 895 web_intents_button_view_->GetBuiltInHorizontalPadding(); |
| 868 } | 896 } |
| 869 | 897 |
| 898 // Now the search bubble view. | |
| 899 if (search_bubble_view_ && search_bubble_view_->visible()) { | |
| 900 gfx::Size size = search_bubble_view_->GetPreferredSize(); | |
| 901 offset -= size.width(); | |
| 902 search_bubble_view_->SetBounds(offset, location_y + kBubbleVerticalPadding, | |
| 903 size.width(), size.height()); | |
| 904 offset -= GetItemPadding(); | |
| 905 } | |
| 906 | |
| 870 // Now lay out items to the left of the edit field. | 907 // Now lay out items to the left of the edit field. |
| 871 if (location_icon_view_->visible()) { | 908 if (location_icon_view_->visible()) { |
| 872 location_icon_view_->SetBounds( | 909 location_icon_view_->SetBounds( |
| 873 kEdgeThickness + GetEdgeItemPadding() - | 910 kEdgeThickness + GetEdgeItemPadding() - |
| 874 location_icon_view_->GetBuiltInHorizontalPadding(), | 911 location_icon_view_->GetBuiltInHorizontalPadding(), |
| 875 location_y, location_icon_width, location_height); | 912 location_y, location_icon_width, location_height); |
| 876 offset = location_icon_view_->bounds().right() + kItemEditPadding - | 913 offset = location_icon_view_->bounds().right() + kItemEditPadding - |
| 877 location_icon_view_->GetBuiltInHorizontalPadding(); | 914 location_icon_view_->GetBuiltInHorizontalPadding(); |
| 878 } else if (ev_bubble_view_->visible()) { | 915 } else if (ev_bubble_view_->visible()) { |
| 879 ev_bubble_view_->SetBounds(kEdgeThickness + kBubbleHorizontalPadding, | 916 ev_bubble_view_->SetBounds(kEdgeThickness + kBubbleHorizontalPadding, |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1571 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1608 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
| 1572 int total_height = | 1609 int total_height = |
| 1573 use_preferred_size ? GetPreferredSize().height() : height(); | 1610 use_preferred_size ? GetPreferredSize().height() : height(); |
| 1574 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); | 1611 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); |
| 1575 } | 1612 } |
| 1576 | 1613 |
| 1577 bool LocationBarView::HasValidSuggestText() const { | 1614 bool LocationBarView::HasValidSuggestText() const { |
| 1578 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1615 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| 1579 !suggested_text_view_->text().empty(); | 1616 !suggested_text_view_->text().empty(); |
| 1580 } | 1617 } |
| OLD | NEW |