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

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

Issue 2345183002: Views: Draw Textfield selected text in gray when top-level Widget loses focus.
Patch Set: Fix lifetime issues with BorderView's widget_ and address review comments. 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
Index: ui/views/controls/textfield/textfield.h
diff --git a/ui/views/controls/textfield/textfield.h b/ui/views/controls/textfield/textfield.h
index 0d77946328f05a0b58694fd2c288787389ca8b69..c5ef6bb71bab69d15ada0626b6b516aa5fe21dd5 100644
--- a/ui/views/controls/textfield/textfield.h
+++ b/ui/views/controls/textfield/textfield.h
@@ -29,6 +29,7 @@
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/textfield/textfield_model.h"
#include "ui/views/drag_controller.h"
+#include "ui/views/focus/focus_manager.h"
#include "ui/views/selection_controller.h"
#include "ui/views/selection_controller_delegate.h"
#include "ui/views/view.h"
@@ -45,6 +46,7 @@ class VIEWS_EXPORT Textfield : public View,
public TextfieldModel::Delegate,
public ContextMenuController,
public DragController,
+ public FocusChangeListener,
msw 2016/11/09 02:14:54 Would it make sense (and/or be easier to manage) t
Patti Lor 2016/11/10 07:29:09 Ah, I hadn't considered using OnWidgetActivationCh
public WordLookupClient,
public SelectionControllerDelegate,
public ui::TouchEditable,
@@ -140,6 +142,10 @@ class VIEWS_EXPORT Textfield : public View,
void SetSelectionBackgroundColor(SkColor color);
void UseDefaultSelectionBackgroundColor();
+ // Gets the selection background color for use when the Textfield was the last
+ // to be focused in a widget.
+ SkColor GetUnfocusedSelectionBackgroundColor() const;
+
// Set drop shadows underneath the text.
void SetShadows(const gfx::ShadowValues& shadows);
@@ -244,6 +250,9 @@ class VIEWS_EXPORT Textfield : public View,
bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
void OnVisibleBoundsChanged() override;
void OnEnabledChanged() override;
+ void ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) override;
+ void NativeViewHierarchyChanged() override;
void OnPaint(gfx::Canvas* canvas) override;
void OnFocus() override;
void OnBlur() override;
@@ -267,6 +276,10 @@ class VIEWS_EXPORT Textfield : public View,
const gfx::Point& press_pt,
const gfx::Point& p) override;
+ // FocusChangeListener overrides:
+ void OnWillChangeFocus(View* focused_before, View* focused_now) override;
+ void OnDidChangeFocus(View* focused_before, View* focused_now) override;
+
// WordLookupClient overrides:
bool GetDecoratedWordAtPoint(const gfx::Point& point,
gfx::DecoratedText* decorated_word,
@@ -364,6 +377,11 @@ class VIEWS_EXPORT Textfield : public View,
bool PasteSelectionClipboard() override;
void UpdateSelectionClipboard() override;
+ // Adds this Textfield as a FocusChangeListener based on |add_as_listener|.
+ // Always removes this Textfield as a listener of the previously listened-to
+ // focus manager (if it exists) before this happens.
+ void ObserveWidgetFocusChanges(bool add_as_listener);
+
// Updates the painted background color.
void UpdateBackgroundColor();
@@ -465,6 +483,12 @@ class VIEWS_EXPORT Textfield : public View,
SkColor selection_text_color_;
SkColor selection_background_color_;
+ // In cases where the Widget is deleted before the Textfield, there is no
+ // longer a way to retrieve the FocusManager. It's still needed to remove this
+ // Textfield as an observer, so keep a reference to the FocusManager this
+ // Textfield is listening to, if any.
+ FocusManager* focus_manager_;
+
// Text to display when empty.
base::string16 placeholder_text_;

Powered by Google App Engine
This is Rietveld 408576698