summaryrefslogtreecommitdiffstats
path: root/views/controls/textfield
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 23:48:30 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 23:48:30 +0000
commit5c9e97acabd4cdab5adb20d2412a5766b3382856 (patch)
treeead11654548e0e110cf8c8dce962801d530d54f7 /views/controls/textfield
parent7f01f83fd464fc13cbdb9d377493d1781decf363 (diff)
downloadchromium_src-5c9e97acabd4cdab5adb20d2412a5766b3382856.zip
chromium_src-5c9e97acabd4cdab5adb20d2412a5766b3382856.tar.gz
chromium_src-5c9e97acabd4cdab5adb20d2412a5766b3382856.tar.bz2
First cut at implementation of FindBar for views / gtk
Also had to implement change notification for TextField on views / gtk Review URL: http://codereview.chromium.org/200035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/textfield')
-rw-r--r--views/controls/textfield/native_textfield_gtk.cc38
-rw-r--r--views/controls/textfield/native_textfield_gtk.h11
-rw-r--r--views/controls/textfield/textfield.cc55
-rw-r--r--views/controls/textfield/textfield.h58
4 files changed, 114 insertions, 48 deletions
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc
index 6ceaab4..ef7a67d 100644
--- a/views/controls/textfield/native_textfield_gtk.cc
+++ b/views/controls/textfield/native_textfield_gtk.cc
@@ -134,18 +134,50 @@ gfx::NativeView NativeTextfieldGtk::GetTestingHandle() const {
return native_view();
}
+// static
+gboolean NativeTextfieldGtk::OnKeyPressEventHandler(
+ GtkWidget* entry,
+ GdkEventKey* event,
+ NativeTextfieldGtk* textfield) {
+ return textfield->OnKeyPressEvent(event);
+}
+
+gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) {
+ Textfield::Controller* controller = textfield_->GetController();
+ if (controller) {
+ Textfield::Keystroke ks(event);
+ return controller->HandleKeystroke(textfield_, ks);
+ }
+ return false;
+}
+
+// static
+gboolean NativeTextfieldGtk::OnChangedHandler(
+ GtkWidget* entry,
+ NativeTextfieldGtk* textfield) {
+ return textfield->OnChanged();
+}
+
+gboolean NativeTextfieldGtk::OnChanged() {
+ Textfield::Controller* controller = textfield_->GetController();
+ if (controller)
+ controller->ContentsChanged(textfield_, GetText());
+ return false;
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeTextfieldGtk, NativeControlGtk overrides:
void NativeTextfieldGtk::CreateNativeControl() {
- // TODO(brettw) hook in an observer to get text change events so we can call
- // the controller.
NativeControlCreated(gtk_entry_new());
}
void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) {
NativeControlGtk::NativeControlCreated(widget);
- // TODO(port): post-creation init
+ g_signal_connect(widget, "changed",
+ G_CALLBACK(OnChangedHandler), this);
+ g_signal_connect(widget, "key-press-event",
+ G_CALLBACK(OnKeyPressEventHandler), this);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/views/controls/textfield/native_textfield_gtk.h b/views/controls/textfield/native_textfield_gtk.h
index 9e10116..ef2f4fe 100644
--- a/views/controls/textfield/native_textfield_gtk.h
+++ b/views/controls/textfield/native_textfield_gtk.h
@@ -43,6 +43,17 @@ class NativeTextfieldGtk : public NativeControlGtk,
private:
Textfield* textfield_;
+ // Callback when the entry text changes.
+ static gboolean OnKeyPressEventHandler(
+ GtkWidget* entry,
+ GdkEventKey* event,
+ NativeTextfieldGtk* textfield);
+ gboolean OnKeyPressEvent(GdkEventKey* event);
+ static gboolean OnChangedHandler(
+ GtkWidget* entry,
+ NativeTextfieldGtk* textfield);
+ gboolean OnChanged();
+
DISALLOW_COPY_AND_ASSIGN(NativeTextfieldGtk);
};
diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc
index 3887697..97240c7 100644
--- a/views/controls/textfield/textfield.cc
+++ b/views/controls/textfield/textfield.cc
@@ -4,10 +4,15 @@
#include "views/controls/textfield/textfield.h"
+#if defined(OS_LINUX)
+#include <gdk/gdkkeysyms.h>
+#endif
+
#include "app/gfx/insets.h"
#if defined(OS_WIN)
#include "app/win_util.h"
#endif
+
#include "base/string_util.h"
#include "views/controls/textfield/native_textfield_wrapper.h"
#include "views/widget/widget.h"
@@ -167,28 +172,6 @@ void Textfield::SyncText() {
text_ = native_wrapper_->GetText();
}
-// static
-bool Textfield::IsKeystrokeEnter(const Keystroke& key) {
-#if defined(OS_WIN)
- return key.key == VK_RETURN;
-#else
- // TODO(port): figure out VK_constants
- NOTIMPLEMENTED();
- return false;
-#endif
-}
-
-// static
-bool Textfield::IsKeystrokeEscape(const Keystroke& key) {
-#if defined(OS_WIN)
- return key.key == VK_ESCAPE;
-#else
- // TODO(port): figure out VK_constants
- NOTIMPLEMENTED();
- return false;
-#endif
-}
-
////////////////////////////////////////////////////////////////////////////////
// Textfield, View overrides:
@@ -296,4 +279,32 @@ NativeTextfieldWrapper* Textfield::CreateWrapper() {
return native_wrapper;
}
+base::KeyboardCode Textfield::Keystroke::GetKeyboardCode() const {
+#if defined(OS_WIN)
+ return static_cast<base::KeyboardCode>(key_);
+#else
+ return static_cast<base::KeyboardCode>(event_.keyval);
+#endif
+}
+
+#if defined(OS_WIN)
+bool Textfield::Keystroke::IsControlHeld() const {
+ return GetKeyState(VK_CONTROL) >= 0;
+}
+
+bool Textfield::Keystroke::IsShiftHeld() const {
+ return GetKeyState(VK_SHIFT) >= 0;
+}
+#else
+bool Textfield::Keystroke::IsControlHeld() const {
+ return (event_.state & gtk_accelerator_get_default_mod_mask()) ==
+ GDK_CONTROL_MASK;
+}
+
+bool Textfield::Keystroke::IsShiftHeld() const {
+ return (event_.state & gtk_accelerator_get_default_mod_mask()) ==
+ GDK_SHIFT_MASK;
+}
+#endif
+
} // namespace views
diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h
index ecd16169..fd01cef 100644
--- a/views/controls/textfield/textfield.h
+++ b/views/controls/textfield/textfield.h
@@ -5,8 +5,13 @@
#ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
#define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
+#if defined (OS_LINUX)
+#include <gdk/gdk.h>
+#endif
+
#include "app/gfx/font.h"
#include "base/basictypes.h"
+#include "base/keyboard_codes.h"
#include "base/string16.h"
#include "views/view.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -30,29 +35,45 @@ class Textfield : public View {
// Cross-platform code can use IsKeystrokeEnter/Escape to check for these
// two common key events.
// TODO(brettw) this should be cleaned up to be more cross-platform.
+ class Keystroke {
+ public:
#if defined(OS_WIN)
- struct Keystroke {
- Keystroke(unsigned int m,
+ const Keystroke(unsigned int m,
wchar_t k,
int r,
unsigned int f)
- : message(m),
- key(k),
- repeat_count(r),
- flags(f) {
+ : message_(m),
+ key_(k),
+ repeat_count_(r),
+ flags_(f) {
}
+ unsigned int message() const { return message_; }
+ wchar_t key() const { return key_; }
+ int repeat_count() const { return repeat_count_; }
+ unsigned int flags() const { return flags_; }
+#else
+ explicit Keystroke(GdkEventKey* event)
+ : event_(*event) {
+ }
+ const GdkEventKey* event() const { return &event_; }
+#endif
+ base::KeyboardCode GetKeyboardCode() const;
+ bool IsControlHeld() const;
+ bool IsShiftHeld() const;
- unsigned int message;
- wchar_t key;
- int repeat_count;
- unsigned int flags;
- };
+ private:
+#if defined(OS_WIN)
+ unsigned int message_;
+ wchar_t key_;
+ int repeat_count_;
+ unsigned int flags_;
#else
- struct Keystroke {
- // TODO(brettw) figure out what this should be on GTK.
- };
+ GdkEventKey event_;
#endif
+ DISALLOW_COPY_AND_ASSIGN(Keystroke);
+ };
+
// This defines the callback interface for other code to be notified of
// changes in the state of a text field.
class Controller {
@@ -157,15 +178,6 @@ class Textfield : public View {
// been deleted during a window close.
void SyncText();
- // Provides a cross-platform way of checking whether a keystroke is one of
- // these common keys. Most code only checks keystrokes against these two keys,
- // so the caller can be cross-platform by implementing the platform-specific
- // parts in here.
- // TODO(brettw) we should use a more cross-platform representation of
- // keyboard events so these are not necessary.
- static bool IsKeystrokeEnter(const Keystroke& key);
- static bool IsKeystrokeEscape(const Keystroke& key);
-
#ifdef UNIT_TEST
gfx::NativeView GetTestingHandle() const {
return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL;