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/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 Loading... | |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 | 208 |
| 203 // Clears Edit history. | 209 // Clears Edit history. |
| 204 void ClearEditHistory(); | 210 void ClearEditHistory(); |
| 205 | 211 |
| 206 // Set the accessible name of the text field. | 212 // Set the accessible name of the text field. |
| 207 void SetAccessibleName(const base::string16& name); | 213 void SetAccessibleName(const base::string16& name); |
| 208 | 214 |
| 209 // Returns whether there is a drag operation originating from the textfield. | 215 // Returns whether there is a drag operation originating from the textfield. |
| 210 bool HasTextBeingDragged(); | 216 bool HasTextBeingDragged(); |
| 211 | 217 |
| 212 // View overrides: | 218 // View: |
|
tapted
2016/10/13 06:21:35
there's a lot of this style still around - usually
Patti Lor
2016/10/24 02:43:17
Reverted in both the .h and .cc :)
| |
| 213 gfx::Insets GetInsets() const override; | 219 gfx::Insets GetInsets() const override; |
| 214 int GetBaseline() const override; | 220 int GetBaseline() const override; |
| 215 gfx::Size GetPreferredSize() const override; | 221 gfx::Size GetPreferredSize() const override; |
| 216 const char* GetClassName() const override; | 222 const char* GetClassName() const override; |
| 217 void SetBorder(std::unique_ptr<Border> b) override; | 223 void SetBorder(std::unique_ptr<Border> b) override; |
| 218 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; | 224 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; |
| 219 bool OnMousePressed(const ui::MouseEvent& event) override; | 225 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 220 bool OnMouseDragged(const ui::MouseEvent& event) override; | 226 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 221 void OnMouseReleased(const ui::MouseEvent& event) override; | 227 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 222 WordLookupClient* GetWordLookupClient() override; | 228 WordLookupClient* GetWordLookupClient() override; |
| 223 void OnGestureEvent(ui::GestureEvent* event) override; | 229 void OnGestureEvent(ui::GestureEvent* event) override; |
| 224 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 230 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 225 bool CanHandleAccelerators() const override; | 231 bool CanHandleAccelerators() const override; |
| 226 void AboutToRequestFocusFromTabTraversal(bool reverse) override; | 232 void AboutToRequestFocusFromTabTraversal(bool reverse) override; |
| 227 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override; | 233 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override; |
| 228 bool GetDropFormats( | 234 bool GetDropFormats( |
| 229 int* formats, | 235 int* formats, |
| 230 std::set<ui::Clipboard::FormatType>* format_types) override; | 236 std::set<ui::Clipboard::FormatType>* format_types) override; |
| 231 bool CanDrop(const ui::OSExchangeData& data) override; | 237 bool CanDrop(const ui::OSExchangeData& data) override; |
| 232 int OnDragUpdated(const ui::DropTargetEvent& event) override; | 238 int OnDragUpdated(const ui::DropTargetEvent& event) override; |
| 233 void OnDragExited() override; | 239 void OnDragExited() override; |
| 234 int OnPerformDrop(const ui::DropTargetEvent& event) override; | 240 int OnPerformDrop(const ui::DropTargetEvent& event) override; |
| 235 void OnDragDone() override; | 241 void OnDragDone() override; |
| 236 void GetAccessibleState(ui::AXViewState* state) override; | 242 void GetAccessibleState(ui::AXViewState* state) override; |
| 237 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 243 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
| 238 bool GetNeedsNotificationWhenVisibleBoundsChange() const override; | 244 bool GetNeedsNotificationWhenVisibleBoundsChange() const override; |
| 239 void OnVisibleBoundsChanged() override; | 245 void OnVisibleBoundsChanged() override; |
| 240 void OnEnabledChanged() override; | 246 void OnEnabledChanged() override; |
| 247 void ViewHierarchyChanged( | |
| 248 const ViewHierarchyChangedDetails& details) override; | |
| 241 void OnPaint(gfx::Canvas* canvas) override; | 249 void OnPaint(gfx::Canvas* canvas) override; |
| 242 void OnFocus() override; | 250 void OnFocus() override; |
| 243 void OnBlur() override; | 251 void OnBlur() override; |
| 244 gfx::Point GetKeyboardContextMenuLocation() override; | 252 gfx::Point GetKeyboardContextMenuLocation() override; |
| 245 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 253 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 246 | 254 |
| 247 // TextfieldModel::Delegate overrides: | 255 // TextfieldModel::Delegate: |
| 248 void OnCompositionTextConfirmedOrCleared() override; | 256 void OnCompositionTextConfirmedOrCleared() override; |
| 249 | 257 |
| 250 // ContextMenuController overrides: | 258 // ContextMenuController: |
| 251 void ShowContextMenuForView(View* source, | 259 void ShowContextMenuForView(View* source, |
| 252 const gfx::Point& point, | 260 const gfx::Point& point, |
| 253 ui::MenuSourceType source_type) override; | 261 ui::MenuSourceType source_type) override; |
| 254 | 262 |
| 255 // DragController overrides: | 263 // DragController: |
| 256 void WriteDragDataForView(View* sender, | 264 void WriteDragDataForView(View* sender, |
| 257 const gfx::Point& press_pt, | 265 const gfx::Point& press_pt, |
| 258 ui::OSExchangeData* data) override; | 266 ui::OSExchangeData* data) override; |
| 259 int GetDragOperationsForView(View* sender, const gfx::Point& p) override; | 267 int GetDragOperationsForView(View* sender, const gfx::Point& p) override; |
| 260 bool CanStartDragForView(View* sender, | 268 bool CanStartDragForView(View* sender, |
| 261 const gfx::Point& press_pt, | 269 const gfx::Point& press_pt, |
| 262 const gfx::Point& p) override; | 270 const gfx::Point& p) override; |
| 263 | 271 |
| 264 // WordLookupClient overrides: | 272 // FocusChangeListener: |
| 273 void OnWillChangeFocus(View* focused_before, View* focused_now) override; | |
| 274 void OnDidChangeFocus(View* focused_before, View* focused_now) override; | |
| 275 | |
| 276 // WordLookupClient: | |
| 265 bool GetDecoratedWordAtPoint(const gfx::Point& point, | 277 bool GetDecoratedWordAtPoint(const gfx::Point& point, |
| 266 gfx::DecoratedText* decorated_word, | 278 gfx::DecoratedText* decorated_word, |
| 267 gfx::Point* baseline_point) override; | 279 gfx::Point* baseline_point) override; |
| 268 | 280 |
| 269 // ui::TouchEditable overrides: | 281 // ui::TouchEditable: |
| 270 void SelectRect(const gfx::Point& start, const gfx::Point& end) override; | 282 void SelectRect(const gfx::Point& start, const gfx::Point& end) override; |
| 271 void MoveCaretTo(const gfx::Point& point) override; | 283 void MoveCaretTo(const gfx::Point& point) override; |
| 272 void GetSelectionEndPoints(gfx::SelectionBound* anchor, | 284 void GetSelectionEndPoints(gfx::SelectionBound* anchor, |
| 273 gfx::SelectionBound* focus) override; | 285 gfx::SelectionBound* focus) override; |
| 274 gfx::Rect GetBounds() override; | 286 gfx::Rect GetBounds() override; |
| 275 gfx::NativeView GetNativeView() const override; | 287 gfx::NativeView GetNativeView() const override; |
| 276 void ConvertPointToScreen(gfx::Point* point) override; | 288 void ConvertPointToScreen(gfx::Point* point) override; |
| 277 void ConvertPointFromScreen(gfx::Point* point) override; | 289 void ConvertPointFromScreen(gfx::Point* point) override; |
| 278 bool DrawsHandles() override; | 290 bool DrawsHandles() override; |
| 279 void OpenContextMenu(const gfx::Point& anchor) override; | 291 void OpenContextMenu(const gfx::Point& anchor) override; |
| 280 void DestroyTouchSelection() override; | 292 void DestroyTouchSelection() override; |
| 281 | 293 |
| 282 // ui::SimpleMenuModel::Delegate overrides: | 294 // ui::SimpleMenuModel::Delegate: |
| 283 bool IsCommandIdChecked(int command_id) const override; | 295 bool IsCommandIdChecked(int command_id) const override; |
| 284 bool IsCommandIdEnabled(int command_id) const override; | 296 bool IsCommandIdEnabled(int command_id) const override; |
| 285 bool GetAcceleratorForCommandId(int command_id, | 297 bool GetAcceleratorForCommandId(int command_id, |
| 286 ui::Accelerator* accelerator) const override; | 298 ui::Accelerator* accelerator) const override; |
| 287 void ExecuteCommand(int command_id, int event_flags) override; | 299 void ExecuteCommand(int command_id, int event_flags) override; |
| 288 | 300 |
| 289 // ui::TextInputClient overrides: | 301 // ui::TextInputClient: |
| 290 void SetCompositionText(const ui::CompositionText& composition) override; | 302 void SetCompositionText(const ui::CompositionText& composition) override; |
| 291 void ConfirmCompositionText() override; | 303 void ConfirmCompositionText() override; |
| 292 void ClearCompositionText() override; | 304 void ClearCompositionText() override; |
| 293 void InsertText(const base::string16& text) override; | 305 void InsertText(const base::string16& text) override; |
| 294 void InsertChar(const ui::KeyEvent& event) override; | 306 void InsertChar(const ui::KeyEvent& event) override; |
| 295 ui::TextInputType GetTextInputType() const override; | 307 ui::TextInputType GetTextInputType() const override; |
| 296 ui::TextInputMode GetTextInputMode() const override; | 308 ui::TextInputMode GetTextInputMode() const override; |
| 297 base::i18n::TextDirection GetTextDirection() const override; | 309 base::i18n::TextDirection GetTextDirection() const override; |
| 298 int GetTextInputFlags() const override; | 310 int GetTextInputFlags() const override; |
| 299 bool CanComposeInline() const override; | 311 bool CanComposeInline() const override; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 327 | 339 |
| 328 // Get the text from the selection clipboard. | 340 // Get the text from the selection clipboard. |
| 329 virtual base::string16 GetSelectionClipboardText() const; | 341 virtual base::string16 GetSelectionClipboardText() const; |
| 330 | 342 |
| 331 // Executes the given |command|. | 343 // Executes the given |command|. |
| 332 virtual void ExecuteTextEditCommand(ui::TextEditCommand command); | 344 virtual void ExecuteTextEditCommand(ui::TextEditCommand command); |
| 333 | 345 |
| 334 private: | 346 private: |
| 335 friend class TextfieldTestApi; | 347 friend class TextfieldTestApi; |
| 336 | 348 |
| 337 // View overrides: | 349 // View: |
| 338 // Declared final since overriding by subclasses would interfere with the | 350 // Declared final since overriding by subclasses would interfere with the |
| 339 // accounting related to the scheduled text edit command. Subclasses should | 351 // accounting related to the scheduled text edit command. Subclasses should |
| 340 // use TextfieldController::HandleKeyEvent, to intercept the key event. | 352 // use TextfieldController::HandleKeyEvent, to intercept the key event. |
| 341 bool OnKeyPressed(const ui::KeyEvent& event) final; | 353 bool OnKeyPressed(const ui::KeyEvent& event) final; |
| 342 bool OnKeyReleased(const ui::KeyEvent& event) final; | 354 bool OnKeyReleased(const ui::KeyEvent& event) final; |
| 343 | 355 |
| 344 // Handles a request to change the value of this text field from software | 356 // Handles a request to change the value of this text field from software |
| 345 // using an accessibility API (typically automation software, screen readers | 357 // using an accessibility API (typically automation software, screen readers |
| 346 // don't normally use this). Sets the value and clears the selection. | 358 // don't normally use this). Sets the value and clears the selection. |
| 347 void AccessibilitySetValue(const base::string16& new_value); | 359 void AccessibilitySetValue(const base::string16& new_value); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 // what overriding color values should be used instead. | 462 // what overriding color values should be used instead. |
| 451 bool use_default_text_color_; | 463 bool use_default_text_color_; |
| 452 bool use_default_background_color_; | 464 bool use_default_background_color_; |
| 453 bool use_default_selection_text_color_; | 465 bool use_default_selection_text_color_; |
| 454 bool use_default_selection_background_color_; | 466 bool use_default_selection_background_color_; |
| 455 SkColor text_color_; | 467 SkColor text_color_; |
| 456 SkColor background_color_; | 468 SkColor background_color_; |
| 457 SkColor selection_text_color_; | 469 SkColor selection_text_color_; |
| 458 SkColor selection_background_color_; | 470 SkColor selection_background_color_; |
| 459 | 471 |
| 472 // Whether to start drawing the text selection in gray due to the Widget | |
| 473 // losing focus. | |
| 474 bool change_selection_background_color_on_next_blur_; | |
| 475 | |
| 460 // Text to display when empty. | 476 // Text to display when empty. |
| 461 base::string16 placeholder_text_; | 477 base::string16 placeholder_text_; |
| 462 | 478 |
| 463 // Placeholder text color. | 479 // Placeholder text color. |
| 464 // TODO(estade): remove this when Harmony/MD is default. | 480 // TODO(estade): remove this when Harmony/MD is default. |
| 465 SkColor placeholder_text_color_; | 481 SkColor placeholder_text_color_; |
| 466 | 482 |
| 467 // The accessible name of the text field. | 483 // The accessible name of the text field. |
| 468 base::string16 accessible_name_; | 484 base::string16 accessible_name_; |
| 469 | 485 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 | 540 |
| 525 // Used to bind callback functions to this object. | 541 // Used to bind callback functions to this object. |
| 526 base::WeakPtrFactory<Textfield> weak_ptr_factory_; | 542 base::WeakPtrFactory<Textfield> weak_ptr_factory_; |
| 527 | 543 |
| 528 DISALLOW_COPY_AND_ASSIGN(Textfield); | 544 DISALLOW_COPY_AND_ASSIGN(Textfield); |
| 529 }; | 545 }; |
| 530 | 546 |
| 531 } // namespace views | 547 } // namespace views |
| 532 | 548 |
| 533 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 549 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| OLD | NEW |