| Index: ui/views/controls/textfield/textfield.h
|
| diff --git a/ui/views/controls/textfield/textfield.h b/ui/views/controls/textfield/textfield.h
|
| index 90eaa984c0b426e58f6c7fe145eaa8e1080109cc..e5dd73f2c4df8962646007b4ff24d125acdfea3d 100644
|
| --- a/ui/views/controls/textfield/textfield.h
|
| +++ b/ui/views/controls/textfield/textfield.h
|
| @@ -12,39 +12,35 @@
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/strings/string16.h"
|
| -#include "base/time/time.h"
|
| -#include "build/build_config.h"
|
| +#include "base/timer/timer.h"
|
| #include "third_party/skia/include/core/SkColor.h"
|
| +#include "ui/base/ime/text_input_client.h"
|
| #include "ui/base/ime/text_input_type.h"
|
| +#include "ui/base/models/simple_menu_model.h"
|
| +#include "ui/base/touch/touch_editing_controller.h"
|
| #include "ui/events/keycodes/keyboard_codes.h"
|
| #include "ui/gfx/font_list.h"
|
| -#include "ui/gfx/native_widget_types.h"
|
| +#include "ui/gfx/range/range.h"
|
| #include "ui/gfx/selection_model.h"
|
| #include "ui/gfx/text_constants.h"
|
| +#include "ui/views/context_menu_controller.h"
|
| +#include "ui/views/controls/textfield/textfield_views_model.h"
|
| +#include "ui/views/drag_controller.h"
|
| #include "ui/views/view.h"
|
|
|
| -#if !defined(OS_LINUX)
|
| -#include "base/logging.h"
|
| -#endif
|
| -
|
| -namespace gfx {
|
| -class Range;
|
| -class ImageSkia;
|
| -}
|
| -
|
| -namespace ui {
|
| -class TextInputClient;
|
| -} // namespace ui
|
| -
|
| namespace views {
|
|
|
| -class ImageView;
|
| -class NativeTextfieldViews;
|
| +class MenuRunner;
|
| class Painter;
|
| class TextfieldController;
|
|
|
| -// This class implements a View that wraps a native text (edit) field.
|
| -class VIEWS_EXPORT Textfield : public View {
|
| +// A views/skia textfield implementation. No platform-specific code is used.
|
| +class VIEWS_EXPORT Textfield : public View,
|
| + public TextfieldViewsModel::Delegate,
|
| + public ContextMenuController,
|
| + public DragController,
|
| + public ui::TouchEditable,
|
| + public ui::TextInputClient {
|
| public:
|
| // The textfield's class name.
|
| static const char kViewClassName[];
|
| @@ -75,35 +71,23 @@ class VIEWS_EXPORT Textfield : public View {
|
| bool IsObscured() const;
|
| void SetObscured(bool obscured);
|
|
|
| - // Gets/sets the duration to reveal the last typed char when the obscured bit
|
| - // is set. A duration of zero effectively disables the feature. Other values
|
| - // cause the last typed char to be shown for the defined duration. Note this
|
| - // only works with NativeTextfieldViews.
|
| - const base::TimeDelta& obscured_reveal_duration() const {
|
| - return obscured_reveal_duration_;
|
| - }
|
| - void set_obscured_reveal_duration(const base::TimeDelta& duration) {
|
| - obscured_reveal_duration_ = duration;
|
| - }
|
| -
|
| - // Gets/Sets the input type of this textfield.
|
| - ui::TextInputType GetTextInputType() const;
|
| + // Sets the input type of this textfield.
|
| void SetTextInputType(ui::TextInputType type);
|
|
|
| - // Gets/Sets the text currently displayed in the Textfield.
|
| - const base::string16& text() const { return text_; }
|
| + // Gets the text currently displayed in the Textfield.
|
| + const base::string16& text() const { return model_->text(); }
|
|
|
| // Sets the text currently displayed in the Textfield. This doesn't
|
| // change the cursor position if the current cursor is within the
|
| // new text's range, or moves the cursor to the end if the cursor is
|
| // out of the new text's range.
|
| - void SetText(const base::string16& text);
|
| + void SetText(const base::string16& new_text);
|
|
|
| // Appends the given string to the previously-existing text in the field.
|
| - void AppendText(const base::string16& text);
|
| + void AppendText(const base::string16& new_text);
|
|
|
| - // Inserts |text| at the current cursor position, replacing any selected text.
|
| - void InsertOrReplaceText(const base::string16& text);
|
| + // Inserts |new_text| at the cursor position, replacing any selected text.
|
| + void InsertOrReplaceText(const base::string16& new_text);
|
|
|
| // Returns the text direction.
|
| base::i18n::TextDirection GetTextDirection() const;
|
| @@ -117,7 +101,7 @@ class VIEWS_EXPORT Textfield : public View {
|
| void SelectAll(bool reversed);
|
|
|
| // Clears the selection within the edit field and sets the caret to the end.
|
| - void ClearSelection() const;
|
| + void ClearSelection();
|
|
|
| // Checks if there is any selected text.
|
| bool HasSelection() const;
|
| @@ -142,29 +126,14 @@ class VIEWS_EXPORT Textfield : public View {
|
| void SetCursorEnabled(bool enabled);
|
|
|
| // Gets/Sets the fonts used when rendering the text within the Textfield.
|
| - const gfx::FontList& font_list() const { return font_list_; }
|
| + const gfx::FontList& GetFontList() const;
|
| void SetFontList(const gfx::FontList& font_list);
|
| - const gfx::Font& GetPrimaryFont() const;
|
| - void SetFont(const gfx::Font& font);
|
| -
|
| - // Sets the left and right margin (in pixels) within the text box. On Windows
|
| - // this is accomplished by packing the left and right margin into a single
|
| - // 32 bit number, so the left and right margins are effectively 16 bits.
|
| - void SetHorizontalMargins(int left, int right);
|
| -
|
| - // Sets the top and bottom margins (in pixels) within the textfield.
|
| - // NOTE: in most cases height could be changed instead.
|
| - void SetVerticalMargins(int top, int bottom);
|
|
|
| // Sets the default width of the text control. See default_width_in_chars_.
|
| void set_default_width_in_chars(int default_width) {
|
| default_width_in_chars_ = default_width;
|
| }
|
|
|
| - // Removes the border from the edit box, giving it a 2D look.
|
| - bool draw_border() const { return draw_border_; }
|
| - void RemoveBorder();
|
| -
|
| // Sets the text to display when empty.
|
| void set_placeholder_text(const base::string16& text) {
|
| placeholder_text_ = text;
|
| @@ -176,24 +145,6 @@ class VIEWS_EXPORT Textfield : public View {
|
| placeholder_text_color_ = color;
|
| }
|
|
|
| - // Getter for the horizontal margins that were set. Returns false if
|
| - // horizontal margins weren't set.
|
| - bool GetHorizontalMargins(int* left, int* right);
|
| -
|
| - // Getter for the vertical margins that were set. Returns false if vertical
|
| - // margins weren't set.
|
| - bool GetVerticalMargins(int* top, int* bottom);
|
| -
|
| - // Updates all properties on the textfield. This is invoked internally.
|
| - // Users of Textfield never need to invoke this directly.
|
| - void UpdateAllProperties();
|
| -
|
| - // Invoked by the edit control when the value changes. This method set
|
| - // the text_ member variable to the value contained in edit control.
|
| - // This is important because the edit control can be replaced if it has
|
| - // been deleted during a window close.
|
| - void SyncText();
|
| -
|
| // Returns whether or not an IME is composing text.
|
| bool IsIMEComposing() const;
|
|
|
| @@ -234,61 +185,188 @@ class VIEWS_EXPORT Textfield : public View {
|
|
|
| void SetFocusPainter(scoped_ptr<Painter> focus_painter);
|
|
|
| - // Provided only for testing:
|
| - NativeTextfieldViews* GetTextfieldViewForTesting() const {
|
| - return textfield_view_;
|
| - }
|
| -
|
| // Returns whether there is a drag operation originating from the textfield.
|
| bool HasTextBeingDragged();
|
|
|
| - // Overridden from View:
|
| - virtual void Layout() OVERRIDE;
|
| + // View overrides:
|
| + // TODO(msw): Match declaration and definition order to View.
|
| virtual int GetBaseline() const OVERRIDE;
|
| virtual gfx::Size GetPreferredSize() OVERRIDE;
|
| virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
|
| virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE;
|
| virtual void OnEnabledChanged() OVERRIDE;
|
| virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
|
| - virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE;
|
| - virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE;
|
| - virtual bool OnMouseDragged(const ui::MouseEvent& e) OVERRIDE;
|
| + virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
|
| + virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
|
| + virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
|
| + virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
|
| virtual void OnFocus() OVERRIDE;
|
| virtual void OnBlur() OVERRIDE;
|
| virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
|
| virtual ui::TextInputClient* GetTextInputClient() OVERRIDE;
|
| virtual gfx::Point GetKeyboardContextMenuLocation() OVERRIDE;
|
| -
|
| - protected:
|
| - virtual void ViewHierarchyChanged(
|
| - const ViewHierarchyChangedDetails& details) OVERRIDE;
|
| + virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
|
| virtual const char* GetClassName() const OVERRIDE;
|
| + virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE;
|
| + virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
|
| + virtual bool GetDropFormats(
|
| + int* formats,
|
| + std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
|
| + virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
|
| + virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
|
| + virtual void OnDragExited() OVERRIDE;
|
| + virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
|
| + virtual void OnDragDone() OVERRIDE;
|
| + virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
|
| +
|
| + // TextfieldViewsModel::Delegate overrides:
|
| + virtual void OnCompositionTextConfirmedOrCleared() OVERRIDE;
|
| +
|
| + // ContextMenuController overrides:
|
| + virtual void ShowContextMenuForView(View* source,
|
| + const gfx::Point& point,
|
| + ui::MenuSourceType source_type) OVERRIDE;
|
| +
|
| + // DragController overrides:
|
| + virtual void WriteDragDataForView(View* sender,
|
| + const gfx::Point& press_pt,
|
| + ui::OSExchangeData* data) OVERRIDE;
|
| + virtual int GetDragOperationsForView(View* sender,
|
| + const gfx::Point& p) OVERRIDE;
|
| + virtual bool CanStartDragForView(View* sender,
|
| + const gfx::Point& press_pt,
|
| + const gfx::Point& p) OVERRIDE;
|
| +
|
| + // ui::TouchEditable overrides:
|
| + virtual void SelectRect(const gfx::Point& start,
|
| + const gfx::Point& end) OVERRIDE;
|
| + virtual void MoveCaretTo(const gfx::Point& point) OVERRIDE;
|
| + virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) OVERRIDE;
|
| + virtual gfx::Rect GetBounds() OVERRIDE;
|
| + virtual gfx::NativeView GetNativeView() const OVERRIDE;
|
| + virtual void ConvertPointToScreen(gfx::Point* point) OVERRIDE;
|
| + virtual void ConvertPointFromScreen(gfx::Point* point) OVERRIDE;
|
| + virtual bool DrawsHandles() OVERRIDE;
|
| + virtual void OpenContextMenu(const gfx::Point& anchor) OVERRIDE;
|
| +
|
| + // ui::SimpleMenuModel::Delegate overrides:
|
| + virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
|
| + virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
|
| + virtual bool GetAcceleratorForCommandId(
|
| + int command_id,
|
| + ui::Accelerator* accelerator) OVERRIDE;
|
| + virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
|
| +
|
| + // ui::TextInputClient overrides:
|
| + virtual void SetCompositionText(
|
| + const ui::CompositionText& composition) OVERRIDE;
|
| + virtual void ConfirmCompositionText() OVERRIDE;
|
| + virtual void ClearCompositionText() OVERRIDE;
|
| + virtual void InsertText(const base::string16& text) OVERRIDE;
|
| + virtual void InsertChar(base::char16 ch, int flags) OVERRIDE;
|
| + virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE;
|
| + virtual ui::TextInputType GetTextInputType() const OVERRIDE;
|
| + virtual ui::TextInputMode GetTextInputMode() const OVERRIDE;
|
| + virtual bool CanComposeInline() const OVERRIDE;
|
| + virtual gfx::Rect GetCaretBounds() const OVERRIDE;
|
| + virtual bool GetCompositionCharacterBounds(uint32 index,
|
| + gfx::Rect* rect) const OVERRIDE;
|
| + virtual bool HasCompositionText() const OVERRIDE;
|
| + virtual bool GetTextRange(gfx::Range* range) const OVERRIDE;
|
| + virtual bool GetCompositionTextRange(gfx::Range* range) const OVERRIDE;
|
| + virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE;
|
| + virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE;
|
| + virtual bool DeleteRange(const gfx::Range& range) OVERRIDE;
|
| + virtual bool GetTextFromRange(const gfx::Range& range,
|
| + base::string16* text) const OVERRIDE;
|
| + virtual void OnInputMethodChanged() OVERRIDE;
|
| + virtual bool ChangeTextDirectionAndLayoutAlignment(
|
| + base::i18n::TextDirection direction) OVERRIDE;
|
| + virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE;
|
| + virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE;
|
| + virtual void OnCandidateWindowShown() OVERRIDE;
|
| + virtual void OnCandidateWindowUpdated() OVERRIDE;
|
| + virtual void OnCandidateWindowHidden() OVERRIDE;
|
|
|
| - // The object that actually implements the native textfield view.
|
| - // TODO(msw): Merge views::NativeTextfieldViews and views::Textfield classes.
|
| - NativeTextfieldViews* textfield_view_;
|
| + protected:
|
| + // Returns the TextfieldViewsModel's text/cursor/selection rendering model.
|
| + gfx::RenderText* GetRenderText() const;
|
|
|
| private:
|
| - // Returns the insets to the rectangle where text is actually painted.
|
| - gfx::Insets GetTextInsets() const;
|
| + friend class TextfieldTest;
|
| + friend class TouchSelectionControllerImplTest;
|
| +
|
| + // Converts the raw text according to the current style, e.g. STYLE_LOWERCASE.
|
| + base::string16 GetTextForDisplay(const base::string16& raw);
|
|
|
| // Handles a request to change the value of this text field from software
|
| // using an accessibility API (typically automation software, screen readers
|
| // don't normally use this). Sets the value and clears the selection.
|
| void AccessibilitySetValue(const base::string16& new_value);
|
|
|
| + // Updates the painted background color.
|
| + void UpdateBackgroundColor();
|
| +
|
| + // Updates any colors that have not been explicitly set from the theme.
|
| + void UpdateColorsFromTheme(const ui::NativeTheme* theme);
|
| +
|
| + // Does necessary updates when the text and/or cursor position changes.
|
| + void UpdateAfterChange(bool text_changed, bool cursor_changed);
|
| +
|
| + // A callback function to periodically update the cursor state.
|
| + void UpdateCursor();
|
| +
|
| + // Repaint the cursor.
|
| + void RepaintCursor();
|
| +
|
| + void PaintTextAndCursor(gfx::Canvas* canvas);
|
| +
|
| + // Helper function to call MoveCursorTo on the TextfieldViewsModel.
|
| + bool MoveCursorTo(const gfx::Point& point, bool select);
|
| +
|
| + // Convenience method to call InputMethod::OnCaretBoundsChanged();
|
| + void OnCaretBoundsChanged();
|
| +
|
| + // Convenience method to call TextfieldController::OnBeforeUserAction();
|
| + void OnBeforeUserAction();
|
| +
|
| + // Convenience method to call TextfieldController::OnAfterUserAction();
|
| + void OnAfterUserAction();
|
| +
|
| + // Calls |model_->Cut()| and notifies TextfieldController on success.
|
| + bool Cut();
|
| +
|
| + // Calls |model_->Copy()| and notifies TextfieldController on success.
|
| + bool Copy();
|
| +
|
| + // Calls |model_->Paste()| and calls TextfieldController::ContentsChanged()
|
| + // explicitly if paste succeeded.
|
| + bool Paste();
|
| +
|
| + // Utility function to prepare the context menu.
|
| + void UpdateContextMenu();
|
| +
|
| + // Tracks the mouse clicks for single/double/triple clicks.
|
| + void TrackMouseClicks(const ui::MouseEvent& event);
|
| +
|
| + // Returns true if the current text input type allows access by the IME.
|
| + bool ImeEditingAllowed() const;
|
| +
|
| + // Reveals the obscured char at |index| for the given |duration|. If |index|
|
| + // is -1, existing revealed index will be cleared.
|
| + void RevealObscuredChar(int index, const base::TimeDelta& duration);
|
| +
|
| + void CreateTouchSelectionControllerAndNotifyIt();
|
| +
|
| + // The text model.
|
| + scoped_ptr<TextfieldViewsModel> model_;
|
| +
|
| // This is the current listener for events from this Textfield.
|
| TextfieldController* controller_;
|
|
|
| // The mask of style options for this Textfield.
|
| StyleFlags style_;
|
|
|
| - // The fonts used to render the text in the Textfield.
|
| - gfx::FontList font_list_;
|
| -
|
| - // The text displayed in the Textfield.
|
| - base::string16 text_;
|
| -
|
| // True if this Textfield cannot accept input and is read-only.
|
| bool read_only_;
|
|
|
| @@ -296,8 +374,7 @@ class VIEWS_EXPORT Textfield : public View {
|
| // This will be reported as the "desired size". Defaults to 0.
|
| int default_width_in_chars_;
|
|
|
| - // Whether the border is drawn.
|
| - bool draw_border_;
|
| + scoped_ptr<Painter> focus_painter_;
|
|
|
| // Text color. Only used if |use_default_text_color_| is false.
|
| SkColor text_color_;
|
| @@ -311,13 +388,6 @@ class VIEWS_EXPORT Textfield : public View {
|
| // Should we use the system background color instead of |background_color_|?
|
| bool use_default_background_color_;
|
|
|
| - // Holds inner textfield margins.
|
| - gfx::Insets margins_;
|
| -
|
| - // Holds whether margins were set.
|
| - bool horizontal_margins_were_set_;
|
| - bool vertical_margins_were_set_;
|
| -
|
| // Text to display when empty.
|
| base::string16 placeholder_text_;
|
|
|
| @@ -333,11 +403,40 @@ class VIEWS_EXPORT Textfield : public View {
|
| // The duration to reveal the last typed char for obscured textfields.
|
| base::TimeDelta obscured_reveal_duration_;
|
|
|
| + // True if InputMethod::CancelComposition() should not be called.
|
| + bool skip_input_method_cancel_composition_;
|
| +
|
| + // The text editing cursor repaint timer and visibility.
|
| + base::RepeatingTimer<Textfield> cursor_repaint_timer_;
|
| + bool is_cursor_visible_;
|
| +
|
| + // The drop cursor is a visual cue for where dragged text will be dropped.
|
| + bool is_drop_cursor_visible_;
|
| + gfx::SelectionModel drop_cursor_position_;
|
| +
|
| + // Is the user potentially dragging and dropping from this view?
|
| + bool initiating_drag_;
|
| +
|
| + // State variables used to track double and triple clicks.
|
| + size_t aggregated_clicks_;
|
| + base::TimeDelta last_click_time_;
|
| + gfx::Point last_click_location_;
|
| + gfx::Range double_click_word_;
|
| +
|
| + scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
|
| +
|
| + // A timer to control the duration of showing the last typed char in
|
| + // obscured text. When the timer is running, the last typed char is shown
|
| + // and when the time expires, the last typed char is obscured.
|
| + base::OneShotTimer<Textfield> obscured_reveal_timer_;
|
| +
|
| + // Context menu related members.
|
| + scoped_ptr<ui::SimpleMenuModel> context_menu_contents_;
|
| + scoped_ptr<views::MenuRunner> context_menu_runner_;
|
| +
|
| // Used to bind callback functions to this object.
|
| base::WeakPtrFactory<Textfield> weak_ptr_factory_;
|
|
|
| - scoped_ptr<Painter> focus_painter_;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(Textfield);
|
| };
|
|
|
|
|