Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm

Issue 2119033002: [Material][Mac] Implement Omnibox Verbose State Chips (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 "chrome/grit/theme_resources.h" 55 #include "chrome/grit/theme_resources.h"
56 #include "components/bookmarks/common/bookmark_pref_names.h" 56 #include "components/bookmarks/common/bookmark_pref_names.h"
57 #include "components/grit/components_scaled_resources.h" 57 #include "components/grit/components_scaled_resources.h"
58 #import "components/omnibox/browser/omnibox_popup_model.h" 58 #import "components/omnibox/browser/omnibox_popup_model.h"
59 #include "components/prefs/pref_service.h" 59 #include "components/prefs/pref_service.h"
60 #include "components/search_engines/template_url.h" 60 #include "components/search_engines/template_url.h"
61 #include "components/search_engines/template_url_service.h" 61 #include "components/search_engines/template_url_service.h"
62 #include "components/security_state/security_state_model.h"
63 #include "components/translate/core/browser/language_state.h" 62 #include "components/translate/core/browser/language_state.h"
64 #include "components/zoom/zoom_controller.h" 63 #include "components/zoom/zoom_controller.h"
65 #include "components/zoom/zoom_event_manager.h" 64 #include "components/zoom/zoom_event_manager.h"
66 #include "content/public/browser/web_contents.h" 65 #include "content/public/browser/web_contents.h"
67 #include "extensions/browser/extension_system.h" 66 #include "extensions/browser/extension_system.h"
68 #include "extensions/common/extension.h" 67 #include "extensions/common/extension.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
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);
453 security_state_bubble_decoration_->SetVisible(false);
450 454
451 // Get the keyword to use for keyword-search and hinting. 455 // Get the keyword to use for keyword-search and hinting.
452 const base::string16 keyword = omnibox_view_->model()->keyword(); 456 const base::string16 keyword = omnibox_view_->model()->keyword();
453 base::string16 short_name; 457 base::string16 short_name;
454 bool is_extension_keyword = false; 458 bool is_extension_keyword = false;
455 if (!keyword.empty()) { 459 if (!keyword.empty()) {
456 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> 460 short_name = TemplateURLServiceFactory::GetForProfile(profile())->
457 GetKeywordShortName(keyword, &is_extension_keyword); 461 GetKeywordShortName(keyword, &is_extension_keyword);
458 } 462 }
459 463
460 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); 464 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint();
461 if (!keyword.empty() && !is_keyword_hint) { 465 if (!keyword.empty() && !is_keyword_hint) {
462 // Switch from location icon to keyword mode. 466 // Switch from location icon to keyword mode.
463 location_icon_decoration_->SetVisible(false); 467 location_icon_decoration_->SetVisible(false);
464 selected_keyword_decoration_->SetVisible(true); 468 selected_keyword_decoration_->SetVisible(true);
465 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); 469 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword);
466 // Note: the first time through this code path the 470 // Note: the first time through this code path the
467 // |selected_keyword_decoration_| has no image set because under Material 471 // |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 472 // Design we need to set its color, which we cannot do until we know the
469 // theme (by being installed in a browser window). 473 // theme (by being installed in a browser window).
470 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); 474 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword));
475 } else if (!keyword.empty() && is_keyword_hint) {
476 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword);
477 keyword_hint_decoration_->SetVisible(true);
471 } else if (ShouldShowEVBubble()) { 478 } else if (ShouldShowEVBubble()) {
472 // Switch from location icon to show the EV bubble instead. 479 // Switch from location icon to show the EV bubble instead.
473 location_icon_decoration_->SetVisible(false); 480 location_icon_decoration_->SetVisible(false);
474 ev_bubble_decoration_->SetVisible(true); 481 security_state_bubble_decoration_->SetVisible(true);
475 482
476 base::string16 label(GetToolbarModel()->GetEVCertName()); 483 base::string16 label(GetToolbarModel()->GetEVCertName());
477 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); 484 security_state_bubble_decoration_->SetFullLabel(
478 } else if (!keyword.empty() && is_keyword_hint) { 485 base::SysUTF16ToNSString(label));
479 keyword_hint_decoration_->SetKeyword(short_name, 486 } else if (ShouldShowSecurityState()) {
480 is_extension_keyword); 487 // TODO(spqchan): Clean up location_bar_view_mac so that animation
481 keyword_hint_decoration_->SetVisible(true); 488 // code isn't in Layout(). See crbug.com/642977.
489 bool is_security_state_visible = true;
490 CGFloat available_width =
491 [cell availableWidthInFrame:[[cell controlView] frame]];
492
493 if (available_width < kMinURLWidth) {
494 // If there's not enough space, animate out the security state bubble.
495 // Show it until it has finished animating out.
496 is_security_state_visible =
497 security_state_bubble_decoration_->AnimatingOut();
498 if (security_state_bubble_decoration_->HasAnimatedIn())
499 security_state_bubble_decoration_->AnimateOut();
500 } else if (security_state_bubble_decoration_->HasAnimatedOut()) {
501 // If there's enough space, but the secure state bubble had animated
502 // out, animate it back in.
503 security_state_bubble_decoration_->AnimateIn(false);
504 }
505
506 // Don't change the label if the bubble is in the process of animating
507 // out the old one.
508 base::string16 label(GetToolbarModel()->GetSecureVerboseText());
509 if (!security_state_bubble_decoration_->AnimatingOut()) {
510 security_state_bubble_decoration_->SetFullLabel(
511 base::SysUTF16ToNSString(label));
512 }
513
514 location_icon_decoration_->SetVisible(!is_security_state_visible);
515 security_state_bubble_decoration_->SetVisible(is_security_state_visible);
482 } 516 }
483 517
484 // These need to change anytime the layout changes. 518 // These need to change anytime the layout changes.
485 // TODO(shess): Anytime the field editor might have changed, the 519 // TODO(shess): Anytime the field editor might have changed, the
486 // cursor rects almost certainly should have changed. The tooltips 520 // cursor rects almost certainly should have changed. The tooltips
487 // might change even when the rects don't change. 521 // might change even when the rects don't change.
488 OnDecorationsChanged(); 522 OnDecorationsChanged();
489 } 523 }
490 524
491 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { 525 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 UpdateBookmarkStarVisibility(); 586 UpdateBookmarkStarVisibility();
553 UpdateSaveCreditCardIcon(); 587 UpdateSaveCreditCardIcon();
554 UpdateTranslateDecoration(); 588 UpdateTranslateDecoration();
555 UpdateZoomDecoration(/*default_zoom_changed=*/false); 589 UpdateZoomDecoration(/*default_zoom_changed=*/false);
556 RefreshPageActionDecorations(); 590 RefreshPageActionDecorations();
557 RefreshContentSettingsDecorations(); 591 RefreshContentSettingsDecorations();
558 if (contents) 592 if (contents)
559 omnibox_view_->OnTabChanged(contents); 593 omnibox_view_->OnTabChanged(contents);
560 else 594 else
561 omnibox_view_->Update(); 595 omnibox_view_->Update();
596
562 OnChanged(); 597 OnChanged();
598
599 // To avoid animating the security state bubble decoration if it
600 // should be hidden for a narrow omnibox, call UpdateSecurityState() after
601 // OnChanged().
602 UpdateSecurityState(contents);
563 } 603 }
564 604
565 void LocationBarViewMac::UpdateWithoutTabRestore() { 605 void LocationBarViewMac::UpdateWithoutTabRestore() {
566 Update(nullptr); 606 Update(nullptr);
567 } 607 }
568 608
569 void LocationBarViewMac::UpdateLocationIcon() { 609 void LocationBarViewMac::UpdateLocationIcon() {
570 bool in_dark_mode = IsLocationBarDark(); 610 SkColor vector_icon_color = GetLocationBarIconColor();
571 611 gfx::VectorIconId vector_icon_id =
572 SkColor vector_icon_color = gfx::kPlaceholderColor; 612 ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID
573 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; 613 : 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 614
597 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); 615 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE);
598 NSImage* image = NSImageFromImageSkiaWithColorSpace( 616 NSImage* image = NSImageFromImageSkiaWithColorSpace(
599 gfx::CreateVectorIcon(vector_icon_id, kDefaultIconSize, 617 gfx::CreateVectorIcon(vector_icon_id, kDefaultIconSize,
600 vector_icon_color), 618 vector_icon_color),
601 base::mac::GetSRGBColorSpace()); 619 base::mac::GetSRGBColorSpace());
602 location_icon_decoration_->SetImage(image); 620 location_icon_decoration_->SetImage(image);
603 ev_bubble_decoration_->SetImage(image); 621 security_state_bubble_decoration_->SetImage(image);
622 security_state_bubble_decoration_->SetLabelColor(vector_icon_color);
623
604 Layout(); 624 Layout();
605 } 625 }
606 626
607 void LocationBarViewMac::UpdateColorsToMatchTheme() { 627 void LocationBarViewMac::UpdateColorsToMatchTheme() {
608 if (!ui::MaterialDesignController::IsModeMaterial() || 628 if (!ui::MaterialDesignController::IsModeMaterial() ||
609 ![[field_ window] inIncognitoMode]) { 629 ![[field_ window] inIncognitoMode]) {
610 return; 630 return;
611 } 631 }
612 632
613 // Update the location-bar icon. 633 // Update the location-bar icon.
(...skipping 15 matching lines...) Expand all
629 649
630 void LocationBarViewMac::OnThemeChanged() { 650 void LocationBarViewMac::OnThemeChanged() {
631 UpdateColorsToMatchTheme(); 651 UpdateColorsToMatchTheme();
632 } 652 }
633 653
634 void LocationBarViewMac::OnChanged() { 654 void LocationBarViewMac::OnChanged() {
635 if (!ui::MaterialDesignController::IsModeMaterial()) { 655 if (!ui::MaterialDesignController::IsModeMaterial()) {
636 const int resource_id = omnibox_view_->GetIcon(); 656 const int resource_id = omnibox_view_->GetIcon();
637 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); 657 NSImage* image = OmniboxViewMac::ImageForResource(resource_id);
638 location_icon_decoration_->SetImage(image); 658 location_icon_decoration_->SetImage(image);
639 ev_bubble_decoration_->SetImage(image); 659 security_state_bubble_decoration_->SetImage(image);
640 Layout(); 660 Layout();
641 return; 661 return;
642 } 662 }
643 UpdateLocationIcon(); 663 UpdateLocationIcon();
644 } 664 }
645 665
646 void LocationBarViewMac::ShowURL() { 666 void LocationBarViewMac::ShowURL() {
647 omnibox_view_->ShowURL(); 667 omnibox_view_->ShowURL();
648 } 668 }
649 669
650 ToolbarModel* LocationBarViewMac::GetToolbarModel() { 670 ToolbarModel* LocationBarViewMac::GetToolbarModel() {
651 return browser_->toolbar_model(); 671 return browser_->toolbar_model();
652 } 672 }
653 673
654 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { 674 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const {
655 return browser_->toolbar_model(); 675 return browser_->toolbar_model();
656 } 676 }
657 677
658 WebContents* LocationBarViewMac::GetWebContents() { 678 WebContents* LocationBarViewMac::GetWebContents() {
659 return browser_->tab_strip_model()->GetActiveWebContents(); 679 return browser_->tab_strip_model()->GetActiveWebContents();
660 } 680 }
661 681
662 bool LocationBarViewMac::ShouldShowEVBubble() const { 682 bool LocationBarViewMac::ShouldShowEVBubble() const {
663 return (GetToolbarModel()->GetSecurityLevel(false) == 683 return (GetToolbarModel()->GetSecurityLevel(false) ==
664 security_state::SecurityStateModel::EV_SECURE); 684 security_state::SecurityStateModel::EV_SECURE);
665 } 685 }
666 686
687 bool LocationBarViewMac::ShouldShowSecurityState() const {
688 security_state::SecurityStateModel::SecurityLevel security =
689 GetToolbarModel()->GetSecurityLevel(false);
690 bool has_verbose_for_security =
691 IsSecureConnection(security) ||
692 security == security_state::SecurityStateModel::SECURITY_ERROR;
693
694 return ui::MaterialDesignController::IsModeMaterial() &&
695 has_verbose_for_security && !omnibox_view_->IsEditingOrEmpty() &&
696 !omnibox_view_->model()->is_keyword_hint();
697 }
698
667 bool LocationBarViewMac::IsLocationBarDark() const { 699 bool LocationBarViewMac::IsLocationBarDark() const {
668 return [[field_ window] inIncognitoModeWithSystemTheme]; 700 return [[field_ window] inIncognitoModeWithSystemTheme];
669 } 701 }
670 702
671 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { 703 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
672 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( 704 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
673 profile())->GetTemplateURLForKeyword(keyword); 705 profile())->GetTemplateURLForKeyword(keyword);
674 if (template_url && 706 if (template_url &&
675 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 707 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
676 return extensions::OmniboxAPI::Get(profile())-> 708 return extensions::OmniboxAPI::Get(profile())->
677 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); 709 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage();
678 } 710 }
679 711
680 if (ui::MaterialDesignController::IsModeMaterial()) { 712 if (ui::MaterialDesignController::IsModeMaterial()) {
681 SkColor icon_color = IsLocationBarDark() ? kMaterialDarkVectorIconColor 713 SkColor icon_color = IsLocationBarDark() ? kMaterialDarkVectorIconColor
682 : gfx::kGoogleBlue700; 714 : gfx::kGoogleBlue700;
683 return NSImageFromImageSkiaWithColorSpace( 715 return NSImageFromImageSkiaWithColorSpace(
684 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, 716 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH,
685 kDefaultIconSize, icon_color), 717 kDefaultIconSize, icon_color),
686 base::mac::GetSRGBColorSpace()); 718 base::mac::GetSRGBColorSpace());
687 } 719 }
688 720
689 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); 721 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
690 } 722 }
691 723
724 SkColor LocationBarViewMac::GetLocationBarIconColor() const {
725 bool in_dark_mode = IsLocationBarDark();
726 if (in_dark_mode)
727 return kMaterialDarkVectorIconColor;
728
729 if (ShouldShowEVBubble())
730 return gfx::kGoogleGreen700;
731
732 security_state::SecurityStateModel::SecurityLevel security_level =
733 GetToolbarModel()->GetSecurityLevel(false);
734
735 if (security_level == security_state::SecurityStateModel::NONE)
736 return gfx::kChromeIconGrey;
737
738 NSColor* srgb_color =
739 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode);
740 NSColor* device_color =
741 [srgb_color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
742 return skia::NSDeviceColorToSkColor(device_color);
743 }
744
692 void LocationBarViewMac::PostNotification(NSString* notification) { 745 void LocationBarViewMac::PostNotification(NSString* notification) {
693 [[NSNotificationCenter defaultCenter] postNotificationName:notification 746 [[NSNotificationCenter defaultCenter] postNotificationName:notification
694 object:[NSValue valueWithPointer:this]]; 747 object:[NSValue valueWithPointer:this]];
695 } 748 }
696 749
697 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( 750 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration(
698 ExtensionAction* page_action) { 751 ExtensionAction* page_action) {
699 DCHECK(page_action); 752 DCHECK(page_action);
700 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 753 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
701 if (page_action_decorations_[i]->GetPageAction() == page_action) 754 if (page_action_decorations_[i]->GetPageAction() == page_action)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { 869 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) {
817 WebContents* web_contents = GetWebContents(); 870 WebContents* web_contents = GetWebContents();
818 if (!web_contents) 871 if (!web_contents)
819 return false; 872 return false;
820 873
821 return zoom_decoration_->UpdateIfNecessary( 874 return zoom_decoration_->UpdateIfNecessary(
822 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, 875 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed,
823 IsLocationBarDark()); 876 IsLocationBarDark());
824 } 877 }
825 878
879 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) {
880 // If the security level has changed, check if the verbose state decoration
881 // needs to be animated. If we need to show it, animate it in. Otherwise,
882 // animate it out if it's already fully displayed.
883 security_state::SecurityStateModel::SecurityLevel new_security_level =
884 GetToolbarModel()->GetSecurityLevel(false);
885 bool is_secure_to_secure = IsSecureConnection(new_security_level) &&
886 IsSecureConnection(security_level_);
887 if (ShouldShowSecurityState() &&
888 security_state_bubble_decoration_->IsVisible()) {
889 // Animate the verbose if we entered a new connection state on the current
890 // tab. If it had animated out (from a narrow width).
891 if (!tab_changed &&
892 (security_level_ != new_security_level && !is_secure_to_secure)) {
893 security_state_bubble_decoration_->AnimateIn();
894 }
895 }
896
897 security_level_ = new_security_level;
898 }
899
900 bool LocationBarViewMac::IsSecureConnection(
901 security_state::SecurityStateModel::SecurityLevel level) const {
902 return level == security_state::SecurityStateModel::SECURE ||
903 level == security_state::SecurityStateModel::EV_SECURE;
904 }
905
826 void LocationBarViewMac::UpdateAccessibilityViewPosition( 906 void LocationBarViewMac::UpdateAccessibilityViewPosition(
827 LocationBarDecoration* decoration) { 907 LocationBarDecoration* decoration) {
828 if (!decoration->IsVisible()) 908 if (!decoration->IsVisible())
829 return; 909 return;
830 NSRect r = 910 NSRect r =
831 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; 911 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]];
832 [decoration->GetAccessibilityView() setFrame:r]; 912 [decoration->GetAccessibilityView() setFrame:r];
833 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r]; 913 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r];
834 } 914 }
835 915
836 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { 916 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() {
837 std::vector<LocationBarDecoration*> decorations; 917 std::vector<LocationBarDecoration*> decorations;
838 // TODO(ellyjones): content setting decorations aren't included right now, nor 918 // TODO(ellyjones): content setting decorations aren't included right now, nor
839 // are page actions and the keyword hint. 919 // are page actions and the keyword hint.
840 decorations.push_back(location_icon_decoration_.get()); 920 decorations.push_back(location_icon_decoration_.get());
841 decorations.push_back(selected_keyword_decoration_.get()); 921 decorations.push_back(selected_keyword_decoration_.get());
842 decorations.push_back(ev_bubble_decoration_.get()); 922 decorations.push_back(security_state_bubble_decoration_.get());
843 decorations.push_back(save_credit_card_decoration_.get()); 923 decorations.push_back(save_credit_card_decoration_.get());
844 decorations.push_back(star_decoration_.get()); 924 decorations.push_back(star_decoration_.get());
845 decorations.push_back(translate_decoration_.get()); 925 decorations.push_back(translate_decoration_.get());
846 decorations.push_back(zoom_decoration_.get()); 926 decorations.push_back(zoom_decoration_.get());
847 decorations.push_back(manage_passwords_decoration_.get()); 927 decorations.push_back(manage_passwords_decoration_.get());
848 return decorations; 928 return decorations;
849 } 929 }
850 930
851 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 931 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
852 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 932 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
853 OnDecorationsChanged(); 933 OnDecorationsChanged();
854 } 934 }
855 935
856 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { 936 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() {
857 std::vector<LocationBarDecoration*> decorations = GetDecorations(); 937 std::vector<LocationBarDecoration*> decorations = GetDecorations();
858 std::vector<NSView*> views; 938 std::vector<NSView*> views;
859 for (auto* decoration : decorations) 939 for (auto* decoration : decorations)
860 views.push_back(decoration->GetAccessibilityView()); 940 views.push_back(decoration->GetAccessibilityView());
861 return views; 941 return views;
862 } 942 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698