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

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 rebase. 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,
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 bool CanDrop(const ui::OSExchangeData& data) override; 242 bool CanDrop(const ui::OSExchangeData& data) override;
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 GetAccessibleState(ui::AXViewState* state) override; 247 void GetAccessibleState(ui::AXViewState* state) override;
242 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 248 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
243 bool GetNeedsNotificationWhenVisibleBoundsChange() const override; 249 bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
244 void OnVisibleBoundsChanged() override; 250 void OnVisibleBoundsChanged() override;
245 void OnEnabledChanged() override; 251 void OnEnabledChanged() override;
252 void ViewHierarchyChanged(
253 const ViewHierarchyChangedDetails& details) override;
246 void OnPaint(gfx::Canvas* canvas) override; 254 void OnPaint(gfx::Canvas* canvas) override;
247 void OnFocus() override; 255 void OnFocus() override;
248 void OnBlur() override; 256 void OnBlur() override;
249 gfx::Point GetKeyboardContextMenuLocation() override; 257 gfx::Point GetKeyboardContextMenuLocation() override;
250 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 258 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
251 259
252 // TextfieldModel::Delegate overrides: 260 // TextfieldModel::Delegate overrides:
253 void OnCompositionTextConfirmedOrCleared() override; 261 void OnCompositionTextConfirmedOrCleared() override;
254 262
255 // ContextMenuController overrides: 263 // ContextMenuController overrides:
256 void ShowContextMenuForView(View* source, 264 void ShowContextMenuForView(View* source,
257 const gfx::Point& point, 265 const gfx::Point& point,
258 ui::MenuSourceType source_type) override; 266 ui::MenuSourceType source_type) override;
259 267
260 // DragController overrides: 268 // DragController overrides:
261 void WriteDragDataForView(View* sender, 269 void WriteDragDataForView(View* sender,
262 const gfx::Point& press_pt, 270 const gfx::Point& press_pt,
263 ui::OSExchangeData* data) override; 271 ui::OSExchangeData* data) override;
264 int GetDragOperationsForView(View* sender, const gfx::Point& p) override; 272 int GetDragOperationsForView(View* sender, const gfx::Point& p) override;
265 bool CanStartDragForView(View* sender, 273 bool CanStartDragForView(View* sender,
266 const gfx::Point& press_pt, 274 const gfx::Point& press_pt,
267 const gfx::Point& p) override; 275 const gfx::Point& p) override;
268 276
277 // FocusChangeListener overrides:
278 void OnWillChangeFocus(View* focused_before, View* focused_now) override;
279 void OnDidChangeFocus(View* focused_before, View* focused_now) override;
280
269 // WordLookupClient overrides: 281 // WordLookupClient overrides:
270 bool GetDecoratedWordAtPoint(const gfx::Point& point, 282 bool GetDecoratedWordAtPoint(const gfx::Point& point,
271 gfx::DecoratedText* decorated_word, 283 gfx::DecoratedText* decorated_word,
272 gfx::Point* baseline_point) override; 284 gfx::Point* baseline_point) override;
273 285
274 // SelectionControllerDelegate overrides: 286 // SelectionControllerDelegate overrides:
275 bool HasTextBeingDragged() const override; 287 bool HasTextBeingDragged() const override;
276 288
277 // ui::TouchEditable overrides: 289 // ui::TouchEditable overrides:
278 void SelectRect(const gfx::Point& start, const gfx::Point& end) override; 290 void SelectRect(const gfx::Point& start, const gfx::Point& end) override;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // what overriding color values should be used instead. 474 // what overriding color values should be used instead.
463 bool use_default_text_color_; 475 bool use_default_text_color_;
464 bool use_default_background_color_; 476 bool use_default_background_color_;
465 bool use_default_selection_text_color_; 477 bool use_default_selection_text_color_;
466 bool use_default_selection_background_color_; 478 bool use_default_selection_background_color_;
467 SkColor text_color_; 479 SkColor text_color_;
468 SkColor background_color_; 480 SkColor background_color_;
469 SkColor selection_text_color_; 481 SkColor selection_text_color_;
470 SkColor selection_background_color_; 482 SkColor selection_background_color_;
471 483
484 // In cases where the Widget is deleted before the Textfield, there is no
485 // longer a way to retrieve the FocusManager. It's still needed to remove this
486 // Textfield as an observer, so keep a reference to the FocusManager this
487 // Textfield is listening to, if any.
488 FocusManager* focus_manager_;
489
472 // Text to display when empty. 490 // Text to display when empty.
473 base::string16 placeholder_text_; 491 base::string16 placeholder_text_;
474 492
475 // Placeholder text color. 493 // Placeholder text color.
476 // TODO(estade): remove this when Harmony/MD is default. 494 // TODO(estade): remove this when Harmony/MD is default.
477 SkColor placeholder_text_color_; 495 SkColor placeholder_text_color_;
478 496
479 // True when the contents are deemed unacceptable and should be indicated as 497 // True when the contents are deemed unacceptable and should be indicated as
480 // such. 498 // such.
481 bool invalid_; 499 bool invalid_;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 551
534 // Used to bind callback functions to this object. 552 // Used to bind callback functions to this object.
535 base::WeakPtrFactory<Textfield> weak_ptr_factory_; 553 base::WeakPtrFactory<Textfield> weak_ptr_factory_;
536 554
537 DISALLOW_COPY_AND_ASSIGN(Textfield); 555 DISALLOW_COPY_AND_ASSIGN(Textfield);
538 }; 556 };
539 557
540 } // namespace views 558 } // namespace views
541 559
542 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 560 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698