Commit 0a107cab authored by shrike's avatar shrike Committed by Commit bot

Convert location bar decorations to Material Design (Mac).

BUG=588152

Review URL: https://codereview.chromium.org/1718563002

Cr-Commit-Position: refs/heads/master@{#381567}
parent 7288268a
......@@ -381,6 +381,14 @@ const CGFloat kAnimationDuration = 0.2;
return;
}
// Allow the ToolbarController to take action upon the
// AutocompleteTextField being added to the window.
if (ui::MaterialDesignController::IsModeMaterial()) {
BrowserWindowController* browserWindowController =
[BrowserWindowController browserWindowControllerForView:self];
[[browserWindowController toolbarController] locationBarWasAddedToWindow];
}
// Invert the textfield's colors when Material Design and Incognito and not
// a custom theme.
if (ui::MaterialDesignController::IsModeMaterial() &&
......
......@@ -23,6 +23,7 @@ class BubbleDecoration : public LocationBarDecoration {
// Setup the drawing parameters.
NSImage* GetImage();
virtual NSColor* GetBackgroundBorderColor() = 0;
void SetImage(NSImage* image);
void SetLabel(NSString* label);
void SetTextColor(NSColor* text_color);
......
......@@ -7,6 +7,10 @@
#import "chrome/browser/ui/cocoa/location_bar/bubble_decoration.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "ui/base/cocoa/nsview_additions.h"
#include "ui/base/material_design/material_design_controller.h"
namespace {
......@@ -14,7 +18,10 @@ namespace {
const CGFloat kRightSideMargin = 1.0;
// Padding between the icon/label and bubble edges.
const CGFloat kBubblePadding = 3.0;
CGFloat BubblePadding() {
return ui::MaterialDesignController::IsModeMaterial() ? 7 : 3;
}
// Padding between the icon and label.
const CGFloat kIconLabelPadding = 4.0;
......@@ -39,14 +46,14 @@ CGFloat BubbleDecoration::GetWidthForImageAndLabel(NSImage* image,
const CGFloat image_width = image ? [image size].width : 0.0;
if (!label)
return kBubblePadding + image_width;
return BubblePadding() + image_width;
// The bubble needs to take up an integral number of pixels.
// Generally -sizeWithAttributes: seems to overestimate rather than
// underestimate, so floor() seems to work better.
const CGFloat label_width =
std::floor([label sizeWithAttributes:attributes_].width);
return kBubblePadding + image_width + kIconLabelPadding + label_width;
return BubblePadding() + image_width + kIconLabelPadding + label_width;
}
NSRect BubbleDecoration::GetImageRectInFrame(NSRect frame) {
......@@ -105,8 +112,25 @@ void BubbleDecoration::DrawWithBackgroundInFrame(NSRect background_frame,
NSView* control_view) {
NSRect rect = NSInsetRect(background_frame, 0, 1);
rect.size.width -= kRightSideMargin;
ui::DrawNinePartImage(
rect, GetBubbleImageIds(), NSCompositeSourceOver, 1.0, true);
if (ui::MaterialDesignController::IsModeMaterial()) {
CGFloat lineWidth = [control_view cr_lineWidth];
rect = NSInsetRect(rect, lineWidth / 2., lineWidth / 2.);
NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:rect
xRadius:3
yRadius:3];
[path setLineWidth:lineWidth];
bool inDarkMode = [[control_view window] inIncognitoModeWithSystemTheme];
if (inDarkMode) {
[[NSColor whiteColor] set];
[path fill];
} else {
[GetBackgroundBorderColor() set];
[path stroke];
}
} else {
ui::DrawNinePartImage(
rect, GetBubbleImageIds(), NSCompositeSourceOver, 1.0, true);
}
DrawInFrame(frame, control_view);
}
......
......@@ -11,7 +11,8 @@
#include "components/content_settings/core/common/content_settings_types.h"
// ContentSettingDecoration is used to display the content settings
// images on the current page.
// images on the current page. For example, the decoration animates into and out
// of view when a page attempts to show a popup and the popup blocker is on.
@class ContentSettingAnimationState;
class ContentSettingImageModel;
......
......@@ -16,14 +16,19 @@
#import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h"
#include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_contents.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
#include "ui/base/cocoa/appkit_utils.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#import "ui/base/cocoa/nsview_additions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/mac/coordinate_conversion.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
......@@ -334,10 +339,37 @@ CGFloat ContentSettingDecoration::GetWidthForSpace(CGFloat width) {
void ContentSettingDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
if ([animation_ animationState] != kNoAnimation) {
NSRect background_rect = NSInsetRect(frame, 0.0, kBorderPadding);
const ui::NinePartImageIds image_ids =
IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE);
ui::DrawNinePartImage(
background_rect, image_ids, NSCompositeSourceOver, 1.0, true);
// This code is almost identical to code that appears in BubbleDecoration.
// Unfortunately ContentSettingDecoration does not descend from
// BubbleDecoration. Even if we move the code to LocationBarDecoration (the
// common ancestor) the semantics here are slightly different: there's a
// general DrawBackgroundInFrame() method for LocationBarDecorations that
// draws the background and then calls DrawInFrame(), but for some reason
// this ContentSettingDecoration's DrawInFrame() also draws the background.
// In short, moving this code upstream to a common parent requires a non-
// trivial bit of refactoring.
if (ui::MaterialDesignController::IsModeMaterial()) {
CGFloat lineWidth = [control_view cr_lineWidth];
NSRect rect =
NSInsetRect(background_rect, lineWidth / 2., lineWidth / 2.);
NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:rect
xRadius:3
yRadius:3];
[path setLineWidth:lineWidth];
bool inDarkMode = [[control_view window] inIncognitoModeWithSystemTheme];
if (inDarkMode) {
[[NSColor whiteColor] set];
[path fill];
} else {
[skia::SkColorToCalibratedNSColor(gfx::kGoogleYellow700) set];
[path stroke];
}
} else {
const ui::NinePartImageIds image_ids =
IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE);
ui::DrawNinePartImage(
background_rect, image_ids, NSCompositeSourceOver, 1.0, true);
}
// Draw the icon.
NSImage* icon = GetImage();
......
......@@ -26,6 +26,9 @@ class EVBubbleDecoration : public BubbleDecoration {
explicit EVBubbleDecoration(LocationIconDecoration* location_icon);
~EVBubbleDecoration() override;
// Return the color used to draw the EvBubbleDecoration background in MD.
NSColor* GetBackgroundBorderColor() override;
// |GetWidthForSpace()| will set |full_label| as the label, if it
// fits, else it will set an elided version.
void SetFullLabel(NSString* full_label);
......
......@@ -8,6 +8,9 @@
#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/text_elider.h"
......@@ -49,12 +52,20 @@ NSColor* ColorWithRGBBytes(int rr, int gg, int bb) {
EVBubbleDecoration::EVBubbleDecoration(LocationIconDecoration* location_icon)
: location_icon_(location_icon) {
// Color tuples stolen from location_bar_view_gtk.cc.
SetTextColor(ColorWithRGBBytes(0x07, 0x95, 0x00));
if (ui::MaterialDesignController::IsModeMaterial()) {
SetTextColor(GetBackgroundBorderColor());
} else {
// Color tuples stolen from location_bar_view_gtk.cc.
SetTextColor(ColorWithRGBBytes(0x07, 0x95, 0x00));
}
}
EVBubbleDecoration::~EVBubbleDecoration() {}
NSColor* EVBubbleDecoration::GetBackgroundBorderColor() {
return skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700);
}
void EVBubbleDecoration::SetFullLabel(NSString* label) {
full_label_.reset([label retain]);
SetLabel(full_label_);
......
......@@ -159,6 +159,14 @@ class LocationBarViewMac : public LocationBar,
// Clears any location bar state stored for |contents|.
void ResetTabState(content::WebContents* contents);
// Set the location bar's icon to the correct image for the current URL.
void UpdateLocationIcon();
// Notify the location bar that it was added to the browser window. Provides
// an update point for interface objects that need to set their appearance
// based on the window's theme.
void OnAddedToWindow();
// ChromeOmniboxEditController:
void UpdateWithoutTabRestore() override;
void OnChanged() override;
......@@ -168,6 +176,7 @@ class LocationBarViewMac : public LocationBar,
const ToolbarModel* GetToolbarModel() const override;
content::WebContents* GetWebContents() override;
bool ShouldShowEVBubble() const;
NSImage* GetKeywordImage(const base::string16& keyword);
AutocompleteTextField* GetAutocompleteTextField() { return field_; }
......
......@@ -67,7 +67,13 @@
#include "skia/ext/skia_utils_mac.h"
#import "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
using content::WebContents;
......@@ -197,6 +203,8 @@ void LocationBarViewMac::UpdateSaveCreditCardIcon() {
bool enabled = controller && controller->IsIconVisible();
command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE,
enabled);
bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
save_credit_card_decoration_->SetIcon(inDarkMode);
save_credit_card_decoration_->SetVisible(enabled);
OnDecorationsChanged();
}
......@@ -339,7 +347,8 @@ void LocationBarViewMac::SetStarred(bool starred) {
}
void LocationBarViewMac::SetTranslateIconLit(bool on) {
translate_decoration_->SetLit(on);
bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
translate_decoration_->SetLit(on, inDarkMode);
OnDecorationsChanged();
}
......@@ -447,8 +456,7 @@ void LocationBarViewMac::Layout() {
selected_keyword_decoration_->SetVisible(true);
selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword);
selected_keyword_decoration_->SetImage(GetKeywordImage(keyword));
} else if (GetToolbarModel()->GetSecurityLevel(false) ==
security_state::SecurityStateModel::EV_SECURE) {
} else if (ShouldShowEVBubble()) {
// Switch from location icon to show the EV bubble instead.
location_icon_decoration_->SetVisible(false);
ev_bubble_decoration_->SetVisible(true);
......@@ -546,20 +554,64 @@ void LocationBarViewMac::UpdateWithoutTabRestore() {
Update(nullptr);
}
void LocationBarViewMac::OnChanged() {
// Update the location-bar icon.
const int resource_id = omnibox_view_->GetIcon();
NSImage* image = OmniboxViewMac::ImageForResource(resource_id);
void LocationBarViewMac::UpdateLocationIcon() {
bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
SkColor vectorIconColor = gfx::kPlaceholderColor;
gfx::VectorIconId vectorIconId = gfx::VectorIconId::VECTOR_ICON_NONE;
const int kIconSize = 16;
if (ShouldShowEVBubble()) {
vectorIconId = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP;
vectorIconColor = gfx::kGoogleGreen700;
} else {
vectorIconId = omnibox_view_->GetVectorIcon(inDarkMode);
if (inDarkMode) {
vectorIconColor = SK_ColorWHITE;
} else {
NSColor* textColor = OmniboxViewMac::BaseTextColor(inDarkMode);
// Convert to the device color space before getting the SkColor.
textColor = [textColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
vectorIconColor = skia::NSDeviceColorToSkColor(textColor);
}
}
DCHECK(vectorIconId != gfx::VectorIconId::VECTOR_ICON_NONE);
NSImage* image = NSImageFromImageSkia(gfx::CreateVectorIcon(
vectorIconId, kIconSize, vectorIconColor));
location_icon_decoration_->SetImage(image);
ev_bubble_decoration_->SetImage(image);
Layout();
}
void LocationBarViewMac::OnAddedToWindow() {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return;
}
// Update the location-bar icon.
UpdateLocationIcon();
// Make sure we're displaying the correct icon color for a dark location bar.
// Make sure we're displaying the correct star color for a dark location bar.
if ([[field_ window] inIncognitoModeWithSystemTheme]) {
star_decoration_->SetStarred(star_decoration_->starred(), true);
}
}
void LocationBarViewMac::OnChanged() {
NSImage* image = nil;
if (ui::MaterialDesignController::IsModeMaterial()) {
UpdateLocationIcon();
} else {
const int resource_id = omnibox_view_->GetIcon();
image = OmniboxViewMac::ImageForResource(resource_id);
location_icon_decoration_->SetImage(image);
ev_bubble_decoration_->SetImage(image);
Layout();
}
}
void LocationBarViewMac::OnSetFocus() {
// Update the keyword and search hint states.
OnChanged();
......@@ -581,6 +633,11 @@ WebContents* LocationBarViewMac::GetWebContents() {
return browser_->tab_strip_model()->GetActiveWebContents();
}
bool LocationBarViewMac::ShouldShowEVBubble() const {
return (GetToolbarModel()->GetSecurityLevel(false) ==
security_state::SecurityStateModel::EV_SECURE);
}
NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
profile())->GetTemplateURLForKeyword(keyword);
......@@ -590,7 +647,10 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage();
}
return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
return ui::MaterialDesignController::IsModeMaterial()
? NSImageFromImageSkia(gfx::CreateVectorIcon(
gfx::VectorIconId::OMNIBOX_SEARCH, 16, gfx::kGoogleBlue700))
: OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
}
void LocationBarViewMac::PostNotification(NSString* notification) {
......@@ -713,7 +773,8 @@ void LocationBarViewMac::UpdateTranslateDecoration() {
bool enabled = language_state.translate_enabled();
command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
translate_decoration_->SetVisible(enabled);
translate_decoration_->SetLit(language_state.IsPageTranslated());
bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
translate_decoration_->SetLit(language_state.IsPageTranslated(), inDarkMode);
}
bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) {
......@@ -721,9 +782,11 @@ bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) {
if (!web_contents)
return false;
bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
return zoom_decoration_->UpdateIfNecessary(
ui_zoom::ZoomController::FromWebContents(web_contents),
default_zoom_changed);
default_zoom_changed,
inDarkMode);
}
void LocationBarViewMac::OnDefaultZoomLevelChanged() {
......
......@@ -9,7 +9,14 @@
#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
#include "chrome/browser/ui/cocoa/passwords/passwords_bubble_cocoa.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
// ManagePasswordsIconCocoa
......@@ -81,7 +88,22 @@ void ManagePasswordsDecoration::UpdateUIState() {
return;
}
SetVisible(true);
SetImage(OmniboxViewMac::ImageForResource(icon_->icon_id()));
if (!ui::MaterialDesignController::IsModeMaterial()) {
SetImage(OmniboxViewMac::ImageForResource(icon_->icon_id()));
} else {
int resource_id = icon_->icon_id();
bool locationBarIsDark =
[[location_bar_->GetAutocompleteTextField() window]
inIncognitoModeWithSystemTheme];
SkColor vectorIconColor = gfx::kGoogleBlue700;
if (resource_id != IDR_SAVE_PASSWORD_ACTIVE) {
vectorIconColor = locationBarIsDark ? SK_ColorWHITE
: gfx::kChromeIconGrey;
}
NSImage* theImage = NSImageFromImageSkia(gfx::CreateVectorIcon(
gfx::VectorIconId::AUTOLOGIN, 16, vectorIconColor));
SetImage(theImage);
}
}
void ManagePasswordsDecoration::UpdateVisibleUI() {
......
......@@ -20,6 +20,11 @@ class SaveCreditCardDecoration : public ImageDecoration {
explicit SaveCreditCardDecoration(CommandUpdater* command_updater);
~SaveCreditCardDecoration() override;
// Set up the SaveCreditCardDecoration's icon to match the darkness of the
// location bar. This happens once the location bar has been added to the
// window so that we know the theme.
void SetIcon(bool locationBarIsDark);
// LocationBarDecoration implementation:
bool AcceptsMousePress() override;
bool OnMousePressed(NSRect frame, NSPoint location) override;
......
......@@ -8,6 +8,8 @@
#include "chrome/browser/command_updater.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
......@@ -15,12 +17,22 @@
SaveCreditCardDecoration::SaveCreditCardDecoration(
CommandUpdater* command_updater)
: command_updater_(command_updater) {
SetImage(NSImageFromImageSkia(gfx::CreateVectorIcon(
gfx::VectorIconId::CREDIT_CARD, 16, SkColorSetRGB(0x96, 0x96, 0x96))));
}
SaveCreditCardDecoration::~SaveCreditCardDecoration() {}
void SaveCreditCardDecoration::SetIcon(bool locationBarIsDark) {
SkColor theColor = gfx::kPlaceholderColor;
if (ui::MaterialDesignController::IsModeMaterial()) {
theColor = locationBarIsDark ? SK_ColorWHITE : gfx::kChromeIconGrey;
} else {
theColor = SkColorSetRGB(0x96, 0x96, 0x96);
}
SetImage(NSImageFromImageSkia(gfx::CreateVectorIcon(
gfx::VectorIconId::CREDIT_CARD, 16, theColor)));
}
NSPoint SaveCreditCardDecoration::GetBubblePointInFrame(NSRect frame) {
const NSRect draw_frame = GetDrawRectInFrame(frame);
return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame));
......
......@@ -19,6 +19,9 @@ class SelectedKeywordDecoration : public BubbleDecoration {
SelectedKeywordDecoration();
~SelectedKeywordDecoration() override;
// Return the color used to draw the SelectedKeywordDecoration in MD.
NSColor* GetBackgroundBorderColor() override;
// Calculates appropriate full and partial label strings based on
// inputs.
void SetKeyword(const base::string16& keyword, bool is_extension_keyword);
......
......@@ -9,16 +9,30 @@
#include "chrome/browser/ui/location_bar/location_bar_util.h"
#include "chrome/grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
SelectedKeywordDecoration::SelectedKeywordDecoration() {
search_image_.reset([OmniboxViewMac::ImageForResource(
IDR_KEYWORD_SEARCH_MAGNIFIER) retain]);
SetTextColor([NSColor blackColor]);
if (!ui::MaterialDesignController::IsModeMaterial()) {
search_image_.reset([OmniboxViewMac::ImageForResource(
IDR_KEYWORD_SEARCH_MAGNIFIER) retain]);
SetTextColor([NSColor blackColor]);
} else {
SetTextColor(GetBackgroundBorderColor());
}
}
SelectedKeywordDecoration::~SelectedKeywordDecoration() {}
NSColor* SelectedKeywordDecoration::GetBackgroundBorderColor() {
return skia::SkColorToCalibratedNSColor(gfx::kGoogleBlue700);
}
CGFloat SelectedKeywordDecoration::GetWidthForSpace(CGFloat width) {
const CGFloat full_width =
GetWidthForImageAndLabel(search_image_, full_string_);
......
......@@ -22,7 +22,7 @@ class TranslateDecoration : public ImageDecoration {
~TranslateDecoration() override;
// Toggles the icon on or off.
void SetLit(bool on);
void SetLit(bool on, bool locationBarIsDark);
// Implement |LocationBarDecoration|
bool AcceptsMousePress() override;
......
......@@ -10,17 +10,32 @@
#include "chrome/grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
TranslateDecoration::TranslateDecoration(CommandUpdater* command_updater)
: command_updater_(command_updater) {
SetLit(false);
SetLit(false, false);
}
TranslateDecoration::~TranslateDecoration() {}
void TranslateDecoration::SetLit(bool on) {
const int image_id = on ? IDR_TRANSLATE_ACTIVE : IDR_TRANSLATE;
SetImage(OmniboxViewMac::ImageForResource(image_id));
void TranslateDecoration::SetLit(bool on, bool locationBarIsDark) {
if (ui::MaterialDesignController::IsModeMaterial()) {
SkColor vectorIconColor = locationBarIsDark ? SK_ColorWHITE
: gfx::kChromeIconGrey;
NSImage* theImage =
NSImageFromImageSkia(gfx::CreateVectorIcon(gfx::VectorIconId::TRANSLATE,
16,
vectorIconColor));
SetImage(theImage);
} else {
const int image_id = on ? IDR_TRANSLATE_ACTIVE : IDR_TRANSLATE;
SetImage(OmniboxViewMac::ImageForResource(image_id));
}
}
NSPoint TranslateDecoration::GetBubblePointInFrame(NSRect frame) {
......
......@@ -30,7 +30,8 @@ class ZoomDecoration : public ImageDecoration,
// Called when this decoration should show or hide itself in its most current
// state. Returns whether any updates were made.
bool UpdateIfNecessary(ui_zoom::ZoomController* zoom_controller,
bool default_zoom_changed);
bool default_zoom_changed,
bool location_bar_is_dark);
// Shows the zoom bubble for this decoration. If |auto_close| is YES, then
// the bubble will automatically close after a fixed period of time.
......@@ -48,7 +49,8 @@ class ZoomDecoration : public ImageDecoration,
// Show and update UI associated with the zoom decoration.
// Virtual and protected for testing.
virtual void ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller,
NSString* tooltip_string);
NSString* tooltip_string,
bool location_bar_is_dark);
private:
friend ZoomDecorationTest;
......
......@@ -16,6 +16,11 @@
#include "grit/theme_resources.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner)
: owner_(owner),
......@@ -28,7 +33,9 @@ ZoomDecoration::~ZoomDecoration() {
}
bool ZoomDecoration::UpdateIfNecessary(
ui_zoom::ZoomController* zoom_controller, bool default_zoom_changed) {
ui_zoom::ZoomController* zoom_controller,
bool default_zoom_changed,
bool location_bar_is_dark) {
if (!ShouldShowDecoration()) {
if (!IsVisible() && !bubble_)
return false;
......@@ -47,7 +54,7 @@ bool ZoomDecoration::UpdateIfNecessary(
return false;
}
ShowAndUpdateUI(zoom_controller, zoom_string);
ShowAndUpdateUI(zoom_controller, zoom_string, location_bar_is_dark);
return true;
}
......@@ -88,16 +95,35 @@ void ZoomDecoration::HideUI() {
}
void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller,
NSString* tooltip_string) {
int image_id = IDR_ZOOM_NORMAL;
ui_zoom::ZoomController::RelativeZoom relative_zoom =
zoom_controller->GetZoomRelativeToDefault();
if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM)
image_id = IDR_ZOOM_MINUS;
else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM)
image_id = IDR_ZOOM_PLUS;
SetImage(OmniboxViewMac::ImageForResource(image_id));
NSString* tooltip_string,
bool location_bar_is_dark) {
if (ui::MaterialDesignController::IsModeMaterial()) {
ui_zoom::ZoomController::RelativeZoom relative_zoom =
zoom_controller->GetZoomRelativeToDefault();
// There is no ZOOM_NORMAL under Material Design.
gfx::VectorIconId iconId =
relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM
? gfx::VectorIconId::ZOOM_MINUS
: gfx::VectorIconId::ZOOM_PLUS;
SkColor vectorIconColor = location_bar_is_dark ? SK_ColorWHITE
: gfx::kChromeIconGrey;
NSImage* theImage =
NSImageFromImageSkia(gfx::CreateVectorIcon(iconId,
16,
vectorIconColor));
SetImage(theImage);
} else {
int image_id = IDR_ZOOM_NORMAL;
ui_zoom::ZoomController::RelativeZoom relative_zoom =
zoom_controller->GetZoomRelativeToDefault();
if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM)
image_id = IDR_ZOOM_MINUS;
else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM)
image_id = IDR_ZOOM_PLUS;
SetImage(OmniboxViewMac::ImageForResource(image_id));
}
tooltip_.reset([tooltip_string retain]);
......
......@@ -17,9 +17,12 @@ class MockZoomDecoration : public ZoomDecoration {
: ZoomDecoration(owner), update_ui_count_(0) {}
bool ShouldShowDecoration() const override { return true; }
void ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller,
NSString* tooltip_string) override {
NSString* tooltip_string,
bool location_bar_is_dark) override {
++update_ui_count_;
ZoomDecoration::ShowAndUpdateUI(zoom_controller, tooltip_string);
ZoomDecoration::ShowAndUpdateUI(zoom_controller,
tooltip_string,
location_bar_is_dark);
}
int update_ui_count_;
......@@ -47,18 +50,26 @@ TEST_F(ZoomDecorationTest, ChangeZoomPercent) {
MockZoomController controller(web_contents());
controller.zoom_percent_ = 100;
decoration.UpdateIfNecessary(&controller, /*default_zoom_changed=*/false);
decoration.UpdateIfNecessary(&controller,
/*default_zoom_changed=*/false,
false);
EXPECT_EQ(1, decoration.update_ui_count_);
decoration.UpdateIfNecessary(&controller, /*default_zoom_changed=*/false);
decoration.UpdateIfNecessary(&controller,
/*default_zoom_changed=*/false,
false);
EXPECT_EQ(1, decoration.update_ui_count_);
controller.zoom_percent_ = 80;
decoration.UpdateIfNecessary(&controller, /*default_zoom_changed=*/false);
decoration.UpdateIfNecessary(&controller,
/*default_zoom_changed=*/false,
false);
EXPECT_EQ(2, decoration.update_ui_count_);
// Always redraw if the default zoom changes.
decoration.UpdateIfNecessary(&controller, /*default_zoom_changed=*/true);
decoration.UpdateIfNecessary(&controller,
/*default_zoom_changed=*/true,
false);
EXPECT_EQ(3, decoration.update_ui_count_);
}
......
......@@ -30,6 +30,8 @@ class Clipboard;
class OmniboxViewMac : public OmniboxView,
public AutocompleteTextFieldObserver {
public:
static NSColor* BaseTextColor(bool inDarkMode);
OmniboxViewMac(OmniboxEditController* controller,
Profile* profile,
CommandUpdater* command_updater,
......
......@@ -31,11 +31,13 @@
#include "components/toolbar/toolbar_model.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/constants.h"
#import "skia/ext/skia_utils_mac.h"
#import "third_party/mozilla/NSPasteboard+Utils.h"
#include "ui/base/clipboard/clipboard.h"
#import "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
......@@ -88,30 +90,23 @@ NSColor* HostTextColor(bool inDarkMode) {
}
return inDarkMode ? [NSColor whiteColor] : [NSColor blackColor];
}
NSColor* BaseTextColor(bool inDarkMode) {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return [NSColor darkGrayColor];
}
return inDarkMode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5] :
[NSColor colorWithCalibratedWhite:0 alpha:0.5];
}
NSColor* SecureSchemeColor(bool inDarkMode) {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return ColorWithRGBBytes(0x07, 0x95, 0x00);
}
return inDarkMode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5] :
ColorWithRGBBytes(0x0B, 0x80, 0x43);
skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700);
}
NSColor* SecurityWarningSchemeColor(bool inDarkMode) {
return inDarkMode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5] :
ColorWithRGBBytes(0xF0, 0x93, 0x00);
skia::SkColorToCalibratedNSColor(gfx::kGoogleYellow700);
}
NSColor* SecurityErrorSchemeColor(bool inDarkMode) {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return ColorWithRGBBytes(0xa2, 0x00, 0x00);
}
return inDarkMode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5] :
ColorWithRGBBytes(0xC5, 0x39, 0x29);
skia::SkColorToCalibratedNSColor(gfx::kGoogleRed700);
}
const char kOmniboxViewMacStateKey[] = "OmniboxViewMacState";
......@@ -162,6 +157,15 @@ NSColor* OmniboxViewMac::SuggestTextColor() {
return [NSColor colorWithCalibratedWhite:0.0 alpha:0.5];
}
// static
NSColor* OmniboxViewMac::BaseTextColor(bool inDarkMode) {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return [NSColor darkGrayColor];
}
return inDarkMode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5]
: [NSColor colorWithCalibratedWhite:0 alpha:0.5];
}
OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller,
Profile* profile,
CommandUpdater* command_updater,
......
......@@ -111,6 +111,9 @@ class NotificationBridge;
// returns nil if we don't want to override the custom field editor for |obj|.
- (id)customFieldEditorForObject:(id)obj;
// Called by the |locationBar_| when it has been added to its window.
- (void)locationBarWasAddedToWindow;
// Make the location bar the first responder, if possible.
- (void)focusLocationBar:(BOOL)selectAll;
......
......@@ -609,6 +609,12 @@ class NotificationBridge : public AppMenuBadgeController::Delegate {
return locationBarView_.get();
}
- (void)locationBarWasAddedToWindow {
// Allow the |locationBarView_| to update itself to match the browser window
// theme.
locationBarView_->OnAddedToWindow();
}
- (void)focusLocationBar:(BOOL)selectAll {
if (locationBarView_.get()) {
locationBarView_->FocusLocation(selectAll ? true : false);
......
......@@ -226,7 +226,7 @@ int AutocompleteMatch::TypeToIcon(Type type) {
// static
gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) {
#if !defined(OS_ANDROID) && !defined(OS_MACOSX) && !defined(OS_IOS)
#if !defined(OS_ANDROID) && !defined(OS_IOS)
static const gfx::VectorIconId kIcons[] = {
gfx::VectorIconId::OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE
gfx::VectorIconId::OMNIBOX_HTTP, // HISTORY_URL
......
......@@ -87,7 +87,7 @@ int OmniboxView::GetIcon() const {
}
gfx::VectorIconId OmniboxView::GetVectorIcon(bool invert) const {
#if !defined(OS_ANDROID) && !defined(OS_MACOSX) && !defined(OS_IOS)
#if !defined(OS_ANDROID) && !defined(OS_IOS)
if (!IsEditingOrEmpty()) {
gfx::VectorIconId id = controller_->GetToolbarModel()->GetVectorIcon();
if (invert) {
......
......@@ -128,7 +128,7 @@ int ToolbarModelImpl::GetIcon() const {
}
gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const {
#if !defined(OS_ANDROID) && !defined(OS_MACOSX) && !defined(OS_IOS)
#if !defined(OS_ANDROID) && !defined(OS_IOS)
switch (GetSecurityLevel(false)) {
case SecurityStateModel::NONE:
return gfx::VectorIconId::LOCATION_BAR_HTTP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment