Skip to content

Commit

Permalink
[MD] Implement incognito colors as a NativeTheme
Browse files Browse the repository at this point in the history
For ChromeOS (and at least for now, Linux), this is NativeThemeAuraDark. For Windows, this is NativeThemeWinDark, which paints controls like NativeThemeWin but uses NativeThemeAuraDark for colors.

This CL focuses on the location bar and omnibox. It adds a number of colors (most of those which have already been spec'd) but is missing lots more colors.

BUG=501377

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

Cr-Commit-Position: refs/heads/master@{#359956}
  • Loading branch information
estade authored and Commit bot committed Nov 17, 2015
1 parent e22c2fb commit 5634546
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ui/aura/window.h"
#include "ui/base/ime/input_method_initializer.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/native_theme/native_theme_dark_aura.h"
#include "ui/views/linux_ui/linux_ui.h"
#endif

Expand Down Expand Up @@ -56,8 +57,10 @@ ui::NativeTheme* GetNativeThemeForWindow(aura::Window* window) {
window->GetNativeWindowProperty(Profile::kProfileKey));
}

if (profile && !profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme))
return ui::NativeThemeAura::instance();
if (profile && !profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) {
return profile->IsOffTheRecord() ? ui::NativeThemeDarkAura::instance()
: ui::NativeThemeAura::instance();
}

return nullptr;
}
Expand Down
14 changes: 14 additions & 0 deletions chrome/browser/ui/views/frame/browser_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@
#if defined(OS_CHROMEOS)
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ui/native_theme/native_theme_dark_aura.h"
#endif

#if defined(OS_LINUX)
#include "chrome/browser/ui/views/frame/browser_command_handler_linux.h"
#endif

#if defined(OS_WIN)
#include "ui/native_theme/native_theme_dark_win.h"
#endif

////////////////////////////////////////////////////////////////////////////////
// BrowserFrame, public:

Expand Down Expand Up @@ -75,6 +80,15 @@ void BrowserFrame::InitBrowserFrame() {
&params.bounds,
&params.show_state);
}

if (browser_view_->browser()->profile()->IsOffTheRecord()) {
#if defined(OS_WIN)
params.native_theme = ui::NativeThemeDarkWin::instance();
#elif defined(OS_CHROMEOS)
params.native_theme = ui::NativeThemeDarkAura::instance();
#endif
}

Init(params);

if (!native_browser_frame_->UsesNativeSystemMenu()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ void IconLabelBubbleView::OnNativeThemeChanged(
return;

label_->SetEnabledColor(GetTextColor());
SkColor border_color = GetBorderColor();
SkColor background_color = SkColorSetA(border_color, 0x13);

bool inverted =
color_utils::GetLuminanceForColor(parent_background_color_) < 128;
SkColor border_color = inverted ? SK_ColorWHITE : GetBorderColor();
SkColor background_color =
inverted ? SK_ColorWHITE : SkColorSetA(border_color, 0x13);
set_background(
new BackgroundWith1PxBorder(background_color, border_color, false));
SetLabelBackgroundColor(background_color);
Expand Down
107 changes: 56 additions & 51 deletions chrome/browser/ui/views/location_bar/location_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ LocationBarView::LocationBarView(Browser* browser,

ui_zoom::ZoomEventManager::GetForBrowserContext(profile)
->AddZoomEventManagerObserver(this);

if (ui::MaterialDesignController::IsModeMaterial()) {
set_background(new BackgroundWith1PxBorder(
GetColor(SecurityStateModel::NONE, BACKGROUND),
SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), is_popup_mode_));
}
}

LocationBarView::~LocationBarView() {
Expand Down Expand Up @@ -222,10 +216,8 @@ void LocationBarView::Init() {
gfx::FontList bubble_font_list =
font_list.DeriveWithHeightUpperBound(bubble_height);

const SkColor background_color =
GetColor(SecurityStateModel::NONE, LocationBarView::BACKGROUND);
const SkColor ev_text_color =
GetColor(SecurityStateModel::EV_SECURE, SECURITY_TEXT);
const SkColor background_color = GetColor(LocationBarView::BACKGROUND);
const SkColor ev_text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER);
ev_bubble_view_ =
new EVBubbleView(bubble_font_list, ev_text_color, background_color, this);
ev_bubble_view_->set_drag_controller(this);
Expand All @@ -252,7 +244,7 @@ void LocationBarView::Init() {
ime_inline_autocomplete_view_->SetVisible(false);
AddChildView(ime_inline_autocomplete_view_);

const SkColor selected_text_color = GetColor(SecurityStateModel::NONE, TEXT);
const SkColor selected_text_color = GetColor(TEXT);
selected_keyword_view_ = new SelectedKeywordView(
bubble_font_list, selected_text_color, background_color, profile());
AddChildView(selected_keyword_view_);
Expand All @@ -261,18 +253,17 @@ void LocationBarView::Init() {
suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
suggested_text_view_->SetAutoColorReadabilityEnabled(false);
suggested_text_view_->SetEnabledColor(
GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT));
GetColor(LocationBarView::DEEMPHASIZED_TEXT));
suggested_text_view_->SetVisible(false);
AddChildView(suggested_text_view_);

keyword_hint_view_ = new KeywordHintView(
profile(), font_list, bubble_font_list,
bubble_height + 2 * kBubbleInteriorVerticalPadding,
GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT),
background_color);
GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color);
AddChildView(keyword_hint_view_);

