Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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; | |
| 254 void NativeViewHierarchyChanged() override; | |
| 246 void OnPaint(gfx::Canvas* canvas) override; | 255 void OnPaint(gfx::Canvas* canvas) override; |
| 247 void OnFocus() override; | 256 void OnFocus() override; |
| 248 void OnBlur() override; | 257 void OnBlur() override; |
| 249 gfx::Point GetKeyboardContextMenuLocation() override; | 258 gfx::Point GetKeyboardContextMenuLocation() override; |
| 250 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 259 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 251 | 260 |
| 252 // TextfieldModel::Delegate overrides: | 261 // TextfieldModel::Delegate overrides: |
| 253 void OnCompositionTextConfirmedOrCleared() override; | 262 void OnCompositionTextConfirmedOrCleared() override; |
| 254 | 263 |
| 255 // ContextMenuController overrides: | 264 // ContextMenuController overrides: |
| 256 void ShowContextMenuForView(View* source, | 265 void ShowContextMenuForView(View* source, |
| 257 const gfx::Point& point, | 266 const gfx::Point& point, |
| 258 ui::MenuSourceType source_type) override; | 267 ui::MenuSourceType source_type) override; |
| 259 | 268 |
| 260 // DragController overrides: | 269 // DragController overrides: |
| 261 void WriteDragDataForView(View* sender, | 270 void WriteDragDataForView(View* sender, |
| 262 const gfx::Point& press_pt, | 271 const gfx::Point& press_pt, |
| 263 ui::OSExchangeData* data) override; | 272 ui::OSExchangeData* data) override; |
| 264 int GetDragOperationsForView(View* sender, const gfx::Point& p) override; | 273 int GetDragOperationsForView(View* sender, const gfx::Point& p) override; |
| 265 bool CanStartDragForView(View* sender, | 274 bool CanStartDragForView(View* sender, |
| 266 const gfx::Point& press_pt, | 275 const gfx::Point& press_pt, |
| 267 const gfx::Point& p) override; | 276 const gfx::Point& p) override; |
| 268 | 277 |
| 278 // FocusChangeListener overrides: | |
| 279 void OnWillChangeFocus(View* focused_before, View* focused_now) override; | |
| 280 void OnDidChangeFocus(View* focused_before, View* focused_now) override; | |
| 281 | |
| 269 // WordLookupClient overrides: | 282 // WordLookupClient overrides: |
| 270 bool GetDecoratedWordAtPoint(const gfx::Point& point, | 283 bool GetDecoratedWordAtPoint(const gfx::Point& point, |
| 271 gfx::DecoratedText* decorated_word, | 284 gfx::DecoratedText* decorated_word, |
| 272 gfx::Point* baseline_point) override; | 285 gfx::Point* baseline_point) override; |
| 273 | 286 |
| 274 // SelectionControllerDelegate overrides: | 287 // SelectionControllerDelegate overrides: |
| 275 bool HasTextBeingDragged() const override; | 288 bool HasTextBeingDragged() const override; |
| 276 | 289 |
| 277 // ui::TouchEditable overrides: | 290 // ui::TouchEditable overrides: |
| 278 void SelectRect(const gfx::Point& start, const gfx::Point& end) override; | 291 void SelectRect(const gfx::Point& start, const gfx::Point& end) override; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 int GetViewHeight() const override; | 369 int GetViewHeight() const override; |
| 357 int GetViewWidth() const override; | 370 int GetViewWidth() const override; |
| 358 int GetDragSelectionDelay() const override; | 371 int GetDragSelectionDelay() const override; |
| 359 void OnBeforePointerAction() override; | 372 void OnBeforePointerAction() override; |
| 360 void OnAfterPointerAction(bool text_changed, bool selection_changed) override; | 373 void OnAfterPointerAction(bool text_changed, bool selection_changed) override; |
| 361 // Callers within Textfield should call UpdateAfterChange depending on the | 374 // Callers within Textfield should call UpdateAfterChange depending on the |
| 362 // return value. | 375 // return value. |
| 363 bool PasteSelectionClipboard() override; | 376 bool PasteSelectionClipboard() override; |
| 364 void UpdateSelectionClipboard() override; | 377 void UpdateSelectionClipboard() override; |
| 365 | 378 |
| 379 // Adds or removes this Textfield as a FocusChangeListener based on | |
| 380 // |add_as_listener|. | |
| 381 void AddOrRemoveAsFocusChangeListener(bool add_as_listener); | |
|
tapted
2016/11/02 03:45:06
It's generally nice to have a `bool` argument read
Patti Lor
2016/11/07 05:34:27
Done.
| |
| 382 | |
| 366 // Handles a request to change the value of this text field from software | 383 // Handles a request to change the value of this text field from software |
| 367 // using an accessibility API (typically automation software, screen readers | 384 // using an accessibility API (typically automation software, screen readers |
| 368 // don't normally use this). If |clear_first| is true, this replaces all text | 385 // don't normally use this). If |clear_first| is true, this replaces all text |
| 369 // with the |new_value|. Otherwise this inserts |new_value| at the cursor | 386 // with the |new_value|. Otherwise this inserts |new_value| at the cursor |
| 370 // position, replacing any selected text. The cursor is placed at the end of | 387 // position, replacing any selected text. The cursor is placed at the end of |
| 371 // |new_value|. | 388 // |new_value|. |
| 372 void AccessibilitySetValue(const base::string16& new_value, bool clear_first); | 389 void AccessibilitySetValue(const base::string16& new_value, bool clear_first); |
| 373 | 390 |
| 374 // Updates the painted background color. | 391 // Updates the painted background color. |
| 375 void UpdateBackgroundColor(); | 392 void UpdateBackgroundColor(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 // what overriding color values should be used instead. | 482 // what overriding color values should be used instead. |
| 466 bool use_default_text_color_; | 483 bool use_default_text_color_; |
| 467 bool use_default_background_color_; | 484 bool use_default_background_color_; |
| 468 bool use_default_selection_text_color_; | 485 bool use_default_selection_text_color_; |
| 469 bool use_default_selection_background_color_; | 486 bool use_default_selection_background_color_; |
| 470 SkColor text_color_; | 487 SkColor text_color_; |
| 471 SkColor background_color_; | 488 SkColor background_color_; |
| 472 SkColor selection_text_color_; | 489 SkColor selection_text_color_; |
| 473 SkColor selection_background_color_; | 490 SkColor selection_background_color_; |
| 474 | 491 |
| 492 // In cases where the Widget is deleted before the Textfield, there is no | |
| 493 // longer a way to retrieve the FocusManager. It's still needed to remove this | |
| 494 // Textfield as an observer, so keep a reference to the FocusManager this | |
| 495 // Textfield is listening to, if any. | |
| 496 FocusManager* focus_manager_; | |
| 497 | |
| 475 // Text to display when empty. | 498 // Text to display when empty. |
| 476 base::string16 placeholder_text_; | 499 base::string16 placeholder_text_; |
| 477 | 500 |
| 478 // Placeholder text color. | 501 // Placeholder text color. |
| 479 // TODO(estade): remove this when Harmony/MD is default. | 502 // TODO(estade): remove this when Harmony/MD is default. |
| 480 SkColor placeholder_text_color_; | 503 SkColor placeholder_text_color_; |
| 481 | 504 |
| 482 // True when the contents are deemed unacceptable and should be indicated as | 505 // True when the contents are deemed unacceptable and should be indicated as |
| 483 // such. | 506 // such. |
| 484 bool invalid_; | 507 bool invalid_; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 | 559 |
| 537 // Used to bind callback functions to this object. | 560 // Used to bind callback functions to this object. |
| 538 base::WeakPtrFactory<Textfield> weak_ptr_factory_; | 561 base::WeakPtrFactory<Textfield> weak_ptr_factory_; |
| 539 | 562 |
| 540 DISALLOW_COPY_AND_ASSIGN(Textfield); | 563 DISALLOW_COPY_AND_ASSIGN(Textfield); |
| 541 }; | 564 }; |
| 542 | 565 |
| 543 } // namespace views | 566 } // namespace views |
| 544 | 567 |
| 545 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 568 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| OLD | NEW |