Commit 1af8d3ff authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

macviews: use mac-y focus rings

This change:
1) Uses the system focus ring color even when SecondaryUiMd is enabled
2) Moves focus ring thickness and inset out to PlatformStyle
3) Adds Mac overrides of the default values

Bug: 832306
Change-Id: I6c18d9d0431dc411a5cb95f9c0639e41f4aa1127
Reviewed-on: https://chromium-review.googlesource.com/1012163
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551030}
parent 6e8dbd1d
...@@ -160,6 +160,12 @@ SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const { ...@@ -160,6 +160,12 @@ SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const {
case kColorId_LabelTextSelectionBackgroundFocused: case kColorId_LabelTextSelectionBackgroundFocused:
case kColorId_TextfieldSelectionBackgroundFocused: case kColorId_TextfieldSelectionBackgroundFocused:
return NSSystemColorToSkColor([NSColor selectedTextBackgroundColor]); return NSSystemColorToSkColor([NSColor selectedTextBackgroundColor]);
case kColorId_FocusedBorderColor:
return NSSystemColorToSkColor([NSColor keyboardFocusIndicatorColor]);
case kColorId_UnfocusedBorderColor:
return NSSystemColorToSkColor([NSColor controlColor]);
default: default:
break; break;
} }
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
#include "ui/views/controls/focus_ring.h" #include "ui/views/controls/focus_ring.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/views/controls/focusable_border.h"
#include "ui/views/style/platform_style.h"
namespace views { namespace views {
namespace { namespace {
// The default stroke width of the focus border in dp.
constexpr float kFocusHaloThicknessDp = 2.f;
FocusRing* GetFocusRing(View* parent) { FocusRing* GetFocusRing(View* parent) {
for (int i = 0; i < parent->child_count(); ++i) { for (int i = 0; i < parent->child_count(); ++i) {
if (parent->child_at(i)->GetClassName() == FocusRing::kViewClassName) if (parent->child_at(i)->GetClassName() == FocusRing::kViewClassName)
...@@ -76,7 +75,7 @@ void FocusRing::Layout() { ...@@ -76,7 +75,7 @@ void FocusRing::Layout() {
// The focus ring handles its own sizing, which is simply to fill the parent // The focus ring handles its own sizing, which is simply to fill the parent
// and extend a little beyond its borders. // and extend a little beyond its borders.
gfx::Rect focus_bounds = parent()->GetLocalBounds(); gfx::Rect focus_bounds = parent()->GetLocalBounds();
focus_bounds.Inset(gfx::Insets(-kFocusHaloThicknessDp)); focus_bounds.Inset(gfx::Insets(PlatformStyle::kFocusHaloInset));
SetBoundsRect(focus_bounds); SetBoundsRect(focus_bounds);
} }
...@@ -85,14 +84,14 @@ void FocusRing::OnPaint(gfx::Canvas* canvas) { ...@@ -85,14 +84,14 @@ void FocusRing::OnPaint(gfx::Canvas* canvas) {
flags.setAntiAlias(true); flags.setAntiAlias(true);
flags.setColor(SkColorSetA(color_, 0x66)); flags.setColor(SkColorSetA(color_, 0x66));
flags.setStyle(cc::PaintFlags::kStroke_Style); flags.setStyle(cc::PaintFlags::kStroke_Style);
flags.setStrokeWidth(kFocusHaloThicknessDp); flags.setStrokeWidth(PlatformStyle::kFocusHaloThickness);
gfx::RectF rect(GetLocalBounds()); gfx::RectF rect(GetLocalBounds());
rect.Inset(gfx::InsetsF(kFocusHaloThicknessDp / 2.f)); rect.Inset(gfx::InsetsF(PlatformStyle::kFocusHaloThickness / 2.f));
// The focus indicator should hug the normal border, when present (as in the // The focus indicator should hug the normal border, when present (as in the
// case of text buttons). Since it's drawn outside the parent view, increase // case of text buttons). Since it's drawn outside the parent view, increase
// the rounding slightly by adding half the ring thickness. // the rounding slightly by adding half the ring thickness.
canvas->DrawRoundRect(rect, corner_radius_ + kFocusHaloThicknessDp / 2.f, canvas->DrawRoundRect(
flags); rect, corner_radius_ + PlatformStyle::kFocusHaloThickness / 2.f, flags);
} }
void FocusRing::OnViewNativeThemeChanged(View* observed_view) { void FocusRing::OnViewNativeThemeChanged(View* observed_view) {
......
...@@ -57,6 +57,9 @@ const bool PlatformStyle::kUseRipples = true; ...@@ -57,6 +57,9 @@ const bool PlatformStyle::kUseRipples = true;
const bool PlatformStyle::kTextfieldScrollsToStartOnFocusChange = false; const bool PlatformStyle::kTextfieldScrollsToStartOnFocusChange = false;
const bool PlatformStyle::kTextfieldUsesDragCursorWhenDraggable = true; const bool PlatformStyle::kTextfieldUsesDragCursorWhenDraggable = true;
const bool PlatformStyle::kShouldElideBookmarksInBookmarksBar = false; const bool PlatformStyle::kShouldElideBookmarksInBookmarksBar = false;
const float PlatformStyle::kFocusHaloThickness = 2.f;
const float PlatformStyle::kFocusHaloInset =
-PlatformStyle::kFocusHaloThickness;
// static // static
std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) { std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) {
......
...@@ -74,6 +74,10 @@ class VIEWS_EXPORT PlatformStyle { ...@@ -74,6 +74,10 @@ class VIEWS_EXPORT PlatformStyle {
// tail] or fade out. // tail] or fade out.
static const bool kShouldElideBookmarksInBookmarksBar; static const bool kShouldElideBookmarksInBookmarksBar;
// The thickness and inset amount of focus ring halos.
static const float kFocusHaloThickness;
static const float kFocusHaloInset;
// Creates the default scrollbar for the given orientation. // Creates the default scrollbar for the given orientation.
static std::unique_ptr<ScrollBar> CreateScrollBar(bool is_horizontal); static std::unique_ptr<ScrollBar> CreateScrollBar(bool is_horizontal);
......
...@@ -42,6 +42,8 @@ const bool PlatformStyle::kTextfieldUsesDragCursorWhenDraggable = false; ...@@ -42,6 +42,8 @@ const bool PlatformStyle::kTextfieldUsesDragCursorWhenDraggable = false;
const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = true; const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = true;
const bool PlatformStyle::kShouldElideBookmarksInBookmarksBar = true; const bool PlatformStyle::kShouldElideBookmarksInBookmarksBar = true;
const bool PlatformStyle::kUseRipples = false; const bool PlatformStyle::kUseRipples = false;
const float PlatformStyle::kFocusHaloThickness = 4.f;
const float PlatformStyle::kFocusHaloInset = -2.f;
const Button::NotifyAction PlatformStyle::kMenuNotifyActivationAction = const Button::NotifyAction PlatformStyle::kMenuNotifyActivationAction =
Button::NOTIFY_ON_PRESS; Button::NOTIFY_ON_PRESS;
......
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