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

Unified Diff: ui/views/controls/button/label_button_label.cc

Issue 2913933002: Move views::Label DisabledColor logic into views::LabelButtonLabel (Closed)
Patch Set: missed-some Created 3 years, 6 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
Index: ui/views/controls/button/label_button_label.cc
diff --git a/ui/views/controls/button/label_button_label.cc b/ui/views/controls/button/label_button_label.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fb0e182a58fdd5dc64f1ec0e3c67ca47b31b88f5
--- /dev/null
+++ b/ui/views/controls/button/label_button_label.cc
@@ -0,0 +1,59 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/controls/button/label_button_label.h"
+
+namespace views {
+
+LabelButtonLabel::LabelButtonLabel(const base::string16& text, int text_context)
+ : Label(text, text_context, style::STYLE_PRIMARY) {
+ SetDisabledColorInternal(
+ style::GetColor(text_context, style::STYLE_DISABLED, GetNativeTheme()),
+ true);
+}
+
+LabelButtonLabel::~LabelButtonLabel() {}
+
+void LabelButtonLabel::SetDisabledColor(SkColor color) {
+ SetDisabledColorInternal(color, false);
+}
+
+void LabelButtonLabel::OnEnabledChanged() {
+ ApplyTextColors();
+ Label::OnEnabledChanged();
+}
+
+void LabelButtonLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) {
+ SetDisabledColorInternal(
+ style::GetColor(text_context(), style::STYLE_DISABLED, GetNativeTheme()),
+ true);
+ Label::OnNativeThemeChanged(theme);
+}
+
+SkColor LabelButtonLabel::GetForegroundColor() const {
+ return enabled() ? enabled_color() : actual_disabled_color_;
+}
+
+void LabelButtonLabel::OnBackgroundColorChanged() {
+ actual_disabled_color_ = EnsureTextColorReadable(requested_disabled_color_);
+}
+
+void LabelButtonLabel::SetDisabledColorInternal(SkColor color,
+ bool from_theme) {
+ if (from_theme && disabled_color_set_)
+ return;
+
+ disabled_color_set_ = !from_theme;
+ if (color == requested_disabled_color_)
+ return;
+
+ requested_disabled_color_ = color;
+ actual_disabled_color_ = EnsureTextColorReadable(requested_disabled_color_);
+ if (!enabled()) {
+ ApplyTextColors();
+ SchedulePaint();
+ }
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698