const SkColor text_color = GetColor(SecurityStateModel::NONE, TEXT);
const SkColor text_color = GetColor(TEXT);
ScopedVector<ContentSettingImageModel> models =
ContentSettingImageModel::GenerateContentSettingImageModels();
for (ContentSettingImageModel* model : models.get()) {
Expand Down Expand Up @@ -319,7 +310,6 @@ bool LocationBarView::IsInitialized() const {
}

SkColor LocationBarView::GetColor(
SecurityStateModel::SecurityLevel security_level,
ColorKind kind) const {
const ui::NativeTheme* native_theme = GetNativeTheme();
switch (kind) {
Expand All @@ -336,45 +326,51 @@ SkColor LocationBarView::GetColor(
ui::NativeTheme::kColorId_TextfieldSelectionColor);

case DEEMPHASIZED_TEXT:
return color_utils::AlphaBlend(
GetColor(security_level, TEXT),
GetColor(security_level, BACKGROUND),
128);

case SECURITY_TEXT: {
SkColor color;
switch (security_level) {
case SecurityStateModel::EV_SECURE:
case SecurityStateModel::SECURE:
color = ui::MaterialDesignController::IsModeMaterial() ?
gfx::kGoogleGreen700 : SkColorSetRGB(7, 149, 0);
break;

case SecurityStateModel::SECURITY_POLICY_WARNING:
return GetColor(security_level, DEEMPHASIZED_TEXT);
break;

case SecurityStateModel::SECURITY_ERROR:
color = ui::MaterialDesignController::IsModeMaterial() ?
gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0);
break;

case SecurityStateModel::SECURITY_WARNING:
return GetColor(security_level, TEXT);
break;

default:
NOTREACHED();
return GetColor(security_level, TEXT);
}
return color_utils::GetReadableColor(
color, GetColor(security_level, BACKGROUND));
return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128);

case EV_BUBBLE_TEXT_AND_BORDER:
return ui::MaterialDesignController::IsModeMaterial()
? gfx::kGoogleGreen700
: SkColorSetRGB(7, 149, 0);
}
NOTREACHED();
return gfx::kPlaceholderColor;
}

SkColor LocationBarView::GetSecureTextColor(
SecurityStateModel::SecurityLevel security_level) const {
bool inverted =
color_utils::GetLuminanceForColor(GetColor(BACKGROUND)) < 128;
SkColor color;
switch (security_level) {
case SecurityStateModel::EV_SECURE:
case SecurityStateModel::SECURE:
if (ui::MaterialDesignController::IsModeMaterial() && inverted)
return GetColor(TEXT);
color = GetColor(EV_BUBBLE_TEXT_AND_BORDER);
break;

case SecurityStateModel::SECURITY_POLICY_WARNING:
return GetColor(DEEMPHASIZED_TEXT);
break;

case SecurityStateModel::SECURITY_ERROR: {
bool md = ui::MaterialDesignController::IsModeMaterial();
if (md && inverted)
return GetColor(TEXT);
color = md ? gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0);
break;
}

case SecurityStateModel::SECURITY_WARNING:
return GetColor(TEXT);
break;

default:
NOTREACHED();
return GetColor(security_level, TEXT);
return gfx::kPlaceholderColor;
}
return color_utils::GetReadableColor(color, GetColor(BACKGROUND));
}

