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

Side by Side 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 unified diff | Download patch
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 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "ui/base/models/simple_menu_model.h" 22 #include "ui/base/models/simple_menu_model.h"
23 #include "ui/base/touch/touch_editing_controller.h" 23 #include "ui/base/touch/touch_editing_controller.h"
24 #include "ui/events/keycodes/keyboard_codes.h" 24 #include "ui/events/keycodes/keyboard_codes.h"
25 #include "ui/gfx/font_list.h" 25 #include "ui/gfx/font_list.h"
26 #include "ui/gfx/range/range.h" 26 #include "ui/gfx/range/range.h"
27 #include "ui/gfx/selection_model.h" 27 #include "ui/gfx/selection_model.h"
28 #include "ui/gfx/text_constants.h" 28 #include "ui/gfx/text_constants.h"
29 #include "ui/views/context_menu_controller.h" 29 #include "ui/views/context_menu_controller.h"
30 #include "ui/views/controls/textfield/textfield_model.h" 30 #include "ui/views/controls/textfield/textfield_model.h"
31 #include "ui/views/drag_controller.h" 31 #include "ui/views/drag_controller.h"
32 #include "ui/views/focus/focus_manager.h"
32 #include "ui/views/selection_controller.h" 33 #include "ui/views/selection_controller.h"
33 #include "ui/views/selection_controller_delegate.h" 34 #include "ui/views/selection_controller_delegate.h"
34 #include "ui/views/view.h" 35 #include "ui/views/view.h"
35 #include "ui/views/word_lookup_client.h" 36 #include "ui/views/word_lookup_client.h"
36 37
37 namespace views { 38 namespace views {
38 39
39 class MenuRunner; 40 class MenuRunner;
40 class Painter; 41 class Painter;
41 class TextfieldController; 42 class TextfieldController;
42 43
43 // A views/skia textfield implementation. No platform-specific code is used. 44 // A views/skia textfield implementation. No platform-specific code is used.
44 class VIEWS_EXPORT Textfield : public View, 45 class VIEWS_EXPORT Textfield : public View,
45 public TextfieldModel::Delegate, 46 public TextfieldModel::Delegate,
46 public ContextMenuController, 47 public ContextMenuController,
47 public DragController, 48 public DragController,
49 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
48 public WordLookupClient, 50 public WordLookupClient,
49 public SelectionControllerDelegate, 51 public SelectionControllerDelegate,
50 public ui::TouchEditable, 52 public ui::TouchEditable,
51 public ui::TextInputClient { 53 public ui::TextInputClient {
52 public: 54 public:
53 // The textfield's class name. 55 // The textfield's class name.
54 static const char kViewClassName[]; 56 static const char kViewClassName[];
55 57
56 // The preferred size of the padding to be used around textfield text. 58 // The preferred size of the padding to be used around textfield text.
57 static const int kTextPadding; 59 static const int kTextPadding;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 void SetSelectionTextColor(SkColor color); 135 void SetSelectionTextColor(SkColor color);
134 void UseDefaultSelectionTextColor(); 136 void UseDefaultSelectionTextColor();
135 137
136 // Gets/sets the selection background color to be used when painting the 138 // Gets/sets the selection background color to be used when painting the
137 // Textfield. Call UseDefaultSelectionBackgroundColor() to restore the default 139 // Textfield. Call UseDefaultSelectionBackgroundColor() to restore the default
138 // system color. 140 // system color.
139 SkColor GetSelectionBackgroundColor() const; 141 SkColor GetSelectionBackgroundColor() const;
140 void SetSelectionBackgroundColor(SkColor color); 142 void SetSelectionBackgroundColor(SkColor color);
141 void UseDefaultSelectionBackgroundColor(); 143 void UseDefaultSelectionBackgroundColor();
142 144
145 // Gets the selection background color for use when the Textfield was the last
146 // to be focused in a widget.
147 SkColor GetUnfocusedSelectionBackgroundColor() const;
148
143 // Set drop shadows underneath the text. 149 // Set drop shadows underneath the text.
144 void SetShadows(const gfx::ShadowValues& shadows); 150 void SetShadows(const gfx::ShadowValues& shadows);
145 151
146 // Gets/Sets whether or not the cursor is enabled. 152 // Gets/Sets whether or not the cursor is enabled.
147 bool GetCursorEnabled() const; 153 bool GetCursorEnabled() const;
148 void SetCursorEnabled(bool enabled); 154 void SetCursorEnabled(bool enabled);
149 155
150 // Gets/Sets the fonts used when rendering the text within the Textfield. 156 // Gets/Sets the fonts used when rendering the text within the Textfield.
151 const gfx::FontList& GetFontList() const; 157 const gfx::FontList& GetFontList() const;
152 void SetFontList(const gfx::FontList& font_list); 158 void SetFontList(const gfx::FontList& font_list);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 int OnDragUpdated(const ui::DropTargetEvent& event) override; 243 int OnDragUpdated(const ui::DropTargetEvent& event) override;
238 void OnDragExited() override; 244 void OnDragExited() override;
239 int OnPerformDrop(const ui::DropTargetEvent& event) override; 245 int OnPerformDrop(const ui::DropTargetEvent& event) override;
240 void OnDragDone() override; 246 void OnDragDone() override;
241 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 247 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
242 bool HandleAccessibleAction(const ui::AXActionData& action_data) override; 248 bool HandleAccessibleAction(const ui::AXActionData& action_data) override;
243 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 249 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
244 bool GetNeedsNotificationWhenVisibleBoundsChange() const override; 250 bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
245 void OnVisibleBoundsChanged() override; 251 void OnVisibleBoundsChanged() override;
246 void OnEnabledChanged() override; 252 void OnEnabledChanged() override;
253 void ViewHierarchyChanged(
254 const ViewHierarchyChangedDetails& details) override;
255 void NativeViewHierarchyChanged() override;
247 void OnPaint(gfx::Canvas* canvas) override; 256 void OnPaint(gfx::Canvas* canvas) override;
248 void OnFocus() override; 257 void OnFocus() override;
249 void OnBlur() override; 258 void OnBlur() override;
250 gfx::Point GetKeyboardContextMenuLocation() override; 259 gfx::Point GetKeyboardContextMenuLocation() override;
251 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 260 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
252 261
253 // TextfieldModel::Delegate overrides: 262 // TextfieldModel::Delegate overrides:
254 void OnCompositionTextConfirmedOrCleared() override; 263 void OnCompositionTextConfirmedOrCleared() override;
255 264
256 // ContextMenuController overrides: 265 // ContextMenuController overrides:
257 void ShowContextMenuForView(View* source, 266 void ShowContextMenuForView(View* source,
258 const gfx::Point& point, 267 const gfx::Point& point,
259 ui::MenuSourceType source_type) override; 268 ui::MenuSourceType source_type) override;
260 269
261 // DragController overrides: 270 // DragController overrides:
262 void WriteDragDataForView(View* sender, 271 void WriteDragDataForView(View* sender,
263 const gfx::Point& press_pt, 272 const gfx::Point& press_pt,
264 ui::OSExchangeData* data) override; 273 ui::OSExchangeData* data) override;
265 int GetDragOperationsForView(View* sender, const gfx::Point& p) override; 274 int GetDragOperationsForView(View* sender, const gfx::Point& p) override;
266 bool CanStartDragForView(View* sender, 275 bool CanStartDragForView(View* sender,
267 const gfx::Point& press_pt, 276 const gfx::Point& press_pt,
268 const gfx::Point& p) override; 277 const gfx::Point& p) override;
269 278
279 // FocusChangeListener overrides:
280 void OnWillChangeFocus(View* focused_before, View* focused_now) override;
281 void OnDidChangeFocus(View* focused_before, View* focused_now) override;
282
270 // WordLookupClient overrides: 283 // WordLookupClient overrides:
271 bool GetDecoratedWordAtPoint(const gfx::Point& point, 284 bool GetDecoratedWordAtPoint(const gfx::Point& point,
272 gfx::DecoratedText* decorated_word, 285 gfx::DecoratedText* decorated_word,
273 gfx::Point* baseline_point) override; 286 gfx::Point* baseline_point) override;
274 287
275 // SelectionControllerDelegate overrides: 288 // SelectionControllerDelegate overrides:
276 bool HasTextBeingDragged() const override; 289 bool HasTextBeingDragged() const override;
277 290
278 // ui::TouchEditable overrides: 291 // ui::TouchEditable overrides:
279 void SelectRect(const gfx::Point& start, const gfx::Point& end) override; 292 void SelectRect(const gfx::Point& start, const gfx::Point& end) override;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 int GetViewHeight() const override; 370 int GetViewHeight() const override;
358 int GetViewWidth() const override; 371 int GetViewWidth() const override;
359 int GetDragSelectionDelay() const override; 372 int GetDragSelectionDelay() const override;
360 void OnBeforePointerAction() override; 373 void OnBeforePointerAction() override;
361 void OnAfterPointerAction(bool text_changed, bool selection_changed) override; 374 void OnAfterPointerAction(bool text_changed, bool selection_changed) override;
362 // Callers within Textfield should call UpdateAfterChange depending on the 375 // Callers within Textfield should call UpdateAfterChange depending on the
363 // return value. 376 // return value.
364 bool PasteSelectionClipboard() override; 377 bool PasteSelectionClipboard() override;
365 void UpdateSelectionClipboard() override; 378 void UpdateSelectionClipboard() override;
366 379
380 // Adds this Textfield as a FocusChangeListener based on |add_as_listener|.
381 // Always removes this Textfield as a listener of the previously listened-to
382 // focus manager (if it exists) before this happens.
383 void ObserveWidgetFocusChanges(bool add_as_listener);
384
367 // Updates the painted background color. 385 // Updates the painted background color.
368 void UpdateBackgroundColor(); 386 void UpdateBackgroundColor();
369 387
370 // Updates the border per the state of |invalid_|. 388 // Updates the border per the state of |invalid_|.
371 void UpdateBorder(); 389 void UpdateBorder();
372 390
373 // Does necessary updates when the text and/or cursor position changes. 391 // Does necessary updates when the text and/or cursor position changes.
374 void UpdateAfterChange(bool text_changed, bool cursor_changed); 392 void UpdateAfterChange(bool text_changed, bool cursor_changed);
375 393
376 // A callback function to periodically update the cursor node_data. 394 // A callback function to periodically update the cursor node_data.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // what overriding color values should be used instead. 476 // what overriding color values should be used instead.
459 bool use_default_text_color_; 477 bool use_default_text_color_;
460 bool use_default_background_color_; 478 bool use_default_background_color_;
461 bool use_default_selection_text_color_; 479 bool use_default_selection_text_color_;
462 bool use_default_selection_background_color_; 480 bool use_default_selection_background_color_;
463 SkColor text_color_; 481 SkColor text_color_;
464 SkColor background_color_; 482 SkColor background_color_;
465 SkColor selection_text_color_; 483 SkColor selection_text_color_;
466 SkColor selection_background_color_; 484 SkColor selection_background_color_;
467 485
486 // In cases where the Widget is deleted before the Textfield, there is no
487 // longer a way to retrieve the FocusManager. It's still needed to remove this
488 // Textfield as an observer, so keep a reference to the FocusManager this
489 // Textfield is listening to, if any.
490 FocusManager* focus_manager_;
491
468 // Text to display when empty. 492 // Text to display when empty.
469 base::string16 placeholder_text_; 493 base::string16 placeholder_text_;
470 494
471 // Placeholder text color. 495 // Placeholder text color.
472 // TODO(estade): remove this when Harmony/MD is default. 496 // TODO(estade): remove this when Harmony/MD is default.
473 SkColor placeholder_text_color_; 497 SkColor placeholder_text_color_;
474 498
475 // True when the contents are deemed unacceptable and should be indicated as 499 // True when the contents are deemed unacceptable and should be indicated as
476 // such. 500 // such.
477 bool invalid_; 501 bool invalid_;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 553
530 // Used to bind callback functions to this object. 554 // Used to bind callback functions to this object.
531 base::WeakPtrFactory<Textfield> weak_ptr_factory_; 555 base::WeakPtrFactory<Textfield> weak_ptr_factory_;
532 556
533 DISALLOW_COPY_AND_ASSIGN(Textfield); 557 DISALLOW_COPY_AND_ASSIGN(Textfield);
534 }; 558 };
535 559
536 } // namespace views 560 } // namespace views
537 561
538 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 562 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698