| 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 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 15 #import "chrome/browser/app_controller_mac.h" | 16 #import "chrome/browser/app_controller_mac.h" |
| 16 #include "chrome/browser/command_updater.h" | 17 #include "chrome/browser/command_updater.h" |
| 17 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
| 18 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 #include "ui/gfx/vector_icons_public.h" | 77 #include "ui/gfx/vector_icons_public.h" |
| 77 | 78 |
| 78 using content::WebContents; | 79 using content::WebContents; |
| 79 | 80 |
| 80 namespace { | 81 namespace { |
| 81 | 82 |
| 82 // 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 |
| 83 // bubble arrow point. | 84 // bubble arrow point. |
| 84 const static int kFirstRunBubbleYOffset = 1; | 85 const static int kFirstRunBubbleYOffset = 1; |
| 85 | 86 |
| 87 const int kDefaultIconSize = 16; |
| 88 const int kMaterialSmallIconSize = 12; |
| 89 |
| 86 } // namespace | 90 } // namespace |
| 87 | 91 |
| 88 // TODO(shess): This code is mostly copied from the gtk | 92 // TODO(shess): This code is mostly copied from the gtk |
| 89 // implementation. Make sure it's all appropriate and flesh it out. | 93 // implementation. Make sure it's all appropriate and flesh it out. |
| 90 | 94 |
| 91 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, | 95 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, |
| 92 CommandUpdater* command_updater, | 96 CommandUpdater* command_updater, |
| 93 Profile* profile, | 97 Profile* profile, |
| 94 Browser* browser) | 98 Browser* browser) |
| 95 : LocationBar(profile), | 99 : LocationBar(profile), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 WebContents* web_contents = GetWebContents(); | 200 WebContents* web_contents = GetWebContents(); |
| 197 if (!web_contents) | 201 if (!web_contents) |
| 198 return; | 202 return; |
| 199 | 203 |
| 200 // |controller| may be nullptr due to lazy initialization. | 204 // |controller| may be nullptr due to lazy initialization. |
| 201 autofill::SaveCardBubbleControllerImpl* controller = | 205 autofill::SaveCardBubbleControllerImpl* controller = |
| 202 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); | 206 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); |
| 203 bool enabled = controller && controller->IsIconVisible(); | 207 bool enabled = controller && controller->IsIconVisible(); |
| 204 command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE, | 208 command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE, |
| 205 enabled); | 209 enabled); |
| 206 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; | 210 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 207 save_credit_card_decoration_->SetIcon(inDarkMode); | 211 save_credit_card_decoration_->SetIcon(in_dark_mode); |
| 208 save_credit_card_decoration_->SetVisible(enabled); | 212 save_credit_card_decoration_->SetVisible(enabled); |
| 209 OnDecorationsChanged(); | 213 OnDecorationsChanged(); |
| 210 } | 214 } |
| 211 | 215 |
| 212 void LocationBarViewMac::UpdatePageActions() { | 216 void LocationBarViewMac::UpdatePageActions() { |
| 213 RefreshPageActionDecorations(); | 217 RefreshPageActionDecorations(); |
| 214 Layout(); | 218 Layout(); |
| 215 | 219 |
| 216 [field_ updateMouseTracking]; | 220 [field_ updateMouseTracking]; |
| 217 [field_ setNeedsDisplay:YES]; | 221 [field_ setNeedsDisplay:YES]; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 if (star_decoration_->starred() == starred) | 344 if (star_decoration_->starred() == starred) |
| 341 return; | 345 return; |
| 342 | 346 |
| 343 star_decoration_->SetStarred(starred, | 347 star_decoration_->SetStarred(starred, |
| 344 [[field_ window] inIncognitoModeWithSystemTheme]); | 348 [[field_ window] inIncognitoModeWithSystemTheme]); |
| 345 UpdateBookmarkStarVisibility(); | 349 UpdateBookmarkStarVisibility(); |
| 346 OnDecorationsChanged(); | 350 OnDecorationsChanged(); |
| 347 } | 351 } |
| 348 | 352 |
| 349 void LocationBarViewMac::SetTranslateIconLit(bool on) { | 353 void LocationBarViewMac::SetTranslateIconLit(bool on) { |
| 350 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; | 354 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 351 translate_decoration_->SetLit(on, inDarkMode); | 355 translate_decoration_->SetLit(on, in_dark_mode); |
| 352 OnDecorationsChanged(); | 356 OnDecorationsChanged(); |
| 353 } | 357 } |
| 354 | 358 |
| 355 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { | 359 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 356 bool changed = UpdateZoomDecoration(/*default_zoom_changed=*/false); | 360 bool changed = UpdateZoomDecoration(/*default_zoom_changed=*/false); |
| 357 if (changed) | 361 if (changed) |
| 358 OnDecorationsChanged(); | 362 OnDecorationsChanged(); |
| 359 | 363 |
| 360 if (can_show_bubble && zoom_decoration_->IsVisible()) | 364 if (can_show_bubble && zoom_decoration_->IsVisible()) |
| 361 zoom_decoration_->ShowBubble(YES); | 365 zoom_decoration_->ShowBubble(YES); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 else | 552 else |
| 549 omnibox_view_->Update(); | 553 omnibox_view_->Update(); |
| 550 OnChanged(); | 554 OnChanged(); |
| 551 } | 555 } |
| 552 | 556 |
| 553 void LocationBarViewMac::UpdateWithoutTabRestore() { | 557 void LocationBarViewMac::UpdateWithoutTabRestore() { |
| 554 Update(nullptr); | 558 Update(nullptr); |
| 555 } | 559 } |
| 556 | 560 |
| 557 void LocationBarViewMac::UpdateLocationIcon() { | 561 void LocationBarViewMac::UpdateLocationIcon() { |
| 558 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; | 562 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 559 | 563 |
| 560 SkColor vectorIconColor = gfx::kPlaceholderColor; | 564 SkColor vector_icon_color = gfx::kPlaceholderColor; |
| 561 gfx::VectorIconId vectorIconId = gfx::VectorIconId::VECTOR_ICON_NONE; | 565 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; |
| 562 const int kIconSize = 16; | 566 int icon_size = kDefaultIconSize; |
| 563 if (ShouldShowEVBubble()) { | 567 if (ShouldShowEVBubble()) { |
| 564 vectorIconId = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; | 568 vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; |
| 565 vectorIconColor = gfx::kGoogleGreen700; | 569 vector_icon_color = gfx::kGoogleGreen700; |
| 570 icon_size = kMaterialSmallIconSize; |
| 566 } else { | 571 } else { |
| 567 vectorIconId = omnibox_view_->GetVectorIcon(inDarkMode); | 572 vector_icon_id = omnibox_view_->GetVectorIcon(in_dark_mode); |
| 568 if (inDarkMode) { | 573 if (in_dark_mode) { |
| 569 vectorIconColor = SK_ColorWHITE; | 574 vector_icon_color = SK_ColorWHITE; |
| 570 } else { | 575 } else { |
| 571 NSColor* textColor = OmniboxViewMac::BaseTextColor(inDarkMode); | 576 vector_icon_color = OmniboxViewMac::BaseTextColorSkia(in_dark_mode); |
| 572 // Convert to the device color space before getting the SkColor. | |
| 573 textColor = [textColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]; | |
| 574 vectorIconColor = skia::NSDeviceColorToSkColor(textColor); | |
| 575 } | 577 } |
| 576 } | 578 } |
| 577 | 579 |
| 578 DCHECK(vectorIconId != gfx::VectorIconId::VECTOR_ICON_NONE); | 580 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); |
| 579 NSImage* image = NSImageFromImageSkia(gfx::CreateVectorIcon( | 581 NSImage* image = NSImageFromImageSkiaWithColorSpace( |
| 580 vectorIconId, kIconSize, vectorIconColor)); | 582 gfx::CreateVectorIcon(vector_icon_id, icon_size, vector_icon_color), |
| 583 base::mac::GetSRGBColorSpace()); |
| 581 | 584 |
| 582 location_icon_decoration_->SetImage(image); | 585 location_icon_decoration_->SetImage(image); |
| 583 ev_bubble_decoration_->SetImage(image); | 586 ev_bubble_decoration_->SetImage(image); |
| 584 | |
| 585 Layout(); | 587 Layout(); |
| 586 } | 588 } |
| 587 | 589 |
| 588 void LocationBarViewMac::UpdateColorsToMatchTheme() { | 590 void LocationBarViewMac::UpdateColorsToMatchTheme() { |
| 589 if (!ui::MaterialDesignController::IsModeMaterial() || | 591 if (!ui::MaterialDesignController::IsModeMaterial() || |
| 590 ![[field_ window] inIncognitoMode]) { | 592 ![[field_ window] inIncognitoMode]) { |
| 591 return; | 593 return; |
| 592 } | 594 } |
| 593 | 595 |
| 594 // Update the location-bar icon. | 596 // Update the location-bar icon. |
| 595 UpdateLocationIcon(); | 597 UpdateLocationIcon(); |
| 596 | 598 |
| 597 // Make sure we're displaying the correct star color for Incognito mode. If | 599 // Make sure we're displaying the correct star color for Incognito mode. If |
| 598 // the window is in Incognito mode, switching between a theme and no theme | 600 // the window is in Incognito mode, switching between a theme and no theme |
| 599 // can move the window in and out of dark mode. | 601 // can move the window in and out of dark mode. |
| 600 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; | 602 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 601 star_decoration_->SetStarred(star_decoration_->starred(), inDarkMode); | 603 star_decoration_->SetStarred(star_decoration_->starred(), in_dark_mode); |
| 602 | 604 |
| 603 // Update the appearance of the text in the Omnibox. | 605 // Update the appearance of the text in the Omnibox. |
| 604 omnibox_view_->Update(); | 606 omnibox_view_->Update(); |
| 605 } | 607 } |
| 606 | 608 |
| 607 void LocationBarViewMac::OnAddedToWindow() { | 609 void LocationBarViewMac::OnAddedToWindow() { |
| 608 UpdateColorsToMatchTheme(); | 610 UpdateColorsToMatchTheme(); |
| 609 } | 611 } |
| 610 | 612 |
| 611 void LocationBarViewMac::OnThemeChanged() { | 613 void LocationBarViewMac::OnThemeChanged() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { | 656 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { |
| 655 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( | 657 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
| 656 profile())->GetTemplateURLForKeyword(keyword); | 658 profile())->GetTemplateURLForKeyword(keyword); |
| 657 if (template_url && | 659 if (template_url && |
| 658 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { | 660 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 659 return extensions::OmniboxAPI::Get(profile())-> | 661 return extensions::OmniboxAPI::Get(profile())-> |
| 660 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); | 662 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); |
| 661 } | 663 } |
| 662 | 664 |
| 663 return ui::MaterialDesignController::IsModeMaterial() | 665 return ui::MaterialDesignController::IsModeMaterial() |
| 664 ? NSImageFromImageSkia(gfx::CreateVectorIcon( | 666 ? NSImageFromImageSkiaWithColorSpace( |
| 665 gfx::VectorIconId::OMNIBOX_SEARCH, 16, gfx::kGoogleBlue700)) | 667 gfx::CreateVectorIcon( |
| 668 gfx::VectorIconId::OMNIBOX_SEARCH, |
| 669 kDefaultIconSize, |
| 670 gfx::kGoogleBlue700), |
| 671 base::mac::GetSRGBColorSpace()) |
| 666 : OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); | 672 : OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
| 667 } | 673 } |
| 668 | 674 |
| 669 void LocationBarViewMac::PostNotification(NSString* notification) { | 675 void LocationBarViewMac::PostNotification(NSString* notification) { |
| 670 [[NSNotificationCenter defaultCenter] postNotificationName:notification | 676 [[NSNotificationCenter defaultCenter] postNotificationName:notification |
| 671 object:[NSValue valueWithPointer:this]]; | 677 object:[NSValue valueWithPointer:this]]; |
| 672 } | 678 } |
| 673 | 679 |
| 674 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( | 680 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( |
| 675 ExtensionAction* page_action) { | 681 ExtensionAction* page_action) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 return; | 785 return; |
| 780 | 786 |
| 781 WebContents* web_contents = GetWebContents(); | 787 WebContents* web_contents = GetWebContents(); |
| 782 if (!web_contents) | 788 if (!web_contents) |
| 783 return; | 789 return; |
| 784 translate::LanguageState& language_state = | 790 translate::LanguageState& language_state = |
| 785 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); | 791 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); |
| 786 bool enabled = language_state.translate_enabled(); | 792 bool enabled = language_state.translate_enabled(); |
| 787 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); | 793 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); |
| 788 translate_decoration_->SetVisible(enabled); | 794 translate_decoration_->SetVisible(enabled); |
| 789 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; | 795 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 790 translate_decoration_->SetLit(language_state.IsPageTranslated(), inDarkMode); | 796 translate_decoration_->SetLit(language_state.IsPageTranslated(), |
| 797 in_dark_mode); |
| 791 } | 798 } |
| 792 | 799 |
| 793 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { | 800 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { |
| 794 WebContents* web_contents = GetWebContents(); | 801 WebContents* web_contents = GetWebContents(); |
| 795 if (!web_contents) | 802 if (!web_contents) |
| 796 return false; | 803 return false; |
| 797 | 804 |
| 798 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; | 805 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 799 return zoom_decoration_->UpdateIfNecessary( | 806 return zoom_decoration_->UpdateIfNecessary( |
| 800 ui_zoom::ZoomController::FromWebContents(web_contents), | 807 ui_zoom::ZoomController::FromWebContents(web_contents), |
| 801 default_zoom_changed, | 808 default_zoom_changed, |
| 802 inDarkMode); | 809 in_dark_mode); |
| 803 } | 810 } |
| 804 | 811 |
| 805 void LocationBarViewMac::OnDefaultZoomLevelChanged() { | 812 void LocationBarViewMac::OnDefaultZoomLevelChanged() { |
| 806 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) | 813 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) |
| 807 OnDecorationsChanged(); | 814 OnDecorationsChanged(); |
| 808 } | 815 } |
| OLD | NEW |