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

Unified Diff: ui/views/controls/focus_ring.cc

Issue 2406363003: Update appearance of invalid textfields in Harmony. (Closed)
Patch Set: combine install with setcolorid Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/focus_ring.h ('k') | ui/views/controls/focusable_border.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/focus_ring.cc
diff --git a/ui/views/controls/focus_ring.cc b/ui/views/controls/focus_ring.cc
index 8e1702b37884dbb2114351b7c52591ba9da9fde7..af52a5090debfa36e7a587eff803153c3d3b8197 100644
--- a/ui/views/controls/focus_ring.cc
+++ b/ui/views/controls/focus_ring.cc
@@ -21,27 +21,35 @@ constexpr float kFocusHaloThicknessDp = 2.f;
constexpr float kFocusHaloCornerRadiusDp =
FocusableBorder::kCornerRadiusDp + kFocusHaloThicknessDp / 2.f;
+FocusRing* GetFocusRing(views::View* parent) {
+ for (int i = 0; i < parent->child_count(); ++i) {
+ if (parent->child_at(i)->GetClassName() == FocusRing::kViewClassName)
+ return static_cast<FocusRing*>(parent->child_at(i));
+ }
+ return nullptr;
+}
+
} // namespace
const char FocusRing::kViewClassName[] = "FocusRing";
// static
-void FocusRing::Install(views::View* parent) {
+void FocusRing::Install(views::View* parent,
+ ui::NativeTheme::ColorId override_color_id) {
DCHECK(parent->HasFocus());
- View* ring = new FocusRing();
- parent->AddChildView(ring);
+ FocusRing* ring = GetFocusRing(parent);
+ if (!ring) {
+ ring = new FocusRing();
+ parent->AddChildView(ring);
+ }
+ ring->override_color_id_ = override_color_id;
ring->Layout();
+ ring->SchedulePaint();
}
// static
void FocusRing::Uninstall(views::View* parent) {
- for (int i = 0; i < parent->child_count(); ++i) {
- if (parent->child_at(i)->GetClassName() == kViewClassName) {
- delete parent->child_at(i);
- return;
- }
- }
- NOTREACHED();
+ delete GetFocusRing(parent);
}
const char* FocusRing::GetClassName() const {
@@ -63,9 +71,12 @@ void FocusRing::Layout() {
void FocusRing::OnPaint(gfx::Canvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
- paint.setColor(SkColorSetA(GetNativeTheme()->GetSystemColor(
- ui::NativeTheme::kColorId_FocusedBorderColor),
- 0x66));
+ paint.setColor(
+ SkColorSetA(GetNativeTheme()->GetSystemColor(
+ override_color_id_ != ui::NativeTheme::kColorId_NumColors
+ ? override_color_id_
+ : ui::NativeTheme::kColorId_FocusedBorderColor),
+ 0x66));
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(kFocusHaloThicknessDp);
gfx::RectF rect(GetLocalBounds());
@@ -73,7 +84,8 @@ void FocusRing::OnPaint(gfx::Canvas* canvas) {
canvas->DrawRoundRect(rect, kFocusHaloCornerRadiusDp, paint);
}
-FocusRing::FocusRing() {
+FocusRing::FocusRing()
+ : override_color_id_(ui::NativeTheme::kColorId_NumColors) {
// A layer is necessary to paint beyond the parent's bounds.
SetPaintToLayer(true);
layer()->SetFillsBoundsOpaquely(false);
« no previous file with comments | « ui/views/controls/focus_ring.h ('k') | ui/views/controls/focusable_border.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698