summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 22:24:11 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 22:24:11 +0000
commitf40630d1ba3e640bb9392b96f2397fcf991b98ab (patch)
tree16995b225f2b03c58a20f5e2b2d852c2138e501c /views
parentf0815756f61f11537f1a354646bb0bb9c93433a1 (diff)
downloadchromium_src-f40630d1ba3e640bb9392b96f2397fcf991b98ab.zip
chromium_src-f40630d1ba3e640bb9392b96f2397fcf991b98ab.tar.gz
chromium_src-f40630d1ba3e640bb9392b96f2397fcf991b98ab.tar.bz2
views textfield: Show the correct cursor.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6293025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/textfield/native_textfield_views.cc54
-rw-r--r--views/controls/textfield/native_textfield_views.h6
2 files changed, 44 insertions, 16 deletions
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index a5a4039..37db36e 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -23,6 +23,10 @@
#include "views/event.h"
#include "views/views_delegate.h"
+#if defined(OS_LINUX)
+#include "gfx/gtk_util.h"
+#endif
+
namespace {
// A global flag to switch the Textfield wrapper to TextfieldViews.
@@ -135,6 +139,17 @@ void NativeTextfieldViews::WillLoseFocus() {
NOTREACHED();
}
+gfx::NativeCursor NativeTextfieldViews::GetCursorForPoint(
+ Event::EventType event_type,
+ const gfx::Point& p) {
+#if defined(OS_WIN)
+ static HCURSOR ibeam = LoadCursor(NULL, IDC_IBEAM);
+ return ibeam;
+#else
+ return gfx::GetCursor(GDK_XTERM);
+#endif
+}
+
/////////////////////////////////////////////////////////////////
// NativeTextfieldViews, views::ContextMenuController overrides:
void NativeTextfieldViews::ShowContextMenu(View* source,
@@ -378,8 +393,9 @@ void NativeTextfieldViews::ExecuteCommand(int command_id) {
NOTREACHED() << "unknown command: " << command_id;
break;
}
- if (text_changed)
- PropagateTextChange();
+
+ // The cursor must have changed if text changed during cut/paste/delete.
+ UpdateAfterChange(text_changed, text_changed);
}
// static
@@ -535,7 +551,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
break;
case ui::VKEY_X:
if (control && editable)
- text_changed = model_->Cut();
+ cursor_changed = text_changed = model_->Cut();
break;
case ui::VKEY_C:
if (control)
@@ -543,7 +559,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
break;
case ui::VKEY_V:
if (control && editable)
- text_changed = model_->Paste();
+ cursor_changed = text_changed = model_->Paste();
break;
case ui::VKEY_RIGHT:
control ? model_->MoveCursorToNextWord(selection)
@@ -600,7 +616,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
model_->MoveCursorToNextWord(true);
}
}
- text_changed = model_->Delete();
+ cursor_changed = text_changed = model_->Delete();
break;
case ui::VKEY_INSERT:
insert_ = !insert_;
@@ -617,17 +633,9 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
model_->Replace(print_char);
text_changed = true;
}
- if (text_changed)
- PropagateTextChange();
- if (cursor_changed) {
- is_cursor_visible_ = true;
- RepaintCursor();
- }
- if (text_changed || cursor_changed) {
- UpdateCursorBoundsAndTextOffset();
- SchedulePaint();
- return true;
- }
+
+ UpdateAfterChange(text_changed, cursor_changed);
+ return (text_changed || cursor_changed);
}
return false;
}
@@ -829,6 +837,20 @@ void NativeTextfieldViews::PropagateTextChange() {
controller->ContentsChanged(textfield_, GetText());
}
+void NativeTextfieldViews::UpdateAfterChange(bool text_changed,
+ bool cursor_changed) {
+ if (text_changed)
+ PropagateTextChange();
+ if (cursor_changed) {
+ is_cursor_visible_ = true;
+ RepaintCursor();
+ }
+ if (text_changed || cursor_changed) {
+ UpdateCursorBoundsAndTextOffset();
+ SchedulePaint();
+ }
+}
+
void NativeTextfieldViews::InitContextMenuIfRequired() {
if (context_menu_menu_.get())
return;
diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h
index fb567cf..1297710 100644
--- a/views/controls/textfield/native_textfield_views.h
+++ b/views/controls/textfield/native_textfield_views.h
@@ -58,6 +58,8 @@ class NativeTextfieldViews : public views::View,
virtual void WillGainFocus();
virtual void DidGainFocus();
virtual void WillLoseFocus();
+ virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
+ const gfx::Point& p);
// views::ContextMenuController overrides:
virtual void ShowContextMenu(View* source,
@@ -184,6 +186,10 @@ class NativeTextfieldViews : public views::View,
// that the text in the textfield has changed.
void PropagateTextChange();
+ // Does necessary updates when the text and/or the position of the cursor
+ // changed.
+ void UpdateAfterChange(bool text_changed, bool cursor_changed);
+
// Utility function to create the context menu if one does not already exist.
void InitContextMenuIfRequired();