Chromium Code Reviews| Index: views/controls/textfield/native_textfield_view.h |
| diff --git a/views/controls/textfield/native_textfield_view.h b/views/controls/textfield/native_textfield_view.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b3150c94d000bddf94e3ab3864a08f5e9a8fe4e9 |
| --- /dev/null |
| +++ b/views/controls/textfield/native_textfield_view.h |
| @@ -0,0 +1,167 @@ |
| +// 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_VIEW_H_ |
| +#define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEW_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 TextfieldViewModel; |
| + |
| +// A non-native, skia based implementation of NativeTextfieldWrapper. |
| +// Following features are not yet supported. |
| +// * BIDI |
| +// * Clipboard (Cut & Paste). |
| +// * Context Menu. |
| +// * IME 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) |
| +class NativeTextfieldView : public views::View, |
|
sky
2010/12/15 20:31:27
This name is confusing given the class description
oshima
2010/12/16 01:15:19
I've been going back and forth, and this name soun
|
| + public NativeTextfieldWrapper { |
| + public: |
| + explicit NativeTextfieldView(Textfield* parent); |
| + ~NativeTextfieldView(); |
| + |
| + // views::View overrides: |
| + virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e); |
| + 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[]; |
| + |
| + static bool IsTextfieldViewEnabled(); |
| + static void SetEnableTextfieldView(bool enabled); |
| + |
| + private: |
| + friend class NativeTextfieldViewTest; |
| + |
| + // A Border class to draw focus border for the text field. |
| + class TextfieldBorder : public Border { |
|
sky
2010/12/15 20:31:27
nit: put this in the .cc?
|
| + 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. |
| + gfx::Font GetFont() const; |
|
sky
2010/12/15 20:31:27
const gfx::Font&
oshima
2010/12/16 01:15:19
Done. It was cut&paste from Textfield. Updated Tex
|
| + |
| + // 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/ |
| + // key_code. Returns 0 if the character is not printable. |
| + char16 GetPrintableChar(const KeyEvent& key_event); |
| + char16 GetPrintableChar(app::KeyboardCode key_code, bool shift); |
| + |
| + // 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<TextfieldViewModel> 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. |
|
sky
2010/12/15 20:31:27
How about naming this is_cursor_visible_?
oshima
2010/12/16 01:15:19
Done.
|
| + bool cursor_; |
| + |
| + // A runnable method factory for callback to update the cursor. |
| + ScopedRunnableMethodFactory<NativeTextfieldView> cursor_timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NativeTextfieldView); |
| +}; |
| + |
| +} // namespace views |
| + |
| +#endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEW_H_ |