| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/time/time.h" |
| 16 #include "build/build_config.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "ui/base/ime/text_input_client.h" | |
| 18 #include "ui/base/ime/text_input_type.h" | 18 #include "ui/base/ime/text_input_type.h" |
| 19 #include "ui/base/models/simple_menu_model.h" | |
| 20 #include "ui/base/touch/touch_editing_controller.h" | |
| 21 #include "ui/events/keycodes/keyboard_codes.h" | 19 #include "ui/events/keycodes/keyboard_codes.h" |
| 22 #include "ui/gfx/font_list.h" | 20 #include "ui/gfx/font_list.h" |
| 23 #include "ui/gfx/range/range.h" | 21 #include "ui/gfx/native_widget_types.h" |
| 24 #include "ui/gfx/selection_model.h" | 22 #include "ui/gfx/selection_model.h" |
| 25 #include "ui/gfx/text_constants.h" | 23 #include "ui/gfx/text_constants.h" |
| 26 #include "ui/views/context_menu_controller.h" | |
| 27 #include "ui/views/controls/textfield/textfield_views_model.h" | |
| 28 #include "ui/views/drag_controller.h" | |
| 29 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 30 | 25 |
| 26 #if !defined(OS_LINUX) |
| 27 #include "base/logging.h" |
| 28 #endif |
| 29 |
| 30 namespace gfx { |
| 31 class Range; |
| 32 class ImageSkia; |
| 33 } |
| 34 |
| 35 namespace ui { |
| 36 class TextInputClient; |
| 37 } // namespace ui |
| 38 |
| 31 namespace views { | 39 namespace views { |
| 32 | 40 |
| 33 class MenuRunner; | 41 class ImageView; |
| 42 class NativeTextfieldViews; |
| 34 class Painter; | 43 class Painter; |
| 35 class TextfieldController; | 44 class TextfieldController; |
| 36 | 45 |
| 37 // A views/skia textfield implementation. No platform-specific code is used. | 46 // This class implements a View that wraps a native text (edit) field. |
| 38 class VIEWS_EXPORT Textfield : public View, | 47 class VIEWS_EXPORT Textfield : public View { |
| 39 public TextfieldViewsModel::Delegate, | |
| 40 public ContextMenuController, | |
| 41 public DragController, | |
| 42 public ui::TouchEditable, | |
| 43 public ui::TextInputClient { | |
| 44 public: | 48 public: |
| 45 // The textfield's class name. | 49 // The textfield's class name. |
| 46 static const char kViewClassName[]; | 50 static const char kViewClassName[]; |
| 47 | 51 |
| 48 enum StyleFlags { | 52 enum StyleFlags { |
| 49 STYLE_DEFAULT = 0, | 53 STYLE_DEFAULT = 0, |
| 50 STYLE_OBSCURED = 1 << 0, | 54 STYLE_OBSCURED = 1 << 0, |
| 51 STYLE_LOWERCASE = 1 << 1 | 55 STYLE_LOWERCASE = 1 << 1 |
| 52 }; | 56 }; |
| 53 | 57 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 | 68 |
| 65 // Gets/Sets whether or not the Textfield is read-only. | 69 // Gets/Sets whether or not the Textfield is read-only. |
| 66 bool read_only() const { return read_only_; } | 70 bool read_only() const { return read_only_; } |
| 67 void SetReadOnly(bool read_only); | 71 void SetReadOnly(bool read_only); |
| 68 | 72 |
| 69 // Gets/sets the STYLE_OBSCURED bit, controlling whether characters in this | 73 // Gets/sets the STYLE_OBSCURED bit, controlling whether characters in this |
| 70 // Textfield are displayed as asterisks/bullets. | 74 // Textfield are displayed as asterisks/bullets. |
| 71 bool IsObscured() const; | 75 bool IsObscured() const; |
| 72 void SetObscured(bool obscured); | 76 void SetObscured(bool obscured); |
| 73 | 77 |
| 74 // Sets the input type of this textfield. | 78 // Gets/sets the duration to reveal the last typed char when the obscured bit |
| 79 // is set. A duration of zero effectively disables the feature. Other values |
| 80 // cause the last typed char to be shown for the defined duration. Note this |
| 81 // only works with NativeTextfieldViews. |
| 82 const base::TimeDelta& obscured_reveal_duration() const { |
| 83 return obscured_reveal_duration_; |
| 84 } |
| 85 void set_obscured_reveal_duration(const base::TimeDelta& duration) { |
| 86 obscured_reveal_duration_ = duration; |
| 87 } |
| 88 |
| 89 // Gets/Sets the input type of this textfield. |
| 90 ui::TextInputType GetTextInputType() const; |
| 75 void SetTextInputType(ui::TextInputType type); | 91 void SetTextInputType(ui::TextInputType type); |
| 76 | 92 |
| 77 // Gets the text currently displayed in the Textfield. | 93 // Gets/Sets the text currently displayed in the Textfield. |
| 78 const base::string16& text() const { return model_->text(); } | 94 const base::string16& text() const { return text_; } |
| 79 | 95 |
| 80 // Sets the text currently displayed in the Textfield. This doesn't | 96 // Sets the text currently displayed in the Textfield. This doesn't |
| 81 // change the cursor position if the current cursor is within the | 97 // change the cursor position if the current cursor is within the |
| 82 // new text's range, or moves the cursor to the end if the cursor is | 98 // new text's range, or moves the cursor to the end if the cursor is |
| 83 // out of the new text's range. | 99 // out of the new text's range. |
| 84 void SetText(const base::string16& new_text); | 100 void SetText(const base::string16& text); |
| 85 | 101 |
| 86 // Appends the given string to the previously-existing text in the field. | 102 // Appends the given string to the previously-existing text in the field. |
| 87 void AppendText(const base::string16& new_text); | 103 void AppendText(const base::string16& text); |
| 88 | 104 |
| 89 // Inserts |new_text| at the cursor position, replacing any selected text. | 105 // Inserts |text| at the current cursor position, replacing any selected text. |
| 90 void InsertOrReplaceText(const base::string16& new_text); | 106 void InsertOrReplaceText(const base::string16& text); |
| 91 | 107 |
| 92 // Returns the text direction. | 108 // Returns the text direction. |
| 93 base::i18n::TextDirection GetTextDirection() const; | 109 base::i18n::TextDirection GetTextDirection() const; |
| 94 | 110 |
| 95 // Returns the text that is currently selected. | 111 // Returns the text that is currently selected. |
| 96 base::string16 GetSelectedText() const; | 112 base::string16 GetSelectedText() const; |
| 97 | 113 |
| 98 // Select the entire text range. If |reversed| is true, the range will end at | 114 // Select the entire text range. If |reversed| is true, the range will end at |
| 99 // the logical beginning of the text; this generally shows the leading portion | 115 // the logical beginning of the text; this generally shows the leading portion |
| 100 // of text that overflows its display area. | 116 // of text that overflows its display area. |
| 101 void SelectAll(bool reversed); | 117 void SelectAll(bool reversed); |
| 102 | 118 |
| 103 // Clears the selection within the edit field and sets the caret to the end. | 119 // Clears the selection within the edit field and sets the caret to the end. |
| 104 void ClearSelection(); | 120 void ClearSelection() const; |
| 105 | 121 |
| 106 // Checks if there is any selected text. | 122 // Checks if there is any selected text. |
| 107 bool HasSelection() const; | 123 bool HasSelection() const; |
| 108 | 124 |
| 109 // Accessor for |style_|. | 125 // Accessor for |style_|. |
| 110 StyleFlags style() const { return style_; } | 126 StyleFlags style() const { return style_; } |
| 111 | 127 |
| 112 // Gets/Sets the text color to be used when painting the Textfield. | 128 // Gets/Sets the text color to be used when painting the Textfield. |
| 113 // Call |UseDefaultTextColor| to restore the default system color. | 129 // Call |UseDefaultTextColor| to restore the default system color. |
| 114 SkColor GetTextColor() const; | 130 SkColor GetTextColor() const; |
| 115 void SetTextColor(SkColor color); | 131 void SetTextColor(SkColor color); |
| 116 void UseDefaultTextColor(); | 132 void UseDefaultTextColor(); |
| 117 | 133 |
| 118 // Gets/Sets the background color to be used when painting the Textfield. | 134 // Gets/Sets the background color to be used when painting the Textfield. |
| 119 // Call |UseDefaultBackgroundColor| to restore the default system color. | 135 // Call |UseDefaultBackgroundColor| to restore the default system color. |
| 120 SkColor GetBackgroundColor() const; | 136 SkColor GetBackgroundColor() const; |
| 121 void SetBackgroundColor(SkColor color); | 137 void SetBackgroundColor(SkColor color); |
| 122 void UseDefaultBackgroundColor(); | 138 void UseDefaultBackgroundColor(); |
| 123 | 139 |
| 124 // Gets/Sets whether or not the cursor is enabled. | 140 // Gets/Sets whether or not the cursor is enabled. |
| 125 bool GetCursorEnabled() const; | 141 bool GetCursorEnabled() const; |
| 126 void SetCursorEnabled(bool enabled); | 142 void SetCursorEnabled(bool enabled); |
| 127 | 143 |
| 128 // Gets/Sets the fonts used when rendering the text within the Textfield. | 144 // Gets/Sets the fonts used when rendering the text within the Textfield. |
| 129 const gfx::FontList& GetFontList() const; | 145 const gfx::FontList& font_list() const { return font_list_; } |
| 130 void SetFontList(const gfx::FontList& font_list); | 146 void SetFontList(const gfx::FontList& font_list); |
| 147 const gfx::Font& GetPrimaryFont() const; |
| 148 void SetFont(const gfx::Font& font); |
| 149 |
| 150 // Sets the left and right margin (in pixels) within the text box. On Windows |
| 151 // this is accomplished by packing the left and right margin into a single |
| 152 // 32 bit number, so the left and right margins are effectively 16 bits. |
| 153 void SetHorizontalMargins(int left, int right); |
| 154 |
| 155 // Sets the top and bottom margins (in pixels) within the textfield. |
| 156 // NOTE: in most cases height could be changed instead. |
| 157 void SetVerticalMargins(int top, int bottom); |
| 131 | 158 |
| 132 // Sets the default width of the text control. See default_width_in_chars_. | 159 // Sets the default width of the text control. See default_width_in_chars_. |
| 133 void set_default_width_in_chars(int default_width) { | 160 void set_default_width_in_chars(int default_width) { |
| 134 default_width_in_chars_ = default_width; | 161 default_width_in_chars_ = default_width; |
| 135 } | 162 } |
| 136 | 163 |
| 164 // Removes the border from the edit box, giving it a 2D look. |
| 165 bool draw_border() const { return draw_border_; } |
| 166 void RemoveBorder(); |
| 167 |
| 137 // Sets the text to display when empty. | 168 // Sets the text to display when empty. |
| 138 void set_placeholder_text(const base::string16& text) { | 169 void set_placeholder_text(const base::string16& text) { |
| 139 placeholder_text_ = text; | 170 placeholder_text_ = text; |
| 140 } | 171 } |
| 141 virtual base::string16 GetPlaceholderText() const; | 172 virtual base::string16 GetPlaceholderText() const; |
| 142 | 173 |
| 143 SkColor placeholder_text_color() const { return placeholder_text_color_; } | 174 SkColor placeholder_text_color() const { return placeholder_text_color_; } |
| 144 void set_placeholder_text_color(SkColor color) { | 175 void set_placeholder_text_color(SkColor color) { |
| 145 placeholder_text_color_ = color; | 176 placeholder_text_color_ = color; |
| 146 } | 177 } |
| 147 | 178 |
| 179 // Getter for the horizontal margins that were set. Returns false if |
| 180 // horizontal margins weren't set. |
| 181 bool GetHorizontalMargins(int* left, int* right); |
| 182 |
| 183 // Getter for the vertical margins that were set. Returns false if vertical |
| 184 // margins weren't set. |
| 185 bool GetVerticalMargins(int* top, int* bottom); |
| 186 |
| 187 // Updates all properties on the textfield. This is invoked internally. |
| 188 // Users of Textfield never need to invoke this directly. |
| 189 void UpdateAllProperties(); |
| 190 |
| 191 // Invoked by the edit control when the value changes. This method set |
| 192 // the text_ member variable to the value contained in edit control. |
| 193 // This is important because the edit control can be replaced if it has |
| 194 // been deleted during a window close. |
| 195 void SyncText(); |
| 196 |
| 148 // Returns whether or not an IME is composing text. | 197 // Returns whether or not an IME is composing text. |
| 149 bool IsIMEComposing() const; | 198 bool IsIMEComposing() const; |
| 150 | 199 |
| 151 // Gets the selected logical text range. | 200 // Gets the selected logical text range. |
| 152 const gfx::Range& GetSelectedRange() const; | 201 const gfx::Range& GetSelectedRange() const; |
| 153 | 202 |
| 154 // Selects the specified logical text range. | 203 // Selects the specified logical text range. |
| 155 void SelectRange(const gfx::Range& range); | 204 void SelectRange(const gfx::Range& range); |
| 156 | 205 |
| 157 // Gets the text selection model. | 206 // Gets the text selection model. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 178 void ClearEditHistory(); | 227 void ClearEditHistory(); |
| 179 | 228 |
| 180 // Set the accessible name of the text field. | 229 // Set the accessible name of the text field. |
| 181 void SetAccessibleName(const base::string16& name); | 230 void SetAccessibleName(const base::string16& name); |
| 182 | 231 |
| 183 // Performs the action associated with the specified command id. | 232 // Performs the action associated with the specified command id. |
| 184 void ExecuteCommand(int command_id); | 233 void ExecuteCommand(int command_id); |
| 185 | 234 |
| 186 void SetFocusPainter(scoped_ptr<Painter> focus_painter); | 235 void SetFocusPainter(scoped_ptr<Painter> focus_painter); |
| 187 | 236 |
| 237 // Provided only for testing: |
| 238 NativeTextfieldViews* GetTextfieldViewForTesting() const { |
| 239 return textfield_view_; |
| 240 } |
| 241 |
| 188 // Returns whether there is a drag operation originating from the textfield. | 242 // Returns whether there is a drag operation originating from the textfield. |
| 189 bool HasTextBeingDragged(); | 243 bool HasTextBeingDragged(); |
| 190 | 244 |
| 191 // View overrides: | 245 // Overridden from View: |
| 192 // TODO(msw): Match declaration and definition order to View. | 246 virtual void Layout() OVERRIDE; |
| 193 virtual int GetBaseline() const OVERRIDE; | 247 virtual int GetBaseline() const OVERRIDE; |
| 194 virtual gfx::Size GetPreferredSize() OVERRIDE; | 248 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 195 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; | 249 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; |
| 196 virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; | 250 virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; |
| 197 virtual void OnEnabledChanged() OVERRIDE; | 251 virtual void OnEnabledChanged() OVERRIDE; |
| 198 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 252 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 199 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 253 virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE; |
| 200 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 254 virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE; |
| 201 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; | 255 virtual bool OnMouseDragged(const ui::MouseEvent& e) OVERRIDE; |
| 202 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | |
| 203 virtual void OnFocus() OVERRIDE; | 256 virtual void OnFocus() OVERRIDE; |
| 204 virtual void OnBlur() OVERRIDE; | 257 virtual void OnBlur() OVERRIDE; |
| 205 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 258 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 206 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; | 259 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; |
| 207 virtual gfx::Point GetKeyboardContextMenuLocation() OVERRIDE; | 260 virtual gfx::Point GetKeyboardContextMenuLocation() OVERRIDE; |
| 208 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; | |
| 209 virtual const char* GetClassName() const OVERRIDE; | |
| 210 virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE; | |
| 211 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | |
| 212 virtual bool GetDropFormats( | |
| 213 int* formats, | |
| 214 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; | |
| 215 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE; | |
| 216 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; | |
| 217 virtual void OnDragExited() OVERRIDE; | |
| 218 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; | |
| 219 virtual void OnDragDone() OVERRIDE; | |
| 220 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | |
| 221 | |
| 222 // TextfieldViewsModel::Delegate overrides: | |
| 223 virtual void OnCompositionTextConfirmedOrCleared() OVERRIDE; | |
| 224 | |
| 225 // ContextMenuController overrides: | |
| 226 virtual void ShowContextMenuForView(View* source, | |
| 227 const gfx::Point& point, | |
| 228 ui::MenuSourceType source_type) OVERRIDE; | |
| 229 | |
| 230 // DragController overrides: | |
| 231 virtual void WriteDragDataForView(View* sender, | |
| 232 const gfx::Point& press_pt, | |
| 233 ui::OSExchangeData* data) OVERRIDE; | |
| 234 virtual int GetDragOperationsForView(View* sender, | |
| 235 const gfx::Point& p) OVERRIDE; | |
| 236 virtual bool CanStartDragForView(View* sender, | |
| 237 const gfx::Point& press_pt, | |
| 238 const gfx::Point& p) OVERRIDE; | |
| 239 | |
| 240 // ui::TouchEditable overrides: | |
| 241 virtual void SelectRect(const gfx::Point& start, | |
| 242 const gfx::Point& end) OVERRIDE; | |
| 243 virtual void MoveCaretTo(const gfx::Point& point) OVERRIDE; | |
| 244 virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) OVERRIDE; | |
| 245 virtual gfx::Rect GetBounds() OVERRIDE; | |
| 246 virtual gfx::NativeView GetNativeView() const OVERRIDE; | |
| 247 virtual void ConvertPointToScreen(gfx::Point* point) OVERRIDE; | |
| 248 virtual void ConvertPointFromScreen(gfx::Point* point) OVERRIDE; | |
| 249 virtual bool DrawsHandles() OVERRIDE; | |
| 250 virtual void OpenContextMenu(const gfx::Point& anchor) OVERRIDE; | |
| 251 | |
| 252 // ui::SimpleMenuModel::Delegate overrides: | |
| 253 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | |
| 254 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | |
| 255 virtual bool GetAcceleratorForCommandId( | |
| 256 int command_id, | |
| 257 ui::Accelerator* accelerator) OVERRIDE; | |
| 258 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | |
| 259 | |
| 260 // ui::TextInputClient overrides: | |
| 261 virtual void SetCompositionText( | |
| 262 const ui::CompositionText& composition) OVERRIDE; | |
| 263 virtual void ConfirmCompositionText() OVERRIDE; | |
| 264 virtual void ClearCompositionText() OVERRIDE; | |
| 265 virtual void InsertText(const base::string16& text) OVERRIDE; | |
| 266 virtual void InsertChar(base::char16 ch, int flags) OVERRIDE; | |
| 267 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE; | |
| 268 virtual ui::TextInputType GetTextInputType() const OVERRIDE; | |
| 269 virtual ui::TextInputMode GetTextInputMode() const OVERRIDE; | |
| 270 virtual bool CanComposeInline() const OVERRIDE; | |
| 271 virtual gfx::Rect GetCaretBounds() const OVERRIDE; | |
| 272 virtual bool GetCompositionCharacterBounds(uint32 index, | |
| 273 gfx::Rect* rect) const OVERRIDE; | |
| 274 virtual bool HasCompositionText() const OVERRIDE; | |
| 275 virtual bool GetTextRange(gfx::Range* range) const OVERRIDE; | |
| 276 virtual bool GetCompositionTextRange(gfx::Range* range) const OVERRIDE; | |
| 277 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE; | |
| 278 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE; | |
| 279 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE; | |
| 280 virtual bool GetTextFromRange(const gfx::Range& range, | |
| 281 base::string16* text) const OVERRIDE; | |
| 282 virtual void OnInputMethodChanged() OVERRIDE; | |
| 283 virtual bool ChangeTextDirectionAndLayoutAlignment( | |
| 284 base::i18n::TextDirection direction) OVERRIDE; | |
| 285 virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE; | |
| 286 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE; | |
| 287 virtual void OnCandidateWindowShown() OVERRIDE; | |
| 288 virtual void OnCandidateWindowUpdated() OVERRIDE; | |
| 289 virtual void OnCandidateWindowHidden() OVERRIDE; | |
| 290 | 261 |
| 291 protected: | 262 protected: |
| 292 // Returns the TextfieldViewsModel's text/cursor/selection rendering model. | 263 virtual void ViewHierarchyChanged( |
| 293 gfx::RenderText* GetRenderText() const; | 264 const ViewHierarchyChangedDetails& details) OVERRIDE; |
| 265 virtual const char* GetClassName() const OVERRIDE; |
| 266 |
| 267 // The object that actually implements the native textfield view. |
| 268 // TODO(msw): Merge views::NativeTextfieldViews and views::Textfield classes. |
| 269 NativeTextfieldViews* textfield_view_; |
| 294 | 270 |
| 295 private: | 271 private: |
| 296 friend class TextfieldTest; | 272 // Returns the insets to the rectangle where text is actually painted. |
| 297 friend class TouchSelectionControllerImplTest; | 273 gfx::Insets GetTextInsets() const; |
| 298 | |
| 299 // Converts the raw text according to the current style, e.g. STYLE_LOWERCASE. | |
| 300 base::string16 GetTextForDisplay(const base::string16& raw); | |
| 301 | 274 |
| 302 // Handles a request to change the value of this text field from software | 275 // Handles a request to change the value of this text field from software |
| 303 // using an accessibility API (typically automation software, screen readers | 276 // using an accessibility API (typically automation software, screen readers |
| 304 // don't normally use this). Sets the value and clears the selection. | 277 // don't normally use this). Sets the value and clears the selection. |
| 305 void AccessibilitySetValue(const base::string16& new_value); | 278 void AccessibilitySetValue(const base::string16& new_value); |
| 306 | 279 |
| 307 // Updates the painted background color. | |
| 308 void UpdateBackgroundColor(); | |
| 309 | |
| 310 // Updates any colors that have not been explicitly set from the theme. | |
| 311 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | |
| 312 | |
| 313 // Does necessary updates when the text and/or cursor position changes. | |
| 314 void UpdateAfterChange(bool text_changed, bool cursor_changed); | |
| 315 | |
| 316 // A callback function to periodically update the cursor state. | |
| 317 void UpdateCursor(); | |
| 318 | |
| 319 // Repaint the cursor. | |
| 320 void RepaintCursor(); | |
| 321 | |
| 322 void PaintTextAndCursor(gfx::Canvas* canvas); | |
| 323 | |
| 324 // Helper function to call MoveCursorTo on the TextfieldViewsModel. | |
| 325 bool MoveCursorTo(const gfx::Point& point, bool select); | |
| 326 | |
| 327 // Convenience method to call InputMethod::OnCaretBoundsChanged(); | |
| 328 void OnCaretBoundsChanged(); | |
| 329 | |
| 330 // Convenience method to call TextfieldController::OnBeforeUserAction(); | |
| 331 void OnBeforeUserAction(); | |
| 332 | |
| 333 // Convenience method to call TextfieldController::OnAfterUserAction(); | |
| 334 void OnAfterUserAction(); | |
| 335 | |
| 336 // Calls |model_->Cut()| and notifies TextfieldController on success. | |
| 337 bool Cut(); | |
| 338 | |
| 339 // Calls |model_->Copy()| and notifies TextfieldController on success. | |
| 340 bool Copy(); | |
| 341 | |
| 342 // Calls |model_->Paste()| and calls TextfieldController::ContentsChanged() | |
| 343 // explicitly if paste succeeded. | |
| 344 bool Paste(); | |
| 345 | |
| 346 // Utility function to prepare the context menu. | |
| 347 void UpdateContextMenu(); | |
| 348 | |
| 349 // Tracks the mouse clicks for single/double/triple clicks. | |
| 350 void TrackMouseClicks(const ui::MouseEvent& event); | |
| 351 | |
| 352 // Returns true if the current text input type allows access by the IME. | |
| 353 bool ImeEditingAllowed() const; | |
| 354 | |
| 355 // Reveals the obscured char at |index| for the given |duration|. If |index| | |
| 356 // is -1, existing revealed index will be cleared. | |
| 357 void RevealObscuredChar(int index, const base::TimeDelta& duration); | |
| 358 | |
| 359 void CreateTouchSelectionControllerAndNotifyIt(); | |
| 360 | |
| 361 // The text model. | |
| 362 scoped_ptr<TextfieldViewsModel> model_; | |
| 363 | |
| 364 // This is the current listener for events from this Textfield. | 280 // This is the current listener for events from this Textfield. |
| 365 TextfieldController* controller_; | 281 TextfieldController* controller_; |
| 366 | 282 |
| 367 // The mask of style options for this Textfield. | 283 // The mask of style options for this Textfield. |
| 368 StyleFlags style_; | 284 StyleFlags style_; |
| 369 | 285 |
| 286 // The fonts used to render the text in the Textfield. |
| 287 gfx::FontList font_list_; |
| 288 |
| 289 // The text displayed in the Textfield. |
| 290 base::string16 text_; |
| 291 |
| 370 // True if this Textfield cannot accept input and is read-only. | 292 // True if this Textfield cannot accept input and is read-only. |
| 371 bool read_only_; | 293 bool read_only_; |
| 372 | 294 |
| 373 // The default number of average characters for the width of this text field. | 295 // The default number of average characters for the width of this text field. |
| 374 // This will be reported as the "desired size". Defaults to 0. | 296 // This will be reported as the "desired size". Defaults to 0. |
| 375 int default_width_in_chars_; | 297 int default_width_in_chars_; |
| 376 | 298 |
| 377 scoped_ptr<Painter> focus_painter_; | 299 // Whether the border is drawn. |
| 300 bool draw_border_; |
| 378 | 301 |
| 379 // Text color. Only used if |use_default_text_color_| is false. | 302 // Text color. Only used if |use_default_text_color_| is false. |
| 380 SkColor text_color_; | 303 SkColor text_color_; |
| 381 | 304 |
| 382 // Should we use the system text color instead of |text_color_|? | 305 // Should we use the system text color instead of |text_color_|? |
| 383 bool use_default_text_color_; | 306 bool use_default_text_color_; |
| 384 | 307 |
| 385 // Background color. Only used if |use_default_background_color_| is false. | 308 // Background color. Only used if |use_default_background_color_| is false. |
| 386 SkColor background_color_; | 309 SkColor background_color_; |
| 387 | 310 |
| 388 // Should we use the system background color instead of |background_color_|? | 311 // Should we use the system background color instead of |background_color_|? |
| 389 bool use_default_background_color_; | 312 bool use_default_background_color_; |
| 390 | 313 |
| 314 // Holds inner textfield margins. |
| 315 gfx::Insets margins_; |
| 316 |
| 317 // Holds whether margins were set. |
| 318 bool horizontal_margins_were_set_; |
| 319 bool vertical_margins_were_set_; |
| 320 |
| 391 // Text to display when empty. | 321 // Text to display when empty. |
| 392 base::string16 placeholder_text_; | 322 base::string16 placeholder_text_; |
| 393 | 323 |
| 394 // Placeholder text color. | 324 // Placeholder text color. |
| 395 SkColor placeholder_text_color_; | 325 SkColor placeholder_text_color_; |
| 396 | 326 |
| 397 // The accessible name of the text field. | 327 // The accessible name of the text field. |
| 398 base::string16 accessible_name_; | 328 base::string16 accessible_name_; |
| 399 | 329 |
| 400 // The input type of this text field. | 330 // The input type of this text field. |
| 401 ui::TextInputType text_input_type_; | 331 ui::TextInputType text_input_type_; |
| 402 | 332 |
| 403 // The duration to reveal the last typed char for obscured textfields. | 333 // The duration to reveal the last typed char for obscured textfields. |
| 404 base::TimeDelta obscured_reveal_duration_; | 334 base::TimeDelta obscured_reveal_duration_; |
| 405 | 335 |
| 406 // True if InputMethod::CancelComposition() should not be called. | |
| 407 bool skip_input_method_cancel_composition_; | |
| 408 | |
| 409 // The text editing cursor repaint timer and visibility. | |
| 410 base::RepeatingTimer<Textfield> cursor_repaint_timer_; | |
| 411 bool is_cursor_visible_; | |
| 412 | |
| 413 // The drop cursor is a visual cue for where dragged text will be dropped. | |
| 414 bool is_drop_cursor_visible_; | |
| 415 gfx::SelectionModel drop_cursor_position_; | |
| 416 | |
| 417 // Is the user potentially dragging and dropping from this view? | |
| 418 bool initiating_drag_; | |
| 419 | |
| 420 // State variables used to track double and triple clicks. | |
| 421 size_t aggregated_clicks_; | |
| 422 base::TimeDelta last_click_time_; | |
| 423 gfx::Point last_click_location_; | |
| 424 gfx::Range double_click_word_; | |
| 425 | |
| 426 scoped_ptr<ui::TouchSelectionController> touch_selection_controller_; | |
| 427 | |
| 428 // A timer to control the duration of showing the last typed char in | |
| 429 // obscured text. When the timer is running, the last typed char is shown | |
| 430 // and when the time expires, the last typed char is obscured. | |
| 431 base::OneShotTimer<Textfield> obscured_reveal_timer_; | |
| 432 | |
| 433 // Context menu related members. | |
| 434 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; | |
| 435 scoped_ptr<views::MenuRunner> context_menu_runner_; | |
| 436 | |
| 437 // Used to bind callback functions to this object. | 336 // Used to bind callback functions to this object. |
| 438 base::WeakPtrFactory<Textfield> weak_ptr_factory_; | 337 base::WeakPtrFactory<Textfield> weak_ptr_factory_; |
| 439 | 338 |
| 339 scoped_ptr<Painter> focus_painter_; |
| 340 |
| 440 DISALLOW_COPY_AND_ASSIGN(Textfield); | 341 DISALLOW_COPY_AND_ASSIGN(Textfield); |
| 441 }; | 342 }; |
| 442 | 343 |
| 443 } // namespace views | 344 } // namespace views |
| 444 | 345 |
| 445 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 346 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| OLD | NEW |