| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #include "components/toolbar/toolbar_model.h" | 66 #include "components/toolbar/toolbar_model.h" |
| 67 #include "components/translate/core/browser/language_state.h" | 67 #include "components/translate/core/browser/language_state.h" |
| 68 #include "components/zoom/zoom_controller.h" | 68 #include "components/zoom/zoom_controller.h" |
| 69 #include "components/zoom/zoom_event_manager.h" | 69 #include "components/zoom/zoom_event_manager.h" |
| 70 #include "content/public/browser/render_widget_host_view.h" | 70 #include "content/public/browser/render_widget_host_view.h" |
| 71 #include "content/public/browser/web_contents.h" | 71 #include "content/public/browser/web_contents.h" |
| 72 #include "extensions/browser/extension_registry.h" | 72 #include "extensions/browser/extension_registry.h" |
| 73 #include "extensions/common/feature_switch.h" | 73 #include "extensions/common/feature_switch.h" |
| 74 #include "ui/accessibility/ax_view_state.h" | 74 #include "ui/accessibility/ax_view_state.h" |
| 75 #include "ui/base/dragdrop/drag_drop_types.h" | 75 #include "ui/base/dragdrop/drag_drop_types.h" |
| 76 #include "ui/base/material_design/material_design_controller.h" | |
| 77 #include "ui/base/resource/resource_bundle.h" | 76 #include "ui/base/resource/resource_bundle.h" |
| 78 #include "ui/base/theme_provider.h" | 77 #include "ui/base/theme_provider.h" |
| 79 #include "ui/compositor/paint_recorder.h" | 78 #include "ui/compositor/paint_recorder.h" |
| 80 #include "ui/events/event.h" | 79 #include "ui/events/event.h" |
| 81 #include "ui/gfx/animation/slide_animation.h" | 80 #include "ui/gfx/animation/slide_animation.h" |
| 82 #include "ui/gfx/canvas.h" | 81 #include "ui/gfx/canvas.h" |
| 83 #include "ui/gfx/color_palette.h" | 82 #include "ui/gfx/color_palette.h" |
| 84 #include "ui/gfx/color_utils.h" | 83 #include "ui/gfx/color_utils.h" |
| 85 #include "ui/gfx/image/image.h" | 84 #include "ui/gfx/image/image.h" |
| 86 #include "ui/gfx/image/image_skia_operations.h" | 85 #include "ui/gfx/image/image_skia_operations.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, | 187 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, |
| 189 incognito), | 188 incognito), |
| 190 SkColorGetA(kBorderColor)); | 189 SkColorGetA(kBorderColor)); |
| 191 } | 190 } |
| 192 | 191 |
| 193 void LocationBarView::Init() { | 192 void LocationBarView::Init() { |
| 194 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're | 193 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're |
| 195 // not prepared for that. | 194 // not prepared for that. |
| 196 DCHECK(GetWidget()); | 195 DCHECK(GetWidget()); |
| 197 | 196 |
| 198 if (ui::MaterialDesignController::IsModeMaterial()) { | 197 // Make sure children with layers are clipped. See http://crbug.com/589497 |
| 199 // Make sure children with layers are clipped. See http://crbug.com/589497 | 198 SetPaintToLayer(true); |
| 200 SetPaintToLayer(true); | 199 layer()->SetFillsBoundsOpaquely(false); |
| 201 layer()->SetFillsBoundsOpaquely(false); | 200 layer()->SetMasksToBounds(true); |
| 202 layer()->SetMasksToBounds(true); | |
| 203 } else if (is_popup_mode_) { | |
| 204 const int kOmniboxPopupBorderImages[] = | |
| 205 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW); | |
| 206 border_painter_.reset( | |
| 207 views::Painter::CreateImageGridPainter(kOmniboxPopupBorderImages)); | |
| 208 } else { | |
| 209 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 210 const gfx::Insets omnibox_border_insets(14, 9); | |
| 211 border_painter_.reset(views::Painter::CreateImagePainter( | |
| 212 *rb.GetImageSkiaNamed(IDR_OMNIBOX_BORDER), omnibox_border_insets)); | |
| 213 } | |
| 214 | 201 |
| 215 // Determine the main font. | 202 // Determine the main font. |
| 216 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( | 203 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( |
| 217 ResourceBundle::BaseFont); | 204 ResourceBundle::BaseFont); |
| 218 const int current_font_size = font_list.GetFontSize(); | 205 const int current_font_size = font_list.GetFontSize(); |
| 219 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); | 206 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); |
| 220 if (current_font_size != desired_font_size) { | 207 if (current_font_size != desired_font_size) { |
| 221 font_list = | 208 font_list = |
| 222 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); | 209 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); |
| 223 } | 210 } |
| 224 // Shrink large fonts to make them fit. | 211 // Shrink large fonts to make them fit. |
| 225 // TODO(pkasting): Stretch the location bar instead in this case. | 212 // TODO(pkasting): Stretch the location bar instead in this case. |
| 226 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); | 213 const int vertical_padding = GetTotalVerticalPadding(); |
| 227 const int location_height = | 214 const int location_height = |
| 228 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); | 215 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); |
| 229 font_list = font_list.DeriveWithHeightUpperBound(location_height); | 216 font_list = font_list.DeriveWithHeightUpperBound(location_height); |
| 230 | 217 |
| 231 // Determine the font for use inside the bubbles. | 218 // Determine the font for use inside the bubbles. |
| 232 const int bubble_padding = | 219 const int bubble_padding = |
| 233 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + | 220 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + |
| 234 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); | 221 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); |
| 235 const int bubble_height = location_height - (bubble_padding * 2); | 222 const int bubble_height = location_height - (bubble_padding * 2); |
| 236 gfx::FontList bubble_font_list = | |
| 237 font_list.DeriveWithHeightUpperBound(bubble_height); | |
| 238 gfx::FontList chip_font_list = ui::MaterialDesignController::IsModeMaterial() | |
| 239 ? font_list | |
| 240 : bubble_font_list; | |
| 241 | 223 |
| 242 const SkColor background_color = GetColor(BACKGROUND); | 224 const SkColor background_color = GetColor(BACKGROUND); |
| 243 location_icon_view_ = | 225 location_icon_view_ = new LocationIconView(font_list, this); |
| 244 new LocationIconView(chip_font_list, background_color, this); | |
| 245 location_icon_view_->set_drag_controller(this); | 226 location_icon_view_->set_drag_controller(this); |
| 246 AddChildView(location_icon_view_); | 227 AddChildView(location_icon_view_); |
| 247 | 228 |
| 248 // Initialize the Omnibox view. | 229 // Initialize the Omnibox view. |
| 249 omnibox_view_ = new OmniboxViewViews( | 230 omnibox_view_ = new OmniboxViewViews( |
| 250 this, profile(), command_updater(), is_popup_mode_, this, font_list); | 231 this, profile(), command_updater(), is_popup_mode_, this, font_list); |
| 251 omnibox_view_->Init(); | 232 omnibox_view_->Init(); |
| 252 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); | 233 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); |
| 253 AddChildView(omnibox_view_); | 234 AddChildView(omnibox_view_); |
| 254 | 235 |
| 255 // Initialize the inline autocomplete view which is visible only when IME is | 236 // Initialize the inline autocomplete view which is visible only when IME is |
| 256 // turned on. Use the same font with the omnibox and highlighted background. | 237 // turned on. Use the same font with the omnibox and highlighted background. |
| 257 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); | 238 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); |
| 258 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 239 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 259 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 240 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
| 260 ime_inline_autocomplete_view_->set_background( | 241 ime_inline_autocomplete_view_->set_background( |
| 261 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 242 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
| 262 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 243 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
| 263 ime_inline_autocomplete_view_->SetEnabledColor( | 244 ime_inline_autocomplete_view_->SetEnabledColor( |
| 264 GetNativeTheme()->GetSystemColor( | 245 GetNativeTheme()->GetSystemColor( |
| 265 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 246 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 266 ime_inline_autocomplete_view_->SetVisible(false); | 247 ime_inline_autocomplete_view_->SetVisible(false); |
| 267 AddChildView(ime_inline_autocomplete_view_); | 248 AddChildView(ime_inline_autocomplete_view_); |
| 268 | 249 |
| 269 const SkColor selected_text_color = GetColor(TEXT); | 250 selected_keyword_view_ = new SelectedKeywordView(font_list, profile()); |
| 270 selected_keyword_view_ = new SelectedKeywordView( | |
| 271 chip_font_list, selected_text_color, background_color, profile()); | |
| 272 AddChildView(selected_keyword_view_); | 251 AddChildView(selected_keyword_view_); |
| 273 | 252 |
| 274 suggested_text_view_ = new views::Label(base::string16(), font_list); | 253 suggested_text_view_ = new views::Label(base::string16(), font_list); |
| 275 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 254 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 276 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 255 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
| 277 suggested_text_view_->SetEnabledColor( | 256 suggested_text_view_->SetEnabledColor( |
| 278 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); | 257 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); |
| 279 suggested_text_view_->SetVisible(false); | 258 suggested_text_view_->SetVisible(false); |
| 280 AddChildView(suggested_text_view_); | 259 AddChildView(suggested_text_view_); |
| 281 | 260 |
| 261 gfx::FontList bubble_font_list = |
| 262 font_list.DeriveWithHeightUpperBound(bubble_height); |
| 282 keyword_hint_view_ = new KeywordHintView( | 263 keyword_hint_view_ = new KeywordHintView( |
| 283 profile(), font_list, bubble_font_list, location_height, | 264 profile(), font_list, bubble_font_list, location_height, |
| 284 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); | 265 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); |
| 285 AddChildView(keyword_hint_view_); | 266 AddChildView(keyword_hint_view_); |
| 286 | 267 |
| 287 ScopedVector<ContentSettingImageModel> models = | 268 ScopedVector<ContentSettingImageModel> models = |
| 288 ContentSettingImageModel::GenerateContentSettingImageModels(); | 269 ContentSettingImageModel::GenerateContentSettingImageModels(); |
| 289 for (ContentSettingImageModel* model : models.get()) { | 270 for (ContentSettingImageModel* model : models.get()) { |
| 290 // ContentSettingImageView takes ownership of its model. | 271 // ContentSettingImageView takes ownership of its model. |
| 291 ContentSettingImageView* image_view = new ContentSettingImageView( | 272 ContentSettingImageView* image_view = |
| 292 model, this, chip_font_list, background_color); | 273 new ContentSettingImageView(model, this, font_list); |
| 293 content_setting_views_.push_back(image_view); | 274 content_setting_views_.push_back(image_view); |
| 294 image_view->SetVisible(false); | 275 image_view->SetVisible(false); |
| 295 AddChildView(image_view); | 276 AddChildView(image_view); |
| 296 } | 277 } |
| 297 models.weak_clear(); | 278 models.weak_clear(); |
| 298 | 279 |
| 299 zoom_view_ = new ZoomView(delegate_); | 280 zoom_view_ = new ZoomView(delegate_); |
| 300 AddChildView(zoom_view_); | 281 AddChildView(zoom_view_); |
| 301 | 282 |
| 302 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); | 283 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 323 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 343 | 324 |
| 344 case SELECTED_TEXT: | 325 case SELECTED_TEXT: |
| 345 return native_theme->GetSystemColor( | 326 return native_theme->GetSystemColor( |
| 346 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 327 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
| 347 | 328 |
| 348 case DEEMPHASIZED_TEXT: | 329 case DEEMPHASIZED_TEXT: |
| 349 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); | 330 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); |
| 350 | 331 |
| 351 case SECURITY_CHIP_TEXT: | 332 case SECURITY_CHIP_TEXT: |
| 352 return ui::MaterialDesignController::IsModeMaterial() | 333 return GetSecureTextColor(GetToolbarModel()->GetSecurityLevel(false)); |
| 353 ? GetSecureTextColor( | |
| 354 GetToolbarModel()->GetSecurityLevel(false)) | |
| 355 : SkColorSetRGB(7, 149, 0); | |
| 356 } | 334 } |
| 357 NOTREACHED(); | 335 NOTREACHED(); |
| 358 return gfx::kPlaceholderColor; | 336 return gfx::kPlaceholderColor; |
| 359 } | 337 } |
| 360 | 338 |
| 361 SkColor LocationBarView::GetSecureTextColor( | 339 SkColor LocationBarView::GetSecureTextColor( |
| 362 security_state::SecurityStateModel::SecurityLevel security_level) const { | 340 security_state::SecurityStateModel::SecurityLevel security_level) const { |
| 363 if (security_level == | 341 if (security_level == |
| 364 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { | 342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { |
| 365 return GetColor(DEEMPHASIZED_TEXT); | 343 return GetColor(DEEMPHASIZED_TEXT); |
| 366 } | 344 } |
| 367 | 345 |
| 368 SkColor text_color = GetColor(TEXT); | 346 SkColor text_color = GetColor(TEXT); |
| 369 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || | 347 if (!color_utils::IsDark(GetColor(BACKGROUND))) { |
| 370 (security_level == security_state::SecurityStateModel::SECURE) || | 348 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || |
| 371 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { | 349 (security_level == security_state::SecurityStateModel::SECURE)) { |
| 372 if (ui::MaterialDesignController::IsModeMaterial()) { | 350 text_color = gfx::kGoogleGreen700; |
| 373 if (color_utils::IsDark(GetColor(BACKGROUND))) | |
| 374 return text_color; | |
| 375 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) | |
| 376 text_color = gfx::kGoogleRed700; | |
| 377 else | |
| 378 text_color = gfx::kGoogleGreen700; | |
| 379 } else if (security_level == | 351 } else if (security_level == |
| 380 security_state::SecurityStateModel::SECURITY_ERROR) { | 352 security_state::SecurityStateModel::SECURITY_ERROR) { |
| 381 text_color = SkColorSetRGB(162, 0, 0); | 353 text_color = gfx::kGoogleRed700; |
| 382 } else { | |
| 383 text_color = GetColor(SECURITY_CHIP_TEXT); | |
| 384 } | 354 } |
| 385 } | 355 } |
| 386 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); | 356 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); |
| 387 } | 357 } |
| 388 | 358 |
| 389 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 359 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 390 DCHECK(zoom_view_); | 360 DCHECK(zoom_view_); |
| 391 if (RefreshZoomView()) { | 361 if (RefreshZoomView()) { |
| 392 Layout(); | 362 Layout(); |
| 393 SchedulePaint(); | 363 SchedulePaint(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 star_view_->SetToggled(on); | 405 star_view_->SetToggled(on); |
| 436 } | 406 } |
| 437 | 407 |
| 438 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 408 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
| 439 gfx::Point origin(omnibox_view_->bounds().origin()); | 409 gfx::Point origin(omnibox_view_->bounds().origin()); |
| 440 origin.set_x(GetMirroredXInView(origin.x())); | 410 origin.set_x(GetMirroredXInView(origin.x())); |
| 441 views::View::ConvertPointToScreen(this, &origin); | 411 views::View::ConvertPointToScreen(this, &origin); |
| 442 return origin; | 412 return origin; |
| 443 } | 413 } |
| 444 | 414 |
| 445 int LocationBarView::GetLocationIconWidth() const { | |
| 446 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 447 constexpr int kVectorIconSize = 16; | |
| 448 return kVectorIconSize; | |
| 449 } | |
| 450 return GetThemeProvider()->GetImageSkiaNamed( | |
| 451 AutocompleteMatch::TypeToIcon( | |
| 452 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width(); | |
| 453 } | |
| 454 | |
| 455 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { | 415 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { |
| 456 ime_inline_autocomplete_view_->SetText(text); | 416 ime_inline_autocomplete_view_->SetText(text); |
| 457 ime_inline_autocomplete_view_->SetVisible(!text.empty()); | 417 ime_inline_autocomplete_view_->SetVisible(!text.empty()); |
| 458 } | 418 } |
| 459 | 419 |
| 460 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { | 420 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { |
| 461 if (suggested_text_view_->text() != text) { | 421 if (suggested_text_view_->text() != text) { |
| 462 suggested_text_view_->SetText(text); | 422 suggested_text_view_->SetText(text); |
| 463 suggested_text_view_->SetVisible(!text.empty()); | 423 suggested_text_view_->SetVisible(!text.empty()); |
| 464 Layout(); | 424 Layout(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 491 void LocationBarView::GetOmniboxPopupPositioningInfo( | 451 void LocationBarView::GetOmniboxPopupPositioningInfo( |
| 492 gfx::Point* top_left_screen_coord, | 452 gfx::Point* top_left_screen_coord, |
| 493 int* popup_width, | 453 int* popup_width, |
| 494 int* left_margin, | 454 int* left_margin, |
| 495 int* right_margin, | 455 int* right_margin, |
| 496 int top_edge_overlap) { | 456 int top_edge_overlap) { |
| 497 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); | 457 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); |
| 498 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); | 458 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); |
| 499 | 459 |
| 500 *popup_width = parent()->width(); | 460 *popup_width = parent()->width(); |
| 501 gfx::Rect location_bar_bounds(bounds()); | 461 *left_margin = x(); |
| 502 if (!ui::MaterialDesignController::IsModeMaterial()) | 462 *right_margin = *popup_width - bounds().right(); |
| 503 location_bar_bounds.Inset(GetHorizontalEdgeThickness(), 0); | |
| 504 *left_margin = location_bar_bounds.x(); | |
| 505 *right_margin = *popup_width - location_bar_bounds.right(); | |
| 506 } | 463 } |
| 507 | 464 |
| 508 //////////////////////////////////////////////////////////////////////////////// | 465 //////////////////////////////////////////////////////////////////////////////// |
| 509 // LocationBarView, public LocationBar implementation: | 466 // LocationBarView, public LocationBar implementation: |
| 510 | 467 |
| 511 void LocationBarView::FocusLocation(bool select_all) { | 468 void LocationBarView::FocusLocation(bool select_all) { |
| 512 omnibox_view_->SetFocus(); | 469 omnibox_view_->SetFocus(); |
| 513 if (select_all) | 470 if (select_all) |
| 514 omnibox_view_->SelectAll(true); | 471 omnibox_view_->SelectAll(true); |
| 515 } | 472 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 528 bool LocationBarView::HasFocus() const { | 485 bool LocationBarView::HasFocus() const { |
| 529 return omnibox_view_->model()->has_focus(); | 486 return omnibox_view_->model()->has_focus(); |
| 530 } | 487 } |
| 531 | 488 |
| 532 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { | 489 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { |
| 533 state->role = ui::AX_ROLE_GROUP; | 490 state->role = ui::AX_ROLE_GROUP; |
| 534 } | 491 } |
| 535 | 492 |
| 536 gfx::Size LocationBarView::GetPreferredSize() const { | 493 gfx::Size LocationBarView::GetPreferredSize() const { |
| 537 // Compute minimum height. | 494 // Compute minimum height. |
| 538 gfx::Size min_size; | 495 gfx::Size min_size(0, GetLayoutConstant(LOCATION_BAR_HEIGHT)); |
| 539 if (ui::MaterialDesignController::IsModeMaterial() || is_popup_mode_) { | |
| 540 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT)); | |
| 541 } else { | |
| 542 min_size = border_painter_->GetMinimumSize(); | |
| 543 } | |
| 544 | 496 |
| 545 if (!IsInitialized()) | 497 if (!IsInitialized()) |
| 546 return min_size; | 498 return min_size; |
| 547 | 499 |
| 548 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); | 500 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); |
| 549 | 501 |
| 550 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 502 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 551 | 503 |
| 552 // Compute width of omnibox-leading content. | 504 // Compute width of omnibox-leading content. |
| 553 const int edge_thickness = GetHorizontalEdgeThickness(); | 505 const int edge_thickness = GetHorizontalEdgeThickness(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 LocationBarLayout::RIGHT_EDGE, item_padding, | 554 LocationBarLayout::RIGHT_EDGE, item_padding, |
| 603 item_padding - omnibox_view_->GetInsets().right()); | 555 item_padding - omnibox_view_->GetInsets().right()); |
| 604 | 556 |
| 605 const base::string16 keyword(omnibox_view_->model()->keyword()); | 557 const base::string16 keyword(omnibox_view_->model()->keyword()); |
| 606 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 558 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
| 607 // to position our child views in this case, because other things may be | 559 // to position our child views in this case, because other things may be |
| 608 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 560 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
| 609 // hits ctrl-d). | 561 // hits ctrl-d). |
| 610 const int bubble_horizontal_padding = | 562 const int bubble_horizontal_padding = |
| 611 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); | 563 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); |
| 612 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); | 564 const int vertical_padding = GetTotalVerticalPadding(); |
| 613 const int location_height = std::max(height() - (vertical_padding * 2), 0); | 565 const int location_height = std::max(height() - (vertical_padding * 2), 0); |
| 614 | 566 |
| 615 location_icon_view_->SetLabel(base::string16()); | 567 location_icon_view_->SetLabel(base::string16()); |
| 616 location_icon_view_->SetBackground(false); | |
| 617 if (ShouldShowKeywordBubble()) { | 568 if (ShouldShowKeywordBubble()) { |
| 618 leading_decorations.AddDecoration(vertical_padding, location_height, true, | 569 leading_decorations.AddDecoration(vertical_padding, location_height, true, |
| 619 0, bubble_horizontal_padding, | 570 0, bubble_horizontal_padding, |
| 620 item_padding, selected_keyword_view_); | 571 item_padding, selected_keyword_view_); |
| 621 if (selected_keyword_view_->keyword() != keyword) { | 572 if (selected_keyword_view_->keyword() != keyword) { |
| 622 selected_keyword_view_->SetKeyword(keyword); | 573 selected_keyword_view_->SetKeyword(keyword); |
| 623 const TemplateURL* template_url = | 574 const TemplateURL* template_url = |
| 624 TemplateURLServiceFactory::GetForProfile(profile())-> | 575 TemplateURLServiceFactory::GetForProfile(profile())-> |
| 625 GetTemplateURLForKeyword(keyword); | 576 GetTemplateURLForKeyword(keyword); |
| 626 if (template_url && | 577 if (template_url && |
| 627 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { | 578 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 628 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> | 579 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> |
| 629 GetOmniboxIcon(template_url->GetExtensionId()); | 580 GetOmniboxIcon(template_url->GetExtensionId()); |
| 630 selected_keyword_view_->SetImage(image.AsImageSkia()); | 581 selected_keyword_view_->SetImage(image.AsImageSkia()); |
| 631 selected_keyword_view_->set_is_extension_icon(true); | |
| 632 } else { | 582 } else { |
| 633 selected_keyword_view_->ResetImage(); | 583 selected_keyword_view_->ResetImage(); |
| 634 selected_keyword_view_->set_is_extension_icon(false); | |
| 635 } | 584 } |
| 636 } | 585 } |
| 637 } else if (ShouldShowSecurityChip()) { | 586 } else if (ShouldShowSecurityChip()) { |
| 638 location_icon_view_->SetLabel(GetSecurityText()); | 587 location_icon_view_->SetLabel(GetSecurityText()); |
| 639 location_icon_view_->SetBackground(true); | |
| 640 // The largest fraction of the omnibox that can be taken by the EV bubble. | 588 // The largest fraction of the omnibox that can be taken by the EV bubble. |
| 641 const double kMaxBubbleFraction = 0.5; | 589 const double kMaxBubbleFraction = 0.5; |
| 642 leading_decorations.AddDecoration( | 590 leading_decorations.AddDecoration( |
| 643 vertical_padding, location_height, false, kMaxBubbleFraction, | 591 vertical_padding, location_height, false, kMaxBubbleFraction, |
| 644 bubble_horizontal_padding, item_padding, location_icon_view_); | 592 bubble_horizontal_padding, item_padding, location_icon_view_); |
| 645 } else { | 593 } else { |
| 646 leading_decorations.AddDecoration(vertical_padding, location_height, | 594 leading_decorations.AddDecoration(vertical_padding, location_height, |
| 647 location_icon_view_); | 595 location_icon_view_); |
| 648 } | 596 } |
| 649 | 597 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 x = entry_width - width; | 737 x = entry_width - width; |
| 790 location_bounds.set_width(x); | 738 location_bounds.set_width(x); |
| 791 ime_inline_autocomplete_view_->SetBounds( | 739 ime_inline_autocomplete_view_->SetBounds( |
| 792 location_bounds.right(), location_bounds.y(), | 740 location_bounds.right(), location_bounds.y(), |
| 793 std::min(width, entry_width), location_bounds.height()); | 741 std::min(width, entry_width), location_bounds.height()); |
| 794 } | 742 } |
| 795 omnibox_view_->SetBoundsRect(location_bounds); | 743 omnibox_view_->SetBoundsRect(location_bounds); |
| 796 } | 744 } |
| 797 | 745 |
| 798 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 746 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 799 if (ui::MaterialDesignController::IsModeMaterial()) { | 747 RefreshLocationIcon(); |
| 800 RefreshLocationIcon(); | 748 if (!is_popup_mode_) { |
| 801 if (!is_popup_mode_) { | 749 set_background( |
| 802 set_background(new BackgroundWith1PxBorder(GetColor(BACKGROUND), | 750 new BackgroundWith1PxBorder(GetColor(BACKGROUND), kBorderColor)); |
| 803 kBorderColor)); | |
| 804 } | |
| 805 } | 751 } |
| 806 } | 752 } |
| 807 | 753 |
| 808 void LocationBarView::Update(const WebContents* contents) { | 754 void LocationBarView::Update(const WebContents* contents) { |
| 809 RefreshContentSettingViews(); | 755 RefreshContentSettingViews(); |
| 810 RefreshZoomView(); | 756 RefreshZoomView(); |
| 811 RefreshPageActionViews(); | 757 RefreshPageActionViews(); |
| 812 RefreshTranslateIcon(); | 758 RefreshTranslateIcon(); |
| 813 RefreshSaveCreditCardIconView(); | 759 RefreshSaveCreditCardIconView(); |
| 814 RefreshManagePasswordsIconView(); | 760 RefreshManagePasswordsIconView(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { | 802 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { |
| 857 return view->visible() ? | 803 return view->visible() ? |
| 858 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + | 804 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + |
| 859 view->GetMinimumSize().width()) : 0; | 805 view->GetMinimumSize().width()) : 0; |
| 860 } | 806 } |
| 861 | 807 |
| 862 int LocationBarView::GetHorizontalEdgeThickness() const { | 808 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 863 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | 809 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); |
| 864 } | 810 } |
| 865 | 811 |
| 866 int LocationBarView::GetVerticalEdgeThickness() const { | 812 int LocationBarView::GetTotalVerticalPadding() const { |
| 867 if (ui::MaterialDesignController::IsModeMaterial()) | 813 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) + |
| 868 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | |
| 869 return is_popup_mode_ ? views::NonClientFrameView::kClientEdgeThickness | |
| 870 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | |
| 871 } | |
| 872 | |
| 873 int LocationBarView::GetVerticalEdgeThicknessWithPadding() const { | |
| 874 return GetVerticalEdgeThickness() + | |
| 875 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); | 814 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); |
| 876 } | 815 } |
| 877 | 816 |
| 878 void LocationBarView::RefreshLocationIcon() { | 817 void LocationBarView::RefreshLocationIcon() { |
| 879 // |omnibox_view_| may not be ready yet if Init() has not been called. The | 818 // |omnibox_view_| may not be ready yet if Init() has not been called. The |
| 880 // icon will be set soon by OnChanged(). | 819 // icon will be set soon by OnChanged(). |
| 881 if (!omnibox_view_) | 820 if (!omnibox_view_) |
| 882 return; | 821 return; |
| 883 | 822 |
| 884 if (ui::MaterialDesignController::IsModeMaterial()) { | 823 security_state::SecurityStateModel::SecurityLevel security_level = |
| 885 security_state::SecurityStateModel::SecurityLevel security_level = | 824 GetToolbarModel()->GetSecurityLevel(false); |
| 886 GetToolbarModel()->GetSecurityLevel(false); | 825 SkColor icon_color = |
| 887 SkColor icon_color = | 826 (security_level == security_state::SecurityStateModel::NONE) |
| 888 (security_level == security_state::SecurityStateModel::NONE) | 827 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) |
| 889 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) | 828 : GetSecureTextColor(security_level); |
| 890 : GetSecureTextColor(security_level); | 829 location_icon_view_->SetImage(gfx::CreateVectorIcon( |
| 891 location_icon_view_->SetImage(gfx::CreateVectorIcon( | 830 omnibox_view_->GetVectorIcon(), kLocationBarIconWidth, icon_color)); |
| 892 omnibox_view_->GetVectorIcon(), GetLocationIconWidth(), icon_color)); | |
| 893 } else { | |
| 894 location_icon_view_->SetImage( | |
| 895 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); | |
| 896 } | |
| 897 } | 831 } |
| 898 | 832 |
| 899 bool LocationBarView::RefreshContentSettingViews() { | 833 bool LocationBarView::RefreshContentSettingViews() { |
| 900 bool visibility_changed = false; | 834 bool visibility_changed = false; |
| 901 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 835 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 902 i != content_setting_views_.end(); ++i) { | 836 i != content_setting_views_.end(); ++i) { |
| 903 const bool was_visible = (*i)->visible(); | 837 const bool was_visible = (*i)->visible(); |
| 904 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr | 838 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr |
| 905 : GetWebContents()); | 839 : GetWebContents()); |
| 906 if (was_visible != (*i)->visible()) | 840 if (was_visible != (*i)->visible()) |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 popup->UpdatePopupAppearance(); | 1222 popup->UpdatePopupAppearance(); |
| 1289 } | 1223 } |
| 1290 | 1224 |
| 1291 void LocationBarView::OnFocus() { | 1225 void LocationBarView::OnFocus() { |
| 1292 omnibox_view_->SetFocus(); | 1226 omnibox_view_->SetFocus(); |
| 1293 } | 1227 } |
| 1294 | 1228 |
| 1295 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1229 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 1296 View::OnPaint(canvas); | 1230 View::OnPaint(canvas); |
| 1297 | 1231 |
| 1298 if (ui::MaterialDesignController::IsModeMaterial()) { | 1232 if (show_focus_rect_ && omnibox_view_->HasFocus()) { |
| 1299 if (show_focus_rect_ && omnibox_view_->HasFocus()) { | 1233 SkPaint paint; |
| 1300 SkPaint paint; | 1234 paint.setAntiAlias(true); |
| 1301 paint.setAntiAlias(true); | 1235 paint.setColor(GetNativeTheme()->GetSystemColor( |
| 1302 paint.setColor(GetNativeTheme()->GetSystemColor( | 1236 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor)); |
| 1303 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor)); | 1237 paint.setStyle(SkPaint::kStroke_Style); |
| 1304 paint.setStyle(SkPaint::kStroke_Style); | 1238 paint.setStrokeWidth(1); |
| 1305 paint.setStrokeWidth(1); | 1239 gfx::RectF focus_rect(GetLocalBounds()); |
| 1306 gfx::RectF focus_rect(GetLocalBounds()); | 1240 focus_rect.Inset(gfx::InsetsF(0.5f)); |
| 1307 focus_rect.Inset(gfx::InsetsF(0.5f)); | 1241 canvas->DrawRoundRect(focus_rect, |
| 1308 canvas->DrawRoundRect( | 1242 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); |
| 1309 focus_rect, BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); | |
| 1310 } | |
| 1311 if (!is_popup_mode_) | |
| 1312 return; // The background and border are painted by our Background. | |
| 1313 } | 1243 } |
| 1244 if (!is_popup_mode_) |
| 1245 return; // The background and border are painted by our Background. |
| 1314 | 1246 |
| 1315 // Fill the location bar background color behind the border. Parts of the | 1247 // Fill the location bar background color behind the border. Parts of the |
| 1316 // border images are meant to rest atop the toolbar background and parts atop | 1248 // border images are meant to rest atop the toolbar background and parts atop |
| 1317 // the omnibox background, so we can't just blindly fill our entire bounds. | 1249 // the omnibox background, so we can't just blindly fill our entire bounds. |
| 1318 gfx::Rect bounds(GetContentsBounds()); | 1250 gfx::Rect bounds(GetContentsBounds()); |
| 1319 bounds.Inset(GetHorizontalEdgeThickness(), | 1251 bounds.Inset( |
| 1320 is_popup_mode_ ? 0 : GetVerticalEdgeThickness()); | 1252 GetHorizontalEdgeThickness(), |
| 1253 is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS)); |
| 1321 SkColor background_color(GetColor(BACKGROUND)); | 1254 SkColor background_color(GetColor(BACKGROUND)); |
| 1322 if (!is_popup_mode_) { | |
| 1323 SkPaint paint; | |
| 1324 paint.setStyle(SkPaint::kFill_Style); | |
| 1325 paint.setColor(background_color); | |
| 1326 const int kBorderCornerRadius = 2; | |
| 1327 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | |
| 1328 // The border itself will be drawn in PaintChildren() since it includes an | |
| 1329 // inner shadow which should be drawn over the contents. | |
| 1330 return; | |
| 1331 } | |
| 1332 | |
| 1333 canvas->FillRect(bounds, background_color); | 1255 canvas->FillRect(bounds, background_color); |
| 1334 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); | 1256 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); |
| 1335 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); | 1257 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); |
| 1336 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); | 1258 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); |
| 1337 } | 1259 } |
| 1338 | 1260 |
| 1339 void LocationBarView::PaintChildren(const ui::PaintContext& context) { | |
| 1340 View::PaintChildren(context); | |
| 1341 ui::PaintRecorder recorder(context, size()); | |
| 1342 | |
| 1343 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | |
| 1344 // the focus rect to appear on top of children we paint here rather than | |
| 1345 // OnPaint(). | |
| 1346 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | |
| 1347 if (!ui::MaterialDesignController::IsModeMaterial() && show_focus_rect_ && | |
| 1348 HasFocus()) | |
| 1349 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); | |
| 1350 | |
| 1351 if (!ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) { | |
| 1352 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | |
| 1353 GetContentsBounds()); | |
| 1354 } | |
| 1355 } | |
| 1356 | |
| 1357 //////////////////////////////////////////////////////////////////////////////// | 1261 //////////////////////////////////////////////////////////////////////////////// |
| 1358 // LocationBarView, private views::DragController implementation: | 1262 // LocationBarView, private views::DragController implementation: |
| 1359 | 1263 |
| 1360 void LocationBarView::WriteDragDataForView(views::View* sender, | 1264 void LocationBarView::WriteDragDataForView(views::View* sender, |
| 1361 const gfx::Point& press_pt, | 1265 const gfx::Point& press_pt, |
| 1362 OSExchangeData* data) { | 1266 OSExchangeData* data) { |
| 1363 DCHECK_NE(GetDragOperationsForView(sender, press_pt), | 1267 DCHECK_NE(GetDragOperationsForView(sender, press_pt), |
| 1364 ui::DragDropTypes::DRAG_NONE); | 1268 ui::DragDropTypes::DRAG_NONE); |
| 1365 | 1269 |
| 1366 WebContents* web_contents = GetWebContents(); | 1270 WebContents* web_contents = GetWebContents(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 // LocationBarView, private TemplateURLServiceObserver implementation: | 1327 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1424 | 1328 |
| 1425 void LocationBarView::OnTemplateURLServiceChanged() { | 1329 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1426 template_url_service_->RemoveObserver(this); | 1330 template_url_service_->RemoveObserver(this); |
| 1427 template_url_service_ = nullptr; | 1331 template_url_service_ = nullptr; |
| 1428 // If the browser is no longer active, let's not show the info bubble, as this | 1332 // If the browser is no longer active, let's not show the info bubble, as this |
| 1429 // would make the browser the active window again. | 1333 // would make the browser the active window again. |
| 1430 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1334 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1431 ShowFirstRunBubble(); | 1335 ShowFirstRunBubble(); |
| 1432 } | 1336 } |
| OLD | NEW |