Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #import "base/mac/mac_util.h" | 9 #import "base/mac/mac_util.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/browser/translate/translate_service.h" | 27 #include "chrome/browser/translate/translate_service.h" |
| 28 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 28 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
| 29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
| 30 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 30 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " | 31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " |
| 32 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 32 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
| 33 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" | 33 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" |
| 34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 36 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 36 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 37 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | |
| 38 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 37 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| 39 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 38 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 40 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" |
| 41 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
| 42 #import "chrome/browser/ui/cocoa/location_bar/save_credit_card_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/save_credit_card_decoration.h" |
| 42 #import "chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.h " | |
| 43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 45 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" |
| 46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 53 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
| 54 #include "chrome/common/pref_names.h" | 54 #include "chrome/common/pref_names.h" |
| 55 #include "components/bookmarks/common/bookmark_pref_names.h" | 55 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 56 #import "components/omnibox/browser/omnibox_popup_model.h" | 56 #import "components/omnibox/browser/omnibox_popup_model.h" |
| 57 #include "components/prefs/pref_service.h" | 57 #include "components/prefs/pref_service.h" |
| 58 #include "components/search_engines/template_url.h" | 58 #include "components/search_engines/template_url.h" |
| 59 #include "components/search_engines/template_url_service.h" | 59 #include "components/search_engines/template_url_service.h" |
| 60 #include "components/security_state/security_state_model.h" | |
| 61 #include "components/translate/core/browser/language_state.h" | 60 #include "components/translate/core/browser/language_state.h" |
| 62 #include "components/zoom/zoom_controller.h" | 61 #include "components/zoom/zoom_controller.h" |
| 63 #include "components/zoom/zoom_event_manager.h" | 62 #include "components/zoom/zoom_event_manager.h" |
| 64 #include "content/public/browser/web_contents.h" | 63 #include "content/public/browser/web_contents.h" |
| 65 #include "extensions/browser/extension_system.h" | 64 #include "extensions/browser/extension_system.h" |
| 66 #include "extensions/common/extension.h" | 65 #include "extensions/common/extension.h" |
| 67 #include "grit/components_scaled_resources.h" | 66 #include "grit/components_scaled_resources.h" |
| 68 #include "grit/theme_resources.h" | 67 #include "grit/theme_resources.h" |
| 69 #include "skia/ext/skia_utils_mac.h" | 68 #include "skia/ext/skia_utils_mac.h" |
| 70 #import "ui/base/cocoa/cocoa_base_utils.h" | 69 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 71 #include "ui/base/l10n/l10n_util_mac.h" | 70 #include "ui/base/l10n/l10n_util_mac.h" |
| 72 #include "ui/base/material_design/material_design_controller.h" | 71 #include "ui/base/material_design/material_design_controller.h" |
| 73 #include "ui/gfx/color_palette.h" | 72 #include "ui/gfx/color_palette.h" |
| 74 #include "ui/gfx/color_utils.h" | 73 #include "ui/gfx/color_utils.h" |
| 75 #include "ui/gfx/image/image.h" | 74 #include "ui/gfx/image/image.h" |
| 76 #include "ui/gfx/image/image_skia_util_mac.h" | 75 #include "ui/gfx/image/image_skia_util_mac.h" |
| 77 #include "ui/gfx/paint_vector_icon.h" | 76 #include "ui/gfx/paint_vector_icon.h" |
| 78 #include "ui/gfx/vector_icons_public.h" | 77 #include "ui/gfx/vector_icons_public.h" |
| 79 | 78 |
| 80 using content::WebContents; | 79 using content::WebContents; |
| 81 | 80 |
| 82 namespace { | 81 namespace { |
| 83 | 82 |
| 84 // Vertical space between the bottom edge of the location_bar and the first run | 83 // Vertical space between the bottom edge of the location_bar and the first run |
| 85 // bubble arrow point. | 84 // bubble arrow point. |
| 86 const static int kFirstRunBubbleYOffset = 1; | 85 const static int kFirstRunBubbleYOffset = 1; |
| 87 | 86 |
| 88 const int kDefaultIconSize = 16; | 87 const int kDefaultIconSize = 16; |
| 89 | 88 |
| 89 // The minimum width the URL should have for the verbose state to be shown. | |
| 90 const int kMinURLWidth = 120; | |
| 91 | |
| 90 // Color of the vector graphic icons when the location bar is dark. | 92 // Color of the vector graphic icons when the location bar is dark. |
| 91 // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF); | 93 // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF); |
| 92 const SkColor kMaterialDarkVectorIconColor = SK_ColorWHITE; | 94 const SkColor kMaterialDarkVectorIconColor = SK_ColorWHITE; |
| 93 | 95 |
| 94 } // namespace | 96 } // namespace |
| 95 | 97 |
| 96 // TODO(shess): This code is mostly copied from the gtk | 98 // TODO(shess): This code is mostly copied from the gtk |
| 97 // implementation. Make sure it's all appropriate and flesh it out. | 99 // implementation. Make sure it's all appropriate and flesh it out. |
| 98 | 100 |
| 99 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, | 101 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, |
| 100 CommandUpdater* command_updater, | 102 CommandUpdater* command_updater, |
| 101 Profile* profile, | 103 Profile* profile, |
| 102 Browser* browser) | 104 Browser* browser) |
| 103 : LocationBar(profile), | 105 : LocationBar(profile), |
| 104 ChromeOmniboxEditController(command_updater), | 106 ChromeOmniboxEditController(command_updater), |
| 105 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), | 107 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), |
| 106 field_(field), | 108 field_(field), |
| 107 location_icon_decoration_(new LocationIconDecoration(this)), | 109 location_icon_decoration_(new LocationIconDecoration(this)), |
| 108 selected_keyword_decoration_(new SelectedKeywordDecoration()), | 110 selected_keyword_decoration_(new SelectedKeywordDecoration()), |
| 109 ev_bubble_decoration_( | 111 security_state_bubble_decoration_( |
| 110 new EVBubbleDecoration(location_icon_decoration_.get())), | 112 new SecurityStateBubbleDecoration(location_icon_decoration_.get(), |
| 113 this)), | |
| 111 save_credit_card_decoration_( | 114 save_credit_card_decoration_( |
| 112 new SaveCreditCardDecoration(command_updater)), | 115 new SaveCreditCardDecoration(command_updater)), |
| 113 star_decoration_(new StarDecoration(command_updater)), | 116 star_decoration_(new StarDecoration(command_updater)), |
| 114 translate_decoration_(new TranslateDecoration(command_updater)), | 117 translate_decoration_(new TranslateDecoration(command_updater)), |
| 115 zoom_decoration_(new ZoomDecoration(this)), | 118 zoom_decoration_(new ZoomDecoration(this)), |
| 116 keyword_hint_decoration_(new KeywordHintDecoration()), | 119 keyword_hint_decoration_(new KeywordHintDecoration()), |
| 117 manage_passwords_decoration_( | 120 manage_passwords_decoration_( |
| 118 new ManagePasswordsDecoration(command_updater, this)), | 121 new ManagePasswordsDecoration(command_updater, this)), |
| 119 browser_(browser), | 122 browser_(browser), |
| 120 location_bar_visible_(true), | 123 location_bar_visible_(true), |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 | 388 |
| 386 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const { | 389 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const { |
| 387 return [field_ bubblePointForDecoration:translate_decoration_.get()]; | 390 return [field_ bubblePointForDecoration:translate_decoration_.get()]; |
| 388 } | 391 } |
| 389 | 392 |
| 390 NSPoint LocationBarViewMac::GetManagePasswordsBubblePoint() const { | 393 NSPoint LocationBarViewMac::GetManagePasswordsBubblePoint() const { |
| 391 return [field_ bubblePointForDecoration:manage_passwords_decoration_.get()]; | 394 return [field_ bubblePointForDecoration:manage_passwords_decoration_.get()]; |
| 392 } | 395 } |
| 393 | 396 |
| 394 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { | 397 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { |
| 395 if (ev_bubble_decoration_->IsVisible()) { | 398 if (security_state_bubble_decoration_->IsVisible()) { |
| 396 return [field_ bubblePointForDecoration:ev_bubble_decoration_.get()]; | 399 return [field_ |
| 400 bubblePointForDecoration:security_state_bubble_decoration_.get()]; | |
| 397 } else { | 401 } else { |
| 398 return [field_ bubblePointForDecoration:location_icon_decoration_.get()]; | 402 return [field_ bubblePointForDecoration:location_icon_decoration_.get()]; |
| 399 } | 403 } |
| 400 } | 404 } |
| 401 | 405 |
| 402 void LocationBarViewMac::OnDecorationsChanged() { | 406 void LocationBarViewMac::OnDecorationsChanged() { |
| 403 // TODO(shess): The field-editor frame and cursor rects should not | 407 // TODO(shess): The field-editor frame and cursor rects should not |
| 404 // change, here. | 408 // change, here. |
| 405 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 409 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 406 for (auto* decoration : decorations) | 410 for (auto* decoration : decorations) |
| 407 UpdateAccessibilityViewPosition(decoration); | 411 UpdateAccessibilityViewPosition(decoration); |
| 408 [field_ updateMouseTracking]; | 412 [field_ updateMouseTracking]; |
| 409 [field_ resetFieldEditorFrameIfNeeded]; | 413 [field_ resetFieldEditorFrameIfNeeded]; |
| 410 [field_ setNeedsDisplay:YES]; | 414 [field_ setNeedsDisplay:YES]; |
| 411 } | 415 } |
| 412 | 416 |
| 413 // TODO(shess): This function should over time grow to closely match | 417 // TODO(shess): This function should over time grow to closely match |
| 414 // the views Layout() function. | 418 // the views Layout() function. |
| 415 void LocationBarViewMac::Layout() { | 419 void LocationBarViewMac::Layout() { |
| 416 AutocompleteTextFieldCell* cell = [field_ cell]; | 420 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 417 | 421 |
| 418 // Reset the left-hand decorations. | 422 // Reset the left-hand decorations. |
| 419 // TODO(shess): Shortly, this code will live somewhere else, like in | 423 // TODO(shess): Shortly, this code will live somewhere else, like in |
| 420 // the constructor. I am still wrestling with how best to deal with | 424 // the constructor. I am still wrestling with how best to deal with |
| 421 // right-hand decorations, which are not a static set. | 425 // right-hand decorations, which are not a static set. |
| 422 [cell clearDecorations]; | 426 [cell clearDecorations]; |
| 423 [cell addLeftDecoration:location_icon_decoration_.get()]; | 427 [cell addLeftDecoration:location_icon_decoration_.get()]; |
| 424 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 428 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
| 425 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 429 [cell addLeftDecoration:security_state_bubble_decoration_.get()]; |
| 426 [cell addRightDecoration:star_decoration_.get()]; | 430 [cell addRightDecoration:star_decoration_.get()]; |
| 427 [cell addRightDecoration:translate_decoration_.get()]; | 431 [cell addRightDecoration:translate_decoration_.get()]; |
| 428 [cell addRightDecoration:zoom_decoration_.get()]; | 432 [cell addRightDecoration:zoom_decoration_.get()]; |
| 429 [cell addRightDecoration:save_credit_card_decoration_.get()]; | 433 [cell addRightDecoration:save_credit_card_decoration_.get()]; |
| 430 [cell addRightDecoration:manage_passwords_decoration_.get()]; | 434 [cell addRightDecoration:manage_passwords_decoration_.get()]; |
| 431 | 435 |
| 432 // Note that display order is right to left. | 436 // Note that display order is right to left. |
| 433 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 437 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 434 [cell addRightDecoration:page_action_decorations_[i]]; | 438 [cell addRightDecoration:page_action_decorations_[i]]; |
| 435 } | 439 } |
| 436 | 440 |
| 437 for (ScopedVector<ContentSettingDecoration>::iterator i = | 441 for (ScopedVector<ContentSettingDecoration>::iterator i = |
| 438 content_setting_decorations_.begin(); | 442 content_setting_decorations_.begin(); |
| 439 i != content_setting_decorations_.end(); ++i) { | 443 i != content_setting_decorations_.end(); ++i) { |
| 440 [cell addRightDecoration:*i]; | 444 [cell addRightDecoration:*i]; |
| 441 } | 445 } |
| 442 | 446 |
| 443 [cell addRightDecoration:keyword_hint_decoration_.get()]; | 447 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
| 444 | 448 |
| 445 // By default only the location icon is visible. | 449 // By default only the location icon is visible. |
| 446 location_icon_decoration_->SetVisible(true); | 450 location_icon_decoration_->SetVisible(true); |
| 447 selected_keyword_decoration_->SetVisible(false); | 451 selected_keyword_decoration_->SetVisible(false); |
| 448 ev_bubble_decoration_->SetVisible(false); | |
| 449 keyword_hint_decoration_->SetVisible(false); | 452 keyword_hint_decoration_->SetVisible(false); |
| 450 | 453 |
| 454 if (omnibox_view_->IsEditingOrEmpty()) | |
| 455 security_state_bubble_decoration_->ResetAndHide(); | |
| 456 else | |
| 457 security_state_bubble_decoration_->SetVisible(false); | |
| 458 | |
| 451 // Get the keyword to use for keyword-search and hinting. | 459 // Get the keyword to use for keyword-search and hinting. |
| 452 const base::string16 keyword = omnibox_view_->model()->keyword(); | 460 const base::string16 keyword = omnibox_view_->model()->keyword(); |
| 453 base::string16 short_name; | 461 base::string16 short_name; |
| 454 bool is_extension_keyword = false; | 462 bool is_extension_keyword = false; |
| 455 if (!keyword.empty()) { | 463 if (!keyword.empty()) { |
| 456 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> | 464 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> |
| 457 GetKeywordShortName(keyword, &is_extension_keyword); | 465 GetKeywordShortName(keyword, &is_extension_keyword); |
| 458 } | 466 } |
| 459 | 467 |
| 460 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); | 468 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); |
| 461 if (!keyword.empty() && !is_keyword_hint) { | 469 if (!keyword.empty() && !is_keyword_hint) { |
| 462 // Switch from location icon to keyword mode. | 470 // Switch from location icon to keyword mode. |
| 463 location_icon_decoration_->SetVisible(false); | 471 location_icon_decoration_->SetVisible(false); |
| 464 selected_keyword_decoration_->SetVisible(true); | 472 selected_keyword_decoration_->SetVisible(true); |
| 465 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); | 473 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
| 466 // Note: the first time through this code path the | 474 // Note: the first time through this code path the |
| 467 // |selected_keyword_decoration_| has no image set because under Material | 475 // |selected_keyword_decoration_| has no image set because under Material |
| 468 // Design we need to set its color, which we cannot do until we know the | 476 // Design we need to set its color, which we cannot do until we know the |
| 469 // theme (by being installed in a browser window). | 477 // theme (by being installed in a browser window). |
| 470 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); | 478 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
| 479 } else if (!keyword.empty() && is_keyword_hint) { | |
| 480 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword); | |
| 481 keyword_hint_decoration_->SetVisible(true); | |
| 471 } else if (ShouldShowEVBubble()) { | 482 } else if (ShouldShowEVBubble()) { |
| 472 // Switch from location icon to show the EV bubble instead. | 483 // Switch from location icon to show the EV bubble instead. |
| 473 location_icon_decoration_->SetVisible(false); | 484 location_icon_decoration_->SetVisible(false); |
| 474 ev_bubble_decoration_->SetVisible(true); | 485 security_state_bubble_decoration_->SetVisible(true); |
| 475 | 486 |
| 476 base::string16 label(GetToolbarModel()->GetEVCertName()); | 487 base::string16 label(GetToolbarModel()->GetEVCertName()); |
| 477 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); | 488 security_state_bubble_decoration_->SetFullLabel( |
| 478 } else if (!keyword.empty() && is_keyword_hint) { | 489 base::SysUTF16ToNSString(label)); |
| 479 keyword_hint_decoration_->SetKeyword(short_name, | 490 } else if (ShouldShowSecurityState()) { |
| 480 is_extension_keyword); | 491 bool is_security_state_visible = true; |
| 481 keyword_hint_decoration_->SetVisible(true); | 492 CGFloat available_width = |
| 493 [cell availableWidthInFrame:[[cell controlView] frame]]; | |
| 494 | |
| 495 // If there's not enough space, animate out the security state bubble. | |
| 496 // Show it until it has finished animating out. | |
| 497 if (available_width < kMinURLWidth) { | |
| 498 is_security_state_visible = | |
| 499 security_state_bubble_decoration_->AnimatingOut(); | |
| 500 if (security_state_bubble_decoration_->HasAnimatedIn()) | |
| 501 security_state_bubble_decoration_->AnimateOut(); | |
| 502 } | |
| 503 | |
| 504 // Don't change the label if the bubble is in the process of animating | |
| 505 // out the old one. | |
| 506 base::string16 label(GetToolbarModel()->GetSecurityVerboseText()); | |
| 507 if (!security_state_bubble_decoration_->AnimatingOut()) { | |
| 508 security_state_bubble_decoration_->SetFullLabel( | |
| 509 base::SysUTF16ToNSString(label)); | |
| 510 } | |
| 511 | |
| 512 location_icon_decoration_->SetVisible(!is_security_state_visible); | |
| 513 security_state_bubble_decoration_->SetVisible(is_security_state_visible); | |
| 482 } | 514 } |
| 483 | 515 |
| 484 // These need to change anytime the layout changes. | 516 // These need to change anytime the layout changes. |
| 485 // TODO(shess): Anytime the field editor might have changed, the | 517 // TODO(shess): Anytime the field editor might have changed, the |
| 486 // cursor rects almost certainly should have changed. The tooltips | 518 // cursor rects almost certainly should have changed. The tooltips |
| 487 // might change even when the rects don't change. | 519 // might change even when the rects don't change. |
| 488 OnDecorationsChanged(); | 520 OnDecorationsChanged(); |
| 489 } | 521 } |
| 490 | 522 |
| 491 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { | 523 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 else | 592 else |
| 561 omnibox_view_->Update(); | 593 omnibox_view_->Update(); |
| 562 OnChanged(); | 594 OnChanged(); |
| 563 } | 595 } |
| 564 | 596 |
| 565 void LocationBarViewMac::UpdateWithoutTabRestore() { | 597 void LocationBarViewMac::UpdateWithoutTabRestore() { |
| 566 Update(nullptr); | 598 Update(nullptr); |
| 567 } | 599 } |
| 568 | 600 |
| 569 void LocationBarViewMac::UpdateLocationIcon() { | 601 void LocationBarViewMac::UpdateLocationIcon() { |
| 570 bool in_dark_mode = IsLocationBarDark(); | 602 SkColor vector_icon_color = GetLocationBarIconColor(); |
| 571 | 603 gfx::VectorIconId vector_icon_id = |
| 572 SkColor vector_icon_color = gfx::kPlaceholderColor; | 604 ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID |
| 573 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; | 605 : omnibox_view_->GetVectorIcon(); |
| 574 if (ShouldShowEVBubble()) { | |
| 575 vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID; | |
| 576 vector_icon_color = gfx::kGoogleGreen700; | |
| 577 } else { | |
| 578 vector_icon_id = omnibox_view_->GetVectorIcon(); | |
| 579 security_state::SecurityStateModel::SecurityLevel security_level = | |
| 580 GetToolbarModel()->GetSecurityLevel(false); | |
| 581 if (security_level == security_state::SecurityStateModel::NONE) { | |
| 582 vector_icon_color = gfx::kChromeIconGrey; | |
| 583 } else { | |
| 584 NSColor* sRGBColor = | |
| 585 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); | |
| 586 NSColor* deviceColor = | |
| 587 [sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; | |
| 588 vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor); | |
| 589 } | |
| 590 } | |
| 591 | |
| 592 // If the theme is dark, then the color should always be | |
| 593 // kMaterialDarkVectorIconColor. | |
| 594 if (in_dark_mode) | |
| 595 vector_icon_color = kMaterialDarkVectorIconColor; | |
| 596 | 606 |
| 597 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); | 607 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); |
| 598 NSImage* image = NSImageFromImageSkiaWithColorSpace( | 608 NSImage* image = NSImageFromImageSkiaWithColorSpace( |
| 599 gfx::CreateVectorIcon(vector_icon_id, kDefaultIconSize, | 609 gfx::CreateVectorIcon(vector_icon_id, kDefaultIconSize, |
| 600 vector_icon_color), | 610 vector_icon_color), |
| 601 base::mac::GetSRGBColorSpace()); | 611 base::mac::GetSRGBColorSpace()); |
| 602 location_icon_decoration_->SetImage(image); | 612 location_icon_decoration_->SetImage(image); |
| 603 ev_bubble_decoration_->SetImage(image); | 613 security_state_bubble_decoration_->SetImage(image); |
| 614 security_state_bubble_decoration_->SetLabelColor(vector_icon_color); | |
| 615 | |
| 604 Layout(); | 616 Layout(); |
| 617 | |
| 618 // If the security level has changed, check if the verbose state decoration | |
| 619 // needs to be animated. If we need to show it, animate it in. Otherwise, | |
| 620 // animate it out if it's already fully displayed. | |
|
Peter Kasting
2016/08/22 22:39:42
This isn't the right way to do things (sorry, krb
Kevin Bailey
2016/08/23 14:10:41
I'm not sure it simplifies things. First, when the
Peter Kasting
2016/08/23 18:57:55
It's not cheating, for two reasons.
First, the an
| |
| 621 security_state::SecurityStateModel::SecurityLevel new_security_level = | |
| 622 GetToolbarModel()->GetSecurityLevel(false); | |
| 623 bool is_secure_to_secure = IsSecureConnection(new_security_level) && | |
| 624 IsSecureConnection(security_level_); | |
| 625 if (security_level_ != new_security_level && !is_secure_to_secure) { | |
| 626 if (ShouldShowSecurityState()) | |
| 627 security_state_bubble_decoration_->AnimateIn(); | |
| 628 else if (security_state_bubble_decoration_->HasAnimatedIn()) | |
| 629 security_state_bubble_decoration_->AnimateOut(); | |
| 630 } else if (security_state_bubble_decoration_->HasAnimatedOut()) { | |
| 631 // Animate the verbose back in if it was animated out. | |
| 632 if (ShouldShowSecurityState()) | |
| 633 security_state_bubble_decoration_->AnimateIn(false); | |
| 634 } | |
| 635 security_level_ = new_security_level; | |
| 605 } | 636 } |
| 606 | 637 |
| 607 void LocationBarViewMac::UpdateColorsToMatchTheme() { | 638 void LocationBarViewMac::UpdateColorsToMatchTheme() { |
| 608 if (!ui::MaterialDesignController::IsModeMaterial() || | 639 if (!ui::MaterialDesignController::IsModeMaterial() || |
| 609 ![[field_ window] inIncognitoMode]) { | 640 ![[field_ window] inIncognitoMode]) { |
| 610 return; | 641 return; |
| 611 } | 642 } |
| 612 | 643 |
| 613 // Update the location-bar icon. | 644 // Update the location-bar icon. |
| 614 UpdateLocationIcon(); | 645 UpdateLocationIcon(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 629 | 660 |
| 630 void LocationBarViewMac::OnThemeChanged() { | 661 void LocationBarViewMac::OnThemeChanged() { |
| 631 UpdateColorsToMatchTheme(); | 662 UpdateColorsToMatchTheme(); |
| 632 } | 663 } |
| 633 | 664 |
| 634 void LocationBarViewMac::OnChanged() { | 665 void LocationBarViewMac::OnChanged() { |
| 635 if (!ui::MaterialDesignController::IsModeMaterial()) { | 666 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 636 const int resource_id = omnibox_view_->GetIcon(); | 667 const int resource_id = omnibox_view_->GetIcon(); |
| 637 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); | 668 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); |
| 638 location_icon_decoration_->SetImage(image); | 669 location_icon_decoration_->SetImage(image); |
| 639 ev_bubble_decoration_->SetImage(image); | 670 security_state_bubble_decoration_->SetImage(image); |
| 640 Layout(); | 671 Layout(); |
| 641 return; | 672 return; |
| 642 } | 673 } |
| 643 UpdateLocationIcon(); | 674 UpdateLocationIcon(); |
| 644 } | 675 } |
| 645 | 676 |
| 646 void LocationBarViewMac::ShowURL() { | 677 void LocationBarViewMac::ShowURL() { |
| 647 omnibox_view_->ShowURL(); | 678 omnibox_view_->ShowURL(); |
| 648 } | 679 } |
| 649 | 680 |
| 650 ToolbarModel* LocationBarViewMac::GetToolbarModel() { | 681 ToolbarModel* LocationBarViewMac::GetToolbarModel() { |
| 651 return browser_->toolbar_model(); | 682 return browser_->toolbar_model(); |
| 652 } | 683 } |
| 653 | 684 |
| 654 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { | 685 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { |
| 655 return browser_->toolbar_model(); | 686 return browser_->toolbar_model(); |
| 656 } | 687 } |
| 657 | 688 |
| 658 WebContents* LocationBarViewMac::GetWebContents() { | 689 WebContents* LocationBarViewMac::GetWebContents() { |
| 659 return browser_->tab_strip_model()->GetActiveWebContents(); | 690 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 660 } | 691 } |
| 661 | 692 |
| 662 bool LocationBarViewMac::ShouldShowEVBubble() const { | 693 bool LocationBarViewMac::ShouldShowEVBubble() const { |
| 663 return (GetToolbarModel()->GetSecurityLevel(false) == | 694 return (GetToolbarModel()->GetSecurityLevel(false) == |
| 664 security_state::SecurityStateModel::EV_SECURE); | 695 security_state::SecurityStateModel::EV_SECURE); |
| 665 } | 696 } |
| 666 | 697 |
| 698 bool LocationBarViewMac::ShouldShowSecurityState() const { | |
| 699 security_state::SecurityStateModel::SecurityLevel security = | |
| 700 GetToolbarModel()->GetSecurityLevel(false); | |
| 701 bool has_verbose_for_security = | |
| 702 IsSecureConnection(security) || | |
| 703 security == security_state::SecurityStateModel::SECURITY_ERROR; | |
| 704 | |
| 705 return ui::MaterialDesignController::IsModeMaterial() && | |
| 706 (has_verbose_for_security || | |
| 707 security_state_bubble_decoration_->AnimatingOut()) && | |
| 708 !omnibox_view_->IsEditingOrEmpty() && | |
| 709 !omnibox_view_->model()->is_keyword_hint(); | |
| 710 } | |
| 711 | |
| 667 bool LocationBarViewMac::IsLocationBarDark() const { | 712 bool LocationBarViewMac::IsLocationBarDark() const { |
| 668 return [[field_ window] inIncognitoModeWithSystemTheme]; | 713 return [[field_ window] inIncognitoModeWithSystemTheme]; |
| 669 } | 714 } |
| 670 | 715 |
| 671 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { | 716 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { |
| 672 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( | 717 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
| 673 profile())->GetTemplateURLForKeyword(keyword); | 718 profile())->GetTemplateURLForKeyword(keyword); |
| 674 if (template_url && | 719 if (template_url && |
| 675 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { | 720 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 676 return extensions::OmniboxAPI::Get(profile())-> | 721 return extensions::OmniboxAPI::Get(profile())-> |
| 677 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); | 722 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); |
| 678 } | 723 } |
| 679 | 724 |
| 680 if (ui::MaterialDesignController::IsModeMaterial()) { | 725 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 681 SkColor icon_color = IsLocationBarDark() ? kMaterialDarkVectorIconColor | 726 SkColor icon_color = IsLocationBarDark() ? kMaterialDarkVectorIconColor |
| 682 : gfx::kGoogleBlue700; | 727 : gfx::kGoogleBlue700; |
| 683 return NSImageFromImageSkiaWithColorSpace( | 728 return NSImageFromImageSkiaWithColorSpace( |
| 684 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, | 729 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, |
| 685 kDefaultIconSize, icon_color), | 730 kDefaultIconSize, icon_color), |
| 686 base::mac::GetSRGBColorSpace()); | 731 base::mac::GetSRGBColorSpace()); |
| 687 } | 732 } |
| 688 | 733 |
| 689 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); | 734 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
| 690 } | 735 } |
| 691 | 736 |
| 737 SkColor LocationBarViewMac::GetLocationBarIconColor() const { | |
| 738 bool in_dark_mode = IsLocationBarDark(); | |
| 739 if (in_dark_mode) | |
| 740 return kMaterialDarkVectorIconColor; | |
| 741 | |
| 742 if (ShouldShowEVBubble()) | |
| 743 return gfx::kGoogleGreen700; | |
| 744 | |
| 745 security_state::SecurityStateModel::SecurityLevel security_level = | |
| 746 GetToolbarModel()->GetSecurityLevel(false); | |
| 747 | |
| 748 if (security_level == security_state::SecurityStateModel::NONE) | |
| 749 return gfx::kChromeIconGrey; | |
| 750 | |
| 751 NSColor* sRGB_color = | |
|
Robert Sesek
2016/08/18 14:43:23
naming: all lowercase
spqchan
2016/08/18 18:37:18
Done.
| |
| 752 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); | |
| 753 NSColor* device_color = | |
| 754 [sRGB_color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; | |
| 755 return skia::NSDeviceColorToSkColor(device_color); | |
| 756 } | |
| 757 | |
| 692 void LocationBarViewMac::PostNotification(NSString* notification) { | 758 void LocationBarViewMac::PostNotification(NSString* notification) { |
| 693 [[NSNotificationCenter defaultCenter] postNotificationName:notification | 759 [[NSNotificationCenter defaultCenter] postNotificationName:notification |
| 694 object:[NSValue valueWithPointer:this]]; | 760 object:[NSValue valueWithPointer:this]]; |
| 695 } | 761 } |
| 696 | 762 |
| 697 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( | 763 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( |
| 698 ExtensionAction* page_action) { | 764 ExtensionAction* page_action) { |
| 699 DCHECK(page_action); | 765 DCHECK(page_action); |
| 700 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 766 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 701 if (page_action_decorations_[i]->GetPageAction() == page_action) | 767 if (page_action_decorations_[i]->GetPageAction() == page_action) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { | 882 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { |
| 817 WebContents* web_contents = GetWebContents(); | 883 WebContents* web_contents = GetWebContents(); |
| 818 if (!web_contents) | 884 if (!web_contents) |
| 819 return false; | 885 return false; |
| 820 | 886 |
| 821 return zoom_decoration_->UpdateIfNecessary( | 887 return zoom_decoration_->UpdateIfNecessary( |
| 822 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, | 888 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, |
| 823 IsLocationBarDark()); | 889 IsLocationBarDark()); |
| 824 } | 890 } |
| 825 | 891 |
| 892 bool LocationBarViewMac::IsSecureConnection( | |
| 893 security_state::SecurityStateModel::SecurityLevel level) const { | |
| 894 return level == security_state::SecurityStateModel::SECURE || | |
| 895 level == security_state::SecurityStateModel::EV_SECURE; | |
| 896 } | |
| 897 | |
| 826 void LocationBarViewMac::UpdateAccessibilityViewPosition( | 898 void LocationBarViewMac::UpdateAccessibilityViewPosition( |
| 827 LocationBarDecoration* decoration) { | 899 LocationBarDecoration* decoration) { |
| 828 if (!decoration->IsVisible()) | 900 if (!decoration->IsVisible()) |
| 829 return; | 901 return; |
| 830 NSRect r = | 902 NSRect r = |
| 831 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; | 903 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; |
| 832 [decoration->GetAccessibilityView() setFrame:r]; | 904 [decoration->GetAccessibilityView() setFrame:r]; |
| 833 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r]; | 905 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r]; |
| 834 } | 906 } |
| 835 | 907 |
| 836 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { | 908 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { |
| 837 std::vector<LocationBarDecoration*> decorations; | 909 std::vector<LocationBarDecoration*> decorations; |
| 838 // TODO(ellyjones): content setting decorations aren't included right now, nor | 910 // TODO(ellyjones): content setting decorations aren't included right now, nor |
| 839 // are page actions and the keyword hint. | 911 // are page actions and the keyword hint. |
| 840 decorations.push_back(location_icon_decoration_.get()); | 912 decorations.push_back(location_icon_decoration_.get()); |
| 841 decorations.push_back(selected_keyword_decoration_.get()); | 913 decorations.push_back(selected_keyword_decoration_.get()); |
| 842 decorations.push_back(ev_bubble_decoration_.get()); | 914 decorations.push_back(security_state_bubble_decoration_.get()); |
| 843 decorations.push_back(save_credit_card_decoration_.get()); | 915 decorations.push_back(save_credit_card_decoration_.get()); |
| 844 decorations.push_back(star_decoration_.get()); | 916 decorations.push_back(star_decoration_.get()); |
| 845 decorations.push_back(translate_decoration_.get()); | 917 decorations.push_back(translate_decoration_.get()); |
| 846 decorations.push_back(zoom_decoration_.get()); | 918 decorations.push_back(zoom_decoration_.get()); |
| 847 decorations.push_back(manage_passwords_decoration_.get()); | 919 decorations.push_back(manage_passwords_decoration_.get()); |
| 848 return decorations; | 920 return decorations; |
| 849 } | 921 } |
| 850 | 922 |
| 851 void LocationBarViewMac::OnDefaultZoomLevelChanged() { | 923 void LocationBarViewMac::OnDefaultZoomLevelChanged() { |
| 852 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) | 924 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) |
| 853 OnDecorationsChanged(); | 925 OnDecorationsChanged(); |
| 854 } | 926 } |
| 855 | 927 |
| 856 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 928 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 857 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 929 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 858 std::vector<NSView*> views; | 930 std::vector<NSView*> views; |
| 859 for (auto* decoration : decorations) | 931 for (auto* decoration : decorations) |
| 860 views.push_back(decoration->GetAccessibilityView()); | 932 views.push_back(decoration->GetAccessibilityView()); |
| 861 return views; | 933 return views; |
| 862 } | 934 } |
| OLD | NEW |