diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-19 03:38:44 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-19 03:38:44 +0000 |
commit | d401e2da59d2faa5d286d214fdc6b692f39e5661 (patch) | |
tree | ff58266d2245088fc15ff02237ffee678605b91f /ui | |
parent | b6cb588fd2f2ec1e19e0614e3d0ddb5a176c6afe (diff) | |
download | chromium_src-d401e2da59d2faa5d286d214fdc6b692f39e5661.zip chromium_src-d401e2da59d2faa5d286d214fdc6b692f39e5661.tar.gz chromium_src-d401e2da59d2faa5d286d214fdc6b692f39e5661.tar.bz2 |
Remove views::NativeTextfieldWrapper, start class cleanup.
A first step towards combining views::Textfield and views::NativeTextfieldViews.
Remove NativeTextfieldWrapper, use NativeTextfieldViews directly.
Remove, inline, and simplify some minimal functionality.
Cleanup some related code/comments/tests.
BUG=131660
TEST=No build breaks, no behavior changes, no regressions.
R=sky@chromium.org
Review URL: https://codereview.chromium.org/105713004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241783 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/controls/textfield/native_textfield_views.cc | 34 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_views.h | 186 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_views_unittest.cc | 3 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_wrapper.h | 188 | ||||
-rw-r--r-- | ui/views/controls/textfield/textfield.cc | 208 | ||||
-rw-r--r-- | ui/views/controls/textfield/textfield.h | 42 | ||||
-rw-r--r-- | ui/views/focus/focus_manager_unittest.cc | 22 | ||||
-rw-r--r-- | ui/views/touchui/touch_selection_controller_impl_unittest.cc | 3 | ||||
-rw-r--r-- | ui/views/view_unittest.cc | 10 | ||||
-rw-r--r-- | ui/views/views.gyp | 1 |
10 files changed, 239 insertions, 458 deletions
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc index 7e78dc5..a69a54b 100644 --- a/ui/views/controls/textfield/native_textfield_views.cc +++ b/ui/views/controls/textfield/native_textfield_views.cc @@ -24,6 +24,7 @@ #include "ui/compositor/layer.h" #include "ui/events/event.h" #include "ui/gfx/canvas.h" +#include "ui/gfx/font_list.h" #include "ui/gfx/insets.h" #include "ui/gfx/range/range.h" #include "ui/gfx/render_text.h" @@ -252,6 +253,10 @@ bool NativeTextfieldViews::OnKeyReleased(const ui::KeyEvent& event) { return false; } +ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() { + return textfield_->read_only() ? NULL : this; +} + bool NativeTextfieldViews::GetDropFormats( int* formats, std::set<OSExchangeData::CustomFormat>* custom_formats) { @@ -587,10 +592,6 @@ void NativeTextfieldViews::UpdateEnabled() { OnTextInputTypeChanged(); } -gfx::Insets NativeTextfieldViews::CalculateInsets() { - return GetInsets(); -} - void NativeTextfieldViews::UpdateHorizontalMargins() { int left, right; if (!textfield_->GetHorizontalMargins(&left, &right)) @@ -609,24 +610,11 @@ void NativeTextfieldViews::UpdateVerticalMargins() { OnBoundsChanged(GetBounds()); } -bool NativeTextfieldViews::SetFocus() { - return false; -} - -View* NativeTextfieldViews::GetView() { - return this; -} - -gfx::NativeView NativeTextfieldViews::GetTestingHandle() const { - NOTREACHED(); - return NULL; -} - bool NativeTextfieldViews::IsIMEComposing() const { return model_->HasCompositionText(); } -gfx::Range NativeTextfieldViews::GetSelectedRange() const { +const gfx::Range& NativeTextfieldViews::GetSelectedRange() const { return GetRenderText()->selection(); } @@ -638,7 +626,7 @@ void NativeTextfieldViews::SelectRange(const gfx::Range& range) { ui::AccessibilityTypes::EVENT_SELECTION_CHANGED, true); } -gfx::SelectionModel NativeTextfieldViews::GetSelectionModel() const { +const gfx::SelectionModel& NativeTextfieldViews::GetSelectionModel() const { return GetRenderText()->selection_model(); } @@ -704,10 +692,6 @@ void NativeTextfieldViews::HandleBlur() { touch_selection_controller_.reset(); } -ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() { - return textfield_->read_only() ? NULL : this; -} - void NativeTextfieldViews::ClearEditHistory() { model_->ClearEditHistory(); } @@ -724,10 +708,6 @@ int NativeTextfieldViews::GetWidthNeededForText() const { return GetRenderText()->GetContentWidth() + GetInsets().width(); } -void NativeTextfieldViews::ExecuteTextCommand(int command_id) { - ExecuteCommand(command_id, 0); -} - bool NativeTextfieldViews::HasTextBeingDragged() { return initiating_drag_; } diff --git a/ui/views/controls/textfield/native_textfield_views.h b/ui/views/controls/textfield/native_textfield_views.h index a922ea1..e154de2 100644 --- a/ui/views/controls/textfield/native_textfield_views.h +++ b/ui/views/controls/textfield/native_textfield_views.h @@ -12,10 +12,9 @@ #include "ui/base/models/simple_menu_model.h" #include "ui/base/touch/touch_editing_controller.h" #include "ui/events/event_constants.h" -#include "ui/gfx/font.h" +#include "ui/gfx/selection_model.h" #include "ui/views/border.h" #include "ui/views/context_menu_controller.h" -#include "ui/views/controls/textfield/native_textfield_wrapper.h" #include "ui/views/controls/textfield/textfield_views_model.h" #include "ui/views/drag_controller.h" #include "ui/views/view.h" @@ -33,20 +32,14 @@ namespace views { class FocusableBorder; class MenuModelAdapter; class MenuRunner; +class Textfield; -// A views/skia only implementation of NativeTextfieldWrapper. -// No platform specific code is used. -// Following features are not yet supported. -// * BIDI/Complex script. -// * Support surrogate pair, or maybe we should just use UTF32 internally. -// * X selection (only if we want to support). -// Once completed, this will replace Textfield, NativeTextfieldWin and -// NativeTextfieldGtk. +// A views/skia textfield implementation. No platform-specific code is used. +// TODO(msw): Merge views::NativeTextfieldViews and views::Textfield classes. class VIEWS_EXPORT NativeTextfieldViews : public View, public ui::TouchEditable, public ContextMenuController, public DragController, - public NativeTextfieldWrapper, public ui::TextInputClient, public TextfieldViewsModel::Delegate { public: @@ -69,6 +62,7 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; virtual void OnDragDone() OVERRIDE; virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; + virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnFocus() OVERRIDE; virtual void OnBlur() OVERRIDE; @@ -101,54 +95,114 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, const gfx::Point& press_pt, const gfx::Point& p) OVERRIDE; - // NativeTextfieldWrapper overrides: - virtual base::string16 GetText() const OVERRIDE; - virtual void UpdateText() OVERRIDE; - virtual void AppendText(const base::string16& text) OVERRIDE; - virtual void InsertOrReplaceText(const base::string16& text) OVERRIDE; - virtual base::i18n::TextDirection GetTextDirection() const OVERRIDE; - virtual base::string16 GetSelectedText() const OVERRIDE; - virtual void SelectAll(bool reversed) OVERRIDE; - virtual void ClearSelection() OVERRIDE; - virtual void UpdateBorder() OVERRIDE; - virtual void UpdateTextColor() OVERRIDE; - virtual void UpdateBackgroundColor() OVERRIDE; - virtual void UpdateReadOnly() OVERRIDE; - virtual void UpdateFont() OVERRIDE; - virtual void UpdateIsObscured() OVERRIDE; - virtual void UpdateEnabled() OVERRIDE; - virtual gfx::Insets CalculateInsets() OVERRIDE; - virtual void UpdateHorizontalMargins() OVERRIDE; - virtual void UpdateVerticalMargins() OVERRIDE; - virtual bool SetFocus() OVERRIDE; - virtual View* GetView() OVERRIDE; - virtual gfx::NativeView GetTestingHandle() const OVERRIDE; - virtual bool IsIMEComposing() const OVERRIDE; - virtual gfx::Range GetSelectedRange() const OVERRIDE; - virtual void SelectRange(const gfx::Range& range) OVERRIDE; - virtual gfx::SelectionModel GetSelectionModel() const OVERRIDE; - virtual void SelectSelectionModel(const gfx::SelectionModel& sel) OVERRIDE; - virtual size_t GetCursorPosition() const OVERRIDE; - virtual bool GetCursorEnabled() const OVERRIDE; - virtual void SetCursorEnabled(bool enabled) OVERRIDE; - virtual bool HandleKeyPressed(const ui::KeyEvent& e) OVERRIDE; - virtual bool HandleKeyReleased(const ui::KeyEvent& e) OVERRIDE; - virtual void HandleFocus() OVERRIDE; - virtual void HandleBlur() OVERRIDE; - virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; - virtual void SetColor(SkColor value) OVERRIDE; - virtual void ApplyColor(SkColor value, const gfx::Range& range) OVERRIDE; - virtual void SetStyle(gfx::TextStyle style, bool value) OVERRIDE; - virtual void ApplyStyle(gfx::TextStyle style, - bool value, - const gfx::Range& range) OVERRIDE; - virtual void ClearEditHistory() OVERRIDE; - virtual int GetFontHeight() OVERRIDE; - virtual int GetTextfieldBaseline() const OVERRIDE; - virtual int GetWidthNeededForText() const OVERRIDE; - virtual void ExecuteTextCommand(int command_id) OVERRIDE; - virtual bool HasTextBeingDragged() OVERRIDE; - virtual gfx::Point GetContextMenuLocation() OVERRIDE; + // Gets the currently displayed text. + base::string16 GetText() const; + + // Updates the text displayed to the text held by the parent Textfield. + void UpdateText(); + + // Adds the specified text to the text already displayed. + void AppendText(const base::string16& text); + + // Inserts |text| at the current cursor position, replacing any selected text. + void InsertOrReplaceText(const base::string16& text); + + // Returns the text direction. + base::i18n::TextDirection GetTextDirection() const; + + // Returns the currently selected text. + base::string16 GetSelectedText() const; + + // Select the entire text range. If |reversed| is true, the range will end at + // the logical beginning of the text; this generally shows the leading portion + // of text that overflows its display area. + void SelectAll(bool reversed); + + // Clears the selection within the textfield and sets the caret to the end. + void ClearSelection(); + + // Updates whether there is a visible border. + void UpdateBorder(); + + // Updates the painted text color. + void UpdateTextColor(); + + // Updates the painted background color. + void UpdateBackgroundColor(); + + // Updates the read-only state. + void UpdateReadOnly(); + + // Updates the font used to render the text. + void UpdateFont(); + + // Updates the obscured state of the text for passwords, etc. + void UpdateIsObscured(); + + // Updates the enabled state. + void UpdateEnabled(); + + // Updates the horizontal and vertical margins. + void UpdateHorizontalMargins(); + void UpdateVerticalMargins(); + + // Returns whether or not an IME is composing text. + bool IsIMEComposing() const; + + // Gets the selected logical text range. + const gfx::Range& GetSelectedRange() const; + + // Selects the specified logical text range. + void SelectRange(const gfx::Range& range); + + // Gets the text selection model. + const gfx::SelectionModel& GetSelectionModel() const; + + // Sets the specified text selection model. + void SelectSelectionModel(const gfx::SelectionModel& sel); + + // Returns the current cursor position. + size_t GetCursorPosition() const; + + // Get or set whether or not the cursor is enabled. + bool GetCursorEnabled() const; + void SetCursorEnabled(bool enabled); + + // Invoked when the parent views::Textfield receives key events. + // returns true if the event was processed. + bool HandleKeyPressed(const ui::KeyEvent& e); + bool HandleKeyReleased(const ui::KeyEvent& e); + + // Invoked when the parent views:Textfield gains or loses focus. + void HandleFocus(); + void HandleBlur(); + + // Set the text colors; see views::Textfield for details. + void SetColor(SkColor value); + void ApplyColor(SkColor value, const gfx::Range& range); + + // Set the text styles; see the corresponding Textfield functions for details. + void SetStyle(gfx::TextStyle style, bool value); + void ApplyStyle(gfx::TextStyle style, bool value, const gfx::Range& range); + + // Clears the Edit history. + void ClearEditHistory(); + + // Get the height in pixels of the fonts used. + int GetFontHeight(); + + // Returns the text baseline; this value does not include any insets. + int GetTextfieldBaseline() const; + + // Returns the width necessary to display the current text, including any + // necessary space for the cursor or border/margin. + int GetWidthNeededForText() const; + + // Returns whether this view is the origin of an ongoing drag operation. + bool HasTextBeingDragged(); + + // Returns the location for keyboard-triggered context menus. + gfx::Point GetContextMenuLocation(); // ui::SimpleMenuModel::Delegate overrides virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; @@ -208,8 +262,7 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, // Returns the TextfieldViewsModel's text/cursor/selection rendering model. gfx::RenderText* GetRenderText() const; - // Converts |text| according to textfield style, e.g. lower case if - // |textfield_| has STYLE_LOWERCASE style. + // Converts |text| according to the current style, e.g. STYLE_LOWERCASE. base::string16 GetTextForDisplay(const base::string16& text); // Updates any colors that have not been explicitly set from the theme. @@ -232,12 +285,11 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, // Helper function to call MoveCursorTo on the TextfieldViewsModel. bool MoveCursorTo(const gfx::Point& point, bool select); - // Utility function to inform the parent textfield (and its controller if any) + // Utility function to inform the parent views::Textfield (and any controller) // that the text in the textfield has changed. void PropagateTextChange(); - // Does necessary updates when the text and/or the position of the cursor - // changed. + // Does necessary updates when the text and/or cursor position changes. void UpdateAfterChange(bool text_changed, bool cursor_changed); // Utility function to prepare the context menu. @@ -291,7 +343,7 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, // is -1, existing revealed index will be cleared. void RevealObscuredChar(int index, const base::TimeDelta& duration); - // The parent textfield, the owner of this object. + // The parent views::Textfield, the owner of this object. Textfield* textfield_; // The text model. @@ -302,7 +354,7 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, // Textfield has explicitly-set margins. FocusableBorder* text_border_; - // The textfield's text and drop cursor visibility. + // The text editing cursor visibility. bool is_cursor_visible_; // The drop cursor is a visual cue for where dragged text will be dropped. @@ -325,7 +377,7 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, gfx::Point last_click_location_; gfx::Range double_click_word_; - // Context menu and its content list for the textfield. + // Context menu related members. scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; scoped_ptr<views::MenuModelAdapter> context_menu_delegate_; scoped_ptr<views::MenuRunner> context_menu_runner_; diff --git a/ui/views/controls/textfield/native_textfield_views_unittest.cc b/ui/views/controls/textfield/native_textfield_views_unittest.cc index e219383..aa926a7 100644 --- a/ui/views/controls/textfield/native_textfield_views_unittest.cc +++ b/ui/views/controls/textfield/native_textfield_views_unittest.cc @@ -179,8 +179,7 @@ class NativeTextfieldViewsTest : public ViewsTestBase, widget_->SetContentsView(container); container->AddChildView(textfield_); - textfield_view_ = static_cast<NativeTextfieldViews*>( - textfield_->GetNativeWrapperForTesting()); + textfield_view_ = textfield_->GetTextfieldViewForTesting(); DCHECK(textfield_view_); textfield_view_->SetBoundsRect(params.bounds); textfield_->set_id(1); diff --git a/ui/views/controls/textfield/native_textfield_wrapper.h b/ui/views/controls/textfield/native_textfield_wrapper.h deleted file mode 100644 index 6bd7219..0000000 --- a/ui/views/controls/textfield/native_textfield_wrapper.h +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_ -#define UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_ - -#include "base/i18n/rtl.h" -#include "base/strings/string16.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/views_export.h" - -namespace gfx { -class Insets; -class Point; -} // namespace gfx - -namespace ui { -class KeyEvent; -class TextInputClient; -} // namespace ui - -namespace views { - -class Textfield; -class View; - -// An interface implemented by an object that provides a platform-native -// text field. -class VIEWS_EXPORT NativeTextfieldWrapper { - public: - // The Textfield calls this when it is destroyed to clean up the wrapper - // object. - virtual ~NativeTextfieldWrapper() {} - - // Gets the text displayed in the wrapped native text field. - virtual base::string16 GetText() const = 0; - - // Updates the text displayed with the text held by the Textfield. - virtual void UpdateText() = 0; - - // Adds the specified text to the text already displayed by the wrapped native - // text field. - virtual void AppendText(const base::string16& text) = 0; - - // Inserts |text| at the current cursor position, replacing any selected text. - virtual void InsertOrReplaceText(const base::string16& text) = 0; - - // Returns the text direction. - virtual base::i18n::TextDirection GetTextDirection() const = 0; - - // Gets the text that is selected in the wrapped native text field. - virtual base::string16 GetSelectedText() const = 0; - - // Select the entire text range. If |reversed| is true, the range will end at - // the logical beginning of the text; this generally shows the leading portion - // of text that overflows its display area. - virtual void SelectAll(bool reversed) = 0; - - // Clears the selection within the edit field and sets the caret to the end. - virtual void ClearSelection() = 0; - - // Updates whether there is a visible border. - virtual void UpdateBorder() = 0; - - // Updates the text color used when painting the native text field. - virtual void UpdateTextColor() = 0; - - // Updates the background color used when painting the native text field. - virtual void UpdateBackgroundColor() = 0; - - // Updates the read-only state of the native text field. - virtual void UpdateReadOnly() = 0; - - // Updates the font used to render text in the native text field. - virtual void UpdateFont() = 0; - - // Updates the visibility of the text in the native text field. - virtual void UpdateIsObscured() = 0; - - // Updates the enabled state of the native text field. - virtual void UpdateEnabled() = 0; - - // Returns the insets for the text field. - virtual gfx::Insets CalculateInsets() = 0; - - // Updates the horizontal margins for the native text field. - virtual void UpdateHorizontalMargins() = 0; - - // Updates the vertical margins for the native text field. - virtual void UpdateVerticalMargins() = 0; - - // Sets the focus to the text field. Returns false if the wrapper - // didn't take focus. - virtual bool SetFocus() = 0; - - // Retrieves the views::View that hosts the native control. - virtual View* GetView() = 0; - - // Returns a handle to the underlying native view for testing. - virtual gfx::NativeView GetTestingHandle() const = 0; - - // Returns whether or not an IME is composing text. - virtual bool IsIMEComposing() const = 0; - - // Gets the selected range. - virtual gfx::Range GetSelectedRange() const = 0; - - // Selects the text given by |range|. - virtual void SelectRange(const gfx::Range& range) = 0; - - // Gets the selection model. - virtual gfx::SelectionModel GetSelectionModel() const = 0; - - // Selects the text given by |sel|. - virtual void SelectSelectionModel(const gfx::SelectionModel& sel) = 0; - - // Returns the currnet cursor position. - virtual size_t GetCursorPosition() const = 0; - - // Get or set whether or not the cursor is enabled. - virtual bool GetCursorEnabled() const = 0; - virtual void SetCursorEnabled(bool enabled) = 0; - - // Following methods are to forward key/focus related events to the - // views wrapper so that TextfieldViews can handle key inputs without - // having focus. - - // Invoked when a key is pressed/release on Textfield. Subclasser - // should return true if the event has been processed and false - // otherwise. - // See also View::OnKeyPressed/OnKeyReleased. - virtual bool HandleKeyPressed(const ui::KeyEvent& e) = 0; - virtual bool HandleKeyReleased(const ui::KeyEvent& e) = 0; - - // Invoked when focus is being moved from or to the Textfield. - // See also View::OnFocus/OnBlur. - virtual void HandleFocus() = 0; - virtual void HandleBlur() = 0; - - // Returns the View's TextInputClient instance or NULL if the View doesn't - // support text input. - virtual ui::TextInputClient* GetTextInputClient() = 0; - - // Set the text colors; see the corresponding Textfield functions for details. - virtual void SetColor(SkColor value) = 0; - virtual void ApplyColor(SkColor value, const gfx::Range& range) = 0; - - // Set the text styles; see the corresponding Textfield functions for details. - virtual void SetStyle(gfx::TextStyle style, bool value) = 0; - virtual void ApplyStyle(gfx::TextStyle style, - bool value, - const gfx::Range& range) = 0; - - // Clears Edit history. - virtual void ClearEditHistory() = 0; - - // Get the height in pixels of the first font used in this textfield. - virtual int GetFontHeight() = 0; - - // Returns the baseline of the textfield. This should not take into account - // any insets. - virtual int GetTextfieldBaseline() const = 0; - - // Returns the width necessary to display the current text, including any - // necessary space for the cursor or border/margin. - virtual int GetWidthNeededForText() const = 0; - - // Performs the action associated with the specified command id. Not called - // ExecuteCommand to avoid name clash. - virtual void ExecuteTextCommand(int command_id) = 0; - - // Returns whether there is a drag operation originating from the textfield. - virtual bool HasTextBeingDragged() = 0; - - // Returns the location for keyboard-triggered context menus. - virtual gfx::Point GetContextMenuLocation() = 0; - - // Creates an appropriate NativeTextfieldWrapper for the platform. - static NativeTextfieldWrapper* CreateWrapper(Textfield* field); -}; - -} // namespace views - -#endif // UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_ diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc index fa41ce1..69adbb7 100644 --- a/ui/views/controls/textfield/textfield.cc +++ b/ui/views/controls/textfield/textfield.cc @@ -21,7 +21,6 @@ #include "ui/native_theme/native_theme.h" #include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/textfield/native_textfield_views.h" -#include "ui/views/controls/textfield/native_textfield_wrapper.h" #include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/painter.h" #include "ui/views/views_delegate.h" @@ -56,7 +55,7 @@ size_t Textfield::GetCaretBlinkMs() { } Textfield::Textfield() - : native_wrapper_(NULL), + : textfield_view_(NULL), controller_(NULL), style_(STYLE_DEFAULT), font_list_(GetDefaultFontList()), @@ -84,7 +83,7 @@ Textfield::Textfield() } Textfield::Textfield(StyleFlags style) - : native_wrapper_(NULL), + : textfield_view_(NULL), controller_(NULL), style_(style), font_list_(GetDefaultFontList()), @@ -127,10 +126,10 @@ TextfieldController* Textfield::GetController() const { void Textfield::SetReadOnly(bool read_only) { // Update read-only without changing the focusable state (or active, etc.). read_only_ = read_only; - if (native_wrapper_) { - native_wrapper_->UpdateReadOnly(); - native_wrapper_->UpdateTextColor(); - native_wrapper_->UpdateBackgroundColor(); + if (textfield_view_) { + textfield_view_->UpdateReadOnly(); + textfield_view_->UpdateTextColor(); + textfield_view_->UpdateBackgroundColor(); } } @@ -146,8 +145,8 @@ void Textfield::SetObscured(bool obscured) { style_ = static_cast<StyleFlags>(style_ & ~STYLE_OBSCURED); SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); } - if (native_wrapper_) - native_wrapper_->UpdateIsObscured(); + if (textfield_view_) + textfield_view_->UpdateIsObscured(); } ui::TextInputType Textfield::GetTextInputType() const { @@ -165,45 +164,45 @@ void Textfield::SetTextInputType(ui::TextInputType type) { void Textfield::SetText(const base::string16& text) { text_ = text; - if (native_wrapper_) - native_wrapper_->UpdateText(); + if (textfield_view_) + textfield_view_->UpdateText(); } void Textfield::AppendText(const base::string16& text) { text_ += text; - if (native_wrapper_) - native_wrapper_->AppendText(text); + if (textfield_view_) + textfield_view_->AppendText(text); } void Textfield::InsertOrReplaceText(const base::string16& text) { - if (native_wrapper_) { - native_wrapper_->InsertOrReplaceText(text); - text_ = native_wrapper_->GetText(); + if (textfield_view_) { + textfield_view_->InsertOrReplaceText(text); + text_ = textfield_view_->GetText(); } } base::i18n::TextDirection Textfield::GetTextDirection() const { - return native_wrapper_ ? - native_wrapper_->GetTextDirection() : base::i18n::UNKNOWN_DIRECTION; + return textfield_view_ ? + textfield_view_->GetTextDirection() : base::i18n::UNKNOWN_DIRECTION; } void Textfield::SelectAll(bool reversed) { - if (native_wrapper_) - native_wrapper_->SelectAll(reversed); + if (textfield_view_) + textfield_view_->SelectAll(reversed); } base::string16 Textfield::GetSelectedText() const { - return native_wrapper_ ? native_wrapper_->GetSelectedText() : + return textfield_view_ ? textfield_view_->GetSelectedText() : base::string16(); } void Textfield::ClearSelection() const { - if (native_wrapper_) - native_wrapper_->ClearSelection(); + if (textfield_view_) + textfield_view_->ClearSelection(); } bool Textfield::HasSelection() const { - return native_wrapper_ && !native_wrapper_->GetSelectedRange().is_empty(); + return textfield_view_ && !textfield_view_->GetSelectedRange().is_empty(); } SkColor Textfield::GetTextColor() const { @@ -218,14 +217,14 @@ SkColor Textfield::GetTextColor() const { void Textfield::SetTextColor(SkColor color) { text_color_ = color; use_default_text_color_ = false; - if (native_wrapper_) - native_wrapper_->UpdateTextColor(); + if (textfield_view_) + textfield_view_->UpdateTextColor(); } void Textfield::UseDefaultTextColor() { use_default_text_color_ = true; - if (native_wrapper_) - native_wrapper_->UpdateTextColor(); + if (textfield_view_) + textfield_view_->UpdateTextColor(); } SkColor Textfield::GetBackgroundColor() const { @@ -240,29 +239,29 @@ SkColor Textfield::GetBackgroundColor() const { void Textfield::SetBackgroundColor(SkColor color) { background_color_ = color; use_default_background_color_ = false; - if (native_wrapper_) - native_wrapper_->UpdateBackgroundColor(); + if (textfield_view_) + textfield_view_->UpdateBackgroundColor(); } void Textfield::UseDefaultBackgroundColor() { use_default_background_color_ = true; - if (native_wrapper_) - native_wrapper_->UpdateBackgroundColor(); + if (textfield_view_) + textfield_view_->UpdateBackgroundColor(); } bool Textfield::GetCursorEnabled() const { - return native_wrapper_ && native_wrapper_->GetCursorEnabled(); + return textfield_view_ && textfield_view_->GetCursorEnabled(); } void Textfield::SetCursorEnabled(bool enabled) { - if (native_wrapper_) - native_wrapper_->SetCursorEnabled(enabled); + if (textfield_view_) + textfield_view_->SetCursorEnabled(enabled); } void Textfield::SetFontList(const gfx::FontList& font_list) { font_list_ = font_list; - if (native_wrapper_) - native_wrapper_->UpdateFont(); + if (textfield_view_) + textfield_view_->UpdateFont(); PreferredSizeChanged(); } @@ -281,8 +280,8 @@ void Textfield::SetHorizontalMargins(int left, int right) { } margins_.Set(margins_.top(), left, margins_.bottom(), right); horizontal_margins_were_set_ = true; - if (native_wrapper_) - native_wrapper_->UpdateHorizontalMargins(); + if (textfield_view_) + textfield_view_->UpdateHorizontalMargins(); PreferredSizeChanged(); } @@ -293,8 +292,8 @@ void Textfield::SetVerticalMargins(int top, int bottom) { } margins_.Set(top, margins_.left(), bottom, margins_.right()); vertical_margins_were_set_ = true; - if (native_wrapper_) - native_wrapper_->UpdateVerticalMargins(); + if (textfield_view_) + textfield_view_->UpdateVerticalMargins(); PreferredSizeChanged(); } @@ -303,8 +302,8 @@ void Textfield::RemoveBorder() { return; draw_border_ = false; - if (native_wrapper_) - native_wrapper_->UpdateBorder(); + if (textfield_view_) + textfield_view_->UpdateBorder(); } base::string16 Textfield::GetPlaceholderText() const { @@ -330,23 +329,23 @@ bool Textfield::GetVerticalMargins(int* top, int* bottom) { } void Textfield::UpdateAllProperties() { - if (native_wrapper_) { - native_wrapper_->UpdateText(); - native_wrapper_->UpdateTextColor(); - native_wrapper_->UpdateBackgroundColor(); - native_wrapper_->UpdateReadOnly(); - native_wrapper_->UpdateFont(); - native_wrapper_->UpdateEnabled(); - native_wrapper_->UpdateBorder(); - native_wrapper_->UpdateIsObscured(); - native_wrapper_->UpdateHorizontalMargins(); - native_wrapper_->UpdateVerticalMargins(); + if (textfield_view_) { + textfield_view_->UpdateText(); + textfield_view_->UpdateTextColor(); + textfield_view_->UpdateBackgroundColor(); + textfield_view_->UpdateReadOnly(); + textfield_view_->UpdateFont(); + textfield_view_->UpdateEnabled(); + textfield_view_->UpdateBorder(); + textfield_view_->UpdateIsObscured(); + textfield_view_->UpdateHorizontalMargins(); + textfield_view_->UpdateVerticalMargins(); } } void Textfield::SyncText() { - if (native_wrapper_) { - base::string16 new_text = native_wrapper_->GetText(); + if (textfield_view_) { + base::string16 new_text = textfield_view_->GetText(); if (new_text != text_) { text_ = new_text; if (controller_) @@ -356,49 +355,49 @@ void Textfield::SyncText() { } bool Textfield::IsIMEComposing() const { - return native_wrapper_ && native_wrapper_->IsIMEComposing(); + return textfield_view_ && textfield_view_->IsIMEComposing(); } -gfx::Range Textfield::GetSelectedRange() const { - return native_wrapper_->GetSelectedRange(); +const gfx::Range& Textfield::GetSelectedRange() const { + return textfield_view_->GetSelectedRange(); } void Textfield::SelectRange(const gfx::Range& range) { - native_wrapper_->SelectRange(range); + textfield_view_->SelectRange(range); } -gfx::SelectionModel Textfield::GetSelectionModel() const { - return native_wrapper_->GetSelectionModel(); +const gfx::SelectionModel& Textfield::GetSelectionModel() const { + return textfield_view_->GetSelectionModel(); } void Textfield::SelectSelectionModel(const gfx::SelectionModel& sel) { - native_wrapper_->SelectSelectionModel(sel); + textfield_view_->SelectSelectionModel(sel); } size_t Textfield::GetCursorPosition() const { - return native_wrapper_->GetCursorPosition(); + return textfield_view_->GetCursorPosition(); } void Textfield::SetColor(SkColor value) { - return native_wrapper_->SetColor(value); + return textfield_view_->SetColor(value); } void Textfield::ApplyColor(SkColor value, const gfx::Range& range) { - return native_wrapper_->ApplyColor(value, range); + return textfield_view_->ApplyColor(value, range); } void Textfield::SetStyle(gfx::TextStyle style, bool value) { - return native_wrapper_->SetStyle(style, value); + return textfield_view_->SetStyle(style, value); } void Textfield::ApplyStyle(gfx::TextStyle style, bool value, const gfx::Range& range) { - return native_wrapper_->ApplyStyle(style, value, range); + return textfield_view_->ApplyStyle(style, value, range); } void Textfield::ClearEditHistory() { - native_wrapper_->ClearEditHistory(); + textfield_view_->ClearEditHistory(); } void Textfield::SetAccessibleName(const base::string16& name) { @@ -406,7 +405,7 @@ void Textfield::SetAccessibleName(const base::string16& name) { } void Textfield::ExecuteCommand(int command_id) { - native_wrapper_->ExecuteTextCommand(command_id); + textfield_view_->ExecuteCommand(command_id, ui::EF_NONE); } void Textfield::SetFocusPainter(scoped_ptr<Painter> focus_painter) { @@ -414,30 +413,30 @@ void Textfield::SetFocusPainter(scoped_ptr<Painter> focus_painter) { } bool Textfield::HasTextBeingDragged() { - return native_wrapper_->HasTextBeingDragged(); + return textfield_view_->HasTextBeingDragged(); } //////////////////////////////////////////////////////////////////////////////// // Textfield, View overrides: void Textfield::Layout() { - if (native_wrapper_) { - native_wrapper_->GetView()->SetBoundsRect(GetContentsBounds()); - native_wrapper_->GetView()->Layout(); + if (textfield_view_) { + textfield_view_->SetBoundsRect(GetContentsBounds()); + textfield_view_->Layout(); } } int Textfield::GetBaseline() const { gfx::Insets insets = GetTextInsets(); - const int baseline = native_wrapper_ ? - native_wrapper_->GetTextfieldBaseline() : font_list_.GetBaseline(); + const int baseline = textfield_view_ ? + textfield_view_->GetTextfieldBaseline() : font_list_.GetBaseline(); return insets.top() + baseline; } gfx::Size Textfield::GetPreferredSize() { gfx::Insets insets = GetTextInsets(); - const int font_height = native_wrapper_ ? native_wrapper_->GetFontHeight() : + const int font_height = textfield_view_ ? textfield_view_->GetFontHeight() : font_list_.GetHeight(); return gfx::Size( GetPrimaryFont().GetExpectedTextWidth(default_width_in_chars_) @@ -462,11 +461,11 @@ void Textfield::OnPaint(gfx::Canvas* canvas) { } bool Textfield::OnKeyPressed(const ui::KeyEvent& e) { - return native_wrapper_ && native_wrapper_->HandleKeyPressed(e); + return textfield_view_ && textfield_view_->HandleKeyPressed(e); } bool Textfield::OnKeyReleased(const ui::KeyEvent& e) { - return native_wrapper_ && native_wrapper_->HandleKeyReleased(e); + return textfield_view_ && textfield_view_->HandleKeyReleased(e); } bool Textfield::OnMouseDragged(const ui::MouseEvent& e) { @@ -476,24 +475,15 @@ bool Textfield::OnMouseDragged(const ui::MouseEvent& e) { } void Textfield::OnFocus() { - if (native_wrapper_) - native_wrapper_->HandleFocus(); - - // Forward the focus to the wrapper if it exists. - if (!native_wrapper_ || !native_wrapper_->SetFocus()) { - // If there is no wrapper or the wrapper didn't take focus, call - // View::Focus to clear the native focus so that we still get - // keyboard messages. - View::OnFocus(); - } - - // Border typically draws focus indicator. + if (textfield_view_) + textfield_view_->HandleFocus(); + View::OnFocus(); SchedulePaint(); } void Textfield::OnBlur() { - if (native_wrapper_) - native_wrapper_->HandleBlur(); + if (textfield_view_) + textfield_view_->HandleBlur(); // Border typically draws focus indicator. SchedulePaint(); @@ -508,7 +498,7 @@ void Textfield::GetAccessibleState(ui::AccessibleViewState* state) { state->state |= ui::AccessibilityTypes::STATE_PROTECTED; state->value = text_; - const gfx::Range range = native_wrapper_->GetSelectedRange(); + const gfx::Range range = textfield_view_->GetSelectedRange(); state->selection_start = range.start(); state->selection_end = range.end(); @@ -520,27 +510,26 @@ void Textfield::GetAccessibleState(ui::AccessibleViewState* state) { } ui::TextInputClient* Textfield::GetTextInputClient() { - return native_wrapper_ ? native_wrapper_->GetTextInputClient() : NULL; + return textfield_view_ ? textfield_view_->GetTextInputClient() : NULL; } gfx::Point Textfield::GetKeyboardContextMenuLocation() { - return native_wrapper_ ? native_wrapper_->GetContextMenuLocation() : + return textfield_view_ ? textfield_view_->GetContextMenuLocation() : View::GetKeyboardContextMenuLocation(); } void Textfield::OnEnabledChanged() { View::OnEnabledChanged(); - if (native_wrapper_) - native_wrapper_->UpdateEnabled(); + if (textfield_view_) + textfield_view_->UpdateEnabled(); } void Textfield::ViewHierarchyChanged( const ViewHierarchyChangedDetails& details) { - if (details.is_add && !native_wrapper_ && GetWidget()) { - // The native wrapper's lifetime will be managed by the view hierarchy after - // we call AddChildView. - native_wrapper_ = NativeTextfieldWrapper::CreateWrapper(this); - AddChildViewAt(native_wrapper_->GetView(), 0); + if (details.is_add && !textfield_view_ && GetWidget()) { + // The textfield view's lifetime is managed by the view hierarchy. + textfield_view_ = new NativeTextfieldViews(this); + AddChildViewAt(textfield_view_, 0); Layout(); UpdateAllProperties(); } @@ -555,8 +544,8 @@ const char* Textfield::GetClassName() const { gfx::Insets Textfield::GetTextInsets() const { gfx::Insets insets = GetInsets(); - if (draw_border_ && native_wrapper_) - insets += native_wrapper_->CalculateInsets(); + if (draw_border_ && textfield_view_) + insets += textfield_view_->GetInsets(); return insets; } @@ -567,13 +556,4 @@ void Textfield::AccessibilitySetValue(const base::string16& new_value) { } } -//////////////////////////////////////////////////////////////////////////////// -// NativeTextfieldWrapper, public: - -// static -NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( - Textfield* field) { - return new NativeTextfieldViews(field); -} - } // namespace views diff --git a/ui/views/controls/textfield/textfield.h b/ui/views/controls/textfield/textfield.h index e76f866..90eaa98 100644 --- a/ui/views/controls/textfield/textfield.h +++ b/ui/views/controls/textfield/textfield.h @@ -19,8 +19,8 @@ #include "ui/events/keycodes/keyboard_codes.h" #include "ui/gfx/font_list.h" #include "ui/gfx/native_widget_types.h" +#include "ui/gfx/selection_model.h" #include "ui/gfx/text_constants.h" -#include "ui/views/controls/textfield/native_textfield_wrapper.h" #include "ui/views/view.h" #if !defined(OS_LINUX) @@ -39,6 +39,7 @@ class TextInputClient; namespace views { class ImageView; +class NativeTextfieldViews; class Painter; class TextfieldController; @@ -196,38 +197,29 @@ class VIEWS_EXPORT Textfield : public View { // Returns whether or not an IME is composing text. bool IsIMEComposing() const; - // Gets the selected range. This is views-implementation only and - // has to be called after the wrapper is created. - // TODO(msw): Return a const reference when NativeTextfieldWin is gone. - gfx::Range GetSelectedRange() const; + // Gets the selected logical text range. + const gfx::Range& GetSelectedRange() const; - // Selects the text given by |range|. This is views-implementation only and - // has to be called after the wrapper is created. + // Selects the specified logical text range. void SelectRange(const gfx::Range& range); - // Gets the selection model. This is views-implementation only and - // has to be called after the wrapper is created. - // TODO(msw): Return a const reference when NativeTextfieldWin is gone. - gfx::SelectionModel GetSelectionModel() const; + // Gets the text selection model. + const gfx::SelectionModel& GetSelectionModel() const; - // Selects the text given by |sel|. This is views-implementation only and - // has to be called after the wrapper is created. + // Sets the specified text selection model. void SelectSelectionModel(const gfx::SelectionModel& sel); - // Returns the current cursor position. This is views-implementation - // only and has to be called after the wrapper is created. + // Returns the current cursor position. size_t GetCursorPosition() const; // Set the text color over the entire text or a logical character range. - // Empty and invalid ranges are ignored. This is views-implementation only and - // has to be called after the wrapper is created. + // Empty and invalid ranges are ignored. void SetColor(SkColor value); void ApplyColor(SkColor value, const gfx::Range& range); // Set various text styles over the entire text or a logical character range. // The respective |style| is applied if |value| is true, or removed if false. - // Empty and invalid ranges are ignored. This is views-implementation only and - // has to be called after the wrapper is created. + // Empty and invalid ranges are ignored. void SetStyle(gfx::TextStyle style, bool value); void ApplyStyle(gfx::TextStyle style, bool value, const gfx::Range& range); @@ -243,11 +235,8 @@ class VIEWS_EXPORT Textfield : public View { void SetFocusPainter(scoped_ptr<Painter> focus_painter); // Provided only for testing: - gfx::NativeView GetTestingHandle() const { - return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; - } - NativeTextfieldWrapper* GetNativeWrapperForTesting() const { - return native_wrapper_; + NativeTextfieldViews* GetTextfieldViewForTesting() const { + return textfield_view_; } // Returns whether there is a drag operation originating from the textfield. @@ -275,8 +264,9 @@ class VIEWS_EXPORT Textfield : public View { const ViewHierarchyChangedDetails& details) OVERRIDE; virtual const char* GetClassName() const OVERRIDE; - // The object that actually implements the native text field. - NativeTextfieldWrapper* native_wrapper_; + // The object that actually implements the native textfield view. + // TODO(msw): Merge views::NativeTextfieldViews and views::Textfield classes. + NativeTextfieldViews* textfield_view_; private: // Returns the insets to the rectangle where text is actually painted. diff --git a/ui/views/focus/focus_manager_unittest.cc b/ui/views/focus/focus_manager_unittest.cc index d04bdf4..9c6a5bc 100644 --- a/ui/views/focus/focus_manager_unittest.cc +++ b/ui/views/focus/focus_manager_unittest.cc @@ -164,26 +164,6 @@ TEST_F(FocusManagerTest, WidgetFocusChangeListener) { widget_listener.focus_changes()[1]); } -#if !defined(USE_AURA) -class TestTextfield : public Textfield { - public: - TestTextfield() {} - virtual gfx::NativeView TestGetNativeControlView() { - return native_wrapper_->GetTestingHandle(); - } -}; - -// Tests that NativeControls do set the focused View appropriately on the -// FocusManager. -TEST_F(FocusManagerTest, DISABLED_FocusNativeControls) { - TestTextfield* textfield = new TestTextfield(); - GetContentsView()->AddChildView(textfield); - // Simulate the native view getting the native focus (such as by user click). - FocusNativeView(textfield->TestGetNativeControlView()); - EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); -} -#endif - // Counts accelerator calls. class TestAcceleratorTarget : public ui::AcceleratorTarget { public: @@ -590,7 +570,7 @@ class FocusManagerDtorTest : public FocusManagerTest { #if !defined(USE_AURA) TEST_F(FocusManagerDtorTest, FocusManagerDestructedLast) { // Setup views hierarchy. - GetContentsView()->AddChildView(new TestTextfield()); + GetContentsView()->AddChildView(new Textfield()); GetContentsView()->AddChildView(new LabelButtonDtorTracked( ASCIIToUTF16("button"), &dtor_tracker_)); diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc index 54c9972..4e34dcb 100644 --- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc +++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc @@ -74,8 +74,7 @@ class TouchSelectionControllerImplTest : public ViewsTestBase { widget_->SetContentsView(container); container->AddChildView(textfield_); - textfield_view_ = static_cast<NativeTextfieldViews*>( - textfield_->GetNativeWrapperForTesting()); + textfield_view_ = textfield_->GetTextfieldViewForTesting(); textfield_->SetBoundsRect(params.bounds); textfield_view_->SetBoundsRect(params.bounds); textfield_->set_id(1); diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc index 91bba05..4f0456e 100644 --- a/ui/views/view_unittest.cc +++ b/ui/views/view_unittest.cc @@ -1782,16 +1782,6 @@ TEST_F(ViewTest, DISABLED_RerouteMouseWheelTest) { WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); EXPECT_EQ(20, scroll_view->GetVisibleRect().y()); - // Then the text-field. - ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), - WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); - EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); - - // Ensure we don't scroll when the mouse is not over that window. - ::SendMessage(view_with_controls->text_field_->GetTestingHandle(), - WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(50, 50)); - EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); - window1->CloseNow(); window2->CloseNow(); } diff --git a/ui/views/views.gyp b/ui/views/views.gyp index 212ecaf..ecf36d2 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -218,7 +218,6 @@ 'controls/table/table_view_row_background_painter.h', 'controls/textfield/native_textfield_views.cc', 'controls/textfield/native_textfield_views.h', - 'controls/textfield/native_textfield_wrapper.h', 'controls/textfield/textfield.cc', 'controls/textfield/textfield.h', 'controls/textfield/textfield_controller.cc', |