| 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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 using content::WebContents; | 100 using content::WebContents; |
| 101 using views::View; | 101 using views::View; |
| 102 | 102 |
| 103 namespace { | 103 namespace { |
| 104 | 104 |
| 105 // The border color for MD windows, as well as non-MD popup windows. | 105 // The border color for MD windows, as well as non-MD popup windows. |
| 106 const SkColor kBorderColor = SkColorSetA(SK_ColorBLACK, 0x4D); | 106 const SkColor kBorderColor = SkColorSetA(SK_ColorBLACK, 0x4D); |
| 107 | 107 |
| 108 int GetEditLeadingInternalSpace() { | 108 int GetEditLeadingInternalSpace() { |
| 109 // The textfield has 1 px of whitespace before the text in the RTL case only. | 109 // The textfield has 1 px of whitespace before the text. |
| 110 if (ui::MaterialDesignController::IsModeMaterial()) |
| 111 return 1; |
| 112 |
| 113 // For legacy reasons, we only apply this in the RTL case in pre-MD. |
| 110 return base::i18n::IsRTL() ? 1 : 0; | 114 return base::i18n::IsRTL() ? 1 : 0; |
| 111 } | 115 } |
| 112 | 116 |
| 113 } // namespace | 117 } // namespace |
| 114 | 118 |
| 115 | 119 |
| 116 // LocationBarView ----------------------------------------------------------- | 120 // LocationBarView ----------------------------------------------------------- |
| 117 | 121 |
| 118 // static | 122 // static |
| 119 const char LocationBarView::kViewClassName[] = "LocationBarView"; | 123 const char LocationBarView::kViewClassName[] = "LocationBarView"; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); | 215 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); |
| 212 font_list = font_list.DeriveWithHeightUpperBound(location_height); | 216 font_list = font_list.DeriveWithHeightUpperBound(location_height); |
| 213 | 217 |
| 214 // Determine the font for use inside the bubbles. | 218 // Determine the font for use inside the bubbles. |
| 215 const int bubble_padding = | 219 const int bubble_padding = |
| 216 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + | 220 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + |
| 217 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); | 221 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); |
| 218 const int bubble_height = location_height - (bubble_padding * 2); | 222 const int bubble_height = location_height - (bubble_padding * 2); |
| 219 gfx::FontList bubble_font_list = | 223 gfx::FontList bubble_font_list = |
| 220 font_list.DeriveWithHeightUpperBound(bubble_height); | 224 font_list.DeriveWithHeightUpperBound(bubble_height); |
| 225 gfx::FontList chip_font_list = ui::MaterialDesignController::IsModeMaterial() |
| 226 ? font_list |
| 227 : bubble_font_list; |
| 221 | 228 |
| 222 const SkColor background_color = GetColor(BACKGROUND); | 229 const SkColor background_color = GetColor(BACKGROUND); |
| 223 location_icon_view_ = | 230 location_icon_view_ = |
| 224 new LocationIconView(bubble_font_list, background_color, this); | 231 new LocationIconView(chip_font_list, background_color, this); |
| 225 location_icon_view_->set_drag_controller(this); | 232 location_icon_view_->set_drag_controller(this); |
| 226 AddChildView(location_icon_view_); | 233 AddChildView(location_icon_view_); |
| 227 | 234 |
| 228 // Initialize the Omnibox view. | 235 // Initialize the Omnibox view. |
| 229 omnibox_view_ = new OmniboxViewViews( | 236 omnibox_view_ = new OmniboxViewViews( |
| 230 this, profile(), command_updater(), is_popup_mode_, this, font_list); | 237 this, profile(), command_updater(), is_popup_mode_, this, font_list); |
| 231 omnibox_view_->Init(); | 238 omnibox_view_->Init(); |
| 232 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); | 239 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); |
| 233 AddChildView(omnibox_view_); | 240 AddChildView(omnibox_view_); |
| 234 | 241 |
| 235 // Initialize the inline autocomplete view which is visible only when IME is | 242 // Initialize the inline autocomplete view which is visible only when IME is |
| 236 // turned on. Use the same font with the omnibox and highlighted background. | 243 // turned on. Use the same font with the omnibox and highlighted background. |
| 237 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); | 244 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); |
| 238 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 245 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 239 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 246 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
| 240 ime_inline_autocomplete_view_->set_background( | 247 ime_inline_autocomplete_view_->set_background( |
| 241 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 248 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
| 242 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 249 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
| 243 ime_inline_autocomplete_view_->SetEnabledColor( | 250 ime_inline_autocomplete_view_->SetEnabledColor( |
| 244 GetNativeTheme()->GetSystemColor( | 251 GetNativeTheme()->GetSystemColor( |
| 245 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 252 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 246 ime_inline_autocomplete_view_->SetVisible(false); | 253 ime_inline_autocomplete_view_->SetVisible(false); |
| 247 AddChildView(ime_inline_autocomplete_view_); | 254 AddChildView(ime_inline_autocomplete_view_); |
| 248 | 255 |
| 249 const SkColor selected_text_color = GetColor(TEXT); | 256 const SkColor selected_text_color = GetColor(TEXT); |
| 250 selected_keyword_view_ = new SelectedKeywordView( | 257 selected_keyword_view_ = new SelectedKeywordView( |
| 251 bubble_font_list, selected_text_color, background_color, profile()); | 258 chip_font_list, selected_text_color, background_color, profile()); |
| 252 AddChildView(selected_keyword_view_); | 259 AddChildView(selected_keyword_view_); |
| 253 | 260 |
| 254 suggested_text_view_ = new views::Label(base::string16(), font_list); | 261 suggested_text_view_ = new views::Label(base::string16(), font_list); |
| 255 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 262 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 256 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 263 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
| 257 suggested_text_view_->SetEnabledColor( | 264 suggested_text_view_->SetEnabledColor( |
| 258 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); | 265 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); |
| 259 suggested_text_view_->SetVisible(false); | 266 suggested_text_view_->SetVisible(false); |
| 260 AddChildView(suggested_text_view_); | 267 AddChildView(suggested_text_view_); |
| 261 | 268 |
| 262 keyword_hint_view_ = new KeywordHintView( | 269 keyword_hint_view_ = new KeywordHintView( |
| 263 profile(), font_list, bubble_font_list, location_height, | 270 profile(), font_list, bubble_font_list, location_height, |
| 264 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); | 271 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); |
| 265 AddChildView(keyword_hint_view_); | 272 AddChildView(keyword_hint_view_); |
| 266 | 273 |
| 267 ScopedVector<ContentSettingImageModel> models = | 274 ScopedVector<ContentSettingImageModel> models = |
| 268 ContentSettingImageModel::GenerateContentSettingImageModels(); | 275 ContentSettingImageModel::GenerateContentSettingImageModels(); |
| 269 for (ContentSettingImageModel* model : models.get()) { | 276 for (ContentSettingImageModel* model : models.get()) { |
| 270 // ContentSettingImageView takes ownership of its model. | 277 // ContentSettingImageView takes ownership of its model. |
| 271 ContentSettingImageView* image_view = new ContentSettingImageView( | 278 ContentSettingImageView* image_view = new ContentSettingImageView( |
| 272 model, this, bubble_font_list, background_color); | 279 model, this, chip_font_list, background_color); |
| 273 content_setting_views_.push_back(image_view); | 280 content_setting_views_.push_back(image_view); |
| 274 image_view->SetVisible(false); | 281 image_view->SetVisible(false); |
| 275 AddChildView(image_view); | 282 AddChildView(image_view); |
| 276 } | 283 } |
| 277 models.weak_clear(); | 284 models.weak_clear(); |
| 278 | 285 |
| 279 zoom_view_ = new ZoomView(delegate_); | 286 zoom_view_ = new ZoomView(delegate_); |
| 280 AddChildView(zoom_view_); | 287 AddChildView(zoom_view_); |
| 281 | 288 |
| 282 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); | 289 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 330 |
| 324 case SELECTED_TEXT: | 331 case SELECTED_TEXT: |
| 325 return native_theme->GetSystemColor( | 332 return native_theme->GetSystemColor( |
| 326 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 333 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
| 327 | 334 |
| 328 case DEEMPHASIZED_TEXT: | 335 case DEEMPHASIZED_TEXT: |
| 329 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); | 336 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); |
| 330 | 337 |
| 331 case EV_BUBBLE_TEXT_AND_BORDER: | 338 case EV_BUBBLE_TEXT_AND_BORDER: |
| 332 return ui::MaterialDesignController::IsModeMaterial() | 339 return ui::MaterialDesignController::IsModeMaterial() |
| 333 ? gfx::kGoogleGreen700 | 340 ? GetSecureTextColor( |
| 341 GetToolbarModel()->GetSecurityLevel(false)) |
| 334 : SkColorSetRGB(7, 149, 0); | 342 : SkColorSetRGB(7, 149, 0); |
| 335 } | 343 } |
| 336 NOTREACHED(); | 344 NOTREACHED(); |
| 337 return gfx::kPlaceholderColor; | 345 return gfx::kPlaceholderColor; |
| 338 } | 346 } |
| 339 | 347 |
| 340 SkColor LocationBarView::GetSecureTextColor( | 348 SkColor LocationBarView::GetSecureTextColor( |
| 341 security_state::SecurityStateModel::SecurityLevel security_level) const { | 349 security_state::SecurityStateModel::SecurityLevel security_level) const { |
| 342 if (security_level == | 350 if (security_level == |
| 343 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { | 351 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { |
| 344 return GetColor(DEEMPHASIZED_TEXT); | 352 return GetColor(DEEMPHASIZED_TEXT); |
| 345 } | 353 } |
| 346 | 354 |
| 347 SkColor text_color = GetColor(TEXT); | 355 SkColor text_color = GetColor(TEXT); |
| 348 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || | 356 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || |
| 349 (security_level == security_state::SecurityStateModel::SECURE) || | 357 (security_level == security_state::SecurityStateModel::SECURE) || |
| 350 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { | 358 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { |
| 351 const bool md = ui::MaterialDesignController::IsModeMaterial(); | 359 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 352 if (md && color_utils::IsDark(GetColor(BACKGROUND))) | 360 if (color_utils::IsDark(GetColor(BACKGROUND))) |
| 353 return text_color; | 361 return text_color; |
| 354 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) | 362 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) |
| 355 text_color = md ? gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0); | 363 text_color = gfx::kGoogleRed700; |
| 356 else | 364 else |
| 365 text_color = gfx::kGoogleGreen700; |
| 366 } else if (security_level == |
| 367 security_state::SecurityStateModel::SECURITY_ERROR) { |
| 368 text_color = SkColorSetRGB(162, 0, 0); |
| 369 } else { |
| 357 text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); | 370 text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); |
| 371 } |
| 358 } | 372 } |
| 359 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); | 373 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); |
| 360 } | 374 } |
| 361 | 375 |
| 362 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 376 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 363 DCHECK(zoom_view_); | 377 DCHECK(zoom_view_); |
| 364 if (RefreshZoomView()) { | 378 if (RefreshZoomView()) { |
| 365 Layout(); | 379 Layout(); |
| 366 SchedulePaint(); | 380 SchedulePaint(); |
| 367 } | 381 } |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); | 856 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); |
| 843 } | 857 } |
| 844 | 858 |
| 845 void LocationBarView::RefreshLocationIcon() { | 859 void LocationBarView::RefreshLocationIcon() { |
| 846 // |omnibox_view_| may not be ready yet if Init() has not been called. The | 860 // |omnibox_view_| may not be ready yet if Init() has not been called. The |
| 847 // icon will be set soon by OnChanged(). | 861 // icon will be set soon by OnChanged(). |
| 848 if (!omnibox_view_) | 862 if (!omnibox_view_) |
| 849 return; | 863 return; |
| 850 | 864 |
| 851 if (ui::MaterialDesignController::IsModeMaterial()) { | 865 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 852 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 853 const int kIconSize = 16; | 866 const int kIconSize = 16; |
| 854 SkColor icon_color = gfx::kPlaceholderColor; | 867 security_state::SecurityStateModel::SecurityLevel security_level = |
| 855 if (ShouldShowEVBubble()) { | 868 GetToolbarModel()->GetSecurityLevel(false); |
| 856 icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; | 869 SkColor icon_color = |
| 857 icon_color = location_icon_view_->GetTextColor(); | 870 (security_level == security_state::SecurityStateModel::NONE) |
| 858 } else { | 871 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) |
| 859 icon_id = omnibox_view_->GetVectorIcon(); | 872 : GetSecureTextColor(security_level); |
| 860 security_state::SecurityStateModel::SecurityLevel security_level = | 873 location_icon_view_->SetImage(gfx::CreateVectorIcon( |
| 861 GetToolbarModel()->GetSecurityLevel(false); | 874 omnibox_view_->GetVectorIcon(), kIconSize, icon_color)); |
| 862 icon_color = (security_level == security_state::SecurityStateModel::NONE) | |
| 863 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) | |
| 864 : GetSecureTextColor(security_level); | |
| 865 } | |
| 866 location_icon_view_->SetImage( | |
| 867 gfx::CreateVectorIcon(icon_id, kIconSize, icon_color)); | |
| 868 } else { | 875 } else { |
| 869 location_icon_view_->SetImage( | 876 location_icon_view_->SetImage( |
| 870 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); | 877 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); |
| 871 } | 878 } |
| 872 } | 879 } |
| 873 | 880 |
| 874 bool LocationBarView::RefreshContentSettingViews() { | 881 bool LocationBarView::RefreshContentSettingViews() { |
| 875 bool visibility_changed = false; | 882 bool visibility_changed = false; |
| 876 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 883 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 877 i != content_setting_views_.end(); ++i) { | 884 i != content_setting_views_.end(); ++i) { |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 // LocationBarView, private TemplateURLServiceObserver implementation: | 1389 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1383 | 1390 |
| 1384 void LocationBarView::OnTemplateURLServiceChanged() { | 1391 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1385 template_url_service_->RemoveObserver(this); | 1392 template_url_service_->RemoveObserver(this); |
| 1386 template_url_service_ = nullptr; | 1393 template_url_service_ = nullptr; |
| 1387 // If the browser is no longer active, let's not show the info bubble, as this | 1394 // If the browser is no longer active, let's not show the info bubble, as this |
| 1388 // would make the browser the active window again. | 1395 // would make the browser the active window again. |
| 1389 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1396 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1390 ShowFirstRunBubble(); | 1397 ShowFirstRunBubble(); |
| 1391 } | 1398 } |
| OLD | NEW |