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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); | 211 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); |
| 212 font_list = font_list.DeriveWithHeightUpperBound(location_height); | 212 font_list = font_list.DeriveWithHeightUpperBound(location_height); |
| 213 | 213 |
| 214 // Determine the font for use inside the bubbles. | 214 // Determine the font for use inside the bubbles. |
| 215 const int bubble_padding = | 215 const int bubble_padding = |
| 216 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + | 216 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + |
| 217 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); | 217 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); |
| 218 const int bubble_height = location_height - (bubble_padding * 2); | 218 const int bubble_height = location_height - (bubble_padding * 2); |
| 219 gfx::FontList bubble_font_list = | 219 gfx::FontList bubble_font_list = |
| 220 font_list.DeriveWithHeightUpperBound(bubble_height); | 220 font_list.DeriveWithHeightUpperBound(bubble_height); |
| 221 gfx::FontList chip_font_list = ui::MaterialDesignController::IsModeMaterial() | |
| 222 ? font_list | |
| 223 : bubble_font_list; | |
| 221 | 224 |
| 222 const SkColor background_color = GetColor(BACKGROUND); | 225 const SkColor background_color = GetColor(BACKGROUND); |
| 223 location_icon_view_ = | 226 location_icon_view_ = |
| 224 new LocationIconView(bubble_font_list, background_color, this); | 227 new LocationIconView(chip_font_list, background_color, this); |
| 225 location_icon_view_->set_drag_controller(this); | 228 location_icon_view_->set_drag_controller(this); |
| 226 AddChildView(location_icon_view_); | 229 AddChildView(location_icon_view_); |
| 227 | 230 |
| 228 // Initialize the Omnibox view. | 231 // Initialize the Omnibox view. |
| 229 omnibox_view_ = new OmniboxViewViews( | 232 omnibox_view_ = new OmniboxViewViews( |
| 230 this, profile(), command_updater(), is_popup_mode_, this, font_list); | 233 this, profile(), command_updater(), is_popup_mode_, this, font_list); |
| 231 omnibox_view_->Init(); | 234 omnibox_view_->Init(); |
| 232 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); | 235 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); |
| 233 AddChildView(omnibox_view_); | 236 AddChildView(omnibox_view_); |
| 234 | 237 |
| 235 // Initialize the inline autocomplete view which is visible only when IME is | 238 // 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. | 239 // turned on. Use the same font with the omnibox and highlighted background. |
| 237 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); | 240 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); |
| 238 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 241 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 239 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 242 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
| 240 ime_inline_autocomplete_view_->set_background( | 243 ime_inline_autocomplete_view_->set_background( |
| 241 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 244 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
| 242 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 245 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
| 243 ime_inline_autocomplete_view_->SetEnabledColor( | 246 ime_inline_autocomplete_view_->SetEnabledColor( |
| 244 GetNativeTheme()->GetSystemColor( | 247 GetNativeTheme()->GetSystemColor( |
| 245 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 248 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 246 ime_inline_autocomplete_view_->SetVisible(false); | 249 ime_inline_autocomplete_view_->SetVisible(false); |
| 247 AddChildView(ime_inline_autocomplete_view_); | 250 AddChildView(ime_inline_autocomplete_view_); |
| 248 | 251 |
| 249 const SkColor selected_text_color = GetColor(TEXT); | 252 const SkColor selected_text_color = GetColor(TEXT); |
| 250 selected_keyword_view_ = new SelectedKeywordView( | 253 selected_keyword_view_ = new SelectedKeywordView( |
| 251 bubble_font_list, selected_text_color, background_color, profile()); | 254 chip_font_list, selected_text_color, background_color, profile()); |
| 252 AddChildView(selected_keyword_view_); | 255 AddChildView(selected_keyword_view_); |
| 253 | 256 |
| 254 suggested_text_view_ = new views::Label(base::string16(), font_list); | 257 suggested_text_view_ = new views::Label(base::string16(), font_list); |
| 255 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 258 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 256 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 259 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
| 257 suggested_text_view_->SetEnabledColor( | 260 suggested_text_view_->SetEnabledColor( |
| 258 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); | 261 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); |
| 259 suggested_text_view_->SetVisible(false); | 262 suggested_text_view_->SetVisible(false); |
| 260 AddChildView(suggested_text_view_); | 263 AddChildView(suggested_text_view_); |
| 261 | 264 |
| 262 keyword_hint_view_ = new KeywordHintView( | 265 keyword_hint_view_ = new KeywordHintView( |
| 263 profile(), font_list, bubble_font_list, location_height, | 266 profile(), font_list, bubble_font_list, location_height, |
| 264 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); | 267 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); |
| 265 AddChildView(keyword_hint_view_); | 268 AddChildView(keyword_hint_view_); |
| 266 | 269 |
| 267 ScopedVector<ContentSettingImageModel> models = | 270 ScopedVector<ContentSettingImageModel> models = |
| 268 ContentSettingImageModel::GenerateContentSettingImageModels(); | 271 ContentSettingImageModel::GenerateContentSettingImageModels(); |
| 269 for (ContentSettingImageModel* model : models.get()) { | 272 for (ContentSettingImageModel* model : models.get()) { |
| 270 // ContentSettingImageView takes ownership of its model. | 273 // ContentSettingImageView takes ownership of its model. |
| 271 ContentSettingImageView* image_view = new ContentSettingImageView( | 274 ContentSettingImageView* image_view = new ContentSettingImageView( |
| 272 model, this, bubble_font_list, background_color); | 275 model, this, chip_font_list, background_color); |
| 273 content_setting_views_.push_back(image_view); | 276 content_setting_views_.push_back(image_view); |
| 274 image_view->SetVisible(false); | 277 image_view->SetVisible(false); |
| 275 AddChildView(image_view); | 278 AddChildView(image_view); |
| 276 } | 279 } |
| 277 models.weak_clear(); | 280 models.weak_clear(); |
| 278 | 281 |
| 279 zoom_view_ = new ZoomView(delegate_); | 282 zoom_view_ = new ZoomView(delegate_); |
| 280 AddChildView(zoom_view_); | 283 AddChildView(zoom_view_); |
| 281 | 284 |
| 282 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); | 285 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 | 326 |
| 324 case SELECTED_TEXT: | 327 case SELECTED_TEXT: |
| 325 return native_theme->GetSystemColor( | 328 return native_theme->GetSystemColor( |
| 326 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 329 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
| 327 | 330 |
| 328 case DEEMPHASIZED_TEXT: | 331 case DEEMPHASIZED_TEXT: |
| 329 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); | 332 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); |
| 330 | 333 |
| 331 case EV_BUBBLE_TEXT_AND_BORDER: | 334 case EV_BUBBLE_TEXT_AND_BORDER: |
| 332 return ui::MaterialDesignController::IsModeMaterial() | 335 return ui::MaterialDesignController::IsModeMaterial() |
| 333 ? gfx::kGoogleGreen700 | 336 ? GetSecureTextColor( |
| 337 GetToolbarModel()->GetSecurityLevel(false)) | |
| 334 : SkColorSetRGB(7, 149, 0); | 338 : SkColorSetRGB(7, 149, 0); |
| 335 } | 339 } |
| 336 NOTREACHED(); | 340 NOTREACHED(); |
| 337 return gfx::kPlaceholderColor; | 341 return gfx::kPlaceholderColor; |
| 338 } | 342 } |
| 339 | 343 |
| 340 SkColor LocationBarView::GetSecureTextColor( | 344 SkColor LocationBarView::GetSecureTextColor( |
| 341 security_state::SecurityStateModel::SecurityLevel security_level) const { | 345 security_state::SecurityStateModel::SecurityLevel security_level) const { |
| 342 if (security_level == | 346 if (security_level == |
| 343 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { | 347 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { |
| 344 return GetColor(DEEMPHASIZED_TEXT); | 348 return GetColor(DEEMPHASIZED_TEXT); |
| 345 } | 349 } |
| 346 | 350 |
| 347 SkColor text_color = GetColor(TEXT); | 351 SkColor text_color = GetColor(TEXT); |
| 348 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || | 352 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || |
| 349 (security_level == security_state::SecurityStateModel::SECURE) || | 353 (security_level == security_state::SecurityStateModel::SECURE) || |
| 350 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { | 354 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { |
| 351 const bool md = ui::MaterialDesignController::IsModeMaterial(); | 355 const bool md = ui::MaterialDesignController::IsModeMaterial(); |
| 352 if (md && color_utils::IsDark(GetColor(BACKGROUND))) | 356 if (md && color_utils::IsDark(GetColor(BACKGROUND))) |
| 353 return text_color; | 357 return text_color; |
| 354 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) | 358 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) |
| 355 text_color = md ? gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0); | 359 text_color = md ? gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0); |
| 360 else if (md) | |
| 361 return gfx::kGoogleGreen700; | |
| 356 else | 362 else |
| 357 text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); | 363 return GetColor(EV_BUBBLE_TEXT_AND_BORDER); |
|
Peter Kasting
2016/05/25 00:03:27
Nit: Shorter, and avoids else after return:
i
Evan Stade
2016/05/25 20:03:44
good suggestion. Since we're switching on md so mu
| |
| 358 } | 364 } |
| 359 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); | 365 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); |
| 360 } | 366 } |
| 361 | 367 |
| 362 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 368 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 363 DCHECK(zoom_view_); | 369 DCHECK(zoom_view_); |
| 364 if (RefreshZoomView()) { | 370 if (RefreshZoomView()) { |
| 365 Layout(); | 371 Layout(); |
| 366 SchedulePaint(); | 372 SchedulePaint(); |
| 367 } | 373 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 563 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 558 const int edge_thickness = GetHorizontalEdgeThickness(); | 564 const int edge_thickness = GetHorizontalEdgeThickness(); |
| 559 int trailing_edge_item_padding = 0; | 565 int trailing_edge_item_padding = 0; |
| 560 if (!ui::MaterialDesignController::IsModeMaterial()) { | 566 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 561 trailing_edge_item_padding = | 567 trailing_edge_item_padding = |
| 562 item_padding - edge_thickness - omnibox_view_->GetInsets().right(); | 568 item_padding - edge_thickness - omnibox_view_->GetInsets().right(); |
| 563 } | 569 } |
| 564 | 570 |
| 565 LocationBarLayout leading_decorations( | 571 LocationBarLayout leading_decorations( |
| 566 LocationBarLayout::LEFT_EDGE, item_padding, | 572 LocationBarLayout::LEFT_EDGE, item_padding, |
| 567 item_padding - omnibox_view_->GetInsets().left() - | 573 ui::MaterialDesignController::IsModeMaterial() |
| 568 GetEditLeadingInternalSpace()); | 574 ? GetLayoutConstant(LOCATION_BAR_PRE_EDIT_SPACING) |
| 575 : (item_padding - omnibox_view_->GetInsets().left() - | |
| 576 GetEditLeadingInternalSpace())); | |
|
Peter Kasting
2016/05/25 00:03:27
Won't not factoring in GetEditLeadingInternalSpace
Evan Stade
2016/05/25 20:03:44
changed
RTL is tricky to get precisely correct be
| |
| 569 LocationBarLayout trailing_decorations( | 577 LocationBarLayout trailing_decorations( |
| 570 LocationBarLayout::RIGHT_EDGE, item_padding, trailing_edge_item_padding); | 578 LocationBarLayout::RIGHT_EDGE, item_padding, trailing_edge_item_padding); |
| 571 | 579 |
| 572 const base::string16 keyword(omnibox_view_->model()->keyword()); | 580 const base::string16 keyword(omnibox_view_->model()->keyword()); |
| 573 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 581 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
| 574 // to position our child views in this case, because other things may be | 582 // to position our child views in this case, because other things may be |
| 575 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 583 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
| 576 // hits ctrl-d). | 584 // hits ctrl-d). |
| 577 const int bubble_horizontal_padding = | 585 const int bubble_horizontal_padding = |
| 578 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); | 586 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); | 850 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); |
| 843 } | 851 } |
| 844 | 852 |
| 845 void LocationBarView::RefreshLocationIcon() { | 853 void LocationBarView::RefreshLocationIcon() { |
| 846 // |omnibox_view_| may not be ready yet if Init() has not been called. The | 854 // |omnibox_view_| may not be ready yet if Init() has not been called. The |
| 847 // icon will be set soon by OnChanged(). | 855 // icon will be set soon by OnChanged(). |
| 848 if (!omnibox_view_) | 856 if (!omnibox_view_) |
| 849 return; | 857 return; |
| 850 | 858 |
| 851 if (ui::MaterialDesignController::IsModeMaterial()) { | 859 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 852 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 853 const int kIconSize = 16; | 860 const int kIconSize = 16; |
| 854 SkColor icon_color = gfx::kPlaceholderColor; | 861 security_state::SecurityStateModel::SecurityLevel security_level = |
| 855 if (ShouldShowEVBubble()) { | 862 GetToolbarModel()->GetSecurityLevel(false); |
| 856 icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; | 863 SkColor icon_color = |
| 857 icon_color = location_icon_view_->GetTextColor(); | 864 (security_level == security_state::SecurityStateModel::NONE) |
| 858 } else { | 865 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) |
| 859 icon_id = omnibox_view_->GetVectorIcon(); | 866 : GetSecureTextColor(security_level); |
| 860 security_state::SecurityStateModel::SecurityLevel security_level = | 867 location_icon_view_->SetImage(gfx::CreateVectorIcon( |
| 861 GetToolbarModel()->GetSecurityLevel(false); | 868 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 { | 869 } else { |
| 869 location_icon_view_->SetImage( | 870 location_icon_view_->SetImage( |
| 870 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); | 871 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); |
| 871 } | 872 } |
| 872 } | 873 } |
| 873 | 874 |
| 874 bool LocationBarView::RefreshContentSettingViews() { | 875 bool LocationBarView::RefreshContentSettingViews() { |
| 875 bool visibility_changed = false; | 876 bool visibility_changed = false; |
| 876 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 877 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 877 i != content_setting_views_.end(); ++i) { | 878 i != content_setting_views_.end(); ++i) { |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1382 // LocationBarView, private TemplateURLServiceObserver implementation: | 1383 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1383 | 1384 |
| 1384 void LocationBarView::OnTemplateURLServiceChanged() { | 1385 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1385 template_url_service_->RemoveObserver(this); | 1386 template_url_service_->RemoveObserver(this); |
| 1386 template_url_service_ = nullptr; | 1387 template_url_service_ = nullptr; |
| 1387 // If the browser is no longer active, let's not show the info bubble, as this | 1388 // 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. | 1389 // would make the browser the active window again. |
| 1389 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1390 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1390 ShowFirstRunBubble(); | 1391 ShowFirstRunBubble(); |
| 1391 } | 1392 } |
| OLD | NEW |