Chromium Code Reviews| Index: views/controls/textfield/native_textfield_views.cc |
| diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc |
| index a3ad114eb91a49c752df741c441d3499428b0ca5..94b66ece935a70df51f5efee3b17dc5ac0cbe1da 100644 |
| --- a/views/controls/textfield/native_textfield_views.cc |
| +++ b/views/controls/textfield/native_textfield_views.cc |
| @@ -57,7 +57,6 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent) |
| insert_(true), |
| is_cursor_visible_(false), |
| ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)) { |
| - SetFocusable(true); |
| set_border(text_border_); |
| // Multiline is not supported. |
| @@ -73,7 +72,7 @@ NativeTextfieldViews::~NativeTextfieldViews() { |
| // NativeTextfieldViews, View overrides: |
| bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& e) { |
| - RequestFocus(); |
| + textfield_->RequestFocus(); |
| size_t pos = FindCursorPosition(e.location()); |
| if (model_->MoveCursorTo(pos, false)) { |
| UpdateCursorBoundsAndTextOffset(); |
| @@ -96,52 +95,41 @@ void NativeTextfieldViews::OnMouseReleased(const views::MouseEvent& e, |
| } |
| bool NativeTextfieldViews::OnKeyPressed(const views::KeyEvent& e) { |
| - Textfield::Controller* controller = textfield_->GetController(); |
| - bool handled = false; |
| - if (controller) { |
| - Textfield::Keystroke ks(&e); |
| - handled = controller->HandleKeystroke(textfield_, ks); |
| - } |
| - return handled || HandleKeyEvent(e); |
| + // OnKeyPressed/OnKeyReleased/WillGainFocus/DidGainFocus/WillLoseFocus |
| + // will never be invoked on NativeTextfieldViews as it will never |
| + // gain a focus. |
|
Jay Civelli
2011/01/06 00:55:54
Nit: gain a focus -> gain focus.
oshima
2011/01/06 01:31:22
Done. fixed other places as well.
|
| + NOTREACHED(); |
| + return false; |
| } |
| bool NativeTextfieldViews::OnKeyReleased(const views::KeyEvent& e) { |
| - return true; |
| + NOTREACHED(); |
| + return false; |
| } |
| void NativeTextfieldViews::Paint(gfx::Canvas* canvas) { |
| - text_border_->set_has_focus(HasFocus()); |
| + text_border_->set_has_focus(textfield_->HasFocus()); |
| PaintBackground(canvas); |
| PaintTextAndCursor(canvas); |
| if (textfield_->draw_border()) |
| PaintBorder(canvas); |
| } |
| +void NativeTextfieldViews::DidChangeBounds(const gfx::Rect& previous, |
| + const gfx::Rect& current) { |
| + UpdateCursorBoundsAndTextOffset(); |
| +} |
| + |
| void NativeTextfieldViews::WillGainFocus() { |
| + NOTREACHED(); |
| } |
| void NativeTextfieldViews::DidGainFocus() { |
| - is_cursor_visible_ = true; |
| - SchedulePaint(); |
| - // Start blinking cursor. |
| - MessageLoop::current()->PostDelayedTask( |
| - FROM_HERE, |
| - cursor_timer_.NewRunnableMethod(&NativeTextfieldViews::UpdateCursor), |
| - kCursorVisibleTimeMs); |
| + NOTREACHED(); |
| } |
| void NativeTextfieldViews::WillLoseFocus() { |
| - // Stop blinking cursor. |
| - cursor_timer_.RevokeAll(); |
| - if (is_cursor_visible_) { |
| - is_cursor_visible_ = false; |
| - RepaintCursor(); |
| - } |
| -} |
| - |
| -void NativeTextfieldViews::DidChangeBounds(const gfx::Rect& previous, |
| - const gfx::Rect& current) { |
| - UpdateCursorBoundsAndTextOffset(); |
| + NOTREACHED(); |
| } |
| ///////////////////////////////////////////////////////////////// |
| @@ -225,15 +213,10 @@ void NativeTextfieldViews::UpdateIsPassword() { |
| } |
| void NativeTextfieldViews::UpdateEnabled() { |
| + SetEnabled(textfield_->IsEnabled()); |
| SchedulePaint(); |
| } |
| -bool NativeTextfieldViews::IsPassword() { |
| - // looks unnecessary. should we remove? |
| - NOTREACHED(); |
| - return false; |
| -} |
| - |
| gfx::Insets NativeTextfieldViews::CalculateInsets() { |
| return GetInsets(); |
| } |
| @@ -258,8 +241,8 @@ void NativeTextfieldViews::UpdateVerticalMargins() { |
| UpdateCursorBoundsAndTextOffset(); |
| } |
| -void NativeTextfieldViews::SetFocus() { |
| - RequestFocus(); |
| +bool NativeTextfieldViews::SetFocus() { |
| + return false; |
| } |
| View* NativeTextfieldViews::GetView() { |
| @@ -275,6 +258,42 @@ bool NativeTextfieldViews::IsIMEComposing() const { |
| return false; |
| } |
| +bool NativeTextfieldViews::HandleKeyPressed(const views::KeyEvent& e) { |
| + Textfield::Controller* controller = textfield_->GetController(); |
| + bool handled = false; |
| + if (controller) { |
| + Textfield::Keystroke ks(&e); |
| + handled = controller->HandleKeystroke(textfield_, ks); |
| + } |
| + return handled || HandleKeyEvent(e); |
| +} |
| + |
| +bool NativeTextfieldViews::HandleKeyReleased(const views::KeyEvent& e) { |
| + return true; |
| +} |
| + |
| +void NativeTextfieldViews::HandleWillGainFocus() { |
| +} |
| + |
| +void NativeTextfieldViews::HandleDidGainFocus() { |
| + is_cursor_visible_ = true; |
| + SchedulePaint(); |
| + // Start blinking cursor. |
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + cursor_timer_.NewRunnableMethod(&NativeTextfieldViews::UpdateCursor), |
| + kCursorVisibleTimeMs); |
| +} |
| + |
| +void NativeTextfieldViews::HandleWillLoseFocus() { |
| + // Stop blinking cursor. |
| + cursor_timer_.RevokeAll(); |
| + if (is_cursor_visible_) { |
| + is_cursor_visible_ = false; |
| + RepaintCursor(); |
| + } |
| +} |
| + |
| // static |
| bool NativeTextfieldViews::IsTextfieldViewsEnabled() { |
| #if defined(TOUCH_UI) |
| @@ -370,7 +389,8 @@ void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { |
| int y = insets.top(); |
| int text_height = height() - insets.height(); |
| SkColor selection_color = |
| - HasFocus() ? kFocusedSelectionColor : kUnfocusedSelectionColor; |
| + textfield_->HasFocus() ? |
| + kFocusedSelectionColor : kUnfocusedSelectionColor; |
| SkColor text_color = |
| textfield_->read_only() ? kReadonlyTextColor : GetTextColor(); |