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

Side by Side Diff: ui/views/controls/focusable_border.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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/focusable_border.h ('k') | ui/views/controls/textfield/textfield.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "ui/views/controls/focusable_border.h" 5 #include "ui/views/controls/focusable_border.h"
6 6
7 #include "third_party/skia/include/core/SkPaint.h" 7 #include "third_party/skia/include/core/SkPaint.h"
8 #include "third_party/skia/include/core/SkPath.h" 8 #include "third_party/skia/include/core/SkPath.h"
9 #include "ui/base/material_design/material_design_controller.h" 9 #include "ui/base/material_design/material_design_controller.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/color_palette.h" 11 #include "ui/gfx/color_palette.h"
12 #include "ui/gfx/color_utils.h" 12 #include "ui/gfx/color_utils.h"
13 #include "ui/gfx/geometry/insets.h" 13 #include "ui/gfx/geometry/insets.h"
14 #include "ui/gfx/scoped_canvas.h" 14 #include "ui/gfx/scoped_canvas.h"
15 #include "ui/gfx/skia_util.h" 15 #include "ui/gfx/skia_util.h"
16 #include "ui/native_theme/native_theme.h" 16 #include "ui/native_theme/native_theme.h"
17 #include "ui/views/controls/textfield/textfield.h" 17 #include "ui/views/controls/textfield/textfield.h"
18 18
19 namespace { 19 namespace {
20 20
21 const int kInsetSize = 1; 21 const int kInsetSize = 1;
22 22
23 } // namespace 23 } // namespace
24 24
25 namespace views { 25 namespace views {
26 26
27 FocusableBorder::FocusableBorder() 27 FocusableBorder::FocusableBorder() : insets_(kInsetSize) {}
28 : insets_(kInsetSize, kInsetSize, kInsetSize, kInsetSize),
29 override_color_(gfx::kPlaceholderColor),
30 use_default_color_(true) {
31 }
32 28
33 FocusableBorder::~FocusableBorder() { 29 FocusableBorder::~FocusableBorder() {
34 } 30 }
35 31
36 void FocusableBorder::SetColor(SkColor color) { 32 void FocusableBorder::SetColorId(
37 override_color_ = color; 33 const base::Optional<ui::NativeTheme::ColorId>& color_id) {
38 use_default_color_ = false; 34 override_color_id_ = color_id;
39 }
40
41 void FocusableBorder::UseDefaultColor() {
42 use_default_color_ = true;
43 } 35 }
44 36
45 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { 37 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) {
46 // In harmony, the focus indicator is a FocusRing. 38 // In harmony, the focus indicator is a FocusRing.
47 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && view.HasFocus()) 39 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && view.HasFocus())
48 return; 40 return;
49 41
50 SkPaint paint; 42 SkPaint paint;
51 paint.setStyle(SkPaint::kStroke_Style); 43 paint.setStyle(SkPaint::kStroke_Style);
52 paint.setColor(GetCurrentColor(view)); 44 paint.setColor(GetCurrentColor(view));
(...skipping 27 matching lines...) Expand all
80 72
81 gfx::Size FocusableBorder::GetMinimumSize() const { 73 gfx::Size FocusableBorder::GetMinimumSize() const {
82 return gfx::Size(); 74 return gfx::Size();
83 } 75 }
84 76
85 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) { 77 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) {
86 insets_.Set(top, left, bottom, right); 78 insets_.Set(top, left, bottom, right);
87 } 79 }
88 80
89 SkColor FocusableBorder::GetCurrentColor(const View& view) const { 81 SkColor FocusableBorder::GetCurrentColor(const View& view) const {
90 if (!use_default_color_) 82 ui::NativeTheme::ColorId color_id =
91 return override_color_; 83 ui::NativeTheme::kColorId_UnfocusedBorderColor;
84 if (override_color_id_)
85 color_id = *override_color_id_;
86 else if (view.HasFocus())
87 color_id = ui::NativeTheme::kColorId_FocusedBorderColor;
92 88
93 SkColor color = view.GetNativeTheme()->GetSystemColor( 89 SkColor color = view.GetNativeTheme()->GetSystemColor(color_id);
94 view.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor :
95 ui::NativeTheme::kColorId_UnfocusedBorderColor);
96 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && 90 if (ui::MaterialDesignController::IsSecondaryUiMaterial() &&
97 !view.enabled()) { 91 !view.enabled()) {
98 return color_utils::BlendTowardOppositeLuma(color, 92 return color_utils::BlendTowardOppositeLuma(color,
99 gfx::kDisabledControlAlpha); 93 gfx::kDisabledControlAlpha);
100 } 94 }
101
102 return color; 95 return color;
103 } 96 }
104 97
105 } // namespace views 98 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/focusable_border.h ('k') | ui/views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698