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

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

Issue 2345183002: Views: Draw Textfield selected text in gray when top-level Widget loses focus.
Patch Set: Refactor to use SelectionController(Delegate). Unfinished! Created 4 years, 1 month 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/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 4b0bef22f724ba3c3d7bd4defe8aab6874b4560c..ed8fd2b971da8e5f7aa7e12ac44171ca20ffc804 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -384,13 +384,6 @@ void Textfield::UseDefaultBackgroundColor() {
UpdateBackgroundColor();
}
-SkColor Textfield::GetSelectionTextColor() const {
- return use_default_selection_text_color_ ?
- GetNativeTheme()->GetSystemColor(
- ui::NativeTheme::kColorId_TextfieldSelectionColor) :
- selection_text_color_;
-}
-
void Textfield::SetSelectionTextColor(SkColor color) {
selection_text_color_ = color;
use_default_selection_text_color_ = false;
@@ -409,24 +402,17 @@ void Textfield::SetShadows(const gfx::ShadowValues& shadows) {
SchedulePaint();
}
-SkColor Textfield::GetSelectionBackgroundColor() const {
- return use_default_selection_background_color_ ?
- GetNativeTheme()->GetSystemColor(
- ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) :
- selection_background_color_;
-}
-
void Textfield::SetSelectionBackgroundColor(SkColor color) {
selection_background_color_ = color;
use_default_selection_background_color_ = false;
- GetRenderText()->set_selection_background_focused_color(
+ GetRenderText()->set_selection_background_color(
GetSelectionBackgroundColor());
SchedulePaint();
}
void Textfield::UseDefaultSelectionBackgroundColor() {
use_default_selection_background_color_ = true;
- GetRenderText()->set_selection_background_focused_color(
+ GetRenderText()->set_selection_background_color(
GetSelectionBackgroundColor());
SchedulePaint();
}
@@ -936,6 +922,17 @@ void Textfield::OnEnabledChanged() {
SchedulePaint();
}
+void Textfield::ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) {
+ // Update the focus manager being listened to.
+ if (details.parent->Contains(this) && details.move_view == nullptr)
+ ObserveWidgetFocusChanges(GetFocusManager(), details.is_add);
+}
+
+void Textfield::NativeViewHierarchyChanged() {
+ ObserveWidgetFocusChanges(GetFocusManager(), true);
+}
+
void Textfield::OnPaint(gfx::Canvas* canvas) {
OnPaintBackground(canvas);
PaintTextAndCursor(canvas);
@@ -988,9 +985,9 @@ void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) {
render_text->SetColor(GetTextColor());
UpdateBackgroundColor();
render_text->set_cursor_color(GetTextColor());
- render_text->set_selection_color(GetSelectionTextColor());
- render_text->set_selection_background_focused_color(
- GetSelectionBackgroundColor());
+ // TODO(patricialor): Does this actually work?
+ UpdateTextSelectionDrawState(this, GetFocusManager()->GetStoredFocusView(),
+ GetFocusManager()->GetFocusedView());
}
////////////////////////////////////////////////////////////////////////////////
@@ -1083,6 +1080,26 @@ bool Textfield::HasTextBeingDragged() const {
return initiating_drag_;
}
+SkColor Textfield::GetSelectionTextColor() const {
+ return use_default_selection_text_color_
+ ? GetNativeTheme()->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldSelectionColor)
+ : selection_text_color_;
+}
+
+SkColor Textfield::GetSelectionBackgroundColor() const {
+ return use_default_selection_background_color_
+ ? GetNativeTheme()->GetSystemColor(
+ ui::NativeTheme::
+ kColorId_TextfieldSelectionBackgroundFocused)
+ : selection_background_color_;
+}
+
+SkColor Textfield::GetSelectionBackgroundUnfocusedColor() const {
+ // TODO(patricialor): Put a proper colour here.
+ return SK_ColorBLUE;
+}
+
////////////////////////////////////////////////////////////////////////////////
// Textfield, ui::TouchEditable overrides:
@@ -1837,6 +1854,11 @@ void Textfield::UpdateSelectionClipboard() {
#endif
}
+void Textfield::OnWillChangeFocus(View* focused_before, View* focused_now) {
+ UpdateTextSelectionDrawState(this, focused_before, focused_now);
+ SchedulePaint();
+}
+
void Textfield::UpdateBackgroundColor() {
const SkColor color = GetBackgroundColor();
if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698