summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/textfield/textfield.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/views/controls/textfield/textfield.cc')
-rw-r--r--ui/views/controls/textfield/textfield.cc208
1 files changed, 94 insertions, 114 deletions
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