Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: views/controls/textfield/textfield_view.h

Issue 3142008: Model, View and Controller for a Gap Buffer based one line text field in view... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/controls/textfield/textfield_view.h
===================================================================
--- views/controls/textfield/textfield_view.h (revision 0)
+++ views/controls/textfield/textfield_view.h (revision 0)
@@ -0,0 +1,88 @@
+// 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_TEXTFIELD_VIEW_H_
+#define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEW_H_
+#pragma once
+
+#include <algorithm>
+
+#include "gfx/canvas.h"
+#include "views/controls/label.h"
+#include "views/controls/textfield/textfield_model.h"
+#include "views/event.h"
+#include "views/view.h"
+
+namespace views {
+
+// View for a MVC of a single line textfield. The textfield inherits from Label
+// to re-use its font and color related code.
+class TextfieldView : public Label {
+ public:
+ TextfieldView();
+ explicit TextfieldView(const std::wstring& text);
+ explicit TextfieldView(TextfieldModel* model);
+
+ virtual void SetController(TextfieldController* controller);
+ // Returns the rectangle in which the text can be painted. This is essentially
+ // the bounds of the view minus the border (insets) width.
+ gfx::Rect GetTextBounds();
+
+
+ // View Overrides. Refer to view.h for documentation.
+ 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 std::wstring GetText();
+
+ // Getters
+ int onscreen_cursor_pos() { return onscreen_cursor_pos_; }
+ std::wstring visible_text() { return visible_text_; }
+
+ static const char kViewClassName[];
+
+ private:
+ // Computes the portion of string that can be painted to the left of cursor.
+ std::wstring GetStringToLeftOfCursor(std::wstring text, int cursor_pos,
+ int onscreen_cursor_pos, gfx::Rect text_bounds);
+
+ // Computes the portion of string that can be painted to the left of cursor.
+ std::wstring GetStringToRightOfCursor(std::wstring text, int cursor_pos,
+ int onscreen_cursor_pos, gfx::Rect text_bounds);
+
+ // Utility function. Gets the character corresponding to a key event.
+ wchar_t GetWritableChar(const KeyEvent& key_event);
+
+ // Utility function. Gets the character corresponding to a key_code.
+ wchar_t GetWritableChar(base::KeyboardCode key_code, bool shift);
+ bool HandleKeyEvent(const KeyEvent& key_event);
+ void Init(const std::wstring& text);
+ bool IsDirectionalKey(base::KeyboardCode key_code);
+ bool IsWritable(base::KeyboardCode key_code);
+ void PaintTextAndCursor(gfx::Canvas* canvas);
+
+ // Safely increments the onscreen position of the cursor (making sure it does
+ // not exceeds the view bounds).
+ void SafeIncCursorPos(int inc);
+
+ // Safely decrements the onscreen position of the cursor (making sure it does
+ // not go below 0).
+ void SafeDecCursorPos(int dec);
+
+ scoped_ptr<TextfieldModel> model_;
+ scoped_ptr<TextfieldController> controller_;
+ std::wstring visible_text_;
+ bool selection_on_;
+ int selection_start_;
+ int onscreen_cursor_pos_;
+};
+};
+#endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEW_H_
Property changes on: views/controls/textfield/textfield_view.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698