void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
Expand Down Expand Up @@ -792,6 +788,15 @@ void LocationBarView::Layout() {
omnibox_view_->SetBoundsRect(location_bounds);
}

void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
if (!ui::MaterialDesignController::IsModeMaterial())
return;

set_background(new BackgroundWith1PxBorder(
GetColor(BACKGROUND), SkColorSetARGB(0x4D, 0x00, 0x00, 0x00),
is_popup_mode_));
}

void LocationBarView::Update(const WebContents* contents) {
RefreshContentSettingViews();
RefreshZoomView();
Expand Down Expand Up @@ -1261,7 +1266,7 @@ void LocationBarView::OnPaint(gfx::Canvas* canvas) {
// the omnibox background, so we can't just blindly fill our entire bounds.
gfx::Rect bounds(GetContentsBounds());
bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness());
SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND));
SkColor color(GetColor(BACKGROUND));
if (is_popup_mode_) {
canvas->FillRect(bounds, color);
} else {
Expand Down
11 changes: 8 additions & 3 deletions chrome/browser/ui/views/location_bar/location_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class LocationBarView : public LocationBar,
TEXT,
SELECTED_TEXT,
DEEMPHASIZED_TEXT,
SECURITY_TEXT,
EV_BUBBLE_TEXT_AND_BORDER,
};

