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

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 up colors for Linux. 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/view.h" 33 #include "ui/views/view.h"
33 #include "ui/views/word_lookup_client.h" 34 #include "ui/views/word_lookup_client.h"
34 35
35 namespace views { 36 namespace views {
36 37
37 class MenuRunner; 38 class MenuRunner;
38 class Painter; 39 class Painter;
39 class TextfieldController; 40 class TextfieldController;
40 41
41 // A views/skia textfield implementation. No platform-specific code is used. 42 // A views/skia textfield implementation. No platform-specific code is used.
42 class VIEWS_EXPORT Textfield : public View, 43 class VIEWS_EXPORT Textfield : public View,
43 public TextfieldModel::Delegate, 44 public TextfieldModel::Delegate,
44 public ContextMenuController, 45 public ContextMenuController,
45 public DragController, 46 public DragController,
47 public FocusChangeListener,
46 public WordLookupClient, 48 public WordLookupClient,
47 public ui::TouchEditable, 49 public ui::TouchEditable,
48 public ui::TextInputClient { 50 public ui::TextInputClient {
49 public: 51 public:
50 // The textfield's class name. 52 // The textfield's class name.
51 static const char kViewClassName[]; 53 static const char kViewClassName[];
52 54
53 // The preferred size of the padding to be used around textfield text. 55 // The preferred size of the padding to be used around textfield text.
54 static const int kTextPadding; 56 static const int kTextPadding;
55 57
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void SetSelectionTextColor(SkColor color); 132 void SetSelectionTextColor(SkColor color);
131 void UseDefaultSelectionTextColor(); 133 void UseDefaultSelectionTextColor();
132 134
133 // Gets/sets the selection background color to be used when painting the 135 // Gets/sets the selection background color to be used when painting the
134 // Textfield. Call UseDefaultSelectionBackgroundColor() to restore the default 136 // Textfield. Call UseDefaultSelectionBackgroundColor() to restore the default
135 // system color. 137 // system color.
136 SkColor GetSelectionBackgroundColor() const; 138 SkColor GetSelectionBackgroundColor() const;
137 void SetSelectionBackgroundColor(SkColor color); 139 void SetSelectionBackgroundColor(SkColor color);
138 void UseDefaultSelectionBackgroundColor(); 140 void UseDefaultSelectionBackgroundColor();
139 141
142 // Gets the selection background color for use when the Textfield was the last
143 // to be focused in a widget.
144 SkColor GetUnfocusedSelectionBackgroundColor() const;
145
140 // Set drop shadows underneath the text. 146 // Set drop shadows underneath the text.
141 void SetShadows(const gfx::ShadowValues& shadows); 147 void SetShadows(const gfx::ShadowValues& shadows);
142 148
143 // Gets/Sets whether or not the cursor is enabled. 149 // Gets/Sets whether or not the cursor is enabled.
144 bool GetCursorEnabled() const; 150 bool GetCursorEnabled() const;
145 void SetCursorEnabled(bool enabled); 151 void SetCursorEnabled(bool enabled);
146 152
147 // Gets/Sets the fonts used when rendering the text within the Textfield. 153 // Gets/Sets the fonts used when rendering the text within the Textfield.
148 const gfx::FontList& GetFontList() const; 154 const gfx::FontList& GetFontList() const;
149 void SetFontList(const gfx::FontList& font_list); 155 void SetFontList(const gfx::FontList& font_list);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 bool CanDrop(const ui::OSExchangeData& data) override; 241 bool CanDrop(const ui::OSExchangeData& data) override;
236 int OnDragUpdated(const ui::DropTargetEvent& event) override; 242 int OnDragUpdated(const ui::DropTargetEvent& event) override;
237 void OnDragExited() override; 243 void OnDragExited() override;
238 int OnPerformDrop(const ui::DropTargetEvent& event) override; 244 int OnPerformDrop(const ui::DropTargetEvent& event) override;
239 void OnDragDone() override; 245 void OnDragDone() override;
240 void GetAccessibleState(ui::AXViewState* state) override; 246 void GetAccessibleState(ui::AXViewState* state) override;
241 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 247 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
242 bool GetNeedsNotificationWhenVisibleBoundsChange() const override; 248 bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
243 void OnVisibleBoundsChanged() override; 249 void OnVisibleBoundsChanged() override;
244 void OnEnabledChanged() override; 250 void OnEnabledChanged() override;
251 void ViewHierarchyChanged(
252 const ViewHierarchyChangedDetails& details) override;
245 void OnPaint(gfx::Canvas* canvas) override; 253 void OnPaint(gfx::Canvas* canvas) override;
246 void OnFocus() override; 254 void OnFocus() override;
247 void OnBlur() override; 255 void OnBlur() override;
248 gfx::Point GetKeyboardContextMenuLocation() override; 256 gfx::Point GetKeyboardContextMenuLocation() override;
249 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 257 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
250 258
251 // TextfieldModel::Delegate overrides: 259 // TextfieldModel::Delegate overrides:
252 void OnCompositionTextConfirmedOrCleared() override; 260 void OnCompositionTextConfirmedOrCleared() override;
253 261
254 // ContextMenuController overrides: 262 // ContextMenuController overrides:
255 void ShowContextMenuForView(View* source, 263 void ShowContextMenuForView(View* source,
256 const gfx::Point& point, 264 const gfx::Point& point,
257 ui::MenuSourceType source_type) override; 265 ui::MenuSourceType source_type) override;
258 266
259 // DragController overrides: 267 // DragController overrides:
260 void WriteDragDataForView(View* sender, 268 void WriteDragDataForView(View* sender,
261 const gfx::Point& press_pt, 269 const gfx::Point& press_pt,
262 ui::OSExchangeData* data) override; 270 ui::OSExchangeData* data) override;
263 int GetDragOperationsForView(View* sender, const gfx::Point& p) override; 271 int GetDragOperationsForView(View* sender, const gfx::Point& p) override;
264 bool CanStartDragForView(View* sender, 272 bool CanStartDragForView(View* sender,
265 const gfx::Point& press_pt, 273 const gfx::Point& press_pt,
266 const gfx::Point& p) override; 274 const gfx::Point& p) override;
267 275
276 // FocusChangeListener overrides:
277 void OnWillChangeFocus(View* focused_before, View* focused_now) override;
278 void OnDidChangeFocus(View* focused_before, View* focused_now) override;
279 #if !defined(OS_MACOSX)
280 void OnFocusManagerDestroying() override;
281 #endif
282
268 // WordLookupClient overrides: 283 // WordLookupClient overrides:
269 bool GetDecoratedWordAtPoint(const gfx::Point& point, 284 bool GetDecoratedWordAtPoint(const gfx::Point& point,
270 gfx::DecoratedText* decorated_word, 285 gfx::DecoratedText* decorated_word,
271 gfx::Point* baseline_point) override; 286 gfx::Point* baseline_point) override;
272 287
273 // ui::TouchEditable overrides: 288 // ui::TouchEditable overrides:
274 void SelectRect(const gfx::Point& start, const gfx::Point& end) override; 289 void SelectRect(const gfx::Point& start, const gfx::Point& end) override;
275 void MoveCaretTo(const gfx::Point& point) override; 290 void MoveCaretTo(const gfx::Point& point) override;
276 void GetSelectionEndPoints(gfx::SelectionBound* anchor, 291 void GetSelectionEndPoints(gfx::SelectionBound* anchor,
277 gfx::SelectionBound* focus) override; 292 gfx::SelectionBound* focus) override;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 // what overriding color values should be used instead. 472 // what overriding color values should be used instead.
458 bool use_default_text_color_; 473 bool use_default_text_color_;
459 bool use_default_background_color_; 474 bool use_default_background_color_;
460 bool use_default_selection_text_color_; 475 bool use_default_selection_text_color_;
461 bool use_default_selection_background_color_; 476 bool use_default_selection_background_color_;
462 SkColor text_color_; 477 SkColor text_color_;
463 SkColor background_color_; 478 SkColor background_color_;
464 SkColor selection_text_color_; 479 SkColor selection_text_color_;
465 SkColor selection_background_color_; 480 SkColor selection_background_color_;
466 481
482 // In cases where the Widget is deleted before the Textfield, there is no
483 // longer a way to retrieve the FocusManager. It's still needed to remove this
484 // Textfield as an observer, so keep a reference to the FocusManager this
485 // Textfield is listening to, if any.
486 FocusManager* focus_manager_;
tapted 2016/10/24 03:11:19 I don't think OWNERS will like this :/ Let's see i
tapted 2016/10/24 06:04:16 I thought more about this. I think the data member
Patti Lor 2016/10/27 00:17:27 The cleanup in the destructor actually didn't have
487
467 // Text to display when empty. 488 // Text to display when empty.
468 base::string16 placeholder_text_; 489 base::string16 placeholder_text_;
469 490
470 // Placeholder text color. 491 // Placeholder text color.
471 // TODO(estade): remove this when Harmony/MD is default. 492 // TODO(estade): remove this when Harmony/MD is default.
472 SkColor placeholder_text_color_; 493 SkColor placeholder_text_color_;
473 494
474 // True when the contents are deemed unacceptable and should be indicated as 495 // True when the contents are deemed unacceptable and should be indicated as
475 // such. 496 // such.
476 bool invalid_; 497 bool invalid_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 556
536 // Used to bind callback functions to this object. 557 // Used to bind callback functions to this object.
537 base::WeakPtrFactory<Textfield> weak_ptr_factory_; 558 base::WeakPtrFactory<Textfield> weak_ptr_factory_;
538 559
539 DISALLOW_COPY_AND_ASSIGN(Textfield); 560 DISALLOW_COPY_AND_ASSIGN(Textfield);
540 }; 561 };
541 562
542 } // namespace views 563 } // namespace views
543 564
544 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 565 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698