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 26 matching lines...) Expand all Loading... | |
| 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_icon_view.h" | 42 #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" | 43 #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" | 44 #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" | 45 #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" | 46 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h" |
| 47 #include "chrome/browser/ui/views/location_bar/search_token_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" |
| 52 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 53 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 53 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" | 54 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
| 54 #include "chrome/browser/ui/zoom/zoom_controller.h" | 55 #include "chrome/browser/ui/zoom/zoom_controller.h" |
| 55 #include "chrome/common/chrome_notification_types.h" | 56 #include "chrome/common/chrome_notification_types.h" |
| 56 #include "chrome/common/extensions/feature_switch.h" | 57 #include "chrome/common/extensions/feature_switch.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 disposition_(CURRENT_TAB), | 171 disposition_(CURRENT_TAB), |
| 171 transition_(content::PageTransitionFromInt( | 172 transition_(content::PageTransitionFromInt( |
| 172 content::PAGE_TRANSITION_TYPED | | 173 content::PAGE_TRANSITION_TYPED | |
| 173 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 174 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
| 174 location_icon_view_(NULL), | 175 location_icon_view_(NULL), |
| 175 ev_bubble_view_(NULL), | 176 ev_bubble_view_(NULL), |
| 176 location_entry_view_(NULL), | 177 location_entry_view_(NULL), |
| 177 selected_keyword_view_(NULL), | 178 selected_keyword_view_(NULL), |
| 178 suggested_text_view_(NULL), | 179 suggested_text_view_(NULL), |
| 179 keyword_hint_view_(NULL), | 180 keyword_hint_view_(NULL), |
| 181 search_token_view_(NULL), | |
| 180 zoom_view_(NULL), | 182 zoom_view_(NULL), |
| 181 open_pdf_in_reader_view_(NULL), | 183 open_pdf_in_reader_view_(NULL), |
| 182 script_bubble_icon_view_(NULL), | 184 script_bubble_icon_view_(NULL), |
| 183 star_view_(NULL), | 185 star_view_(NULL), |
| 184 web_intents_button_view_(NULL), | 186 web_intents_button_view_(NULL), |
| 185 action_box_button_view_(NULL), | 187 action_box_button_view_(NULL), |
| 186 mode_(mode), | 188 mode_(mode), |
| 187 show_focus_rect_(false), | 189 show_focus_rect_(false), |
| 188 template_url_service_(NULL), | 190 template_url_service_(NULL), |
| 189 animation_offset_(0) { | 191 animation_offset_(0) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 profile_); | 259 profile_); |
| 258 AddChildView(selected_keyword_view_); | 260 AddChildView(selected_keyword_view_); |
| 259 selected_keyword_view_->SetFont(font_); | 261 selected_keyword_view_->SetFont(font_); |
| 260 selected_keyword_view_->SetVisible(false); | 262 selected_keyword_view_->SetVisible(false); |
| 261 | 263 |
| 262 keyword_hint_view_ = new KeywordHintView(profile_, this); | 264 keyword_hint_view_ = new KeywordHintView(profile_, this); |
| 263 AddChildView(keyword_hint_view_); | 265 AddChildView(keyword_hint_view_); |
| 264 keyword_hint_view_->SetVisible(false); | 266 keyword_hint_view_->SetVisible(false); |
| 265 keyword_hint_view_->SetFont(font_); | 267 keyword_hint_view_->SetFont(font_); |
| 266 | 268 |
| 269 search_token_view_ = new SearchTokenView(this); | |
| 270 search_token_view_->SetFont(font_); | |
| 271 AddChildView(search_token_view_); | |
| 272 search_token_view_->SetVisible(false); | |
|
Peter Kasting
2012/12/17 21:01:00
Nit: For consistency and efficiency, can you make
kuan
2012/12/20 00:26:14
Done.
| |
| 273 | |
| 267 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 274 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 268 ContentSettingImageView* content_blocked_view = | 275 ContentSettingImageView* content_blocked_view = |
| 269 new ContentSettingImageView(static_cast<ContentSettingsType>(i), | 276 new ContentSettingImageView(static_cast<ContentSettingsType>(i), |
| 270 kCSBubbleBackgroundImages, this, | 277 kCSBubbleBackgroundImages, this, |
| 271 font_, | 278 font_, |
| 272 GetColor(ToolbarModel::NONE, TEXT)); | 279 GetColor(ToolbarModel::NONE, TEXT)); |
| 273 content_setting_views_.push_back(content_blocked_view); | 280 content_setting_views_.push_back(content_blocked_view); |
| 274 AddChildView(content_blocked_view); | 281 AddChildView(content_blocked_view); |
| 275 content_blocked_view->SetVisible(false); | 282 content_blocked_view->SetVisible(false); |
| 276 } | 283 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 | 424 |
| 418 bool star_enabled = star_view_ && !model_->GetInputInProgress() && | 425 bool star_enabled = star_view_ && !model_->GetInputInProgress() && |
| 419 edit_bookmarks_enabled_.GetValue(); | 426 edit_bookmarks_enabled_.GetValue(); |
| 420 | 427 |
| 421 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 428 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
| 422 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR, | 429 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR, |
| 423 star_enabled); | 430 star_enabled); |
| 424 if (star_view_ && !extensions::FeatureSwitch::action_box()->IsEnabled()) | 431 if (star_view_ && !extensions::FeatureSwitch::action_box()->IsEnabled()) |
| 425 star_view_->SetVisible(star_enabled); | 432 star_view_->SetVisible(star_enabled); |
| 426 | 433 |
| 434 string16 search_provider; | |
| 435 if (model_->WouldReplaceSearchURLWithSearchTerms()) { | |
| 436 const TemplateURL* template_url = | |
| 437 TemplateURLServiceFactory::GetForProfile(profile_)-> | |
| 438 GetDefaultSearchProvider(); | |
| 439 if (template_url) | |
| 440 search_provider = template_url->short_name(); | |
| 441 } | |
| 442 search_token_view_->SetSearchProvider(search_provider); | |
| 443 | |
| 427 // Don't Update in app launcher mode so that the location entry does not show | 444 // Don't Update in app launcher mode so that the location entry does not show |
| 428 // a URL or security background. | 445 // a URL or security background. |
| 429 if (mode_ != APP_LAUNCHER) | 446 if (mode_ != APP_LAUNCHER) |
| 430 location_entry_->Update(tab_for_state_restoring); | 447 location_entry_->Update(tab_for_state_restoring); |
| 431 OnChanged(); | 448 OnChanged(); |
| 432 } | 449 } |
| 433 | 450 |
| 434 void LocationBarView::UpdateContentSettingsIcons() { | 451 void LocationBarView::UpdateContentSettingsIcons() { |
| 435 RefreshContentSettingViews(); | 452 RefreshContentSettingViews(); |
| 436 | 453 |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 // the added view. | 912 // the added view. |
| 896 location_bounds.Inset(0, 0, kEditInternalSpace, 0); | 913 location_bounds.Inset(0, 0, kEditInternalSpace, 0); |
| 897 LayoutView(keyword_hint_view_, kItemEditPadding, | 914 LayoutView(keyword_hint_view_, kItemEditPadding, |
| 898 AvailableWidth(max_edit_width), false, &location_bounds); | 915 AvailableWidth(max_edit_width), false, &location_bounds); |
| 899 if (!keyword_hint_view_->visible()) { | 916 if (!keyword_hint_view_->visible()) { |
| 900 // Put back the enlargement that we undid above. | 917 // Put back the enlargement that we undid above. |
| 901 location_bounds.Inset(0, 0, -kEditInternalSpace, 0); | 918 location_bounds.Inset(0, 0, -kEditInternalSpace, 0); |
| 902 } | 919 } |
| 903 } | 920 } |
| 904 | 921 |
| 922 // If |search_token_view_| has search provider and there's enough space left | |
| 923 // after query string in the omnibox, lay it out on the immediate right of the | |
| 924 // query string. | |
| 925 if (search_token_view_->HasSearchProvider()) { | |
| 926 // |entry_width| has already been enlarged by |kEditInternalSpace|, but | |
| 927 // |search_token_view_| is a trailing view, and doesn't need it to the | |
| 928 // right. As for the padding to the left, the view itself manages it. | |
|
Peter Kasting
2012/12/17 21:01:00
This isn't right, see comments in search_token_vie
kuan
2012/12/20 00:26:14
Done.
| |
| 929 location_bounds.Inset(0, 0, kEditInternalSpace, 0); | |
| 930 int pref_width = search_token_view_->GetPreferredSize().width(); | |
| 931 search_token_view_->SetVisible(pref_width < AvailableWidth(max_edit_width)); | |
|
Peter Kasting
2012/12/17 21:01:00
Use LayoutView() for calculating visibility and se
kuan
2012/12/20 00:26:14
i initially tried that, and discovered that Layout
Peter Kasting
2012/12/20 01:45:39
I suggest modifying LayoutView() to do the right t
beaudoin
2012/12/20 03:05:01
Before investing too much time in this, check out
kuan
2012/12/20 16:51:22
should i wait for philippe's refactoring cl to lan
| |
| 932 if (search_token_view_->visible()) { | |
| 933 search_token_view_->SetBounds( | |
| 934 location_bounds.right() - pref_width, | |
| 935 location_y, pref_width, location_height); | |
| 936 location_bounds.set_width(location_bounds.width() - pref_width); | |
| 937 } else { | |
| 938 // Put back the enlargement that we undid above. | |
| 939 location_bounds.Inset(0, 0, -kEditInternalSpace, 0); | |
| 940 } | |
| 941 } | |
| 942 | |
| 905 // Layout out the suggested text view right aligned to the location | 943 // 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 | 944 // 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 | 945 // 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, | 946 // suggested text. If we can't it means either the suggested text is too big, |
| 909 // or the user has scrolled. | 947 // or the user has scrolled. |
| 910 | 948 |
| 911 // TODO(sky): We could potentially combine this with the previous step to | 949 // TODO(sky): We could potentially combine this with the previous step to |
| 912 // force using minimum size if necessary, but currently the chance of showing | 950 // force using minimum size if necessary, but currently the chance of showing |
| 913 // keyword hints and suggested text is minimal and we're not confident this | 951 // keyword hints and suggested text is minimal and we're not confident this |
| 914 // is the right approach for suggested text. | 952 // is the right approach for suggested text. |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1575 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1613 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
| 1576 int total_height = | 1614 int total_height = |
| 1577 use_preferred_size ? GetPreferredSize().height() : height(); | 1615 use_preferred_size ? GetPreferredSize().height() : height(); |
| 1578 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); | 1616 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); |
| 1579 } | 1617 } |
| 1580 | 1618 |
| 1581 bool LocationBarView::HasValidSuggestText() const { | 1619 bool LocationBarView::HasValidSuggestText() const { |
| 1582 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1620 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| 1583 !suggested_text_view_->text().empty(); | 1621 !suggested_text_view_->text().empty(); |
| 1584 } | 1622 } |
| OLD | NEW |