LocationBarView(Browser* browser,
Expand All @@ -138,8 +138,12 @@ class LocationBarView : public LocationBar,

// Returns the appropriate color for the desired kind, based on the user's
// system theme.
SkColor GetColor(SecurityStateModel::SecurityLevel security_level,
ColorKind kind) const;
SkColor GetColor(ColorKind kind) const;

// Returns the color to be used for security text in the context of
// |security_level|.
SkColor GetSecureTextColor(
SecurityStateModel::SecurityLevel security_level) const;

// Returns the delegate.
Delegate* delegate() const { return delegate_; }
Expand Down Expand Up @@ -247,6 +251,7 @@ class LocationBarView : public LocationBar,
void GetAccessibleState(ui::AXViewState* state) override;
gfx::Size GetPreferredSize() const override;
void Layout() override;
void OnNativeThemeChanged(const ui::NativeTheme* theme) override;

// ChromeOmniboxEditController:
void UpdateWithoutTabRestore() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() {
params.parent = popup_parent->GetNativeView();
params.bounds = GetPopupBounds();
params.context = popup_parent->GetNativeWindow();
params.native_theme = popup_parent->GetNativeTheme();
popup_->Init(params);
// Third-party software such as DigitalPersona identity verification can
// hook the underlying window creation methods and use SendMessage to
Expand Down
14 changes: 6 additions & 8 deletions chrome/browser/ui/views/omnibox/omnibox_view_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ gfx::Size OmniboxViewViews::GetMinimumSize() const {
void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) {
views::Textfield::OnNativeThemeChanged(theme);
if (location_bar_view_) {
SetBackgroundColor(location_bar_view_->GetColor(
SecurityStateModel::NONE, LocationBarView::BACKGROUND));
SetBackgroundColor(
location_bar_view_->GetColor(LocationBarView::BACKGROUND));
}
EmphasizeURLComponents();
}
Expand Down Expand Up @@ -633,12 +633,10 @@ void OmniboxViewViews::EmphasizeURLComponents() {
base::UTF8ToUTF16(extensions::kExtensionScheme);
bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url);
SetColor(location_bar_view_->GetColor(
security_level_,
grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
if (grey_base && !grey_out_url) {
ApplyColor(
location_bar_view_->GetColor(security_level_, LocationBarView::TEXT),
gfx::Range(host.begin, host.end()));
ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT),
gfx::Range(host.begin, host.end()));
}

// Emphasize the scheme for security UI display purposes (if necessary).
Expand All @@ -649,8 +647,8 @@ void OmniboxViewViews::EmphasizeURLComponents() {
SetStyle(gfx::DIAGONAL_STRIKE, false);
if (!model()->user_input_in_progress() && text_is_url &&
scheme.is_nonempty() && (security_level_ != SecurityStateModel::NONE)) {
SkColor security_color = location_bar_view_->GetColor(
security_level_, LocationBarView::SECURITY_TEXT);
SkColor security_color =
location_bar_view_->GetSecureTextColor(security_level_);
const bool strike = (security_level_ == SecurityStateModel::SECURITY_ERROR);
const gfx::Range scheme_range(scheme.begin, scheme.end());
ApplyColor(security_color, scheme_range);
Expand Down
8 changes: 8 additions & 0 deletions ui/gfx/color_palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@

namespace gfx {

// A placeholder value for unset colors. This should never be visible and is red
// as a visual flag for misbehaving code.
const SkColor kPlaceholderColor = SK_ColorRED;

const SkColor kChromeIconGrey = SkColorSetRGB(0x5A, 0x5A, 0x5A);

// The number refers to the shade of darkness. Each color in the MD
// palette ranges from 100-900.
const SkColor kGoogleBlue300 = SkColorSetRGB(0x7B, 0xAA, 0xF7);
const SkColor kGoogleBlue500 = SkColorSetRGB(0x42, 0x85, 0xF4);
const SkColor kGoogleBlue700 = SkColorSetRGB(0x33, 0x67, 0xD6);
const SkColor kGoogleRed300 = SkColorSetRGB(0xE6, 0x7C, 0x73);
const SkColor kGoogleRed700 = SkColorSetRGB(0xC5, 0x39, 0x29);
const SkColor kGoogleGreen300 = SkColorSetRGB(0x57, 0xBB, 0x8A);
const SkColor kGoogleGreen700 = SkColorSetRGB(0x0B, 0x80, 0x43);
const SkColor kGoogleYellow300 = SkColorSetRGB(0xF7, 0xCB, 0x4D);
const SkColor kGoogleYellow700 = SkColorSetRGB(0xF0, 0x93, 0x00);

} // namespace gfx
Expand Down
4 changes: 4 additions & 0 deletions ui/native_theme/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ component("native_theme") {
"native_theme_android.h",
"native_theme_base.cc",
"native_theme_base.h",
"native_theme_dark_win.cc",
"native_theme_dark_win.h",
"native_theme_mac.h",
"native_theme_mac.mm",
"native_theme_observer.cc",
Expand All @@ -28,6 +30,8 @@ component("native_theme") {
sources += [
"native_theme_aura.cc",
"native_theme_aura.h",
"native_theme_dark_aura.cc",
"native_theme_dark_aura.h",
]

if (is_win) {
Expand Down
2 changes: 1 addition & 1 deletion ui/native_theme/common_theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool CommonThemeGetSystemColor(NativeTheme::ColorId color_id, SkColor* color) {
const SkColor kSelectedMenuItemForegroundColorMd = SK_ColorBLACK;
// Link:
const SkColor kLinkDisabledColorMd = SK_ColorBLACK;
const SkColor kLinkEnabledColorMd = SkColorSetRGB(0x33, 0x67, 0xD6);
const SkColor kLinkEnabledColorMd = gfx::kGoogleBlue700;

switch (color_id) {
// MenuItem
Expand Down
4 changes: 4 additions & 0 deletions ui/native_theme/native_theme.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
'native_theme_aurawin.h',
'native_theme_base.cc',
'native_theme_base.h',
'native_theme_dark_aura.cc',
'native_theme_dark_aura.h',
'native_theme_dark_win.cc',
'native_theme_dark_win.h',
'native_theme_mac.h',
'native_theme_mac.mm',
'native_theme_observer.cc',
Expand Down
Loading

0 comments on commit 5634546

Please sign in to comment.