summaryrefslogtreecommitdiffstats
path: root/views/controls/textfield/native_textfield_views.h
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 07:48:55 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 07:48:55 +0000
commitd98e7ceee03e22fbf3f93a9b4488128843ae59a1 (patch)
treeb07941d88f64a8a56783c55ba59bb18c6806a864 /views/controls/textfield/native_textfield_views.h
parent0c81ba665bab0e37ff9b82fdfd71d136044d5c96 (diff)
downloadchromium_src-d98e7ceee03e22fbf3f93a9b4488128843ae59a1.zip
chromium_src-d98e7ceee03e22fbf3f93a9b4488128843ae59a1.tar.gz
chromium_src-d98e7ceee03e22fbf3f93a9b4488128843ae59a1.tar.bz2
no native implementation of Textfield.
This is based on the original CL http://codereview.chromium.org/3142008. The key difference is * This uses Textfield framework and NativeTextfieldView implements NativeTextfieldWrapper. This allows us to swap the implementation without recompling the tree and can start testing on bots. * Changed the name of the model to TextfieldViewModel as TextfieldModel may be confusing as other Textfield implementations are not using it. I also changed to use string16 instead of gap buffer as it's enough for single line text. We can update the model to use GapBuffer when necessary. * Changed to use string16 as that's what chrome codebase should use. * Added a switch to turn on TextfieldView. I also filled a couple of features such as: * selection by key * mouse actions (move cursor, selection) * used WordIterator, which is i18n compatible, to move cursor by word * blinking cursor This is only for linux based build due to KeyStroke difference. I'm going to move some of test utlity function in chrome/browser/automation/ui_controls to app/test and will add more test once the migration is done. BUG=none TEST=new unit tests are added : NativeTestfieldViewTest and TextfieldViewModelTest. Review URL: http://codereview.chromium.org/5857002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69523 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/textfield/native_textfield_views.h')
-rw-r--r--views/controls/textfield/native_textfield_views.h172
1 files changed, 172 insertions, 0 deletions
diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h
new file mode 100644
index 0000000..cfb47be
--- /dev/null
+++ b/views/controls/textfield/native_textfield_views.h
@@ -0,0 +1,172 @@
+// Copyright (c) 2010 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 VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_
+#define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_
+#pragma once
+
+#include "base/string16.h"
+#include "base/task.h"
+#include "gfx/font.h"
+#include "views/border.h"
+#include "views/controls/textfield/native_textfield_wrapper.h"
+#include "views/view.h"
+
+namespace gfx {
+class Canvas;
+} // namespace
+
+namespace views {
+
+class KeyEvent;
+class TextfieldViewsModel;
+
+// A views/skia only implementation of NativeTextfieldWrapper.
+// No platform specific code is used.
+// Following features are not yet supported.
+// * BIDI
+// * Clipboard (Cut & Paste).
+// * Context Menu.
+// * IME/i18n support.
+// * X selection (only if we want to support).
+// * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in
+// chromeos, so we may not need them)
+// * Double click to select word, and triple click to select all.
+class NativeTextfieldViews : public views::View,
+ public NativeTextfieldWrapper {
+ public:
+ explicit NativeTextfieldViews(Textfield* parent);
+ ~NativeTextfieldViews();
+
+ // views::View overrides:
+ virtual bool OnMousePressed(const views::MouseEvent& e);
+ virtual bool OnMouseDragged(const views::MouseEvent& e);
+ virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled);
+ virtual bool OnKeyPressed(const views::KeyEvent& e);
+ virtual bool OnKeyReleased(const views::KeyEvent& e);
+ virtual void Paint(gfx::Canvas* canvas);
+ virtual void WillGainFocus();
+ virtual void DidGainFocus();
+ virtual void WillLoseFocus();
+ virtual void DidChangeBounds(const gfx::Rect& previous,
+ const gfx::Rect& current);
+
+ // NativeTextfieldWrapper overrides:
+ virtual string16 GetText() const;
+ virtual void UpdateText();
+ virtual void AppendText(const string16& text);
+ virtual string16 GetSelectedText() const;
+ virtual void SelectAll();
+ virtual void ClearSelection();
+ virtual void UpdateBorder();
+ virtual void UpdateTextColor();
+ virtual void UpdateBackgroundColor();
+ virtual void UpdateReadOnly();
+ virtual void UpdateFont();
+ virtual void UpdateIsPassword();
+ virtual void UpdateEnabled();
+ virtual bool IsPassword();
+ virtual gfx::Insets CalculateInsets();
+ virtual void UpdateHorizontalMargins();
+ virtual void UpdateVerticalMargins();
+ virtual void SetFocus();
+ virtual View* GetView();
+ virtual gfx::NativeView GetTestingHandle() const;
+ virtual bool IsIMEComposing() const;
+
+ // class name of internal
+ static const char kViewClassName[];
+
+ // Returns true when
+ // 1) built with GYP_DEFIENS="touchui=1"
+ // 2) enabled by SetEnableTextfieldViews(true)
+ // 3) enabled by the command line flag "--enable-textfield-view".
+ static bool IsTextfieldViewsEnabled();
+ // Enable/Disable TextfieldViews implementation for Textfield.
+ static void SetEnableTextfieldViews(bool enabled);
+
+ private:
+ friend class NativeTextfieldViewsTest;
+
+ // A Border class to draw focus border for the text field.
+ class TextfieldBorder : public Border {
+ public:
+ TextfieldBorder();
+
+ // Border implementation.
+ virtual void Paint(const View& view, gfx::Canvas* canvas) const;
+ virtual void GetInsets(gfx::Insets* insets) const;
+
+ // Sets the insets of the border.
+ void SetInsets(int top, int left, int bottom, int right);
+
+ // Sets the focus state.
+ void set_has_focus(bool has_focus) {
+ has_focus_ = has_focus;
+ }
+
+ private:
+ bool has_focus_;
+ gfx::Insets insets_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextfieldBorder);
+ };
+
+ // Returns the Textfield's font.
+ const gfx::Font& GetFont() const;
+
+ // Returns the Textfield's text color.
+ SkColor GetTextColor() const;
+
+ // A callback function to periodically update the cursor state.
+ void UpdateCursor();
+
+ // Repaint the cursor.
+ void RepaintCursor();
+
+ // Update the cursor_bounds and text_offset.
+ void UpdateCursorBoundsAndTextOffset();
+
+ void PaintTextAndCursor(gfx::Canvas* canvas);
+
+ // Handle the keyevent.
+ bool HandleKeyEvent(const KeyEvent& key_event);
+
+ // Utility function. Gets the character corresponding to a keyevent.
+ // Returns 0 if the character is not printable.
+ char16 GetPrintableChar(const KeyEvent& key_event);
+
+ // Find a cusor position for given |point| in this views coordinates.
+ size_t FindCursorPosition(const gfx::Point& point) const;
+
+ // The parent textfield, the owner of this object.
+ Textfield* textfield_;
+
+ // The text model.
+ scoped_ptr<TextfieldViewsModel> model_;
+
+ // The reference to the border class. The object is owned by View::border_.
+ TextfieldBorder* text_border_;
+
+ // The x offset for the text to be drawn, without insets;
+ int text_offset_;
+
+ // Cursor's bounds in the textfield's coordinates.
+ gfx::Rect cursor_bounds_;
+
+ // True if the textfield is in insert mode.
+ bool insert_;
+
+ // The drawing state of cursor. True to draw.
+ bool is_cursor_visible_;
+
+ // A runnable method factory for callback to update the cursor.
+ ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews);
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_